From 32d65b5f58526d87a3b9f97ee3c5481cf16f262e Mon Sep 17 00:00:00 2001 From: ryanhamshire Date: Sun, 20 Dec 2015 20:30:00 -0800 Subject: [PATCH] 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. --- .../ryanhamshire/GriefPrevention/Claim.java | 8 +++---- .../GriefPrevention/EntityCleanupTask.java | 2 +- .../GriefPrevention/EntityEventHandler.java | 4 ++-- .../GriefPrevention/PlayerEventHandler.java | 21 +++++++++++++++++-- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/me/ryanhamshire/GriefPrevention/Claim.java b/src/me/ryanhamshire/GriefPrevention/Claim.java index 2e3307b..3b552f3 100644 --- a/src/me/ryanhamshire/GriefPrevention/Claim.java +++ b/src/me/ryanhamshire/GriefPrevention/Claim.java @@ -736,9 +736,9 @@ public class 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 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)) { 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; } diff --git a/src/me/ryanhamshire/GriefPrevention/EntityCleanupTask.java b/src/me/ryanhamshire/GriefPrevention/EntityCleanupTask.java index 234d82f..a2f602d 100644 --- a/src/me/ryanhamshire/GriefPrevention/EntityCleanupTask.java +++ b/src/me/ryanhamshire/GriefPrevention/EntityCleanupTask.java @@ -132,7 +132,7 @@ class EntityCleanupTask implements Runnable if(GriefPrevention.instance.creativeRulesApply(claim.getLesserBoundaryCorner())) { //check its entity count and remove any extras - claim.allowMoreEntities(); + claim.allowMoreEntities(true); } } diff --git a/src/me/ryanhamshire/GriefPrevention/EntityEventHandler.java b/src/me/ryanhamshire/GriefPrevention/EntityEventHandler.java index e51091a..5f97d4b 100644 --- a/src/me/ryanhamshire/GriefPrevention/EntityEventHandler.java +++ b/src/me/ryanhamshire/GriefPrevention/EntityEventHandler.java @@ -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!) 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); return; @@ -544,7 +544,7 @@ public class EntityEventHandler implements Listener Claim claim = this.dataStore.getClaimAt(event.getBlock().getLocation(), false, playerData.lastClaim); if(claim == null) return; - String noEntitiesReason = claim.allowMoreEntities(); + String noEntitiesReason = claim.allowMoreEntities(false); if(noEntitiesReason != null) { GriefPrevention.sendMessage(event.getPlayer(), TextMode.Err, noEntitiesReason); diff --git a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java index 67de154..9b13343 100644 --- a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java +++ b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java @@ -56,6 +56,7 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.Hanging; import org.bukkit.entity.Horse; import org.bukkit.entity.Item; +import org.bukkit.entity.ItemFrame; import org.bukkit.entity.Player; import org.bukkit.entity.Tameable; 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 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 - 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 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); if(claim == null) return; - String noEntitiesReason = claim.allowMoreEntities(); + String noEntitiesReason = claim.allowMoreEntities(false); if(noEntitiesReason != null) { GriefPrevention.sendMessage(player, TextMode.Err, noEntitiesReason);