Remove unused check for creative mode

This commit is contained in:
destro174 2022-02-19 20:57:34 +01:00
parent 2c8121dd2c
commit b4a60683d9
7 changed files with 7 additions and 360 deletions

View File

@ -467,18 +467,6 @@ public class BlockEventHandler implements Listener
{
GriefPrevention.sendMessage(player, TextMode.Warn, Messages.NoPistonsOutsideClaims);
}
//limit active blocks in creative mode worlds
if (!player.hasPermission("griefprevention.adminclaims") && GriefPrevention.instance.creativeRulesApply(block.getLocation()) && isActiveBlock(block))
{
String noPlaceReason = claim.allowMoreActiveBlocks();
if (noPlaceReason != null)
{
GriefPrevention.sendMessage(player, TextMode.Err, noPlaceReason);
placeEvent.setCancelled(true);
return;
}
}
}
static boolean isActiveBlock(Block block)
@ -865,31 +853,6 @@ public class BlockEventHandler implements Listener
}
}
//otherwise if creative mode world, don't flow
else if (GriefPrevention.instance.creativeRulesApply(toLocation))
{
spreadEvent.setCancelled(true);
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onForm(BlockFormEvent event)
{
Block block = event.getBlock();
Location location = block.getLocation();
if (GriefPrevention.instance.creativeRulesApply(location))
{
Material type = block.getType();
if (type == Material.COBBLESTONE || type == Material.OBSIDIAN || type == Material.LAVA || type == Material.WATER)
{
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(location, false, null);
if (claim == null)
{
event.setCancelled(true);
}
}
}
}
//Stop projectiles from destroying blocks that don't fire a proper event
@ -949,14 +912,6 @@ public class BlockEventHandler implements Listener
Claim fromClaim = this.dataStore.getClaimAt(fromBlock.getLocation(), false, null);
Claim toClaim = this.dataStore.getClaimAt(toBlock.getLocation(), false, fromClaim);
//into wilderness is NOT OK in creative mode worlds
Material materialDispensed = dispenseEvent.getItem().getType();
if ((materialDispensed == Material.WATER_BUCKET || materialDispensed == Material.LAVA_BUCKET) && GriefPrevention.instance.creativeRulesApply(dispenseEvent.getBlock().getLocation()) && toClaim == null)
{
dispenseEvent.setCancelled(true);
return;
}
//wilderness to wilderness is OK
if (fromClaim == null && toClaim == null) return;

View File

@ -138,37 +138,6 @@ public class Claim
//don't do it for very large claims
if (this.getArea() > 10000) return;
//only in creative mode worlds
if (!GriefPrevention.instance.creativeRulesApply(this.lesserBoundaryCorner)) return;
Location lesser = this.getLesserBoundaryCorner();
Location greater = this.getGreaterBoundaryCorner();
if (lesser.getWorld().getEnvironment() == Environment.NETHER) return; //don't clean up lava in the nether
int seaLevel = 0; //clean up all fluids in the end
//respect sea level in normal worlds
if (lesser.getWorld().getEnvironment() == Environment.NORMAL)
seaLevel = GriefPrevention.instance.getSeaLevel(lesser.getWorld());
for (int x = lesser.getBlockX(); x <= greater.getBlockX(); x++)
{
for (int z = lesser.getBlockZ(); z <= greater.getBlockZ(); z++)
{
for (int y = seaLevel - 1; y <= lesser.getWorld().getMaxHeight(); y++)
{
//dodge the exclusion claim
Block block = lesser.getWorld().getBlockAt(x, y, z);
if (exclusionClaim != null && exclusionClaim.contains(block.getLocation(), true, false)) continue;
if (block.getType() == Material.LAVA || block.getType() == Material.WATER)
{
block.setType(Material.AIR);
}
}
}
}
}
//determines whether or not a claim has surface lava
@ -874,64 +843,6 @@ public class Claim
return thisCorner.getWorld().getName().compareTo(otherCorner.getWorld().getName()) < 0;
}
long getPlayerInvestmentScore()
{
//decide which blocks will be considered player placed
Location lesserBoundaryCorner = this.getLesserBoundaryCorner();
Set<Material> playerBlocks = RestoreNatureProcessingTask.getPlayerBlocks(lesserBoundaryCorner.getWorld().getEnvironment(), lesserBoundaryCorner.getBlock().getBiome());
//scan the claim for player placed blocks
double score = 0;
boolean creativeMode = GriefPrevention.instance.creativeRulesApply(lesserBoundaryCorner);
for (int x = this.lesserBoundaryCorner.getBlockX(); x <= this.greaterBoundaryCorner.getBlockX(); x++)
{
for (int z = this.lesserBoundaryCorner.getBlockZ(); z <= this.greaterBoundaryCorner.getBlockZ(); z++)
{
int y = this.lesserBoundaryCorner.getBlockY();
for (; y < GriefPrevention.instance.getSeaLevel(this.lesserBoundaryCorner.getWorld()) - 5; y++)
{
Block block = this.lesserBoundaryCorner.getWorld().getBlockAt(x, y, z);
if (playerBlocks.contains(block.getType()))
{
if (block.getType() == Material.CHEST && !creativeMode)
{
score += 10;
}
else
{
score += .5;
}
}
}
for (; y < this.lesserBoundaryCorner.getWorld().getMaxHeight(); y++)
{
Block block = this.lesserBoundaryCorner.getWorld().getBlockAt(x, y, z);
if (playerBlocks.contains(block.getType()))
{
if (block.getType() == Material.CHEST && !creativeMode)
{
score += 10;
}
else if (creativeMode && (block.getType() == Material.LAVA))
{
score -= 10;
}
else
{
score += 1;
}
}
}
}
}
return (long) score;
}
public ArrayList<Chunk> getChunks()
{
ArrayList<Chunk> chunks = new ArrayList<>();

View File

@ -119,17 +119,6 @@ class EntityCleanupTask implements Runnable
List<Claim> claims = GriefPrevention.instance.dataStore.claims;
int j = (int) (claims.size() * this.percentageStart);
int k = (int) (claims.size() * (this.percentageStart + .05));
for (; j < claims.size() && j < k; j++)
{
Claim claim = claims.get(j);
//if it's a creative mode claim
if (GriefPrevention.instance.creativeRulesApply(claim.getLesserBoundaryCorner()))
{
//check its entity count and remove any extras
claim.allowMoreEntities(true);
}
}
//schedule the next run of this task, in 3 minutes (20L is approximately 1 second)
double nextRunPercentageStart = this.percentageStart + .05;

View File

@ -394,19 +394,6 @@ public class EntityEventHandler implements Listener
boolean applySurfaceRules = world.getEnvironment() == Environment.NORMAL && ((isCreeper && GriefPrevention.instance.config_blockSurfaceCreeperExplosions) || (!isCreeper && GriefPrevention.instance.config_blockSurfaceOtherExplosions));
//special rule for creative worlds: explosions don't destroy anything
if (GriefPrevention.instance.creativeRulesApply(location))
{
for (int i = 0; i < blocks.size(); i++)
{
Block block = blocks.get(i);
blocks.remove(i--);
}
return;
}
//make a list of blocks which were allowed to explode
List<Block> explodedBlocks = new ArrayList<>();
Claim cachedClaim = null;
@ -448,12 +435,6 @@ public class EntityEventHandler implements Listener
@EventHandler(priority = EventPriority.LOWEST)
public void onItemSpawn(ItemSpawnEvent event)
{
//if in a creative world, cancel the event (don't drop items on the ground)
if (GriefPrevention.instance.creativeRulesApply(event.getLocation()))
{
event.setCancelled(true);
}
//if item is on watch list, apply protection
ArrayList<PendingItemProtection> watchList = GriefPrevention.instance.pendingItemWatchList;
Item newItem = event.getEntity();
@ -509,30 +490,6 @@ public class EntityEventHandler implements Listener
}
}
//when a creature spawns...
@EventHandler(priority = EventPriority.LOWEST)
public void onEntitySpawn(CreatureSpawnEvent event)
{
//these rules apply only to creative worlds
if (!GriefPrevention.instance.creativeRulesApply(event.getLocation())) return;
//chicken eggs and breeding could potentially make a mess in the wilderness, once griefers get involved
SpawnReason reason = event.getSpawnReason();
if (reason != SpawnReason.SPAWNER_EGG && reason != SpawnReason.BUILD_IRONGOLEM && reason != SpawnReason.BUILD_SNOWMAN && event.getEntityType() != EntityType.ARMOR_STAND)
{
event.setCancelled(true);
return;
}
//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(true) != null)
{
event.setCancelled(true);
return;
}
}
//when an entity dies...
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityDeath(EntityDeathEvent event)
@ -542,13 +499,6 @@ public class EntityEventHandler implements Listener
//don't do the rest 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()))
{
event.setDroppedExp(0);
event.getDrops().clear();
}
//FEATURE: when a player is involved in a siege (attacker or defender role)
//his death will end the siege
@ -681,21 +631,6 @@ public class EntityEventHandler implements Listener
return;
}
//otherwise, apply entity-count limitations for creative worlds
else if (GriefPrevention.instance.creativeRulesApply(event.getEntity().getLocation()))
{
PlayerData playerData = this.dataStore.getPlayerData(event.getPlayer().getUniqueId());
Claim claim = this.dataStore.getClaimAt(event.getBlock().getLocation(), false, playerData.lastClaim);
if (claim == null) return;
String noEntitiesReason = claim.allowMoreEntities(false);
if (noEntitiesReason != null)
{
GriefPrevention.sendMessage(event.getPlayer(), TextMode.Err, noEntitiesReason);
event.setCancelled(true);
return;
}
}
}
private boolean isMonster(Entity entity)

View File

@ -59,11 +59,7 @@ class EquipShovelProcessingTask implements Runnable
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.RemainingBlocks, String.valueOf(remainingBlocks));
//link to a video demo of land claiming, based on world type
if (GriefPrevention.instance.creativeRulesApply(player.getLocation()))
{
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.CreativeBasicsVideo2, DataStore.CREATIVE_VIDEO_URL);
}
else if (GriefPrevention.instance.claimsEnabledForWorld(player.getLocation().getWorld()))
if (GriefPrevention.instance.claimsEnabledForWorld(player.getLocation().getWorld()))
{
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.SurvivalBasicsVideo2, DataStore.SURVIVAL_VIDEO_URL);
}

View File

@ -103,7 +103,6 @@ public class GriefPrevention extends JavaPlugin
//claim mode for each world
public ConcurrentHashMap<World, ClaimsMode> config_claims_worldModes;
private boolean config_creativeWorldsExist; //note on whether there are any creative mode worlds, to save cpu cycles on a common hash lookup
public boolean config_claims_preventGlobalMonsterEggs; //whether monster eggs can be placed regardless of trust.
public boolean config_claims_preventTheft; //whether containers and crafting blocks are protectable
@ -449,7 +448,6 @@ public class GriefPrevention extends JavaPlugin
//decide claim mode for each world
this.config_claims_worldModes = new ConcurrentHashMap<>();
this.config_creativeWorldsExist = false;
for (World world : worlds)
{
//is it specified in the config file?
@ -466,7 +464,6 @@ public class GriefPrevention extends JavaPlugin
{
GriefPrevention.AddLogEntry("Error: Invalid claim mode \"" + configSetting + "\". Options are Survival and Disabled.");
this.config_claims_worldModes.put(world, ClaimsMode.Disabled);
this.config_creativeWorldsExist = true;
}
}
@ -990,11 +987,7 @@ public class GriefPrevention extends JavaPlugin
GriefPrevention.sendMessage(player, TextMode.Success, Messages.CreateClaimSuccess);
//link to a video demo of land claiming, based on world type
if (GriefPrevention.instance.creativeRulesApply(player.getLocation()))
{
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.CreativeBasicsVideo2, DataStore.CREATIVE_VIDEO_URL);
}
else if (GriefPrevention.instance.claimsEnabledForWorld(player.getLocation().getWorld()))
if (GriefPrevention.instance.claimsEnabledForWorld(player.getLocation().getWorld()))
{
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.SurvivalBasicsVideo2, DataStore.SURVIVAL_VIDEO_URL);
}
@ -1015,11 +1008,7 @@ public class GriefPrevention extends JavaPlugin
if (args.length < 1)
{
//link to a video demo of land claiming, based on world type
if (GriefPrevention.instance.creativeRulesApply(player.getLocation()))
{
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.CreativeBasicsVideo2, DataStore.CREATIVE_VIDEO_URL);
}
else if (GriefPrevention.instance.claimsEnabledForWorld(player.getLocation().getWorld()))
if (GriefPrevention.instance.claimsEnabledForWorld(player.getLocation().getWorld()))
{
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.SurvivalBasicsVideo2, DataStore.SURVIVAL_VIDEO_URL);
}
@ -1034,11 +1023,7 @@ public class GriefPrevention extends JavaPlugin
catch (NumberFormatException e)
{
//link to a video demo of land claiming, based on world type
if (GriefPrevention.instance.creativeRulesApply(player.getLocation()))
{
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.CreativeBasicsVideo2, DataStore.CREATIVE_VIDEO_URL);
}
else if (GriefPrevention.instance.claimsEnabledForWorld(player.getLocation().getWorld()))
if (GriefPrevention.instance.claimsEnabledForWorld(player.getLocation().getWorld()))
{
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.SurvivalBasicsVideo2, DataStore.SURVIVAL_VIDEO_URL);
}
@ -3226,14 +3211,6 @@ public class GriefPrevention extends JavaPlugin
return mode != null && mode != ClaimsMode.Disabled;
}
//determines whether creative anti-grief rules apply at a location
boolean creativeRulesApply(Location location)
{
if (!this.config_creativeWorldsExist) return false;
return false;
}
public String allowBuild(Player player, Location location)
{
// TODO check all derivatives and rework API
@ -3253,29 +3230,7 @@ public class GriefPrevention extends JavaPlugin
//wilderness rules
if (claim == null)
{
//no building in the wilderness in creative mode
if (this.creativeRulesApply(location))
{
//exception: when chest claims are enabled, players who have zero land claims and are placing a chest
if (material != Material.CHEST || playerData.getClaims().size() > 0 || GriefPrevention.instance.config_claims_automaticClaimsForNewPlayersRadius == -1)
{
String reason = this.dataStore.getMessage(Messages.NoBuildOutsideClaims);
if (player.hasPermission("griefprevention.ignoreclaims"))
reason += " " + this.dataStore.getMessage(Messages.IgnoreClaimsAdvertisement);
reason += " " + this.dataStore.getMessage(Messages.CreativeBasicsVideo2, DataStore.CREATIVE_VIDEO_URL);
return reason;
}
else
{
return null;
}
}
//but it's fine in survival mode
else
{
return null;
}
return null;
}
//if not in the wilderness, then apply claim rules (permissions, etc)
@ -3316,21 +3271,7 @@ public class GriefPrevention extends JavaPlugin
//wilderness rules
if (claim == null)
{
//no building in the wilderness in creative mode
if (this.creativeRulesApply(location))
{
String reason = this.dataStore.getMessage(Messages.NoBuildOutsideClaims);
if (player.hasPermission("griefprevention.ignoreclaims"))
reason += " " + this.dataStore.getMessage(Messages.IgnoreClaimsAdvertisement);
reason += " " + this.dataStore.getMessage(Messages.CreativeBasicsVideo2, DataStore.CREATIVE_VIDEO_URL);
return reason;
}
//but it's fine in survival mode
else
{
return null;
}
return null;
}
else
{
@ -3380,7 +3321,7 @@ public class GriefPrevention extends JavaPlugin
//create task
//when done processing, this task will create a main thread task to actually update the world with processing results
RestoreNatureProcessingTask task = new RestoreNatureProcessingTask(snapshots, miny, chunk.getWorld().getEnvironment(), lesserBoundaryCorner.getBlock().getBiome(), lesserBoundaryCorner, greaterBoundaryCorner, this.getSeaLevel(chunk.getWorld()), aggressiveMode, GriefPrevention.instance.creativeRulesApply(lesserBoundaryCorner), playerReceivingVisualization);
RestoreNatureProcessingTask task = new RestoreNatureProcessingTask(snapshots, miny, chunk.getWorld().getEnvironment(), lesserBoundaryCorner.getBlock().getBiome(), lesserBoundaryCorner, greaterBoundaryCorner, this.getSeaLevel(chunk.getWorld()), aggressiveMode, false, playerReceivingVisualization);
GriefPrevention.instance.getServer().getScheduler().runTaskLaterAsynchronously(GriefPrevention.instance, task, delayInTicks);
}

View File

@ -494,13 +494,6 @@ class PlayerEventHandler implements Listener
{
Player player = event.getPlayer();
//in creative worlds, dropping items is blocked
if (instance.creativeRulesApply(player.getLocation()))
{
event.setCancelled(true);
return;
}
PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
//FEATURE: players under siege or in PvP combat, can't throw items on the ground to hide
@ -672,22 +665,6 @@ class PlayerEventHandler implements Listener
}
}
//limit armor placements when entity count is too high
if (entity.getType() == EntityType.ARMOR_STAND && 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;
@ -978,20 +955,6 @@ class PlayerEventHandler implements Listener
minLavaDistance = 3;
}
//otherwise no wilderness dumping in creative mode worlds
else if (instance.creativeRulesApply(block.getLocation()))
{
if (block.getY() >= instance.getSeaLevel(block.getWorld()) - 5 && !player.hasPermission("griefprevention.lava"))
{
if (bucketEvent.getBucket() == Material.LAVA_BUCKET)
{
GriefPrevention.sendMessage(player, TextMode.Err, Messages.NoWildernessBuckets);
bucketEvent.setCancelled(true);
return;
}
}
}
//lava buckets can't be dumped near other players unless pvp is on
if (!doesAllowLavaProximityInWorld(block.getWorld()) && !player.hasPermission("griefprevention.lava"))
{
@ -1418,49 +1381,6 @@ class PlayerEventHandler implements Listener
return;
}
//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.FURNACE_MINECART ||
materialInHand == Material.CHEST_MINECART ||
materialInHand == Material.TNT_MINECART ||
materialInHand == Material.ARMOR_STAND ||
materialInHand == Material.ITEM_FRAME ||
materialInHand == Material.GLOW_ITEM_FRAME ||
spawn_eggs.contains(materialInHand) ||
materialInHand == Material.INFESTED_STONE ||
materialInHand == Material.INFESTED_COBBLESTONE ||
materialInHand == Material.INFESTED_STONE_BRICKS ||
materialInHand == Material.INFESTED_MOSSY_STONE_BRICKS ||
materialInHand == Material.INFESTED_CRACKED_STONE_BRICKS ||
materialInHand == Material.INFESTED_CHISELED_STONE_BRICKS ||
materialInHand == Material.HOPPER_MINECART) &&
instance.creativeRulesApply(clickedBlock.getLocation()))
{
//player needs build permission at this location
String noBuildReason = instance.allowBuild(player, clickedBlock.getLocation(), Material.MINECART);
if (noBuildReason != null)
{
GriefPrevention.sendMessage(player, TextMode.Err, noBuildReason);
event.setCancelled(true);
return;
}
//enforce limit on total number of entities in this claim
if (playerData == null) playerData = this.dataStore.getPlayerData(player.getUniqueId());
Claim claim = this.dataStore.getClaimAt(clickedBlock.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;
}
return;
}
//if he's investigating a claim
else if (materialInHand == instance.config_claims_investigationTool && hand == EquipmentSlot.HAND)
{