diff --git a/src/main/java/kernitus/plugin/OldCombatMechanics/module/ModuleAttackCooldown.java b/src/main/java/kernitus/plugin/OldCombatMechanics/module/ModuleAttackCooldown.java index 0e2d6f22..5e2d9176 100644 --- a/src/main/java/kernitus/plugin/OldCombatMechanics/module/ModuleAttackCooldown.java +++ b/src/main/java/kernitus/plugin/OldCombatMechanics/module/ModuleAttackCooldown.java @@ -6,7 +6,6 @@ package kernitus.plugin.OldCombatMechanics.module; import kernitus.plugin.OldCombatMechanics.OCMMain; -import kernitus.plugin.OldCombatMechanics.utilities.Messenger; import org.bukkit.Bukkit; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; @@ -17,15 +16,13 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; -import java.util.Arrays; -import java.util.Objects; -import java.util.Optional; - /** * Disables the attack cooldown. */ public class ModuleAttackCooldown extends OCMModule { + private final double NEW_ATTACK_SPEED = 4; + public ModuleAttackCooldown(OCMMain plugin) { super(plugin, "disable-attack-cooldown"); } @@ -47,7 +44,7 @@ public void onWorldChange(PlayerChangedWorldEvent e) { @EventHandler(priority = EventPriority.HIGHEST) public void onPlayerQuit(PlayerQuitEvent e) { - setAttackSpeed(e.getPlayer(), PVPMode.NEW_PVP.getBaseAttackSpeed()); + setAttackSpeed(e.getPlayer(), NEW_ATTACK_SPEED); } /** @@ -58,13 +55,13 @@ public void onPlayerQuit(PlayerQuitEvent e) { private void adjustAttackSpeed(Player player) { final double attackSpeed = isEnabled(player) ? module().getDouble("generic-attack-speed") - : PVPMode.NEW_PVP.getBaseAttackSpeed(); + : NEW_ATTACK_SPEED; setAttackSpeed(player, attackSpeed); } @Override - public void onModesetChange(Player player){ + public void onModesetChange(Player player) { adjustAttackSpeed(player); } @@ -74,78 +71,17 @@ public void onModesetChange(Player player){ * @param player the player to set it for * @param attackSpeed the attack speed to set it to */ - public static void setAttackSpeed(Player player, double attackSpeed) { + public void setAttackSpeed(Player player, double attackSpeed) { final AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED); if (attribute == null) return; final double baseValue = attribute.getBaseValue(); if (baseValue != attackSpeed) { - Messenger.debug(String.format("Setting attack speed for player %s to %.2f (was: %.2f)", player.getName(), attackSpeed, baseValue)); + debug(String.format("Setting attack speed to %.2f (was: %.2f)", attackSpeed, baseValue), player); attribute.setBaseValue(attackSpeed); player.saveData(); } } - - public static void setAttackSpeed(Player player, PVPMode mode) { - setAttackSpeed(player, mode.getBaseAttackSpeed()); - } - - /** - * The different pvp modes for 1.8 or newer. - */ - public enum PVPMode { - // 40 is needed for no cooldown whatsoever - OLD_PVP("1.8", 40), - NEW_PVP("1.9+", 4); - - private final String name; - private final double baseAttackSpeed; - - PVPMode(String name, double baseAttackSpeed) { - this.name = name; - this.baseAttackSpeed = baseAttackSpeed; - } - - /** - * Returns the human-readable name of the mode. - * - * @return the human-readable name - */ - public String getName() { - return name; - } - - /** - * The {@link Attribute#GENERIC_ATTACK_SPEED} base value. - *

- * The value might be an approximation, if the attribute does not exist in the PVP mode. - * - * @return the base value - */ - public double getBaseAttackSpeed() { - return baseAttackSpeed; - } - - /** - * Returns the PVP mode for the player, defaulting to {@link #OLD_PVP}. - * - * @param player the player to get it for - * @return the PVP mode of the player - */ - public static PVPMode getModeForPlayer(Player player) { - Objects.requireNonNull(player, "Player cannot be null!"); - - final double baseAttackSpeed = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED).getBaseValue(); - - return getByBaseAttackSpeed(baseAttackSpeed).orElse(PVPMode.OLD_PVP); - } - - private static Optional getByBaseAttackSpeed(double speed) { - return Arrays.stream(values()) - .filter(pvpMode -> pvpMode.getBaseAttackSpeed() == speed) - .findFirst(); - } - } } diff --git a/src/main/java/kernitus/plugin/OldCombatMechanics/utilities/damage/EntityDamageByEntityListener.java b/src/main/java/kernitus/plugin/OldCombatMechanics/utilities/damage/EntityDamageByEntityListener.java index fd5068c0..54378cdf 100644 --- a/src/main/java/kernitus/plugin/OldCombatMechanics/utilities/damage/EntityDamageByEntityListener.java +++ b/src/main/java/kernitus/plugin/OldCombatMechanics/utilities/damage/EntityDamageByEntityListener.java @@ -178,7 +178,6 @@ public void onEntityDamage(EntityDamageEvent event) { @EventHandler(priority = EventPriority.MONITOR) public void afterEntityDamage(EntityDamageEvent event) { final Entity damagee = event.getEntity(); - debug("monitor DAMAGE to " + damagee.getName() + " CAUSE: " + event.getCause()); if (event instanceof EntityDamageByEntityEvent) { if (lastDamages.containsKey(damagee.getUniqueId())) { diff --git a/src/main/java/kernitus/plugin/OldCombatMechanics/utilities/storage/PlayerData.java b/src/main/java/kernitus/plugin/OldCombatMechanics/utilities/storage/PlayerData.java index dac9fcd4..c27aac82 100644 --- a/src/main/java/kernitus/plugin/OldCombatMechanics/utilities/storage/PlayerData.java +++ b/src/main/java/kernitus/plugin/OldCombatMechanics/utilities/storage/PlayerData.java @@ -38,7 +38,7 @@ public void setModesetForWorld(UUID worldId, String modeset) { public static PlayerData fromDocument(Document doc) { final PlayerData playerData = new PlayerData(); - Document modesetByWorldDoc = (Document) doc.get("modesetByWorld"); + final Document modesetByWorldDoc = (Document) doc.get("modesetByWorld"); if (modesetByWorldDoc != null) { for (Map.Entry entry : modesetByWorldDoc.entrySet()) { UUID worldId = UUID.fromString(entry.getKey());