diff --git a/plugin/src/main/java/com/denizenscript/denizen/events/entity/AreaEnterExitScriptEvent.java b/plugin/src/main/java/com/denizenscript/denizen/events/entity/AreaEnterExitScriptEvent.java index 56555ffdd9..7ae638b0ed 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/events/entity/AreaEnterExitScriptEvent.java +++ b/plugin/src/main/java/com/denizenscript/denizen/events/entity/AreaEnterExitScriptEvent.java @@ -5,6 +5,8 @@ import com.denizenscript.denizen.objects.notable.NotableManager; import com.denizenscript.denizen.utilities.debugging.Debug; import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData; +import com.denizenscript.denizencore.flags.AbstractFlagTracker; +import com.denizenscript.denizencore.flags.FlaggableObject; import com.denizenscript.denizencore.objects.ObjectTag; import com.denizenscript.denizencore.objects.core.ElementTag; import com.denizenscript.denizencore.objects.notable.Notable; @@ -103,6 +105,12 @@ else if (areaName.equals("ellipsoid")) { return false; } } + else if (areaName.startsWith("area_flagged:")) { + AbstractFlagTracker tracker = ((FlaggableObject) area).getFlagTracker(); + if (tracker == null || !tracker.hasFlag(areaName.substring("area_flagged:".length()))) { + return false; + } + } else { if (!runGenericCheck(areaName, area.getNoteName())) { return false; @@ -184,6 +192,7 @@ public void init() { boolean needsMatchers = false; HashSet exacts = new HashSet<>(); List matchList = new ArrayList<>(); + HashSet flags = new HashSet<>(); onlyTrackPlayers = true; for (ScriptPath path : eventPaths) { if (!path.eventArgLowerAt(0).equals("player")) { @@ -193,10 +202,7 @@ public void init() { if (area.equals("notable")) { area = path.eventArgLowerAt(3); } - if (area.equals("cuboid")) { - doTrackAll = true; - } - else if (area.equals("ellipsoid")) { + if (area.equals("cuboid") || area.equals("ellipsoid") || area.equals("polygon")) { doTrackAll = true; } MatchHelper matcher = createMatcher(area); @@ -210,14 +216,19 @@ else if (!needsMatchers && (matcher instanceof ExactMatchHelper)) { needsMatchers = true; } matchList.add(matcher); + if (area.startsWith("area_flagged:")) { + flags.add(CoreUtilities.toLowerCase(area.substring("area_flagged:".length()))); + } } exactTracked = needsMatchers ? null : exacts.toArray(new String[0]); matchers = needsMatchers ? matchList.toArray(new MatchHelper[0]) : null; + flagTracked = flags.size() > 0 ? flags.toArray(new String[0]) : null; registerCorrectClass(); } public boolean doTrackAll = false; public String[] exactTracked = null; + public String[] flagTracked = null; public MatchHelper[] matchers = null; public boolean onlyTrackPlayers = true; public static HashMap> entitiesInArea = new HashMap<>(); @@ -236,13 +247,23 @@ public void cancellationChanged() { super.cancellationChanged(); } - public boolean anyMatch(String name) { + public boolean anyMatch(String name, FlaggableObject flaggable) { if (doTrackAll) { return true; } - for (MatchHelper matcher : matchers) { - if (matcher.doesMatch(name)) { - return true; + if (matchers != null) { + for (MatchHelper matcher : matchers) { + if (matcher.doesMatch(name)) { + return true; + } + } + } + if (flagTracked != null) { + for (String flag : flagTracked) { + AbstractFlagTracker tracker = flaggable.getFlagTracker(); + if (tracker != null && tracker.hasFlag(flag)) { + return true; + } } } return false; @@ -276,19 +297,19 @@ public void processNewPosition(EntityTag entity, Location pos, Event eventCause) return; } HashSet inAreas = entitiesInArea.get(entity.getUUID()); - if (doTrackAll || matchers != null) { + if (doTrackAll || matchers != null || flagTracked != null) { for (CuboidTag cuboid : NotableManager.getAllType(CuboidTag.class)) { - if (anyMatch(cuboid.noteName)) { + if (anyMatch(cuboid.noteName, cuboid)) { processSingle(cuboid, entity, inAreas, pos, eventCause); } } for (EllipsoidTag ellipsoid : NotableManager.getAllType(EllipsoidTag.class)) { - if (anyMatch(ellipsoid.noteName)) { + if (anyMatch(ellipsoid.noteName, ellipsoid)) { processSingle(ellipsoid, entity, inAreas, pos, eventCause); } } for (PolygonTag polygon : NotableManager.getAllType(PolygonTag.class)) { - if (anyMatch(polygon.noteName)) { + if (anyMatch(polygon.noteName, polygon)) { processSingle(polygon, entity, inAreas, pos, eventCause); } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/InventoryTag.java b/plugin/src/main/java/com/denizenscript/denizen/objects/InventoryTag.java index fff94da6cf..047a37280c 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/InventoryTag.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/InventoryTag.java @@ -423,7 +423,7 @@ public static boolean matches(String arg) { if (ScriptRegistry.containsScript(tid, InventoryScriptContainer.class)) { return true; } - if (NotableManager.isType(tid, InventoryTag.class)) { + if (NotableManager.getSavedObject(tid) instanceof InventoryTag) { return true; } for (String idType : idTypes) { diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/notable/NotableManager.java b/plugin/src/main/java/com/denizenscript/denizen/objects/notable/NotableManager.java index 29bb95b0ea..fbc8d3b43e 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/notable/NotableManager.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/notable/NotableManager.java @@ -19,10 +19,7 @@ import java.io.File; import java.io.IOException; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; @@ -38,8 +35,8 @@ public NotableManager() { } public static HashMap notableObjects = new HashMap<>(); - public static HashMap typeTracker = new HashMap<>(); public static HashMap reverseObjects = new HashMap<>(); + public static HashMap> notesByType = new HashMap<>(); public static boolean isSaved(Notable object) { return reverseObjects.containsKey(object); @@ -61,18 +58,13 @@ public static String getSavedId(Notable object) { return reverseObjects.get(object); } - public static boolean isType(String id, Class type) { - Class trackedType = typeTracker.get(CoreUtilities.toLowerCase(id)); - return trackedType == type; - } - public static void saveAs(Notable object, String id) { if (object == null) { return; } notableObjects.put(CoreUtilities.toLowerCase(id), object); reverseObjects.put(object, CoreUtilities.toLowerCase(id)); - typeTracker.put(CoreUtilities.toLowerCase(id), object.getClass()); + notesByType.get(object.getClass()).add(object); } public static Notable remove(String id) { @@ -82,7 +74,7 @@ public static Notable remove(String id) { } notableObjects.remove(CoreUtilities.toLowerCase(id)); reverseObjects.remove(obj); - typeTracker.remove(CoreUtilities.toLowerCase(id)); + notesByType.get(obj.getClass()).remove(obj); return obj; } @@ -90,19 +82,11 @@ public static void remove(Notable obj) { String id = reverseObjects.get(obj); notableObjects.remove(CoreUtilities.toLowerCase(id)); reverseObjects.remove(obj); - typeTracker.remove(CoreUtilities.toLowerCase(id)); + notesByType.get(obj.getClass()).remove(obj); } - public static List getAllType(Class type) { - List objects = new ArrayList<>(); - for (Map.Entry notable : notableObjects.entrySet()) { - // dB.log(notable.toString()); - if (isType(notable.getKey(), type)) { - objects.add((T) notable.getValue()); - } - } - - return objects; + public static Set getAllType(Class type) { + return (Set) notesByType.get(type); } /** @@ -110,7 +94,9 @@ public static List getAllType(Class type) { */ private static void _recallNotables() { notableObjects.clear(); - typeTracker.clear(); + for (Set set : notesByType.values()) { + set.clear(); + } reverseObjects.clear(); // Find each type of notable for (String key : Denizen.getInstance().notableManager().getNotables().getKeys(false)) { @@ -222,6 +208,7 @@ public static void registerWithNotableManager(Class notable) { String note = method.getAnnotation(Note.class).value(); objects.put(notable, note); reverse_objects.put(note, notable); + notesByType.put(notable, new HashSet<>()); } } }