Fixed PvP rules worlds config setting.

Previously applied SOME pvp rules to non-pvp worlds.
This commit is contained in:
ryanhamshire 2015-07-17 20:19:55 -07:00
parent 7b74f7b7f2
commit 797f46882b
3 changed files with 8 additions and 12 deletions

View File

@ -584,7 +584,7 @@ class EntityEventHandler implements Listener
} }
//if the attacker is a player and defender is a player (pvp combat) //if the attacker is a player and defender is a player (pvp combat)
if(attacker != null && event.getEntity() instanceof Player && GriefPrevention.instance.config_pvp_enabledWorlds.contains(attacker.getWorld())) if(attacker != null && event.getEntity() instanceof Player && GriefPrevention.instance.pvpRulesApply(attacker.getWorld()))
{ {
//FEATURE: prevent pvp in the first minute after spawn, and prevent pvp when one or both players have no inventory //FEATURE: prevent pvp in the first minute after spawn, and prevent pvp when one or both players have no inventory
@ -726,7 +726,7 @@ class EntityEventHandler implements Listener
if(attackerData.ignoreClaims) return; if(attackerData.ignoreClaims) return;
//otherwise disallow in non-pvp worlds //otherwise disallow in non-pvp worlds
if(!GriefPrevention.instance.config_pvp_enabledWorlds.contains(subEvent.getEntity().getLocation().getWorld())) if(!GriefPrevention.instance.pvpRulesApply(subEvent.getEntity().getLocation().getWorld()))
{ {
OfflinePlayer owner = GriefPrevention.instance.getServer().getOfflinePlayer(ownerID); OfflinePlayer owner = GriefPrevention.instance.getServer().getOfflinePlayer(ownerID);
String ownerName = owner.getName(); String ownerName = owner.getName();

View File

@ -124,7 +124,7 @@ public class GriefPrevention extends JavaPlugin
public String config_spam_allowedIpAddresses; //IP addresses which will not be censored public String config_spam_allowedIpAddresses; //IP addresses which will not be censored
public int config_spam_deathMessageCooldownSeconds; //cooldown period for death messages (per player) in seconds public int config_spam_deathMessageCooldownSeconds; //cooldown period for death messages (per player) in seconds
public ArrayList<World> config_pvp_enabledWorlds; //list of worlds where pvp anti-grief rules apply HashMap<World, Boolean> config_pvp_specifiedWorlds; //list of worlds where pvp anti-grief rules apply, according to the config file
public boolean config_pvp_protectFreshSpawns; //whether to make newly spawned players immune until they pick up an item public boolean config_pvp_protectFreshSpawns; //whether to make newly spawned players immune until they pick up an item
public boolean config_pvp_punishLogout; //whether to kill players who log out during PvP combat public boolean config_pvp_punishLogout; //whether to kill players who log out during PvP combat
public int config_pvp_combatTimeoutSeconds; //how long combat is considered to continue after the most recent damage public int config_pvp_combatTimeoutSeconds; //how long combat is considered to continue after the most recent damage
@ -471,14 +471,11 @@ public class GriefPrevention extends JavaPlugin
} }
//pvp worlds list //pvp worlds list
this.config_pvp_enabledWorlds = new ArrayList<World>(); this.config_pvp_specifiedWorlds = new HashMap<World, Boolean>();
for(World world : worlds) for(World world : worlds)
{ {
boolean pvpWorld = config.getBoolean("GriefPrevention.PvP.RulesEnabledInWorld." + world.getName(), world.getPVP()); boolean pvpWorld = config.getBoolean("GriefPrevention.PvP.RulesEnabledInWorld." + world.getName(), world.getPVP());
if(pvpWorld) this.config_pvp_specifiedWorlds.put(world, pvpWorld);
{
this.config_pvp_enabledWorlds.add(world);
}
} }
//sea level //sea level
@ -751,7 +748,7 @@ public class GriefPrevention extends JavaPlugin
for(World world : worlds) for(World world : worlds)
{ {
outConfig.set("GriefPrevention.PvP.RulesEnabledInWorld." + world.getName(), this.config_pvp_enabledWorlds.contains(world)); outConfig.set("GriefPrevention.PvP.RulesEnabledInWorld." + world.getName(), this.pvpRulesApply(world));
} }
outConfig.set("GriefPrevention.PvP.ProtectFreshSpawns", this.config_pvp_protectFreshSpawns); outConfig.set("GriefPrevention.PvP.ProtectFreshSpawns", this.config_pvp_protectFreshSpawns);
outConfig.set("GriefPrevention.PvP.PunishLogout", this.config_pvp_punishLogout); outConfig.set("GriefPrevention.PvP.PunishLogout", this.config_pvp_punishLogout);
@ -3006,8 +3003,8 @@ public class GriefPrevention extends JavaPlugin
public boolean pvpRulesApply(World world) public boolean pvpRulesApply(World world)
{ {
if(this.config_pvp_enabledWorlds.contains(world)) return true; Boolean configSetting = this.config_pvp_specifiedWorlds.get(world);
if(configSetting != null) return configSetting;
return world.getPVP(); return world.getPVP();
} }
} }

View File

@ -1110,7 +1110,6 @@ class PlayerEventHandler implements Listener
return; return;
} }
if(!GriefPrevention.instance.pvpRulesApply(entity.getLocation().getWorld())) if(!GriefPrevention.instance.pvpRulesApply(entity.getLocation().getWorld()))
{ {
//otherwise disallow //otherwise disallow