From ed0dfe95c2e4db3220d6cbc12de40d881e514b5a Mon Sep 17 00:00:00 2001 From: Jules Date: Mon, 7 Feb 2022 20:27:05 +0100 Subject: [PATCH] Prev commit rollback, added /mi update apply 7 --- .../mmoitems/gui/edition/AbilityEdition.java | 2 +- .../mmoitems/listener/PlayerListener.java | 7 ++----- .../Indyuce/mmoitems/manager/ConfigManager.java | 2 +- .../mmoitems/manager/PluginUpdateManager.java | 17 +++++++++++++++++ .../Indyuce/mmoitems/skill/RegisteredSkill.java | 3 +-- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/Indyuce/mmoitems/gui/edition/AbilityEdition.java b/src/main/java/net/Indyuce/mmoitems/gui/edition/AbilityEdition.java index 50d4d3c3..4cee806b 100644 --- a/src/main/java/net/Indyuce/mmoitems/gui/edition/AbilityEdition.java +++ b/src/main/java/net/Indyuce/mmoitems/gui/edition/AbilityEdition.java @@ -98,7 +98,7 @@ public class AbilityEdition extends EditionInventory { if (ability != null) { ConfigurationSection section = getEditedSection().getConfigurationSection("ability." + configKey); - for (String modifier : ((SkillHandler) ability.getHandler()).getModifiers()) { + for (String modifier : ability.getHandler().getModifiers()) { ItemStack modifierItem = VersionMaterial.GRAY_DYE.toItem(); ItemMeta modifierItemMeta = modifierItem.getItemMeta(); modifierItemMeta.setDisplayName(ChatColor.GREEN + MMOUtils.caseOnWords(modifier.toLowerCase().replace("-", " "))); diff --git a/src/main/java/net/Indyuce/mmoitems/listener/PlayerListener.java b/src/main/java/net/Indyuce/mmoitems/listener/PlayerListener.java index 0baad61c..87a60b84 100644 --- a/src/main/java/net/Indyuce/mmoitems/listener/PlayerListener.java +++ b/src/main/java/net/Indyuce/mmoitems/listener/PlayerListener.java @@ -326,18 +326,15 @@ public class PlayerListener implements Listener { // Create registered skill RegisteredSkill registeredSkill = new RegisteredSkill(event.getCast().getHandler(), event.getCast().getHandler().getId()); - for (Object obj : event.getCast().getHandler().getModifiers()) { - String mod = obj.toString(); + for (String mod : event.getCast().getHandler().getModifiers()) { registeredSkill.setDefaultValue(mod, event.getMetadata().getModifier(mod)); registeredSkill.setName(mod, MMOUtils.caseOnWords(mod.toLowerCase().replace("-", " ").replace("_", " "))); } // Create ability data AbilityData abilityData = new AbilityData(registeredSkill, TriggerType.API); - for (Object obj : event.getCast().getHandler().getModifiers()) { - String mod = obj.toString(); + for (String mod : event.getCast().getHandler().getModifiers()) abilityData.setModifier(mod, event.getMetadata().getModifier(mod)); - } // Find ability target LivingEntity target = event.getMetadata().hasTargetEntity() && event.getMetadata().getTargetEntityOrNull() instanceof LivingEntity ? diff --git a/src/main/java/net/Indyuce/mmoitems/manager/ConfigManager.java b/src/main/java/net/Indyuce/mmoitems/manager/ConfigManager.java index 37b94126..3b49e703 100644 --- a/src/main/java/net/Indyuce/mmoitems/manager/ConfigManager.java +++ b/src/main/java/net/Indyuce/mmoitems/manager/ConfigManager.java @@ -134,7 +134,7 @@ public class ConfigManager implements Reloadable { if (!abilities.getConfig().getKeys(true).contains("ability." + path)) abilities.getConfig().set("ability." + path, ability.getName()); - for (String modifier : ((SkillHandler) ability.getHandler()).getModifiers()) + for (String modifier : ability.getHandler().getModifiers()) if (!abilities.getConfig().getKeys(true).contains("modifier." + modifier)) abilities.getConfig().set("modifier." + modifier, MMOUtils.caseOnWords(modifier.replace("-", " "))); } diff --git a/src/main/java/net/Indyuce/mmoitems/manager/PluginUpdateManager.java b/src/main/java/net/Indyuce/mmoitems/manager/PluginUpdateManager.java index 2cd0a277..b3aa7923 100644 --- a/src/main/java/net/Indyuce/mmoitems/manager/PluginUpdateManager.java +++ b/src/main/java/net/Indyuce/mmoitems/manager/PluginUpdateManager.java @@ -1,5 +1,7 @@ package net.Indyuce.mmoitems.manager; +import io.lumine.mythic.lib.MythicLib; +import io.lumine.mythic.lib.skill.handler.SkillHandler; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.ConfigFile; import net.Indyuce.mmoitems.api.PluginUpdate; @@ -246,6 +248,21 @@ public class PluginUpdateManager { sender.sendMessage("Config updates successfully applied, reloading skills.."); MMOItems.plugin.getSkills().initialize(true); })); + + register(new PluginUpdate(7, new String[]{"MI 6.7 introduced a 'timer' skill modifier for all skills.", + "This update registers that modifier in every of your skills.", + "Has to be ran after &6/mi update apply 6&7."}, sender -> { + + for (SkillHandler handler : MythicLib.plugin.getSkills().getHandlers()) { + ConfigFile config = new ConfigFile("/skill", handler.getLowerCaseId()); + config.getConfig().set("modifier.timer.name", "Timer"); + config.getConfig().set("modifier.timer.default-value", 0d); + config.save(); + } + + sender.sendMessage("Config updates successfully applied, reloading skills.."); + MMOItems.plugin.getSkills().initialize(true); + })); } public void register(PluginUpdate update) { diff --git a/src/main/java/net/Indyuce/mmoitems/skill/RegisteredSkill.java b/src/main/java/net/Indyuce/mmoitems/skill/RegisteredSkill.java index e86aeac7..8ff00add 100644 --- a/src/main/java/net/Indyuce/mmoitems/skill/RegisteredSkill.java +++ b/src/main/java/net/Indyuce/mmoitems/skill/RegisteredSkill.java @@ -1,6 +1,5 @@ package net.Indyuce.mmoitems.skill; -import io.lumine.mythic.lib.UtilityMethods; import io.lumine.mythic.lib.skill.handler.SkillHandler; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOUtils; @@ -24,7 +23,7 @@ public class RegisteredSkill { this.name = Objects.requireNonNull(config.getString("name"), "Could not fill skill name"); for (String mod : handler.getModifiers()) { - modifierNames.put(mod, config.getString("modifier." + mod + ".name", UtilityMethods.caseOnWords(mod.replace("-", " ")))); + modifierNames.put(mod, Objects.requireNonNull(config.getString("modifier." + mod + ".name"), "Could not find translation for modifier '" + mod + "'")); modifierDefaultValues.put(mod, config.getDouble("modifier." + mod + ".default-value")); } }