Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Since (annotation) - support multiple lines #7381

Merged
merged 10 commits into from
Jan 4, 2025
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/doc/Documentation.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private static void insertSyntaxElement(final PrintWriter pw, final SyntaxElemen
return;
}
final String desc = validateHTML(StringUtils.join(elementClass.getAnnotation(Description.class).value(), "<br/>"), type + "s");
final String since = validateHTML(elementClass.getAnnotation(Since.class).value(), type + "s");
final String since = validateHTML(StringUtils.join(elementClass.getAnnotation(Since.class).value(), "<br/>"), type + "s");
if (desc == null || since == null) {
Skript.warning("" + elementClass.getSimpleName() + "'s description or 'since' is invalid");
return;
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/ch/njol/skript/doc/HTMLGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
*/
public class HTMLGenerator extends DocumentationGenerator {

private static final String SKRIPT_VERSION = Skript.getVersion().toString().replaceAll("-(dev|alpha|beta)\\d*", ""); // Filter branches
private static final Pattern NEW_TAG_PATTERN = Pattern.compile(SKRIPT_VERSION + "(?!\\.)"); // (?!\\.) to avoid matching 2.6 in 2.6.1 etc.
private static final String SKRIPT_VERSION = Skript.getVersion().toString().replaceAll("-(dev|alpha|beta|pre)\\d*", "").replace(".0", ""); // Filter branches
private static final Pattern NEW_TAG_PATTERN = Pattern.compile(SKRIPT_VERSION + "(?!\\.[1-9])"); // (?!\\.) to avoid matching 2.6 in 2.6.1 etc.
private static final Pattern RETURN_TYPE_LINK_PATTERN = Pattern.compile("( ?href=\"(classes\\.html|)#|)\\$\\{element\\.return-type-linkcheck}");

private final String skeleton;
Expand Down Expand Up @@ -434,7 +434,7 @@ private String generateAnnotated(String descTemp, SyntaxElementInfo<?> info, @Nu

// Since
Since since = c.getAnnotation(Since.class);
desc = desc.replace("${element.since}", getDefaultIfNullOrEmpty((since != null ? since.value() : null), "Unknown"));
desc = desc.replace("${element.since}", Joiner.on("<br/>").join(getDefaultIfNullOrEmpty((since != null ? since.value() : null), "Unknown")));

Keywords keywords = c.getAnnotation(Keywords.class);
desc = desc.replace("${element.keywords}", keywords == null ? "" : Joiner.on(", ").join(keywords.value()));
Expand Down Expand Up @@ -488,7 +488,13 @@ private String generateAnnotated(String descTemp, SyntaxElementInfo<?> info, @Nu
desc = handleIf(desc, "${if by-addon}", false);

// New Elements
desc = handleIf(desc, "${if new-element}", NEW_TAG_PATTERN.matcher((since != null ? since.value() : "")).find());
ShaneBeee marked this conversation as resolved.
Show resolved Hide resolved
if (since != null) {
String[] value = since.value();
String s = value[value.length - 1];
desc = handleIf(desc, "${if new-element}", NEW_TAG_PATTERN.matcher(s).find());
} else {
desc = handleIf(desc, "${if new-element}", false);
}

// Structure - EntryData
if (info instanceof StructureInfo) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/doc/JSONGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public JSONGenerator(File templateDir, File outputDir) {
syntaxJsonObject.addProperty("name", nameAnnotation.value());

Since sinceAnnotation = syntaxClass.getAnnotation(Since.class);
syntaxJsonObject.addProperty("since", sinceAnnotation == null ? null : sinceAnnotation.value());
syntaxJsonObject.add("since", sinceAnnotation == null ? null : convertToJsonArray(sinceAnnotation.value()));

Description descriptionAnnotation = syntaxClass.getAnnotation(Description.class);
if (descriptionAnnotation != null) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/doc/Since.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
@Documented
public @interface Since {

public String value();
public String[] value();
}
7 changes: 6 additions & 1 deletion src/main/java/ch/njol/skript/expressions/ExprName.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@
"\tset the player's tab list name to \"&lt;green&gt;%player's name%\"",
"set the name of the player's tool to \"Legendary Sword of Awesomeness\""
})
@Since("before 2.1, 2.2-dev20 (inventory name), 2.4 (non-living entity support, changeable inventory name), 2.7 (worlds)")
@Since({
"before 2.1",
"2.2-dev20 (inventory name)",
"2.4 (non-living entity support, changeable inventory name)",
"2.7 (worlds)"
})
public class ExprName extends SimplePropertyExpression<Object, String> {

@Nullable
Expand Down
Loading