From e7c05d7ee33f9391b1946cac3f2dc228ab2b20d1 Mon Sep 17 00:00:00 2001 From: Alex 'mcmonkey' Goodwin Date: Sat, 14 Nov 2020 23:43:38 -0800 Subject: [PATCH] delete legacy flag smart event --- .../com/denizenscript/denizen/Denizen.java | 1 - .../denizen/events/core/FlagSmartEvent.java | 58 ------- .../denizen/flags/FlagManager.java | 147 ------------------ 3 files changed, 206 deletions(-) delete mode 100644 plugin/src/main/java/com/denizenscript/denizen/events/core/FlagSmartEvent.java diff --git a/plugin/src/main/java/com/denizenscript/denizen/Denizen.java b/plugin/src/main/java/com/denizenscript/denizen/Denizen.java index 98dc301b9a..af1eaf520e 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/Denizen.java +++ b/plugin/src/main/java/com/denizenscript/denizen/Denizen.java @@ -337,7 +337,6 @@ public void onEnable() { CommonRegistries.registerMainTagHandlers(); eventManager = new OldEventManager(); // Register all the legacy 'Core' SmartEvents. - OldEventManager.registerSmartEvent(new FlagSmartEvent()); OldEventManager.registerSmartEvent(new NPCNavigationSmartEvent()); // Register all the modern script events ScriptEventRegistry.registerMainEvents(); diff --git a/plugin/src/main/java/com/denizenscript/denizen/events/core/FlagSmartEvent.java b/plugin/src/main/java/com/denizenscript/denizen/events/core/FlagSmartEvent.java deleted file mode 100644 index 0cf2f406de..0000000000 --- a/plugin/src/main/java/com/denizenscript/denizen/events/core/FlagSmartEvent.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.denizenscript.denizen.events.core; - -import com.denizenscript.denizen.utilities.debugging.Debug; -import com.denizenscript.denizencore.events.OldSmartEvent; -import org.bukkit.event.Listener; - -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Handler event, actual events are fired in FlagManager.java - */ -public class FlagSmartEvent implements OldSmartEvent, Listener { - - /////////////////// - // SMARTEVENT METHODS - /////////////// - - @Override - public boolean shouldInitialize(Set events) { - - // Loop through event names from loaded world script events - for (String event : events) { - - // Use a regex pattern to narrow down matches - Matcher m = Pattern.compile("on ((player|npc|server) )?flag( \\w+)? (cleared|changed|expires)", Pattern.CASE_INSENSITIVE) - .matcher(event); - - if (m.matches()) { - Debug.echoError("You are using flag events ('" + event + "'). These are only available for experimental dev reasons, and should ABSOLUTELY NOT be used in any live scripts."); - return true; - } - } - return false; - } - - @Override - public void _initialize() { - active = true; - Debug.log("Loaded Flag SmartEvent."); - } - - @Override - public void breakDown() { - active = false; - } - - ////////////// - // MECHANICS - /////////// - - static boolean active = false; - - public static boolean isActive() { - return active; - } -} diff --git a/plugin/src/main/java/com/denizenscript/denizen/flags/FlagManager.java b/plugin/src/main/java/com/denizenscript/denizen/flags/FlagManager.java index 982804b7d5..adfc74448e 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/flags/FlagManager.java +++ b/plugin/src/main/java/com/denizenscript/denizen/flags/FlagManager.java @@ -4,13 +4,9 @@ import com.denizenscript.denizen.objects.NPCTag; import com.denizenscript.denizen.objects.PlayerTag; import com.denizenscript.denizen.utilities.DenizenAPI; -import com.denizenscript.denizen.utilities.depends.Depends; import com.denizenscript.denizencore.objects.*; -import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; import com.denizenscript.denizen.Denizen; -import com.denizenscript.denizen.events.core.FlagSmartEvent; import com.denizenscript.denizencore.DenizenCore; -import com.denizenscript.denizencore.events.OldEventManager; import com.denizenscript.denizencore.objects.core.DurationTag; import com.denizenscript.denizencore.objects.core.ElementTag; import com.denizenscript.denizencore.objects.core.ListTag; @@ -222,52 +218,11 @@ public Value get(int index) { public void clear() { String OldOwner = flagOwner; String OldName = flagName; - ObjectTag OldValue = FlagSmartEvent.isActive() ? (value.size() > 1 - ? value.asList() - : value.size() == 1 ? new ElementTag(value.get(0).asString()) : new ElementTag("null")) : null; denizen.getSaves().set(flagPath, null); denizen.getSaves().set(flagPath + "-expiration", null); valid = false; rebuild(); - - if (FlagSmartEvent.isActive()) { - List world_script_events = new ArrayList<>(); - - Map context = new HashMap<>(); - PlayerTag player = null; - if (PlayerTag.matches(OldOwner)) { - player = PlayerTag.valueOf(OldOwner, CoreUtilities.basicContext); - } - NPCTag npc = null; - if (Depends.citizens != null && NPCTag.matches(OldOwner)) { - npc = NPCTag.valueOf(OldOwner, CoreUtilities.basicContext); - } - - String type; - - if (player != null) { - type = "player"; - } - else if (npc != null) { - type = "npc"; - } - else { - type = "server"; - } - world_script_events.add(type + " flag cleared"); - world_script_events.add(type + " flag " + OldName + " cleared"); - - context.put("owner", new ElementTag(OldOwner)); - context.put("name", new ElementTag(OldName)); - context.put("type", new ElementTag(type)); - context.put("old_value", OldValue); - - world_script_events.add("flag cleared"); - - OldEventManager.doEvents(world_script_events, - new BukkitScriptEntryData(player, npc), context); - } } /** @@ -469,15 +424,6 @@ public int size() { * if you are extending the usage of Flags yourself. */ public void save() { - String oldOwner = flagOwner; - String oldName = flagName; - ObjectTag oldValue = null; - if (FlagSmartEvent.isActive()) { - ListTag oldValueList = value.asList(); - oldValue = oldValueList.size() > 1 ? oldValueList - : oldValueList.size() == 1 ? new ElementTag(oldValueList.get(0)) : new ElementTag("null"); - } - if (value.values != null) { denizen.getSaves().set(flagPath, value.values); } @@ -485,52 +431,6 @@ public void save() { denizen.getSaves().set(flagPath, value.size == 0 ? null : value.firstValue); } denizen.getSaves().set(flagPath + "-expiration", (expiration > 0 ? expiration : null)); - - if (FlagSmartEvent.isActive()) { - List world_script_events = new ArrayList<>(); - - Map context = new HashMap<>(); - PlayerTag player = null; - if (PlayerTag.matches(oldOwner)) { - player = PlayerTag.valueOf(oldOwner, CoreUtilities.basicContext); - } - NPCTag npc = null; - if (Depends.citizens != null && NPCTag.matches(oldOwner)) { - npc = NPCTag.valueOf(oldOwner, CoreUtilities.basicContext); - } - EntityTag entity = null; - if (EntityTag.matches(oldOwner)) { - entity = EntityTag.valueOf(oldOwner, CoreUtilities.basicContext); - } - - String type; - - if (player != null) { - type = "player"; - } - else if (npc != null) { - type = "npc"; - } - else if (entity != null) { - type = "entity"; - } - else { - type = "server"; - } - world_script_events.add(type + " flag changed"); - world_script_events.add(type + " flag " + oldName + " changed"); - - context.put("owner", new ElementTag(oldOwner)); - context.put("name", new ElementTag(oldName)); - context.put("type", new ElementTag(type)); - context.put("old_value", oldValue); - - world_script_events.add("flag changed"); - - OldEventManager.doEvents(world_script_events, - new BukkitScriptEntryData(player, npc), context); - } - } @Override @@ -549,58 +449,11 @@ public boolean checkExpired() { if (expiration > 1 && expiration < DenizenCore.currentTimeMillis) { String oldOwner = flagOwner; String oldName = flagName; - ObjectTag oldValue = FlagSmartEvent.isActive() ? (value.size() > 1 - ? value.asList() - : value.size() == 1 ? new ElementTag(value.get(0).asString()) : new ElementTag("null")) : null; denizen.getSaves().set(flagPath + "-expiration", null); denizen.getSaves().set(flagPath, null); valid = false; rebuild(); //dB.log('\'' + flagName + "' has expired! " + flagPath); - if (FlagSmartEvent.isActive()) { - List world_script_events = new ArrayList<>(); - - Map context = new HashMap<>(); - PlayerTag player = null; - if (PlayerTag.matches(oldOwner)) { - player = PlayerTag.valueOf(oldOwner, CoreUtilities.basicContext); - } - NPCTag npc = null; - if (Depends.citizens != null && NPCTag.matches(oldOwner)) { - npc = NPCTag.valueOf(oldOwner, CoreUtilities.basicContext); - } - EntityTag entity = null; - if (EntityTag.matches(oldOwner)) { - entity = EntityTag.valueOf(oldOwner, CoreUtilities.basicContext); - } - - String type; - - if (player != null) { - type = "player"; - } - else if (npc != null) { - type = "npc"; - } - else if (entity != null) { - type = "entity"; - } - else { - type = "server"; - } - world_script_events.add(type + " flag expires"); - world_script_events.add(type + " flag " + oldName + " expires"); - - context.put("owner", new ElementTag(oldOwner)); - context.put("name", new ElementTag(oldName)); - context.put("type", new ElementTag(type)); - context.put("old_value", oldValue); - - world_script_events.add("flag expires"); - - OldEventManager.doEvents(world_script_events, - new BukkitScriptEntryData(player, npc), context); - } return true; } }