From 35a890517936c21d6d4e6125f9dad9f92d61dbf5 Mon Sep 17 00:00:00 2001 From: Indyuce Date: Sat, 2 Nov 2019 18:14:50 +0100 Subject: [PATCH] Fixed x2 cooldown issue --- .../mmocore/api/player/PlayerSkillData.java | 7 +++++- .../Indyuce/mmocore/listener/SpellCast.java | 23 +++++++++++------ .../mmocore/manager/ConfigManager.java | 25 +++++++++++-------- 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/api/player/PlayerSkillData.java b/src/main/java/net/Indyuce/mmocore/api/player/PlayerSkillData.java index 4959af66..6016f1a0 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/PlayerSkillData.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/PlayerSkillData.java @@ -28,6 +28,11 @@ public class PlayerSkillData { this.data = data; } + /* + * any method which returns long RETURNS milliseconds (cooldowns are either + * stored in double when it's the actual value or in long when it's precise + * up to 3 digits) + */ public long getCooldown(SkillInfo skill) { return Math.max(0, lastCast(skill.getSkill()) + 1000 * (long) skill.getModifier("cooldown", data.getSkillLevel(skill.getSkill())) - System.currentTimeMillis()); } @@ -59,7 +64,7 @@ public class PlayerSkillData { public void cacheModifiers(MythicMobSkill mmSkill, SkillResult cast) { for (String modifier : cast.getSkill().getModifiers()) cacheModifier(mmSkill, modifier, cast.getModifier(modifier)); - + cacheModifier(mmSkill, "level", cast.getLevel()); } diff --git a/src/main/java/net/Indyuce/mmocore/listener/SpellCast.java b/src/main/java/net/Indyuce/mmocore/listener/SpellCast.java index 32fbe006..b9422110 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/SpellCast.java +++ b/src/main/java/net/Indyuce/mmocore/listener/SpellCast.java @@ -14,6 +14,7 @@ import org.bukkit.scheduler.BukkitRunnable; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.api.skill.Skill.SkillInfo; public class SpellCast implements Listener { @EventHandler @@ -106,21 +107,27 @@ public class SpellCast implements Listener { private String getFormat(PlayerData data) { String str = ""; - for (int j = 0; j < data.getBoundSkills().size(); j++) - str += (str.isEmpty() ? "" : split) + (onCooldown(data, j) && data.getBoundSkill(j).getSkill().hasModifier("cooldown") ? onCooldown.replace("{cooldown}", "" + ((int) data.getSkillData().getCooldown(data.getBoundSkill(j)) / 100) / 5) : - noMana(data, j) ? noMana : ready).replace("{index}", "" + (j + 1 + (data.getPlayer().getInventory().getHeldItemSlot() <= j ? 1 : 0))).replace("{skill}", data.getBoundSkill(j).getSkill().getName()); + for (int j = 0; j < data.getBoundSkills().size(); j++) { + SkillInfo skill = data.getBoundSkill(j); + str += (str.isEmpty() ? "" : split) + (onCooldown(data, skill) ? onCooldown.replace("{cooldown}", "" + data.getSkillData().getCooldown(skill) / 1000) : noMana(data, skill) ? noMana : ready).replace("{index}", "" + (j + 1 + (data.getPlayer().getInventory().getHeldItemSlot() <= j ? 1 : 0))).replace("{skill}", data.getBoundSkill(j).getSkill().getName()); + } return str; } - private boolean onCooldown(PlayerData data, int index) { - return data.getBoundSkill(index).getSkill().hasModifier("cooldown") && data.getSkillData().getCooldown(data.getBoundSkill(index)) > 0; + /* + * no longer use index as arguments because data.getBoundSkill(int) has + * n-complexity, it has to iterate through a list. using skillInfo + * argument uses only one iteration + */ + private boolean onCooldown(PlayerData data, SkillInfo skill) { + return skill.getSkill().hasModifier("cooldown") && data.getSkillData().getCooldown(skill) > 0; } - private boolean noMana(PlayerData data, int index) { - return data.getBoundSkill(index).getSkill().hasModifier("mana") && data.getBoundSkill(index).getModifier("mana", data.getSkillLevel(data.getBoundSkill(index).getSkill())) > data.getMana(); + private boolean noMana(PlayerData data, SkillInfo skill) { + return skill.getSkill().hasModifier("mana") && skill.getModifier("mana", data.getSkillLevel(skill.getSkill())) > data.getMana(); } - + @Override public void run() { if (!playerData.isOnline() || playerData.getPlayer().isDead()) diff --git a/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java b/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java index 5ee63042..450174b9 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java @@ -185,19 +185,22 @@ public class ConfigManager { } public class SimpleMessage { - String message; - - SimpleMessage(String m) { - message = m; + private final String message; + + SimpleMessage(String message) { + this.message = message; } - - public String message() - { return message.startsWith("%") ? message.substring(1) : message; } - + + public String message() { + return message.startsWith("%") ? message.substring(1) : message; + } + public boolean send(Player player) { - if(!message.isEmpty()) { - if(message.startsWith("%")) PlayerData.get(player.getUniqueId()).displayActionBar(message.substring(1)); - else player.sendMessage(message); + if (!message.isEmpty()) { + if (message.startsWith("%")) + PlayerData.get(player.getUniqueId()).displayActionBar(message.substring(1)); + else + player.sendMessage(message); } return !message.isEmpty(); }