Skip to content

Commit

Permalink
Fix empty event requirements in docs (#7499)
Browse files Browse the repository at this point in the history
  • Loading branch information
Efnilite authored Feb 28, 2025
1 parent 198bddb commit 70b3ce6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
40 changes: 24 additions & 16 deletions src/main/java/ch/njol/skript/doc/HTMLGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -387,21 +382,30 @@ private static String minifyHtml(String page) {
return sb.toString();
}

private static String handleIf(String desc, String start, boolean value) {
/**
* Handles an optional part in an HTML description.
* @param desc The existing description.
* @param condition The condition string to check.
* @param value Whether
* @return The modified description.
*/
private static String handleIf(String desc, String condition, boolean value) {
assert desc != null;
int ifStart = desc.indexOf(start);
int ifStart = desc.indexOf(condition);

while (ifStart != -1) {
int ifEnd = desc.indexOf("${end}", ifStart);
String data = desc.substring(ifStart + start.length() + 1, ifEnd);
String data = desc.substring(ifStart + condition.length() + 1, ifEnd);

String before = desc.substring(0, ifStart);
String after = desc.substring(ifEnd + 6);

if (value)
desc = before + data + after;
desc = before + data + after; // include if condition is met
else
desc = before + after;
desc = before + after; // skip if condition is not met

ifStart = desc.indexOf(start, ifEnd);
ifStart = desc.indexOf(condition, ifEnd);
}

return desc;
Expand Down Expand Up @@ -605,10 +609,14 @@ private String generateEvent(String descTemp, SkriptEventInfo<?> info, @Nullable
}
desc = desc.replace("${element.events-safe}", events == null ? "" : Joiner.on(", ").join((events != null ? events.value() : null)));

// Required Plugins
String[] requiredPlugins = info.getRequiredPlugins();
desc = handleIf(desc, "${if required-plugins}", requiredPlugins != null);
desc = desc.replace("${element.required-plugins}", Joiner.on(", ").join(requiredPlugins == null ? new String[0] : requiredPlugins));
// RequiredPlugins
String[] plugins = info.getRequiredPlugins();
desc = handleIf(desc, "${if required-plugins}", plugins != null && plugins.length > 0);
if (plugins == null) {
desc = desc.replace("${element.required-plugins}", "");
} else {
desc = desc.replace("${element.required-plugins}", Joiner.on(", ").join(plugins));
}

// New Elements
desc = handleIf(desc, "${if new-element}", NEW_TAG_PATTERN.matcher(since).find());
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/ch/njol/skript/lang/SkriptEventInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ public sealed class SkriptEventInfo<E extends SkriptEvent> extends StructureInfo
public final String name;

private ListeningBehavior listeningBehavior;
private String @Nullable [] description, examples, keywords, requiredPlugins;
private @Nullable String since, documentationID;

private String @Nullable [] description = null;
private String @Nullable [] examples = null;
private String @Nullable [] keywords = null;
private String @Nullable [] requiredPlugins = null;

private @Nullable String since = null;
private @Nullable String documentationID = null;

private final String id;

Expand Down

0 comments on commit 70b3ce6

Please sign in to comment.