From e92cb8e67a1d3e63fb744d54639b012efdd708c4 Mon Sep 17 00:00:00 2001 From: Indyuce Date: Fri, 24 Dec 2021 15:20:47 +0100 Subject: [PATCH] mmocoreManager code cleanup --- .../java/net/Indyuce/mmocore/MMOCore.java | 56 ++++++------ .../mmocore/api/player/PlayerData.java | 31 +++++-- .../api/player/profess/PlayerClass.java | 4 +- .../player/profess/event/EventTrigger.java | 17 ++-- .../profess/event/EventTriggerHandler.java | 6 ++ .../mmocore/api/player/social/Party.java | 4 +- .../command/rpg/ReloadCommandTreeNode.java | 2 +- .../Indyuce/mmocore/experience/ExpCurve.java | 5 +- .../provider/ExperienceDispenser.java | 10 ++- .../provider/MainExperienceDispenser.java | 2 +- .../ProfessionExperienceDispenser.java | 2 +- .../source/type/ExperienceSource.java | 2 +- .../mmocore/manager/AttributeManager.java | 13 ++- .../Indyuce/mmocore/manager/ClassManager.java | 27 +++--- .../mmocore/manager/DropTableManager.java | 12 ++- .../mmocore/manager/LootChestManager.java | 11 ++- .../Indyuce/mmocore/manager/MMOManager.java | 7 -- .../Indyuce/mmocore/manager/QuestManager.java | 12 ++- .../Indyuce/mmocore/manager/SkillManager.java | 54 ++++++------ .../data/mysql/MySQLPlayerDataManager.java | 19 +++-- .../data/yaml/YAMLPlayerDataManager.java | 15 ++-- .../manager/profession/AlchemyManager.java | 49 +++++++---- .../{ => profession}/CustomBlockManager.java | 22 ++--- .../manager/profession/EnchantManager.java | 38 ++++++--- .../profession/ExperienceSourceManager.java | 5 +- .../manager/profession/FishingManager.java | 40 ++++----- .../manager/profession/ProfessionManager.java | 85 +++++++++---------- .../manager/profession/SmithingManager.java | 55 +++++++----- .../profession/SpecificProfessionManager.java | 23 +++++ .../mmocore/manager/social/PartyManager.java | 17 ++-- 30 files changed, 359 insertions(+), 286 deletions(-) delete mode 100644 src/main/java/net/Indyuce/mmocore/manager/MMOManager.java rename src/main/java/net/Indyuce/mmocore/manager/{ => profession}/CustomBlockManager.java (93%) create mode 100644 src/main/java/net/Indyuce/mmocore/manager/profession/SpecificProfessionManager.java diff --git a/src/main/java/net/Indyuce/mmocore/MMOCore.java b/src/main/java/net/Indyuce/mmocore/MMOCore.java index 039c0fa7..2d7dc82c 100644 --- a/src/main/java/net/Indyuce/mmocore/MMOCore.java +++ b/src/main/java/net/Indyuce/mmocore/MMOCore.java @@ -70,7 +70,6 @@ public class MMOCore extends LuminePlugin { public final SkillManager skillManager = new SkillManager(); public final ClassManager classManager = new ClassManager(); public final DropTableManager dropTableManager = new DropTableManager(); - public final CustomBlockManager mineManager = new CustomBlockManager(); public final BoosterManager boosterManager = new BoosterManager(); public final AttributeManager attributeManager = new AttributeManager(); public final PartyManager partyManager = new PartyManager(); @@ -79,9 +78,8 @@ public class MMOCore extends LuminePlugin { public final net.Indyuce.mmocore.manager.ExperienceManager experience = new net.Indyuce.mmocore.manager.ExperienceManager(); public final LootChestManager lootChests = new LootChestManager(); - /* - * professions - */ + // Profession managers + public final net.Indyuce.mmocore.manager.profession.CustomBlockManager mineManager = new net.Indyuce.mmocore.manager.profession.CustomBlockManager(); public final FishingManager fishingManager = new FishingManager(); public final AlchemyManager alchemyManager = new AlchemyManager(); public final EnchantManager enchantManager = new EnchantManager(); @@ -206,7 +204,7 @@ public class MMOCore extends LuminePlugin { return; } - reloadPlugin(); + initializePlugin(false); if (getConfig().getBoolean("vanilla-exp-redirection.enabled")) Bukkit.getPluginManager().registerEvents(new RedirectVanillaExp(getConfig().getDouble("vanilla-exp-redirection.ratio")), this); @@ -336,45 +334,39 @@ public class MMOCore extends LuminePlugin { lootChests.getActive().forEach(chest -> chest.unregister(false)); } - public void reloadPlugin() { + /** + * Called either when the server starts when initializing the manager for + * the first time, or when issuing a plugin reload; in that case, stuff + * like listeners must all be cleared before. + * + * Also see {@link MMOCoreManager} + * + * @param clearBefore True when issuing a plugin reload + */ + public void initializePlugin(boolean clearBefore) { reloadConfig(); configManager = new ConfigManager(); skillManager.reload(); - mineManager.clear(); - mineManager.reload(); + mineManager.initialize(clearBefore); + partyManager.initialize(clearBefore); + attributeManager.initialize(clearBefore); - fishingManager.clear(); - alchemyManager.clear(); - smithingManager.clear(); + // Experience must be loaded before professions and classes + experience.initialize(clearBefore); - partyManager.clear(); - partyManager.reload(); + // Drop tables must be loaded before professions + dropTableManager.initialize(clearBefore); - attributeManager.clear(); - attributeManager.reload(); - - // experience must be loaded before professions and classes - experience.reload(); - - // drop tables must be loaded before professions - dropTableManager.clear(); - dropTableManager.reload(); - - professionManager.clear(); - professionManager.reload(); - - classManager.clear(); - classManager.reload(); + professionManager.initialize(clearBefore); + classManager.initialize(clearBefore); InventoryManager.load(); - questManager.clear(); - questManager.reload(); - - lootChests.reload(); + questManager.initialize(clearBefore); + lootChests.initialize(clearBefore); waypointManager = new WaypointManager(new ConfigFile("waypoints").getConfig()); restrictionManager = new RestrictionManager(new ConfigFile("restrictions").getConfig()); diff --git a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index 5bd963ee..cf142602 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -91,20 +91,31 @@ public class PlayerData extends OfflinePlayerData implements Closable { */ private boolean fullyLoaded = false; + /** + * If the player data was loaded using temporary data. + * See {@link TemporaryPlayerData} for more info + */ + private final boolean usingTemporaryData; + public PlayerData(MMOPlayerData mmoData) { + this(mmoData, false); + } + + public PlayerData(MMOPlayerData mmoData, TemporaryPlayerData tempData) { + this(mmoData, true); + + mana = tempData.getDouble("mana"); + stamina = tempData.getDouble("stamina"); + stellium = tempData.getDouble("stellium"); + } + + private PlayerData(MMOPlayerData mmoData, boolean usingTemporaryData) { super(mmoData.getUniqueId()); this.mmoData = mmoData; this.playerStats = new PlayerStats(this); this.questData = new PlayerQuests(this); - } - - public PlayerData(MMOPlayerData mmoData, TemporaryPlayerData tempData) { - this(mmoData); - - mana = tempData.getDouble("mana"); - stamina = tempData.getDouble("stamina"); - stellium = tempData.getDouble("stellium"); + this.usingTemporaryData = usingTemporaryData; } /** @@ -660,6 +671,10 @@ public class PlayerData extends OfflinePlayerData implements Closable { this.fullyLoaded = true; } + public boolean hasUsedTemporaryData() { + return usingTemporaryData; + } + public boolean isCasting() { return skillCasting != null; } diff --git a/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java b/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java index 83380933..f7804b36 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java @@ -85,7 +85,7 @@ public class PlayerClass extends PostLoadObject { actionBarFormat = config.contains("action-bar", true) ? config.getString("action-bar") : null; expCurve = config.contains("exp-curve") - ? MMOCore.plugin.experience.getOrThrow( + ? MMOCore.plugin.experience.getCurveOrThrow( config.get("exp-curve").toString().toLowerCase().replace("_", "-").replace(" ", "-")) : ExpCurve.DEFAULT; @@ -129,7 +129,7 @@ public class PlayerClass extends PostLoadObject { for (String key : config.getStringList("main-exp-sources")) try { ExperienceSource source = MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), dispenser); - MMOCore.plugin.professionManager.registerExpSource(source); + MMOCore.plugin.experience.registerSource(source); } catch (IllegalArgumentException exception) { MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load exp source '" + key + "' from class '" + id + "': " + exception.getMessage()); diff --git a/src/main/java/net/Indyuce/mmocore/api/player/profess/event/EventTrigger.java b/src/main/java/net/Indyuce/mmocore/api/player/profess/event/EventTrigger.java index 0303b5f2..6bf9d71b 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/profess/event/EventTrigger.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/profess/event/EventTrigger.java @@ -1,16 +1,21 @@ package net.Indyuce.mmocore.api.player.profess.event; +import io.lumine.mythic.lib.api.MMOLineConfig; +import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.api.quest.trigger.Trigger; +import net.Indyuce.mmocore.experience.droptable.ExperienceTable; +import org.apache.commons.lang.Validate; + import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import java.util.logging.Level; -import org.apache.commons.lang.Validate; - -import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.quest.trigger.Trigger; -import io.lumine.mythic.lib.api.MMOLineConfig; - +/** + * @deprecated Replaced by {@link ExperienceTable} and will + * be removed in 1.8.4 + */ +@Deprecated public class EventTrigger { private final String event; private final Set triggers = new LinkedHashSet<>(); diff --git a/src/main/java/net/Indyuce/mmocore/api/player/profess/event/EventTriggerHandler.java b/src/main/java/net/Indyuce/mmocore/api/player/profess/event/EventTriggerHandler.java index dca36f22..2e0d44ff 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/profess/event/EventTriggerHandler.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/profess/event/EventTriggerHandler.java @@ -1,7 +1,13 @@ package net.Indyuce.mmocore.api.player.profess.event; +import net.Indyuce.mmocore.experience.droptable.ExperienceTable; import org.bukkit.event.Listener; +/** + * @deprecated Replaced by {@link ExperienceTable} and will + * be removed in 1.8.4 + */ +@Deprecated public interface EventTriggerHandler extends Listener { boolean handles(String event); } diff --git a/src/main/java/net/Indyuce/mmocore/api/player/social/Party.java b/src/main/java/net/Indyuce/mmocore/api/player/social/Party.java index 244167e2..c5f355d2 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/social/Party.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/social/Party.java @@ -62,13 +62,13 @@ public class Party { reopenInventories(); - // disband the party if no member left + // Disband the party if no member left if (members.count() < 1) { MMOCore.plugin.partyManager.unregisterParty(this); return; } - // transfer ownership + // Transfer ownership if (owner.equals(data)) { owner = members.get(0); if (notify && owner.isOnline()) diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/ReloadCommandTreeNode.java b/src/main/java/net/Indyuce/mmocore/command/rpg/ReloadCommandTreeNode.java index 6cf499d0..f964d556 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/ReloadCommandTreeNode.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/ReloadCommandTreeNode.java @@ -19,7 +19,7 @@ public class ReloadCommandTreeNode extends CommandTreeNode { long ms = System.currentTimeMillis(); MMOCore.plugin.reloadConfig(); - MMOCore.plugin.reloadPlugin(); + MMOCore.plugin.initializePlugin(true); PlayerData.getAll().forEach(PlayerData::update); diff --git a/src/main/java/net/Indyuce/mmocore/experience/ExpCurve.java b/src/main/java/net/Indyuce/mmocore/experience/ExpCurve.java index 6769099f..b45ed8a7 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/ExpCurve.java +++ b/src/main/java/net/Indyuce/mmocore/experience/ExpCurve.java @@ -7,6 +7,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import net.Indyuce.mmocore.api.player.PlayerData; import org.apache.commons.lang.Validate; public class ExpCurve { @@ -21,7 +22,9 @@ public class ExpCurve { /** * Purely arbitrary but MMOCore needs a default exp curve for everything * otherwise there might be divisions by 0 when trying to update the vanilla - * exp bar which requires a 0.0 -> 1.0 float as parameter + * exp bar which requires a 0.0 -> 1.0 float as parameter. + * + * See {@link PlayerData#refreshVanillaExp()} */ public static final ExpCurve DEFAULT = new ExpCurve("default", 100, 200, 300, 400, 500); diff --git a/src/main/java/net/Indyuce/mmocore/experience/provider/ExperienceDispenser.java b/src/main/java/net/Indyuce/mmocore/experience/provider/ExperienceDispenser.java index 29af833c..2a345d30 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/provider/ExperienceDispenser.java +++ b/src/main/java/net/Indyuce/mmocore/experience/provider/ExperienceDispenser.java @@ -22,7 +22,15 @@ public interface ExperienceDispenser { */ void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation); - boolean matches(PlayerData playerData); + /** + * Experience sources handle both CLASS experience sources and PROFESSION + * experience sources. Professions have no problem because whatever + * class the player has chosen, he can get exp in that profession. + *

+ * But class experience sources must first make sure that the player has + * the right class before giving exp to the player + */ + boolean shouldHandle(PlayerData playerData); default Location getPlayerLocation(PlayerData player) { return player.isOnline() ? player.getPlayer().getLocation() : null; diff --git a/src/main/java/net/Indyuce/mmocore/experience/provider/MainExperienceDispenser.java b/src/main/java/net/Indyuce/mmocore/experience/provider/MainExperienceDispenser.java index b3f3918c..cca398ab 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/provider/MainExperienceDispenser.java +++ b/src/main/java/net/Indyuce/mmocore/experience/provider/MainExperienceDispenser.java @@ -23,7 +23,7 @@ public class MainExperienceDispenser implements ExperienceDispenser { } @Override - public boolean matches(PlayerData playerData) { + public boolean shouldHandle(PlayerData playerData) { return playerData.getProfess().equals(profess); } } diff --git a/src/main/java/net/Indyuce/mmocore/experience/provider/ProfessionExperienceDispenser.java b/src/main/java/net/Indyuce/mmocore/experience/provider/ProfessionExperienceDispenser.java index 674afe88..4d66d9c8 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/provider/ProfessionExperienceDispenser.java +++ b/src/main/java/net/Indyuce/mmocore/experience/provider/ProfessionExperienceDispenser.java @@ -21,7 +21,7 @@ public class ProfessionExperienceDispenser implements ExperienceDispenser { } @Override - public boolean matches(PlayerData playerData) { + public boolean shouldHandle(PlayerData playerData) { return true; } } diff --git a/src/main/java/net/Indyuce/mmocore/experience/source/type/ExperienceSource.java b/src/main/java/net/Indyuce/mmocore/experience/source/type/ExperienceSource.java index 681326a0..644666d5 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/source/type/ExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/experience/source/type/ExperienceSource.java @@ -18,7 +18,7 @@ public abstract class ExperienceSource { public abstract ExperienceSourceManager newManager(); public boolean matches(PlayerData player, T obj) { - return getDispenser().matches(player) && matchesParameter(player, obj); + return getDispenser().shouldHandle(player) && matchesParameter(player, obj); } public abstract boolean matchesParameter(PlayerData player, T obj); diff --git a/src/main/java/net/Indyuce/mmocore/manager/AttributeManager.java b/src/main/java/net/Indyuce/mmocore/manager/AttributeManager.java index cd07a80f..ab85face 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/AttributeManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/AttributeManager.java @@ -9,7 +9,7 @@ import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.ConfigFile; import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute; -public class AttributeManager implements MMOManager { +public class AttributeManager implements MMOCoreManager { private final Map map = new HashMap<>(); public PlayerAttribute get(String id) { @@ -23,9 +23,11 @@ public class AttributeManager implements MMOManager { public Collection getAll() { return map.values(); } - + @Override - public void reload() { + public void initialize(boolean clearBefore) { + if (clearBefore) + map.clear(); ConfigFile config = new ConfigFile("attributes"); for (String key : config.getConfig().getKeys(false)) @@ -36,9 +38,4 @@ public class AttributeManager implements MMOManager { MMOCore.log(Level.WARNING, "Could not load attribute '" + key + "': " + exception.getMessage()); } } - - @Override - public void clear() { - map.clear(); - } } diff --git a/src/main/java/net/Indyuce/mmocore/manager/ClassManager.java b/src/main/java/net/Indyuce/mmocore/manager/ClassManager.java index 17c90715..25c9415b 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/ClassManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/ClassManager.java @@ -26,7 +26,7 @@ import net.Indyuce.mmocore.api.player.profess.event.trigger.ClassChosenEventTrig import net.Indyuce.mmocore.api.player.profess.event.trigger.LevelUpEventTrigger; import net.Indyuce.mmocore.api.player.profess.event.trigger.MultipleLevelUpEventTrigger; -public class ClassManager implements MMOManager { +public class ClassManager implements MMOCoreManager { private final Map map = new HashMap<>(); /* @@ -84,7 +84,17 @@ public class ClassManager implements MMOManager { } @Override - public void reload() { + public void initialize(boolean clearBefore) { + if (clearBefore) { + map.clear(); + triggerHandlers.forEach(HandlerList::unregisterAll); + + /* + * Do not clear the list of trigger listeners, since it's only setup + * once the server loads and it is never modified. + */ + } + for (File file : new File(MMOCore.plugin.getDataFolder() + "/classes").listFiles()) try { String id = file.getName().substring(0, file.getName().length() - 4); @@ -104,19 +114,8 @@ public class ClassManager implements MMOManager { .orElse(new PlayerClass("HUMAN", "Human", Material.LEATHER_BOOTS)); /* - * register event triggers + * Register event triggers */ triggerHandlers.forEach(handler -> Bukkit.getPluginManager().registerEvents(handler, MMOCore.plugin)); } - - @Override - public void clear() { - map.clear(); - triggerHandlers.forEach(HandlerList::unregisterAll); - - /* - * do not clear the list of trigger listeners, since it's only setup - * once the server loads and it is never modified. - */ - } } diff --git a/src/main/java/net/Indyuce/mmocore/manager/DropTableManager.java b/src/main/java/net/Indyuce/mmocore/manager/DropTableManager.java index 9bb04f13..00e21b48 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/DropTableManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/DropTableManager.java @@ -16,7 +16,7 @@ import org.bukkit.configuration.file.YamlConfiguration; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.loot.droptable.DropTable; -public class DropTableManager implements MMOManager { +public class DropTableManager implements MMOCoreManager { private final Map map = new HashMap<>(); public void register(DropTable table) { @@ -59,7 +59,10 @@ public class DropTableManager implements MMOManager { } @Override - public void reload() { + public void initialize(boolean clearBefore) { + if (clearBefore) + map.clear(); + for (File file : new File(MMOCore.plugin.getDataFolder() + "/drop-tables").listFiles()) try { @@ -77,9 +80,4 @@ public class DropTableManager implements MMOManager { Bukkit.getScheduler().runTask(MMOCore.plugin, () -> map.values().forEach(PostLoadObject::postLoad)); } - - @Override - public void clear() { - map.clear(); - } } diff --git a/src/main/java/net/Indyuce/mmocore/manager/LootChestManager.java b/src/main/java/net/Indyuce/mmocore/manager/LootChestManager.java index 2f3ff309..b7805bf5 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/LootChestManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/LootChestManager.java @@ -15,7 +15,7 @@ import net.Indyuce.mmocore.api.ConfigFile; import net.Indyuce.mmocore.loot.chest.LootChest; import net.Indyuce.mmocore.loot.chest.LootChestRegion; -public class LootChestManager { +public class LootChestManager implements MMOCoreManager { /* * all active loot chests in the server @@ -57,9 +57,12 @@ public class LootChestManager { return null; } - public void reload() { - regions.values().forEach(region -> region.getRunnable().cancel()); - regions.clear(); + @Override + public void initialize(boolean clearBefore) { + if (clearBefore) { + regions.values().forEach(region -> region.getRunnable().cancel()); + regions.clear(); + } FileConfiguration config = new ConfigFile("loot-chests").getConfig(); for (String key : config.getKeys(false)) diff --git a/src/main/java/net/Indyuce/mmocore/manager/MMOManager.java b/src/main/java/net/Indyuce/mmocore/manager/MMOManager.java deleted file mode 100644 index 93df1478..00000000 --- a/src/main/java/net/Indyuce/mmocore/manager/MMOManager.java +++ /dev/null @@ -1,7 +0,0 @@ -package net.Indyuce.mmocore.manager; - -public interface MMOManager { - void reload(); - - void clear(); -} diff --git a/src/main/java/net/Indyuce/mmocore/manager/QuestManager.java b/src/main/java/net/Indyuce/mmocore/manager/QuestManager.java index da345e6e..31768d61 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/QuestManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/QuestManager.java @@ -13,7 +13,7 @@ import org.bukkit.configuration.file.YamlConfiguration; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.quest.Quest; -public class QuestManager implements MMOManager { +public class QuestManager implements MMOCoreManager { private final Map quests = new LinkedHashMap<>(); public void load(File file) { @@ -45,7 +45,10 @@ public class QuestManager implements MMOManager { } @Override - public void reload() { + public void initialize(boolean clearBefore) { + if (clearBefore) + quests.clear(); + load(new File(MMOCore.plugin.getDataFolder() + "/quests")); for (Quest quest : quests.values()) try { @@ -54,9 +57,4 @@ public class QuestManager implements MMOManager { MMOCore.plugin.getLogger().log(Level.WARNING, "Could not post-load quest '" + quest.getId() + "': " + exception.getMessage()); } } - - @Override - public void clear() { - quests.clear(); - } } diff --git a/src/main/java/net/Indyuce/mmocore/manager/SkillManager.java b/src/main/java/net/Indyuce/mmocore/manager/SkillManager.java index 7a2ef6f4..e6f64c7a 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/SkillManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/SkillManager.java @@ -24,8 +24,32 @@ import net.Indyuce.mmocore.comp.mythicmobs.MythicSkill; public class SkillManager { private final Map skills = new LinkedHashMap<>(); + public void register(Skill skill) { + skills.put(skill.getId().toUpperCase(), skill); + } + + public Skill get(String id) { + return skills.get(id.toUpperCase()); + } + + public boolean has(String id) { + return skills.containsKey(id.toUpperCase()); + } + + public Collection getAll() { + return skills.values(); + } + + public Set getActive() { + return skills.values().stream().filter(skill -> !skill.isPassive()).collect(Collectors.toSet()); + } + + public Set getKeys() { + return skills.keySet(); + } + /* - * skills are initialized when MMOCore enables but SkillManager must be + * Skills are initialized when MMOCore enables but SkillManager must be * instanced when MMOCore loads so that extra plugins can register skills * before CLASSES are loaded */ @@ -53,9 +77,7 @@ public class SkillManager { if (!mythicMobs.exists()) mythicMobs.mkdir(); - /* - * load MythicMobs addon skills - */ + // Load MythicMobs addon skills if (Bukkit.getPluginManager().getPlugin("MythicMobs") != null) for (File file : mythicMobs.listFiles()) { try { @@ -96,28 +118,4 @@ public class SkillManager { config.save(); } } - - public void register(Skill skill) { - skills.put(skill.getId().toUpperCase(), skill); - } - - public Skill get(String id) { - return skills.get(id.toUpperCase()); - } - - public boolean has(String id) { - return skills.containsKey(id.toUpperCase()); - } - - public Collection getAll() { - return skills.values(); - } - - public Set getActive() { - return skills.values().stream().filter(skill -> !skill.isPassive()).collect(Collectors.toSet()); - } - - public Set getKeys() { - return skills.keySet(); - } } diff --git a/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java b/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java index 2d116970..b9cefc77 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java @@ -44,11 +44,14 @@ public class MySQLPlayerDataManager extends PlayerDataManager { data.setAttributePoints(getDefaultData().getAttributePoints()); data.setAttributeReallocationPoints(getDefaultData().getAttrReallocPoints()); data.setExperience(0); - data.setMana(data.getStats().getStat(StatType.MAX_MANA)); - data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA)); - data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM)); data.getQuestData().updateBossBar(); + if (!data.hasUsedTemporaryData()) { + data.setMana(data.getStats().getStat(StatType.MAX_MANA)); + data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA)); + data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM)); + } + data.setFullyLoaded(); MMOCore.sqlDebug("Loaded DEFAULT data for: '" + data.getUniqueId() + "' as no saved data was found."); return; @@ -62,9 +65,13 @@ public class MySQLPlayerDataManager extends PlayerDataManager { data.setExperience(result.getInt("experience")); if (!isEmpty(result.getString("class"))) data.setClass(MMOCore.plugin.classManager.get(result.getString("class"))); - data.setMana(data.getStats().getStat(StatType.MAX_MANA)); - data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA)); - data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM)); + + if (!data.hasUsedTemporaryData()) { + data.setMana(data.getStats().getStat(StatType.MAX_MANA)); + data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA)); + data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM)); + } + if (!isEmpty(result.getString("guild"))) data.setGuild(MMOCore.plugin.dataProvider.getGuildManager().stillInGuild(data.getUniqueId(), result.getString("guild"))); if (!isEmpty(result.getString("attributes"))) data.getAttributes().load(result.getString("attributes")); diff --git a/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java b/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java index 21bca359..48033be2 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/data/yaml/YAMLPlayerDataManager.java @@ -32,9 +32,13 @@ public class YAMLPlayerDataManager extends PlayerDataManager { data.setExperience(config.getInt("experience")); if (config.contains("class")) data.setClass(MMOCore.plugin.classManager.get(config.getString("class"))); - data.setMana(data.getStats().getStat(StatType.MAX_MANA)); - data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA)); - data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM)); + + if (!data.hasUsedTemporaryData()) { + data.setMana(data.getStats().getStat(StatType.MAX_MANA)); + data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA)); + data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM)); + } + if (config.contains("guild")) data.setGuild(MMOCore.plugin.dataProvider.getGuildManager().stillInGuild(data.getUniqueId(), config.getString("guild"))); if (config.contains("attribute")) @@ -55,9 +59,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager { if (data.getProfess().hasSkill(id)) data.getBoundSkills().add(data.getProfess().getSkill(id)); - /* - * load class slots, use try so the player can log in. - */ + // Load class slots, use try so the player can log in. if (config.contains("class-info")) for (String key : config.getConfigurationSection("class-info").getKeys(false)) try { @@ -67,6 +69,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager { } catch (IllegalArgumentException exception) { MMOCore.log(Level.WARNING, "Could not load class info '" + key + "': " + exception.getMessage()); } + data.setFullyLoaded(); } diff --git a/src/main/java/net/Indyuce/mmocore/manager/profession/AlchemyManager.java b/src/main/java/net/Indyuce/mmocore/manager/profession/AlchemyManager.java index a492e387..46460be8 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/profession/AlchemyManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/profession/AlchemyManager.java @@ -1,18 +1,39 @@ package net.Indyuce.mmocore.manager.profession; +import net.Indyuce.mmocore.MMOCore; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.potion.PotionType; + import java.util.HashMap; import java.util.Map; +import java.util.logging.Level; -import org.bukkit.potion.PotionType; - -import net.Indyuce.mmocore.manager.MMOManager; - -public class AlchemyManager implements MMOManager { +public class AlchemyManager extends SpecificProfessionManager { public double splash, lingering, upgrade, extend; // private Map custom = new HashMap<>(); private final Map base = new HashMap<>(); + public AlchemyManager() { + super("alchemy-experience"); + } + + @Override + public void loadProfessionConfiguration(ConfigurationSection config) { + splash = 1 + config.getDouble("special.splash") / 100; + lingering = 1 + config.getDouble("special.lingering") / 100; + extend = 1 + config.getDouble("special.extend") / 100; + upgrade = 1 + config.getDouble("special.upgrade") / 100; + + for (String key : config.getConfigurationSection("effects").getKeys(false)) + try { + PotionType type = PotionType.valueOf(key.toUpperCase().replace("-", "_").replace(" ", "_")); + MMOCore.plugin.alchemyManager.registerBaseExperience(type, config.getDouble("effects." + key)); + } catch (IllegalArgumentException exception) { + MMOCore.log(Level.WARNING, "Could not read potion type from " + key); + } + } + // public double getWeight(PotionEffectType type) { // return custom.containsKey(type) ? custom.get(type) : 0; // } @@ -39,15 +60,11 @@ public class AlchemyManager implements MMOManager { // } // } - @Override - public void reload() { - // TODO Auto-generated method stub - - } - - @Override - public void clear() { - splash = lingering = upgrade = extend = 1; - base.clear(); - } + @Override + public void initialize(boolean clearBefore) { + if (clearBefore) { + splash = lingering = upgrade = extend = 1; + base.clear(); + } + } } diff --git a/src/main/java/net/Indyuce/mmocore/manager/CustomBlockManager.java b/src/main/java/net/Indyuce/mmocore/manager/profession/CustomBlockManager.java similarity index 93% rename from src/main/java/net/Indyuce/mmocore/manager/CustomBlockManager.java rename to src/main/java/net/Indyuce/mmocore/manager/profession/CustomBlockManager.java index c39904d9..c6e72d9e 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/CustomBlockManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/profession/CustomBlockManager.java @@ -1,4 +1,4 @@ -package net.Indyuce.mmocore.manager; +package net.Indyuce.mmocore.manager.profession; import io.papermc.lib.PaperLib; import net.Indyuce.mmocore.MMOCore; @@ -11,6 +11,7 @@ import net.Indyuce.mmocore.loot.droptable.condition.Condition; import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance; import net.Indyuce.mmocore.api.util.MMOCoreUtils; import io.lumine.mythic.lib.api.MMOLineConfig; +import net.Indyuce.mmocore.manager.profession.SpecificProfessionManager; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.Block; @@ -22,7 +23,7 @@ import java.util.*; import java.util.function.Function; import java.util.logging.Level; -public class CustomBlockManager implements MMOManager { +public class CustomBlockManager extends SpecificProfessionManager { /** * Registered block infos @@ -49,6 +50,8 @@ public class CustomBlockManager implements MMOManager { private boolean protect; public CustomBlockManager() { + super("on-mine"); + registerBlockType(block -> MMOCoreUtils.isPlayerHead(block.getType()) ? Optional.of(new SkullBlockType(block)) : Optional.empty()); } @@ -160,7 +163,8 @@ public class CustomBlockManager implements MMOManager { return true; } - public void loadDropTables(ConfigurationSection config) { + @Override + public void loadProfessionConfiguration(ConfigurationSection config) { for (String key : config.getKeys(false)) try { register(new BlockInfo(config.getConfigurationSection(key))); @@ -177,8 +181,11 @@ public class CustomBlockManager implements MMOManager { } @Override - public void reload() { - customMineConditions.clear(); + public void initialize(boolean clearBefore) { + if (clearBefore) { + customMineConditions.clear(); + map.clear(); + } this.protect = MMOCore.plugin.getConfig().getBoolean("protect-custom-mine"); @@ -189,9 +196,4 @@ public class CustomBlockManager implements MMOManager { MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load custom mining condition '" + key + "': " + exception.getMessage()); } } - - @Override - public void clear() { - map.clear(); - } } diff --git a/src/main/java/net/Indyuce/mmocore/manager/profession/EnchantManager.java b/src/main/java/net/Indyuce/mmocore/manager/profession/EnchantManager.java index 8880e0c9..592d69f4 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/profession/EnchantManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/profession/EnchantManager.java @@ -1,15 +1,32 @@ package net.Indyuce.mmocore.manager.profession; +import io.lumine.mythic.lib.MythicLib; +import net.Indyuce.mmocore.MMOCore; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.enchantments.Enchantment; + import java.util.HashMap; import java.util.Map; +import java.util.logging.Level; -import org.bukkit.enchantments.Enchantment; - -import net.Indyuce.mmocore.manager.MMOManager; - -public class EnchantManager implements MMOManager { +public class EnchantManager extends SpecificProfessionManager { private final Map base = new HashMap<>(); + public EnchantManager() { + super("base-enchant-exp"); + } + + @Override + public void loadProfessionConfiguration(ConfigurationSection config) { + for (String key : config.getKeys(false)) + try { + Enchantment enchant = MythicLib.plugin.getVersion().getWrapper().getEnchantmentFromString(key.toLowerCase().replace("-", "_")); + MMOCore.plugin.enchantManager.registerBaseExperience(enchant, config.getDouble(key)); + } catch (IllegalArgumentException exception) { + MMOCore.log(Level.WARNING, "Could not find enchant with name '" + key + "'"); + } + } + public void registerBaseExperience(Enchantment enchant, double value) { base.put(enchant, value); } @@ -19,13 +36,8 @@ public class EnchantManager implements MMOManager { } @Override - public void reload() { - // TODO Auto-generated method stub - - } - - @Override - public void clear() { - base.clear(); + public void initialize(boolean clearBefore) { + if (clearBefore) + base.clear(); } } diff --git a/src/main/java/net/Indyuce/mmocore/manager/profession/ExperienceSourceManager.java b/src/main/java/net/Indyuce/mmocore/manager/profession/ExperienceSourceManager.java index 0744b047..98ab98d8 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/profession/ExperienceSourceManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/profession/ExperienceSourceManager.java @@ -1,13 +1,14 @@ package net.Indyuce.mmocore.manager.profession; import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.experience.source.type.ExperienceSource; import org.bukkit.Bukkit; import org.bukkit.event.Listener; import java.util.HashSet; import java.util.Set; -public abstract class ExperienceSourceManager implements Listener { +public abstract class ExperienceSourceManager implements Listener { /** * List of all active experience sources @@ -20,8 +21,6 @@ public abstract class ExperienceSourceManager implements Listener { public void registerSource(T source) { sources.add(source); - - getSources(); } public Set getSources() { diff --git a/src/main/java/net/Indyuce/mmocore/manager/profession/FishingManager.java b/src/main/java/net/Indyuce/mmocore/manager/profession/FishingManager.java index badb7889..10aecdde 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/profession/FishingManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/profession/FishingManager.java @@ -1,30 +1,28 @@ package net.Indyuce.mmocore.manager.profession; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Random; -import java.util.Set; -import java.util.logging.Level; - -import org.apache.commons.lang.Validate; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.entity.Entity; - +import io.lumine.mythic.lib.api.MMOLineConfig; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.loot.droptable.condition.Condition; import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance; import net.Indyuce.mmocore.loot.droptable.dropitem.fishing.FishingDropItem; -import net.Indyuce.mmocore.manager.MMOManager; -import io.lumine.mythic.lib.api.MMOLineConfig; +import org.apache.commons.lang.Validate; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.Entity; -public class FishingManager implements MMOManager { +import java.util.*; +import java.util.logging.Level; + +public class FishingManager extends SpecificProfessionManager { private final Set tables = new LinkedHashSet<>(); private static final Random random = new Random(); - public void loadDropTables(ConfigurationSection config) { + public FishingManager() { + super("on-fish"); + } + + @Override + public void loadProfessionConfiguration(ConfigurationSection config) { for (String key : config.getKeys(false)) try { tables.add(new FishingDropTable(config.getConfigurationSection(key))); @@ -107,12 +105,8 @@ public class FishingManager implements MMOManager { } @Override - public void reload() { - // TODO Auto-generated method stub - } - - @Override - public void clear() { - tables.clear(); + public void initialize(boolean clearBefore) { + if (clearBefore) + tables.clear(); } } diff --git a/src/main/java/net/Indyuce/mmocore/manager/profession/ProfessionManager.java b/src/main/java/net/Indyuce/mmocore/manager/profession/ProfessionManager.java index e196d335..6bee333a 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/profession/ProfessionManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/profession/ProfessionManager.java @@ -1,50 +1,41 @@ package net.Indyuce.mmocore.manager.profession; -import java.io.File; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Level; - -import io.lumine.mythic.lib.api.util.PostLoadObject; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.event.HandlerList; - import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.experience.Profession; -import net.Indyuce.mmocore.experience.source.type.ExperienceSource; -import net.Indyuce.mmocore.manager.MMOManager; +import net.Indyuce.mmocore.manager.MMOCoreManager; +import org.apache.commons.lang.Validate; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.YamlConfiguration; +import org.jetbrains.annotations.NotNull; -public class ProfessionManager implements MMOManager { +import java.io.File; +import java.util.*; +import java.util.logging.Level; - /** - * Loaded professions. - */ +public class ProfessionManager implements MMOCoreManager { private final Map professions = new HashMap<>(); - - /** - * Saves different experience sources based on experience source type. - */ - private final Map, ExperienceSourceManager> managers = new HashMap<>(); - - @SuppressWarnings("unchecked") - public ExperienceSourceManager getManager(Class t) { - return (ExperienceSourceManager) managers.get(t); - } - - @SuppressWarnings("unchecked") - public > void registerExpSource(T source) { - Class path = (Class) source.getClass(); - - if (!managers.containsKey(path)) - managers.put(path, source.newManager()); - getManager(path).registerSource(source); - } + private final Set professionManagers = new HashSet<>(); public void register(Profession profession) { professions.put(profession.getId(), profession); } + public void registerProfessionManager(@NotNull SpecificProfessionManager professionManager) { + Validate.notNull(professionManager); + + professionManagers.add(professionManager); + } + + public void loadProfessionConfigurations(ConfigurationSection config) { + for (SpecificProfessionManager manager : professionManagers) + if (config.contains(manager.getStringKey())) + try { + manager.loadProfessionConfiguration(config.getConfigurationSection(manager.getStringKey())); + } catch (RuntimeException exception) { + MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load profession config '" + manager.getStringKey() + "': " + exception.getMessage()); + } + } + public Profession get(String id) { return professions.get(id); } @@ -58,7 +49,20 @@ public class ProfessionManager implements MMOManager { } @Override - public void reload() { + public void initialize(boolean clearBefore) { + if (clearBefore) + professions.clear(); + + // Load default profession managers (can't be done on constructor because MMOCore.plugin is null) + if (professionManagers.isEmpty()) { + registerProfessionManager(MMOCore.plugin.alchemyManager); + registerProfessionManager(MMOCore.plugin.enchantManager); + registerProfessionManager(MMOCore.plugin.fishingManager); + registerProfessionManager(MMOCore.plugin.smithingManager); + } + + professionManagers.forEach(manager -> manager.initialize(clearBefore)); + for (File file : new File(MMOCore.plugin.getDataFolder() + "/professions").listFiles()) try { String id = file.getName().substring(0, file.getName().length() - 4); @@ -66,14 +70,5 @@ public class ProfessionManager implements MMOManager { } catch (IllegalArgumentException exception) { MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load profession " + file.getName() + ": " + exception.getMessage()); } - - getAll().forEach(PostLoadObject::postLoad); - } - - @Override - public void clear() { - managers.values().forEach(HandlerList::unregisterAll); - managers.clear(); - professions.clear(); } } diff --git a/src/main/java/net/Indyuce/mmocore/manager/profession/SmithingManager.java b/src/main/java/net/Indyuce/mmocore/manager/profession/SmithingManager.java index 7fccef35..40e0a8d4 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/profession/SmithingManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/profession/SmithingManager.java @@ -1,35 +1,44 @@ package net.Indyuce.mmocore.manager.profession; +import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; + import java.util.HashMap; import java.util.Map; -import org.bukkit.Material; +public class SmithingManager extends SpecificProfessionManager { + private final Map base = new HashMap<>(); -import net.Indyuce.mmocore.manager.MMOManager; + public SmithingManager() { + super("repair-exp"); + } -public class SmithingManager implements MMOManager { - private final Map base = new HashMap<>(); + public void registerBaseExperience(Material material, double value) { + base.put(material, value); + } - public void registerBaseExperience(Material material, double value) { - base.put(material, value); - } + public double getBaseExperience(Material material) { + return base.get(material); + } - public double getBaseExperience(Material material) { - return base.get(material); - } - - public boolean hasExperience(Material material) { - return base.containsKey(material); - } + public boolean hasExperience(Material material) { + return base.containsKey(material); + } - @Override - public void reload() { - // TODO Auto-generated method stub + @Override + public void loadProfessionConfiguration(ConfigurationSection config) { + for (String key : config.getKeys(false)) + try { + Material material = Material.valueOf(key.toUpperCase().replace("-", "_").replace(" ", "_")); + registerBaseExperience(material, config.getDouble(key)); + } catch (IllegalArgumentException exception) { + throw new RuntimeException("Could not read material from '" + key + "'"); + } + } - } - - @Override - public void clear() { - base.clear(); - } + @Override + public void initialize(boolean clearBefore) { + if (clearBefore) + base.clear(); + } } diff --git a/src/main/java/net/Indyuce/mmocore/manager/profession/SpecificProfessionManager.java b/src/main/java/net/Indyuce/mmocore/manager/profession/SpecificProfessionManager.java new file mode 100644 index 00000000..334fa2b2 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/manager/profession/SpecificProfessionManager.java @@ -0,0 +1,23 @@ +package net.Indyuce.mmocore.manager.profession; + +import net.Indyuce.mmocore.manager.MMOCoreManager; +import org.bukkit.configuration.ConfigurationSection; + +public abstract class SpecificProfessionManager implements MMOCoreManager { + + /** + * String key used to detect and load profession config in any + * profession.yml config + */ + private final String key; + + public SpecificProfessionManager(String key) { + this.key = key; + } + + public String getStringKey() { + return key; + } + + public abstract void loadProfessionConfiguration(ConfigurationSection config); +} diff --git a/src/main/java/net/Indyuce/mmocore/manager/social/PartyManager.java b/src/main/java/net/Indyuce/mmocore/manager/social/PartyManager.java index fd111953..40104745 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/social/PartyManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/social/PartyManager.java @@ -5,7 +5,7 @@ import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.social.Party; import net.Indyuce.mmocore.api.player.stats.StatType; -import net.Indyuce.mmocore.manager.MMOManager; +import net.Indyuce.mmocore.manager.MMOCoreManager; import org.bukkit.configuration.ConfigurationSection; import java.util.HashMap; @@ -14,8 +14,7 @@ import java.util.Map; import java.util.Set; import java.util.logging.Level; - -public class PartyManager implements MMOManager { +public class PartyManager implements MMOCoreManager { private final Set parties = new HashSet<>(); private final Map buffs = new HashMap<>(); @@ -34,7 +33,7 @@ public class PartyManager implements MMOManager { } public void unregisterParty(Party party) { - // IMPORTANT: clears all party stats before unregistering the party + // IMPORTANT: clears all party members before unregistering the party party.getMembers().forEach(party::removeMember); parties.remove(party); } @@ -52,7 +51,10 @@ public class PartyManager implements MMOManager { } @Override - public void reload() { + public void initialize(boolean clearBefore) { + if (clearBefore) + buffs.clear(); + ConfigurationSection config = MMOCore.plugin.getConfig().getConfigurationSection("party.buff"); if (config != null) for (String key : config.getKeys(false)) @@ -63,9 +65,4 @@ public class PartyManager implements MMOManager { MMOCore.log(Level.WARNING, "Could not load party buff '" + key + "': " + exception.getMessage()); } } - - @Override - public void clear() { - buffs.clear(); - } }