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 f7804b36..253ce169 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 @@ -7,7 +7,6 @@ import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.util.PostLoadObject; import io.lumine.mythic.lib.version.VersionMaterial; import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.player.profess.event.EventTrigger; import net.Indyuce.mmocore.api.player.profess.resource.ManaDisplayOptions; import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource; import net.Indyuce.mmocore.api.player.profess.resource.ResourceRegeneration; @@ -19,8 +18,8 @@ import net.Indyuce.mmocore.experience.ExpCurve; import net.Indyuce.mmocore.experience.provider.ExperienceDispenser; import net.Indyuce.mmocore.experience.provider.MainExperienceDispenser; import net.Indyuce.mmocore.experience.source.type.ExperienceSource; -import net.Indyuce.mmocore.skill.Skill; -import net.Indyuce.mmocore.skill.Skill.SkillInfo; +import net.Indyuce.mmocore.skill.ClassSkill; +import net.Indyuce.mmocore.skill.RegisteredSkill; import net.md_5.bungee.api.ChatColor; import org.apache.commons.lang.Validate; import org.bukkit.Material; @@ -44,11 +43,10 @@ public class PlayerClass extends PostLoadObject { private final ExpCurve expCurve; private final Map stats = new HashMap<>(); - private final Map skills = new LinkedHashMap<>(); + private final Map skills = new LinkedHashMap<>(); private final List subclasses = new ArrayList<>(); private final Map resourceHandlers = new HashMap<>(); - private final Map eventTriggers = new HashMap<>(); private final CastingParticle castParticle; @@ -102,9 +100,8 @@ public class PlayerClass extends PostLoadObject { if (config.contains("skills")) for (String key : config.getConfigurationSection("skills").getKeys(false)) try { - Validate.isTrue(MMOCore.plugin.skillManager.has(key), "Could not find skill " + key); - skills.put(key.toUpperCase(), MMOCore.plugin.skillManager.get(key) - .newSkillInfo(config.getConfigurationSection("skills." + key))); + Validate.isTrue(MMOCore.plugin.skillManager.hasSkill(key), "Could not find skill " + key); + skills.put(key, new ClassSkill(MMOCore.plugin.skillManager.getSkill(key), config.getConfigurationSection("skills." + key))); } catch (IllegalArgumentException exception) { MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load skill info '" + key + "' from class '" + id + "': " + exception.getMessage()); @@ -136,19 +133,9 @@ public class PlayerClass extends PostLoadObject { } } - if (config.contains("triggers")) - for (String key : config.getConfigurationSection("triggers").getKeys(false)) { - try { - String format = key.toLowerCase().replace("_", "-").replace(" ", "-"); - eventTriggers.put(format, new EventTrigger(format, config.getStringList("triggers." + key))); - } catch (IllegalArgumentException exception) { - MMOCore.log(Level.WARNING, "Could not load trigger '" + key + "' from class '" + id + "':" + exception.getMessage()); - } - } - /* - * must make sure all the resourceHandlers are registered when the placer class - * is initialized. + * Must make sure all the resourceHandlers are registered + * when the placer class is initialized. */ for (PlayerResource resource : PlayerResource.values()) { if (config.isConfigurationSection("resource." + resource.name().toLowerCase())) @@ -165,8 +152,12 @@ public class PlayerClass extends PostLoadObject { } } - /* - * used to generate display class + /** + * Used to generate the default Human class if no one is + * specified after loading all the player classes. This is + * a very basic class that will make sure MMOCore can still + * continue to run without having to stop the server because + * some option was not provided */ public PlayerClass(String id, String name, Material material) { super(null); @@ -281,16 +272,16 @@ public class PlayerClass extends PostLoadObject { return false; } - public boolean hasSkill(Skill skill) { - return hasSkill(skill.getId()); + public boolean hasSkill(RegisteredSkill skill) { + return hasSkill(skill.getHandler().getId()); } public boolean hasSkill(String id) { return skills.containsKey(id); } - public SkillInfo getSkill(Skill skill) { - return getSkill(skill.getId()); + public ClassSkill getSkill(RegisteredSkill skill) { + return getSkill(skill.getHandler().getId()); } /** @@ -299,30 +290,18 @@ public class PlayerClass extends PostLoadObject { *

* Examples: * - {@link net.Indyuce.mmocore.skill.list.Neptune_Gift} - * - {@link net.Indyuce.mmocore.skill.list.Fire_Berserker} + * - {@link net.Indyuce.mmocore.skill.list.Ambers} */ - public Optional findSkill(Skill skill) { - SkillInfo found = skills.get(skill.getId()); + public Optional findSkill(RegisteredSkill skill) { + ClassSkill found = skills.get(skill.getHandler().getId()); return found == null ? Optional.empty() : Optional.of(found); } - public SkillInfo getSkill(String id) { + public ClassSkill getSkill(String id) { return skills.get(id); } - public Set getEventTriggers() { - return eventTriggers.keySet(); - } - - public boolean hasEventTriggers(String name) { - return eventTriggers.containsKey(name); - } - - public EventTrigger getEventTriggers(String name) { - return eventTriggers.get(name); - } - - public Collection getSkills() { + public Collection getSkills() { return skills.values(); } 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 deleted file mode 100644 index 6bf9d71b..00000000 --- a/src/main/java/net/Indyuce/mmocore/api/player/profess/event/EventTrigger.java +++ /dev/null @@ -1,44 +0,0 @@ -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; - -/** - * @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<>(); - - public EventTrigger(String event, List list) { - Validate.notNull(list, "Could not load trigger list"); - - this.event = event; - - for (String format : list) - try { - triggers.add(MMOCore.plugin.loadManager.loadTrigger(new MMOLineConfig(format))); - } catch (IllegalArgumentException exception) { - MMOCore.plugin.getLogger().log(Level.WARNING, - "Could not load trigger '" + format + "' from event trigger '" + event + "': " + exception.getMessage()); - } - } - - public String getEvent() { - return event; - } - - public Set getTriggers() { - return triggers; - } -} 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 deleted file mode 100644 index 2e0d44ff..00000000 --- a/src/main/java/net/Indyuce/mmocore/api/player/profess/event/EventTriggerHandler.java +++ /dev/null @@ -1,13 +0,0 @@ -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/profess/event/trigger/AttackEventTrigger.java b/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/AttackEventTrigger.java deleted file mode 100644 index 7df652ea..00000000 --- a/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/AttackEventTrigger.java +++ /dev/null @@ -1,32 +0,0 @@ -package net.Indyuce.mmocore.api.player.profess.event.trigger; - -import io.lumine.mythic.lib.api.event.PlayerAttackEvent; -import io.lumine.mythic.lib.damage.DamageType; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.api.player.profess.PlayerClass; -import net.Indyuce.mmocore.api.player.profess.event.EventTriggerHandler; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; - -public class AttackEventTrigger implements EventTriggerHandler { - - @Override - public boolean handles(String event) { - return event.endsWith("-damage"); - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void a(PlayerAttackEvent event) { - // We don't want players dying by themselves when using an enderpearl. - if (event.getPlayer().equals(event.getEntity())) return; - - PlayerData player = PlayerData.get(event.getData().getUniqueId()); - PlayerClass profess = player.getProfess(); - - for (DamageType type : event.getAttack().getDamage().collectTypes()) { - String path = type.getPath() + "-damage"; - if (profess.hasEventTriggers(path)) - profess.getEventTriggers(path).getTriggers().forEach(trigger -> trigger.apply(player)); - } - } -} diff --git a/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/BlockBrokenTrigger.java b/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/BlockBrokenTrigger.java deleted file mode 100644 index a94e95d2..00000000 --- a/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/BlockBrokenTrigger.java +++ /dev/null @@ -1,23 +0,0 @@ -package net.Indyuce.mmocore.api.player.profess.event.trigger; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.block.BlockBreakEvent; - -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.api.player.profess.event.EventTriggerHandler; - -public class BlockBrokenTrigger implements EventTriggerHandler { - - @Override - public boolean handles(String event) { - return event.startsWith("break-block"); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void a(BlockBreakEvent event) { - PlayerData player = PlayerData.get(event.getPlayer()); - if (player.getProfess().hasEventTriggers("break-block")) - player.getProfess().getEventTriggers("break-block").getTriggers().forEach(trigger -> trigger.apply(player)); - } -} diff --git a/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/BlockPlacedTrigger.java b/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/BlockPlacedTrigger.java deleted file mode 100644 index 28681269..00000000 --- a/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/BlockPlacedTrigger.java +++ /dev/null @@ -1,23 +0,0 @@ -package net.Indyuce.mmocore.api.player.profess.event.trigger; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.block.BlockPlaceEvent; - -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.api.player.profess.event.EventTriggerHandler; - -public class BlockPlacedTrigger implements EventTriggerHandler { - - @Override - public boolean handles(String event) { - return event.startsWith("place-block"); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void a(BlockPlaceEvent event) { - PlayerData player = PlayerData.get(event.getPlayer()); - if (player.getProfess().hasEventTriggers("place-block")) - player.getProfess().getEventTriggers("place-block").getTriggers().forEach(trigger -> trigger.apply(player)); - } -} diff --git a/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/ClassChosenEventTrigger.java b/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/ClassChosenEventTrigger.java deleted file mode 100644 index d221da5b..00000000 --- a/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/ClassChosenEventTrigger.java +++ /dev/null @@ -1,28 +0,0 @@ -package net.Indyuce.mmocore.api.player.profess.event.trigger; - -import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.event.PlayerChangeClassEvent; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.api.player.profess.event.EventTriggerHandler; -import org.bukkit.Bukkit; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; - -public class ClassChosenEventTrigger implements EventTriggerHandler { - - @Override - public boolean handles(String event) { - return event.startsWith("class-chosen"); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void a(PlayerChangeClassEvent event) { - PlayerData player = event.getData(); - if (event.getNewClass().hasEventTriggers("class-chosen")) { - Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> { - event.getNewClass().getEventTriggers("class-chosen").getTriggers().forEach(trigger -> trigger.apply(player)); - }, 1); - - } - } -} diff --git a/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/LevelUpEventTrigger.java b/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/LevelUpEventTrigger.java deleted file mode 100644 index 9852ee5b..00000000 --- a/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/LevelUpEventTrigger.java +++ /dev/null @@ -1,41 +0,0 @@ -package net.Indyuce.mmocore.api.player.profess.event.trigger; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; - -import net.Indyuce.mmocore.api.event.PlayerLevelUpEvent; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.api.player.profess.PlayerClass; -import net.Indyuce.mmocore.api.player.profess.event.EventTriggerHandler; - -public class LevelUpEventTrigger implements EventTriggerHandler { - - @Override - public boolean handles(String event) { - return event.startsWith("level-up"); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void a(PlayerLevelUpEvent event) { - PlayerData player = event.getData(); - PlayerClass profess = player.getProfess(); - - for(int i = event.getOldLevel(); i < event.getNewLevel(); i++) { - int level = i + 1; - if(event.hasProfession()) { - String prof = event.getProfession().getId().toLowerCase(); - processTrigger(player, profess, "level-up-" + prof); - processTrigger(player, profess, "level-up-" + prof + "-" + level); - } else { - processTrigger(player, profess, "level-up"); - processTrigger(player, profess, "level-up-" + level); - if(profess.getMaxLevel() == level) - processTrigger(player, profess, "level-up-max"); - } - } - } - - public void processTrigger(PlayerData player, PlayerClass profess, String trigger) { - if(profess.hasEventTriggers(trigger)) profess.getEventTriggers(trigger).getTriggers().forEach(t -> t.apply(player)); - } -} diff --git a/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/MultipleLevelUpEventTrigger.java b/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/MultipleLevelUpEventTrigger.java deleted file mode 100644 index b520d374..00000000 --- a/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/MultipleLevelUpEventTrigger.java +++ /dev/null @@ -1,47 +0,0 @@ -package net.Indyuce.mmocore.api.player.profess.event.trigger; - -import net.Indyuce.mmocore.api.event.PlayerLevelUpEvent; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.api.player.profess.PlayerClass; -import net.Indyuce.mmocore.api.player.profess.event.EventTriggerHandler; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; - -import java.text.DecimalFormat; - -public class MultipleLevelUpEventTrigger implements EventTriggerHandler { - - @Override - public boolean handles(String event) { - return event.startsWith("level-up-multiple"); - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void a(PlayerLevelUpEvent event) { - PlayerData player = event.getData(); - PlayerClass profess = player.getProfess(); - - for(int i = event.getOldLevel(); i < event.getNewLevel(); i++) { - int level = i + 1; - - for (String t : profess.getEventTriggers()){ - if (t.startsWith("level-up-multiple")) { - String[] split = t.split("-"); - double multiple = Double.parseDouble(split[split.length-1]); - if (level / multiple % 1 == 0) { - DecimalFormat f = new DecimalFormat("#"); - if (event.hasProfession()) { - processTrigger(player, profess, "level-up-multiple-" + event.getProfession().getId().toLowerCase() + "-" + f.format(multiple)); - } else { - processTrigger(player, profess, "level-up-multiple-" + f.format(multiple)); - } - } - } - } - } - } - - public void processTrigger(PlayerData player, PlayerClass profess, String trigger) { - if(profess.hasEventTriggers(trigger)) profess.getEventTriggers(trigger).getTriggers().forEach(t -> t.apply(player)); - } -}