From ba1306cdead234628932b9151cc784eaf84748c8 Mon Sep 17 00:00:00 2001 From: BerndiVader Date: Fri, 25 Jan 2019 20:25:32 +0100 Subject: [PATCH] unregister listeners on custom modules reload remove custom moduleclasses from their lists on reload --- src/main/java/me/blackvein/quests/Quests.java | 47 +++++++++++++++---- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/src/main/java/me/blackvein/quests/Quests.java b/src/main/java/me/blackvein/quests/Quests.java index 986d18dc2..dbd8c0ecd 100644 --- a/src/main/java/me/blackvein/quests/Quests.java +++ b/src/main/java/me/blackvein/quests/Quests.java @@ -64,6 +64,7 @@ import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.entity.Tameable; +import org.bukkit.event.HandlerList; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; @@ -230,15 +231,44 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener public List getCustomRequirements() { return customRequirements; } + + public Optional getCustomRequirement(String class_name) { + int size=customRequirements.size(); + for(int i1=0;i1 getCustomRewards() { return customRewards; } + public Optional getCustomReward(String class_name) { + int size=customRewards.size(); + for(int i1=0;i1 getCustomObjectives() { return customObjectives; } + public Optional getCustomObjective(String class_name) { + int size=customObjectives.size(); + for(int i1=0;i1 getQuests() { return quests; } @@ -528,9 +558,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener Class requirementClass = c.asSubclass(CustomRequirement.class); Constructor cstrctr = requirementClass.getConstructor(); CustomRequirement requirement = cstrctr.newInstance(); - if (customRequirements.contains(requirement)) { - customRequirements.remove(requirement); - } + Optionaloo=getCustomRequirement(requirement.getClass().getName()); + if (oo.isPresent()) customRequirements.remove(oo.get()); customRequirements.add(requirement); String name = requirement.getName() == null ? "[" + jar.getName() + "]" : requirement.getName(); String author = requirement.getAuthor() == null ? "[Unknown]" : requirement.getAuthor(); @@ -540,9 +569,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener Class rewardClass = c.asSubclass(CustomReward.class); Constructor cstrctr = rewardClass.getConstructor(); CustomReward reward = cstrctr.newInstance(); - if (customRewards.contains(reward)) { - customRewards.remove(reward); - } + Optionaloo=getCustomReward(reward.getClass().getName()); + if (oo.isPresent()) customRewards.remove(oo.get()); customRewards.add(reward); String name = reward.getName() == null ? "[" + jar.getName() + "]" : reward.getName(); String author = reward.getAuthor() == null ? "[Unknown]" : reward.getAuthor(); @@ -552,8 +580,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener Class objectiveClass = c.asSubclass(CustomObjective.class); Constructor cstrctr = objectiveClass.getConstructor(); CustomObjective objective = cstrctr.newInstance(); - if (customObjectives.contains(objective)) { - customObjectives.remove(objective); + Optionaloo=getCustomObjective(objective.getClass().getName()); + if (oo.isPresent()) { + HandlerList.unregisterAll(oo.get()); + customObjectives.remove(oo.get()); } customObjectives.add(objective); String name = objective.getName() == null ? "[" + jar.getName() + "]" : objective.getName(); @@ -738,6 +768,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener public void reloadQuests() { quests.clear(); events.clear(); + loadQuests(); loadData(); loadEvents();