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

🚀 Add Cancellable section #5691

Merged
merged 10 commits into from
Jul 1, 2024
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it might be good to have a common isCancellable method between this and EffCancelEvent

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

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
Loading