Added smarts for PvP rules in undeclared worlds.

For worlds which aren't listed in the config file because they weren't
detected when GP booted, GP will use Bukkit's world.getPvP() method.
This commit is contained in:
ryanhamshire 2015-06-17 19:11:23 -07:00
parent 4aa94fabb4
commit a3969c168c
4 changed files with 15 additions and 8 deletions

View File

@ -182,7 +182,7 @@ public class BlockEventHandler implements Listener
//FEATURE: limit fire placement, to prevent PvP-by-fire
//if placed block is fire and pvp is off, apply rules for proximity to other players
if(block.getType() == Material.FIRE && !GriefPrevention.instance.config_pvp_enabledWorlds.contains(block.getWorld()) && !player.hasPermission("griefprevention.lava"))
if(block.getType() == Material.FIRE && !GriefPrevention.instance.pvpRulesApply(block.getWorld()) && !player.hasPermission("griefprevention.lava"))
{
List<Player> players = block.getWorld().getPlayers();
for(int i = 0; i < players.size(); i++)

View File

@ -407,7 +407,7 @@ class EntityEventHandler implements Listener
World world = entity.getWorld();
//decide whether or not to apply this feature to this situation (depends on the world where it happens)
boolean isPvPWorld = GriefPrevention.instance.config_pvp_enabledWorlds.contains(world);
boolean isPvPWorld = GriefPrevention.instance.pvpRulesApply(world);
if((isPvPWorld && GriefPrevention.instance.config_lockDeathDropsInPvpWorlds) ||
(!isPvPWorld && GriefPrevention.instance.config_lockDeathDropsInNonPvpWorlds))
{
@ -537,7 +537,7 @@ class EntityEventHandler implements Listener
if(event.getEntity() instanceof Horse && !GriefPrevention.instance.config_claims_protectHorses) return;
//protect pets from environmental damage types which could be easily caused by griefers
if(event.getEntity() instanceof Tameable && !GriefPrevention.instance.config_pvp_enabledWorlds.contains(event.getEntity().getWorld()))
if(event.getEntity() instanceof Tameable && !GriefPrevention.instance.pvpRulesApply(event.getEntity().getWorld()))
{
Tameable tameable = (Tameable)event.getEntity();
if(tameable.isTamed())
@ -836,7 +836,7 @@ class EntityEventHandler implements Listener
EntityDamageByEntityEvent subEvent = (EntityDamageByEntityEvent) event;
//if not in a pvp rules world, do nothing
if(!GriefPrevention.instance.config_pvp_enabledWorlds.contains(defender.getWorld())) return;
if(!GriefPrevention.instance.pvpRulesApply(defender.getWorld())) return;
//determine which player is attacking, if any
Player attacker = null;

View File

@ -2640,7 +2640,7 @@ public class GriefPrevention extends JavaPlugin
if(!this.config_pvp_protectFreshSpawns) return;
//if pvp is disabled, do nothing
if(!this.config_pvp_enabledWorlds.contains(player.getWorld())) return;
if(!pvpRulesApply(player.getWorld())) return;
//if player is in creative mode, do nothing
if(player.getGameMode() == GameMode.CREATIVE) return;
@ -2983,4 +2983,11 @@ public class GriefPrevention extends JavaPlugin
return false;
}
public boolean pvpRulesApply(World world)
{
if(this.config_pvp_enabledWorlds.contains(world)) return true;
return world.getPVP();
}
}

View File

@ -1101,7 +1101,7 @@ class PlayerEventHandler implements Listener
return;
}
if(!GriefPrevention.instance.config_pvp_enabledWorlds.contains(entity.getLocation().getWorld()))
if(!GriefPrevention.instance.pvpRulesApply(entity.getLocation().getWorld()))
{
//otherwise disallow
OfflinePlayer owner = GriefPrevention.instance.getServer().getOfflinePlayer(ownerID);
@ -1260,7 +1260,7 @@ class PlayerEventHandler implements Listener
}
//the rest of this code is specific to pvp worlds
if(!GriefPrevention.instance.config_pvp_enabledWorlds.contains(player.getWorld())) return;
if(!GriefPrevention.instance.pvpRulesApply(player.getWorld())) return;
//if we're preventing spawn camping and the player was previously empty handed...
if(GriefPrevention.instance.config_pvp_protectFreshSpawns && (player.getItemInHand().getType() == Material.AIR))
@ -1349,7 +1349,7 @@ class PlayerEventHandler implements Listener
}
//lava buckets can't be dumped near other players unless pvp is on
if(!GriefPrevention.instance.config_pvp_enabledWorlds.contains(block.getWorld()) && !player.hasPermission("griefprevention.lava"))
if(!GriefPrevention.instance.pvpRulesApply(block.getWorld()) && !player.hasPermission("griefprevention.lava"))
{
if(bucketEvent.getBucket() == Material.LAVA_BUCKET)
{