config to prevent ravagers from breaking blocks in claims

Defaults to true to remain consistent with behavior of preventing
enderman from taking blocks and entities from trampling crops

Closes #530

Also intellij is insistent on replacing tabs
This commit is contained in:
RoboMWM 2019-07-29 21:48:33 -07:00
parent 99a676a6d1
commit cdeac80635
2 changed files with 94 additions and 82 deletions

View File

@ -144,90 +144,99 @@ public class EntityEventHandler implements Listener
else if(!GriefPrevention.instance.config_rabbitsEatCrops && event.getEntityType() == EntityType.RABBIT) else if(!GriefPrevention.instance.config_rabbitsEatCrops && event.getEntityType() == EntityType.RABBIT)
{ {
event.setCancelled(true); event.setCancelled(true);
} else if(event.getEntityType() == EntityType.WITHER && GriefPrevention.instance.config_claims_worldModes.get(event.getBlock().getWorld()) != ClaimsMode.Disabled)
{
Claim claim = this.dataStore.getClaimAt(event.getBlock().getLocation(), false, null);
if(claim == null || !claim.areExplosivesAllowed || !GriefPrevention.instance.config_blockClaimExplosions)
{
event.setCancelled(true);
}
} }
else if(GriefPrevention.instance.config_claims_worldModes.get(event.getBlock().getWorld()) != ClaimsMode.Disabled)
{
if (event.getEntityType() == EntityType.WITHER)
{
Claim claim = this.dataStore.getClaimAt(event.getBlock().getLocation(), false, null);
if (claim == null || !claim.areExplosivesAllowed || !GriefPrevention.instance.config_blockClaimExplosions)
{
event.setCancelled(true);
}
}
//don't allow crops to be trampled, except by a player with build permission else if (!GriefPrevention.instance.config_claims_ravagersBreakBlocks && event.getEntityType() == EntityType.RAVAGER)
else if(event.getTo() == Material.DIRT && event.getBlock().getType() == Material.FARMLAND) {
{ event.setCancelled(true);
if(event.getEntityType() != EntityType.PLAYER) }
{
event.setCancelled(true);
}
else
{
Player player = (Player)event.getEntity();
Block block = event.getBlock();
if(GriefPrevention.instance.allowBreak(player, block, block.getLocation()) != null)
{
event.setCancelled(true);
}
}
}
//Prevent breaking lilypads via collision with a boat. Thanks Jikoo. //don't allow crops to be trampled, except by a player with build permission
else if (event.getEntity() instanceof Vehicle && !event.getEntity().getPassengers().isEmpty()) { else if (event.getTo() == Material.DIRT && event.getBlock().getType() == Material.FARMLAND)
Entity driver = event.getEntity().getPassengers().get(0); {
if (driver instanceof Player) { if (event.getEntityType() != EntityType.PLAYER)
Block block = event.getBlock(); {
if (GriefPrevention.instance.allowBreak((Player) driver, block, block.getLocation()) != null) { event.setCancelled(true);
event.setCancelled(true); } else
} {
} Player player = (Player) event.getEntity();
} Block block = event.getBlock();
if (GriefPrevention.instance.allowBreak(player, block, block.getLocation()) != null)
{
event.setCancelled(true);
}
}
}
}
//sand cannon fix - when the falling block doesn't fall straight down, take additional anti-grief steps //Prevent breaking lilypads via collision with a boat. Thanks Jikoo.
else if (event.getEntityType() == EntityType.FALLING_BLOCK) else if (event.getEntity() instanceof Vehicle && !event.getEntity().getPassengers().isEmpty()) {
{ Entity driver = event.getEntity().getPassengers().get(0);
FallingBlock entity = (FallingBlock)event.getEntity(); if (driver instanceof Player) {
Block block = event.getBlock(); Block block = event.getBlock();
if (GriefPrevention.instance.allowBreak((Player) driver, block, block.getLocation()) != null) {
event.setCancelled(true);
}
}
}
//if changing a block TO air, this is when the falling block formed. note its original location //sand cannon fix - when the falling block doesn't fall straight down, take additional anti-grief steps
if(event.getTo() == Material.AIR) else if (event.getEntityType() == EntityType.FALLING_BLOCK)
{ {
entity.setMetadata("GP_FALLINGBLOCK", new FixedMetadataValue(GriefPrevention.instance, block.getLocation())); FallingBlock entity = (FallingBlock)event.getEntity();
} Block block = event.getBlock();
//otherwise, the falling block is forming a block. compare new location to original source
else
{
List<MetadataValue> values = entity.getMetadata("GP_FALLINGBLOCK");
//if we're not sure where this entity came from (maybe another plugin didn't follow the standard?), allow the block to form
//Or if entity fell through an end portal, allow it to form, as the event is erroneously fired twice in this scenario.
if(values.size() < 1) return;
Location originalLocation = (Location)(values.get(0).value()); //if changing a block TO air, this is when the falling block formed. note its original location
Location newLocation = block.getLocation(); if(event.getTo() == Material.AIR)
{
entity.setMetadata("GP_FALLINGBLOCK", new FixedMetadataValue(GriefPrevention.instance, block.getLocation()));
}
//otherwise, the falling block is forming a block. compare new location to original source
else
{
List<MetadataValue> values = entity.getMetadata("GP_FALLINGBLOCK");
//if we're not sure where this entity came from (maybe another plugin didn't follow the standard?), allow the block to form
//Or if entity fell through an end portal, allow it to form, as the event is erroneously fired twice in this scenario.
if(values.size() < 1) return;
//if did not fall straight down Location originalLocation = (Location)(values.get(0).value());
if(originalLocation.getBlockX() != newLocation.getBlockX() || originalLocation.getBlockZ() != newLocation.getBlockZ()) Location newLocation = block.getLocation();
{
//in creative mode worlds, never form the block
if(GriefPrevention.instance.config_claims_worldModes.get(newLocation.getWorld()) == ClaimsMode.Creative)
{
event.setCancelled(true);
return;
}
//in other worlds, if landing in land claim, only allow if source was also in the land claim //if did not fall straight down
Claim claim = this.dataStore.getClaimAt(newLocation, false, null); if(originalLocation.getBlockX() != newLocation.getBlockX() || originalLocation.getBlockZ() != newLocation.getBlockZ())
if(claim != null && !claim.contains(originalLocation, false, false)) {
{ //in creative mode worlds, never form the block
//when not allowed, drop as item instead of forming a block if(GriefPrevention.instance.config_claims_worldModes.get(newLocation.getWorld()) == ClaimsMode.Creative)
event.setCancelled(true); {
@SuppressWarnings("deprecation") event.setCancelled(true);
ItemStack itemStack = new ItemStack(entity.getMaterial(), 1); return;
Item item = block.getWorld().dropItem(entity.getLocation(), itemStack); }
item.setVelocity(new Vector());
} //in other worlds, if landing in land claim, only allow if source was also in the land claim
} Claim claim = this.dataStore.getClaimAt(newLocation, false, null);
} if(claim != null && !claim.contains(originalLocation, false, false))
} {
//when not allowed, drop as item instead of forming a block
event.setCancelled(true);
@SuppressWarnings("deprecation")
ItemStack itemStack = new ItemStack(entity.getMaterial(), 1);
Item item = block.getWorld().dropItem(entity.getLocation(), itemStack);
item.setVelocity(new Vector());
}
}
}
}
}
} }
//Used by "sand cannon" fix to ignore fallingblocks that fell through End Portals //Used by "sand cannon" fix to ignore fallingblocks that fell through End Portals

View File

@ -187,6 +187,7 @@ public class GriefPrevention extends JavaPlugin
public boolean config_smartBan; //whether to ban accounts which very likely owned by a banned player public boolean config_smartBan; //whether to ban accounts which very likely owned by a banned player
public boolean config_endermenMoveBlocks; //whether or not endermen may move blocks around public boolean config_endermenMoveBlocks; //whether or not endermen may move blocks around
public boolean config_claims_ravagersBreakBlocks; //whether or not ravagers may break blocks in claims
public boolean config_silverfishBreakBlocks; //whether silverfish may break blocks public boolean config_silverfishBreakBlocks; //whether silverfish may break blocks
public boolean config_creaturesTrampleCrops; //whether or not non-player entities may trample crops public boolean config_creaturesTrampleCrops; //whether or not non-player entities may trample crops
public boolean config_rabbitsEatCrops; //whether or not rabbits may eat crops public boolean config_rabbitsEatCrops; //whether or not rabbits may eat crops
@ -583,6 +584,7 @@ public class GriefPrevention extends JavaPlugin
String accessTrustSlashCommands = config.getString("GriefPrevention.Claims.CommandsRequiringAccessTrust", "/sethome"); String accessTrustSlashCommands = config.getString("GriefPrevention.Claims.CommandsRequiringAccessTrust", "/sethome");
this.config_claims_supplyPlayerManual = config.getBoolean("GriefPrevention.Claims.DeliverManuals", true); this.config_claims_supplyPlayerManual = config.getBoolean("GriefPrevention.Claims.DeliverManuals", true);
this.config_claims_manualDeliveryDelaySeconds = config.getInt("GriefPrevention.Claims.ManualDeliveryDelaySeconds", 30); this.config_claims_manualDeliveryDelaySeconds = config.getInt("GriefPrevention.Claims.ManualDeliveryDelaySeconds", 30);
this.config_claims_ravagersBreakBlocks = config.getBoolean("GriefPrevention.Claims.RavagersBreakBlocks", true);
this.config_claims_firespreads = config.getBoolean("GriefPrevention.Claims.FireSpreadsInClaims", false); this.config_claims_firespreads = config.getBoolean("GriefPrevention.Claims.FireSpreadsInClaims", false);
this.config_claims_firedamages = config.getBoolean("GriefPrevention.Claims.FireDamagesInClaims", false); this.config_claims_firedamages = config.getBoolean("GriefPrevention.Claims.FireDamagesInClaims", false);
@ -834,6 +836,7 @@ public class GriefPrevention extends JavaPlugin
outConfig.set("GriefPrevention.Claims.CommandsRequiringAccessTrust", accessTrustSlashCommands); outConfig.set("GriefPrevention.Claims.CommandsRequiringAccessTrust", accessTrustSlashCommands);
outConfig.set("GriefPrevention.Claims.DeliverManuals", config_claims_supplyPlayerManual); outConfig.set("GriefPrevention.Claims.DeliverManuals", config_claims_supplyPlayerManual);
outConfig.set("GriefPrevention.Claims.ManualDeliveryDelaySeconds", config_claims_manualDeliveryDelaySeconds); outConfig.set("GriefPrevention.Claims.ManualDeliveryDelaySeconds", config_claims_manualDeliveryDelaySeconds);
outConfig.set("GriefPrevention.Claims.RavagersBreakBlocks", config_claims_ravagersBreakBlocks);
outConfig.set("GriefPrevention.Claims.FireSpreadsInClaims", config_claims_firespreads); outConfig.set("GriefPrevention.Claims.FireSpreadsInClaims", config_claims_firespreads);
outConfig.set("GriefPrevention.Claims.FireDamagesInClaims", config_claims_firedamages); outConfig.set("GriefPrevention.Claims.FireDamagesInClaims", config_claims_firedamages);