From fb90f45784cc2c331568e5fc2f4b667962468f88 Mon Sep 17 00:00:00 2001 From: Ayham Al-Ali <20037329+AyhamAl-Ali@users.noreply.github.com> Date: Thu, 11 May 2023 00:23:12 +0300 Subject: [PATCH 1/4] Add Cancellable section --- .../ch/njol/skript/doc/HTMLGenerator.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/ch/njol/skript/doc/HTMLGenerator.java b/src/main/java/ch/njol/skript/doc/HTMLGenerator.java index 0da3679904c..13878e9cb41 100644 --- a/src/main/java/ch/njol/skript/doc/HTMLGenerator.java +++ b/src/main/java/ch/njol/skript/doc/HTMLGenerator.java @@ -36,6 +36,8 @@ import com.google.common.collect.Lists; import com.google.common.io.Files; import org.apache.commons.lang.StringUtils; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; import org.eclipse.jdt.annotation.Nullable; import org.skriptlang.skript.lang.entry.EntryData; import org.skriptlang.skript.lang.entry.EntryValidator; @@ -481,6 +483,9 @@ private String generateAnnotated(String descTemp, SyntaxElementInfo info, @Nu } desc = desc.replace("${element.id}", ID); + // Cancellable + desc = handleIf(desc, "${if cancellable}", false); + // Events Events events = c.getAnnotation(Events.class); desc = handleIf(desc, "${if events}", events != null); @@ -603,6 +608,17 @@ private String generateEvent(String descTemp, SkriptEventInfo info, @Nullable String[] keywords = info.getKeywords(); desc = desc.replace("${element.keywords}", keywords == null ? "" : Joiner.on(", ").join(keywords)); + // Cancellable + boolean cancellable = false; + for (Class event : info.events) { + if (Cancellable.class.isAssignableFrom(event)) { + cancellable = true; // let's assume all are cancellable otherwise EffCancellable would do the rest in action + break; + } + } + desc = handleIf(desc, "${if cancellable}", cancellable); + desc = desc.replace("${element.cancellable}", !cancellable ? "" : "Yes"); + // Documentation ID String ID = info.getDocumentationID() != null ? info.getDocumentationID() : info.getId(); // Fix duplicated IDs @@ -717,6 +733,9 @@ private String generateClass(String descTemp, ClassInfo info, @Nullable Strin } desc = desc.replace("${element.id}", ID); + // Cancellable + desc = handleIf(desc, "${if cancellable}", false); + // Events Events events = c.getAnnotation(Events.class); desc = handleIf(desc, "${if events}", events != null); @@ -816,6 +835,9 @@ private String generateFunction(String descTemp, JavaFunction info) { // Documentation ID desc = desc.replace("${element.id}", info.getName()); + // Cancellable + desc = handleIf(desc, "${if cancellable}", false); + // Events desc = handleIf(desc, "${if events}", false); // Functions do not require events nor plugins (at time writing this) From 2880466ee0820916552764e9d105e6968b9a03f9 Mon Sep 17 00:00:00 2001 From: Ayham Al-Ali <20037329+AyhamAl-Ali@users.noreply.github.com> Date: Thu, 11 May 2023 00:25:03 +0300 Subject: [PATCH 2/4] Correct effect name EffCancelEvent --- src/main/java/ch/njol/skript/doc/HTMLGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/doc/HTMLGenerator.java b/src/main/java/ch/njol/skript/doc/HTMLGenerator.java index 13878e9cb41..222a65f3f5a 100644 --- a/src/main/java/ch/njol/skript/doc/HTMLGenerator.java +++ b/src/main/java/ch/njol/skript/doc/HTMLGenerator.java @@ -612,7 +612,7 @@ private String generateEvent(String descTemp, SkriptEventInfo info, @Nullable boolean cancellable = false; for (Class event : info.events) { if (Cancellable.class.isAssignableFrom(event)) { - cancellable = true; // let's assume all are cancellable otherwise EffCancellable would do the rest in action + cancellable = true; // let's assume all are cancellable otherwise EffCancelEvent would do the rest in action break; } } From 8d8270c8e32dd6487b62fd70acf7555a0e286c8a Mon Sep 17 00:00:00 2001 From: Ayham Al-Ali <20037329+AyhamAl-Ali@users.noreply.github.com> Date: Thu, 21 Sep 2023 23:01:26 +0300 Subject: [PATCH 3/4] Support EffCancelEvent extra hardcoded event --- src/main/java/ch/njol/skript/doc/HTMLGenerator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/doc/HTMLGenerator.java b/src/main/java/ch/njol/skript/doc/HTMLGenerator.java index 222a65f3f5a..ba618f94e88 100644 --- a/src/main/java/ch/njol/skript/doc/HTMLGenerator.java +++ b/src/main/java/ch/njol/skript/doc/HTMLGenerator.java @@ -38,6 +38,7 @@ import org.apache.commons.lang.StringUtils; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; +import org.bukkit.event.block.BlockCanBuildEvent; import org.eclipse.jdt.annotation.Nullable; import org.skriptlang.skript.lang.entry.EntryData; import org.skriptlang.skript.lang.entry.EntryValidator; @@ -611,7 +612,7 @@ private String generateEvent(String descTemp, SkriptEventInfo info, @Nullable // Cancellable boolean cancellable = false; for (Class event : info.events) { - if (Cancellable.class.isAssignableFrom(event)) { + if (Cancellable.class.isAssignableFrom(event) || BlockCanBuildEvent.class.isAssignableFrom(event)) { cancellable = true; // let's assume all are cancellable otherwise EffCancelEvent would do the rest in action break; } From 45732072a80024fc5d831ae848e9c114c526ae06 Mon Sep 17 00:00:00 2001 From: Ayham Al-Ali <20037329+AyhamAl-Ali@users.noreply.github.com> Date: Fri, 22 Sep 2023 01:46:32 +0300 Subject: [PATCH 4/4] Nothing, just better logic! --- src/main/java/ch/njol/skript/doc/HTMLGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/doc/HTMLGenerator.java b/src/main/java/ch/njol/skript/doc/HTMLGenerator.java index ba618f94e88..08ffc3f75d6 100644 --- a/src/main/java/ch/njol/skript/doc/HTMLGenerator.java +++ b/src/main/java/ch/njol/skript/doc/HTMLGenerator.java @@ -618,7 +618,7 @@ private String generateEvent(String descTemp, SkriptEventInfo info, @Nullable } } desc = handleIf(desc, "${if cancellable}", cancellable); - desc = desc.replace("${element.cancellable}", !cancellable ? "" : "Yes"); + desc = desc.replace("${element.cancellable}", cancellable ? "Yes" : ""); // if not cancellable the section is hidden // Documentation ID String ID = info.getDocumentationID() != null ? info.getDocumentationID() : info.getId();