From ca6024e15192d012117450748c13a515dab74ddc Mon Sep 17 00:00:00 2001 From: ryanhamshire Date: Sun, 19 Oct 2014 13:19:53 -0700 Subject: [PATCH] Redesigned per-world claim mode configuration. Much easier to understand and customize, especially for server owners who are new to GP and have both survival and creative worlds. Also, a performance improvement - when claim creation is disabled in a world, GP will not protect any existing claims in that world. --- .../GriefPrevention/BlockEventHandler.java | 31 ++- .../GriefPrevention/ClaimsMode.java | 8 + .../GriefPrevention/DataStore.java | 2 +- .../GriefPrevention/EntityCleanupTask.java | 9 +- .../GriefPrevention/EntityEventHandler.java | 23 ++- .../GriefPrevention/GriefPrevention.java | 193 +++++++++++------- .../GriefPrevention/PlayerEventHandler.java | 17 +- 7 files changed, 198 insertions(+), 85 deletions(-) create mode 100644 src/me/ryanhamshire/GriefPrevention/ClaimsMode.java diff --git a/src/me/ryanhamshire/GriefPrevention/BlockEventHandler.java b/src/me/ryanhamshire/GriefPrevention/BlockEventHandler.java index a25e14c..38bc76d 100644 --- a/src/me/ryanhamshire/GriefPrevention/BlockEventHandler.java +++ b/src/me/ryanhamshire/GriefPrevention/BlockEventHandler.java @@ -187,6 +187,9 @@ public class BlockEventHandler implements Listener } } + //don't track in worlds where claims are not enabled + if(!GriefPrevention.instance.claimsEnabledForWorld(placeEvent.getBlock().getWorld())) return; + //make sure the player is allowed to build at the location String noBuildReason = GriefPrevention.instance.allowBuild(player, block.getLocation()); if(noBuildReason != null) @@ -370,9 +373,12 @@ public class BlockEventHandler implements Listener @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onBlockPistonExtend (BlockPistonExtendEvent event) { - //pushing down is ALWAYS safe + //pushing down is ALWAYS safe if(event.getDirection() == BlockFace.DOWN) return; + //don't track in worlds where claims are not enabled + if(!GriefPrevention.instance.claimsEnabledForWorld(event.getBlock().getWorld())) return; + Block pistonBlock = event.getBlock(); List blocks = event.getBlocks(); @@ -489,7 +495,7 @@ public class BlockEventHandler implements Listener @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onBlockPistonRetract (BlockPistonRetractEvent event) { - //we only care about sticky pistons retracting + //we only care about sticky pistons retracting if(!event.isSticky()) return; //pulling up is always safe @@ -498,6 +504,9 @@ public class BlockEventHandler implements Listener //if pulling "air", always safe if(event.getRetractLocation().getBlock().getType() == Material.AIR) return; + //don't track in worlds where claims are not enabled + if(!GriefPrevention.instance.claimsEnabledForWorld(event.getBlock().getWorld())) return; + //if pistons limited to only pulling blocks which are in the same claim the piston is in if(GriefPrevention.instance.config_pistonsInClaimsOnly) { @@ -569,6 +578,9 @@ public class BlockEventHandler implements Listener return; } + //don't track in worlds where claims are not enabled + if(!GriefPrevention.instance.claimsEnabledForWorld(spreadEvent.getBlock().getWorld())) return; + //never spread into a claimed area, regardless of settings if(this.dataStore.getClaimAt(spreadEvent.getBlock().getLocation(), false, null) != null) { @@ -619,6 +631,9 @@ public class BlockEventHandler implements Listener return; } + //don't track in worlds where claims are not enabled + if(!GriefPrevention.instance.claimsEnabledForWorld(burnEvent.getBlock().getWorld())) return; + //never burn claimed blocks, regardless of settings if(this.dataStore.getClaimAt(burnEvent.getBlock().getLocation(), false, null) != null) { @@ -632,8 +647,8 @@ public class BlockEventHandler implements Listener @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onBlockFromTo (BlockFromToEvent spreadEvent) { - //don't track fluid movement in worlds where claims are not enabled - if(!GriefPrevention.instance.config_claims_enabledWorlds.contains(spreadEvent.getBlock().getWorld())) return; + //don't track in worlds where claims are not enabled + if(!GriefPrevention.instance.claimsEnabledForWorld(spreadEvent.getBlock().getWorld())) return; //always allow fluids to flow straight down if(spreadEvent.getFace() == BlockFace.DOWN) return; @@ -681,7 +696,10 @@ public class BlockEventHandler implements Listener @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onDispense(BlockDispenseEvent dispenseEvent) { - //from where? + //don't track in worlds where claims are not enabled + if(!GriefPrevention.instance.claimsEnabledForWorld(dispenseEvent.getBlock().getWorld())) return; + + //from where? Block fromBlock = dispenseEvent.getBlock(); Dispenser dispenser = new Dispenser(fromBlock.getType(), fromBlock.getData()); @@ -714,6 +732,9 @@ public class BlockEventHandler implements Listener //only take these potentially expensive steps if configured to do so if(!GriefPrevention.instance.config_limitTreeGrowth) return; + //don't track in worlds where claims are not enabled + if(!GriefPrevention.instance.claimsEnabledForWorld(growEvent.getWorld())) return; + Location rootLocation = growEvent.getLocation(); Claim rootClaim = this.dataStore.getClaimAt(rootLocation, false, null); String rootOwnerName = null; diff --git a/src/me/ryanhamshire/GriefPrevention/ClaimsMode.java b/src/me/ryanhamshire/GriefPrevention/ClaimsMode.java new file mode 100644 index 0000000..7764e88 --- /dev/null +++ b/src/me/ryanhamshire/GriefPrevention/ClaimsMode.java @@ -0,0 +1,8 @@ +package me.ryanhamshire.GriefPrevention; + +public enum ClaimsMode +{ + Survival, + Creative, + Disabled +} \ No newline at end of file diff --git a/src/me/ryanhamshire/GriefPrevention/DataStore.java b/src/me/ryanhamshire/GriefPrevention/DataStore.java index 5fbe4fc..4c678f7 100644 --- a/src/me/ryanhamshire/GriefPrevention/DataStore.java +++ b/src/me/ryanhamshire/GriefPrevention/DataStore.java @@ -512,7 +512,7 @@ public abstract class DataStore } //creative mode claims always go to bedrock - if(GriefPrevention.instance.config_claims_enabledCreativeWorlds.contains(world)) + if(GriefPrevention.instance.config_claims_worldModes.get(world) == ClaimsMode.Creative) { smally = 2; } diff --git a/src/me/ryanhamshire/GriefPrevention/EntityCleanupTask.java b/src/me/ryanhamshire/GriefPrevention/EntityCleanupTask.java index 0d0b7aa..234d82f 100644 --- a/src/me/ryanhamshire/GriefPrevention/EntityCleanupTask.java +++ b/src/me/ryanhamshire/GriefPrevention/EntityCleanupTask.java @@ -45,7 +45,14 @@ class EntityCleanupTask implements Runnable @Override public void run() { - ArrayList worlds = GriefPrevention.instance.config_claims_enabledCreativeWorlds; + ArrayList worlds = new ArrayList(); + for(World world : GriefPrevention.instance.getServer().getWorlds()) + { + if(GriefPrevention.instance.config_claims_worldModes.get(world) == ClaimsMode.Creative) + { + worlds.add(world); + } + } for(int i = 0; i < worlds.size(); i++) { diff --git a/src/me/ryanhamshire/GriefPrevention/EntityEventHandler.java b/src/me/ryanhamshire/GriefPrevention/EntityEventHandler.java index 90118be..ce2d039 100644 --- a/src/me/ryanhamshire/GriefPrevention/EntityEventHandler.java +++ b/src/me/ryanhamshire/GriefPrevention/EntityEventHandler.java @@ -88,7 +88,7 @@ class EntityEventHandler implements Listener } //don't allow the wither to break blocks, when the wither is determined, too expensive to constantly check for claimed blocks - else if(event.getEntityType() == EntityType.WITHER && GriefPrevention.instance.config_claims_enabledWorlds.contains(event.getBlock().getWorld())) + else if(event.getEntityType() == EntityType.WITHER && GriefPrevention.instance.config_claims_worldModes.get(event.getBlock().getWorld()) != ClaimsMode.Disabled) { event.setCancelled(true); } @@ -120,7 +120,7 @@ class EntityEventHandler implements Listener //FEATURE: explosions don't destroy blocks when they explode near or above sea level in standard worlds boolean isCreeper = (explodeEvent.getEntity() != null && explodeEvent.getEntity() instanceof Creeper); - if( location.getWorld().getEnvironment() == Environment.NORMAL && GriefPrevention.instance.config_claims_enabledWorlds.contains(location.getWorld()) && ((isCreeper && GriefPrevention.instance.config_blockSurfaceCreeperExplosions) || (!isCreeper && GriefPrevention.instance.config_blockSurfaceOtherExplosions))) + if( location.getWorld().getEnvironment() == Environment.NORMAL && GriefPrevention.instance.claimsEnabledForWorld(location.getWorld()) && ((isCreeper && GriefPrevention.instance.config_blockSurfaceCreeperExplosions) || (!isCreeper && GriefPrevention.instance.config_blockSurfaceOtherExplosions))) { for(int i = 0; i < blocks.size(); i++) { @@ -224,6 +224,9 @@ class EntityEventHandler implements Listener { LivingEntity entity = event.getEntity(); + //don't track in worlds where claims are not enabled + if(!GriefPrevention.instance.claimsEnabledForWorld(entity.getWorld())) return; + //special rule for creative worlds: killed entities don't drop items or experience orbs if(GriefPrevention.instance.creativeRulesApply(entity.getLocation())) { @@ -272,7 +275,10 @@ class EntityEventHandler implements Listener @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onHangingBreak(HangingBreakEvent event) { - //FEATURE: claimed paintings are protected from breakage + //don't track in worlds where claims are not enabled + if(!GriefPrevention.instance.claimsEnabledForWorld(event.getEntity().getWorld())) return; + + //FEATURE: claimed paintings are protected from breakage //explosions don't destroy hangings if(event.getCause() == RemoveCause.EXPLOSION) @@ -314,7 +320,10 @@ class EntityEventHandler implements Listener @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onPaintingPlace(HangingPlaceEvent event) { - //FEATURE: similar to above, placing a painting requires build permission in the claim + //don't track in worlds where claims are not enabled + if(!GriefPrevention.instance.claimsEnabledForWorld(event.getBlock().getWorld())) return; + + //FEATURE: similar to above, placing a painting requires build permission in the claim //if the player doesn't have permission, don't allow the placement String noBuildReason = GriefPrevention.instance.allowBuild(event.getPlayer(), event.getEntity().getLocation()); @@ -454,6 +463,9 @@ class EntityEventHandler implements Listener //if theft protection is enabled if(event instanceof EntityDamageByEntityEvent) { + //don't track in worlds where claims are not enabled + if(!GriefPrevention.instance.claimsEnabledForWorld(event.getEntity().getWorld())) return; + //if the damaged entity is a claimed item frame, the damager needs to be a player with container trust in the claim if(subEvent.getEntityType() == EntityType.ITEM_FRAME) { @@ -561,6 +573,9 @@ class EntityEventHandler implements Listener //all of this is anti theft code if(!GriefPrevention.instance.config_claims_preventTheft) return; + //don't track in worlds where claims are not enabled + if(!GriefPrevention.instance.claimsEnabledForWorld(event.getVehicle().getWorld())) return; + //determine which player is attacking, if any Player attacker = null; Entity damageSource = event.getAttacker(); diff --git a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java index 77d55a1..9c017c3 100644 --- a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java +++ b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java @@ -63,8 +63,9 @@ public class GriefPrevention extends JavaPlugin public DataStore dataStore; //configuration variables, loaded/saved from a config.yml - public ArrayList config_claims_enabledWorlds; //list of worlds where players can create GriefPrevention claims - public ArrayList config_claims_enabledCreativeWorlds; //list of worlds where additional creative mode anti-grief rules apply + + //claim mode for each world + public ConcurrentHashMap config_claims_worldModes = new ConcurrentHashMap(); public boolean config_claims_preventTheft; //whether containers and crafting blocks are protectable public boolean config_claims_protectCreatures; //whether claimed animals may be injured by players without permission @@ -178,72 +179,103 @@ public class GriefPrevention extends JavaPlugin //read configuration settings (note defaults) - //default for claims worlds list - ArrayList defaultClaimsWorldNames = new ArrayList(); - List worlds = this.getServer().getWorlds(); - for(int i = 0; i < worlds.size(); i++) - { - defaultClaimsWorldNames.add(worlds.get(i).getName()); - } - - //get claims world names from the config file - List claimsEnabledWorldNames = config.getStringList("GriefPrevention.Claims.Worlds"); - if(claimsEnabledWorldNames == null || claimsEnabledWorldNames.size() == 0) - { - claimsEnabledWorldNames = defaultClaimsWorldNames; - } + //get (deprecated node) claims world names from the config file + List worlds = this.getServer().getWorlds(); + List deprecated_claimsEnabledWorldNames = config.getStringList("GriefPrevention.Claims.Worlds"); //validate that list - this.config_claims_enabledWorlds = new ArrayList(); - for(int i = 0; i < claimsEnabledWorldNames.size(); i++) + for(int i = 0; i < deprecated_claimsEnabledWorldNames.size(); i++) { - String worldName = claimsEnabledWorldNames.get(i); + String worldName = deprecated_claimsEnabledWorldNames.get(i); World world = this.getServer().getWorld(worldName); if(world == null) { - AddLogEntry("Error: Claims Configuration: There's no world named \"" + worldName + "\". Please update your config.yml."); - } - else - { - this.config_claims_enabledWorlds.add(world); + deprecated_claimsEnabledWorldNames.remove(i--); } } - //default creative claim world names - List defaultCreativeWorldNames = new ArrayList(); - - //if default game mode for the server is creative, creative rules will apply to all worlds unless the config specifies otherwise - if(this.getServer().getDefaultGameMode() == GameMode.CREATIVE) - { - for(int i = 0; i < defaultClaimsWorldNames.size(); i++) - { - defaultCreativeWorldNames.add(defaultClaimsWorldNames.get(i)); - } - } - - //get creative world names from the config file - List creativeClaimsEnabledWorldNames = config.getStringList("GriefPrevention.Claims.CreativeRulesWorlds"); - if(creativeClaimsEnabledWorldNames == null || creativeClaimsEnabledWorldNames.size() == 0) - { - creativeClaimsEnabledWorldNames = defaultCreativeWorldNames; - } + //get (deprecated node) creative world names from the config file + List deprecated_creativeClaimsEnabledWorldNames = config.getStringList("GriefPrevention.Claims.CreativeRulesWorlds"); //validate that list - this.config_claims_enabledCreativeWorlds = new ArrayList(); - for(int i = 0; i < creativeClaimsEnabledWorldNames.size(); i++) + for(int i = 0; i < deprecated_creativeClaimsEnabledWorldNames.size(); i++) { - String worldName = creativeClaimsEnabledWorldNames.get(i); + String worldName = deprecated_creativeClaimsEnabledWorldNames.get(i); World world = this.getServer().getWorld(worldName); if(world == null) { - AddLogEntry("Error: Claims Configuration: There's no world named \"" + worldName + "\". Please update your config.yml."); - } - else - { - this.config_claims_enabledCreativeWorlds.add(world); + deprecated_claimsEnabledWorldNames.remove(i--); } } + //decide claim mode for each world + for(World world : worlds) + { + //is it specified in the config file? + String configSetting = config.getString("GriefPrevention.Claims.Mode." + world.getName()); + if(configSetting != null) + { + ClaimsMode claimsMode = this.configStringToClaimsMode(configSetting); + if(claimsMode != null) + { + this.config_claims_worldModes.put(world, claimsMode); + continue; + } + else + { + GriefPrevention.AddLogEntry("Error: Invalid claim mode \"" + configSetting + "\". Options are Survival, Creative, and Disabled."); + this.config_claims_worldModes.put(world, ClaimsMode.Creative); + } + } + + //was it specified in a deprecated config node? + if(deprecated_creativeClaimsEnabledWorldNames.contains(world.getName())) + { + this.config_claims_worldModes.put(world, ClaimsMode.Creative); + } + + else if(deprecated_claimsEnabledWorldNames.contains(world.getName())) + { + this.config_claims_worldModes.put(world, ClaimsMode.Survival); + } + + //does the world's name indicate its purpose? + else if(world.getName().toLowerCase().contains("survival")) + { + this.config_claims_worldModes.put(world, ClaimsMode.Survival); + } + + else if(world.getName().toLowerCase().contains("creative")) + { + this.config_claims_worldModes.put(world, ClaimsMode.Creative); + } + + //decide a default based on server type and world type + else if(this.getServer().getDefaultGameMode() == GameMode.CREATIVE) + { + this.config_claims_worldModes.put(world, ClaimsMode.Creative); + } + + else if(world.getEnvironment() == Environment.NORMAL) + { + this.config_claims_worldModes.put(world, ClaimsMode.Survival); + } + + else + { + this.config_claims_worldModes.put(world, ClaimsMode.Disabled); + } + + //if the setting WOULD be disabled but this is a server upgrading from the old config format, + //then default to survival mode for safety's sake (to protect any admin claims which may + //have been created there) + if(this.config_claims_worldModes.get(world) == ClaimsMode.Disabled && + deprecated_claimsEnabledWorldNames.size() > 0) + { + this.config_claims_worldModes.put(world, ClaimsMode.Survival); + } + } + //default for pvp worlds list ArrayList defaultPvpWorldNames = new ArrayList(); for(int i = 0; i < worlds.size(); i++) @@ -303,19 +335,10 @@ public class GriefPrevention extends JavaPlugin this.config_claims_minSize = config.getInt("GriefPrevention.Claims.MinimumSize", 10); this.config_claims_maxDepth = config.getInt("GriefPrevention.Claims.MaximumDepth", 0); this.config_claims_trappedCooldownHours = config.getInt("GriefPrevention.Claims.TrappedCommandCooldownHours", 8); - this.config_claims_chestClaimExpirationDays = config.getInt("GriefPrevention.Claims.Expiration.ChestClaimDays", 7); - outConfig.set("GriefPrevention.Claims.Expiration.ChestClaimDays", this.config_claims_chestClaimExpirationDays); - this.config_claims_unusedClaimExpirationDays = config.getInt("GriefPrevention.Claims.Expiration.UnusedClaimDays", 14); - outConfig.set("GriefPrevention.Claims.Expiration.UnusedClaimDays", this.config_claims_unusedClaimExpirationDays); - this.config_claims_expirationDays = config.getInt("GriefPrevention.Claims.Expiration.AllClaimDays", 0); - outConfig.set("GriefPrevention.Claims.Expiration.AllClaimDays", this.config_claims_expirationDays); - this.config_claims_survivalAutoNatureRestoration = config.getBoolean("GriefPrevention.Claims.Expiration.AutomaticNatureRestoration.SurvivalWorlds", false); - outConfig.set("GriefPrevention.Claims.Expiration.AutomaticNatureRestoration.SurvivalWorlds", this.config_claims_survivalAutoNatureRestoration); - this.config_spam_enabled = config.getBoolean("GriefPrevention.Spam.Enabled", true); this.config_spam_loginCooldownSeconds = config.getInt("GriefPrevention.Spam.LoginCooldownSeconds", 60); this.config_spam_warningMessage = config.getString("GriefPrevention.Spam.WarningMessage", "Please reduce your noise level. Spammers will be banned."); @@ -534,8 +557,14 @@ public class GriefPrevention extends JavaPlugin String databaseUserName = config.getString("GriefPrevention.Database.UserName", ""); String databasePassword = config.getString("GriefPrevention.Database.Password", ""); - outConfig.set("GriefPrevention.Claims.Worlds", claimsEnabledWorldNames); - outConfig.set("GriefPrevention.Claims.CreativeRulesWorlds", creativeClaimsEnabledWorldNames); + //claims mode by world + for(World world : this.config_claims_worldModes.keySet()) + { + outConfig.set( + "GriefPrevention.Claims.Mode." + world.getName(), + this.config_claims_worldModes.get(world).name()); + } + outConfig.set("GriefPrevention.Claims.PreventTheft", this.config_claims_preventTheft); outConfig.set("GriefPrevention.Claims.ProtectCreatures", this.config_claims_protectCreatures); outConfig.set("GriefPrevention.Claims.PreventButtonsSwitches", this.config_claims_preventButtonsSwitches); @@ -555,6 +584,10 @@ public class GriefPrevention extends JavaPlugin outConfig.set("GriefPrevention.Claims.TrappedCommandCooldownHours", this.config_claims_trappedCooldownHours); outConfig.set("GriefPrevention.Claims.InvestigationTool", this.config_claims_investigationTool.name()); outConfig.set("GriefPrevention.Claims.ModificationTool", this.config_claims_modificationTool.name()); + outConfig.set("GriefPrevention.Claims.Expiration.ChestClaimDays", this.config_claims_chestClaimExpirationDays); + outConfig.set("GriefPrevention.Claims.Expiration.UnusedClaimDays", this.config_claims_unusedClaimExpirationDays); + outConfig.set("GriefPrevention.Claims.Expiration.AllClaimDays", this.config_claims_expirationDays); + outConfig.set("GriefPrevention.Claims.Expiration.AutomaticNatureRestoration.SurvivalWorlds", this.config_claims_survivalAutoNatureRestoration); outConfig.set("GriefPrevention.Spam.Enabled", this.config_spam_enabled); outConfig.set("GriefPrevention.Spam.LoginCooldownSeconds", this.config_spam_loginCooldownSeconds); @@ -775,7 +808,27 @@ public class GriefPrevention extends JavaPlugin AddLogEntry("Boot finished."); } - //handles slash commands + private ClaimsMode configStringToClaimsMode(String configSetting) + { + if(configSetting.equalsIgnoreCase("Survival")) + { + return ClaimsMode.Survival; + } + else if(configSetting.equalsIgnoreCase("Creative")) + { + return ClaimsMode.Creative; + } + else if(configSetting.equalsIgnoreCase("Disabled")) + { + return ClaimsMode.Disabled; + } + else + { + return null; + } + } + + //handles slash commands public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){ Player player = null; @@ -2275,12 +2328,6 @@ public class GriefPrevention extends JavaPlugin GriefPrevention.sendMessage(player, TextMode.Success, Messages.PvPImmunityStart); } - //checks whether players can create claims in a world - public boolean claimsEnabledForWorld(World world) - { - return this.config_claims_enabledWorlds.contains(world); - } - //checks whether players siege in a world public boolean siegeEnabledForWorld(World world) { @@ -2556,10 +2603,16 @@ public class GriefPrevention extends JavaPlugin } } - //determines whether creative anti-grief rules apply at a location + //checks whether players can create claims in a world + public boolean claimsEnabledForWorld(World world) + { + return this.config_claims_worldModes.get(world) != ClaimsMode.Disabled; + } + + //determines whether creative anti-grief rules apply at a location boolean creativeRulesApply(Location location) { - return this.config_claims_enabledCreativeWorlds.contains(location.getWorld()); + return this.config_claims_worldModes.get((location.getWorld())) == ClaimsMode.Creative; } public String allowBuild(Player player, Location location) diff --git a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java index c4f855b..45c78fb 100644 --- a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java +++ b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java @@ -755,6 +755,9 @@ class PlayerEventHandler implements Listener { Player player = event.getPlayer(); Entity entity = event.getRightClicked(); + + if(!GriefPrevention.instance.claimsEnabledForWorld(entity.getWorld())) return; + PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId()); //don't allow interaction with item frames in claimed areas without build permission @@ -912,7 +915,9 @@ class PlayerEventHandler implements Listener @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onPlayerBedEnter (PlayerBedEnterEvent bedEvent) { - if(!GriefPrevention.instance.config_claims_preventButtonsSwitches) return; + if(!GriefPrevention.instance.claimsEnabledForWorld(bedEvent.getBed().getWorld())) return; + + if(!GriefPrevention.instance.config_claims_preventButtonsSwitches) return; Player player = bedEvent.getPlayer(); PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId()); @@ -937,7 +942,9 @@ class PlayerEventHandler implements Listener @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onPlayerBucketEmpty (PlayerBucketEmptyEvent bucketEvent) { - Player player = bucketEvent.getPlayer(); + if(!GriefPrevention.instance.claimsEnabledForWorld(bucketEvent.getBlockClicked().getWorld())) return; + + Player player = bucketEvent.getPlayer(); Block block = bucketEvent.getBlockClicked().getRelative(bucketEvent.getBlockFace()); int minLavaDistance = 10; @@ -959,7 +966,7 @@ class PlayerEventHandler implements Listener } //otherwise no wilderness dumping (unless underground) in worlds where claims are enabled - else if(GriefPrevention.instance.config_claims_enabledWorlds.contains(block.getWorld())) + else if(GriefPrevention.instance.claimsEnabledForWorld(block.getWorld())) { if(block.getY() >= GriefPrevention.instance.getSeaLevel(block.getWorld()) - 5 && !player.hasPermission("griefprevention.lava")) { @@ -1000,6 +1007,8 @@ class PlayerEventHandler implements Listener Player player = bucketEvent.getPlayer(); Block block = bucketEvent.getBlockClicked(); + if(!GriefPrevention.instance.claimsEnabledForWorld(block.getWorld())) return; + //make sure the player is allowed to build at the location String noBuildReason = GriefPrevention.instance.allowBuild(player, block.getLocation()); if(noBuildReason != null) @@ -1738,7 +1747,7 @@ class PlayerEventHandler implements Listener if(lastShovelLocation == null) { //if claims are not enabled in this world and it's not an administrative claim, display an error message and stop - if(!GriefPrevention.instance.claimsEnabledForWorld(player.getWorld()) && playerData.shovelMode != ShovelMode.Admin) + if(!GriefPrevention.instance.claimsEnabledForWorld(player.getWorld())) { GriefPrevention.sendMessage(player, TextMode.Err, Messages.ClaimsDisabledWorld); return;