From 98afe494c111a605f8cceec176692c805a6875c1 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 27 Nov 2018 20:00:38 -0800 Subject: [PATCH 1/3] Add option to disable combat cooldown --- war/.gitignore | 1 + war/src/main/java/com/tommytony/war/War.java | 1 + war/src/main/java/com/tommytony/war/config/WarConfig.java | 3 ++- .../main/java/com/tommytony/war/event/WarPlayerListener.java | 3 +++ 4 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 war/.gitignore diff --git a/war/.gitignore b/war/.gitignore new file mode 100644 index 0000000..b83d222 --- /dev/null +++ b/war/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/war/src/main/java/com/tommytony/war/War.java b/war/src/main/java/com/tommytony/war/War.java index f8f2b5a..74cf770 100644 --- a/war/src/main/java/com/tommytony/war/War.java +++ b/war/src/main/java/com/tommytony/war/War.java @@ -147,6 +147,7 @@ public class War extends JavaPlugin { warConfig.put(WarConfig.LANGUAGE, Locale.getDefault().toString()); warConfig.put(WarConfig.AUTOJOIN, ""); warConfig.put(WarConfig.TPWARMUP, 0); + warConfig.put(WarConfig.DISABLECOOLDOWN, false); warzoneDefaultConfig.put(WarzoneConfig.AUTOASSIGN, false); warzoneDefaultConfig.put(WarzoneConfig.BLOCKHEADS, true); diff --git a/war/src/main/java/com/tommytony/war/config/WarConfig.java b/war/src/main/java/com/tommytony/war/config/WarConfig.java index 22cbf3a..bfc769f 100644 --- a/war/src/main/java/com/tommytony/war/config/WarConfig.java +++ b/war/src/main/java/com/tommytony/war/config/WarConfig.java @@ -13,7 +13,8 @@ public enum WarConfig { MAXSIZE (Integer.class, "Max size", "Maximum volume of a warzone"), LANGUAGE (String.class, "Language", "Preferred server language"), AUTOJOIN (String.class, "Auto-join", "Name of warzone to send players to upon join"), - TPWARMUP(Integer.class, "TP warmup", "Amount of seconds a player must wait after requesting a teleport"); + TPWARMUP(Integer.class, "TP warmup", "Amount of seconds a player must wait after requesting a teleport"), + DISABLECOOLDOWN(Boolean.class, "Disable the 1.9 combat cooldown", "Disables the attack cooldown when swinging a weapon"); private final Class configType; private final String title; diff --git a/war/src/main/java/com/tommytony/war/event/WarPlayerListener.java b/war/src/main/java/com/tommytony/war/event/WarPlayerListener.java index 6d495ed..f14cc75 100644 --- a/war/src/main/java/com/tommytony/war/event/WarPlayerListener.java +++ b/war/src/main/java/com/tommytony/war/event/WarPlayerListener.java @@ -19,6 +19,7 @@ import com.tommytony.war.utility.LoadoutSelection; import com.tommytony.war.volume.Volume; import org.apache.commons.lang.Validate; import org.bukkit.*; +import org.bukkit.attribute.Attribute; import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; import org.bukkit.entity.Item; @@ -47,6 +48,7 @@ import java.util.logging.Level; public class WarPlayerListener implements Listener { private java.util.Random random = new java.util.Random(); private HashMap latestLocations = new HashMap(); + private boolean cooldownDisabled = War.war.getWarConfig().getBoolean(WarConfig.DISABLECOOLDOWN); /** * Correctly removes quitting players from warzones @@ -70,6 +72,7 @@ public class WarPlayerListener implements Listener { @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onPlayerJoin(final PlayerJoinEvent event) { + event.getPlayer().getAttribute(Attribute.GENERIC_ATTACK_SPEED).setBaseValue(cooldownDisabled ? 1024 : 4); String autojoinName = War.war.getWarConfig().getString(WarConfig.AUTOJOIN); boolean autojoinEnabled = !autojoinName.isEmpty(); if (autojoinEnabled) { // Won't be able to find warzone if unset From 2e6466fab2fa50241d45defe76c0f45a89687531 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 27 Nov 2018 21:33:00 -0800 Subject: [PATCH 2/3] Fix NPE and reset attack speed when necessary --- war/.gitignore | 1 - .../main/java/com/tommytony/war/config/WarConfig.java | 2 +- .../com/tommytony/war/event/WarPlayerListener.java | 11 ++++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) delete mode 100644 war/.gitignore diff --git a/war/.gitignore b/war/.gitignore deleted file mode 100644 index b83d222..0000000 --- a/war/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/target/ diff --git a/war/src/main/java/com/tommytony/war/config/WarConfig.java b/war/src/main/java/com/tommytony/war/config/WarConfig.java index bfc769f..839ca43 100644 --- a/war/src/main/java/com/tommytony/war/config/WarConfig.java +++ b/war/src/main/java/com/tommytony/war/config/WarConfig.java @@ -14,7 +14,7 @@ public enum WarConfig { LANGUAGE (String.class, "Language", "Preferred server language"), AUTOJOIN (String.class, "Auto-join", "Name of warzone to send players to upon join"), TPWARMUP(Integer.class, "TP warmup", "Amount of seconds a player must wait after requesting a teleport"), - DISABLECOOLDOWN(Boolean.class, "Disable the 1.9 combat cooldown", "Disables the attack cooldown when swinging a weapon"); + DISABLECOOLDOWN (Boolean.class, "Disable the 1.9 combat cooldown", "Disables the attack cooldown when swinging a weapon"); private final Class configType; private final String title; diff --git a/war/src/main/java/com/tommytony/war/event/WarPlayerListener.java b/war/src/main/java/com/tommytony/war/event/WarPlayerListener.java index f14cc75..b95e2b0 100644 --- a/war/src/main/java/com/tommytony/war/event/WarPlayerListener.java +++ b/war/src/main/java/com/tommytony/war/event/WarPlayerListener.java @@ -47,8 +47,7 @@ import java.util.logging.Level; */ public class WarPlayerListener implements Listener { private java.util.Random random = new java.util.Random(); - private HashMap latestLocations = new HashMap(); - private boolean cooldownDisabled = War.war.getWarConfig().getBoolean(WarConfig.DISABLECOOLDOWN); + private HashMap latestLocations = new HashMap(); /** * Correctly removes quitting players from warzones @@ -68,11 +67,17 @@ public class WarPlayerListener implements Listener { War.war.removeWandBearer(player); } } + event.getPlayer().getAttribute(Attribute.GENERIC_ATTACK_SPEED).setBaseValue(4.0); } @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onPlayerJoin(final PlayerJoinEvent event) { - event.getPlayer().getAttribute(Attribute.GENERIC_ATTACK_SPEED).setBaseValue(cooldownDisabled ? 1024 : 4); + boolean cooldownDisabled = War.war.getWarConfig().getBoolean(WarConfig.DISABLECOOLDOWN); + if(cooldownDisabled) { + event.getPlayer().getAttribute(Attribute.GENERIC_ATTACK_SPEED).setBaseValue(1024.0); + } else { + event.getPlayer().getAttribute(Attribute.GENERIC_ATTACK_SPEED).setBaseValue(4.0); + } String autojoinName = War.war.getWarConfig().getString(WarConfig.AUTOJOIN); boolean autojoinEnabled = !autojoinName.isEmpty(); if (autojoinEnabled) { // Won't be able to find warzone if unset From 3217c0a7324e4e76f0b8fdab11d3ddaa42c51c05 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 28 Nov 2018 15:57:53 -0800 Subject: [PATCH 3/3] Only set player attack speed when in warzone --- war/src/main/java/com/tommytony/war/Team.java | 8 ++++++++ .../java/com/tommytony/war/event/WarPlayerListener.java | 8 -------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/war/src/main/java/com/tommytony/war/Team.java b/war/src/main/java/com/tommytony/war/Team.java index 50dc4b8..ff5f461 100644 --- a/war/src/main/java/com/tommytony/war/Team.java +++ b/war/src/main/java/com/tommytony/war/Team.java @@ -8,6 +8,7 @@ import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.OfflinePlayer; +import org.bukkit.attribute.Attribute; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; @@ -371,6 +372,12 @@ public class Team { player.setScoreboard(this.warzone.getScoreboard()); } warzone.updateScoreboard(); + boolean cooldownEnabled = War.war.getWarConfig().getBoolean(WarConfig.DISABLECOOLDOWN); + if(cooldownEnabled) { + player.getAttribute(Attribute.GENERIC_ATTACK_SPEED).setBaseValue(1024.0); + } else { + player.getAttribute(Attribute.GENERIC_ATTACK_SPEED).setBaseValue(4.0); + } } public List getPlayers() { @@ -431,6 +438,7 @@ public class Team { } this.warzone.getLoadoutSelections().remove(thePlayer); warzone.updateScoreboard(); + thePlayer.getAttribute(Attribute.GENERIC_ATTACK_SPEED).setBaseValue(4.0); } public int getRemainingLives() { diff --git a/war/src/main/java/com/tommytony/war/event/WarPlayerListener.java b/war/src/main/java/com/tommytony/war/event/WarPlayerListener.java index b95e2b0..be86ea9 100644 --- a/war/src/main/java/com/tommytony/war/event/WarPlayerListener.java +++ b/war/src/main/java/com/tommytony/war/event/WarPlayerListener.java @@ -19,7 +19,6 @@ import com.tommytony.war.utility.LoadoutSelection; import com.tommytony.war.volume.Volume; import org.apache.commons.lang.Validate; import org.bukkit.*; -import org.bukkit.attribute.Attribute; import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; import org.bukkit.entity.Item; @@ -67,17 +66,10 @@ public class WarPlayerListener implements Listener { War.war.removeWandBearer(player); } } - event.getPlayer().getAttribute(Attribute.GENERIC_ATTACK_SPEED).setBaseValue(4.0); } @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onPlayerJoin(final PlayerJoinEvent event) { - boolean cooldownDisabled = War.war.getWarConfig().getBoolean(WarConfig.DISABLECOOLDOWN); - if(cooldownDisabled) { - event.getPlayer().getAttribute(Attribute.GENERIC_ATTACK_SPEED).setBaseValue(1024.0); - } else { - event.getPlayer().getAttribute(Attribute.GENERIC_ATTACK_SPEED).setBaseValue(4.0); - } String autojoinName = War.war.getWarConfig().getString(WarConfig.AUTOJOIN); boolean autojoinEnabled = !autojoinName.isEmpty(); if (autojoinEnabled) { // Won't be able to find warzone if unset