Better experience around entity limits.

Armor stands weren't handled well - if a player directed an armor stand,
he may come back later to find some other items like paintings for
example missing.  Now if at the limit, no placing new armor stands or
interact with (putting items on) existing stands.
This commit is contained in:
ryanhamshire 2015-12-20 20:30:00 -08:00
parent 5e39bec04f
commit 32d65b5f58
4 changed files with 26 additions and 9 deletions

View File

@ -736,9 +736,9 @@ public class Claim
} }
//whether more entities may be added to a claim //whether more entities may be added to a claim
public String allowMoreEntities() public String allowMoreEntities(boolean remove)
{ {
if(this.parent != null) return this.parent.allowMoreEntities(); if(this.parent != null) return this.parent.allowMoreEntities(remove);
//this rule only applies to creative mode worlds //this rule only applies to creative mode worlds
if(!GriefPrevention.instance.creativeRulesApply(this.getLesserBoundaryCorner())) return null; if(!GriefPrevention.instance.creativeRulesApply(this.getLesserBoundaryCorner())) return null;
@ -765,12 +765,12 @@ public class Claim
if(!(entity instanceof Player) && this.contains(entity.getLocation(), false, false)) if(!(entity instanceof Player) && this.contains(entity.getLocation(), false, false))
{ {
totalEntities++; totalEntities++;
if(totalEntities > maxEntities) entity.remove(); if(remove && totalEntities > maxEntities) entity.remove();
} }
} }
} }
if(totalEntities > maxEntities) return GriefPrevention.instance.dataStore.getMessage(Messages.TooManyEntitiesInClaim); if(totalEntities >= maxEntities) return GriefPrevention.instance.dataStore.getMessage(Messages.TooManyEntitiesInClaim);
return null; return null;
} }

View File

@ -132,7 +132,7 @@ class EntityCleanupTask implements Runnable
if(GriefPrevention.instance.creativeRulesApply(claim.getLesserBoundaryCorner())) if(GriefPrevention.instance.creativeRulesApply(claim.getLesserBoundaryCorner()))
{ {
//check its entity count and remove any extras //check its entity count and remove any extras
claim.allowMoreEntities(); claim.allowMoreEntities(true);
} }
} }

View File

@ -389,7 +389,7 @@ public class EntityEventHandler implements Listener
//otherwise, just apply the limit on total entities per claim (and no spawning in the wilderness!) //otherwise, just apply the limit on total entities per claim (and no spawning in the wilderness!)
Claim claim = this.dataStore.getClaimAt(event.getLocation(), false, null); Claim claim = this.dataStore.getClaimAt(event.getLocation(), false, null);
if(claim == null || claim.allowMoreEntities() != null) if(claim == null || claim.allowMoreEntities(true) != null)
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;
@ -544,7 +544,7 @@ public class EntityEventHandler implements Listener
Claim claim = this.dataStore.getClaimAt(event.getBlock().getLocation(), false, playerData.lastClaim); Claim claim = this.dataStore.getClaimAt(event.getBlock().getLocation(), false, playerData.lastClaim);
if(claim == null) return; if(claim == null) return;
String noEntitiesReason = claim.allowMoreEntities(); String noEntitiesReason = claim.allowMoreEntities(false);
if(noEntitiesReason != null) if(noEntitiesReason != null)
{ {
GriefPrevention.sendMessage(event.getPlayer(), TextMode.Err, noEntitiesReason); GriefPrevention.sendMessage(event.getPlayer(), TextMode.Err, noEntitiesReason);

View File

@ -56,6 +56,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Hanging; import org.bukkit.entity.Hanging;
import org.bukkit.entity.Horse; import org.bukkit.entity.Horse;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable; import org.bukkit.entity.Tameable;
import org.bukkit.entity.Vehicle; import org.bukkit.entity.Vehicle;
@ -1248,6 +1249,22 @@ class PlayerEventHandler implements Listener
} }
} }
//limit armor placements when entity count is too high
if(entity.getType() == EntityType.ARMOR_STAND && GriefPrevention.instance.creativeRulesApply(player.getLocation()))
{
if(playerData == null) playerData = this.dataStore.getPlayerData(player.getUniqueId());
Claim claim = this.dataStore.getClaimAt(entity.getLocation(), false, playerData.lastClaim);
if(claim == null) return;
String noEntitiesReason = claim.allowMoreEntities(false);
if(noEntitiesReason != null)
{
GriefPrevention.sendMessage(player, TextMode.Err, noEntitiesReason);
event.setCancelled(true);
return;
}
}
//always allow interactions when player is in ignore claims mode //always allow interactions when player is in ignore claims mode
if(playerData.ignoreClaims) return; if(playerData.ignoreClaims) return;
@ -1814,7 +1831,7 @@ class PlayerEventHandler implements Listener
} }
//if it's a spawn egg, minecart, or boat, and this is a creative world, apply special rules //if it's a spawn egg, minecart, or boat, and this is a creative world, apply special rules
else if(clickedBlock != null && (materialInHand == Material.MINECART || materialInHand == Material.POWERED_MINECART || materialInHand == Material.STORAGE_MINECART || materialInHand == Material.BOAT) && GriefPrevention.instance.creativeRulesApply(clickedBlock.getLocation())) else if(clickedBlock != null && (materialInHand == Material.MINECART || materialInHand == Material.POWERED_MINECART || materialInHand == Material.STORAGE_MINECART || materialInHand == Material.BOAT || materialInHand == Material.ARMOR_STAND || materialInHand == Material.ITEM_FRAME || materialInHand == Material.MONSTER_EGG || materialInHand == Material.MONSTER_EGGS) && GriefPrevention.instance.creativeRulesApply(clickedBlock.getLocation()))
{ {
//player needs build permission at this location //player needs build permission at this location
String noBuildReason = GriefPrevention.instance.allowBuild(player, clickedBlock.getLocation(), Material.MINECART); String noBuildReason = GriefPrevention.instance.allowBuild(player, clickedBlock.getLocation(), Material.MINECART);
@ -1830,7 +1847,7 @@ class PlayerEventHandler implements Listener
Claim claim = this.dataStore.getClaimAt(clickedBlock.getLocation(), false, playerData.lastClaim); Claim claim = this.dataStore.getClaimAt(clickedBlock.getLocation(), false, playerData.lastClaim);
if(claim == null) return; if(claim == null) return;
String noEntitiesReason = claim.allowMoreEntities(); String noEntitiesReason = claim.allowMoreEntities(false);
if(noEntitiesReason != null) if(noEntitiesReason != null)
{ {
GriefPrevention.sendMessage(player, TextMode.Err, noEntitiesReason); GriefPrevention.sendMessage(player, TextMode.Err, noEntitiesReason);