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