Skip to content

Commit

Permalink
🚀 Add Cancellable section (#5691)
Browse files Browse the repository at this point in the history
* Add Cancellable section

* Correct effect name EffCancelEvent

* Support EffCancelEvent extra hardcoded event

* Nothing, just better logic!

---------

Co-authored-by: sovdee <[email protected]>
Co-authored-by: Moderocky <[email protected]>
  • Loading branch information
3 people authored Jul 1, 2024
1 parent 27094a6 commit 55d7fdc
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main/java/ch/njol/skript/doc/HTMLGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
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.bukkit.event.block.BlockCanBuildEvent;
import org.eclipse.jdt.annotation.Nullable;
import org.skriptlang.skript.lang.entry.EntryData;
import org.skriptlang.skript.lang.entry.EntryValidator;
Expand Down Expand Up @@ -481,6 +484,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);
Expand Down Expand Up @@ -603,6 +609,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<? extends Event> event : info.events) {
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;
}
}
desc = handleIf(desc, "${if cancellable}", cancellable);
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();
// Fix duplicated IDs
Expand Down Expand Up @@ -719,6 +736,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);
Expand Down Expand Up @@ -821,6 +841,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)

Expand Down

0 comments on commit 55d7fdc

Please sign in to comment.