diff --git a/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java b/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java index b5175f25..21bed8f3 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/profess/SavedClassInformation.java @@ -13,7 +13,7 @@ import com.google.gson.JsonObject; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute; -import net.Indyuce.mmocore.skill.Skill; +import net.Indyuce.mmocore.skill.RegisteredSkill; import net.Indyuce.mmocore.manager.data.PlayerDataManager.DefaultPlayerData; public class SavedClassInformation { @@ -102,16 +102,16 @@ public class SavedClassInformation { return skills.keySet(); } - public int getSkillLevel(Skill skill) { - return getSkillLevel(skill.getId()); + public int getSkillLevel(RegisteredSkill skill) { + return getSkillLevel(skill.getHandler().getId()); } public int getSkillLevel(String id) { return skills.get(id); } - public void registerSkillLevel(Skill skill, int level) { - registerSkillLevel(skill.getId(), level); + public void registerSkillLevel(RegisteredSkill skill, int level) { + registerSkillLevel(skill.getHandler().getId(), level); } public void registerSkillLevel(String attribute, int level) { diff --git a/src/main/java/net/Indyuce/mmocore/manager/ClassManager.java b/src/main/java/net/Indyuce/mmocore/manager/ClassManager.java index 25c9415b..f173cc23 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/ClassManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/ClassManager.java @@ -1,121 +1,78 @@ package net.Indyuce.mmocore.manager; -import java.io.File; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.logging.Level; - -import org.apache.commons.lang.Validate; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.event.HandlerList; - import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.profess.ClassOption; import net.Indyuce.mmocore.api.player.profess.PlayerClass; -import net.Indyuce.mmocore.api.player.profess.event.EventTriggerHandler; -import net.Indyuce.mmocore.api.player.profess.event.trigger.AttackEventTrigger; -import net.Indyuce.mmocore.api.player.profess.event.trigger.BlockBrokenTrigger; -import net.Indyuce.mmocore.api.player.profess.event.trigger.BlockPlacedTrigger; -import net.Indyuce.mmocore.api.player.profess.event.trigger.ClassChosenEventTrigger; -import net.Indyuce.mmocore.api.player.profess.event.trigger.LevelUpEventTrigger; -import net.Indyuce.mmocore.api.player.profess.event.trigger.MultipleLevelUpEventTrigger; +import org.apache.commons.lang.Validate; +import org.bukkit.Material; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.io.File; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Level; public class ClassManager implements MMOCoreManager { - private final Map map = new HashMap<>(); + private final Map map = new HashMap<>(); - /* - * cached default class. if there are two default classes, the last one - * overrides the previous. - */ - private PlayerClass defaultClass; + /** + * Cached default class. If there happens to have two default + * classes, the last one overrides the previous. + */ + private PlayerClass defaultClass; - /* - * same different types of trigger events to be able to map them later in - * the player class instances. - */ - private final Set triggerHandlers = new HashSet<>(); + public void register(PlayerClass playerClass) { + map.put(playerClass.getId(), playerClass); + } - public ClassManager() { - registerEvent(new LevelUpEventTrigger()); - registerEvent(new AttackEventTrigger()); - registerEvent(new ClassChosenEventTrigger()); - registerEvent(new BlockBrokenTrigger()); - registerEvent(new BlockPlacedTrigger()); - registerEvent(new MultipleLevelUpEventTrigger()); - } + public boolean has(String id) { + return map.containsKey(id); + } - public void registerEvent(EventTriggerHandler handler) { - triggerHandlers.add(handler); - } + public PlayerClass get(String id) { + return map.get(id); + } - public void register(PlayerClass playerClass) { - map.put(playerClass.getId(), playerClass); - } + public PlayerClass getOrThrow(String id) { + Validate.isTrue(map.containsKey(id), "Could not find class with ID '" + id + "'"); + return map.get(id); + } - public boolean has(String id) { - return map.containsKey(id); - } + public Collection getAll() { + return map.values(); + } - public PlayerClass get(String id) { - return map.get(id); - } + public PlayerClass getDefaultClass() { + return defaultClass; + } - public PlayerClass getOrThrow(String id) { - Validate.isTrue(map.containsKey(id), "Could not find class with ID '" + id + "'"); - return map.get(id); - } + public void reloadPlayerClasses() { + PlayerData.getAll().forEach(data -> data.setClass(get(data.getProfess().getId()))); + } - public Collection getAll() { - return map.values(); - } + @Override + public void initialize(boolean clearBefore) { + if (clearBefore) + map.clear(); - public PlayerClass getDefaultClass() { - return defaultClass; - } + for (File file : new File(MMOCore.plugin.getDataFolder() + "/classes").listFiles()) + try { + String id = file.getName().substring(0, file.getName().length() - 4); + register(new PlayerClass(id, YamlConfiguration.loadConfiguration(file))); + } catch (IllegalArgumentException exception) { + MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load class '" + file.getName() + "': " + exception.getMessage()); + } - public void reloadPlayerClasses() { - PlayerData.getAll().forEach(data -> data.setClass(get(data.getProfess().getId()))); - } + for (PlayerClass profess : map.values()) + try { + profess.postLoad(); + } catch (IllegalArgumentException exception) { + MMOCore.plugin.getLogger().log(Level.WARNING, "Could not post-load class '" + profess.getId() + "': " + exception.getMessage()); + } - @Override - 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); - register(new PlayerClass(id, YamlConfiguration.loadConfiguration(file))); - } catch (IllegalArgumentException exception) { - MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load class '" + file.getName() + "': " + exception.getMessage()); - } - - for (PlayerClass profess : map.values()) - try { - profess.postLoad(); - } catch (IllegalArgumentException exception) { - MMOCore.plugin.getLogger().log(Level.WARNING, "Could not post-load class '" + profess.getId() + "': " + exception.getMessage()); - } - - defaultClass = map.values().stream().filter(profess -> profess.hasOption(ClassOption.DEFAULT)).findFirst() - .orElse(new PlayerClass("HUMAN", "Human", Material.LEATHER_BOOTS)); - - /* - * Register event triggers - */ - triggerHandlers.forEach(handler -> Bukkit.getPluginManager().registerEvents(handler, MMOCore.plugin)); - } + defaultClass = map.values().stream().filter(profess -> profess.hasOption(ClassOption.DEFAULT)).findFirst() + .orElse(new PlayerClass("HUMAN", "Human", Material.LEATHER_BOOTS)); + } }