Skip to content

Commit

Permalink
add location_flagged, item_flagged, new location event meta
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 13, 2021
1 parent 12e90cb commit b34d6b5
Show file tree
Hide file tree
Showing 151 changed files with 190 additions and 170 deletions.
Expand Up @@ -22,7 +22,7 @@ public class EntityKnocksbackEntityScriptEvent extends BukkitScriptEvent impleme
//
// @Regex ^on [^\s]+ knocks back [^\s]+$
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
// @Switch with:<item> to only process the event when the item used to cause damage (in the damager's hand) is a specified item.
//
// @Plugin Paper
Expand Down
Expand Up @@ -20,7 +20,7 @@ public class EntityPathfindScriptEvent extends BukkitScriptEvent implements List
//
// @Regex ^on [^\s]+ pathfinds$
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
// @Switch to:<area> to only process the event if the entity is pathfinding into a specified area.
// @Switch at:<entity> to only process the event when the entity is pathfinding at a specified entity.
//
Expand Down
Expand Up @@ -18,7 +18,7 @@ public class ExperienceOrbMergeScriptEvent extends BukkitScriptEvent implements
//
// @Regex ^on experience orbs merge$
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Plugin Paper
//
Expand Down
Expand Up @@ -18,7 +18,7 @@ public class PlayerAbsorbsExperienceScriptEvent extends BukkitScriptEvent implem
//
// @Regex ^on player absorbs experience$
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Plugin Paper
//
Expand Down
Expand Up @@ -21,7 +21,7 @@ public class PlayerBeaconEffectScriptEvent extends BukkitScriptEvent implements
//
// @Regex ^on player beacon effect applied$
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Plugin Paper
//
Expand Down
Expand Up @@ -20,7 +20,7 @@ public class PlayerClicksFakeEntityScriptEvent extends BukkitScriptEvent impleme
//
// @Regex ^on player ([^\s]+ )?clicks fake entity$
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Plugin Paper
//
Expand Down
Expand Up @@ -17,7 +17,7 @@ public class PlayerSpectatesEntityScriptEvent extends BukkitScriptEvent implemen
//
// @Regex ^on player spectates [^\s]+$
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Plugin Paper
//
Expand Down
Expand Up @@ -17,7 +17,7 @@ public class PlayerStopsSpectatingScriptEvent extends BukkitScriptEvent implemen
//
// @Regex ^on player stops spectating( [^\s]+)?$
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Plugin Paper
//
Expand Down
Expand Up @@ -23,7 +23,7 @@ public class PreEntitySpawnScriptEvent extends BukkitScriptEvent implements List
//
// @Regex ^on [^\s]+ prespawns( because [^\s]+)?$
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Cancellable true
//
Expand Down
Expand Up @@ -18,7 +18,7 @@ public class ProjectileCollideScriptEvent extends BukkitScriptEvent implements L
//
// @Regex ^on [^\s]+ collides with [^\s]+$
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Plugin Paper
//
Expand Down
Expand Up @@ -21,7 +21,7 @@ public class TNTPrimesScriptEvent extends BukkitScriptEvent implements Listener
//
// @Regex ^on tnt primes$
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Plugin Paper
//
Expand Down
Expand Up @@ -5,6 +5,7 @@
import com.denizenscript.denizen.objects.notable.NotableManager;
import com.denizenscript.denizen.tags.BukkitTagContext;
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData;
import com.denizenscript.denizencore.flags.AbstractFlagTracker;
import com.denizenscript.denizencore.objects.core.ScriptTag;
import com.denizenscript.denizencore.utilities.Deprecations;
import com.denizenscript.denizencore.utilities.debugging.Debug;
Expand Down Expand Up @@ -47,6 +48,8 @@ public abstract class BukkitScriptEvent extends ScriptEvent {
//
// "<item>" or similar expects of course an ItemTag.
// You can use any valid item material type like "stick", or the name of an item script, or "item" as a catch-all, or "potion" for any potion item.
// Items can also be used with an "item_flagged" secondary prefix, so for an event that has "with:<item>", you can also do "with:item_flagged:<flag name>".
// For item matchers that aren't switches, this works similarly, like "on player consumes item_flagged:myflag:" (note that this is not a switch).
//
// "<inventory>" or similar expects of course an InventoryTag.
// You can use "inventory" as a catch-all, "note" to mean any noted inventory, the name of an inventory script,
Expand Down Expand Up @@ -174,6 +177,9 @@ public boolean couldMatchItem(String text) {
if (text.equals("item")) {
return true;
}
if (text.startsWith("item_flagged:")) {
return true;
}
if (MaterialTag.matches(text)) {
MaterialTag mat = MaterialTag.valueOf(text, CoreUtilities.noDebugContext);
if (mat == null || !mat.getMaterial().isItem()) {
Expand Down Expand Up @@ -412,7 +418,27 @@ public boolean runInCheck(ScriptPath path, Location location) {
return runInCheck(path, location, "in");
}

public boolean runLocationFlaggedCheck(ScriptPath path, String switchName, Location location) {
String flagged = path.switches.get(switchName);
if (flagged == null) {
return true;
}
if (location == null) {
return false;
}
AbstractFlagTracker tracker = new LocationTag(location).getFlagTracker();
for (String flag : CoreUtilities.split(flagged, '|')) {
if (!tracker.hasFlag(flag)) {
return false;
}
}
return true;
}

public boolean runInCheck(ScriptPath path, Location location, String innote) {
if (!runLocationFlaggedCheck(path, "location_flagged", location)) {
return false;
}
String inputText = path.switches.get(innote);
if (inputText == null) {
int index;
Expand Down Expand Up @@ -551,31 +577,13 @@ public boolean runPermissionCheck(ScriptPath path, String switchName, PlayerTag
return true;
}

// <--[language]
// @name Player Event Switches
// @group Script Events
// @description
// There are a few special switches available to any script event with a linked player.
//
// The "flagged:<flag name>" will limit the event to only fire when the player has the flag with the specified name.
// It can be used like "on player breaks block flagged:nobreak:" (that would be used alongside "- flag player nobreak").
//
// The "permission:<perm key>" will limit the event to only fire when the player has the specified permission key.
// It can be used like "on player breaks block permission:denizen.my.perm:"
//
// Note that these switches will be ignored for events that do not have a linked player.
// Be cautious with events that will only sometimes have a linked player.
//
// For multiple flag or permission requirements, just list them separated by '|' pipes, like "flagged:a|b|c".
// -->

public boolean runAutomaticPlayerSwitches(ScriptPath path) {
if (!path.switches.containsKey("flagged") && !path.switches.containsKey("permission")) {
return true;
}
BukkitScriptEntryData data = (BukkitScriptEntryData) getScriptEntryData();
if (!data.hasPlayer()) {
return true;
return false;
}
if (!runFlaggedCheck(path, data.getPlayer())) {
return false;
Expand Down Expand Up @@ -686,6 +694,14 @@ public boolean tryItem(ItemTag item, String comparedto) {
return false;
}
comparedto = CoreUtilities.toLowerCase(comparedto);
if (comparedto.startsWith("item_flagged:")) {
for (String flag : CoreUtilities.split(comparedto.substring("item_flagged:".length()), '|')) {
if (!item.getFlagTracker().hasFlag(flag)) {
return false;
}
}
return true;
}
if (comparedto.equals("item")) {
return true;
}
Expand Down
Expand Up @@ -22,7 +22,7 @@ public class BlockBuiltScriptEvent extends BukkitScriptEvent implements Listener
//
// @Group Block
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Cancellable true
//
Expand Down
Expand Up @@ -19,7 +19,7 @@ public class BlockBurnsScriptEvent extends BukkitScriptEvent implements Listener
//
// @Group Block
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Cancellable true
//
Expand Down
Expand Up @@ -25,7 +25,7 @@ public class BlockDispensesScriptEvent extends BukkitScriptEvent implements List
//
// @Group Block
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Cancellable true
//
Expand Down
Expand Up @@ -26,7 +26,7 @@ public class BlockExplodesScriptEvent extends BukkitScriptEvent implements Liste
//
// @Group Block
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Cancellable true
//
Expand Down
Expand Up @@ -19,7 +19,7 @@ public class BlockFadesScriptEvent extends BukkitScriptEvent implements Listener
//
// @Group Block
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Cancellable true
//
Expand Down
Expand Up @@ -20,7 +20,7 @@ public class BlockFallsScriptEvent extends BukkitScriptEvent implements Listener
//
// @Group Block
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Cancellable true
//
Expand Down
Expand Up @@ -19,7 +19,7 @@ public class BlockFormsScriptEvent extends BukkitScriptEvent implements Listener
//
// @Group Block
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Cancellable true
//
Expand Down
Expand Up @@ -21,7 +21,7 @@ public class BlockGrowsScriptEvent extends BukkitScriptEvent implements Listener
//
// @Group Block
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
// @Switch from:<age> to only process the event if the material started at a specific age.
// @Switch to:<age> to only process the event if the material ended at a specific age.
//
Expand Down
Expand Up @@ -20,7 +20,7 @@ public class BlockIgnitesScriptEvent extends BukkitScriptEvent implements Listen
//
// @Group Block
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
// @Switch cause:<cause> to only process the event when it came from a specified cause.
//
// @Cancellable true
Expand Down
Expand Up @@ -20,7 +20,7 @@ public class BlockPhysicsScriptEvent extends BukkitScriptEvent implements Listen
//
// @Group Block
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Warning This event may fire very rapidly.
//
Expand Down
Expand Up @@ -19,7 +19,7 @@ public class BlockSpreadsScriptEvent extends BukkitScriptEvent implements Listen
//
// @Group Block
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Cancellable true
//
Expand Down
Expand Up @@ -19,7 +19,7 @@ public class BrewingStandFueledScriptEvent extends BukkitScriptEvent implements
//
// @Group Block
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Cancellable true
//
Expand Down
Expand Up @@ -18,7 +18,7 @@ public class BrewsScriptEvent extends BukkitScriptEvent implements Listener {
//
// @Group Block
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Cancellable true
//
Expand Down
Expand Up @@ -21,7 +21,7 @@ public class CauldronLevelChangeScriptEvent extends BukkitScriptEvent implements
//
// @Group Block
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
// @Switch cause:<cause> to only process the event when it came from a specified cause.
//
// @Cancellable true
Expand Down
Expand Up @@ -21,7 +21,7 @@ public class FurnaceBurnsItemScriptEvent extends BukkitScriptEvent implements Li
//
// @Group Block
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Cancellable true
//
Expand Down
Expand Up @@ -21,7 +21,7 @@ public class FurnaceSmeltsItemScriptEvent extends BukkitScriptEvent implements L
//
// @Group Block
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Triggers when a furnace smelts an item.
//
Expand Down
Expand Up @@ -19,7 +19,7 @@ public class LeafDecaysScriptEvent extends BukkitScriptEvent implements Listener
//
// @Group Block
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Cancellable true
//
Expand Down
Expand Up @@ -21,7 +21,7 @@ public class LiquidSpreadScriptEvent extends BukkitScriptEvent implements Listen
//
// @Group Block
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Cancellable true
//
Expand Down
Expand Up @@ -19,7 +19,7 @@ public class NoteBlockPlaysNoteScriptEvent extends BukkitScriptEvent implements
//
// @Group Block
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
// @Switch instrument:<instrument> to only process the event if a specific instrument was played.
//
// @Cancellable true
Expand Down
Expand Up @@ -22,7 +22,7 @@ public class PistonExtendsScriptEvent extends BukkitScriptEvent implements Liste
//
// @Group Block
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Cancellable true
//
Expand Down
Expand Up @@ -22,7 +22,7 @@ public class PistonRetractsScriptEvent extends BukkitScriptEvent implements List
//
// @Group Block
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Cancellable true
//
Expand Down
Expand Up @@ -18,7 +18,7 @@ public class RedstoneScriptEvent extends BukkitScriptEvent implements Listener {
//
// @Group Block
//
// @Switch in:<area> to only process the event if it occurred within a specified area.
// @Location true
//
// @Warning This event fires very very rapidly!
//
Expand Down

0 comments on commit b34d6b5

Please sign in to comment.