Skip to content

Commit

Permalink
Add config toggle for whether to listen to cancelled events by defaul…
Browse files Browse the repository at this point in the history
…t. (#6680)

* Add config toggle

* Update src/main/resources/config.sk

Co-authored-by: _tud <[email protected]>

---------

Co-authored-by: _tud <[email protected]>
  • Loading branch information
sovdeeth and UnderscoreTud authored Jul 1, 2024
1 parent 1d587d4 commit 1a42f52
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/main/java/ch/njol/skript/SkriptConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ public static String formatDate(final long timestamp) {
}
});

/**
* Determines whether `on &lt;event&gt;` will be triggered by cancelled events or not.
*/
public static final Option<Boolean> listenCancelledByDefault = new Option<>("listen to cancelled events by default", false)
.optional(true);


/**
* Maximum number of digits to display after the period for floats and doubles
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/ch/njol/skript/lang/SkriptEventInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package ch.njol.skript.lang;

import ch.njol.skript.SkriptAPIException;
import ch.njol.skript.SkriptConfig;
import org.bukkit.event.Event;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.eclipse.jdt.annotation.Nullable;
Expand Down Expand Up @@ -74,8 +75,8 @@ public SkriptEventInfo(String name, String[] patterns, Class<E> eventClass, Stri
// uses the name without 'on ' or '*'
this.id = "" + name.toLowerCase(Locale.ENGLISH).replaceAll("[#'\"<>/&]", "").replaceAll("\\s+", "_");

// default listening behavior should be to listen to uncancelled events
this.listeningBehavior = ListeningBehavior.UNCANCELLED;
// default listening behavior should be dependent on config setting
this.listeningBehavior = SkriptConfig.listenCancelledByDefault.value() ? ListeningBehavior.ANY : ListeningBehavior.UNCANCELLED;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/config.sk
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ plugin priority: high
# - effects 'remove ... from drops'/'clear drops': Drops added by other plugins are not removed => increase priority
# Skript removes drops it shouldn't => decrease priority or specify which item types to remove

listen to cancelled events by default: false
# Determines whether `on <event>` will be triggered by all events (true) or only uncancelled events (false).
# The default is false, which maintains traditional Skript behavior.

number accuracy: 2
# How many digits should be displayed after the dot at maximum when displaying numbers.
Expand Down

0 comments on commit 1a42f52

Please sign in to comment.