Fix event manager bug

Former-commit-id: dad544a7013489f623b6920b0227df15d9372a9a [formerly 79a55d64ad1cf20d2b8ec9269b61ee5729fb8390]
Former-commit-id: 4289c87324836ef42add8b106d5d0e8128c52019
This commit is contained in:
Ghost_chu committed 2019-09-13 10:08:34 +08:00
1 parent bd527fa093
commit fa28f55942
1 file changed
+19 -18
@@ -23,7 +23,7 @@ import java.util.logging.Level;
* The EventManager for QuickShop protection caller.
*/
public class QSEventManager {
private HashMap<String, Set<PluginEventFilterContainer>> containerSet = new HashMap<>();
private HashMap<String, Set<PluginEventFilterContainer>> filterSet = new HashMap<>();
private QuickShop plugin;
public QSEventManager(@NotNull QuickShop plugin) {
@@ -50,13 +50,13 @@ public class QSEventManager {
plugin.getLogger().warning("Event filter: " + filterString + " plugin name invalid.");
continue;
}
containerSet.putIfAbsent(cPlugin, new HashSet<>());
Set<PluginEventFilterContainer> containers = containerSet.get(cPlugin);
filterSet.putIfAbsent(cPlugin, new HashSet<>());
Set<PluginEventFilterContainer> containers = filterSet.get(cPlugin);
boolean result = containers.add(new PluginEventFilterContainer(cListener, cEvent));
if (!result) {
plugin.getLogger().warning("Event filter: " + filterString + " duplicated.");
} else {
containerSet.put(cPlugin, containers);
filterSet.put(cPlugin, containers);
}
}
}
@@ -74,23 +74,24 @@ public class QSEventManager {
Util.debugLog("Skipping " + registration.getPlugin().getName() + " cause plugin is unloaded.");
continue;
}
Set<PluginEventFilterContainer> containers = containerSet.get(registration.getPlugin().getName());
Set<PluginEventFilterContainer> containers = filterSet.get(registration.getPlugin().getName());
if (containers == null) {
Util.debugLog("Container is null, skipping...");
continue;
}
boolean cancelPluginCalling = false;
for (PluginEventFilterContainer disabledContainer : containers) {
if (disabledContainer.getListener().equals(registration.getListener().getClass().getName())) {
if (disabledContainer.getEvent().equals(event.getClass().getName())) {
Util.debugLog("Skipping event " + event.getClass().getName() + " calling for plugin " + registration.getPlugin().getName() + "'s listener " + registration.getListener().getClass().getName());
cancelPluginCalling = true;
break;
Util.debugLog("Container is null, direct call events...");
}else{
Util.debugLog("Detected the filter for this plugin, checking...");
boolean cancelPluginCalling = false;
for (PluginEventFilterContainer disabledContainer : containers) {
if (disabledContainer.getListener().equals(registration.getListener().getClass().getName())) {
if (disabledContainer.getEvent().equals(event.getClass().getName())) {
Util.debugLog("Skipping event " + event.getClass().getName() + " calling for plugin " + registration.getPlugin().getName() + "'s listener " + registration.getListener().getClass().getName());
cancelPluginCalling = true;
break;
}
}
}
}
if(cancelPluginCalling) {
continue; //Skip this listener calling+
if(cancelPluginCalling) {
continue; //Skip this listener calling+
}
}
Util.debugLog("Calling event " + event.getClass().getName() + " calling for plugin " + registration.getPlugin().getName() + "'s listener " + registration.getListener().getClass().getName());
try {