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.
This commit is contained in:
parent
c0520880ff
commit
ca6024e151
|
|
@ -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
|
//make sure the player is allowed to build at the location
|
||||||
String noBuildReason = GriefPrevention.instance.allowBuild(player, block.getLocation());
|
String noBuildReason = GriefPrevention.instance.allowBuild(player, block.getLocation());
|
||||||
if(noBuildReason != null)
|
if(noBuildReason != null)
|
||||||
|
|
@ -370,9 +373,12 @@ public class BlockEventHandler implements Listener
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||||
public void onBlockPistonExtend (BlockPistonExtendEvent event)
|
public void onBlockPistonExtend (BlockPistonExtendEvent event)
|
||||||
{
|
{
|
||||||
//pushing down is ALWAYS safe
|
//pushing down is ALWAYS safe
|
||||||
if(event.getDirection() == BlockFace.DOWN) return;
|
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();
|
Block pistonBlock = event.getBlock();
|
||||||
List<Block> blocks = event.getBlocks();
|
List<Block> blocks = event.getBlocks();
|
||||||
|
|
||||||
|
|
@ -489,7 +495,7 @@ public class BlockEventHandler implements Listener
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||||
public void onBlockPistonRetract (BlockPistonRetractEvent event)
|
public void onBlockPistonRetract (BlockPistonRetractEvent event)
|
||||||
{
|
{
|
||||||
//we only care about sticky pistons retracting
|
//we only care about sticky pistons retracting
|
||||||
if(!event.isSticky()) return;
|
if(!event.isSticky()) return;
|
||||||
|
|
||||||
//pulling up is always safe
|
//pulling up is always safe
|
||||||
|
|
@ -498,6 +504,9 @@ public class BlockEventHandler implements Listener
|
||||||
//if pulling "air", always safe
|
//if pulling "air", always safe
|
||||||
if(event.getRetractLocation().getBlock().getType() == Material.AIR) return;
|
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 pistons limited to only pulling blocks which are in the same claim the piston is in
|
||||||
if(GriefPrevention.instance.config_pistonsInClaimsOnly)
|
if(GriefPrevention.instance.config_pistonsInClaimsOnly)
|
||||||
{
|
{
|
||||||
|
|
@ -569,6 +578,9 @@ public class BlockEventHandler implements Listener
|
||||||
return;
|
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
|
//never spread into a claimed area, regardless of settings
|
||||||
if(this.dataStore.getClaimAt(spreadEvent.getBlock().getLocation(), false, null) != null)
|
if(this.dataStore.getClaimAt(spreadEvent.getBlock().getLocation(), false, null) != null)
|
||||||
{
|
{
|
||||||
|
|
@ -619,6 +631,9 @@ public class BlockEventHandler implements Listener
|
||||||
return;
|
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
|
//never burn claimed blocks, regardless of settings
|
||||||
if(this.dataStore.getClaimAt(burnEvent.getBlock().getLocation(), false, null) != null)
|
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)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||||
public void onBlockFromTo (BlockFromToEvent spreadEvent)
|
public void onBlockFromTo (BlockFromToEvent spreadEvent)
|
||||||
{
|
{
|
||||||
//don't track fluid movement in worlds where claims are not enabled
|
//don't track in worlds where claims are not enabled
|
||||||
if(!GriefPrevention.instance.config_claims_enabledWorlds.contains(spreadEvent.getBlock().getWorld())) return;
|
if(!GriefPrevention.instance.claimsEnabledForWorld(spreadEvent.getBlock().getWorld())) return;
|
||||||
|
|
||||||
//always allow fluids to flow straight down
|
//always allow fluids to flow straight down
|
||||||
if(spreadEvent.getFace() == BlockFace.DOWN) return;
|
if(spreadEvent.getFace() == BlockFace.DOWN) return;
|
||||||
|
|
@ -681,7 +696,10 @@ public class BlockEventHandler implements Listener
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||||
public void onDispense(BlockDispenseEvent dispenseEvent)
|
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();
|
Block fromBlock = dispenseEvent.getBlock();
|
||||||
Dispenser dispenser = new Dispenser(fromBlock.getType(), fromBlock.getData());
|
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
|
//only take these potentially expensive steps if configured to do so
|
||||||
if(!GriefPrevention.instance.config_limitTreeGrowth) return;
|
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();
|
Location rootLocation = growEvent.getLocation();
|
||||||
Claim rootClaim = this.dataStore.getClaimAt(rootLocation, false, null);
|
Claim rootClaim = this.dataStore.getClaimAt(rootLocation, false, null);
|
||||||
String rootOwnerName = null;
|
String rootOwnerName = null;
|
||||||
|
|
|
||||||
8
src/me/ryanhamshire/GriefPrevention/ClaimsMode.java
Normal file
8
src/me/ryanhamshire/GriefPrevention/ClaimsMode.java
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
package me.ryanhamshire.GriefPrevention;
|
||||||
|
|
||||||
|
public enum ClaimsMode
|
||||||
|
{
|
||||||
|
Survival,
|
||||||
|
Creative,
|
||||||
|
Disabled
|
||||||
|
}
|
||||||
|
|
@ -512,7 +512,7 @@ public abstract class DataStore
|
||||||
}
|
}
|
||||||
|
|
||||||
//creative mode claims always go to bedrock
|
//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;
|
smally = 2;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,14 @@ class EntityCleanupTask implements Runnable
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
ArrayList<World> worlds = GriefPrevention.instance.config_claims_enabledCreativeWorlds;
|
ArrayList<World> worlds = new ArrayList<World>();
|
||||||
|
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++)
|
for(int i = 0; i < worlds.size(); i++)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -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
|
//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);
|
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
|
//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);
|
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++)
|
for(int i = 0; i < blocks.size(); i++)
|
||||||
{
|
{
|
||||||
|
|
@ -224,6 +224,9 @@ class EntityEventHandler implements Listener
|
||||||
{
|
{
|
||||||
LivingEntity entity = event.getEntity();
|
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
|
//special rule for creative worlds: killed entities don't drop items or experience orbs
|
||||||
if(GriefPrevention.instance.creativeRulesApply(entity.getLocation()))
|
if(GriefPrevention.instance.creativeRulesApply(entity.getLocation()))
|
||||||
{
|
{
|
||||||
|
|
@ -272,7 +275,10 @@ class EntityEventHandler implements Listener
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||||
public void onHangingBreak(HangingBreakEvent event)
|
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
|
//explosions don't destroy hangings
|
||||||
if(event.getCause() == RemoveCause.EXPLOSION)
|
if(event.getCause() == RemoveCause.EXPLOSION)
|
||||||
|
|
@ -314,7 +320,10 @@ class EntityEventHandler implements Listener
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||||
public void onPaintingPlace(HangingPlaceEvent event)
|
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
|
//if the player doesn't have permission, don't allow the placement
|
||||||
String noBuildReason = GriefPrevention.instance.allowBuild(event.getPlayer(), event.getEntity().getLocation());
|
String noBuildReason = GriefPrevention.instance.allowBuild(event.getPlayer(), event.getEntity().getLocation());
|
||||||
|
|
@ -454,6 +463,9 @@ class EntityEventHandler implements Listener
|
||||||
//if theft protection is enabled
|
//if theft protection is enabled
|
||||||
if(event instanceof EntityDamageByEntityEvent)
|
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 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)
|
if(subEvent.getEntityType() == EntityType.ITEM_FRAME)
|
||||||
{
|
{
|
||||||
|
|
@ -561,6 +573,9 @@ class EntityEventHandler implements Listener
|
||||||
//all of this is anti theft code
|
//all of this is anti theft code
|
||||||
if(!GriefPrevention.instance.config_claims_preventTheft) return;
|
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
|
//determine which player is attacking, if any
|
||||||
Player attacker = null;
|
Player attacker = null;
|
||||||
Entity damageSource = event.getAttacker();
|
Entity damageSource = event.getAttacker();
|
||||||
|
|
|
||||||
|
|
@ -63,8 +63,9 @@ public class GriefPrevention extends JavaPlugin
|
||||||
public DataStore dataStore;
|
public DataStore dataStore;
|
||||||
|
|
||||||
//configuration variables, loaded/saved from a config.yml
|
//configuration variables, loaded/saved from a config.yml
|
||||||
public ArrayList<World> config_claims_enabledWorlds; //list of worlds where players can create GriefPrevention claims
|
|
||||||
public ArrayList<World> config_claims_enabledCreativeWorlds; //list of worlds where additional creative mode anti-grief rules apply
|
//claim mode for each world
|
||||||
|
public ConcurrentHashMap<World, ClaimsMode> config_claims_worldModes = new ConcurrentHashMap<World, ClaimsMode>();
|
||||||
|
|
||||||
public boolean config_claims_preventTheft; //whether containers and crafting blocks are protectable
|
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
|
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)
|
//read configuration settings (note defaults)
|
||||||
|
|
||||||
//default for claims worlds list
|
//get (deprecated node) claims world names from the config file
|
||||||
ArrayList<String> defaultClaimsWorldNames = new ArrayList<String>();
|
|
||||||
List<World> worlds = this.getServer().getWorlds();
|
List<World> worlds = this.getServer().getWorlds();
|
||||||
for(int i = 0; i < worlds.size(); i++)
|
List<String> deprecated_claimsEnabledWorldNames = config.getStringList("GriefPrevention.Claims.Worlds");
|
||||||
{
|
|
||||||
defaultClaimsWorldNames.add(worlds.get(i).getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
//get claims world names from the config file
|
|
||||||
List<String> claimsEnabledWorldNames = config.getStringList("GriefPrevention.Claims.Worlds");
|
|
||||||
if(claimsEnabledWorldNames == null || claimsEnabledWorldNames.size() == 0)
|
|
||||||
{
|
|
||||||
claimsEnabledWorldNames = defaultClaimsWorldNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
//validate that list
|
//validate that list
|
||||||
this.config_claims_enabledWorlds = new ArrayList<World>();
|
for(int i = 0; i < deprecated_claimsEnabledWorldNames.size(); i++)
|
||||||
for(int i = 0; i < claimsEnabledWorldNames.size(); i++)
|
|
||||||
{
|
{
|
||||||
String worldName = claimsEnabledWorldNames.get(i);
|
String worldName = deprecated_claimsEnabledWorldNames.get(i);
|
||||||
World world = this.getServer().getWorld(worldName);
|
World world = this.getServer().getWorld(worldName);
|
||||||
if(world == null)
|
if(world == null)
|
||||||
{
|
{
|
||||||
AddLogEntry("Error: Claims Configuration: There's no world named \"" + worldName + "\". Please update your config.yml.");
|
deprecated_claimsEnabledWorldNames.remove(i--);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.config_claims_enabledWorlds.add(world);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//default creative claim world names
|
//get (deprecated node) creative world names from the config file
|
||||||
List<String> defaultCreativeWorldNames = new ArrayList<String>();
|
List<String> deprecated_creativeClaimsEnabledWorldNames = config.getStringList("GriefPrevention.Claims.CreativeRulesWorlds");
|
||||||
|
|
||||||
//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<String> creativeClaimsEnabledWorldNames = config.getStringList("GriefPrevention.Claims.CreativeRulesWorlds");
|
|
||||||
if(creativeClaimsEnabledWorldNames == null || creativeClaimsEnabledWorldNames.size() == 0)
|
|
||||||
{
|
|
||||||
creativeClaimsEnabledWorldNames = defaultCreativeWorldNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
//validate that list
|
//validate that list
|
||||||
this.config_claims_enabledCreativeWorlds = new ArrayList<World>();
|
for(int i = 0; i < deprecated_creativeClaimsEnabledWorldNames.size(); i++)
|
||||||
for(int i = 0; i < creativeClaimsEnabledWorldNames.size(); i++)
|
|
||||||
{
|
{
|
||||||
String worldName = creativeClaimsEnabledWorldNames.get(i);
|
String worldName = deprecated_creativeClaimsEnabledWorldNames.get(i);
|
||||||
World world = this.getServer().getWorld(worldName);
|
World world = this.getServer().getWorld(worldName);
|
||||||
if(world == null)
|
if(world == null)
|
||||||
{
|
{
|
||||||
AddLogEntry("Error: Claims Configuration: There's no world named \"" + worldName + "\". Please update your config.yml.");
|
deprecated_claimsEnabledWorldNames.remove(i--);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.config_claims_enabledCreativeWorlds.add(world);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//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
|
//default for pvp worlds list
|
||||||
ArrayList<String> defaultPvpWorldNames = new ArrayList<String>();
|
ArrayList<String> defaultPvpWorldNames = new ArrayList<String>();
|
||||||
for(int i = 0; i < worlds.size(); i++)
|
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_minSize = config.getInt("GriefPrevention.Claims.MinimumSize", 10);
|
||||||
this.config_claims_maxDepth = config.getInt("GriefPrevention.Claims.MaximumDepth", 0);
|
this.config_claims_maxDepth = config.getInt("GriefPrevention.Claims.MaximumDepth", 0);
|
||||||
this.config_claims_trappedCooldownHours = config.getInt("GriefPrevention.Claims.TrappedCommandCooldownHours", 8);
|
this.config_claims_trappedCooldownHours = config.getInt("GriefPrevention.Claims.TrappedCommandCooldownHours", 8);
|
||||||
|
|
||||||
this.config_claims_chestClaimExpirationDays = config.getInt("GriefPrevention.Claims.Expiration.ChestClaimDays", 7);
|
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);
|
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);
|
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);
|
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_enabled = config.getBoolean("GriefPrevention.Spam.Enabled", true);
|
||||||
this.config_spam_loginCooldownSeconds = config.getInt("GriefPrevention.Spam.LoginCooldownSeconds", 60);
|
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.");
|
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 databaseUserName = config.getString("GriefPrevention.Database.UserName", "");
|
||||||
String databasePassword = config.getString("GriefPrevention.Database.Password", "");
|
String databasePassword = config.getString("GriefPrevention.Database.Password", "");
|
||||||
|
|
||||||
outConfig.set("GriefPrevention.Claims.Worlds", claimsEnabledWorldNames);
|
//claims mode by world
|
||||||
outConfig.set("GriefPrevention.Claims.CreativeRulesWorlds", creativeClaimsEnabledWorldNames);
|
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.PreventTheft", this.config_claims_preventTheft);
|
||||||
outConfig.set("GriefPrevention.Claims.ProtectCreatures", this.config_claims_protectCreatures);
|
outConfig.set("GriefPrevention.Claims.ProtectCreatures", this.config_claims_protectCreatures);
|
||||||
outConfig.set("GriefPrevention.Claims.PreventButtonsSwitches", this.config_claims_preventButtonsSwitches);
|
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.TrappedCommandCooldownHours", this.config_claims_trappedCooldownHours);
|
||||||
outConfig.set("GriefPrevention.Claims.InvestigationTool", this.config_claims_investigationTool.name());
|
outConfig.set("GriefPrevention.Claims.InvestigationTool", this.config_claims_investigationTool.name());
|
||||||
outConfig.set("GriefPrevention.Claims.ModificationTool", this.config_claims_modificationTool.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.Enabled", this.config_spam_enabled);
|
||||||
outConfig.set("GriefPrevention.Spam.LoginCooldownSeconds", this.config_spam_loginCooldownSeconds);
|
outConfig.set("GriefPrevention.Spam.LoginCooldownSeconds", this.config_spam_loginCooldownSeconds);
|
||||||
|
|
@ -775,7 +808,27 @@ public class GriefPrevention extends JavaPlugin
|
||||||
AddLogEntry("Boot finished.");
|
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){
|
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
|
||||||
|
|
||||||
Player player = null;
|
Player player = null;
|
||||||
|
|
@ -2275,12 +2328,6 @@ public class GriefPrevention extends JavaPlugin
|
||||||
GriefPrevention.sendMessage(player, TextMode.Success, Messages.PvPImmunityStart);
|
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
|
//checks whether players siege in a world
|
||||||
public boolean siegeEnabledForWorld(World 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)
|
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)
|
public String allowBuild(Player player, Location location)
|
||||||
|
|
|
||||||
|
|
@ -755,6 +755,9 @@ class PlayerEventHandler implements Listener
|
||||||
{
|
{
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
Entity entity = event.getRightClicked();
|
Entity entity = event.getRightClicked();
|
||||||
|
|
||||||
|
if(!GriefPrevention.instance.claimsEnabledForWorld(entity.getWorld())) return;
|
||||||
|
|
||||||
PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
|
PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
|
||||||
|
|
||||||
//don't allow interaction with item frames in claimed areas without build permission
|
//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)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||||
public void onPlayerBedEnter (PlayerBedEnterEvent bedEvent)
|
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();
|
Player player = bedEvent.getPlayer();
|
||||||
PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
|
PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
|
||||||
|
|
@ -937,7 +942,9 @@ class PlayerEventHandler implements Listener
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||||
public void onPlayerBucketEmpty (PlayerBucketEmptyEvent bucketEvent)
|
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());
|
Block block = bucketEvent.getBlockClicked().getRelative(bucketEvent.getBlockFace());
|
||||||
int minLavaDistance = 10;
|
int minLavaDistance = 10;
|
||||||
|
|
||||||
|
|
@ -959,7 +966,7 @@ class PlayerEventHandler implements Listener
|
||||||
}
|
}
|
||||||
|
|
||||||
//otherwise no wilderness dumping (unless underground) in worlds where claims are enabled
|
//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"))
|
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();
|
Player player = bucketEvent.getPlayer();
|
||||||
Block block = bucketEvent.getBlockClicked();
|
Block block = bucketEvent.getBlockClicked();
|
||||||
|
|
||||||
|
if(!GriefPrevention.instance.claimsEnabledForWorld(block.getWorld())) return;
|
||||||
|
|
||||||
//make sure the player is allowed to build at the location
|
//make sure the player is allowed to build at the location
|
||||||
String noBuildReason = GriefPrevention.instance.allowBuild(player, block.getLocation());
|
String noBuildReason = GriefPrevention.instance.allowBuild(player, block.getLocation());
|
||||||
if(noBuildReason != null)
|
if(noBuildReason != null)
|
||||||
|
|
@ -1738,7 +1747,7 @@ class PlayerEventHandler implements Listener
|
||||||
if(lastShovelLocation == null)
|
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 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);
|
GriefPrevention.sendMessage(player, TextMode.Err, Messages.ClaimsDisabledWorld);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user