Fix NPE and reset attack speed when necessary

This commit is contained in:
= 2018-11-27 21:33:00 -08:00
parent 98afe494c1
commit 2e6466fab2
No known key found for this signature in database
GPG Key ID: 918580825B8F6862
3 changed files with 9 additions and 5 deletions

1
war/.gitignore vendored
View File

@ -1 +0,0 @@
/target/

View File

@ -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;

View File

@ -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<String, Location> latestLocations = new HashMap<String, Location>();
private boolean cooldownDisabled = War.war.getWarConfig().getBoolean(WarConfig.DISABLECOOLDOWN);
private HashMap<String, Location> latestLocations = new HashMap<String, Location>();
/**
* 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