reformat code
- Lots of tabs to spaces going on - That's a lot of changes! #63
This commit is contained in:
parent
bc05440617
commit
40f554d386
|
|
@ -1,13 +1,13 @@
|
|||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChunkSnapshot;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
//automatically extends a claim downward based on block types detected
|
||||
class AutoExtendClaimTask implements Runnable
|
||||
{
|
||||
|
|
@ -26,7 +26,7 @@ class AutoExtendClaimTask implements Runnable
|
|||
public void run()
|
||||
{
|
||||
int newY = this.getLowestBuiltY();
|
||||
if(newY < this.claim.getLesserBoundaryCorner().getBlockY())
|
||||
if (newY < this.claim.getLesserBoundaryCorner().getBlockY())
|
||||
{
|
||||
Bukkit.getScheduler().runTask(GriefPrevention.instance, new ExecuteExtendClaimTask(claim, newY));
|
||||
}
|
||||
|
|
@ -36,67 +36,67 @@ class AutoExtendClaimTask implements Runnable
|
|||
{
|
||||
int y = this.claim.getLesserBoundaryCorner().getBlockY();
|
||||
|
||||
if(this.yTooSmall(y)) return y;
|
||||
if (this.yTooSmall(y)) return y;
|
||||
|
||||
try
|
||||
{
|
||||
for(ChunkSnapshot chunk : this.chunks)
|
||||
for (ChunkSnapshot chunk : this.chunks)
|
||||
{
|
||||
Biome biome = chunk.getBiome(0, 0);
|
||||
ArrayList<Material> playerBlockIDs = RestoreNatureProcessingTask.getPlayerBlocks(this.worldType, biome);
|
||||
|
||||
boolean ychanged = true;
|
||||
while(!this.yTooSmall(y) && ychanged)
|
||||
while (!this.yTooSmall(y) && ychanged)
|
||||
{
|
||||
ychanged = false;
|
||||
for(int x = 0; x < 16; x++)
|
||||
for (int x = 0; x < 16; x++)
|
||||
{
|
||||
for(int z = 0; z < 16; z++)
|
||||
for (int z = 0; z < 16; z++)
|
||||
{
|
||||
Material blockType = chunk.getBlockType(x, y, z);
|
||||
while(!this.yTooSmall(y) && playerBlockIDs.contains(blockType))
|
||||
while (!this.yTooSmall(y) && playerBlockIDs.contains(blockType))
|
||||
{
|
||||
ychanged = true;
|
||||
blockType = chunk.getBlockType(x, --y, z);
|
||||
}
|
||||
|
||||
if(this.yTooSmall(y)) return y;
|
||||
if (this.yTooSmall(y)) return y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(this.yTooSmall(y)) return y;
|
||||
if (this.yTooSmall(y)) return y;
|
||||
}
|
||||
}
|
||||
catch (NoSuchMethodError e)
|
||||
{
|
||||
GriefPrevention.instance.getLogger().severe("You are running an outdated build of Craftbukkit/Spigot/Paper. Please update.");
|
||||
for(ChunkSnapshot chunk : this.chunks)
|
||||
for (ChunkSnapshot chunk : this.chunks)
|
||||
{
|
||||
Biome biome = chunk.getBiome(0, 0);
|
||||
ArrayList<Material> playerBlockIDs = RestoreNatureProcessingTask.getPlayerBlocks(this.worldType, biome);
|
||||
|
||||
boolean ychanged = true;
|
||||
while(!this.yTooSmall(y) && ychanged)
|
||||
while (!this.yTooSmall(y) && ychanged)
|
||||
{
|
||||
ychanged = false;
|
||||
for(int x = 0; x < 16; x++)
|
||||
for (int x = 0; x < 16; x++)
|
||||
{
|
||||
for(int z = 0; z < 16; z++)
|
||||
for (int z = 0; z < 16; z++)
|
||||
{
|
||||
Material blockType = chunk.getBlockType(x, y, z);
|
||||
while(!this.yTooSmall(y) && playerBlockIDs.contains(blockType))
|
||||
while (!this.yTooSmall(y) && playerBlockIDs.contains(blockType))
|
||||
{
|
||||
ychanged = true;
|
||||
blockType = chunk.getBlockType(x, --y, z);
|
||||
}
|
||||
|
||||
if(this.yTooSmall(y)) return y;
|
||||
if (this.yTooSmall(y)) return y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(this.yTooSmall(y)) return y;
|
||||
if (this.yTooSmall(y)) return y;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ public class BlockEventHandler implements Listener
|
|||
|
||||
//make sure the player is allowed to break at the location
|
||||
String noBuildReason = GriefPrevention.instance.allowBreak(player, block, block.getLocation(), breakEvent);
|
||||
if(noBuildReason != null)
|
||||
if (noBuildReason != null)
|
||||
{
|
||||
GriefPrevention.sendMessage(player, TextMode.Err, noBuildReason);
|
||||
breakEvent.setCancelled(true);
|
||||
|
|
@ -117,17 +117,17 @@ public class BlockEventHandler implements Listener
|
|||
public void onSignChanged(SignChangeEvent event)
|
||||
{
|
||||
//send sign content to online administrators
|
||||
if(!GriefPrevention.instance.config_signNotifications) return;
|
||||
if (!GriefPrevention.instance.config_signNotifications) return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
if(player == null) return;
|
||||
if (player == null) return;
|
||||
|
||||
StringBuilder lines = new StringBuilder(" placed a sign @ " + GriefPrevention.getfriendlyLocationString(event.getBlock().getLocation()));
|
||||
boolean notEmpty = false;
|
||||
for(int i = 0; i < event.getLines().length; i++)
|
||||
for (int i = 0; i < event.getLines().length; i++)
|
||||
{
|
||||
String withoutSpaces = event.getLine(i).replace(" ", "");
|
||||
if(!withoutSpaces.isEmpty())
|
||||
if (!withoutSpaces.isEmpty())
|
||||
{
|
||||
notEmpty = true;
|
||||
lines.append("\n " + event.getLine(i));
|
||||
|
|
@ -137,7 +137,7 @@ public class BlockEventHandler implements Listener
|
|||
String signMessage = lines.toString();
|
||||
|
||||
//prevent signs with blocked IP addresses
|
||||
if(!player.hasPermission("griefprevention.spam") && GriefPrevention.instance.containsBlockedIP(signMessage))
|
||||
if (!player.hasPermission("griefprevention.spam") && GriefPrevention.instance.containsBlockedIP(signMessage))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
|
|
@ -153,13 +153,13 @@ public class BlockEventHandler implements Listener
|
|||
PlayerEventHandler.makeSocialLogEntry(player.getName(), signMessage);
|
||||
//playerData.lastSignMessage = signMessage;
|
||||
|
||||
if(!player.hasPermission("griefprevention.eavesdropsigns"))
|
||||
if (!player.hasPermission("griefprevention.eavesdropsigns"))
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<Player> players = (Collection<Player>)GriefPrevention.instance.getServer().getOnlinePlayers();
|
||||
for(Player otherPlayer : players)
|
||||
Collection<Player> players = (Collection<Player>) GriefPrevention.instance.getServer().getOnlinePlayers();
|
||||
for (Player otherPlayer : players)
|
||||
{
|
||||
if(otherPlayer.hasPermission("griefprevention.eavesdropsigns"))
|
||||
if (otherPlayer.hasPermission("griefprevention.eavesdropsigns"))
|
||||
{
|
||||
otherPlayer.sendMessage(ChatColor.GRAY + player.getName() + signMessage);
|
||||
}
|
||||
|
|
@ -175,13 +175,13 @@ public class BlockEventHandler implements Listener
|
|||
Player player = placeEvent.getPlayer();
|
||||
|
||||
//don't track in worlds where claims are not enabled
|
||||
if(!GriefPrevention.instance.claimsEnabledForWorld(placeEvent.getBlock().getWorld())) return;
|
||||
if (!GriefPrevention.instance.claimsEnabledForWorld(placeEvent.getBlock().getWorld())) return;
|
||||
|
||||
//make sure the player is allowed to build at the location
|
||||
for(BlockState block : placeEvent.getReplacedBlockStates())
|
||||
for (BlockState block : placeEvent.getReplacedBlockStates())
|
||||
{
|
||||
String noBuildReason = GriefPrevention.instance.allowBuild(player, block.getLocation(), block.getType());
|
||||
if(noBuildReason != null)
|
||||
if (noBuildReason != null)
|
||||
{
|
||||
GriefPrevention.sendMessage(player, TextMode.Err, noBuildReason);
|
||||
placeEvent.setCancelled(true);
|
||||
|
|
@ -190,10 +190,13 @@ public class BlockEventHandler implements Listener
|
|||
}
|
||||
}
|
||||
|
||||
private boolean doesAllowFireProximityInWorld(World world) {
|
||||
if (GriefPrevention.instance.pvpRulesApply(world)) {
|
||||
private boolean doesAllowFireProximityInWorld(World world)
|
||||
{
|
||||
if (GriefPrevention.instance.pvpRulesApply(world))
|
||||
{
|
||||
return GriefPrevention.instance.config_pvp_allowFireNearPlayers;
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
return GriefPrevention.instance.config_pvp_allowFireNearPlayers_NonPvp;
|
||||
}
|
||||
}
|
||||
|
|
@ -209,20 +212,21 @@ public class BlockEventHandler implements Listener
|
|||
//FEATURE: limit fire placement, to prevent PvP-by-fire
|
||||
|
||||
//if placed block is fire and pvp is off, apply rules for proximity to other players
|
||||
if(block.getType() == Material.FIRE && !doesAllowFireProximityInWorld(block.getWorld()))
|
||||
if (block.getType() == Material.FIRE && !doesAllowFireProximityInWorld(block.getWorld()))
|
||||
{
|
||||
List<Player> players = block.getWorld().getPlayers();
|
||||
for(int i = 0; i < players.size(); i++)
|
||||
for (int i = 0; i < players.size(); i++)
|
||||
{
|
||||
Player otherPlayer = players.get(i);
|
||||
|
||||
// Ignore players in creative or spectator mode to avoid users from checking if someone is spectating near them
|
||||
if(otherPlayer.getGameMode() == GameMode.CREATIVE || otherPlayer.getGameMode() == GameMode.SPECTATOR) {
|
||||
if (otherPlayer.getGameMode() == GameMode.CREATIVE || otherPlayer.getGameMode() == GameMode.SPECTATOR)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Location location = otherPlayer.getLocation();
|
||||
if(!otherPlayer.equals(player) && location.distanceSquared(block.getLocation()) < 9 && player.canSee(otherPlayer))
|
||||
if (!otherPlayer.equals(player) && location.distanceSquared(block.getLocation()) < 9 && player.canSee(otherPlayer))
|
||||
{
|
||||
GriefPrevention.sendMessage(player, TextMode.Err, Messages.PlayerTooCloseForFire2);
|
||||
placeEvent.setCancelled(true);
|
||||
|
|
@ -232,11 +236,11 @@ public class BlockEventHandler implements Listener
|
|||
}
|
||||
|
||||
//don't track in worlds where claims are not enabled
|
||||
if(!GriefPrevention.instance.claimsEnabledForWorld(placeEvent.getBlock().getWorld())) return;
|
||||
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(), block.getType());
|
||||
if(noBuildReason != null)
|
||||
if (noBuildReason != null)
|
||||
{
|
||||
// Allow players with container trust to place books in lecterns
|
||||
PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
|
||||
|
|
@ -263,19 +267,19 @@ public class BlockEventHandler implements Listener
|
|||
//if the block is being placed within or under an existing claim
|
||||
PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
|
||||
Claim claim = this.dataStore.getClaimAt(block.getLocation(), true, playerData.lastClaim);
|
||||
if(claim != null)
|
||||
if (claim != null)
|
||||
{
|
||||
playerData.lastClaim = claim;
|
||||
|
||||
//warn about TNT not destroying claimed blocks
|
||||
if(block.getType() == Material.TNT && !claim.areExplosivesAllowed && playerData.siegeData == null)
|
||||
if (block.getType() == Material.TNT && !claim.areExplosivesAllowed && playerData.siegeData == null)
|
||||
{
|
||||
GriefPrevention.sendMessage(player, TextMode.Warn, Messages.NoTNTDamageClaims);
|
||||
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.ClaimExplosivesAdvertisement);
|
||||
}
|
||||
|
||||
//if the player has permission for the claim and he's placing UNDER the claim
|
||||
if(block.getY() <= claim.lesserBoundaryCorner.getBlockY() && claim.allowBuild(player, block.getType()) == null)
|
||||
if (block.getY() <= claim.lesserBoundaryCorner.getBlockY() && claim.allowBuild(player, block.getType()) == null)
|
||||
{
|
||||
//extend the claim downward
|
||||
this.dataStore.extendClaim(claim, block.getY() - GriefPrevention.instance.config_claims_claimsExtendIntoGroundDistance);
|
||||
|
|
@ -288,10 +292,10 @@ public class BlockEventHandler implements Listener
|
|||
//FEATURE: automatically create a claim when a player who has no claims places a chest
|
||||
|
||||
//otherwise if there's no claim, the player is placing a chest, and new player automatic claims are enabled
|
||||
else if(GriefPrevention.instance.config_claims_automaticClaimsForNewPlayersRadius > -1 && player.hasPermission("griefprevention.createclaims") && block.getType() == Material.CHEST)
|
||||
else if (GriefPrevention.instance.config_claims_automaticClaimsForNewPlayersRadius > -1 && player.hasPermission("griefprevention.createclaims") && block.getType() == Material.CHEST)
|
||||
{
|
||||
//if the chest is too deep underground, don't create the claim and explain why
|
||||
if(GriefPrevention.instance.config_claims_preventTheft && block.getY() < GriefPrevention.instance.config_claims_maxDepth)
|
||||
if (GriefPrevention.instance.config_claims_preventTheft && block.getY() < GriefPrevention.instance.config_claims_maxDepth)
|
||||
{
|
||||
GriefPrevention.sendMessage(player, TextMode.Warn, Messages.TooDeepToClaim);
|
||||
return;
|
||||
|
|
@ -300,10 +304,10 @@ public class BlockEventHandler implements Listener
|
|||
int radius = GriefPrevention.instance.config_claims_automaticClaimsForNewPlayersRadius;
|
||||
|
||||
//if the player doesn't have any claims yet, automatically create a claim centered at the chest
|
||||
if(playerData.getClaims().size() == 0)
|
||||
if (playerData.getClaims().size() == 0)
|
||||
{
|
||||
//radius == 0 means protect ONLY the chest
|
||||
if(GriefPrevention.instance.config_claims_automaticClaimsForNewPlayersRadius == 0)
|
||||
if (GriefPrevention.instance.config_claims_automaticClaimsForNewPlayersRadius == 0)
|
||||
{
|
||||
this.dataStore.createClaim(block.getWorld(), block.getX(), block.getX(), block.getY(), block.getY(), block.getZ(), block.getZ(), player.getUniqueId(), null, null, player);
|
||||
GriefPrevention.sendMessage(player, TextMode.Success, Messages.ChestClaimConfirmation);
|
||||
|
|
@ -313,7 +317,7 @@ public class BlockEventHandler implements Listener
|
|||
else
|
||||
{
|
||||
//if failure due to insufficient claim blocks available
|
||||
if(playerData.getRemainingClaimBlocks() < 1)
|
||||
if (playerData.getRemainingClaimBlocks() < 1)
|
||||
{
|
||||
GriefPrevention.sendMessage(player, TextMode.Warn, Messages.NoEnoughBlocksForChestClaim);
|
||||
return;
|
||||
|
|
@ -322,10 +326,10 @@ public class BlockEventHandler implements Listener
|
|||
//as long as the automatic claim overlaps another existing claim, shrink it
|
||||
//note that since the player had permission to place the chest, at the very least, the automatic claim will include the chest
|
||||
CreateClaimResult result = null;
|
||||
while(radius >= 0)
|
||||
while (radius >= 0)
|
||||
{
|
||||
int area = (radius * 2 + 1) * (radius * 2 + 1);
|
||||
if(playerData.getRemainingClaimBlocks() >= area)
|
||||
if (playerData.getRemainingClaimBlocks() >= area)
|
||||
{
|
||||
result = this.dataStore.createClaim(
|
||||
block.getWorld(),
|
||||
|
|
@ -336,13 +340,13 @@ public class BlockEventHandler implements Listener
|
|||
null, null,
|
||||
player);
|
||||
|
||||
if(result.succeeded) break;
|
||||
if (result.succeeded) break;
|
||||
}
|
||||
|
||||
radius--;
|
||||
}
|
||||
|
||||
if(result != null && result.succeeded)
|
||||
if (result != null && result.succeeded)
|
||||
{
|
||||
//notify and explain to player
|
||||
GriefPrevention.sendMessage(player, TextMode.Success, Messages.AutomaticClaimNotification);
|
||||
|
|
@ -357,19 +361,19 @@ public class BlockEventHandler implements Listener
|
|||
}
|
||||
|
||||
//check to see if this chest is in a claim, and warn when it isn't
|
||||
if(GriefPrevention.instance.config_claims_preventTheft && this.dataStore.getClaimAt(block.getLocation(), false, playerData.lastClaim) == null)
|
||||
if (GriefPrevention.instance.config_claims_preventTheft && this.dataStore.getClaimAt(block.getLocation(), false, playerData.lastClaim) == null)
|
||||
{
|
||||
GriefPrevention.sendMessage(player, TextMode.Warn, Messages.UnprotectedChestWarning);
|
||||
}
|
||||
}
|
||||
|
||||
//FEATURE: limit wilderness tree planting to grass, or dirt with more blocks beneath it
|
||||
else if(Tag.SAPLINGS.isTagged(block.getType()) && GriefPrevention.instance.config_blockSkyTrees && GriefPrevention.instance.claimsEnabledForWorld(player.getWorld()))
|
||||
else if (Tag.SAPLINGS.isTagged(block.getType()) && GriefPrevention.instance.config_blockSkyTrees && GriefPrevention.instance.claimsEnabledForWorld(player.getWorld()))
|
||||
{
|
||||
Block earthBlock = placeEvent.getBlockAgainst();
|
||||
if(earthBlock.getType() != Material.GRASS)
|
||||
if (earthBlock.getType() != Material.GRASS)
|
||||
{
|
||||
if(earthBlock.getRelative(BlockFace.DOWN).getType() == Material.AIR ||
|
||||
if (earthBlock.getRelative(BlockFace.DOWN).getType() == Material.AIR ||
|
||||
earthBlock.getRelative(BlockFace.DOWN).getRelative(BlockFace.DOWN).getType() == Material.AIR)
|
||||
{
|
||||
placeEvent.setCancelled(true);
|
||||
|
|
@ -378,28 +382,28 @@ public class BlockEventHandler implements Listener
|
|||
}
|
||||
|
||||
//FEATURE: warn players when they're placing non-trash blocks outside of their claimed areas
|
||||
else if(!this.trashBlocks.contains(block.getType()) && GriefPrevention.instance.claimsEnabledForWorld(block.getWorld()))
|
||||
else if (!this.trashBlocks.contains(block.getType()) && GriefPrevention.instance.claimsEnabledForWorld(block.getWorld()))
|
||||
{
|
||||
if(!playerData.warnedAboutBuildingOutsideClaims && !player.hasPermission("griefprevention.adminclaims")
|
||||
if (!playerData.warnedAboutBuildingOutsideClaims && !player.hasPermission("griefprevention.adminclaims")
|
||||
&& player.hasPermission("griefprevention.createclaims") && ((playerData.lastClaim == null
|
||||
&& playerData.getClaims().size() == 0) || (playerData.lastClaim != null
|
||||
&& playerData.lastClaim.isNear(player.getLocation(), 15))))
|
||||
{
|
||||
Long now = null;
|
||||
if(playerData.buildWarningTimestamp == null || (now = System.currentTimeMillis()) - playerData.buildWarningTimestamp > 600000) //10 minute cooldown
|
||||
if (playerData.buildWarningTimestamp == null || (now = System.currentTimeMillis()) - playerData.buildWarningTimestamp > 600000) //10 minute cooldown
|
||||
{
|
||||
GriefPrevention.sendMessage(player, TextMode.Warn, Messages.BuildingOutsideClaims);
|
||||
playerData.warnedAboutBuildingOutsideClaims = true;
|
||||
|
||||
if(now == null) now = System.currentTimeMillis();
|
||||
if (now == null) now = System.currentTimeMillis();
|
||||
playerData.buildWarningTimestamp = now;
|
||||
|
||||
if(playerData.getClaims().size() < 2)
|
||||
if (playerData.getClaims().size() < 2)
|
||||
{
|
||||
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.SurvivalBasicsVideo2, DataStore.SURVIVAL_VIDEO_URL);
|
||||
}
|
||||
|
||||
if(playerData.lastClaim != null)
|
||||
if (playerData.lastClaim != null)
|
||||
{
|
||||
Visualization visualization = Visualization.FromClaim(playerData.lastClaim, block.getY(), VisualizationType.Claim, player.getLocation());
|
||||
Visualization.Apply(player, visualization);
|
||||
|
|
@ -409,7 +413,7 @@ public class BlockEventHandler implements Listener
|
|||
}
|
||||
|
||||
//warn players when they place TNT above sea level, since it doesn't destroy blocks there
|
||||
if( GriefPrevention.instance.config_blockSurfaceOtherExplosions && block.getType() == Material.TNT &&
|
||||
if (GriefPrevention.instance.config_blockSurfaceOtherExplosions && block.getType() == Material.TNT &&
|
||||
block.getWorld().getEnvironment() != Environment.NETHER &&
|
||||
block.getY() > GriefPrevention.instance.getSeaLevel(block.getWorld()) - 5 &&
|
||||
claim == null &&
|
||||
|
|
@ -419,18 +423,18 @@ public class BlockEventHandler implements Listener
|
|||
}
|
||||
|
||||
//warn players about disabled pistons outside of land claims
|
||||
if( GriefPrevention.instance.config_pistonsInClaimsOnly &&
|
||||
if (GriefPrevention.instance.config_pistonsInClaimsOnly &&
|
||||
(block.getType() == Material.PISTON || block.getType() == Material.STICKY_PISTON) &&
|
||||
claim == null )
|
||||
claim == null)
|
||||
{
|
||||
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))
|
||||
if (!player.hasPermission("griefprevention.adminclaims") && GriefPrevention.instance.creativeRulesApply(block.getLocation()) && isActiveBlock(block))
|
||||
{
|
||||
String noPlaceReason = claim.allowMoreActiveBlocks();
|
||||
if(noPlaceReason != null)
|
||||
if (noPlaceReason != null)
|
||||
{
|
||||
GriefPrevention.sendMessage(player, TextMode.Err, noPlaceReason);
|
||||
placeEvent.setCancelled(true);
|
||||
|
|
@ -451,36 +455,36 @@ public class BlockEventHandler implements Listener
|
|||
|
||||
static boolean isActiveBlock(Material type)
|
||||
{
|
||||
if(type == Material.HOPPER || type == Material.BEACON || type == Material.SPAWNER) return true;
|
||||
if (type == Material.HOPPER || type == Material.BEACON || type == Material.SPAWNER) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
//blocks "pushing" other players' blocks around (pistons)
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onBlockPistonExtend (BlockPistonExtendEvent event)
|
||||
public void onBlockPistonExtend(BlockPistonExtendEvent event)
|
||||
{
|
||||
//return if piston checks are not enabled
|
||||
if(!GriefPrevention.instance.config_checkPistonMovement) return;
|
||||
if (!GriefPrevention.instance.config_checkPistonMovement) return;
|
||||
|
||||
//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;
|
||||
if (!GriefPrevention.instance.claimsEnabledForWorld(event.getBlock().getWorld())) return;
|
||||
|
||||
Block pistonBlock = event.getBlock();
|
||||
List<Block> blocks = event.getBlocks();
|
||||
|
||||
//if no blocks moving, then only check to make sure we're not pushing into a claim from outside
|
||||
//this avoids pistons breaking non-solids just inside a claim, like torches, doors, and touchplates
|
||||
if(blocks.size() == 0)
|
||||
if (blocks.size() == 0)
|
||||
{
|
||||
Block invadedBlock = pistonBlock.getRelative(event.getDirection());
|
||||
|
||||
//pushing "air" is harmless
|
||||
if(invadedBlock.getType() == Material.AIR) return;
|
||||
if (invadedBlock.getType() == Material.AIR) return;
|
||||
|
||||
if( this.dataStore.getClaimAt(pistonBlock.getLocation(), false, null) == null &&
|
||||
if (this.dataStore.getClaimAt(pistonBlock.getLocation(), false, null) == null &&
|
||||
this.dataStore.getClaimAt(invadedBlock.getLocation(), false, null) != null)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
|
|
@ -492,22 +496,22 @@ public class BlockEventHandler implements Listener
|
|||
//who owns the piston, if anyone?
|
||||
String pistonClaimOwnerName = "_";
|
||||
Claim claim = this.dataStore.getClaimAt(event.getBlock().getLocation(), false, null);
|
||||
if(claim != null) pistonClaimOwnerName = claim.getOwnerName();
|
||||
if (claim != null) pistonClaimOwnerName = claim.getOwnerName();
|
||||
|
||||
//if pistons are limited to same-claim block movement
|
||||
if(GriefPrevention.instance.config_pistonsInClaimsOnly)
|
||||
if (GriefPrevention.instance.config_pistonsInClaimsOnly)
|
||||
{
|
||||
//if piston is not in a land claim, cancel event
|
||||
if(claim == null)
|
||||
if (claim == null)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
for(Block pushedBlock : event.getBlocks())
|
||||
for (Block pushedBlock : event.getBlocks())
|
||||
{
|
||||
//if pushing blocks located outside the land claim it lives in, cancel the event
|
||||
if(!claim.contains(pushedBlock.getLocation(), false, false))
|
||||
if (!claim.contains(pushedBlock.getLocation(), false, false))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
|
|
@ -516,7 +520,7 @@ public class BlockEventHandler implements Listener
|
|||
//if pushing a block inside the claim out of the claim, cancel the event
|
||||
//reason: could push into another land claim, don't want to spend CPU checking for that
|
||||
//reason: push ice out, place torch, get water outside the claim
|
||||
if(!claim.contains(pushedBlock.getRelative(event.getDirection()).getLocation(), false, false))
|
||||
if (!claim.contains(pushedBlock.getRelative(event.getDirection()).getLocation(), false, false))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
|
|
@ -529,15 +533,15 @@ public class BlockEventHandler implements Listener
|
|||
{
|
||||
//which blocks are being pushed?
|
||||
Claim cachedClaim = claim;
|
||||
for(int i = 0; i < blocks.size(); i++)
|
||||
for (int i = 0; i < blocks.size(); i++)
|
||||
{
|
||||
//if ANY of the pushed blocks are owned by someone other than the piston owner, cancel the event
|
||||
Block block = blocks.get(i);
|
||||
claim = this.dataStore.getClaimAt(block.getLocation(), false, cachedClaim);
|
||||
if(claim != null)
|
||||
if (claim != null)
|
||||
{
|
||||
cachedClaim = claim;
|
||||
if(!claim.getOwnerName().equals(pistonClaimOwnerName))
|
||||
if (!claim.getOwnerName().equals(pistonClaimOwnerName))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
pistonBlock.getWorld().createExplosion(pistonBlock.getLocation(), 0);
|
||||
|
|
@ -549,12 +553,12 @@ public class BlockEventHandler implements Listener
|
|||
}
|
||||
|
||||
//if any of the blocks are being pushed into a claim from outside, cancel the event
|
||||
for(int i = 0; i < blocks.size(); i++)
|
||||
for (int i = 0; i < blocks.size(); i++)
|
||||
{
|
||||
Block block = blocks.get(i);
|
||||
Claim originalClaim = this.dataStore.getClaimAt(block.getLocation(), false, cachedClaim);
|
||||
String originalOwnerName = "";
|
||||
if(originalClaim != null)
|
||||
if (originalClaim != null)
|
||||
{
|
||||
cachedClaim = originalClaim;
|
||||
originalOwnerName = originalClaim.getOwnerName();
|
||||
|
|
@ -562,13 +566,13 @@ public class BlockEventHandler implements Listener
|
|||
|
||||
Claim newClaim = this.dataStore.getClaimAt(block.getRelative(event.getDirection()).getLocation(), false, cachedClaim);
|
||||
String newOwnerName = "";
|
||||
if(newClaim != null)
|
||||
if (newClaim != null)
|
||||
{
|
||||
newOwnerName = newClaim.getOwnerName();
|
||||
}
|
||||
|
||||
//if pushing this block will change ownership, cancel the event and take away the piston (for performance reasons)
|
||||
if(!newOwnerName.equals(originalOwnerName) && !newOwnerName.isEmpty())
|
||||
if (!newOwnerName.equals(originalOwnerName) && !newOwnerName.isEmpty())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
pistonBlock.getWorld().createExplosion(pistonBlock.getLocation(), 0);
|
||||
|
|
@ -582,34 +586,34 @@ public class BlockEventHandler implements Listener
|
|||
|
||||
//blocks theft by pulling blocks out of a claim (again pistons)
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onBlockPistonRetract (BlockPistonRetractEvent event)
|
||||
public void onBlockPistonRetract(BlockPistonRetractEvent event)
|
||||
{
|
||||
//return if piston checks are not enabled
|
||||
if(!GriefPrevention.instance.config_checkPistonMovement) return;
|
||||
if (!GriefPrevention.instance.config_checkPistonMovement) return;
|
||||
|
||||
//pulling up is always safe
|
||||
if(event.getDirection() == BlockFace.UP) return;
|
||||
if (event.getDirection() == BlockFace.UP) return;
|
||||
|
||||
try
|
||||
{
|
||||
//don't track in worlds where claims are not enabled
|
||||
if(!GriefPrevention.instance.claimsEnabledForWorld(event.getBlock().getWorld())) return;
|
||||
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)
|
||||
if (GriefPrevention.instance.config_pistonsInClaimsOnly)
|
||||
{
|
||||
//if piston not in a land claim, cancel event
|
||||
Claim pistonClaim = this.dataStore.getClaimAt(event.getBlock().getLocation(), false, null);
|
||||
if(pistonClaim == null && !event.getBlocks().isEmpty())
|
||||
if (pistonClaim == null && !event.getBlocks().isEmpty())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
for(Block movedBlock : event.getBlocks())
|
||||
for (Block movedBlock : event.getBlocks())
|
||||
{
|
||||
//if pulled block isn't in the same land claim, cancel the event
|
||||
if(!pistonClaim.contains(movedBlock.getLocation(), false, false))
|
||||
if (!pistonClaim.contains(movedBlock.getLocation(), false, false))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
|
|
@ -625,18 +629,18 @@ public class BlockEventHandler implements Listener
|
|||
Block block = event.getBlock();
|
||||
Location pistonLocation = block.getLocation();
|
||||
Claim pistonClaim = this.dataStore.getClaimAt(pistonLocation, false, null);
|
||||
if(pistonClaim != null) pistonOwnerName = pistonClaim.getOwnerName();
|
||||
if (pistonClaim != null) pistonOwnerName = pistonClaim.getOwnerName();
|
||||
|
||||
String movingBlockOwnerName = "_";
|
||||
for(Block movedBlock : event.getBlocks())
|
||||
for (Block movedBlock : event.getBlocks())
|
||||
{
|
||||
//who owns the moving block, if anyone?
|
||||
Claim movingBlockClaim = this.dataStore.getClaimAt(movedBlock.getLocation(), false, pistonClaim);
|
||||
if(movingBlockClaim != null) movingBlockOwnerName = movingBlockClaim.getOwnerName();
|
||||
if (movingBlockClaim != null) movingBlockOwnerName = movingBlockClaim.getOwnerName();
|
||||
|
||||
//if there are owners for the blocks, they must be the same player
|
||||
//otherwise cancel the event
|
||||
if(!pistonOwnerName.equals(movingBlockOwnerName))
|
||||
if (!pistonOwnerName.equals(movingBlockOwnerName))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
block.getWorld().createExplosion(block.getLocation(), 0);
|
||||
|
|
@ -647,7 +651,7 @@ public class BlockEventHandler implements Listener
|
|||
}
|
||||
}
|
||||
}
|
||||
catch(NoSuchMethodError exception)
|
||||
catch (NoSuchMethodError exception)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Your server is running an outdated version of 1.8 which has a griefing vulnerability. Update your server (reruns buildtools.jar to get an updated server JAR file) to ensure players can't steal claimed blocks using pistons.");
|
||||
}
|
||||
|
|
@ -655,18 +659,19 @@ public class BlockEventHandler implements Listener
|
|||
|
||||
//blocks are ignited ONLY by flint and steel (not by being near lava, open flames, etc), unless configured otherwise
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onBlockIgnite (BlockIgniteEvent igniteEvent)
|
||||
public void onBlockIgnite(BlockIgniteEvent igniteEvent)
|
||||
{
|
||||
//don't track in worlds where claims are not enabled
|
||||
if(!GriefPrevention.instance.claimsEnabledForWorld(igniteEvent.getBlock().getWorld())) return;
|
||||
if (!GriefPrevention.instance.claimsEnabledForWorld(igniteEvent.getBlock().getWorld())) return;
|
||||
|
||||
if(igniteEvent.getCause() == IgniteCause.LIGHTNING && GriefPrevention.instance.dataStore.getClaimAt(igniteEvent.getIgnitingEntity().getLocation(), false, null) != null){
|
||||
if (igniteEvent.getCause() == IgniteCause.LIGHTNING && GriefPrevention.instance.dataStore.getClaimAt(igniteEvent.getIgnitingEntity().getLocation(), false, null) != null)
|
||||
{
|
||||
// if(igniteEvent.getIgnitingEntity().hasMetadata("GP_TRIDENT")){ //BlockIgniteEvent is called before LightningStrikeEvent. See #532
|
||||
igniteEvent.setCancelled(true);
|
||||
// }
|
||||
}
|
||||
|
||||
if(!GriefPrevention.instance.config_fireSpreads && igniteEvent.getCause() != IgniteCause.FLINT_AND_STEEL && igniteEvent.getCause() != IgniteCause.LIGHTNING)
|
||||
if (!GriefPrevention.instance.config_fireSpreads && igniteEvent.getCause() != IgniteCause.FLINT_AND_STEEL && igniteEvent.getCause() != IgniteCause.LIGHTNING)
|
||||
{
|
||||
igniteEvent.setCancelled(true);
|
||||
}
|
||||
|
|
@ -674,19 +679,19 @@ public class BlockEventHandler implements Listener
|
|||
|
||||
//fire doesn't spread unless configured to, but other blocks still do (mushrooms and vines, for example)
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onBlockSpread (BlockSpreadEvent spreadEvent)
|
||||
public void onBlockSpread(BlockSpreadEvent spreadEvent)
|
||||
{
|
||||
if(spreadEvent.getSource().getType() != Material.FIRE) return;
|
||||
if (spreadEvent.getSource().getType() != Material.FIRE) return;
|
||||
|
||||
//don't track in worlds where claims are not enabled
|
||||
if(!GriefPrevention.instance.claimsEnabledForWorld(spreadEvent.getBlock().getWorld())) return;
|
||||
if (!GriefPrevention.instance.claimsEnabledForWorld(spreadEvent.getBlock().getWorld())) return;
|
||||
|
||||
if(!GriefPrevention.instance.config_fireSpreads)
|
||||
if (!GriefPrevention.instance.config_fireSpreads)
|
||||
{
|
||||
spreadEvent.setCancelled(true);
|
||||
|
||||
Block underBlock = spreadEvent.getSource().getRelative(BlockFace.DOWN);
|
||||
if(underBlock.getType() != Material.NETHERRACK)
|
||||
if (underBlock.getType() != Material.NETHERRACK)
|
||||
{
|
||||
spreadEvent.getSource().setType(Material.AIR);
|
||||
}
|
||||
|
|
@ -695,14 +700,14 @@ public class BlockEventHandler implements Listener
|
|||
}
|
||||
|
||||
//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)
|
||||
{
|
||||
if(GriefPrevention.instance.config_claims_firespreads) return;
|
||||
if (GriefPrevention.instance.config_claims_firespreads) return;
|
||||
spreadEvent.setCancelled(true);
|
||||
|
||||
//if the source of the spread is not fire on netherrack, put out that source fire to save cpu cycles
|
||||
Block source = spreadEvent.getSource();
|
||||
if(source.getRelative(BlockFace.DOWN).getType() != Material.NETHERRACK)
|
||||
if (source.getRelative(BlockFace.DOWN).getType() != Material.NETHERRACK)
|
||||
{
|
||||
source.setType(Material.AIR);
|
||||
}
|
||||
|
|
@ -711,16 +716,16 @@ public class BlockEventHandler implements Listener
|
|||
|
||||
//blocks are not destroyed by fire, unless configured to do so
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onBlockBurn (BlockBurnEvent burnEvent)
|
||||
public void onBlockBurn(BlockBurnEvent burnEvent)
|
||||
{
|
||||
//don't track in worlds where claims are not enabled
|
||||
if(!GriefPrevention.instance.claimsEnabledForWorld(burnEvent.getBlock().getWorld())) return;
|
||||
if (!GriefPrevention.instance.claimsEnabledForWorld(burnEvent.getBlock().getWorld())) return;
|
||||
|
||||
if(!GriefPrevention.instance.config_fireDestroys)
|
||||
if (!GriefPrevention.instance.config_fireDestroys)
|
||||
{
|
||||
burnEvent.setCancelled(true);
|
||||
Block block = burnEvent.getBlock();
|
||||
Block [] adjacentBlocks = new Block []
|
||||
Block[] adjacentBlocks = new Block[]
|
||||
{
|
||||
block.getRelative(BlockFace.UP),
|
||||
block.getRelative(BlockFace.DOWN),
|
||||
|
|
@ -731,17 +736,17 @@ public class BlockEventHandler implements Listener
|
|||
};
|
||||
|
||||
//pro-actively put out any fires adjacent the burning block, to reduce future processing here
|
||||
for(int i = 0; i < adjacentBlocks.length; i++)
|
||||
for (int i = 0; i < adjacentBlocks.length; i++)
|
||||
{
|
||||
Block adjacentBlock = adjacentBlocks[i];
|
||||
if(adjacentBlock.getType() == Material.FIRE && adjacentBlock.getRelative(BlockFace.DOWN).getType() != Material.NETHERRACK)
|
||||
if (adjacentBlock.getType() == Material.FIRE && adjacentBlock.getRelative(BlockFace.DOWN).getType() != Material.NETHERRACK)
|
||||
{
|
||||
adjacentBlock.setType(Material.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
Block aboveBlock = block.getRelative(BlockFace.UP);
|
||||
if(aboveBlock.getType() == Material.FIRE)
|
||||
if (aboveBlock.getType() == Material.FIRE)
|
||||
{
|
||||
aboveBlock.setType(Material.AIR);
|
||||
}
|
||||
|
|
@ -749,25 +754,25 @@ public class BlockEventHandler implements Listener
|
|||
}
|
||||
|
||||
//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)
|
||||
{
|
||||
if(GriefPrevention.instance.config_claims_firedamages) return;
|
||||
if (GriefPrevention.instance.config_claims_firedamages) return;
|
||||
burnEvent.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//ensures fluids don't flow into land claims from outside
|
||||
private Claim lastSpreadClaim = null;
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onBlockFromTo (BlockFromToEvent spreadEvent)
|
||||
public void onBlockFromTo(BlockFromToEvent spreadEvent)
|
||||
{
|
||||
//always allow fluids to flow straight down
|
||||
if(spreadEvent.getFace() == BlockFace.DOWN) return;
|
||||
if (spreadEvent.getFace() == BlockFace.DOWN) return;
|
||||
|
||||
//don't track in worlds where claims are not enabled
|
||||
if(!GriefPrevention.instance.claimsEnabledForWorld(spreadEvent.getBlock().getWorld())) return;
|
||||
if (!GriefPrevention.instance.claimsEnabledForWorld(spreadEvent.getBlock().getWorld())) return;
|
||||
|
||||
//where to?
|
||||
Block toBlock = spreadEvent.getToBlock();
|
||||
|
|
@ -775,13 +780,13 @@ public class BlockEventHandler implements Listener
|
|||
Claim toClaim = this.dataStore.getClaimAt(toLocation, false, lastSpreadClaim);
|
||||
|
||||
//if into a land claim, it must be from the same land claim
|
||||
if(toClaim != null)
|
||||
if (toClaim != null)
|
||||
{
|
||||
this.lastSpreadClaim = toClaim;
|
||||
if(!toClaim.contains(spreadEvent.getBlock().getLocation(), false, true))
|
||||
if (!toClaim.contains(spreadEvent.getBlock().getLocation(), false, true))
|
||||
{
|
||||
//exception: from parent into subdivision
|
||||
if(toClaim.parent == null || !toClaim.parent.contains(spreadEvent.getBlock().getLocation(), false, false))
|
||||
if (toClaim.parent == null || !toClaim.parent.contains(spreadEvent.getBlock().getLocation(), false, false))
|
||||
{
|
||||
spreadEvent.setCancelled(true);
|
||||
}
|
||||
|
|
@ -789,7 +794,7 @@ public class BlockEventHandler implements Listener
|
|||
}
|
||||
|
||||
//otherwise if creative mode world, don't flow
|
||||
else if(GriefPrevention.instance.creativeRulesApply(toLocation))
|
||||
else if (GriefPrevention.instance.creativeRulesApply(toLocation))
|
||||
{
|
||||
spreadEvent.setCancelled(true);
|
||||
}
|
||||
|
|
@ -801,13 +806,13 @@ public class BlockEventHandler implements Listener
|
|||
Block block = event.getBlock();
|
||||
Location location = block.getLocation();
|
||||
|
||||
if(GriefPrevention.instance.creativeRulesApply(location))
|
||||
if (GriefPrevention.instance.creativeRulesApply(location))
|
||||
{
|
||||
Material type = block.getType();
|
||||
if(type == Material.COBBLESTONE || type == Material.OBSIDIAN || type == Material.LAVA || type == Material.WATER)
|
||||
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)
|
||||
if (claim == null)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
|
@ -820,7 +825,7 @@ public class BlockEventHandler implements Listener
|
|||
private void chorusFlower(ProjectileHitEvent event)
|
||||
{
|
||||
//don't track in worlds where claims are not enabled
|
||||
if(!GriefPrevention.instance.claimsEnabledForWorld(event.getEntity().getWorld())) return;
|
||||
if (!GriefPrevention.instance.claimsEnabledForWorld(event.getEntity().getWorld())) return;
|
||||
|
||||
if (event.getHitBlock() == null || event.getHitBlock().getType() != Material.CHORUS_FLOWER)
|
||||
return;
|
||||
|
|
@ -835,7 +840,7 @@ public class BlockEventHandler implements Listener
|
|||
Projectile projectile = event.getEntity();
|
||||
|
||||
if (projectile.getShooter() instanceof Player)
|
||||
shooter = (Player)projectile.getShooter();
|
||||
shooter = (Player) projectile.getShooter();
|
||||
|
||||
if (shooter == null)
|
||||
{
|
||||
|
|
@ -860,12 +865,12 @@ public class BlockEventHandler implements Listener
|
|||
public void onDispense(BlockDispenseEvent dispenseEvent)
|
||||
{
|
||||
//don't track in worlds where claims are not enabled
|
||||
if(!GriefPrevention.instance.claimsEnabledForWorld(dispenseEvent.getBlock().getWorld())) return;
|
||||
if (!GriefPrevention.instance.claimsEnabledForWorld(dispenseEvent.getBlock().getWorld())) return;
|
||||
|
||||
//from where?
|
||||
Block fromBlock = dispenseEvent.getBlock();
|
||||
BlockData fromData = fromBlock.getBlockData();
|
||||
if(!(fromData instanceof Dispenser)) return;
|
||||
if (!(fromData instanceof Dispenser)) return;
|
||||
Dispenser dispenser = (Dispenser) fromData;
|
||||
|
||||
//to where?
|
||||
|
|
@ -875,59 +880,59 @@ public class BlockEventHandler implements Listener
|
|||
|
||||
//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)
|
||||
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;
|
||||
if (fromClaim == null && toClaim == null) return;
|
||||
|
||||
//within claim is OK
|
||||
if(fromClaim == toClaim) return;
|
||||
if (fromClaim == toClaim) return;
|
||||
|
||||
//everything else is NOT OK
|
||||
dispenseEvent.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onTreeGrow (StructureGrowEvent growEvent)
|
||||
public void onTreeGrow(StructureGrowEvent growEvent)
|
||||
{
|
||||
//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;
|
||||
if (!GriefPrevention.instance.claimsEnabledForWorld(growEvent.getWorld())) return;
|
||||
|
||||
Location rootLocation = growEvent.getLocation();
|
||||
Claim rootClaim = this.dataStore.getClaimAt(rootLocation, false, null);
|
||||
String rootOwnerName = null;
|
||||
|
||||
//who owns the spreading block, if anyone?
|
||||
if(rootClaim != null)
|
||||
if (rootClaim != null)
|
||||
{
|
||||
//tree growth in subdivisions is dependent on who owns the top level claim
|
||||
if(rootClaim.parent != null) rootClaim = rootClaim.parent;
|
||||
if (rootClaim.parent != null) rootClaim = rootClaim.parent;
|
||||
|
||||
//if an administrative claim, just let the tree grow where it wants
|
||||
if(rootClaim.isAdminClaim()) return;
|
||||
if (rootClaim.isAdminClaim()) return;
|
||||
|
||||
//otherwise, note the owner of the claim
|
||||
rootOwnerName = rootClaim.getOwnerName();
|
||||
}
|
||||
|
||||
//for each block growing
|
||||
for(int i = 0; i < growEvent.getBlocks().size(); i++)
|
||||
for (int i = 0; i < growEvent.getBlocks().size(); i++)
|
||||
{
|
||||
BlockState block = growEvent.getBlocks().get(i);
|
||||
Claim blockClaim = this.dataStore.getClaimAt(block.getLocation(), false, rootClaim);
|
||||
|
||||
//if it's growing into a claim
|
||||
if(blockClaim != null)
|
||||
if (blockClaim != null)
|
||||
{
|
||||
//if there's no owner for the new tree, or the owner for the new tree is different from the owner of the claim
|
||||
if(rootOwnerName == null || !rootOwnerName.equals(blockClaim.getOwnerName()))
|
||||
if (rootOwnerName == null || !rootOwnerName.equals(blockClaim.getOwnerName()))
|
||||
{
|
||||
growEvent.getBlocks().remove(i--);
|
||||
}
|
||||
|
|
@ -936,28 +941,28 @@ public class BlockEventHandler implements Listener
|
|||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onInventoryPickupItem (InventoryPickupItemEvent event)
|
||||
public void onInventoryPickupItem(InventoryPickupItemEvent event)
|
||||
{
|
||||
//prevent hoppers from picking-up items dropped by players on death
|
||||
|
||||
InventoryHolder holder = event.getInventory().getHolder();
|
||||
if(holder instanceof HopperMinecart || holder instanceof Hopper)
|
||||
if (holder instanceof HopperMinecart || holder instanceof Hopper)
|
||||
{
|
||||
Item item = event.getItem();
|
||||
List<MetadataValue> data = item.getMetadata("GP_ITEMOWNER");
|
||||
//if this is marked as belonging to a player
|
||||
if(data != null && data.size() > 0)
|
||||
if (data != null && data.size() > 0)
|
||||
{
|
||||
UUID ownerID = (UUID)data.get(0).value();
|
||||
UUID ownerID = (UUID) data.get(0).value();
|
||||
|
||||
//has that player unlocked his drops?
|
||||
OfflinePlayer owner = GriefPrevention.instance.getServer().getOfflinePlayer(ownerID);
|
||||
if(owner.isOnline())
|
||||
if (owner.isOnline())
|
||||
{
|
||||
PlayerData playerData = this.dataStore.getPlayerData(ownerID);
|
||||
|
||||
//if locked, don't allow pickup
|
||||
if(!playerData.dropsAreUnlocked)
|
||||
if (!playerData.dropsAreUnlocked)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,9 +19,6 @@
|
|||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
|
@ -49,7 +46,7 @@ class CheckForPortalTrapTask extends BukkitRunnable
|
|||
@Override
|
||||
public void run()
|
||||
{
|
||||
if(player.isOnline() && player.getPortalCooldown() >= 10 && player.hasMetadata("GP_PORTALRESCUE"))
|
||||
if (player.isOnline() && player.getPortalCooldown() >= 10 && player.hasMetadata("GP_PORTALRESCUE"))
|
||||
{
|
||||
instance.AddLogEntry("Rescued " + player.getName() + " from a nether portal.\nTeleported from " + player.getLocation().toString() + " to " + returnLocation.toString(), CustomLogEntryTypes.Debug);
|
||||
player.teleport(returnLocation);
|
||||
|
|
|
|||
|
|
@ -18,15 +18,26 @@
|
|||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
//represents a player claim
|
||||
//creating an instance doesn't make an effective claim
|
||||
//only claims which have been added to the datastore have any effect
|
||||
|
|
@ -82,7 +93,7 @@ public class Claim
|
|||
//administrative claims are created and maintained by players with the griefprevention.adminclaims permission.
|
||||
public boolean isAdminClaim()
|
||||
{
|
||||
if(this.parent != null) return this.parent.isAdminClaim();
|
||||
if (this.parent != null) return this.parent.isAdminClaim();
|
||||
|
||||
return (this.ownerID == null);
|
||||
}
|
||||
|
|
@ -104,9 +115,9 @@ public class Claim
|
|||
//and when he has some level of permission in the claim
|
||||
public boolean canSiege(Player defender)
|
||||
{
|
||||
if(this.isAdminClaim()) return false;
|
||||
if (this.isAdminClaim()) return false;
|
||||
|
||||
if(this.allowAccess(defender) != null) return false;
|
||||
if (this.allowAccess(defender) != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -117,35 +128,36 @@ public class Claim
|
|||
public void removeSurfaceFluids(Claim exclusionClaim)
|
||||
{
|
||||
//don't do this for administrative claims
|
||||
if(this.isAdminClaim()) return;
|
||||
if (this.isAdminClaim()) return;
|
||||
|
||||
//don't do it for very large claims
|
||||
if(this.getArea() > 10000) return;
|
||||
if (this.getArea() > 10000) return;
|
||||
|
||||
//only in creative mode worlds
|
||||
if(!GriefPrevention.instance.creativeRulesApply(this.lesserBoundaryCorner)) return;
|
||||
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
|
||||
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());
|
||||
if (lesser.getWorld().getEnvironment() == Environment.NORMAL)
|
||||
seaLevel = GriefPrevention.instance.getSeaLevel(lesser.getWorld());
|
||||
|
||||
for(int x = lesser.getBlockX(); x <= greater.getBlockX(); x++)
|
||||
for (int x = lesser.getBlockX(); x <= greater.getBlockX(); x++)
|
||||
{
|
||||
for(int z = lesser.getBlockZ(); z <= greater.getBlockZ(); z++)
|
||||
for (int z = lesser.getBlockZ(); z <= greater.getBlockZ(); z++)
|
||||
{
|
||||
for(int y = seaLevel - 1; y <= lesser.getWorld().getMaxHeight(); y++)
|
||||
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 (exclusionClaim != null && exclusionClaim.contains(block.getLocation(), true, false)) continue;
|
||||
|
||||
if(block.getType() == Material.LAVA || block.getType() == Material.WATER)
|
||||
if (block.getType() == Material.LAVA || block.getType() == Material.WATER)
|
||||
{
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
|
|
@ -162,23 +174,24 @@ public class Claim
|
|||
Location greater = this.getGreaterBoundaryCorner();
|
||||
|
||||
//don't bother for very large claims, too expensive
|
||||
if(this.getArea() > 10000) return false;
|
||||
if (this.getArea() > 10000) return false;
|
||||
|
||||
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());
|
||||
if (lesser.getWorld().getEnvironment() == Environment.NORMAL)
|
||||
seaLevel = GriefPrevention.instance.getSeaLevel(lesser.getWorld());
|
||||
|
||||
for(int x = lesser.getBlockX(); x <= greater.getBlockX(); x++)
|
||||
for (int x = lesser.getBlockX(); x <= greater.getBlockX(); x++)
|
||||
{
|
||||
for(int z = lesser.getBlockZ(); z <= greater.getBlockZ(); z++)
|
||||
for (int z = lesser.getBlockZ(); z <= greater.getBlockZ(); z++)
|
||||
{
|
||||
for(int y = seaLevel - 1; y <= lesser.getWorld().getMaxHeight(); y++)
|
||||
for (int y = seaLevel - 1; y <= lesser.getWorld().getMaxHeight(); y++)
|
||||
{
|
||||
//dodge the exclusion claim
|
||||
Block block = lesser.getWorld().getBlockAt(x, y, z);
|
||||
|
||||
if(block.getType() == Material.WATER || block.getType() == Material.LAVA)
|
||||
if (block.getType() == Material.WATER || block.getType() == Material.LAVA)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
@ -206,24 +219,24 @@ public class Claim
|
|||
this.ownerID = ownerID;
|
||||
|
||||
//other permissions
|
||||
for(String builderID : builderIDs)
|
||||
for (String builderID : builderIDs)
|
||||
{
|
||||
this.setPermission(builderID, ClaimPermission.Build);
|
||||
}
|
||||
|
||||
for(String containerID : containerIDs)
|
||||
for (String containerID : containerIDs)
|
||||
{
|
||||
this.setPermission(containerID, ClaimPermission.Inventory);
|
||||
}
|
||||
|
||||
for(String accessorID : accessorIDs)
|
||||
for (String accessorID : accessorIDs)
|
||||
{
|
||||
this.setPermission(accessorID, ClaimPermission.Access);
|
||||
}
|
||||
|
||||
for(String managerID : managerIDs)
|
||||
for (String managerID : managerIDs)
|
||||
{
|
||||
if(managerID != null && !managerID.isEmpty())
|
||||
if (managerID != null && !managerID.isEmpty())
|
||||
{
|
||||
this.managers.add(managerID);
|
||||
}
|
||||
|
|
@ -282,26 +295,26 @@ public class Claim
|
|||
public String allowEdit(Player player)
|
||||
{
|
||||
//if we don't know who's asking, always say no (i've been told some mods can make this happen somehow)
|
||||
if(player == null) return "";
|
||||
if (player == null) return "";
|
||||
|
||||
//special cases...
|
||||
|
||||
//admin claims need adminclaims permission only.
|
||||
if(this.isAdminClaim())
|
||||
if (this.isAdminClaim())
|
||||
{
|
||||
if(player.hasPermission("griefprevention.adminclaims")) return null;
|
||||
if (player.hasPermission("griefprevention.adminclaims")) return null;
|
||||
}
|
||||
|
||||
//anyone with deleteclaims permission can modify non-admin claims at any time
|
||||
else
|
||||
{
|
||||
if(player.hasPermission("griefprevention.deleteclaims")) return null;
|
||||
if (player.hasPermission("griefprevention.deleteclaims")) return null;
|
||||
}
|
||||
|
||||
//no resizing, deleting, and so forth while under siege
|
||||
if(player.getUniqueId().equals(this.ownerID))
|
||||
if (player.getUniqueId().equals(this.ownerID))
|
||||
{
|
||||
if(this.siegeData != null)
|
||||
if (this.siegeData != null)
|
||||
{
|
||||
return GriefPrevention.instance.dataStore.getMessage(Messages.NoModifyDuringSiege);
|
||||
}
|
||||
|
|
@ -311,7 +324,7 @@ public class Claim
|
|||
}
|
||||
|
||||
//permission inheritance for subdivisions
|
||||
if(this.parent != null)
|
||||
if (this.parent != null)
|
||||
{
|
||||
if (player.getUniqueId().equals(this.parent.ownerID))
|
||||
return null;
|
||||
|
|
@ -341,51 +354,52 @@ public class Claim
|
|||
public String allowBuild(Player player, Material material)
|
||||
{
|
||||
//if we don't know who's asking, always say no (i've been told some mods can make this happen somehow)
|
||||
if(player == null) return "";
|
||||
if (player == null) return "";
|
||||
|
||||
//when a player tries to build in a claim, if he's under siege, the siege may extend to include the new claim
|
||||
GriefPrevention.instance.dataStore.tryExtendSiege(player, this);
|
||||
|
||||
//admin claims can always be modified by admins, no exceptions
|
||||
if(this.isAdminClaim())
|
||||
if (this.isAdminClaim())
|
||||
{
|
||||
if(player.hasPermission("griefprevention.adminclaims")) return null;
|
||||
if (player.hasPermission("griefprevention.adminclaims")) return null;
|
||||
}
|
||||
|
||||
//no building while under siege
|
||||
if(this.siegeData != null)
|
||||
if (this.siegeData != null)
|
||||
{
|
||||
return GriefPrevention.instance.dataStore.getMessage(Messages.NoBuildUnderSiege, this.siegeData.attacker.getName());
|
||||
}
|
||||
|
||||
//no building while in pvp combat
|
||||
PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId());
|
||||
if(playerData.inPvpCombat())
|
||||
if (playerData.inPvpCombat())
|
||||
{
|
||||
return GriefPrevention.instance.dataStore.getMessage(Messages.NoBuildPvP);
|
||||
}
|
||||
|
||||
//owners can make changes, or admins with ignore claims mode enabled
|
||||
if(player.getUniqueId().equals(this.ownerID) || GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId()).ignoreClaims) return null;
|
||||
if (player.getUniqueId().equals(this.ownerID) || GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId()).ignoreClaims)
|
||||
return null;
|
||||
|
||||
//anyone with explicit build permission can make changes
|
||||
if(this.hasExplicitPermission(player, ClaimPermission.Build)) return null;
|
||||
if (this.hasExplicitPermission(player, ClaimPermission.Build)) return null;
|
||||
|
||||
//also everyone is a member of the "public", so check for public permission
|
||||
if(ClaimPermission.Build.isGrantedBy(this.playerIDToClaimPermissionMap.get("public"))) return null;
|
||||
if (ClaimPermission.Build.isGrantedBy(this.playerIDToClaimPermissionMap.get("public"))) return null;
|
||||
|
||||
//allow for farming with /containertrust permission
|
||||
if(this.allowContainers(player) == null)
|
||||
if (this.allowContainers(player) == null)
|
||||
{
|
||||
//do allow for farming, if player has /containertrust permission
|
||||
if(this.placeableForFarming(material))
|
||||
if (this.placeableForFarming(material))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//subdivision permission inheritance
|
||||
if(this.parent != null)
|
||||
if (this.parent != null)
|
||||
{
|
||||
if (player.getUniqueId().equals(this.parent.ownerID))
|
||||
return null;
|
||||
|
|
@ -395,7 +409,7 @@ public class Claim
|
|||
|
||||
//failure message for all other cases
|
||||
String reason = GriefPrevention.instance.dataStore.getMessage(Messages.NoBuildPermission, this.getOwnerName());
|
||||
if(player.hasPermission("griefprevention.ignoreclaims"))
|
||||
if (player.hasPermission("griefprevention.ignoreclaims"))
|
||||
reason += " " + GriefPrevention.instance.dataStore.getMessage(Messages.IgnoreClaimsAdvertisement);
|
||||
|
||||
return reason;
|
||||
|
|
@ -416,7 +430,7 @@ public class Claim
|
|||
{
|
||||
String node = stringToPermission.getKey();
|
||||
// Ensure valid permission format for permissions - [permission.node]
|
||||
if (node.length() < 3 || node.charAt(0) != '[' || node.charAt(node.length() -1) != ']')
|
||||
if (node.length() < 3 || node.charAt(0) != '[' || node.charAt(node.length() - 1) != ']')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
@ -436,15 +450,15 @@ public class Claim
|
|||
public String allowBreak(Player player, Material material)
|
||||
{
|
||||
//if under siege, some blocks will be breakable
|
||||
if(this.siegeData != null || this.doorsOpen)
|
||||
if (this.siegeData != null || this.doorsOpen)
|
||||
{
|
||||
boolean breakable = false;
|
||||
|
||||
//search for block type in list of breakable blocks
|
||||
for(int i = 0; i < GriefPrevention.instance.config_siege_blocks.size(); i++)
|
||||
for (int i = 0; i < GriefPrevention.instance.config_siege_blocks.size(); i++)
|
||||
{
|
||||
Material breakableMaterial = GriefPrevention.instance.config_siege_blocks.get(i);
|
||||
if(breakableMaterial == material)
|
||||
if (breakableMaterial == material)
|
||||
{
|
||||
breakable = true;
|
||||
break;
|
||||
|
|
@ -452,15 +466,13 @@ public class Claim
|
|||
}
|
||||
|
||||
//custom error messages for siege mode
|
||||
if(!breakable)
|
||||
if (!breakable)
|
||||
{
|
||||
return GriefPrevention.instance.dataStore.getMessage(Messages.NonSiegeMaterial);
|
||||
}
|
||||
else if(player.getUniqueId().equals(this.ownerID))
|
||||
} else if (player.getUniqueId().equals(this.ownerID))
|
||||
{
|
||||
return GriefPrevention.instance.dataStore.getMessage(Messages.NoOwnerBuildUnderSiege);
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
|
@ -474,25 +486,26 @@ public class Claim
|
|||
public String allowAccess(Player player)
|
||||
{
|
||||
//following a siege where the defender lost, the claim will allow everyone access for a time
|
||||
if(this.doorsOpen) return null;
|
||||
if (this.doorsOpen) return null;
|
||||
|
||||
//admin claims need adminclaims permission only.
|
||||
if(this.isAdminClaim())
|
||||
if (this.isAdminClaim())
|
||||
{
|
||||
if(player.hasPermission("griefprevention.adminclaims")) return null;
|
||||
if (player.hasPermission("griefprevention.adminclaims")) return null;
|
||||
}
|
||||
|
||||
//claim owner and admins in ignoreclaims mode have access
|
||||
if(player.getUniqueId().equals(this.ownerID) || GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId()).ignoreClaims) return null;
|
||||
if (player.getUniqueId().equals(this.ownerID) || GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId()).ignoreClaims)
|
||||
return null;
|
||||
|
||||
//look for explicit individual access, inventory, or build permission
|
||||
if(this.hasExplicitPermission(player, ClaimPermission.Access)) return null;
|
||||
if (this.hasExplicitPermission(player, ClaimPermission.Access)) return null;
|
||||
|
||||
//also check for public permission
|
||||
if(ClaimPermission.Access.isGrantedBy(this.playerIDToClaimPermissionMap.get("public"))) return null;
|
||||
if (ClaimPermission.Access.isGrantedBy(this.playerIDToClaimPermissionMap.get("public"))) return null;
|
||||
|
||||
//permission inheritance for subdivisions
|
||||
if(this.parent != null)
|
||||
if (this.parent != null)
|
||||
{
|
||||
if (player.getUniqueId().equals(this.parent.ownerID))
|
||||
return null;
|
||||
|
|
@ -502,7 +515,7 @@ public class Claim
|
|||
|
||||
//catch-all error message for all other cases
|
||||
String reason = GriefPrevention.instance.dataStore.getMessage(Messages.NoAccessPermission, this.getOwnerName());
|
||||
if(player.hasPermission("griefprevention.ignoreclaims"))
|
||||
if (player.hasPermission("griefprevention.ignoreclaims"))
|
||||
reason += " " + GriefPrevention.instance.dataStore.getMessage(Messages.IgnoreClaimsAdvertisement);
|
||||
return reason;
|
||||
}
|
||||
|
|
@ -511,34 +524,35 @@ public class Claim
|
|||
public String allowContainers(Player player)
|
||||
{
|
||||
//if we don't know who's asking, always say no (i've been told some mods can make this happen somehow)
|
||||
if(player == null) return "";
|
||||
if (player == null) return "";
|
||||
|
||||
//trying to access inventory in a claim may extend an existing siege to include this claim
|
||||
GriefPrevention.instance.dataStore.tryExtendSiege(player, this);
|
||||
|
||||
//if under siege, nobody accesses containers
|
||||
if(this.siegeData != null)
|
||||
if (this.siegeData != null)
|
||||
{
|
||||
return GriefPrevention.instance.dataStore.getMessage(Messages.NoContainersSiege, siegeData.attacker.getName());
|
||||
}
|
||||
|
||||
//owner and administrators in ignoreclaims mode have access
|
||||
if(player.getUniqueId().equals(this.ownerID) || GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId()).ignoreClaims) return null;
|
||||
if (player.getUniqueId().equals(this.ownerID) || GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId()).ignoreClaims)
|
||||
return null;
|
||||
|
||||
//admin claims need adminclaims permission only.
|
||||
if(this.isAdminClaim())
|
||||
if (this.isAdminClaim())
|
||||
{
|
||||
if(player.hasPermission("griefprevention.adminclaims")) return null;
|
||||
if (player.hasPermission("griefprevention.adminclaims")) return null;
|
||||
}
|
||||
|
||||
//check for explicit individual container or build permission
|
||||
if(this.hasExplicitPermission(player, ClaimPermission.Inventory)) return null;
|
||||
if (this.hasExplicitPermission(player, ClaimPermission.Inventory)) return null;
|
||||
|
||||
//check for public container or build permission
|
||||
if(ClaimPermission.Inventory.isGrantedBy(this.playerIDToClaimPermissionMap.get("public"))) return null;
|
||||
if (ClaimPermission.Inventory.isGrantedBy(this.playerIDToClaimPermissionMap.get("public"))) return null;
|
||||
|
||||
//permission inheritance for subdivisions
|
||||
if(this.parent != null)
|
||||
if (this.parent != null)
|
||||
{
|
||||
if (player.getUniqueId().equals(this.parent.ownerID))
|
||||
return null;
|
||||
|
|
@ -548,7 +562,7 @@ public class Claim
|
|||
|
||||
//error message for all other cases
|
||||
String reason = GriefPrevention.instance.dataStore.getMessage(Messages.NoContainersPermission, this.getOwnerName());
|
||||
if(player.hasPermission("griefprevention.ignoreclaims"))
|
||||
if (player.hasPermission("griefprevention.ignoreclaims"))
|
||||
reason += " " + GriefPrevention.instance.dataStore.getMessage(Messages.IgnoreClaimsAdvertisement);
|
||||
return reason;
|
||||
}
|
||||
|
|
@ -557,27 +571,27 @@ public class Claim
|
|||
public String allowGrantPermission(Player player)
|
||||
{
|
||||
//if we don't know who's asking, always say no (i've been told some mods can make this happen somehow)
|
||||
if(player == null) return "";
|
||||
if (player == null) return "";
|
||||
|
||||
//anyone who can modify the claim can do this
|
||||
if(this.allowEdit(player) == null) return null;
|
||||
if (this.allowEdit(player) == null) return null;
|
||||
|
||||
//anyone who's in the managers (/PermissionTrust) list can do this
|
||||
for(int i = 0; i < this.managers.size(); i++)
|
||||
for (int i = 0; i < this.managers.size(); i++)
|
||||
{
|
||||
String managerID = this.managers.get(i);
|
||||
if(player.getUniqueId().toString().equals(managerID)) return null;
|
||||
if (player.getUniqueId().toString().equals(managerID)) return null;
|
||||
|
||||
else if(managerID.startsWith("[") && managerID.endsWith("]"))
|
||||
else if (managerID.startsWith("[") && managerID.endsWith("]"))
|
||||
{
|
||||
managerID = managerID.substring(1, managerID.length() - 1);
|
||||
if(managerID == null || managerID.isEmpty()) continue;
|
||||
if(player.hasPermission(managerID)) return null;
|
||||
if (managerID == null || managerID.isEmpty()) continue;
|
||||
if (player.hasPermission(managerID)) return null;
|
||||
}
|
||||
}
|
||||
|
||||
//permission inheritance for subdivisions
|
||||
if(this.parent != null)
|
||||
if (this.parent != null)
|
||||
{
|
||||
if (player.getUniqueId().equals(this.parent.ownerID))
|
||||
return null;
|
||||
|
|
@ -587,7 +601,7 @@ public class Claim
|
|||
|
||||
//generic error message
|
||||
String reason = GriefPrevention.instance.dataStore.getMessage(Messages.NoPermissionTrust, this.getOwnerName());
|
||||
if(player.hasPermission("griefprevention.ignoreclaims"))
|
||||
if (player.hasPermission("griefprevention.ignoreclaims"))
|
||||
reason += " " + GriefPrevention.instance.dataStore.getMessage(Messages.IgnoreClaimsAdvertisement);
|
||||
return reason;
|
||||
}
|
||||
|
|
@ -618,7 +632,7 @@ public class Claim
|
|||
{
|
||||
this.playerIDToClaimPermissionMap.remove(playerID.toLowerCase());
|
||||
|
||||
for(Claim child : this.children)
|
||||
for (Claim child : this.children)
|
||||
{
|
||||
child.dropPermission(playerID);
|
||||
}
|
||||
|
|
@ -630,7 +644,7 @@ public class Claim
|
|||
this.playerIDToClaimPermissionMap.clear();
|
||||
this.managers.clear();
|
||||
|
||||
for(Claim child : this.children)
|
||||
for (Claim child : this.children)
|
||||
{
|
||||
child.clearPermissions();
|
||||
}
|
||||
|
|
@ -642,27 +656,25 @@ public class Claim
|
|||
{
|
||||
//loop through all the entries in the hash map
|
||||
Iterator<Map.Entry<String, ClaimPermission>> mappingsIterator = this.playerIDToClaimPermissionMap.entrySet().iterator();
|
||||
while(mappingsIterator.hasNext())
|
||||
while (mappingsIterator.hasNext())
|
||||
{
|
||||
Map.Entry<String, ClaimPermission> entry = mappingsIterator.next();
|
||||
|
||||
//build up a list for each permission level
|
||||
if(entry.getValue() == ClaimPermission.Build)
|
||||
if (entry.getValue() == ClaimPermission.Build)
|
||||
{
|
||||
builders.add(entry.getKey());
|
||||
}
|
||||
else if(entry.getValue() == ClaimPermission.Inventory)
|
||||
} else if (entry.getValue() == ClaimPermission.Inventory)
|
||||
{
|
||||
containers.add(entry.getKey());
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
accessors.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
//managers are handled a little differently
|
||||
for(int i = 0; i < this.managers.size(); i++)
|
||||
for (int i = 0; i < this.managers.size(); i++)
|
||||
{
|
||||
managers.add(this.managers.get(i));
|
||||
}
|
||||
|
|
@ -684,10 +696,10 @@ public class Claim
|
|||
//returns a friendly owner name (for admin claims, returns "an administrator" as the owner)
|
||||
public String getOwnerName()
|
||||
{
|
||||
if(this.parent != null)
|
||||
if (this.parent != null)
|
||||
return this.parent.getOwnerName();
|
||||
|
||||
if(this.ownerID == null)
|
||||
if (this.ownerID == null)
|
||||
return GriefPrevention.instance.dataStore.getMessage(Messages.OwnerNameForAdminClaims);
|
||||
|
||||
return GriefPrevention.lookupPlayerName(this.ownerID);
|
||||
|
|
@ -699,7 +711,7 @@ public class Claim
|
|||
public boolean contains(Location location, boolean ignoreHeight, boolean excludeSubdivisions)
|
||||
{
|
||||
//not in the same world implies false
|
||||
if(!location.getWorld().equals(this.lesserBoundaryCorner.getWorld())) return false;
|
||||
if (!location.getWorld().equals(this.lesserBoundaryCorner.getWorld())) return false;
|
||||
|
||||
double x = location.getX();
|
||||
double y = location.getY();
|
||||
|
|
@ -712,25 +724,25 @@ public class Claim
|
|||
z >= this.lesserBoundaryCorner.getZ() &&
|
||||
z < this.greaterBoundaryCorner.getZ() + 1;
|
||||
|
||||
if(!inClaim) return false;
|
||||
if (!inClaim) return false;
|
||||
|
||||
//additional check for subdivisions
|
||||
//you're only in a subdivision when you're also in its parent claim
|
||||
//NOTE: if a player creates subdivions then resizes the parent claim, it's possible that
|
||||
//a subdivision can reach outside of its parent's boundaries. so this check is important!
|
||||
if(this.parent != null)
|
||||
if (this.parent != null)
|
||||
{
|
||||
return this.parent.contains(location, ignoreHeight, false);
|
||||
}
|
||||
|
||||
//code to exclude subdivisions in this check
|
||||
else if(excludeSubdivisions)
|
||||
else if (excludeSubdivisions)
|
||||
{
|
||||
//search all subdivisions to see if the location is in any of them
|
||||
for(int i = 0; i < this.children.size(); i++)
|
||||
for (int i = 0; i < this.children.size(); i++)
|
||||
{
|
||||
//if we find such a subdivision, return false
|
||||
if(this.children.get(i).contains(location, ignoreHeight, true))
|
||||
if (this.children.get(i).contains(location, ignoreHeight, true))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
@ -748,40 +760,42 @@ public class Claim
|
|||
//NOTE: if trying to understand this makes your head hurt, don't feel bad - it hurts mine too.
|
||||
//try drawing pictures to visualize test cases.
|
||||
|
||||
if(!this.lesserBoundaryCorner.getWorld().equals(otherClaim.getLesserBoundaryCorner().getWorld())) return false;
|
||||
if (!this.lesserBoundaryCorner.getWorld().equals(otherClaim.getLesserBoundaryCorner().getWorld())) return false;
|
||||
|
||||
//first, check the corners of this claim aren't inside any existing claims
|
||||
if(otherClaim.contains(this.lesserBoundaryCorner, true, false)) return true;
|
||||
if(otherClaim.contains(this.greaterBoundaryCorner, true, false)) return true;
|
||||
if(otherClaim.contains(new Location(this.lesserBoundaryCorner.getWorld(), this.lesserBoundaryCorner.getBlockX(), 0, this.greaterBoundaryCorner.getBlockZ()), true, false)) return true;
|
||||
if(otherClaim.contains(new Location(this.lesserBoundaryCorner.getWorld(), this.greaterBoundaryCorner.getBlockX(), 0, this.lesserBoundaryCorner.getBlockZ()), true, false)) return true;
|
||||
if (otherClaim.contains(this.lesserBoundaryCorner, true, false)) return true;
|
||||
if (otherClaim.contains(this.greaterBoundaryCorner, true, false)) return true;
|
||||
if (otherClaim.contains(new Location(this.lesserBoundaryCorner.getWorld(), this.lesserBoundaryCorner.getBlockX(), 0, this.greaterBoundaryCorner.getBlockZ()), true, false))
|
||||
return true;
|
||||
if (otherClaim.contains(new Location(this.lesserBoundaryCorner.getWorld(), this.greaterBoundaryCorner.getBlockX(), 0, this.lesserBoundaryCorner.getBlockZ()), true, false))
|
||||
return true;
|
||||
|
||||
//verify that no claim's lesser boundary point is inside this new claim, to cover the "existing claim is entirely inside new claim" case
|
||||
if(this.contains(otherClaim.getLesserBoundaryCorner(), true, false)) return true;
|
||||
if (this.contains(otherClaim.getLesserBoundaryCorner(), true, false)) return true;
|
||||
|
||||
//verify this claim doesn't band across an existing claim, either horizontally or vertically
|
||||
if( this.getLesserBoundaryCorner().getBlockZ() <= otherClaim.getGreaterBoundaryCorner().getBlockZ() &&
|
||||
if (this.getLesserBoundaryCorner().getBlockZ() <= otherClaim.getGreaterBoundaryCorner().getBlockZ() &&
|
||||
this.getLesserBoundaryCorner().getBlockZ() >= otherClaim.getLesserBoundaryCorner().getBlockZ() &&
|
||||
this.getLesserBoundaryCorner().getBlockX() < otherClaim.getLesserBoundaryCorner().getBlockX() &&
|
||||
this.getGreaterBoundaryCorner().getBlockX() > otherClaim.getGreaterBoundaryCorner().getBlockX() )
|
||||
this.getGreaterBoundaryCorner().getBlockX() > otherClaim.getGreaterBoundaryCorner().getBlockX())
|
||||
return true;
|
||||
|
||||
if( this.getGreaterBoundaryCorner().getBlockZ() <= otherClaim.getGreaterBoundaryCorner().getBlockZ() &&
|
||||
if (this.getGreaterBoundaryCorner().getBlockZ() <= otherClaim.getGreaterBoundaryCorner().getBlockZ() &&
|
||||
this.getGreaterBoundaryCorner().getBlockZ() >= otherClaim.getLesserBoundaryCorner().getBlockZ() &&
|
||||
this.getLesserBoundaryCorner().getBlockX() < otherClaim.getLesserBoundaryCorner().getBlockX() &&
|
||||
this.getGreaterBoundaryCorner().getBlockX() > otherClaim.getGreaterBoundaryCorner().getBlockX() )
|
||||
this.getGreaterBoundaryCorner().getBlockX() > otherClaim.getGreaterBoundaryCorner().getBlockX())
|
||||
return true;
|
||||
|
||||
if( this.getLesserBoundaryCorner().getBlockX() <= otherClaim.getGreaterBoundaryCorner().getBlockX() &&
|
||||
if (this.getLesserBoundaryCorner().getBlockX() <= otherClaim.getGreaterBoundaryCorner().getBlockX() &&
|
||||
this.getLesserBoundaryCorner().getBlockX() >= otherClaim.getLesserBoundaryCorner().getBlockX() &&
|
||||
this.getLesserBoundaryCorner().getBlockZ() < otherClaim.getLesserBoundaryCorner().getBlockZ() &&
|
||||
this.getGreaterBoundaryCorner().getBlockZ() > otherClaim.getGreaterBoundaryCorner().getBlockZ() )
|
||||
this.getGreaterBoundaryCorner().getBlockZ() > otherClaim.getGreaterBoundaryCorner().getBlockZ())
|
||||
return true;
|
||||
|
||||
if( this.getGreaterBoundaryCorner().getBlockX() <= otherClaim.getGreaterBoundaryCorner().getBlockX() &&
|
||||
if (this.getGreaterBoundaryCorner().getBlockX() <= otherClaim.getGreaterBoundaryCorner().getBlockX() &&
|
||||
this.getGreaterBoundaryCorner().getBlockX() >= otherClaim.getLesserBoundaryCorner().getBlockX() &&
|
||||
this.getLesserBoundaryCorner().getBlockZ() < otherClaim.getLesserBoundaryCorner().getBlockZ() &&
|
||||
this.getGreaterBoundaryCorner().getBlockZ() > otherClaim.getGreaterBoundaryCorner().getBlockZ() )
|
||||
this.getGreaterBoundaryCorner().getBlockZ() > otherClaim.getGreaterBoundaryCorner().getBlockZ())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
|
@ -790,63 +804,65 @@ public class Claim
|
|||
//whether more entities may be added to a claim
|
||||
public String allowMoreEntities(boolean remove)
|
||||
{
|
||||
if(this.parent != null) return this.parent.allowMoreEntities(remove);
|
||||
if (this.parent != null) return this.parent.allowMoreEntities(remove);
|
||||
|
||||
//this rule only applies to creative mode worlds
|
||||
if(!GriefPrevention.instance.creativeRulesApply(this.getLesserBoundaryCorner())) return null;
|
||||
if (!GriefPrevention.instance.creativeRulesApply(this.getLesserBoundaryCorner())) return null;
|
||||
|
||||
//admin claims aren't restricted
|
||||
if(this.isAdminClaim()) return null;
|
||||
if (this.isAdminClaim()) return null;
|
||||
|
||||
//don't apply this rule to very large claims
|
||||
if(this.getArea() > 10000) return null;
|
||||
if (this.getArea() > 10000) return null;
|
||||
|
||||
//determine maximum allowable entity count, based on claim size
|
||||
int maxEntities = this.getArea() / 50;
|
||||
if(maxEntities == 0) return GriefPrevention.instance.dataStore.getMessage(Messages.ClaimTooSmallForEntities);
|
||||
if (maxEntities == 0) return GriefPrevention.instance.dataStore.getMessage(Messages.ClaimTooSmallForEntities);
|
||||
|
||||
//count current entities (ignoring players)
|
||||
int totalEntities = 0;
|
||||
ArrayList<Chunk> chunks = this.getChunks();
|
||||
for(Chunk chunk : chunks)
|
||||
for (Chunk chunk : chunks)
|
||||
{
|
||||
Entity [] entities = chunk.getEntities();
|
||||
for(int i = 0; i < entities.length; i++)
|
||||
Entity[] entities = chunk.getEntities();
|
||||
for (int i = 0; i < entities.length; i++)
|
||||
{
|
||||
Entity entity = entities[i];
|
||||
if(!(entity instanceof Player) && this.contains(entity.getLocation(), false, false))
|
||||
if (!(entity instanceof Player) && this.contains(entity.getLocation(), false, false))
|
||||
{
|
||||
totalEntities++;
|
||||
if(remove && totalEntities > maxEntities) entity.remove();
|
||||
if (remove && totalEntities > maxEntities) entity.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(totalEntities >= maxEntities) return GriefPrevention.instance.dataStore.getMessage(Messages.TooManyEntitiesInClaim);
|
||||
if (totalEntities >= maxEntities)
|
||||
return GriefPrevention.instance.dataStore.getMessage(Messages.TooManyEntitiesInClaim);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String allowMoreActiveBlocks()
|
||||
{
|
||||
if(this.parent != null) return this.parent.allowMoreActiveBlocks();
|
||||
if (this.parent != null) return this.parent.allowMoreActiveBlocks();
|
||||
|
||||
//determine maximum allowable entity count, based on claim size
|
||||
int maxActives = this.getArea() / 100;
|
||||
if(maxActives == 0) return GriefPrevention.instance.dataStore.getMessage(Messages.ClaimTooSmallForActiveBlocks);
|
||||
if (maxActives == 0)
|
||||
return GriefPrevention.instance.dataStore.getMessage(Messages.ClaimTooSmallForActiveBlocks);
|
||||
|
||||
//count current actives
|
||||
int totalActives = 0;
|
||||
ArrayList<Chunk> chunks = this.getChunks();
|
||||
for(Chunk chunk : chunks)
|
||||
for (Chunk chunk : chunks)
|
||||
{
|
||||
BlockState [] actives = chunk.getTileEntities();
|
||||
for(int i = 0; i < actives.length; i++)
|
||||
BlockState[] actives = chunk.getTileEntities();
|
||||
for (int i = 0; i < actives.length; i++)
|
||||
{
|
||||
BlockState active = actives[i];
|
||||
if(BlockEventHandler.isActiveBlock(active))
|
||||
if (BlockEventHandler.isActiveBlock(active))
|
||||
{
|
||||
if(this.contains(active.getLocation(), false, false))
|
||||
if (this.contains(active.getLocation(), false, false))
|
||||
{
|
||||
totalActives++;
|
||||
}
|
||||
|
|
@ -854,7 +870,8 @@ public class Claim
|
|||
}
|
||||
}
|
||||
|
||||
if(totalActives >= maxActives) return GriefPrevention.instance.dataStore.getMessage(Messages.TooManyActiveBlocksInClaim);
|
||||
if (totalActives >= maxActives)
|
||||
return GriefPrevention.instance.dataStore.getMessage(Messages.TooManyActiveBlocksInClaim);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
@ -865,13 +882,13 @@ public class Claim
|
|||
Location thisCorner = this.getLesserBoundaryCorner();
|
||||
Location otherCorner = otherClaim.getLesserBoundaryCorner();
|
||||
|
||||
if(thisCorner.getBlockX() > otherCorner.getBlockX()) return true;
|
||||
if (thisCorner.getBlockX() > otherCorner.getBlockX()) return true;
|
||||
|
||||
if(thisCorner.getBlockX() < otherCorner.getBlockX()) return false;
|
||||
if (thisCorner.getBlockX() < otherCorner.getBlockX()) return false;
|
||||
|
||||
if(thisCorner.getBlockZ() > otherCorner.getBlockZ()) return true;
|
||||
if (thisCorner.getBlockZ() > otherCorner.getBlockZ()) return true;
|
||||
|
||||
if(thisCorner.getBlockZ() < otherCorner.getBlockZ()) return false;
|
||||
if (thisCorner.getBlockZ() < otherCorner.getBlockZ()) return false;
|
||||
|
||||
return thisCorner.getWorld().getName().compareTo(otherCorner.getWorld().getName()) < 0;
|
||||
}
|
||||
|
|
@ -888,41 +905,38 @@ public class Claim
|
|||
|
||||
boolean creativeMode = GriefPrevention.instance.creativeRulesApply(lesserBoundaryCorner);
|
||||
|
||||
for(int x = this.lesserBoundaryCorner.getBlockX(); x <= this.greaterBoundaryCorner.getBlockX(); x++)
|
||||
for (int x = this.lesserBoundaryCorner.getBlockX(); x <= this.greaterBoundaryCorner.getBlockX(); x++)
|
||||
{
|
||||
for(int z = this.lesserBoundaryCorner.getBlockZ(); z <= this.greaterBoundaryCorner.getBlockZ(); z++)
|
||||
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++)
|
||||
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 (playerBlocks.contains(block.getType()))
|
||||
{
|
||||
if(block.getType() == Material.CHEST && !creativeMode)
|
||||
if (block.getType() == Material.CHEST && !creativeMode)
|
||||
{
|
||||
score += 10;
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
score += .5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(; y < this.lesserBoundaryCorner.getWorld().getMaxHeight(); y++)
|
||||
for (; y < this.lesserBoundaryCorner.getWorld().getMaxHeight(); y++)
|
||||
{
|
||||
Block block = this.lesserBoundaryCorner.getWorld().getBlockAt(x, y, z);
|
||||
if(playerBlocks.contains(block.getType()))
|
||||
if (playerBlocks.contains(block.getType()))
|
||||
{
|
||||
if(block.getType() == Material.CHEST && !creativeMode)
|
||||
if (block.getType() == Material.CHEST && !creativeMode)
|
||||
{
|
||||
score += 10;
|
||||
}
|
||||
else if(creativeMode && (block.getType() == Material.LAVA))
|
||||
} else if (creativeMode && (block.getType() == Material.LAVA))
|
||||
{
|
||||
score -= 10;
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
score += 1;
|
||||
}
|
||||
|
|
@ -931,7 +945,7 @@ public class Claim
|
|||
}
|
||||
}
|
||||
|
||||
return (long)score;
|
||||
return (long) score;
|
||||
}
|
||||
|
||||
public ArrayList<Chunk> getChunks()
|
||||
|
|
@ -942,9 +956,9 @@ public class Claim
|
|||
Chunk lesserChunk = this.getLesserBoundaryCorner().getChunk();
|
||||
Chunk greaterChunk = this.getGreaterBoundaryCorner().getChunk();
|
||||
|
||||
for(int x = lesserChunk.getX(); x <= greaterChunk.getX(); x++)
|
||||
for (int x = lesserChunk.getX(); x <= greaterChunk.getX(); x++)
|
||||
{
|
||||
for(int z = lesserChunk.getZ(); z <= greaterChunk.getZ(); z++)
|
||||
for (int z = lesserChunk.getZ(); z <= greaterChunk.getZ(); z++)
|
||||
{
|
||||
chunks.add(world.getChunkAt(x, z));
|
||||
}
|
||||
|
|
@ -961,9 +975,9 @@ public class Claim
|
|||
int largeX = this.getGreaterBoundaryCorner().getBlockX() >> 4;
|
||||
int largeZ = this.getGreaterBoundaryCorner().getBlockZ() >> 4;
|
||||
|
||||
for(int x = smallX; x <= largeX; x++)
|
||||
for (int x = smallX; x <= largeX; x++)
|
||||
{
|
||||
for(int z = smallZ; z <= largeZ; z++)
|
||||
for (int z = smallZ; z <= largeZ; z++)
|
||||
{
|
||||
hashes.add(DataStore.getChunkHash(x, z));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
|
@ -46,12 +46,12 @@ class CleanupUnusedClaimPreTask implements Runnable
|
|||
|
||||
//expiration code uses last logout timestamp to decide whether to expire claims
|
||||
//don't expire claims for online players
|
||||
if(ownerInfo.isOnline())
|
||||
if (ownerInfo.isOnline())
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Player is online. Ignoring.", CustomLogEntryTypes.Debug, true);
|
||||
return;
|
||||
}
|
||||
if(ownerInfo.getLastPlayed() <= 0)
|
||||
if (ownerInfo.getLastPlayed() <= 0)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Player is new or not in the server's cached userdata. Ignoring. getLastPlayed = " + ownerInfo.getLastPlayed(), CustomLogEntryTypes.Debug, true);
|
||||
return;
|
||||
|
|
@ -59,7 +59,7 @@ class CleanupUnusedClaimPreTask implements Runnable
|
|||
|
||||
//skip claims belonging to exempted players based on block totals in config
|
||||
int bonusBlocks = ownerData.getBonusClaimBlocks();
|
||||
if(bonusBlocks >= GriefPrevention.instance.config_claims_expirationExemptionBonusBlocks || bonusBlocks + ownerData.getAccruedClaimBlocks() >= GriefPrevention.instance.config_claims_expirationExemptionTotalBlocks)
|
||||
if (bonusBlocks >= GriefPrevention.instance.config_claims_expirationExemptionBonusBlocks || bonusBlocks + ownerData.getAccruedClaimBlocks() >= GriefPrevention.instance.config_claims_expirationExemptionTotalBlocks)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Player exempt from claim expiration based on claim block counts vs. config file settings.", CustomLogEntryTypes.Debug, true);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -16,17 +16,16 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.events.ClaimExpirationEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.events.ClaimExpirationEvent;
|
||||
|
||||
class CleanupUnusedClaimTask implements Runnable
|
||||
{
|
||||
Claim claim;
|
||||
|
|
@ -47,19 +46,19 @@ class CleanupUnusedClaimTask implements Runnable
|
|||
|
||||
//determine area of the default chest claim
|
||||
int areaOfDefaultClaim = 0;
|
||||
if(GriefPrevention.instance.config_claims_automaticClaimsForNewPlayersRadius >= 0)
|
||||
if (GriefPrevention.instance.config_claims_automaticClaimsForNewPlayersRadius >= 0)
|
||||
{
|
||||
areaOfDefaultClaim = (int)Math.pow(GriefPrevention.instance.config_claims_automaticClaimsForNewPlayersRadius * 2 + 1, 2);
|
||||
areaOfDefaultClaim = (int) Math.pow(GriefPrevention.instance.config_claims_automaticClaimsForNewPlayersRadius * 2 + 1, 2);
|
||||
}
|
||||
|
||||
//if this claim is a chest claim and those are set to expire
|
||||
if(claim.getArea() <= areaOfDefaultClaim && GriefPrevention.instance.config_claims_chestClaimExpirationDays > 0)
|
||||
if (claim.getArea() <= areaOfDefaultClaim && GriefPrevention.instance.config_claims_chestClaimExpirationDays > 0)
|
||||
{
|
||||
//if the owner has been gone at least a week, and if he has ONLY the new player claim, it will be removed
|
||||
Calendar sevenDaysAgo = Calendar.getInstance();
|
||||
sevenDaysAgo.add(Calendar.DATE, -GriefPrevention.instance.config_claims_chestClaimExpirationDays);
|
||||
boolean newPlayerClaimsExpired = sevenDaysAgo.getTime().after(new Date(ownerInfo.getLastPlayed()));
|
||||
if(newPlayerClaimsExpired && ownerData.getClaims().size() == 1)
|
||||
if (newPlayerClaimsExpired && ownerData.getClaims().size() == 1)
|
||||
{
|
||||
if (expireEventCanceled())
|
||||
return;
|
||||
|
|
@ -67,7 +66,7 @@ class CleanupUnusedClaimTask implements Runnable
|
|||
GriefPrevention.instance.dataStore.deleteClaim(claim, true, true);
|
||||
|
||||
//if configured to do so, restore the land to natural
|
||||
if(GriefPrevention.instance.creativeRulesApply(claim.getLesserBoundaryCorner()) || GriefPrevention.instance.config_claims_survivalAutoNatureRestoration)
|
||||
if (GriefPrevention.instance.creativeRulesApply(claim.getLesserBoundaryCorner()) || GriefPrevention.instance.config_claims_survivalAutoNatureRestoration)
|
||||
{
|
||||
GriefPrevention.instance.restoreClaim(claim, 0);
|
||||
}
|
||||
|
|
@ -77,18 +76,18 @@ class CleanupUnusedClaimTask implements Runnable
|
|||
}
|
||||
|
||||
//if configured to always remove claims after some inactivity period without exceptions...
|
||||
else if(GriefPrevention.instance.config_claims_expirationDays > 0)
|
||||
else if (GriefPrevention.instance.config_claims_expirationDays > 0)
|
||||
{
|
||||
Calendar earliestPermissibleLastLogin = Calendar.getInstance();
|
||||
earliestPermissibleLastLogin.add(Calendar.DATE, -GriefPrevention.instance.config_claims_expirationDays);
|
||||
|
||||
if(earliestPermissibleLastLogin.getTime().after(new Date(ownerInfo.getLastPlayed())))
|
||||
if (earliestPermissibleLastLogin.getTime().after(new Date(ownerInfo.getLastPlayed())))
|
||||
{
|
||||
if (expireEventCanceled())
|
||||
return;
|
||||
//make a copy of this player's claim list
|
||||
Vector<Claim> claims = new Vector<Claim>();
|
||||
for(int i = 0; i < ownerData.getClaims().size(); i++)
|
||||
for (int i = 0; i < ownerData.getClaims().size(); i++)
|
||||
{
|
||||
claims.add(ownerData.getClaims().get(i));
|
||||
}
|
||||
|
|
@ -97,34 +96,32 @@ class CleanupUnusedClaimTask implements Runnable
|
|||
GriefPrevention.instance.dataStore.deleteClaimsForPlayer(claim.ownerID, true);
|
||||
GriefPrevention.AddLogEntry(" All of " + claim.getOwnerName() + "'s claims have expired.", CustomLogEntryTypes.AdminActivity);
|
||||
|
||||
for(int i = 0; i < claims.size(); i++)
|
||||
for (int i = 0; i < claims.size(); i++)
|
||||
{
|
||||
//if configured to do so, restore the land to natural
|
||||
if(GriefPrevention.instance.creativeRulesApply(claims.get(i).getLesserBoundaryCorner()) || GriefPrevention.instance.config_claims_survivalAutoNatureRestoration)
|
||||
if (GriefPrevention.instance.creativeRulesApply(claims.get(i).getLesserBoundaryCorner()) || GriefPrevention.instance.config_claims_survivalAutoNatureRestoration)
|
||||
{
|
||||
GriefPrevention.instance.restoreClaim(claims.get(i), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if(GriefPrevention.instance.config_claims_unusedClaimExpirationDays > 0 && GriefPrevention.instance.creativeRulesApply(claim.getLesserBoundaryCorner()))
|
||||
} else if (GriefPrevention.instance.config_claims_unusedClaimExpirationDays > 0 && GriefPrevention.instance.creativeRulesApply(claim.getLesserBoundaryCorner()))
|
||||
{
|
||||
//avoid scanning large claims and administrative claims
|
||||
if(claim.isAdminClaim() || claim.getWidth() > 25 || claim.getHeight() > 25) return;
|
||||
if (claim.isAdminClaim() || claim.getWidth() > 25 || claim.getHeight() > 25) return;
|
||||
|
||||
//otherwise scan the claim content
|
||||
int minInvestment = 400;
|
||||
|
||||
long investmentScore = claim.getPlayerInvestmentScore();
|
||||
|
||||
if(investmentScore < minInvestment)
|
||||
if (investmentScore < minInvestment)
|
||||
{
|
||||
//if the owner has been gone at least a week, and if he has ONLY the new player claim, it will be removed
|
||||
Calendar sevenDaysAgo = Calendar.getInstance();
|
||||
sevenDaysAgo.add(Calendar.DATE, -GriefPrevention.instance.config_claims_unusedClaimExpirationDays);
|
||||
boolean claimExpired = sevenDaysAgo.getTime().after(new Date(ownerInfo.getLastPlayed()));
|
||||
if(claimExpired)
|
||||
if (claimExpired)
|
||||
{
|
||||
if (expireEventCanceled())
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,9 @@
|
|||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.Charset;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
|
@ -26,10 +29,6 @@ import java.util.Date;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
|
||||
class CustomLogger
|
||||
{
|
||||
private final SimpleDateFormat timestampFormat = new SimpleDateFormat("HH:mm");
|
||||
|
|
@ -51,7 +50,7 @@ class CustomLogger
|
|||
|
||||
//unless disabled, schedule recurring tasks
|
||||
int daysToKeepLogs = GriefPrevention.instance.config_logs_daysToKeep;
|
||||
if(daysToKeepLogs > 0)
|
||||
if (daysToKeepLogs > 0)
|
||||
{
|
||||
BukkitScheduler scheduler = GriefPrevention.instance.getServer().getScheduler();
|
||||
final long ticksPerSecond = 20L;
|
||||
|
|
@ -62,14 +61,15 @@ class CustomLogger
|
|||
}
|
||||
|
||||
private static final Pattern inlineFormatterPattern = Pattern.compile("§.");
|
||||
|
||||
void AddEntry(String entry, CustomLogEntryTypes entryType)
|
||||
{
|
||||
//if disabled, do nothing
|
||||
int daysToKeepLogs = GriefPrevention.instance.config_logs_daysToKeep;
|
||||
if(daysToKeepLogs == 0) return;
|
||||
if (daysToKeepLogs == 0) return;
|
||||
|
||||
//if entry type is not enabled, do nothing
|
||||
if(!this.isEnabledType(entryType)) return;
|
||||
if (!this.isEnabledType(entryType)) return;
|
||||
|
||||
//otherwise write to the in-memory buffer, after removing formatters
|
||||
Matcher matcher = inlineFormatterPattern.matcher(entry);
|
||||
|
|
@ -80,12 +80,16 @@ class CustomLogger
|
|||
|
||||
private boolean isEnabledType(CustomLogEntryTypes entryType)
|
||||
{
|
||||
if(entryType == CustomLogEntryTypes.Exception) return true;
|
||||
if(entryType == CustomLogEntryTypes.SocialActivity && !GriefPrevention.instance.config_logs_socialEnabled) return false;
|
||||
if(entryType == CustomLogEntryTypes.SuspiciousActivity && !GriefPrevention.instance.config_logs_suspiciousEnabled) return false;
|
||||
if(entryType == CustomLogEntryTypes.AdminActivity && !GriefPrevention.instance.config_logs_adminEnabled) return false;
|
||||
if(entryType == CustomLogEntryTypes.Debug && !GriefPrevention.instance.config_logs_debugEnabled) return false;
|
||||
if(entryType == CustomLogEntryTypes.MutedChat && !GriefPrevention.instance.config_logs_mutedChatEnabled) return false;
|
||||
if (entryType == CustomLogEntryTypes.Exception) return true;
|
||||
if (entryType == CustomLogEntryTypes.SocialActivity && !GriefPrevention.instance.config_logs_socialEnabled)
|
||||
return false;
|
||||
if (entryType == CustomLogEntryTypes.SuspiciousActivity && !GriefPrevention.instance.config_logs_suspiciousEnabled)
|
||||
return false;
|
||||
if (entryType == CustomLogEntryTypes.AdminActivity && !GriefPrevention.instance.config_logs_adminEnabled)
|
||||
return false;
|
||||
if (entryType == CustomLogEntryTypes.Debug && !GriefPrevention.instance.config_logs_debugEnabled) return false;
|
||||
if (entryType == CustomLogEntryTypes.MutedChat && !GriefPrevention.instance.config_logs_mutedChatEnabled)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -95,7 +99,7 @@ class CustomLogger
|
|||
try
|
||||
{
|
||||
//if nothing to write, stop here
|
||||
if(this.queuedEntries.length() == 0) return;
|
||||
if (this.queuedEntries.length() == 0) return;
|
||||
|
||||
//determine filename based on date
|
||||
String filename = this.filenameFormat.format(new Date()) + ".log";
|
||||
|
|
@ -109,7 +113,7 @@ class CustomLogger
|
|||
//the unwritten entries will remain the buffer for the next write to retry
|
||||
this.queuedEntries.setLength(0);
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
@ -121,20 +125,20 @@ class CustomLogger
|
|||
{
|
||||
//get list of log files
|
||||
File logFolder = new File(this.logFolderPath);
|
||||
File [] files = logFolder.listFiles();
|
||||
File[] files = logFolder.listFiles();
|
||||
|
||||
//delete any created before x days ago
|
||||
int daysToKeepLogs = GriefPrevention.instance.config_logs_daysToKeep;
|
||||
Calendar expirationBoundary = Calendar.getInstance();
|
||||
expirationBoundary.add(Calendar.DATE, -daysToKeepLogs);
|
||||
for(int i = 0; i < files.length; i++)
|
||||
for (int i = 0; i < files.length; i++)
|
||||
{
|
||||
File file = files[i];
|
||||
if(file.isDirectory()) continue; //skip any folders
|
||||
if (file.isDirectory()) continue; //skip any folders
|
||||
|
||||
String filename = file.getName().replace(".log", "");
|
||||
String [] dateParts = filename.split("_"); //format is yyyy_MM_dd
|
||||
if(dateParts.length != 3) continue;
|
||||
String[] dateParts = filename.split("_"); //format is yyyy_MM_dd
|
||||
if (dateParts.length != 3) continue;
|
||||
|
||||
try
|
||||
{
|
||||
|
|
@ -144,19 +148,19 @@ class CustomLogger
|
|||
|
||||
Calendar filedate = Calendar.getInstance();
|
||||
filedate.set(year, month, day);
|
||||
if(filedate.before(expirationBoundary))
|
||||
if (filedate.before(expirationBoundary))
|
||||
{
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
catch(NumberFormatException e)
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
//throw this away - effectively ignoring any files without the correct filename format
|
||||
GriefPrevention.AddLogEntry("Ignoring an unexpected file in the abridged logs folder: " + file.getName(), CustomLogEntryTypes.Debug, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -18,14 +18,27 @@
|
|||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.sql.*;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
import org.bukkit.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.UUID;
|
||||
|
||||
//manages data stored in the file system
|
||||
public class DatabaseDataStore extends DataStore
|
||||
|
|
@ -66,7 +79,7 @@ public class DatabaseDataStore extends DataStore
|
|||
//load the java driver for mySQL
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("ERROR: Unable to load Java's mySQL database driver. Check to make sure you've installed it properly.");
|
||||
throw e;
|
||||
|
|
@ -76,7 +89,7 @@ public class DatabaseDataStore extends DataStore
|
|||
{
|
||||
this.refreshDataConnection();
|
||||
}
|
||||
catch(Exception e2)
|
||||
catch (Exception e2)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("ERROR: Unable to connect to database. Check your config file settings.");
|
||||
throw e2;
|
||||
|
|
@ -103,12 +116,12 @@ public class DatabaseDataStore extends DataStore
|
|||
//if the next claim id table is empty, this is a brand new database which will write using the latest schema
|
||||
//otherwise, schema version is determined by schemaversion table (or =0 if table is empty, see getSchemaVersion())
|
||||
ResultSet results = statement.executeQuery("SELECT * FROM griefprevention_nextclaimid;");
|
||||
if(!results.next())
|
||||
if (!results.next())
|
||||
{
|
||||
this.setSchemaVersion(latestSchemaVersion);
|
||||
}
|
||||
}
|
||||
catch(Exception e3)
|
||||
catch (Exception e3)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("ERROR: Unable to create the necessary database table. Details:");
|
||||
GriefPrevention.AddLogEntry(e3.getMessage());
|
||||
|
|
@ -133,15 +146,15 @@ public class DatabaseDataStore extends DataStore
|
|||
Statement statement = databaseConnection.createStatement();
|
||||
ResultSet results = statement.executeQuery("SELECT * FROM griefprevention_playerdata;");
|
||||
|
||||
while(results.next())
|
||||
while (results.next())
|
||||
{
|
||||
String name = results.getString("name");
|
||||
|
||||
//ignore non-groups. all group names start with a dollar sign.
|
||||
if(!name.startsWith("$")) continue;
|
||||
if (!name.startsWith("$")) continue;
|
||||
|
||||
String groupName = name.substring(1);
|
||||
if(groupName == null || groupName.isEmpty()) continue; //defensive coding, avoid unlikely cases
|
||||
if (groupName == null || groupName.isEmpty()) continue; //defensive coding, avoid unlikely cases
|
||||
|
||||
int groupBonusBlocks = results.getInt("bonusblocks");
|
||||
|
||||
|
|
@ -152,10 +165,10 @@ public class DatabaseDataStore extends DataStore
|
|||
results = statement.executeQuery("SELECT * FROM griefprevention_nextclaimid;");
|
||||
|
||||
//if there's nothing yet, add it
|
||||
if(!results.next())
|
||||
if (!results.next())
|
||||
{
|
||||
statement.execute("INSERT INTO griefprevention_nextclaimid VALUES(0);");
|
||||
this.nextClaimID = (long)0;
|
||||
this.nextClaimID = (long) 0;
|
||||
}
|
||||
|
||||
//otherwise load it
|
||||
|
|
@ -164,7 +177,7 @@ public class DatabaseDataStore extends DataStore
|
|||
this.nextClaimID = results.getLong("nextid");
|
||||
}
|
||||
|
||||
if(this.getSchemaVersion() == 0)
|
||||
if (this.getSchemaVersion() == 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -178,7 +191,7 @@ public class DatabaseDataStore extends DataStore
|
|||
HashMap<String, UUID> changes = new HashMap<String, UUID>();
|
||||
|
||||
ArrayList<String> namesToConvert = new ArrayList<String>();
|
||||
while(results.next())
|
||||
while (results.next())
|
||||
{
|
||||
//get the id
|
||||
String playerName = results.getString("name");
|
||||
|
|
@ -193,7 +206,7 @@ public class DatabaseDataStore extends DataStore
|
|||
UUIDFetcher fetcher = new UUIDFetcher(namesToConvert);
|
||||
fetcher.call();
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Failed to resolve a batch of names to UUIDs. Details:" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
|
|
@ -203,7 +216,7 @@ public class DatabaseDataStore extends DataStore
|
|||
results.beforeFirst();
|
||||
|
||||
//for each result
|
||||
while(results.next())
|
||||
while (results.next())
|
||||
{
|
||||
//get the id
|
||||
String playerName = results.getString("name");
|
||||
|
|
@ -214,33 +227,34 @@ public class DatabaseDataStore extends DataStore
|
|||
UUID playerID = UUIDFetcher.getUUIDOf(playerName);
|
||||
|
||||
//if successful, update the playerdata row by replacing the player's name with the player's UUID
|
||||
if(playerID != null)
|
||||
if (playerID != null)
|
||||
{
|
||||
changes.put(playerName, playerID);
|
||||
}
|
||||
}
|
||||
//otherwise leave it as-is. no harm done - it won't be requested by name, and this update only happens once.
|
||||
catch(Exception ex){ }
|
||||
catch (Exception ex) { }
|
||||
}
|
||||
|
||||
//refresh data connection in case data migration took a long time
|
||||
this.refreshDataConnection();
|
||||
|
||||
for(String name : changes.keySet())
|
||||
for (String name : changes.keySet())
|
||||
{
|
||||
try (PreparedStatement updateStmnt = this.databaseConnection.prepareStatement(this.getUpdateNameSQL()))
|
||||
{
|
||||
try (PreparedStatement updateStmnt = this.databaseConnection.prepareStatement(this.getUpdateNameSQL())) {
|
||||
updateStmnt.setString(1, changes.get(name).toString());
|
||||
updateStmnt.setString(2, name);
|
||||
updateStmnt.executeUpdate();
|
||||
}
|
||||
catch(SQLException e)
|
||||
catch (SQLException e)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Unable to convert player data for " + name + ". Skipping.");
|
||||
GriefPrevention.AddLogEntry(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(SQLException e)
|
||||
catch (SQLException e)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Unable to convert player data. Details:");
|
||||
GriefPrevention.AddLogEntry(e.getMessage());
|
||||
|
|
@ -248,7 +262,7 @@ public class DatabaseDataStore extends DataStore
|
|||
}
|
||||
}
|
||||
|
||||
if(this.getSchemaVersion() <= 2)
|
||||
if (this.getSchemaVersion() <= 2)
|
||||
{
|
||||
statement = this.databaseConnection.createStatement();
|
||||
statement.execute("ALTER TABLE griefprevention_claimdata ADD inheritNothing BOOLEAN DEFAULT 0 AFTER managers;");
|
||||
|
|
@ -263,7 +277,7 @@ public class DatabaseDataStore extends DataStore
|
|||
List<World> validWorlds = Bukkit.getServer().getWorlds();
|
||||
|
||||
Long claimID = null;
|
||||
while(results.next())
|
||||
while (results.next())
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -283,14 +297,13 @@ public class DatabaseDataStore extends DataStore
|
|||
String greaterCornerString = results.getString("greatercorner");
|
||||
greaterBoundaryCorner = this.locationFromString(greaterCornerString, validWorlds);
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
if(e.getMessage() != null && e.getMessage().contains("World not found"))
|
||||
if (e.getMessage() != null && e.getMessage().contains("World not found"))
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Failed to load a claim (ID:" + claimID.toString() + ") because its world isn't loaded (yet?). Please delete the claim or contact the GriefPrevention developer with information about which plugin(s) you're using to load or create worlds. " + lesserCornerString);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
|
|
@ -298,29 +311,27 @@ public class DatabaseDataStore extends DataStore
|
|||
|
||||
String ownerName = results.getString("owner");
|
||||
UUID ownerID = null;
|
||||
if(ownerName.isEmpty() || ownerName.startsWith("--"))
|
||||
if (ownerName.isEmpty() || ownerName.startsWith("--"))
|
||||
{
|
||||
ownerID = null; //administrative land claim or subdivision
|
||||
}
|
||||
else if(this.getSchemaVersion() < 1)
|
||||
} else if (this.getSchemaVersion() < 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
ownerID = UUIDFetcher.getUUIDOf(ownerName);
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("This owner name did not convert to a UUID: " + ownerName + ".");
|
||||
GriefPrevention.AddLogEntry(" Converted land claim to administrative @ " + lesserBoundaryCorner.toString());
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
try
|
||||
{
|
||||
ownerID = UUID.fromString(ownerName);
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("This owner entry is not a UUID: " + ownerName + ".");
|
||||
GriefPrevention.AddLogEntry(" Converted land claim to administrative @ " + lesserBoundaryCorner.toString());
|
||||
|
|
@ -344,22 +355,20 @@ public class DatabaseDataStore extends DataStore
|
|||
managerNames = this.convertNameListToUUIDList(managerNames);
|
||||
Claim claim = new Claim(lesserBoundaryCorner, greaterBoundaryCorner, ownerID, builderNames, containerNames, accessorNames, managerNames, inheritNothing, claimID);
|
||||
|
||||
if(removeClaim)
|
||||
if (removeClaim)
|
||||
{
|
||||
claimsToRemove.add(claim);
|
||||
}
|
||||
else if(parentId == -1)
|
||||
} else if (parentId == -1)
|
||||
{
|
||||
//top level claim
|
||||
this.addClaim(claim, false);
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
//subdivision
|
||||
subdivisionsToLoad.add(claim);
|
||||
}
|
||||
}
|
||||
catch(SQLException e)
|
||||
catch (SQLException e)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Unable to load a claim. Details: " + e.getMessage() + " ... " + results.toString());
|
||||
e.printStackTrace();
|
||||
|
|
@ -367,12 +376,12 @@ public class DatabaseDataStore extends DataStore
|
|||
}
|
||||
|
||||
//add subdivisions to their parent claims
|
||||
for(Claim childClaim : subdivisionsToLoad)
|
||||
for (Claim childClaim : subdivisionsToLoad)
|
||||
{
|
||||
//find top level claim parent
|
||||
Claim topLevelClaim = this.getClaimAt(childClaim.getLesserBoundaryCorner(), true, null);
|
||||
|
||||
if(topLevelClaim == null)
|
||||
if (topLevelClaim == null)
|
||||
{
|
||||
claimsToRemove.add(childClaim);
|
||||
GriefPrevention.AddLogEntry("Removing orphaned claim subdivision: " + childClaim.getLesserBoundaryCorner().toString());
|
||||
|
|
@ -385,12 +394,12 @@ public class DatabaseDataStore extends DataStore
|
|||
childClaim.inDataStore = true;
|
||||
}
|
||||
|
||||
for(Claim claim : claimsToRemove)
|
||||
for (Claim claim : claimsToRemove)
|
||||
{
|
||||
this.deleteClaimFromSecondaryStorage(claim);
|
||||
}
|
||||
|
||||
if(this.getSchemaVersion() <= 2)
|
||||
if (this.getSchemaVersion() <= 2)
|
||||
{
|
||||
this.refreshDataConnection();
|
||||
statement = this.databaseConnection.createStatement();
|
||||
|
|
@ -413,7 +422,7 @@ public class DatabaseDataStore extends DataStore
|
|||
//write claim data to the database
|
||||
this.writeClaimData(claim);
|
||||
}
|
||||
catch(SQLException e)
|
||||
catch (SQLException e)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Unable to save data for claim at " + this.locationToString(claim.lesserBoundaryCorner) + ". Details:");
|
||||
GriefPrevention.AddLogEntry(e.getMessage());
|
||||
|
|
@ -426,7 +435,7 @@ public class DatabaseDataStore extends DataStore
|
|||
String lesserCornerString = this.locationToString(claim.getLesserBoundaryCorner());
|
||||
String greaterCornerString = this.locationToString(claim.getGreaterBoundaryCorner());
|
||||
String owner = "";
|
||||
if(claim.ownerID != null) owner = claim.ownerID.toString();
|
||||
if (claim.ownerID != null) owner = claim.ownerID.toString();
|
||||
|
||||
ArrayList<String> builders = new ArrayList<String>();
|
||||
ArrayList<String> containers = new ArrayList<String>();
|
||||
|
|
@ -442,7 +451,8 @@ public class DatabaseDataStore extends DataStore
|
|||
boolean inheritNothing = claim.getSubclaimRestrictions();
|
||||
long parentId = claim.parent == null ? -1 : claim.parent.id;
|
||||
|
||||
try (PreparedStatement insertStmt = this.databaseConnection.prepareStatement(this.getInsertClaimSQL())) {
|
||||
try (PreparedStatement insertStmt = this.databaseConnection.prepareStatement(this.getInsertClaimSQL()))
|
||||
{
|
||||
|
||||
insertStmt.setLong(1, claim.id);
|
||||
insertStmt.setString(2, owner);
|
||||
|
|
@ -456,7 +466,7 @@ public class DatabaseDataStore extends DataStore
|
|||
insertStmt.setLong(10, parentId);
|
||||
insertStmt.executeUpdate();
|
||||
}
|
||||
catch(SQLException e)
|
||||
catch (SQLException e)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Unable to save data for claim at " + this.locationToString(claim.lesserBoundaryCorner) + ". Details:");
|
||||
GriefPrevention.AddLogEntry(e.getMessage());
|
||||
|
|
@ -467,11 +477,12 @@ public class DatabaseDataStore extends DataStore
|
|||
@Override
|
||||
synchronized void deleteClaimFromSecondaryStorage(Claim claim)
|
||||
{
|
||||
try(PreparedStatement deleteStmnt = this.databaseConnection.prepareStatement(this.getDeleteClaimSQL())) {
|
||||
try (PreparedStatement deleteStmnt = this.databaseConnection.prepareStatement(this.getDeleteClaimSQL()))
|
||||
{
|
||||
deleteStmnt.setLong(1, claim.id);
|
||||
deleteStmnt.executeUpdate();
|
||||
}
|
||||
catch(SQLException e)
|
||||
catch (SQLException e)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Unable to delete data for claim " + claim.id + ". Details:");
|
||||
GriefPrevention.AddLogEntry(e.getMessage());
|
||||
|
|
@ -485,19 +496,19 @@ public class DatabaseDataStore extends DataStore
|
|||
PlayerData playerData = new PlayerData();
|
||||
playerData.playerID = playerID;
|
||||
|
||||
try (PreparedStatement selectStmnt = this.databaseConnection.prepareStatement( this.getGetPlayerDataSQL()))
|
||||
try (PreparedStatement selectStmnt = this.databaseConnection.prepareStatement(this.getGetPlayerDataSQL()))
|
||||
{
|
||||
selectStmnt.setString(1, playerID.toString());
|
||||
ResultSet results = selectStmnt.executeQuery();
|
||||
|
||||
//if data for this player exists, use it
|
||||
if(results.next())
|
||||
if (results.next())
|
||||
{
|
||||
playerData.setAccruedClaimBlocks(results.getInt("accruedblocks"));
|
||||
playerData.setBonusClaimBlocks(results.getInt("bonusblocks"));
|
||||
}
|
||||
}
|
||||
catch(SQLException e)
|
||||
catch (SQLException e)
|
||||
{
|
||||
StringWriter errors = new StringWriter();
|
||||
e.printStackTrace(new PrintWriter(errors));
|
||||
|
|
@ -512,7 +523,7 @@ public class DatabaseDataStore extends DataStore
|
|||
public void overrideSavePlayerData(UUID playerID, PlayerData playerData)
|
||||
{
|
||||
//never save data for the "administrative" account. an empty string for player name indicates administrative account
|
||||
if(playerID == null) return;
|
||||
if (playerID == null) return;
|
||||
|
||||
this.savePlayerData(playerID.toString(), playerData);
|
||||
}
|
||||
|
|
@ -520,7 +531,8 @@ public class DatabaseDataStore extends DataStore
|
|||
private void savePlayerData(String playerID, PlayerData playerData)
|
||||
{
|
||||
try (PreparedStatement deleteStmnt = this.databaseConnection.prepareStatement(this.getDeletePlayerDataSQL());
|
||||
PreparedStatement insertStmnt = this.databaseConnection.prepareStatement(this.getInsertPlayerDataSQL())) {
|
||||
PreparedStatement insertStmnt = this.databaseConnection.prepareStatement(this.getInsertPlayerDataSQL()))
|
||||
{
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(playerID));
|
||||
|
||||
SimpleDateFormat sqlFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
|
@ -534,7 +546,7 @@ public class DatabaseDataStore extends DataStore
|
|||
insertStmnt.setInt(4, playerData.getBonusClaimBlocks());
|
||||
insertStmnt.executeUpdate();
|
||||
}
|
||||
catch(SQLException e)
|
||||
catch (SQLException e)
|
||||
{
|
||||
StringWriter errors = new StringWriter();
|
||||
e.printStackTrace(new PrintWriter(errors));
|
||||
|
|
@ -554,12 +566,13 @@ public class DatabaseDataStore extends DataStore
|
|||
this.nextClaimID = nextID;
|
||||
|
||||
try (PreparedStatement deleteStmnt = this.databaseConnection.prepareStatement(this.getDeleteNextClaimIdSQL());
|
||||
PreparedStatement insertStmnt = this.databaseConnection.prepareStatement(this.getInsertNextClaimIdSQL())) {
|
||||
PreparedStatement insertStmnt = this.databaseConnection.prepareStatement(this.getInsertNextClaimIdSQL()))
|
||||
{
|
||||
deleteStmnt.execute();
|
||||
insertStmnt.setLong(1, nextID);
|
||||
insertStmnt.executeUpdate();
|
||||
}
|
||||
catch(SQLException e)
|
||||
catch (SQLException e)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Unable to set next claim ID to " + nextID + ". Details:");
|
||||
GriefPrevention.AddLogEntry(e.getMessage());
|
||||
|
|
@ -572,7 +585,8 @@ public class DatabaseDataStore extends DataStore
|
|||
{
|
||||
//group bonus blocks are stored in the player data table, with player name = $groupName
|
||||
try (PreparedStatement deleteStmnt = this.databaseConnection.prepareStatement(this.getDeleteGroupBonusSQL());
|
||||
PreparedStatement insertStmnt = this.databaseConnection.prepareStatement(this.getInsertPlayerDataSQL())) {
|
||||
PreparedStatement insertStmnt = this.databaseConnection.prepareStatement(this.getInsertPlayerDataSQL()))
|
||||
{
|
||||
SimpleDateFormat sqlFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String dateString = sqlFormat.format(new Date());
|
||||
deleteStmnt.setString(1, '$' + groupName);
|
||||
|
|
@ -584,7 +598,7 @@ public class DatabaseDataStore extends DataStore
|
|||
insertStmnt.setInt(4, currentValue);
|
||||
insertStmnt.executeUpdate();
|
||||
}
|
||||
catch(SQLException e)
|
||||
catch (SQLException e)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Unable to save data for group " + groupName + ". Details:");
|
||||
GriefPrevention.AddLogEntry(e.getMessage());
|
||||
|
|
@ -594,16 +608,17 @@ public class DatabaseDataStore extends DataStore
|
|||
@Override
|
||||
synchronized void close()
|
||||
{
|
||||
if(this.databaseConnection != null)
|
||||
if (this.databaseConnection != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(!this.databaseConnection.isClosed())
|
||||
if (!this.databaseConnection.isClosed())
|
||||
{
|
||||
this.databaseConnection.close();
|
||||
}
|
||||
}
|
||||
catch(SQLException e){};
|
||||
catch (SQLException e) {}
|
||||
;
|
||||
}
|
||||
|
||||
this.databaseConnection = null;
|
||||
|
|
@ -611,9 +626,9 @@ public class DatabaseDataStore extends DataStore
|
|||
|
||||
private synchronized void refreshDataConnection() throws SQLException
|
||||
{
|
||||
if(this.databaseConnection == null || !this.databaseConnection.isValid(3))
|
||||
if (this.databaseConnection == null || !this.databaseConnection.isValid(3))
|
||||
{
|
||||
if(this.databaseConnection != null && !this.databaseConnection.isClosed())
|
||||
if (this.databaseConnection != null && !this.databaseConnection.isClosed())
|
||||
{
|
||||
this.databaseConnection.close();
|
||||
}
|
||||
|
|
@ -633,11 +648,12 @@ public class DatabaseDataStore extends DataStore
|
|||
@Override
|
||||
protected int getSchemaVersionFromStorage()
|
||||
{
|
||||
try (PreparedStatement selectStmnt = this.databaseConnection.prepareStatement(this.getSelectSchemaVersionSQL())) {
|
||||
try (PreparedStatement selectStmnt = this.databaseConnection.prepareStatement(this.getSelectSchemaVersionSQL()))
|
||||
{
|
||||
ResultSet results = selectStmnt.executeQuery();
|
||||
|
||||
//if there's nothing yet, assume 0 and add it
|
||||
if(!results.next())
|
||||
if (!results.next())
|
||||
{
|
||||
this.setSchemaVersion(0);
|
||||
return 0;
|
||||
|
|
@ -648,7 +664,7 @@ public class DatabaseDataStore extends DataStore
|
|||
return results.getInt("version");
|
||||
}
|
||||
}
|
||||
catch(SQLException e)
|
||||
catch (SQLException e)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Unable to retrieve schema version from database. Details:");
|
||||
GriefPrevention.AddLogEntry(e.getMessage());
|
||||
|
|
@ -661,13 +677,14 @@ public class DatabaseDataStore extends DataStore
|
|||
protected void updateSchemaVersionInStorage(int versionToSet)
|
||||
{
|
||||
try (PreparedStatement deleteStmnt = this.databaseConnection.prepareStatement(this.getDeleteSchemaVersionSQL());
|
||||
PreparedStatement insertStmnt = this.databaseConnection.prepareStatement(this.getInsertSchemaVerSQL())) {
|
||||
PreparedStatement insertStmnt = this.databaseConnection.prepareStatement(this.getInsertSchemaVerSQL()))
|
||||
{
|
||||
deleteStmnt.execute();
|
||||
|
||||
insertStmnt.setInt(1, versionToSet);
|
||||
insertStmnt.executeUpdate();
|
||||
}
|
||||
catch(SQLException e)
|
||||
catch (SQLException e)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Unable to set next schema version to " + versionToSet + ". Details:");
|
||||
GriefPrevention.AddLogEntry(e.getMessage());
|
||||
|
|
@ -676,62 +693,77 @@ public class DatabaseDataStore extends DataStore
|
|||
|
||||
/**
|
||||
* Concats an array to a string divided with the ; sign
|
||||
*
|
||||
* @param input Arraylist with strings to concat
|
||||
* @return String with all values from input array
|
||||
*/
|
||||
private String storageStringBuilder(ArrayList<String> input) {
|
||||
private String storageStringBuilder(ArrayList<String> input)
|
||||
{
|
||||
String output = "";
|
||||
for(String string : input) {
|
||||
for (String string : input)
|
||||
{
|
||||
output += string + ";";
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
public String getUpdateNameSQL() {
|
||||
public String getUpdateNameSQL()
|
||||
{
|
||||
return updateNameSQL;
|
||||
}
|
||||
|
||||
public String getInsertClaimSQL() {
|
||||
public String getInsertClaimSQL()
|
||||
{
|
||||
return insertClaimSQL;
|
||||
}
|
||||
|
||||
public String getDeleteClaimSQL() {
|
||||
public String getDeleteClaimSQL()
|
||||
{
|
||||
return deleteClaimSQL;
|
||||
}
|
||||
|
||||
public String getGetPlayerDataSQL() {
|
||||
public String getGetPlayerDataSQL()
|
||||
{
|
||||
return getPlayerDataSQL;
|
||||
}
|
||||
|
||||
public String getDeletePlayerDataSQL() {
|
||||
public String getDeletePlayerDataSQL()
|
||||
{
|
||||
return deletePlayerDataSQL;
|
||||
}
|
||||
|
||||
public String getInsertPlayerDataSQL() {
|
||||
public String getInsertPlayerDataSQL()
|
||||
{
|
||||
return insertPlayerDataSQL;
|
||||
}
|
||||
|
||||
public String getInsertNextClaimIdSQL() {
|
||||
public String getInsertNextClaimIdSQL()
|
||||
{
|
||||
return insertNextClaimIdSQL;
|
||||
}
|
||||
|
||||
public String getDeleteGroupBonusSQL() {
|
||||
public String getDeleteGroupBonusSQL()
|
||||
{
|
||||
return deleteGroupBonusSQL;
|
||||
}
|
||||
|
||||
public String getInsertSchemaVerSQL() {
|
||||
public String getInsertSchemaVerSQL()
|
||||
{
|
||||
return insertSchemaVerSQL;
|
||||
}
|
||||
|
||||
public String getDeleteNextClaimIdSQL() {
|
||||
public String getDeleteNextClaimIdSQL()
|
||||
{
|
||||
return deleteNextClaimIdSQL;
|
||||
}
|
||||
|
||||
public String getDeleteSchemaVersionSQL() {
|
||||
public String getDeleteSchemaVersionSQL()
|
||||
{
|
||||
return deleteSchemaVersionSQL;
|
||||
}
|
||||
|
||||
public String getSelectSchemaVersionSQL() {
|
||||
public String getSelectSchemaVersionSQL()
|
||||
{
|
||||
return selectSchemaVersionSQL;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,13 +16,13 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import java.util.Collection;
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.events.AccrueClaimBlocksEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
//FEATURE: give players claim blocks for playing, as long as they're not away from their computer
|
||||
|
||||
//runs every 5 minutes in the main thread, grants blocks per hour / 12 to each online player who appears to be actively playing
|
||||
|
|
@ -43,13 +43,13 @@ class DeliverClaimBlocksTask implements Runnable
|
|||
public void run()
|
||||
{
|
||||
//if no player specified, this task will create a player-specific task for each online player, scheduled one tick apart
|
||||
if(this.player == null)
|
||||
if (this.player == null)
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<Player> players = (Collection<Player>)GriefPrevention.instance.getServer().getOnlinePlayers();
|
||||
Collection<Player> players = (Collection<Player>) GriefPrevention.instance.getServer().getOnlinePlayers();
|
||||
|
||||
long i = 0;
|
||||
for(Player onlinePlayer : players)
|
||||
for (Player onlinePlayer : players)
|
||||
{
|
||||
DeliverClaimBlocksTask newTask = new DeliverClaimBlocksTask(onlinePlayer, instance);
|
||||
instance.getServer().getScheduler().scheduleSyncDelayedTask(instance, newTask, i++);
|
||||
|
|
@ -59,7 +59,7 @@ class DeliverClaimBlocksTask implements Runnable
|
|||
}
|
||||
|
||||
//deliver claim blocks to the specified player
|
||||
if(!this.player.isOnline())
|
||||
if (!this.player.isOnline())
|
||||
{
|
||||
return; //player is not online to receive claim blocks
|
||||
}
|
||||
|
|
@ -76,7 +76,7 @@ class DeliverClaimBlocksTask implements Runnable
|
|||
isIdle = player.isInsideVehicle() || player.getLocation().getBlock().isLiquid() ||
|
||||
!(playerData.lastAfkCheckLocation == null || playerData.lastAfkCheckLocation.distanceSquared(player.getLocation()) > idleThresholdSquared);
|
||||
}
|
||||
catch(IllegalArgumentException ignore) //can't measure distance when to/from are different worlds
|
||||
catch (IllegalArgumentException ignore) //can't measure distance when to/from are different worlds
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -119,7 +119,7 @@ class DeliverClaimBlocksTask implements Runnable
|
|||
//many other operations will cause this player's data to save, including his eventual logout
|
||||
//dataStore.savePlayerData(player.getUniqueIdentifier(), playerData);
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Problem delivering claim blocks to player " + player.getName() + ":");
|
||||
e.printStackTrace();
|
||||
|
|
|
|||
|
|
@ -46,43 +46,41 @@ class EntityCleanupTask implements Runnable
|
|||
public void run()
|
||||
{
|
||||
ArrayList<World> worlds = new ArrayList<World>();
|
||||
for(World world : GriefPrevention.instance.getServer().getWorlds())
|
||||
for (World world : GriefPrevention.instance.getServer().getWorlds())
|
||||
{
|
||||
if(GriefPrevention.instance.config_claims_worldModes.get(world) == ClaimsMode.Creative)
|
||||
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++)
|
||||
{
|
||||
World world = worlds.get(i);
|
||||
|
||||
List<Entity> entities = world.getEntities();
|
||||
|
||||
//starting and stopping point. each execution of the task scans 10% of the server's (loaded) entities
|
||||
int j = (int)(entities.size() * this.percentageStart);
|
||||
int k = (int)(entities.size() * (this.percentageStart + .1));
|
||||
int j = (int) (entities.size() * this.percentageStart);
|
||||
int k = (int) (entities.size() * (this.percentageStart + .1));
|
||||
Claim cachedClaim = null;
|
||||
for(; j < entities.size() && j < k; j++)
|
||||
for (; j < entities.size() && j < k; j++)
|
||||
{
|
||||
Entity entity = entities.get(j);
|
||||
|
||||
boolean remove = false;
|
||||
if(entity instanceof Boat) //boats must be occupied
|
||||
if (entity instanceof Boat) //boats must be occupied
|
||||
{
|
||||
Boat boat = (Boat)entity;
|
||||
if(boat.isEmpty()) remove = true;
|
||||
}
|
||||
|
||||
else if(entity instanceof Vehicle)
|
||||
Boat boat = (Boat) entity;
|
||||
if (boat.isEmpty()) remove = true;
|
||||
} else if (entity instanceof Vehicle)
|
||||
{
|
||||
Vehicle vehicle = (Vehicle)entity;
|
||||
Vehicle vehicle = (Vehicle) entity;
|
||||
|
||||
//minecarts in motion must be occupied by a player
|
||||
if(vehicle.getVelocity().lengthSquared() != 0)
|
||||
if (vehicle.getVelocity().lengthSquared() != 0)
|
||||
{
|
||||
if(vehicle.isEmpty() || !(vehicle.getPassenger() instanceof Player))
|
||||
if (vehicle.isEmpty() || !(vehicle.getPassenger() instanceof Player))
|
||||
{
|
||||
remove = true;
|
||||
}
|
||||
|
|
@ -92,7 +90,7 @@ class EntityCleanupTask implements Runnable
|
|||
else
|
||||
{
|
||||
Material material = world.getBlockAt(vehicle.getLocation()).getType();
|
||||
if(material != Material.RAIL && material != Material.POWERED_RAIL && material != Material.DETECTOR_RAIL)
|
||||
if (material != Material.RAIL && material != Material.POWERED_RAIL && material != Material.DETECTOR_RAIL)
|
||||
{
|
||||
remove = true;
|
||||
}
|
||||
|
|
@ -100,20 +98,19 @@ class EntityCleanupTask implements Runnable
|
|||
}
|
||||
|
||||
//all non-player entities must be in claims
|
||||
else if(!(entity instanceof Player))
|
||||
else if (!(entity instanceof Player))
|
||||
{
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(entity.getLocation(), false, cachedClaim);
|
||||
if(claim != null)
|
||||
if (claim != null)
|
||||
{
|
||||
cachedClaim = claim;
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
remove = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(remove)
|
||||
if (remove)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Removing entity " + entity.getType().name() + " @ " + entity.getLocation(), CustomLogEntryTypes.Debug, true);
|
||||
entity.remove();
|
||||
|
|
@ -123,14 +120,14 @@ class EntityCleanupTask implements Runnable
|
|||
|
||||
//starting and stopping point. each execution of the task scans 5% of the server's claims
|
||||
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++)
|
||||
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()))
|
||||
if (GriefPrevention.instance.creativeRulesApply(claim.getLesserBoundaryCorner()))
|
||||
{
|
||||
//check its entity count and remove any extras
|
||||
claim.allowMoreEntities(true);
|
||||
|
|
@ -139,7 +136,7 @@ class EntityCleanupTask implements Runnable
|
|||
|
||||
//schedule the next run of this task, in 3 minutes (20L is approximately 1 second)
|
||||
double nextRunPercentageStart = this.percentageStart + .05;
|
||||
if(nextRunPercentageStart > .99)
|
||||
if (nextRunPercentageStart > .99)
|
||||
{
|
||||
nextRunPercentageStart = 0;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -38,7 +38,8 @@ class EquipShovelProcessingTask implements Runnable
|
|||
public void run()
|
||||
{
|
||||
//if he's not holding the golden shovel anymore, do nothing
|
||||
if(GriefPrevention.instance.getItemInHand(player, EquipmentSlot.HAND).getType() != GriefPrevention.instance.config_claims_modificationTool) return;
|
||||
if (GriefPrevention.instance.getItemInHand(player, EquipmentSlot.HAND).getType() != GriefPrevention.instance.config_claims_modificationTool)
|
||||
return;
|
||||
|
||||
PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId());
|
||||
|
||||
|
|
@ -47,7 +48,7 @@ class EquipShovelProcessingTask implements Runnable
|
|||
playerData.claimResizing = null;
|
||||
|
||||
//always reset to basic claims mode
|
||||
if(playerData.shovelMode != ShovelMode.Basic)
|
||||
if (playerData.shovelMode != ShovelMode.Basic)
|
||||
{
|
||||
playerData.shovelMode = ShovelMode.Basic;
|
||||
GriefPrevention.sendMessage(player, TextMode.Info, Messages.ShovelBasicClaimMode);
|
||||
|
|
@ -58,18 +59,17 @@ 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()))
|
||||
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()))
|
||||
} else if (GriefPrevention.instance.claimsEnabledForWorld(player.getLocation().getWorld()))
|
||||
{
|
||||
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.SurvivalBasicsVideo2, DataStore.SURVIVAL_VIDEO_URL);
|
||||
}
|
||||
|
||||
//if standing in a claim owned by the player, visualize it
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(player.getLocation(), true, playerData.lastClaim);
|
||||
if(claim != null && claim.allowEdit(player) == null)
|
||||
if (claim != null && claim.allowEdit(player) == null)
|
||||
{
|
||||
playerData.lastClaim = claim;
|
||||
Visualization.Apply(player, Visualization.FromClaim(claim, player.getEyeLocation().getBlockY(), VisualizationType.Claim, player.getLocation()));
|
||||
|
|
|
|||
|
|
@ -45,10 +45,10 @@ class FindUnusedClaimsTask implements Runnable
|
|||
public void run()
|
||||
{
|
||||
//don't do anything when there are no claims
|
||||
if(claimOwnerUUIDs.isEmpty()) return;
|
||||
if (claimOwnerUUIDs.isEmpty()) return;
|
||||
|
||||
//wrap search around to beginning
|
||||
if(!claimOwnerIterator.hasNext())
|
||||
if (!claimOwnerIterator.hasNext())
|
||||
{
|
||||
refreshUUIDs();
|
||||
return;
|
||||
|
|
@ -57,12 +57,14 @@ class FindUnusedClaimsTask implements Runnable
|
|||
GriefPrevention.instance.getServer().getScheduler().runTaskAsynchronously(GriefPrevention.instance, new CleanupUnusedClaimPreTask(claimOwnerIterator.next()));
|
||||
}
|
||||
|
||||
public void refreshUUIDs() {
|
||||
public void refreshUUIDs()
|
||||
{
|
||||
// Fetch owner UUIDs from list of claims
|
||||
claimOwnerUUIDs = GriefPrevention.instance.dataStore.claims.stream().map(claim -> claim.ownerID)
|
||||
.distinct().filter(Objects::nonNull).collect(Collectors.toList());
|
||||
|
||||
if (!claimOwnerUUIDs.isEmpty()) {
|
||||
if (!claimOwnerUUIDs.isEmpty())
|
||||
{
|
||||
// Randomize order
|
||||
Collections.shuffle(claimOwnerUUIDs);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ public class FlatFileDataStore extends DataStore
|
|||
boolean newDataStore = false;
|
||||
File playerDataFolder = new File(playerDataFolderPath);
|
||||
File claimDataFolder = new File(claimDataFolderPath);
|
||||
if(!playerDataFolder.exists() || !claimDataFolder.exists())
|
||||
if (!playerDataFolder.exists() || !claimDataFolder.exists())
|
||||
{
|
||||
newDataStore = true;
|
||||
playerDataFolder.mkdirs();
|
||||
|
|
@ -78,23 +78,23 @@ public class FlatFileDataStore extends DataStore
|
|||
}
|
||||
|
||||
//if there's no data yet, then anything written will use the schema implemented by this code
|
||||
if(newDataStore)
|
||||
if (newDataStore)
|
||||
{
|
||||
this.setSchemaVersion(DataStore.latestSchemaVersion);
|
||||
}
|
||||
|
||||
//load group data into memory
|
||||
File [] files = playerDataFolder.listFiles();
|
||||
for(int i = 0; i < files.length; i++)
|
||||
File[] files = playerDataFolder.listFiles();
|
||||
for (int i = 0; i < files.length; i++)
|
||||
{
|
||||
File file = files[i];
|
||||
if(!file.isFile()) continue; //avoids folders
|
||||
if (!file.isFile()) continue; //avoids folders
|
||||
|
||||
//all group data files start with a dollar sign. ignoring the rest, which are player data files.
|
||||
if(!file.getName().startsWith("$")) continue;
|
||||
if (!file.getName().startsWith("$")) continue;
|
||||
|
||||
String groupName = file.getName().substring(1);
|
||||
if(groupName == null || groupName.isEmpty()) continue; //defensive coding, avoid unlikely cases
|
||||
if (groupName == null || groupName.isEmpty()) continue; //defensive coding, avoid unlikely cases
|
||||
|
||||
BufferedReader inStream = null;
|
||||
try
|
||||
|
|
@ -106,7 +106,7 @@ public class FlatFileDataStore extends DataStore
|
|||
|
||||
this.permissionToBonusBlocksMap.put(groupName, groupBonusBlocks);
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
StringWriter errors = new StringWriter();
|
||||
e.printStackTrace(new PrintWriter(errors));
|
||||
|
|
@ -115,14 +115,14 @@ public class FlatFileDataStore extends DataStore
|
|||
|
||||
try
|
||||
{
|
||||
if(inStream != null) inStream.close();
|
||||
if (inStream != null) inStream.close();
|
||||
}
|
||||
catch(IOException exception) {}
|
||||
catch (IOException exception) {}
|
||||
}
|
||||
|
||||
//load next claim number from file
|
||||
File nextClaimIdFile = new File(nextClaimIdFilePath);
|
||||
if(nextClaimIdFile.exists())
|
||||
if (nextClaimIdFile.exists())
|
||||
{
|
||||
BufferedReader inStream = null;
|
||||
try
|
||||
|
|
@ -135,22 +135,22 @@ public class FlatFileDataStore extends DataStore
|
|||
//try to parse into a long value
|
||||
this.nextClaimID = Long.parseLong(line);
|
||||
}
|
||||
catch(Exception e){ }
|
||||
catch (Exception e) { }
|
||||
|
||||
try
|
||||
{
|
||||
if(inStream != null) inStream.close();
|
||||
if (inStream != null) inStream.close();
|
||||
}
|
||||
catch(IOException exception) {}
|
||||
catch (IOException exception) {}
|
||||
}
|
||||
|
||||
//if converting up from schema version 0, rename player data files using UUIDs instead of player names
|
||||
//get a list of all the files in the claims data folder
|
||||
if(this.getSchemaVersion() == 0)
|
||||
if (this.getSchemaVersion() == 0)
|
||||
{
|
||||
files = playerDataFolder.listFiles();
|
||||
ArrayList<String> namesToConvert = new ArrayList<String>();
|
||||
for(File playerFile : files)
|
||||
for (File playerFile : files)
|
||||
{
|
||||
namesToConvert.add(playerFile.getName());
|
||||
}
|
||||
|
|
@ -161,23 +161,23 @@ public class FlatFileDataStore extends DataStore
|
|||
UUIDFetcher fetcher = new UUIDFetcher(namesToConvert);
|
||||
fetcher.call();
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Failed to resolve a batch of names to UUIDs. Details:" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//rename files
|
||||
for(File playerFile : files)
|
||||
for (File playerFile : files)
|
||||
{
|
||||
String currentFilename = playerFile.getName();
|
||||
|
||||
//if corrected casing and a record already exists using the correct casing, skip this one
|
||||
String correctedCasing = UUIDFetcher.correctedNames.get(currentFilename);
|
||||
if(correctedCasing != null && !currentFilename.equals(correctedCasing))
|
||||
if (correctedCasing != null && !currentFilename.equals(correctedCasing))
|
||||
{
|
||||
File correctedCasingFile = new File(playerDataFolder.getPath() + File.separator + correctedCasing);
|
||||
if(correctedCasingFile.exists())
|
||||
if (correctedCasingFile.exists())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
@ -190,12 +190,12 @@ public class FlatFileDataStore extends DataStore
|
|||
playerID = UUIDFetcher.getUUIDOf(currentFilename);
|
||||
|
||||
//if successful, rename the file using the UUID
|
||||
if(playerID != null)
|
||||
if (playerID != null)
|
||||
{
|
||||
playerFile.renameTo(new File(playerDataFolder, playerID.toString()));
|
||||
}
|
||||
}
|
||||
catch(Exception ex){ }
|
||||
catch (Exception ex) { }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -203,11 +203,10 @@ public class FlatFileDataStore extends DataStore
|
|||
//get a list of all the files in the claims data folder
|
||||
files = claimDataFolder.listFiles();
|
||||
|
||||
if(this.getSchemaVersion() <= 1)
|
||||
if (this.getSchemaVersion() <= 1)
|
||||
{
|
||||
this.loadClaimData_Legacy(files);
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
this.loadClaimData(files);
|
||||
}
|
||||
|
|
@ -215,16 +214,16 @@ public class FlatFileDataStore extends DataStore
|
|||
super.initialize();
|
||||
}
|
||||
|
||||
void loadClaimData_Legacy(File [] files) throws Exception
|
||||
void loadClaimData_Legacy(File[] files) throws Exception
|
||||
{
|
||||
List<World> validWorlds = Bukkit.getServer().getWorlds();
|
||||
|
||||
for(int i = 0; i < files.length; i++)
|
||||
for (int i = 0; i < files.length; i++)
|
||||
{
|
||||
if(files[i].isFile()) //avoids folders
|
||||
if (files[i].isFile()) //avoids folders
|
||||
{
|
||||
//skip any file starting with an underscore, to avoid special files not representing land claims
|
||||
if(files[i].getName().startsWith("_")) continue;
|
||||
if (files[i].getName().startsWith("_")) continue;
|
||||
|
||||
//the filename is the claim ID. try to parse it
|
||||
long claimID;
|
||||
|
|
@ -236,7 +235,7 @@ public class FlatFileDataStore extends DataStore
|
|||
|
||||
//because some older versions used a different file name pattern before claim IDs were introduced,
|
||||
//those files need to be "converted" by renaming them to a unique ID
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
claimID = this.nextClaimID;
|
||||
this.incrementNextClaimID();
|
||||
|
|
@ -254,17 +253,17 @@ public class FlatFileDataStore extends DataStore
|
|||
inStream = new BufferedReader(new FileReader(files[i].getAbsolutePath()));
|
||||
String line = inStream.readLine();
|
||||
|
||||
while(line != null)
|
||||
while (line != null)
|
||||
{
|
||||
//skip any SUB:### lines from previous versions
|
||||
if(line.toLowerCase().startsWith("sub:"))
|
||||
if (line.toLowerCase().startsWith("sub:"))
|
||||
{
|
||||
line = inStream.readLine();
|
||||
}
|
||||
|
||||
//skip any UUID lines from previous versions
|
||||
Matcher match = uuidpattern.matcher(line.trim());
|
||||
if(match.find())
|
||||
if (match.find())
|
||||
{
|
||||
line = inStream.readLine();
|
||||
}
|
||||
|
|
@ -281,29 +280,27 @@ public class FlatFileDataStore extends DataStore
|
|||
line = inStream.readLine();
|
||||
String ownerName = line;
|
||||
UUID ownerID = null;
|
||||
if(ownerName.isEmpty() || ownerName.startsWith("--"))
|
||||
if (ownerName.isEmpty() || ownerName.startsWith("--"))
|
||||
{
|
||||
ownerID = null; //administrative land claim or subdivision
|
||||
}
|
||||
else if(this.getSchemaVersion() == 0)
|
||||
} else if (this.getSchemaVersion() == 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
ownerID = UUIDFetcher.getUUIDOf(ownerName);
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Couldn't resolve this name to a UUID: " + ownerName + ".");
|
||||
GriefPrevention.AddLogEntry(" Converted land claim to administrative @ " + lesserBoundaryCorner.toString());
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
try
|
||||
{
|
||||
ownerID = UUID.fromString(ownerName);
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Error - this is not a valid UUID: " + ownerName + ".");
|
||||
GriefPrevention.AddLogEntry(" Converted land claim to administrative @ " + lesserBoundaryCorner.toString());
|
||||
|
|
@ -327,18 +324,18 @@ public class FlatFileDataStore extends DataStore
|
|||
|
||||
//seventh line is list of players who can grant permissions
|
||||
line = inStream.readLine();
|
||||
if(line == null) line = "";
|
||||
if (line == null) line = "";
|
||||
List<String> managerNames = Arrays.asList(line.split(";"));
|
||||
managerNames = this.convertNameListToUUIDList(managerNames);
|
||||
|
||||
//skip any remaining extra lines, until the "===" string, indicating the end of this claim or subdivision
|
||||
line = inStream.readLine();
|
||||
while(line != null && !line.contains("==="))
|
||||
while (line != null && !line.contains("==="))
|
||||
line = inStream.readLine();
|
||||
|
||||
//build a claim instance from those data
|
||||
//if this is the first claim loaded from this file, it's the top level claim
|
||||
if(topLevelClaim == null)
|
||||
if (topLevelClaim == null)
|
||||
{
|
||||
//instantiate
|
||||
topLevelClaim = new Claim(lesserBoundaryCorner, greaterBoundaryCorner, ownerID, builderNames, containerNames, accessorNames, managerNames, claimID);
|
||||
|
|
@ -366,15 +363,14 @@ public class FlatFileDataStore extends DataStore
|
|||
}
|
||||
|
||||
//if there's any problem with the file's content, log an error message and skip it
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
if(e.getMessage() != null && e.getMessage().contains("World not found"))
|
||||
if (e.getMessage() != null && e.getMessage().contains("World not found"))
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Failed to load a claim " + files[i].getName() + " because its world isn't loaded (yet?). Please delete the claim file or contact the GriefPrevention developer with information about which plugin(s) you're using to load or create worlds. " + lesserCornerString);
|
||||
inStream.close();
|
||||
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
StringWriter errors = new StringWriter();
|
||||
e.printStackTrace(new PrintWriter(errors));
|
||||
|
|
@ -385,25 +381,25 @@ public class FlatFileDataStore extends DataStore
|
|||
|
||||
try
|
||||
{
|
||||
if(inStream != null) inStream.close();
|
||||
if (inStream != null) inStream.close();
|
||||
}
|
||||
catch(IOException exception) {}
|
||||
catch (IOException exception) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loadClaimData(File [] files) throws Exception
|
||||
void loadClaimData(File[] files) throws Exception
|
||||
{
|
||||
ConcurrentHashMap<Claim, Long> orphans = new ConcurrentHashMap<Claim, Long>();
|
||||
for(int i = 0; i < files.length; i++)
|
||||
for (int i = 0; i < files.length; i++)
|
||||
{
|
||||
if(files[i].isFile()) //avoids folders
|
||||
if (files[i].isFile()) //avoids folders
|
||||
{
|
||||
//skip any file starting with an underscore, to avoid special files not representing land claims
|
||||
if(files[i].getName().startsWith("_")) continue;
|
||||
if (files[i].getName().startsWith("_")) continue;
|
||||
|
||||
//delete any which don't end in .yml
|
||||
if(!files[i].getName().endsWith(".yml"))
|
||||
if (!files[i].getName().endsWith(".yml"))
|
||||
{
|
||||
files[i].delete();
|
||||
continue;
|
||||
|
|
@ -419,7 +415,7 @@ public class FlatFileDataStore extends DataStore
|
|||
|
||||
//because some older versions used a different file name pattern before claim IDs were introduced,
|
||||
//those files need to be "converted" by renaming them to a unique ID
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
claimID = this.nextClaimID;
|
||||
this.incrementNextClaimID();
|
||||
|
|
@ -432,24 +428,22 @@ public class FlatFileDataStore extends DataStore
|
|||
{
|
||||
ArrayList<Long> out_parentID = new ArrayList<Long>(); //hacky output parameter
|
||||
Claim claim = this.loadClaim(files[i], out_parentID, claimID);
|
||||
if(out_parentID.size() == 0 || out_parentID.get(0) == -1)
|
||||
if (out_parentID.size() == 0 || out_parentID.get(0) == -1)
|
||||
{
|
||||
this.addClaim(claim, false);
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
orphans.put(claim, out_parentID.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
//if there's any problem with the file's content, log an error message and skip it
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
if(e.getMessage() != null && e.getMessage().contains("World not found"))
|
||||
if (e.getMessage() != null && e.getMessage().contains("World not found"))
|
||||
{
|
||||
files[i].delete();
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
StringWriter errors = new StringWriter();
|
||||
e.printStackTrace(new PrintWriter(errors));
|
||||
|
|
@ -460,10 +454,10 @@ public class FlatFileDataStore extends DataStore
|
|||
}
|
||||
|
||||
//link children to parents
|
||||
for(Claim child : orphans.keySet())
|
||||
for (Claim child : orphans.keySet())
|
||||
{
|
||||
Claim parent = this.getClaim(orphans.get(child));
|
||||
if(parent != null)
|
||||
if (parent != null)
|
||||
{
|
||||
child.parent = parent;
|
||||
this.addClaim(child, false);
|
||||
|
|
@ -475,7 +469,7 @@ public class FlatFileDataStore extends DataStore
|
|||
{
|
||||
List<String> lines = Files.readLines(file, Charset.forName("UTF-8"));
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for(String line : lines)
|
||||
for (String line : lines)
|
||||
{
|
||||
builder.append(line).append('\n');
|
||||
}
|
||||
|
|
@ -496,13 +490,13 @@ public class FlatFileDataStore extends DataStore
|
|||
//owner
|
||||
String ownerIdentifier = yaml.getString("Owner");
|
||||
UUID ownerID = null;
|
||||
if(!ownerIdentifier.isEmpty())
|
||||
if (!ownerIdentifier.isEmpty())
|
||||
{
|
||||
try
|
||||
{
|
||||
ownerID = UUID.fromString(ownerIdentifier);
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Error - this is not a valid UUID: " + ownerIdentifier + ".");
|
||||
GriefPrevention.AddLogEntry(" Converted land claim to administrative @ " + lesserBoundaryCorner.toString());
|
||||
|
|
@ -539,7 +533,7 @@ public class FlatFileDataStore extends DataStore
|
|||
|
||||
//owner
|
||||
String ownerID = "";
|
||||
if(claim.ownerID != null) ownerID = claim.ownerID.toString();
|
||||
if (claim.ownerID != null) ownerID = claim.ownerID.toString();
|
||||
yaml.set("Owner", ownerID);
|
||||
|
||||
ArrayList<String> builders = new ArrayList<String>();
|
||||
|
|
@ -554,7 +548,7 @@ public class FlatFileDataStore extends DataStore
|
|||
yaml.set("Managers", managers);
|
||||
|
||||
Long parentID = -1L;
|
||||
if(claim.parent != null)
|
||||
if (claim.parent != null)
|
||||
{
|
||||
parentID = claim.parent.id;
|
||||
}
|
||||
|
|
@ -582,7 +576,7 @@ public class FlatFileDataStore extends DataStore
|
|||
}
|
||||
|
||||
//if any problem, log it
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
StringWriter errors = new StringWriter();
|
||||
e.printStackTrace(new PrintWriter(errors));
|
||||
|
|
@ -598,7 +592,7 @@ public class FlatFileDataStore extends DataStore
|
|||
|
||||
//remove from disk
|
||||
File claimFile = new File(claimDataFolderPath + File.separator + claimID + ".yml");
|
||||
if(claimFile.exists() && !claimFile.delete())
|
||||
if (claimFile.exists() && !claimFile.delete())
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Error: Unable to delete claim file \"" + claimFile.getAbsolutePath() + "\".");
|
||||
}
|
||||
|
|
@ -613,7 +607,7 @@ public class FlatFileDataStore extends DataStore
|
|||
playerData.playerID = playerID;
|
||||
|
||||
//if it exists as a file, read the file
|
||||
if(playerFile.exists())
|
||||
if (playerFile.exists())
|
||||
{
|
||||
boolean needRetry = false;
|
||||
int retriesRemaining = 5;
|
||||
|
|
@ -662,7 +656,7 @@ public class FlatFileDataStore extends DataStore
|
|||
}
|
||||
|
||||
//if there's any problem with the file's content, retry up to 5 times with 5 milliseconds between
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
latestException = e;
|
||||
needRetry = true;
|
||||
|
|
@ -671,14 +665,14 @@ public class FlatFileDataStore extends DataStore
|
|||
|
||||
try
|
||||
{
|
||||
if(needRetry) Thread.sleep(5);
|
||||
if (needRetry) Thread.sleep(5);
|
||||
}
|
||||
catch(InterruptedException exception) {}
|
||||
catch (InterruptedException exception) {}
|
||||
|
||||
}while(needRetry && retriesRemaining >= 0);
|
||||
} while (needRetry && retriesRemaining >= 0);
|
||||
|
||||
//if last attempt failed, log information about the problem
|
||||
if(needRetry)
|
||||
if (needRetry)
|
||||
{
|
||||
StringWriter errors = new StringWriter();
|
||||
latestException.printStackTrace(new PrintWriter(errors));
|
||||
|
|
@ -695,7 +689,7 @@ public class FlatFileDataStore extends DataStore
|
|||
public void overrideSavePlayerData(UUID playerID, PlayerData playerData)
|
||||
{
|
||||
//never save data for the "administrative" account. null for claim owner ID indicates administrative account
|
||||
if(playerID == null) return;
|
||||
if (playerID == null) return;
|
||||
|
||||
StringBuilder fileContent = new StringBuilder();
|
||||
try
|
||||
|
|
@ -723,7 +717,7 @@ public class FlatFileDataStore extends DataStore
|
|||
}
|
||||
|
||||
//if any problem, log it
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("GriefPrevention: Unexpected exception saving data for player \"" + playerID.toString() + "\": " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
|
|
@ -749,7 +743,7 @@ public class FlatFileDataStore extends DataStore
|
|||
}
|
||||
|
||||
//if any problem, log it
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Unexpected exception saving next claim ID: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
|
|
@ -758,9 +752,9 @@ public class FlatFileDataStore extends DataStore
|
|||
//close the file
|
||||
try
|
||||
{
|
||||
if(outStream != null) outStream.close();
|
||||
if (outStream != null) outStream.close();
|
||||
}
|
||||
catch(IOException exception) {}
|
||||
catch (IOException exception) {}
|
||||
}
|
||||
|
||||
//grants a group (players with a specific permission) bonus claim blocks as long as they're still members of the group
|
||||
|
|
@ -782,7 +776,7 @@ public class FlatFileDataStore extends DataStore
|
|||
}
|
||||
|
||||
//if any problem, log it
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Unexpected exception saving data for group \"" + groupName + "\": " + e.getMessage());
|
||||
}
|
||||
|
|
@ -790,22 +784,22 @@ public class FlatFileDataStore extends DataStore
|
|||
try
|
||||
{
|
||||
//close the file
|
||||
if(outStream != null)
|
||||
if (outStream != null)
|
||||
{
|
||||
outStream.close();
|
||||
}
|
||||
}
|
||||
catch(IOException exception){}
|
||||
catch (IOException exception) {}
|
||||
}
|
||||
|
||||
synchronized void migrateData(DatabaseDataStore databaseStore)
|
||||
{
|
||||
//migrate claims
|
||||
for(int i = 0; i < this.claims.size(); i++)
|
||||
for (int i = 0; i < this.claims.size(); i++)
|
||||
{
|
||||
Claim claim = this.claims.get(i);
|
||||
databaseStore.addClaim(claim, true);
|
||||
for(Claim child : claim.children)
|
||||
for (Claim child : claim.children)
|
||||
{
|
||||
databaseStore.addClaim(child, true);
|
||||
}
|
||||
|
|
@ -813,7 +807,7 @@ public class FlatFileDataStore extends DataStore
|
|||
|
||||
//migrate groups
|
||||
Iterator<String> groupNamesEnumerator = this.permissionToBonusBlocksMap.keySet().iterator();
|
||||
while(groupNamesEnumerator.hasNext())
|
||||
while (groupNamesEnumerator.hasNext())
|
||||
{
|
||||
String groupName = groupNamesEnumerator.next();
|
||||
databaseStore.saveGroupBonusBlocks(groupName, this.permissionToBonusBlocksMap.get(groupName));
|
||||
|
|
@ -821,19 +815,19 @@ public class FlatFileDataStore extends DataStore
|
|||
|
||||
//migrate players
|
||||
File playerDataFolder = new File(playerDataFolderPath);
|
||||
File [] files = playerDataFolder.listFiles();
|
||||
for(int i = 0; i < files.length; i++)
|
||||
File[] files = playerDataFolder.listFiles();
|
||||
for (int i = 0; i < files.length; i++)
|
||||
{
|
||||
File file = files[i];
|
||||
if(!file.isFile()) continue; //avoids folders
|
||||
if(file.isHidden()) continue; //avoid hidden files, which are likely not created by GriefPrevention
|
||||
if (!file.isFile()) continue; //avoids folders
|
||||
if (file.isHidden()) continue; //avoid hidden files, which are likely not created by GriefPrevention
|
||||
|
||||
//all group data files start with a dollar sign. ignoring those, already handled above
|
||||
if(file.getName().startsWith("$")) continue;
|
||||
if (file.getName().startsWith("$")) continue;
|
||||
|
||||
//ignore special files
|
||||
if(file.getName().startsWith("_")) continue;
|
||||
if(file.getName().endsWith(".ignore")) continue;
|
||||
if (file.getName().startsWith("_")) continue;
|
||||
if (file.getName().endsWith(".ignore")) continue;
|
||||
|
||||
UUID playerID = UUID.fromString(file.getName());
|
||||
databaseStore.savePlayerData(playerID, this.getPlayerData(playerID));
|
||||
|
|
@ -841,7 +835,7 @@ public class FlatFileDataStore extends DataStore
|
|||
}
|
||||
|
||||
//migrate next claim ID
|
||||
if(this.nextClaimID > databaseStore.nextClaimID)
|
||||
if (this.nextClaimID > databaseStore.nextClaimID)
|
||||
{
|
||||
databaseStore.setNextClaimID(this.nextClaimID);
|
||||
}
|
||||
|
|
@ -853,14 +847,14 @@ public class FlatFileDataStore extends DataStore
|
|||
do
|
||||
{
|
||||
String claimsFolderBackupPath = claimDataFolderPath;
|
||||
if(i > 0) claimsFolderBackupPath += String.valueOf(i);
|
||||
if (i > 0) claimsFolderBackupPath += String.valueOf(i);
|
||||
claimsBackupFolder = new File(claimsFolderBackupPath);
|
||||
|
||||
String playersFolderBackupPath = playerDataFolderPath;
|
||||
if(i > 0) playersFolderBackupPath += String.valueOf(i);
|
||||
if (i > 0) playersFolderBackupPath += String.valueOf(i);
|
||||
playersBackupFolder = new File(playersFolderBackupPath);
|
||||
i++;
|
||||
} while(claimsBackupFolder.exists() || playersBackupFolder.exists());
|
||||
} while (claimsBackupFolder.exists() || playersBackupFolder.exists());
|
||||
|
||||
File claimsFolder = new File(claimDataFolderPath);
|
||||
File playersFolder = new File(playerDataFolderPath);
|
||||
|
|
@ -880,7 +874,7 @@ public class FlatFileDataStore extends DataStore
|
|||
int getSchemaVersionFromStorage()
|
||||
{
|
||||
File schemaVersionFile = new File(schemaVersionFilePath);
|
||||
if(schemaVersionFile.exists())
|
||||
if (schemaVersionFile.exists())
|
||||
{
|
||||
BufferedReader inStream = null;
|
||||
int schemaVersion = 0;
|
||||
|
|
@ -894,17 +888,16 @@ public class FlatFileDataStore extends DataStore
|
|||
//try to parse into an int value
|
||||
schemaVersion = Integer.parseInt(line);
|
||||
}
|
||||
catch(Exception e){ }
|
||||
catch (Exception e) { }
|
||||
|
||||
try
|
||||
{
|
||||
if(inStream != null) inStream.close();
|
||||
if (inStream != null) inStream.close();
|
||||
}
|
||||
catch(IOException exception) {}
|
||||
catch (IOException exception) {}
|
||||
|
||||
return schemaVersion;
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
this.updateSchemaVersionInStorage(0);
|
||||
return 0;
|
||||
|
|
@ -927,7 +920,7 @@ public class FlatFileDataStore extends DataStore
|
|||
}
|
||||
|
||||
//if any problem, log it
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Unexpected exception saving schema version: " + e.getMessage());
|
||||
}
|
||||
|
|
@ -935,9 +928,9 @@ public class FlatFileDataStore extends DataStore
|
|||
//close the file
|
||||
try
|
||||
{
|
||||
if(outStream != null) outStream.close();
|
||||
if (outStream != null) outStream.close();
|
||||
}
|
||||
catch(IOException exception) {}
|
||||
catch (IOException exception) {}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,13 +1,13 @@
|
|||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
|
||||
//loads ignore data from file into a hash map
|
||||
class IgnoreLoaderThread extends Thread
|
||||
{
|
||||
|
|
@ -27,7 +27,7 @@ class IgnoreLoaderThread extends Thread
|
|||
File ignoreFile = new File(DataStore.playerDataFolderPath + File.separator + this.playerToLoad + ".ignore");
|
||||
|
||||
//if the file doesn't exist, there's nothing to do here
|
||||
if(!ignoreFile.exists()) return;
|
||||
if (!ignoreFile.exists()) return;
|
||||
|
||||
boolean needRetry = false;
|
||||
int retriesRemaining = 5;
|
||||
|
|
@ -42,10 +42,10 @@ class IgnoreLoaderThread extends Thread
|
|||
List<String> lines = Files.readLines(ignoreFile, Charset.forName("UTF-8"));
|
||||
|
||||
//each line is one ignore. asterisks indicate administrative ignores
|
||||
for(String line : lines)
|
||||
for (String line : lines)
|
||||
{
|
||||
boolean adminIgnore = false;
|
||||
if(line.startsWith("*"))
|
||||
if (line.startsWith("*"))
|
||||
{
|
||||
adminIgnore = true;
|
||||
line = line.substring(1);
|
||||
|
|
@ -55,12 +55,12 @@ class IgnoreLoaderThread extends Thread
|
|||
UUID ignoredUUID = UUID.fromString(line);
|
||||
this.destinationMap.put(ignoredUUID, adminIgnore);
|
||||
}
|
||||
catch(IllegalArgumentException e){} //if a bad UUID, ignore the line
|
||||
catch (IllegalArgumentException e) {} //if a bad UUID, ignore the line
|
||||
}
|
||||
}
|
||||
|
||||
//if there's any problem with the file's content, retry up to 5 times with 5 milliseconds between
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
latestException = e;
|
||||
needRetry = true;
|
||||
|
|
@ -69,14 +69,14 @@ class IgnoreLoaderThread extends Thread
|
|||
|
||||
try
|
||||
{
|
||||
if(needRetry) Thread.sleep(5);
|
||||
if (needRetry) Thread.sleep(5);
|
||||
}
|
||||
catch(InterruptedException exception) {}
|
||||
catch (InterruptedException exception) {}
|
||||
|
||||
}while(needRetry && retriesRemaining >= 0);
|
||||
} while (needRetry && retriesRemaining >= 0);
|
||||
|
||||
//if last attempt failed, log information about the problem
|
||||
if(needRetry)
|
||||
if (needRetry)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Retry attempts exhausted. Unable to load ignore data for player \"" + playerToLoad.toString() + "\": " + latestException.toString());
|
||||
latestException.printStackTrace();
|
||||
|
|
|
|||
|
|
@ -56,18 +56,18 @@ public class MaterialInfo
|
|||
@Override
|
||||
public String toString()
|
||||
{
|
||||
String returnValue = String.valueOf(this.typeID) + ":" + (this.allDataValues?"*":String.valueOf(this.data));
|
||||
if(this.description != null) returnValue += ":" + this.description;
|
||||
String returnValue = String.valueOf(this.typeID) + ":" + (this.allDataValues ? "*" : String.valueOf(this.data));
|
||||
if (this.description != null) returnValue += ":" + this.description;
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
public static MaterialInfo fromString(String string)
|
||||
{
|
||||
if(string == null || string.isEmpty()) return null;
|
||||
if (string == null || string.isEmpty()) return null;
|
||||
|
||||
String [] parts = string.split(":");
|
||||
if(parts.length < 3) return null;
|
||||
String[] parts = string.split(":");
|
||||
if (parts.length < 3) return null;
|
||||
|
||||
try
|
||||
{
|
||||
|
|
@ -75,12 +75,11 @@ public class MaterialInfo
|
|||
|
||||
byte data;
|
||||
boolean allDataValues;
|
||||
if(parts[1].equals("*"))
|
||||
if (parts[1].equals("*"))
|
||||
{
|
||||
allDataValues = true;
|
||||
data = 0;
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
allDataValues = false;
|
||||
data = Byte.parseByte(parts[1]);
|
||||
|
|
@ -88,7 +87,7 @@ public class MaterialInfo
|
|||
|
||||
return new MaterialInfo(typeID, data, allDataValues, parts[2]);
|
||||
}
|
||||
catch(NumberFormatException exception)
|
||||
catch (NumberFormatException exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
class PendingItemProtection
|
||||
{
|
||||
public Location location;
|
||||
|
|
|
|||
|
|
@ -17,24 +17,16 @@
|
|||
*/
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.Claim;
|
||||
import me.ryanhamshire.GriefPrevention.GriefPrevention;
|
||||
import me.ryanhamshire.GriefPrevention.ShovelMode;
|
||||
import me.ryanhamshire.GriefPrevention.SiegeData;
|
||||
import me.ryanhamshire.GriefPrevention.Visualization;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
//holds all of GriefPrevention's player-tied data
|
||||
public class PlayerData
|
||||
{
|
||||
|
|
@ -142,13 +134,13 @@ public class PlayerData
|
|||
//whether or not this player is "in" pvp combat
|
||||
public boolean inPvpCombat()
|
||||
{
|
||||
if(this.lastPvpTimestamp == 0) return false;
|
||||
if (this.lastPvpTimestamp == 0) return false;
|
||||
|
||||
long now = Calendar.getInstance().getTimeInMillis();
|
||||
|
||||
long elapsed = now - this.lastPvpTimestamp;
|
||||
|
||||
if(elapsed > GriefPrevention.instance.config_pvp_combatTimeoutSeconds * 1000) //X seconds
|
||||
if (elapsed > GriefPrevention.instance.config_pvp_combatTimeoutSeconds * 1000) //X seconds
|
||||
{
|
||||
this.lastPvpTimestamp = 0;
|
||||
return false;
|
||||
|
|
@ -161,7 +153,7 @@ public class PlayerData
|
|||
public int getRemainingClaimBlocks()
|
||||
{
|
||||
int remainingBlocks = this.getAccruedClaimBlocks() + this.getBonusClaimBlocks() + GriefPrevention.instance.dataStore.getGroupBonusBlocks(this.playerID);
|
||||
for(int i = 0; i < this.getClaims().size(); i++)
|
||||
for (int i = 0; i < this.getClaims().size(); i++)
|
||||
{
|
||||
Claim claim = this.getClaims().get(i);
|
||||
remainingBlocks -= claim.getArea();
|
||||
|
|
@ -173,15 +165,15 @@ public class PlayerData
|
|||
//don't load data from secondary storage until it's needed
|
||||
public synchronized int getAccruedClaimBlocks()
|
||||
{
|
||||
if(this.accruedClaimBlocks == null) this.loadDataFromSecondaryStorage();
|
||||
if (this.accruedClaimBlocks == null) this.loadDataFromSecondaryStorage();
|
||||
|
||||
//update claim blocks with any he has accrued during his current play session
|
||||
if(this.newlyAccruedClaimBlocks > 0)
|
||||
if (this.newlyAccruedClaimBlocks > 0)
|
||||
{
|
||||
int accruedLimit = this.getAccruedClaimBlocksLimit();
|
||||
|
||||
//if over the limit before adding blocks, leave it as-is, because the limit may have changed AFTER he accrued the blocks
|
||||
if(this.accruedClaimBlocks < accruedLimit)
|
||||
if (this.accruedClaimBlocks < accruedLimit)
|
||||
{
|
||||
//move any in the holding area
|
||||
int newTotal = this.accruedClaimBlocks + this.newlyAccruedClaimBlocks;
|
||||
|
|
@ -205,7 +197,7 @@ public class PlayerData
|
|||
|
||||
public int getBonusClaimBlocks()
|
||||
{
|
||||
if(this.bonusClaimBlocks == null) this.loadDataFromSecondaryStorage();
|
||||
if (this.bonusClaimBlocks == null) this.loadDataFromSecondaryStorage();
|
||||
return bonusClaimBlocks;
|
||||
}
|
||||
|
||||
|
|
@ -219,32 +211,30 @@ public class PlayerData
|
|||
//reach out to secondary storage to get any data there
|
||||
PlayerData storageData = GriefPrevention.instance.dataStore.getPlayerDataFromStorage(this.playerID);
|
||||
|
||||
if(this.accruedClaimBlocks == null)
|
||||
if (this.accruedClaimBlocks == null)
|
||||
{
|
||||
if(storageData.accruedClaimBlocks != null)
|
||||
if (storageData.accruedClaimBlocks != null)
|
||||
{
|
||||
this.accruedClaimBlocks = storageData.accruedClaimBlocks;
|
||||
|
||||
//ensure at least minimum accrued are accrued (in case of settings changes to increase initial amount)
|
||||
if(GriefPrevention.instance.config_advanced_fixNegativeClaimblockAmounts && (this.accruedClaimBlocks < GriefPrevention.instance.config_claims_initialBlocks))
|
||||
if (GriefPrevention.instance.config_advanced_fixNegativeClaimblockAmounts && (this.accruedClaimBlocks < GriefPrevention.instance.config_claims_initialBlocks))
|
||||
{
|
||||
this.accruedClaimBlocks = GriefPrevention.instance.config_claims_initialBlocks;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
this.accruedClaimBlocks = GriefPrevention.instance.config_claims_initialBlocks;
|
||||
}
|
||||
}
|
||||
|
||||
if(this.bonusClaimBlocks == null)
|
||||
if (this.bonusClaimBlocks == null)
|
||||
{
|
||||
if(storageData.bonusClaimBlocks != null)
|
||||
if (storageData.bonusClaimBlocks != null)
|
||||
{
|
||||
this.bonusClaimBlocks = storageData.bonusClaimBlocks;
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
this.bonusClaimBlocks = 0;
|
||||
}
|
||||
|
|
@ -253,22 +243,22 @@ public class PlayerData
|
|||
|
||||
public Vector<Claim> getClaims()
|
||||
{
|
||||
if(this.claims == null)
|
||||
if (this.claims == null)
|
||||
{
|
||||
this.claims = new Vector<Claim>();
|
||||
|
||||
//find all the claims belonging to this player and note them for future reference
|
||||
DataStore dataStore = GriefPrevention.instance.dataStore;
|
||||
int totalClaimsArea = 0;
|
||||
for(int i = 0; i < dataStore.claims.size(); i++)
|
||||
for (int i = 0; i < dataStore.claims.size(); i++)
|
||||
{
|
||||
Claim claim = dataStore.claims.get(i);
|
||||
if(!claim.inDataStore)
|
||||
if (!claim.inDataStore)
|
||||
{
|
||||
dataStore.claims.remove(i--);
|
||||
continue;
|
||||
}
|
||||
if(playerID.equals(claim.ownerID))
|
||||
if (playerID.equals(claim.ownerID))
|
||||
{
|
||||
this.claims.add(claim);
|
||||
totalClaimsArea += claim.getArea();
|
||||
|
|
@ -280,15 +270,15 @@ public class PlayerData
|
|||
|
||||
//if total claimed area is more than total blocks available
|
||||
int totalBlocks = this.accruedClaimBlocks + this.getBonusClaimBlocks() + GriefPrevention.instance.dataStore.getGroupBonusBlocks(this.playerID);
|
||||
if(GriefPrevention.instance.config_advanced_fixNegativeClaimblockAmounts && totalBlocks < totalClaimsArea)
|
||||
if (GriefPrevention.instance.config_advanced_fixNegativeClaimblockAmounts && totalBlocks < totalClaimsArea)
|
||||
{
|
||||
OfflinePlayer player = GriefPrevention.instance.getServer().getOfflinePlayer(this.playerID);
|
||||
GriefPrevention.AddLogEntry(player.getName() + " has more claimed land than blocks available. Adding blocks to fix.", CustomLogEntryTypes.Debug, true);
|
||||
GriefPrevention.AddLogEntry(player.getName() + " Accrued blocks: " + this.getAccruedClaimBlocks() + " Bonus blocks: " + this.getBonusClaimBlocks(), CustomLogEntryTypes.Debug, true);
|
||||
GriefPrevention.AddLogEntry("Total blocks: " + totalBlocks + " Total claimed area: " + totalClaimsArea, CustomLogEntryTypes.Debug, true);
|
||||
for(Claim claim : this.claims)
|
||||
for (Claim claim : this.claims)
|
||||
{
|
||||
if(!claim.inDataStore) continue;
|
||||
if (!claim.inDataStore) continue;
|
||||
GriefPrevention.AddLogEntry(
|
||||
GriefPrevention.getfriendlyLocationString(claim.getLesserBoundaryCorner()) + " // "
|
||||
+ GriefPrevention.getfriendlyLocationString(claim.getGreaterBoundaryCorner()) + " = "
|
||||
|
|
@ -307,7 +297,7 @@ public class PlayerData
|
|||
GriefPrevention.AddLogEntry("New total blocks: " + totalBlocks, CustomLogEntryTypes.Debug, true);
|
||||
|
||||
//if that didn't fix it, then make up the difference with bonus blocks
|
||||
if(totalBlocks < totalClaimsArea)
|
||||
if (totalBlocks < totalClaimsArea)
|
||||
{
|
||||
int bonusBlocksToAdd = totalClaimsArea - totalBlocks;
|
||||
this.bonusClaimBlocks += bonusBlocksToAdd;
|
||||
|
|
@ -321,9 +311,9 @@ public class PlayerData
|
|||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < this.claims.size(); i++)
|
||||
for (int i = 0; i < this.claims.size(); i++)
|
||||
{
|
||||
if(!claims.get(i).inDataStore)
|
||||
if (!claims.get(i).inDataStore)
|
||||
{
|
||||
claims.remove(i--);
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -58,12 +58,11 @@ class PlayerKickBanTask implements Runnable
|
|||
return; // cancelled by a plugin
|
||||
}
|
||||
|
||||
if(this.ban)
|
||||
if (this.ban)
|
||||
{
|
||||
//ban
|
||||
GriefPrevention.banPlayer(this.player, this.reason, this.source);
|
||||
}
|
||||
else if(this.player.isOnline())
|
||||
} else if (this.player.isOnline())
|
||||
{
|
||||
this.player.kickPlayer(this.reason);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,25 +46,24 @@ class PlayerRescueTask implements Runnable
|
|||
public void run()
|
||||
{
|
||||
//if he logged out, don't do anything
|
||||
if(!player.isOnline()) return;
|
||||
if (!player.isOnline()) return;
|
||||
|
||||
//he no longer has a pending /trapped slash command, so he can try to use it again now
|
||||
PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId());
|
||||
playerData.pendingTrapped = false;
|
||||
|
||||
//if the player moved three or more blocks from where he used /trapped, admonish him and don't save him
|
||||
if(player.getLocation().distance(this.location) > 3)
|
||||
if (player.getLocation().distance(this.location) > 3)
|
||||
{
|
||||
GriefPrevention.sendMessage(player, TextMode.Err, Messages.RescueAbortedMoved);
|
||||
return;
|
||||
}
|
||||
|
||||
//otherwise find a place to teleport him
|
||||
if(this.destination == null)
|
||||
if (this.destination == null)
|
||||
{
|
||||
this.destination = GriefPrevention.instance.ejectPlayer(this.player);
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
player.teleport(this.destination);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,19 +34,18 @@ class PvPImmunityValidationTask implements Runnable
|
|||
@Override
|
||||
public void run()
|
||||
{
|
||||
if(!player.isOnline()) return;
|
||||
if (!player.isOnline()) return;
|
||||
|
||||
PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId());
|
||||
if(!playerData.pvpImmune) return;
|
||||
if (!playerData.pvpImmune) return;
|
||||
|
||||
//check the player's inventory for anything
|
||||
if(!GriefPrevention.isInventoryEmpty(player))
|
||||
if (!GriefPrevention.isInventoryEmpty(player))
|
||||
{
|
||||
//if found, cancel invulnerability and notify
|
||||
playerData.pvpImmune = false;
|
||||
GriefPrevention.sendMessage(player, TextMode.Warn, Messages.PvPImmunityEnd);
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
//otherwise check again in one minute
|
||||
GriefPrevention.instance.getServer().getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, this, 1200L);
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@
|
|||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
|
|
@ -30,6 +28,8 @@ import org.bukkit.entity.Entity;
|
|||
import org.bukkit.entity.Hanging;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
//this main thread task takes the output from the RestoreNatureProcessingTask\
|
||||
//and updates the world accordingly
|
||||
class RestoreNatureExecutionTask implements Runnable
|
||||
|
|
@ -63,18 +63,18 @@ class RestoreNatureExecutionTask implements Runnable
|
|||
//note that the edge of the results is not applied (the 1-block-wide band around the outside of the chunk)
|
||||
//those data were sent to the processing thread for referernce purposes, but aren't part of the area selected for restoration
|
||||
Claim cachedClaim = null;
|
||||
for(int x = 1; x < this.snapshots.length - 1; x++)
|
||||
for (int x = 1; x < this.snapshots.length - 1; x++)
|
||||
{
|
||||
for(int z = 1; z < this.snapshots[0][0].length - 1; z++)
|
||||
for (int z = 1; z < this.snapshots[0][0].length - 1; z++)
|
||||
{
|
||||
for(int y = this.miny; y < this.snapshots[0].length; y++)
|
||||
for (int y = this.miny; y < this.snapshots[0].length; y++)
|
||||
{
|
||||
BlockSnapshot blockUpdate = this.snapshots[x][y][z];
|
||||
Block currentBlock = blockUpdate.location.getBlock();
|
||||
if(blockUpdate.typeId != currentBlock.getType()|| !blockUpdate.data.equals(currentBlock.getBlockData()))
|
||||
if (blockUpdate.typeId != currentBlock.getType() || !blockUpdate.data.equals(currentBlock.getBlockData()))
|
||||
{
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(blockUpdate.location, false, cachedClaim);
|
||||
if(claim != null)
|
||||
if (claim != null)
|
||||
{
|
||||
cachedClaim = claim;
|
||||
break;
|
||||
|
|
@ -85,7 +85,7 @@ class RestoreNatureExecutionTask implements Runnable
|
|||
currentBlock.setType(blockUpdate.typeId, false);
|
||||
// currentBlock.setBlockData(blockUpdate.data, false);
|
||||
}
|
||||
catch(IllegalArgumentException e)
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
//just don't update this block and continue trying to update other blocks
|
||||
}
|
||||
|
|
@ -96,14 +96,14 @@ class RestoreNatureExecutionTask implements Runnable
|
|||
|
||||
//clean up any entities in the chunk, ensure no players are suffocated
|
||||
Chunk chunk = this.lesserCorner.getChunk();
|
||||
Entity [] entities = chunk.getEntities();
|
||||
for(int i = 0; i < entities.length; i++)
|
||||
Entity[] entities = chunk.getEntities();
|
||||
for (int i = 0; i < entities.length; i++)
|
||||
{
|
||||
Entity entity = entities[i];
|
||||
if(!(entity instanceof Player || entity instanceof Animals))
|
||||
if (!(entity instanceof Player || entity instanceof Animals))
|
||||
{
|
||||
//hanging entities (paintings, item frames) are protected when they're in land claims
|
||||
if(!(entity instanceof Hanging) || GriefPrevention.instance.dataStore.getClaimAt(entity.getLocation(), false, null) == null)
|
||||
if (!(entity instanceof Hanging) || GriefPrevention.instance.dataStore.getClaimAt(entity.getLocation(), false, null) == null)
|
||||
{
|
||||
//everything else is removed
|
||||
entity.remove();
|
||||
|
|
@ -120,7 +120,7 @@ class RestoreNatureExecutionTask implements Runnable
|
|||
}
|
||||
|
||||
//show visualization to player who started the restoration
|
||||
if(player != null)
|
||||
if (player != null)
|
||||
{
|
||||
Claim claim = new Claim(lesserCorner, greaterCorner, null, new ArrayList<String>(), new ArrayList<String>(), new ArrayList<String>(), new ArrayList<String>(), null);
|
||||
Visualization visualization = Visualization.FromClaim(claim, player.getLocation().getBlockY(), VisualizationType.RestoreNature, player.getLocation());
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@
|
|||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
|
|
@ -29,6 +27,8 @@ import org.bukkit.block.data.Levelled;
|
|||
import org.bukkit.block.data.type.Leaves;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
//non-main-thread task which processes world data to repair the unnatural
|
||||
//after processing is complete, creates a main thread task to make the necessary changes to the world
|
||||
class RestoreNatureProcessingTask implements Runnable
|
||||
|
|
@ -58,7 +58,7 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
{
|
||||
this.snapshots = snapshots;
|
||||
this.miny = miny;
|
||||
if(this.miny < 0) this.miny = 0;
|
||||
if (this.miny < 0) this.miny = 0;
|
||||
this.environment = environment;
|
||||
this.lesserBoundaryCorner = lesserBoundaryCorner;
|
||||
this.greaterBoundaryCorner = greaterBoundaryCorner;
|
||||
|
|
@ -79,7 +79,7 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
this.notAllowedToHang.add(Material.ACACIA_LOG);
|
||||
this.notAllowedToHang.add(Material.DARK_OAK_LOG);
|
||||
|
||||
if(this.aggressiveMode)
|
||||
if (this.aggressiveMode)
|
||||
{
|
||||
this.notAllowedToHang.add(Material.GRASS);
|
||||
this.notAllowedToHang.add(Material.STONE);
|
||||
|
|
@ -91,7 +91,7 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
//in aggressive or creative world mode, also treat these blocks as user placed, to be removed
|
||||
//this is helpful in the few cases where griefers intentionally use natural blocks to grief,
|
||||
//like a single-block tower of iron ore or a giant penis constructed with melons
|
||||
if(this.aggressiveMode || this.creativeMode)
|
||||
if (this.aggressiveMode || this.creativeMode)
|
||||
{
|
||||
this.playerBlocks.add(Material.IRON_ORE);
|
||||
this.playerBlocks.add(Material.GOLD_ORE);
|
||||
|
|
@ -104,7 +104,7 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
this.playerBlocks.add(Material.PUMPKIN_STEM);
|
||||
}
|
||||
|
||||
if(this.aggressiveMode)
|
||||
if (this.aggressiveMode)
|
||||
{
|
||||
this.playerBlocks.add(Material.OAK_LEAVES);
|
||||
this.playerBlocks.add(Material.SPRUCE_LEAVES);
|
||||
|
|
@ -168,16 +168,16 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
@SuppressWarnings("deprecation")
|
||||
private void removePlayerLeaves()
|
||||
{
|
||||
if(this.seaLevel < 1) return;
|
||||
if (this.seaLevel < 1) return;
|
||||
|
||||
for(int x = 1; x < snapshots.length - 1; x++)
|
||||
for (int x = 1; x < snapshots.length - 1; x++)
|
||||
{
|
||||
for(int z = 1; z < snapshots[0][0].length - 1; z++)
|
||||
for (int z = 1; z < snapshots[0][0].length - 1; z++)
|
||||
{
|
||||
for(int y = this.seaLevel - 1; y < snapshots[0].length; y++)
|
||||
for (int y = this.seaLevel - 1; y < snapshots[0].length; y++)
|
||||
{
|
||||
BlockSnapshot block = snapshots[x][y][z];
|
||||
if(Tag.LEAVES.isTagged(block.typeId) && ((Leaves) block.data).isPersistent())
|
||||
if (Tag.LEAVES.isTagged(block.typeId) && ((Leaves) block.data).isPersistent())
|
||||
{
|
||||
block.typeId = Material.AIR;
|
||||
}
|
||||
|
|
@ -190,13 +190,13 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
@SuppressWarnings("deprecation")
|
||||
private void removeSandstone()
|
||||
{
|
||||
for(int x = 1; x < snapshots.length - 1; x++)
|
||||
for (int x = 1; x < snapshots.length - 1; x++)
|
||||
{
|
||||
for(int z = 1; z < snapshots[0][0].length - 1; z++)
|
||||
for (int z = 1; z < snapshots[0][0].length - 1; z++)
|
||||
{
|
||||
for(int y = snapshots[0].length - 2; y > miny; y--)
|
||||
for (int y = snapshots[0].length - 2; y > miny; y--)
|
||||
{
|
||||
if(snapshots[x][y][z].typeId != Material.SANDSTONE) continue;
|
||||
if (snapshots[x][y][z].typeId != Material.SANDSTONE) continue;
|
||||
|
||||
BlockSnapshot leftBlock = this.snapshots[x + 1][y][z];
|
||||
BlockSnapshot rightBlock = this.snapshots[x - 1][y][z];
|
||||
|
|
@ -206,10 +206,10 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
BlockSnapshot aboveBlock = this.snapshots[x][y + 1][z];
|
||||
|
||||
//skip blocks which may cause a cave-in
|
||||
if(aboveBlock.typeId == Material.SAND && underBlock.typeId == Material.AIR) continue;
|
||||
if (aboveBlock.typeId == Material.SAND && underBlock.typeId == Material.AIR) continue;
|
||||
|
||||
//count adjacent non-air/non-leaf blocks
|
||||
if( leftBlock.typeId == Material.SAND ||
|
||||
if (leftBlock.typeId == Material.SAND ||
|
||||
rightBlock.typeId == Material.SAND ||
|
||||
upBlock.typeId == Material.SAND ||
|
||||
downBlock.typeId == Material.SAND ||
|
||||
|
|
@ -217,8 +217,7 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
underBlock.typeId == Material.SAND)
|
||||
{
|
||||
snapshots[x][y][z].typeId = Material.SAND;
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
snapshots[x][y][z].typeId = Material.AIR;
|
||||
}
|
||||
|
|
@ -230,15 +229,15 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
@SuppressWarnings("deprecation")
|
||||
private void reduceStone()
|
||||
{
|
||||
if(this.seaLevel < 1) return;
|
||||
if (this.seaLevel < 1) return;
|
||||
|
||||
for(int x = 1; x < snapshots.length - 1; x++)
|
||||
for (int x = 1; x < snapshots.length - 1; x++)
|
||||
{
|
||||
for(int z = 1; z < snapshots[0][0].length - 1; z++)
|
||||
for (int z = 1; z < snapshots[0][0].length - 1; z++)
|
||||
{
|
||||
int thisy = this.highestY(x, z, true);
|
||||
|
||||
while(thisy > this.seaLevel - 1 && (this.snapshots[x][thisy][z].typeId == Material.STONE || this.snapshots[x][thisy][z].typeId == Material.SANDSTONE))
|
||||
while (thisy > this.seaLevel - 1 && (this.snapshots[x][thisy][z].typeId == Material.STONE || this.snapshots[x][thisy][z].typeId == Material.SANDSTONE))
|
||||
{
|
||||
BlockSnapshot leftBlock = this.snapshots[x + 1][thisy][z];
|
||||
BlockSnapshot rightBlock = this.snapshots[x - 1][thisy][z];
|
||||
|
|
@ -247,24 +246,24 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
|
||||
//count adjacent non-air/non-leaf blocks
|
||||
byte adjacentBlockCount = 0;
|
||||
if(leftBlock.typeId != Material.AIR && !Tag.LEAVES.isTagged(leftBlock.typeId) && leftBlock.typeId != Material.VINE)
|
||||
if (leftBlock.typeId != Material.AIR && !Tag.LEAVES.isTagged(leftBlock.typeId) && leftBlock.typeId != Material.VINE)
|
||||
{
|
||||
adjacentBlockCount++;
|
||||
}
|
||||
if(rightBlock.typeId != Material.AIR && !Tag.LEAVES.isTagged(rightBlock.typeId) && rightBlock.typeId != Material.VINE)
|
||||
if (rightBlock.typeId != Material.AIR && !Tag.LEAVES.isTagged(rightBlock.typeId) && rightBlock.typeId != Material.VINE)
|
||||
{
|
||||
adjacentBlockCount++;
|
||||
}
|
||||
if(downBlock.typeId != Material.AIR && !Tag.LEAVES.isTagged(downBlock.typeId) && downBlock.typeId != Material.VINE)
|
||||
if (downBlock.typeId != Material.AIR && !Tag.LEAVES.isTagged(downBlock.typeId) && downBlock.typeId != Material.VINE)
|
||||
{
|
||||
adjacentBlockCount++;
|
||||
}
|
||||
if(upBlock.typeId != Material.AIR && !Tag.LEAVES.isTagged(upBlock.typeId) && upBlock.typeId != Material.VINE)
|
||||
if (upBlock.typeId != Material.AIR && !Tag.LEAVES.isTagged(upBlock.typeId) && upBlock.typeId != Material.VINE)
|
||||
{
|
||||
adjacentBlockCount++;
|
||||
}
|
||||
|
||||
if(adjacentBlockCount < 3)
|
||||
if (adjacentBlockCount < 3)
|
||||
{
|
||||
this.snapshots[x][thisy][z].typeId = Material.AIR;
|
||||
}
|
||||
|
|
@ -278,24 +277,24 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
@SuppressWarnings("deprecation")
|
||||
private void reduceLogs()
|
||||
{
|
||||
if(this.seaLevel < 1) return;
|
||||
if (this.seaLevel < 1) return;
|
||||
|
||||
boolean jungleBiome = this.biome == Biome.JUNGLE || this.biome == Biome.JUNGLE_HILLS;
|
||||
|
||||
//scan all blocks above sea level
|
||||
for(int x = 1; x < snapshots.length - 1; x++)
|
||||
for (int x = 1; x < snapshots.length - 1; x++)
|
||||
{
|
||||
for(int z = 1; z < snapshots[0][0].length - 1; z++)
|
||||
for (int z = 1; z < snapshots[0][0].length - 1; z++)
|
||||
{
|
||||
for(int y = this.seaLevel - 1; y < snapshots[0].length; y++)
|
||||
for (int y = this.seaLevel - 1; y < snapshots[0].length; y++)
|
||||
{
|
||||
BlockSnapshot block = snapshots[x][y][z];
|
||||
|
||||
//skip non-logs
|
||||
if(!Tag.LOGS.isTagged(block.typeId)) continue;
|
||||
if (!Tag.LOGS.isTagged(block.typeId)) continue;
|
||||
|
||||
//if in jungle biome, skip jungle logs
|
||||
if(jungleBiome && block.typeId == Material.JUNGLE_LOG) continue;
|
||||
if (jungleBiome && block.typeId == Material.JUNGLE_LOG) continue;
|
||||
|
||||
//examine adjacent blocks for logs
|
||||
BlockSnapshot leftBlock = this.snapshots[x + 1][y][z];
|
||||
|
|
@ -304,7 +303,7 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
BlockSnapshot downBlock = this.snapshots[x][y][z - 1];
|
||||
|
||||
//if any, remove the log
|
||||
if(Tag.LOGS.isTagged(leftBlock.typeId) || Tag.LOGS.isTagged(rightBlock.typeId) || Tag.LOGS.isTagged(upBlock.typeId) || Tag.LOGS.isTagged(downBlock.typeId))
|
||||
if (Tag.LOGS.isTagged(leftBlock.typeId) || Tag.LOGS.isTagged(rightBlock.typeId) || Tag.LOGS.isTagged(upBlock.typeId) || Tag.LOGS.isTagged(downBlock.typeId))
|
||||
{
|
||||
this.snapshots[x][y][z].typeId = Material.AIR;
|
||||
}
|
||||
|
|
@ -317,18 +316,18 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
private void removePlayerBlocks()
|
||||
{
|
||||
int miny = this.miny;
|
||||
if(miny < 1) miny = 1;
|
||||
if (miny < 1) miny = 1;
|
||||
|
||||
//remove all player blocks
|
||||
for(int x = 1; x < snapshots.length - 1; x++)
|
||||
for (int x = 1; x < snapshots.length - 1; x++)
|
||||
{
|
||||
for(int z = 1; z < snapshots[0][0].length - 1; z++)
|
||||
for (int z = 1; z < snapshots[0][0].length - 1; z++)
|
||||
{
|
||||
for(int y = miny; y < snapshots[0].length - 1; y++)
|
||||
for (int y = miny; y < snapshots[0].length - 1; y++)
|
||||
{
|
||||
BlockSnapshot block = snapshots[x][y][z];
|
||||
|
||||
if(this.playerBlocks.contains(block.typeId))
|
||||
if (this.playerBlocks.contains(block.typeId))
|
||||
{
|
||||
block.typeId = Material.AIR;
|
||||
}
|
||||
|
|
@ -341,20 +340,20 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
private void removeHanging()
|
||||
{
|
||||
int miny = this.miny;
|
||||
if(miny < 1) miny = 1;
|
||||
if (miny < 1) miny = 1;
|
||||
|
||||
for(int x = 1; x < snapshots.length - 1; x++)
|
||||
for (int x = 1; x < snapshots.length - 1; x++)
|
||||
{
|
||||
for(int z = 1; z < snapshots[0][0].length - 1; z++)
|
||||
for (int z = 1; z < snapshots[0][0].length - 1; z++)
|
||||
{
|
||||
for(int y = miny; y < snapshots[0].length - 1; y++)
|
||||
for (int y = miny; y < snapshots[0].length - 1; y++)
|
||||
{
|
||||
BlockSnapshot block = snapshots[x][y][z];
|
||||
BlockSnapshot underBlock = snapshots[x][y - 1][z];
|
||||
|
||||
if(underBlock.typeId == Material.AIR || underBlock.typeId == Material.WATER || Tag.LEAVES.isTagged(underBlock.typeId))
|
||||
if (underBlock.typeId == Material.AIR || underBlock.typeId == Material.WATER || Tag.LEAVES.isTagged(underBlock.typeId))
|
||||
{
|
||||
if(this.notAllowedToHang.contains(block.typeId))
|
||||
if (this.notAllowedToHang.contains(block.typeId))
|
||||
{
|
||||
block.typeId = Material.AIR;
|
||||
}
|
||||
|
|
@ -367,7 +366,7 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
@SuppressWarnings("deprecation")
|
||||
private void removeWallsAndTowers()
|
||||
{
|
||||
Material [] excludedBlocksArray = new Material []
|
||||
Material[] excludedBlocksArray = new Material[]
|
||||
{
|
||||
Material.CACTUS,
|
||||
Material.GRASS,
|
||||
|
|
@ -391,7 +390,7 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
};
|
||||
|
||||
ArrayList<Material> excludedBlocks = new ArrayList<Material>();
|
||||
for(int i = 0; i < excludedBlocksArray.length; i++) excludedBlocks.add(excludedBlocksArray[i]);
|
||||
for (int i = 0; i < excludedBlocksArray.length; i++) excludedBlocks.add(excludedBlocksArray[i]);
|
||||
|
||||
excludedBlocks.addAll(Tag.SAPLINGS.getValues());
|
||||
excludedBlocks.addAll(Tag.LEAVES.getValues());
|
||||
|
|
@ -400,16 +399,16 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
do
|
||||
{
|
||||
changed = false;
|
||||
for(int x = 1; x < snapshots.length - 1; x++)
|
||||
for (int x = 1; x < snapshots.length - 1; x++)
|
||||
{
|
||||
for(int z = 1; z < snapshots[0][0].length - 1; z++)
|
||||
for (int z = 1; z < snapshots[0][0].length - 1; z++)
|
||||
{
|
||||
int thisy = this.highestY(x, z, false);
|
||||
if(excludedBlocks.contains(this.snapshots[x][thisy][z].typeId)) continue;
|
||||
if (excludedBlocks.contains(this.snapshots[x][thisy][z].typeId)) continue;
|
||||
|
||||
int righty = this.highestY(x + 1, z, false);
|
||||
int lefty = this.highestY(x - 1, z, false);
|
||||
while(lefty < thisy && righty < thisy)
|
||||
while (lefty < thisy && righty < thisy)
|
||||
{
|
||||
this.snapshots[x][thisy--][z].typeId = Material.AIR;
|
||||
changed = true;
|
||||
|
|
@ -417,33 +416,32 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
|
||||
int upy = this.highestY(x, z + 1, false);
|
||||
int downy = this.highestY(x, z - 1, false);
|
||||
while(upy < thisy && downy < thisy)
|
||||
while (upy < thisy && downy < thisy)
|
||||
{
|
||||
this.snapshots[x][thisy--][z].typeId = Material.AIR;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}while(changed);
|
||||
} while (changed);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void coverSurfaceStone()
|
||||
{
|
||||
for(int x = 1; x < snapshots.length - 1; x++)
|
||||
for (int x = 1; x < snapshots.length - 1; x++)
|
||||
{
|
||||
for(int z = 1; z < snapshots[0][0].length - 1; z++)
|
||||
for (int z = 1; z < snapshots[0][0].length - 1; z++)
|
||||
{
|
||||
int y = this.highestY(x, z, true);
|
||||
BlockSnapshot block = snapshots[x][y][z];
|
||||
|
||||
if(block.typeId == Material.STONE || block.typeId == Material.GRAVEL || block.typeId == Material.FARMLAND || block.typeId == Material.DIRT || block.typeId == Material.SANDSTONE)
|
||||
if (block.typeId == Material.STONE || block.typeId == Material.GRAVEL || block.typeId == Material.FARMLAND || block.typeId == Material.DIRT || block.typeId == Material.SANDSTONE)
|
||||
{
|
||||
if(this.biome == Biome.DESERT || this.biome == Biome.DESERT_HILLS || this.biome == Biome.BEACH)
|
||||
if (this.biome == Biome.DESERT || this.biome == Biome.DESERT_HILLS || this.biome == Biome.BEACH)
|
||||
{
|
||||
this.snapshots[x][y][z].typeId = Material.SAND;
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
this.snapshots[x][y][z].typeId = Material.GRASS_BLOCK;
|
||||
}
|
||||
|
|
@ -472,21 +470,21 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
do
|
||||
{
|
||||
changed = false;
|
||||
for(int x = 1; x < snapshots.length - 1; x++)
|
||||
for (int x = 1; x < snapshots.length - 1; x++)
|
||||
{
|
||||
for(int z = 1; z < snapshots[0][0].length - 1; z++)
|
||||
for (int z = 1; z < snapshots[0][0].length - 1; z++)
|
||||
{
|
||||
for(int y = 0; y < snapshots[0].length - 1; y++)
|
||||
for (int y = 0; y < snapshots[0].length - 1; y++)
|
||||
{
|
||||
BlockSnapshot block = this.snapshots[x][y][z];
|
||||
if(!fillableBlocks.contains(block.typeId)) continue;
|
||||
if (!fillableBlocks.contains(block.typeId)) continue;
|
||||
|
||||
BlockSnapshot leftBlock = this.snapshots[x + 1][y][z];
|
||||
BlockSnapshot rightBlock = this.snapshots[x - 1][y][z];
|
||||
|
||||
if(!fillableBlocks.contains(leftBlock.typeId) && !fillableBlocks.contains(rightBlock.typeId))
|
||||
if (!fillableBlocks.contains(leftBlock.typeId) && !fillableBlocks.contains(rightBlock.typeId))
|
||||
{
|
||||
if(!notSuitableForFillBlocks.contains(rightBlock.typeId))
|
||||
if (!notSuitableForFillBlocks.contains(rightBlock.typeId))
|
||||
{
|
||||
block.typeId = rightBlock.typeId;
|
||||
changed = true;
|
||||
|
|
@ -496,9 +494,9 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
BlockSnapshot upBlock = this.snapshots[x][y][z + 1];
|
||||
BlockSnapshot downBlock = this.snapshots[x][y][z - 1];
|
||||
|
||||
if(!fillableBlocks.contains(upBlock.typeId) && !fillableBlocks.contains(downBlock.typeId))
|
||||
if (!fillableBlocks.contains(upBlock.typeId) && !fillableBlocks.contains(downBlock.typeId))
|
||||
{
|
||||
if(!notSuitableForFillBlocks.contains(downBlock.typeId))
|
||||
if (!notSuitableForFillBlocks.contains(downBlock.typeId))
|
||||
{
|
||||
block.typeId = downBlock.typeId;
|
||||
changed = true;
|
||||
|
|
@ -507,30 +505,30 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
}
|
||||
}
|
||||
}
|
||||
}while(changed);
|
||||
} while (changed);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void fixWater()
|
||||
{
|
||||
int miny = this.miny;
|
||||
if(miny < 1) miny = 1;
|
||||
if (miny < 1) miny = 1;
|
||||
|
||||
boolean changed;
|
||||
|
||||
//remove hanging water or lava
|
||||
for(int x = 1; x < snapshots.length - 1; x++)
|
||||
for (int x = 1; x < snapshots.length - 1; x++)
|
||||
{
|
||||
for(int z = 1; z < snapshots[0][0].length - 1; z++)
|
||||
for (int z = 1; z < snapshots[0][0].length - 1; z++)
|
||||
{
|
||||
for(int y = miny; y < snapshots[0].length - 1; y++)
|
||||
for (int y = miny; y < snapshots[0].length - 1; y++)
|
||||
{
|
||||
BlockSnapshot block = this.snapshots[x][y][z];
|
||||
BlockSnapshot underBlock = this.snapshots[x][y--][z];
|
||||
if(block.typeId == Material.WATER || block.typeId == Material.LAVA)
|
||||
if (block.typeId == Material.WATER || block.typeId == Material.LAVA)
|
||||
{
|
||||
// check if block below is air or is a non-source fluid block (level 1-7 = flowing, 8 = falling)
|
||||
if(underBlock.typeId == Material.AIR || (underBlock.typeId == Material.WATER && (((Levelled) underBlock.data).getLevel() != 0)))
|
||||
if (underBlock.typeId == Material.AIR || (underBlock.typeId == Material.WATER && (((Levelled) underBlock.data).getLevel() != 0)))
|
||||
{
|
||||
block.typeId = Material.AIR;
|
||||
}
|
||||
|
|
@ -543,16 +541,16 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
do
|
||||
{
|
||||
changed = false;
|
||||
for(int y = Math.max(this.seaLevel - 10, 0); y <= this.seaLevel; y++)
|
||||
for (int y = Math.max(this.seaLevel - 10, 0); y <= this.seaLevel; y++)
|
||||
{
|
||||
for(int x = 1; x < snapshots.length - 1; x++)
|
||||
for (int x = 1; x < snapshots.length - 1; x++)
|
||||
{
|
||||
for(int z = 1; z < snapshots[0][0].length - 1; z++)
|
||||
for (int z = 1; z < snapshots[0][0].length - 1; z++)
|
||||
{
|
||||
BlockSnapshot block = snapshots[x][y][z];
|
||||
|
||||
//only consider air blocks and flowing water blocks for upgrade to water source blocks
|
||||
if(block.typeId == Material.AIR || (block.typeId == Material.WATER && ((Levelled) block.data).getLevel() != 0))
|
||||
if (block.typeId == Material.AIR || (block.typeId == Material.WATER && ((Levelled) block.data).getLevel() != 0))
|
||||
{
|
||||
BlockSnapshot leftBlock = this.snapshots[x + 1][y][z];
|
||||
BlockSnapshot rightBlock = this.snapshots[x - 1][y][z];
|
||||
|
|
@ -561,29 +559,30 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
BlockSnapshot underBlock = this.snapshots[x][y - 1][z];
|
||||
|
||||
//block underneath MUST be source water
|
||||
if(!(underBlock.typeId == Material.WATER && ((Levelled) underBlock.data).getLevel() == 0)) continue;
|
||||
if (!(underBlock.typeId == Material.WATER && ((Levelled) underBlock.data).getLevel() == 0))
|
||||
continue;
|
||||
|
||||
//count adjacent source water blocks
|
||||
byte adjacentSourceWaterCount = 0;
|
||||
if(leftBlock.typeId == Material.WATER && ((Levelled) leftBlock.data).getLevel() == 0)
|
||||
if (leftBlock.typeId == Material.WATER && ((Levelled) leftBlock.data).getLevel() == 0)
|
||||
{
|
||||
adjacentSourceWaterCount++;
|
||||
}
|
||||
if(rightBlock.typeId == Material.WATER && ((Levelled) rightBlock.data).getLevel() == 0)
|
||||
if (rightBlock.typeId == Material.WATER && ((Levelled) rightBlock.data).getLevel() == 0)
|
||||
{
|
||||
adjacentSourceWaterCount++;
|
||||
}
|
||||
if(upBlock.typeId == Material.WATER && ((Levelled) upBlock.data).getLevel() == 0)
|
||||
if (upBlock.typeId == Material.WATER && ((Levelled) upBlock.data).getLevel() == 0)
|
||||
{
|
||||
adjacentSourceWaterCount++;
|
||||
}
|
||||
if(downBlock.typeId == Material.WATER && ((Levelled) downBlock.data).getLevel() == 0)
|
||||
if (downBlock.typeId == Material.WATER && ((Levelled) downBlock.data).getLevel() == 0)
|
||||
{
|
||||
adjacentSourceWaterCount++;
|
||||
}
|
||||
|
||||
//at least two adjacent blocks must be source water
|
||||
if(adjacentSourceWaterCount >= 2)
|
||||
if (adjacentSourceWaterCount >= 2)
|
||||
{
|
||||
block.typeId = Material.WATER;
|
||||
((Levelled) downBlock.data).setLevel(0);
|
||||
|
|
@ -593,25 +592,25 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
}
|
||||
}
|
||||
}
|
||||
}while(changed);
|
||||
} while (changed);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void removeDumpedFluids()
|
||||
{
|
||||
if(this.seaLevel < 1) return;
|
||||
if (this.seaLevel < 1) return;
|
||||
|
||||
//remove any surface water or lava above sea level, presumed to be placed by players
|
||||
//sometimes, this is naturally generated. but replacing it is very easy with a bucket, so overall this is a good plan
|
||||
if(this.environment == Environment.NETHER) return;
|
||||
for(int x = 1; x < snapshots.length - 1; x++)
|
||||
if (this.environment == Environment.NETHER) return;
|
||||
for (int x = 1; x < snapshots.length - 1; x++)
|
||||
{
|
||||
for(int z = 1; z < snapshots[0][0].length - 1; z++)
|
||||
for (int z = 1; z < snapshots[0][0].length - 1; z++)
|
||||
{
|
||||
for(int y = this.seaLevel - 1; y < snapshots[0].length - 1; y++)
|
||||
for (int y = this.seaLevel - 1; y < snapshots[0].length - 1; y++)
|
||||
{
|
||||
BlockSnapshot block = snapshots[x][y][z];
|
||||
if(block.typeId == Material.WATER || block.typeId == Material.LAVA)
|
||||
if (block.typeId == Material.WATER || block.typeId == Material.LAVA)
|
||||
{
|
||||
block.typeId = Material.AIR;
|
||||
}
|
||||
|
|
@ -624,10 +623,10 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
private int highestY(int x, int z, boolean ignoreLeaves)
|
||||
{
|
||||
int y;
|
||||
for(y = snapshots[0].length - 1; y > 0; y--)
|
||||
for (y = snapshots[0].length - 1; y > 0; y--)
|
||||
{
|
||||
BlockSnapshot block = this.snapshots[x][y][z];
|
||||
if(block.typeId != Material.AIR &&
|
||||
if (block.typeId != Material.AIR &&
|
||||
!(ignoreLeaves && block.typeId == Material.SNOW) &&
|
||||
!(ignoreLeaves && Tag.LEAVES.isTagged(block.typeId)) &&
|
||||
!(block.typeId == Material.WATER) &&
|
||||
|
|
@ -929,7 +928,7 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
playerBlocks.add(Material.BONE_BLOCK);
|
||||
|
||||
//these are unnatural in the standard world, but not in the nether
|
||||
if(environment != Environment.NETHER)
|
||||
if (environment != Environment.NETHER)
|
||||
{
|
||||
playerBlocks.add(Material.NETHERRACK);
|
||||
playerBlocks.add(Material.SOUL_SAND);
|
||||
|
|
@ -941,7 +940,7 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
}
|
||||
|
||||
//these are unnatural in the standard and nether worlds, but not in the end
|
||||
if(environment != Environment.THE_END)
|
||||
if (environment != Environment.THE_END)
|
||||
{
|
||||
playerBlocks.add(Material.OBSIDIAN);
|
||||
playerBlocks.add(Material.END_STONE);
|
||||
|
|
@ -951,7 +950,7 @@ class RestoreNatureProcessingTask implements Runnable
|
|||
}
|
||||
|
||||
//these are unnatural in sandy biomes, but not elsewhere
|
||||
if(biome == Biome.DESERT || biome == Biome.DESERT_HILLS || biome == Biome.BEACH || environment != Environment.NORMAL)
|
||||
if (biome == Biome.DESERT || biome == Biome.DESERT_HILLS || biome == Biome.BEACH || environment != Environment.NORMAL)
|
||||
{
|
||||
playerBlocks.add(Material.OAK_LEAVES);
|
||||
playerBlocks.add(Material.SPRUCE_LEAVES);
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import java.util.Collection;
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
//secures a claim after a siege looting window has closed
|
||||
class SecureClaimTask implements Runnable
|
||||
{
|
||||
|
|
@ -36,7 +36,7 @@ class SecureClaimTask implements Runnable
|
|||
public void run()
|
||||
{
|
||||
//for each claim involved in this siege
|
||||
for(int i = 0; i < this.siegeData.claims.size(); i++)
|
||||
for (int i = 0; i < this.siegeData.claims.size(); i++)
|
||||
{
|
||||
//lock the doors
|
||||
Claim claim = this.siegeData.claims.get(i);
|
||||
|
|
@ -44,10 +44,10 @@ class SecureClaimTask implements Runnable
|
|||
|
||||
//eject bad guys
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<Player> onlinePlayers = (Collection<Player>)GriefPrevention.instance.getServer().getOnlinePlayers();
|
||||
for(Player player : onlinePlayers)
|
||||
Collection<Player> onlinePlayers = (Collection<Player>) GriefPrevention.instance.getServer().getOnlinePlayers();
|
||||
for (Player player : onlinePlayers)
|
||||
{
|
||||
if(claim.contains(player.getLocation(), false, false) && claim.allowAccess(player) != null)
|
||||
if (claim.contains(player.getLocation(), false, false) && claim.allowAccess(player) != null)
|
||||
{
|
||||
GriefPrevention.sendMessage(player, TextMode.Err, Messages.SiegeDoorsLockedEjection);
|
||||
GriefPrevention.instance.ejectPlayer(player);
|
||||
|
|
|
|||
|
|
@ -39,14 +39,14 @@ class SendPlayerMessageTask implements Runnable
|
|||
@Override
|
||||
public void run()
|
||||
{
|
||||
if(player == null)
|
||||
if (player == null)
|
||||
{
|
||||
GriefPrevention.AddLogEntry(color + message);
|
||||
return;
|
||||
}
|
||||
|
||||
//if the player is dead, save it for after his respawn
|
||||
if(this.player.isDead())
|
||||
if (this.player.isDead())
|
||||
{
|
||||
PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(this.player.getUniqueId());
|
||||
playerData.messageOnRespawn = this.color + this.message;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
//enumeration for golden shovel modes
|
||||
public enum ShovelMode
|
||||
|
|
|
|||
|
|
@ -42,10 +42,10 @@ class SiegeCheckupTask implements Runnable
|
|||
Claim defenderClaim = dataStore.getClaimAt(defender.getLocation(), false, null);
|
||||
|
||||
//if this is a new claim and he has some permission there, extend the siege to include it
|
||||
if(defenderClaim != null)
|
||||
if (defenderClaim != null)
|
||||
{
|
||||
String noAccessReason = defenderClaim.allowAccess(defender);
|
||||
if(defenderClaim.canSiege(defender) && noAccessReason == null)
|
||||
if (defenderClaim.canSiege(defender) && noAccessReason == null)
|
||||
{
|
||||
this.siegeData.claims.add(defenderClaim);
|
||||
defenderClaim.siegeData = this.siegeData;
|
||||
|
|
@ -57,25 +57,25 @@ class SiegeCheckupTask implements Runnable
|
|||
boolean defenderRemains = this.playerRemains(defender);
|
||||
|
||||
//if they're both here, just plan to come check again later
|
||||
if(attackerRemains && defenderRemains)
|
||||
if (attackerRemains && defenderRemains)
|
||||
{
|
||||
this.scheduleAnotherCheck();
|
||||
}
|
||||
|
||||
//otherwise attacker wins if the defender runs away
|
||||
else if(attackerRemains && !defenderRemains)
|
||||
else if (attackerRemains && !defenderRemains)
|
||||
{
|
||||
dataStore.endSiege(this.siegeData, attacker.getName(), defender.getName(), null);
|
||||
}
|
||||
|
||||
//or defender wins if the attacker leaves
|
||||
else if(!attackerRemains && defenderRemains)
|
||||
else if (!attackerRemains && defenderRemains)
|
||||
{
|
||||
dataStore.endSiege(this.siegeData, defender.getName(), attacker.getName(), null);
|
||||
}
|
||||
|
||||
//if they both left, but are still close together, the battle continues (check again later)
|
||||
else if(attacker.getWorld().equals(defender.getWorld()) && attacker.getLocation().distanceSquared(defender.getLocation()) < 2500) //50-block radius for chasing
|
||||
else if (attacker.getWorld().equals(defender.getWorld()) && attacker.getLocation().distanceSquared(defender.getLocation()) < 2500) //50-block radius for chasing
|
||||
{
|
||||
this.scheduleAnotherCheck();
|
||||
}
|
||||
|
|
@ -90,10 +90,10 @@ class SiegeCheckupTask implements Runnable
|
|||
//a player has to be within 25 blocks of the edge of a besieged claim to be considered still in the fight
|
||||
private boolean playerRemains(Player player)
|
||||
{
|
||||
for(int i = 0; i < this.siegeData.claims.size(); i++)
|
||||
for (int i = 0; i < this.siegeData.claims.size(); i++)
|
||||
{
|
||||
Claim claim = this.siegeData.claims.get(i);
|
||||
if(claim.isNear(player.getLocation(), 25))
|
||||
if (claim.isNear(player.getLocation(), 25))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,10 +18,10 @@
|
|||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
//information about an ongoing siege
|
||||
public class SiegeData
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,10 +15,11 @@ class SpamDetector
|
|||
|
||||
//data for individual chatters
|
||||
ConcurrentHashMap<UUID, ChatterData> dataStore = new ConcurrentHashMap<UUID, ChatterData>();
|
||||
|
||||
private ChatterData getChatterData(UUID chatterID)
|
||||
{
|
||||
ChatterData data = this.dataStore.get(chatterID);
|
||||
if(data == null)
|
||||
if (data == null)
|
||||
{
|
||||
data = new ChatterData();
|
||||
this.dataStore.put(chatterID, data);
|
||||
|
|
@ -33,7 +34,7 @@ class SpamDetector
|
|||
result.finalMessage = message;
|
||||
|
||||
//remedy any CAPS SPAM, exception for very short messages which could be emoticons like =D or XD
|
||||
if(message.length() > 4 && this.stringsAreSimilar(message.toUpperCase(), message))
|
||||
if (message.length() > 4 && this.stringsAreSimilar(message.toUpperCase(), message))
|
||||
{
|
||||
message = message.toLowerCase();
|
||||
result.finalMessage = message;
|
||||
|
|
@ -43,7 +44,7 @@ class SpamDetector
|
|||
ChatterData chatterData = this.getChatterData(chatterID);
|
||||
|
||||
//mute if total volume of text from this player is too high
|
||||
if(message.length() > 50 && chatterData.getTotalRecentLength(timestamp) > 200)
|
||||
if (message.length() > 50 && chatterData.getTotalRecentLength(timestamp) > 200)
|
||||
{
|
||||
spam = true;
|
||||
result.muteReason = "too much chat sent in 10 seconds";
|
||||
|
|
@ -51,13 +52,12 @@ class SpamDetector
|
|||
}
|
||||
|
||||
//always mute an exact match to the last chat message
|
||||
if(result.finalMessage.equals(this.lastChatMessage) && timestamp - this.lastChatMessageTimestamp < 2000)
|
||||
if (result.finalMessage.equals(this.lastChatMessage) && timestamp - this.lastChatMessageTimestamp < 2000)
|
||||
{
|
||||
chatterData.spamLevel += ++this.duplicateMessageCount;
|
||||
spam = true;
|
||||
result.muteReason = "repeat message";
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
this.lastChatMessage = message;
|
||||
this.lastChatMessageTimestamp = timestamp;
|
||||
|
|
@ -68,7 +68,7 @@ class SpamDetector
|
|||
long millisecondsSinceLastMessage = timestamp - chatterData.lastMessageTimestamp;
|
||||
|
||||
//if the message came too close to the last one
|
||||
if(millisecondsSinceLastMessage < 1500)
|
||||
if (millisecondsSinceLastMessage < 1500)
|
||||
{
|
||||
//increment the spam counter
|
||||
chatterData.spamLevel++;
|
||||
|
|
@ -76,7 +76,7 @@ class SpamDetector
|
|||
}
|
||||
|
||||
//if it's exactly the same as the last message from the same player and within 30 seconds
|
||||
if(result.muteReason == null && millisecondsSinceLastMessage < 30000 && result.finalMessage.equalsIgnoreCase(chatterData.lastMessage))
|
||||
if (result.muteReason == null && millisecondsSinceLastMessage < 30000 && result.finalMessage.equalsIgnoreCase(chatterData.lastMessage))
|
||||
{
|
||||
chatterData.spamLevel++;
|
||||
spam = true;
|
||||
|
|
@ -84,68 +84,66 @@ class SpamDetector
|
|||
}
|
||||
|
||||
//if it's very similar to the last message from the same player and within 10 seconds of that message
|
||||
if(result.muteReason == null && millisecondsSinceLastMessage < 10000 && this.stringsAreSimilar(message.toLowerCase(), chatterData.lastMessage.toLowerCase()))
|
||||
if (result.muteReason == null && millisecondsSinceLastMessage < 10000 && this.stringsAreSimilar(message.toLowerCase(), chatterData.lastMessage.toLowerCase()))
|
||||
{
|
||||
chatterData.spamLevel++;
|
||||
spam = true;
|
||||
if(chatterData.spamLevel > 2)
|
||||
if (chatterData.spamLevel > 2)
|
||||
{
|
||||
result.muteReason = "similar message";
|
||||
}
|
||||
}
|
||||
|
||||
//if the message was mostly non-alpha-numerics or doesn't include much whitespace, consider it a spam (probably ansi art or random text gibberish)
|
||||
if(result.muteReason == null && message.length() > 5)
|
||||
if (result.muteReason == null && message.length() > 5)
|
||||
{
|
||||
int symbolsCount = 0;
|
||||
int whitespaceCount = 0;
|
||||
for(int i = 0; i < message.length(); i++)
|
||||
for (int i = 0; i < message.length(); i++)
|
||||
{
|
||||
char character = message.charAt(i);
|
||||
if(!(Character.isLetterOrDigit(character)))
|
||||
if (!(Character.isLetterOrDigit(character)))
|
||||
{
|
||||
symbolsCount++;
|
||||
}
|
||||
|
||||
if(Character.isWhitespace(character))
|
||||
if (Character.isWhitespace(character))
|
||||
{
|
||||
whitespaceCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if(symbolsCount > message.length() / 2 || (message.length() > 15 && whitespaceCount < message.length() / 10))
|
||||
if (symbolsCount > message.length() / 2 || (message.length() > 15 && whitespaceCount < message.length() / 10))
|
||||
{
|
||||
spam = true;
|
||||
if(chatterData.spamLevel > 0) result.muteReason = "gibberish";
|
||||
if (chatterData.spamLevel > 0) result.muteReason = "gibberish";
|
||||
chatterData.spamLevel++;
|
||||
}
|
||||
}
|
||||
|
||||
//very short messages close together are spam
|
||||
if(result.muteReason == null && message.length() < 5 && millisecondsSinceLastMessage < 3000)
|
||||
if (result.muteReason == null && message.length() < 5 && millisecondsSinceLastMessage < 3000)
|
||||
{
|
||||
spam = true;
|
||||
chatterData.spamLevel++;
|
||||
}
|
||||
|
||||
//if the message was determined to be a spam, consider taking action
|
||||
if(spam)
|
||||
if (spam)
|
||||
{
|
||||
//anything above level 8 for a player which has received a warning... kick or if enabled, ban
|
||||
if(chatterData.spamLevel > 8 && chatterData.spamWarned)
|
||||
if (chatterData.spamLevel > 8 && chatterData.spamWarned)
|
||||
{
|
||||
result.shouldBanChatter = true;
|
||||
}
|
||||
|
||||
else if(chatterData.spamLevel >= 4)
|
||||
} else if (chatterData.spamLevel >= 4)
|
||||
{
|
||||
if(!chatterData.spamWarned)
|
||||
if (!chatterData.spamWarned)
|
||||
{
|
||||
chatterData.spamWarned = true;
|
||||
result.shouldWarnChatter = true;
|
||||
}
|
||||
|
||||
if(result.muteReason == null)
|
||||
if (result.muteReason == null)
|
||||
{
|
||||
result.muteReason = "too-frequent text";
|
||||
}
|
||||
|
|
@ -173,40 +171,40 @@ class SpamDetector
|
|||
|
||||
//determine which is shorter
|
||||
String shorterString, longerString;
|
||||
if(lastMessage.length() < message.length())
|
||||
if (lastMessage.length() < message.length())
|
||||
{
|
||||
shorterString = lastMessage;
|
||||
longerString = message;
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
shorterString = message;
|
||||
longerString = lastMessage;
|
||||
}
|
||||
|
||||
if(shorterString.length() <= 5) return shorterString.equals(longerString);
|
||||
if (shorterString.length() <= 5) return shorterString.equals(longerString);
|
||||
|
||||
//set similarity tolerance
|
||||
int maxIdenticalCharacters = longerString.length() - longerString.length() / 4;
|
||||
|
||||
//trivial check on length
|
||||
if(shorterString.length() < maxIdenticalCharacters) return false;
|
||||
if (shorterString.length() < maxIdenticalCharacters) return false;
|
||||
|
||||
//compare forward
|
||||
int identicalCount = 0;
|
||||
int i;
|
||||
for(i = 0; i < shorterString.length(); i++)
|
||||
for (i = 0; i < shorterString.length(); i++)
|
||||
{
|
||||
if(shorterString.charAt(i) == longerString.charAt(i)) identicalCount++;
|
||||
if(identicalCount > maxIdenticalCharacters) return true;
|
||||
if (shorterString.charAt(i) == longerString.charAt(i)) identicalCount++;
|
||||
if (identicalCount > maxIdenticalCharacters) return true;
|
||||
}
|
||||
|
||||
//compare backward
|
||||
int j;
|
||||
for(j = 0; j < shorterString.length() - i; j++)
|
||||
for (j = 0; j < shorterString.length() - i; j++)
|
||||
{
|
||||
if(shorterString.charAt(shorterString.length() - j - 1) == longerString.charAt(longerString.length() - j - 1)) identicalCount++;
|
||||
if(identicalCount > maxIdenticalCharacters) return true;
|
||||
if (shorterString.charAt(shorterString.length() - j - 1) == longerString.charAt(longerString.length() - j - 1))
|
||||
identicalCount++;
|
||||
if (identicalCount > maxIdenticalCharacters) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
@ -245,7 +243,7 @@ class ChatterData
|
|||
public int getTotalRecentLength(long timestamp)
|
||||
{
|
||||
LengthTimestampPair oldestPair = this.recentMessageLengths.peek();
|
||||
while(oldestPair != null && timestamp - oldestPair.timestamp > 10000)
|
||||
while (oldestPair != null && timestamp - oldestPair.timestamp > 10000)
|
||||
{
|
||||
this.recentMessageLengths.poll();
|
||||
this.recentTotalLength -= oldestPair.length;
|
||||
|
|
|
|||
|
|
@ -13,9 +13,12 @@ import java.io.OutputStream;
|
|||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
class UUIDFetcher {
|
||||
class UUIDFetcher
|
||||
{
|
||||
private static int PROFILES_PER_REQUEST = 100;
|
||||
private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft";
|
||||
private final JSONParser jsonParser = new JSONParser();
|
||||
|
|
@ -28,23 +31,25 @@ class UUIDFetcher {
|
|||
//record of username -> proper casing updates
|
||||
static HashMap<String, String> correctedNames;
|
||||
|
||||
public UUIDFetcher(List<String> names, boolean rateLimiting) {
|
||||
public UUIDFetcher(List<String> names, boolean rateLimiting)
|
||||
{
|
||||
this.names = names;
|
||||
this.rateLimiting = rateLimiting;
|
||||
}
|
||||
|
||||
public UUIDFetcher(List<String> names) {
|
||||
public UUIDFetcher(List<String> names)
|
||||
{
|
||||
this(names, true);
|
||||
}
|
||||
|
||||
public void call() throws Exception
|
||||
{
|
||||
if(lookupCache == null)
|
||||
if (lookupCache == null)
|
||||
{
|
||||
lookupCache = new HashMap<String, UUID>();
|
||||
}
|
||||
|
||||
if(correctedNames == null)
|
||||
if (correctedNames == null)
|
||||
{
|
||||
correctedNames = new HashMap<String, String>();
|
||||
}
|
||||
|
|
@ -52,10 +57,10 @@ class UUIDFetcher {
|
|||
GriefPrevention.AddLogEntry("UUID conversion process started. Please be patient - this may take a while.");
|
||||
|
||||
GriefPrevention.AddLogEntry("Mining your local world data to save calls to Mojang...");
|
||||
OfflinePlayer [] players = GriefPrevention.instance.getServer().getOfflinePlayers();
|
||||
for(OfflinePlayer player : players)
|
||||
OfflinePlayer[] players = GriefPrevention.instance.getServer().getOfflinePlayers();
|
||||
for (OfflinePlayer player : players)
|
||||
{
|
||||
if(player.getName() != null && player.getUniqueId() != null)
|
||||
if (player.getName() != null && player.getUniqueId() != null)
|
||||
{
|
||||
lookupCache.put(player.getName(), player.getUniqueId());
|
||||
lookupCache.put(player.getName().toLowerCase(), player.getUniqueId());
|
||||
|
|
@ -65,11 +70,11 @@ class UUIDFetcher {
|
|||
|
||||
//try to get correct casing from local data
|
||||
GriefPrevention.AddLogEntry("Checking local server data to get correct casing for player names...");
|
||||
for(int i = 0; i < names.size(); i++)
|
||||
for (int i = 0; i < names.size(); i++)
|
||||
{
|
||||
String name = names.get(i);
|
||||
String correctCasingName = correctedNames.get(name);
|
||||
if(correctCasingName != null && !name.equals(correctCasingName))
|
||||
if (correctCasingName != null && !name.equals(correctCasingName))
|
||||
{
|
||||
GriefPrevention.AddLogEntry(name + " --> " + correctCasingName);
|
||||
names.set(i, correctCasingName);
|
||||
|
|
@ -78,11 +83,11 @@ class UUIDFetcher {
|
|||
|
||||
//look for local uuid's first
|
||||
GriefPrevention.AddLogEntry("Checking local server data for UUIDs already seen...");
|
||||
for(int i = 0; i < names.size(); i++)
|
||||
for (int i = 0; i < names.size(); i++)
|
||||
{
|
||||
String name = names.get(i);
|
||||
UUID uuid = lookupCache.get(name);
|
||||
if(uuid != null)
|
||||
if (uuid != null)
|
||||
{
|
||||
GriefPrevention.AddLogEntry(name + " --> " + uuid.toString());
|
||||
names.remove(i--);
|
||||
|
|
@ -90,7 +95,7 @@ class UUIDFetcher {
|
|||
}
|
||||
|
||||
//for online mode, call Mojang to resolve the rest
|
||||
if(GriefPrevention.instance.getServer().getOnlineMode())
|
||||
if (GriefPrevention.instance.getServer().getOnlineMode())
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Calling Mojang to get UUIDs for remaining unresolved players (this is the slowest step)...");
|
||||
|
||||
|
|
@ -109,16 +114,16 @@ class UUIDFetcher {
|
|||
{
|
||||
array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
//in case of error 429 too many requests, pause and then retry later
|
||||
if(e.getMessage().contains("429"))
|
||||
if (e.getMessage().contains("429"))
|
||||
{
|
||||
retry = true;
|
||||
|
||||
//if this is the first time we're sending anything, the batch size must be too big
|
||||
//try reducing it
|
||||
if(i == 0 && PROFILES_PER_REQUEST > 1)
|
||||
if (i == 0 && PROFILES_PER_REQUEST > 1)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Batch size " + PROFILES_PER_REQUEST + " seems too large. Looking for a workable batch size...");
|
||||
PROFILES_PER_REQUEST = Math.max(PROFILES_PER_REQUEST - 5, 1);
|
||||
|
|
@ -131,15 +136,15 @@ class UUIDFetcher {
|
|||
GriefPrevention.AddLogEntry("Mojang says we're sending requests too fast. Will retry every 30 seconds until we succeed...");
|
||||
Thread.sleep(30000);
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}while(retry);
|
||||
} while (retry);
|
||||
|
||||
for (Object profile : array) {
|
||||
for (Object profile : array)
|
||||
{
|
||||
JSONObject jsonProfile = (JSONObject) profile;
|
||||
String id = (String) jsonProfile.get("id");
|
||||
String name = (String) jsonProfile.get("name");
|
||||
|
|
@ -148,7 +153,8 @@ class UUIDFetcher {
|
|||
lookupCache.put(name, uuid);
|
||||
lookupCache.put(name.toLowerCase(), uuid);
|
||||
}
|
||||
if (rateLimiting) {
|
||||
if (rateLimiting)
|
||||
{
|
||||
Thread.sleep(200L);
|
||||
}
|
||||
}
|
||||
|
|
@ -159,7 +165,7 @@ class UUIDFetcher {
|
|||
{
|
||||
GriefPrevention.AddLogEntry("Generating offline mode UUIDs for remaining unresolved players...");
|
||||
|
||||
for(int i = 0; i < names.size(); i++)
|
||||
for (int i = 0; i < names.size(); i++)
|
||||
{
|
||||
String name = names.get(i);
|
||||
UUID uuid = java.util.UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
|
||||
|
|
@ -170,14 +176,16 @@ class UUIDFetcher {
|
|||
}
|
||||
}
|
||||
|
||||
private static void writeBody(HttpURLConnection connection, String body) throws Exception {
|
||||
private static void writeBody(HttpURLConnection connection, String body) throws Exception
|
||||
{
|
||||
OutputStream stream = connection.getOutputStream();
|
||||
stream.write(body.getBytes());
|
||||
stream.flush();
|
||||
stream.close();
|
||||
}
|
||||
|
||||
private static HttpURLConnection createConnection() throws Exception {
|
||||
private static HttpURLConnection createConnection() throws Exception
|
||||
{
|
||||
URL url = new URL(PROFILE_URL);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
|
|
@ -188,19 +196,23 @@ class UUIDFetcher {
|
|||
return connection;
|
||||
}
|
||||
|
||||
private static UUID getUUID(String id) {
|
||||
return UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" +id.substring(20, 32));
|
||||
private static UUID getUUID(String id)
|
||||
{
|
||||
return UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" + id.substring(20, 32));
|
||||
}
|
||||
|
||||
public static byte[] toBytes(UUID uuid) {
|
||||
public static byte[] toBytes(UUID uuid)
|
||||
{
|
||||
ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]);
|
||||
byteBuffer.putLong(uuid.getMostSignificantBits());
|
||||
byteBuffer.putLong(uuid.getLeastSignificantBits());
|
||||
return byteBuffer.array();
|
||||
}
|
||||
|
||||
public static UUID fromBytes(byte[] array) {
|
||||
if (array.length != 16) {
|
||||
public static UUID fromBytes(byte[] array)
|
||||
{
|
||||
if (array.length != 16)
|
||||
{
|
||||
throw new IllegalArgumentException("Illegal byte array length: " + array.length);
|
||||
}
|
||||
ByteBuffer byteBuffer = ByteBuffer.wrap(array);
|
||||
|
|
@ -212,7 +224,7 @@ class UUIDFetcher {
|
|||
public static UUID getUUIDOf(String name) throws Exception
|
||||
{
|
||||
UUID result = lookupCache.get(name);
|
||||
if(result == null)
|
||||
if (result == null)
|
||||
{
|
||||
//throw up our hands and report the problem in the logs
|
||||
//this player will lose his land claim blocks, but claims will stay in place as admin claims
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@
|
|||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
|
|
@ -30,6 +28,8 @@ import org.bukkit.block.data.BlockData;
|
|||
import org.bukkit.block.data.Lightable;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
//represents a visualization sent to a player
|
||||
//FEATURE: to show players visually where claim boundaries are, we send them fake block change packets
|
||||
//the result is that those players see new blocks, but the world hasn't been changed. other players can't see the new blocks, either.
|
||||
|
|
@ -43,13 +43,13 @@ public class Visualization
|
|||
PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId());
|
||||
|
||||
//if he has any current visualization, clear it first
|
||||
if(playerData.currentVisualization != null)
|
||||
if (playerData.currentVisualization != null)
|
||||
{
|
||||
Visualization.Revert(player);
|
||||
}
|
||||
|
||||
//if he's online, create a task to send him the visualization
|
||||
if(player.isOnline() && visualization.elements.size() > 0 && visualization.elements.get(0).location.getWorld().equals(player.getWorld()))
|
||||
if (player.isOnline() && visualization.elements.size() > 0 && visualization.elements.get(0).location.getWorld().equals(player.getWorld()))
|
||||
{
|
||||
GriefPrevention.instance.getServer().getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, new VisualizationApplicationTask(player, playerData, visualization), 1L);
|
||||
}
|
||||
|
|
@ -59,13 +59,13 @@ public class Visualization
|
|||
@SuppressWarnings("deprecation")
|
||||
public static void Revert(Player player)
|
||||
{
|
||||
if(!player.isOnline()) return;
|
||||
if (!player.isOnline()) return;
|
||||
|
||||
PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId());
|
||||
|
||||
Visualization visualization = playerData.currentVisualization;
|
||||
|
||||
if(playerData.currentVisualization != null)
|
||||
if (playerData.currentVisualization != null)
|
||||
{
|
||||
//locality
|
||||
int minx = player.getLocation().getBlockX() - 100;
|
||||
|
|
@ -77,14 +77,14 @@ public class Visualization
|
|||
visualization.removeElementsOutOfRange(visualization.elements, minx, minz, maxx, maxz);
|
||||
|
||||
//send real block information for any remaining elements
|
||||
for(int i = 0; i < visualization.elements.size(); i++)
|
||||
for (int i = 0; i < visualization.elements.size(); i++)
|
||||
{
|
||||
VisualizationElement element = visualization.elements.get(i);
|
||||
|
||||
//check player still in world where visualization exists
|
||||
if(i == 0)
|
||||
if (i == 0)
|
||||
{
|
||||
if(!player.getWorld().equals(element.location.getWorld())) return;
|
||||
if (!player.getWorld().equals(element.location.getWorld())) return;
|
||||
}
|
||||
|
||||
player.sendBlockChange(element.location, element.realBlock);
|
||||
|
|
@ -99,7 +99,7 @@ public class Visualization
|
|||
public static Visualization FromClaim(Claim claim, int height, VisualizationType visualizationType, Location locality)
|
||||
{
|
||||
//visualize only top level claims
|
||||
if(claim.parent != null)
|
||||
if (claim.parent != null)
|
||||
{
|
||||
return FromClaim(claim.parent, height, visualizationType, locality);
|
||||
}
|
||||
|
|
@ -107,15 +107,15 @@ public class Visualization
|
|||
Visualization visualization = new Visualization();
|
||||
|
||||
//add subdivisions first
|
||||
for(int i = 0; i < claim.children.size(); i++)
|
||||
for (int i = 0; i < claim.children.size(); i++)
|
||||
{
|
||||
Claim child = claim.children.get(i);
|
||||
if(!child.inDataStore) continue;
|
||||
if (!child.inDataStore) continue;
|
||||
visualization.addClaimElements(child, height, VisualizationType.Subdivision, locality);
|
||||
}
|
||||
|
||||
//special visualization for administrative land claims
|
||||
if(claim.isAdminClaim() && visualizationType == VisualizationType.Claim)
|
||||
if (claim.isAdminClaim() && visualizationType == VisualizationType.Claim)
|
||||
{
|
||||
visualizationType = VisualizationType.AdminClaim;
|
||||
}
|
||||
|
|
@ -147,31 +147,23 @@ public class Visualization
|
|||
|
||||
ArrayList<VisualizationElement> newElements = new ArrayList<VisualizationElement>();
|
||||
|
||||
if(visualizationType == VisualizationType.Claim)
|
||||
if (visualizationType == VisualizationType.Claim)
|
||||
{
|
||||
cornerBlockData = Material.GLOWSTONE.createBlockData();
|
||||
accentBlockData = Material.GOLD_BLOCK.createBlockData();
|
||||
}
|
||||
|
||||
else if(visualizationType == VisualizationType.AdminClaim)
|
||||
} else if (visualizationType == VisualizationType.AdminClaim)
|
||||
{
|
||||
cornerBlockData = Material.GLOWSTONE.createBlockData();
|
||||
accentBlockData = Material.PUMPKIN.createBlockData();
|
||||
}
|
||||
|
||||
else if(visualizationType == VisualizationType.Subdivision)
|
||||
} else if (visualizationType == VisualizationType.Subdivision)
|
||||
{
|
||||
cornerBlockData = Material.IRON_BLOCK.createBlockData();
|
||||
accentBlockData = Material.WHITE_WOOL.createBlockData();
|
||||
}
|
||||
|
||||
else if(visualizationType == VisualizationType.RestoreNature)
|
||||
} else if (visualizationType == VisualizationType.RestoreNature)
|
||||
{
|
||||
cornerBlockData = Material.DIAMOND_BLOCK.createBlockData();
|
||||
accentBlockData = Material.DIAMOND_BLOCK.createBlockData();
|
||||
}
|
||||
|
||||
else
|
||||
} else
|
||||
{
|
||||
cornerBlockData = Material.REDSTONE_ORE.createBlockData();
|
||||
((Lightable) cornerBlockData).setLit(true);
|
||||
|
|
@ -192,18 +184,18 @@ public class Visualization
|
|||
//top line
|
||||
newElements.add(new VisualizationElement(new Location(world, smallx, 0, bigz), cornerBlockData, Material.AIR.createBlockData()));
|
||||
newElements.add(new VisualizationElement(new Location(world, smallx + 1, 0, bigz), accentBlockData, Material.AIR.createBlockData()));
|
||||
for(int x = smallx + STEP; x < bigx - STEP / 2; x += STEP)
|
||||
for (int x = smallx + STEP; x < bigx - STEP / 2; x += STEP)
|
||||
{
|
||||
if(x > minx && x < maxx)
|
||||
if (x > minx && x < maxx)
|
||||
newElements.add(new VisualizationElement(new Location(world, x, 0, bigz), accentBlockData, Material.AIR.createBlockData()));
|
||||
}
|
||||
newElements.add(new VisualizationElement(new Location(world, bigx - 1, 0, bigz), accentBlockData, Material.AIR.createBlockData()));
|
||||
|
||||
//bottom line
|
||||
newElements.add(new VisualizationElement(new Location(world, smallx + 1, 0, smallz), accentBlockData, Material.AIR.createBlockData()));
|
||||
for(int x = smallx + STEP; x < bigx - STEP / 2; x += STEP)
|
||||
for (int x = smallx + STEP; x < bigx - STEP / 2; x += STEP)
|
||||
{
|
||||
if(x > minx && x < maxx)
|
||||
if (x > minx && x < maxx)
|
||||
newElements.add(new VisualizationElement(new Location(world, x, 0, smallz), accentBlockData, Material.AIR.createBlockData()));
|
||||
}
|
||||
newElements.add(new VisualizationElement(new Location(world, bigx - 1, 0, smallz), accentBlockData, Material.AIR.createBlockData()));
|
||||
|
|
@ -211,9 +203,9 @@ public class Visualization
|
|||
//left line
|
||||
newElements.add(new VisualizationElement(new Location(world, smallx, 0, smallz), cornerBlockData, Material.AIR.createBlockData()));
|
||||
newElements.add(new VisualizationElement(new Location(world, smallx, 0, smallz + 1), accentBlockData, Material.AIR.createBlockData()));
|
||||
for(int z = smallz + STEP; z < bigz - STEP / 2; z += STEP)
|
||||
for (int z = smallz + STEP; z < bigz - STEP / 2; z += STEP)
|
||||
{
|
||||
if(z > minz && z < maxz)
|
||||
if (z > minz && z < maxz)
|
||||
newElements.add(new VisualizationElement(new Location(world, smallx, 0, z), accentBlockData, Material.AIR.createBlockData()));
|
||||
}
|
||||
newElements.add(new VisualizationElement(new Location(world, smallx, 0, bigz - 1), accentBlockData, Material.AIR.createBlockData()));
|
||||
|
|
@ -221,9 +213,9 @@ public class Visualization
|
|||
//right line
|
||||
newElements.add(new VisualizationElement(new Location(world, bigx, 0, smallz), cornerBlockData, Material.AIR.createBlockData()));
|
||||
newElements.add(new VisualizationElement(new Location(world, bigx, 0, smallz + 1), accentBlockData, Material.AIR.createBlockData()));
|
||||
for(int z = smallz + STEP; z < bigz - STEP / 2; z += STEP)
|
||||
for (int z = smallz + STEP; z < bigz - STEP / 2; z += STEP)
|
||||
{
|
||||
if(z > minz && z < maxz)
|
||||
if (z > minz && z < maxz)
|
||||
newElements.add(new VisualizationElement(new Location(world, bigx, 0, z), accentBlockData, Material.AIR.createBlockData()));
|
||||
}
|
||||
newElements.add(new VisualizationElement(new Location(world, bigx, 0, bigz - 1), accentBlockData, Material.AIR.createBlockData()));
|
||||
|
|
@ -233,17 +225,17 @@ public class Visualization
|
|||
this.removeElementsOutOfRange(newElements, minx, minz, maxx, maxz);
|
||||
|
||||
//remove any elements outside the claim
|
||||
for(int i = 0; i < newElements.size(); i++)
|
||||
for (int i = 0; i < newElements.size(); i++)
|
||||
{
|
||||
VisualizationElement element = newElements.get(i);
|
||||
if(!claim.contains(element.location, true, false))
|
||||
if (!claim.contains(element.location, true, false))
|
||||
{
|
||||
newElements.remove(i--);
|
||||
}
|
||||
}
|
||||
|
||||
//set Y values and real block information for any remaining visualization blocks
|
||||
for(VisualizationElement element : newElements)
|
||||
for (VisualizationElement element : newElements)
|
||||
{
|
||||
Location tempLocation = element.location;
|
||||
element.location = getVisibleLocation(tempLocation.getWorld(), tempLocation.getBlockX(), height, tempLocation.getBlockZ(), waterIsTransparent);
|
||||
|
|
@ -257,10 +249,10 @@ public class Visualization
|
|||
//removes any elements which are out of visualization range
|
||||
private void removeElementsOutOfRange(ArrayList<VisualizationElement> elements, int minx, int minz, int maxx, int maxz)
|
||||
{
|
||||
for(int i = 0; i < elements.size(); i++)
|
||||
for (int i = 0; i < elements.size(); i++)
|
||||
{
|
||||
Location location = elements.get(i).location;
|
||||
if(location.getX() < minx || location.getX() > maxx || location.getZ() < minz || location.getZ() > maxz)
|
||||
if (location.getX() < minx || location.getX() > maxx || location.getZ() < minz || location.getZ() > maxz)
|
||||
{
|
||||
elements.remove(i--);
|
||||
}
|
||||
|
|
@ -273,7 +265,7 @@ public class Visualization
|
|||
Block block = world.getBlockAt(x, y, z);
|
||||
BlockFace direction = (isTransparent(block, waterIsTransparent)) ? BlockFace.DOWN : BlockFace.UP;
|
||||
|
||||
while( block.getY() >= 1 &&
|
||||
while (block.getY() >= 1 &&
|
||||
block.getY() < world.getMaxHeight() - 1 &&
|
||||
(!isTransparent(block.getRelative(BlockFace.UP), waterIsTransparent) || isTransparent(block, waterIsTransparent)))
|
||||
{
|
||||
|
|
@ -325,7 +317,7 @@ public class Visualization
|
|||
{
|
||||
Visualization visualization = new Visualization();
|
||||
|
||||
for(Claim claim : claims)
|
||||
for (Claim claim : claims)
|
||||
{
|
||||
visualization.addClaimElements(claim, height, type, locality);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
|
@ -39,12 +39,12 @@ class VisualizationApplicationTask implements Runnable
|
|||
public void run()
|
||||
{
|
||||
//for each element (=block) of the visualization
|
||||
for(int i = 0; i < visualization.elements.size(); i++)
|
||||
for (int i = 0; i < visualization.elements.size(); i++)
|
||||
{
|
||||
VisualizationElement element = visualization.elements.get(i);
|
||||
|
||||
//send the player a fake block change event
|
||||
if(!element.location.getChunk().isLoaded()) continue; //cheap distance check
|
||||
if (!element.location.getChunk().isLoaded()) continue; //cheap distance check
|
||||
player.sendBlockChange(element.location, element.visualizedBlock);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@
|
|||
*/
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
//represents a "fake" block sent to a player as part of a visualization
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.events.VisualizationEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
|
|
@ -42,7 +42,7 @@ class VisualizationReversionTask implements Runnable
|
|||
public void run()
|
||||
{
|
||||
//don't do anything if the player's current visualization is different from the one scheduled to revert
|
||||
if(playerData.currentVisualization != visualization) return;
|
||||
if (playerData.currentVisualization != visualization) return;
|
||||
|
||||
// alert plugins of a visualization
|
||||
Bukkit.getPluginManager().callEvent(new VisualizationEvent(player, Collections.<Claim>emptySet()));
|
||||
|
|
|
|||
|
|
@ -20,14 +20,14 @@ public class WelcomeTask implements Runnable
|
|||
public void run()
|
||||
{
|
||||
//abort if player has logged out since this task was scheduled
|
||||
if(!this.player.isOnline()) return;
|
||||
if (!this.player.isOnline()) return;
|
||||
|
||||
//offer advice and a helpful link
|
||||
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.AvoidGriefClaimLand);
|
||||
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.SurvivalBasicsVideo2, DataStore.SURVIVAL_VIDEO_URL);
|
||||
|
||||
//give the player a reference book for later
|
||||
if(GriefPrevention.instance.config_claims_supplyPlayerManual)
|
||||
if (GriefPrevention.instance.config_claims_supplyPlayerManual)
|
||||
{
|
||||
ItemFactory factory = Bukkit.getItemFactory();
|
||||
BookMeta meta = (BookMeta) factory.getItemMeta(Material.WRITTEN_BOOK);
|
||||
|
|
@ -46,7 +46,7 @@ public class WelcomeTask implements Runnable
|
|||
String infoToolName = GriefPrevention.instance.config_claims_investigationTool.name().replace('_', ' ').toLowerCase();
|
||||
String configClaimTools = datastore.getMessage(Messages.BookTools, editToolName, infoToolName);
|
||||
page1.append(configClaimTools);
|
||||
if(GriefPrevention.instance.config_claims_automaticClaimsForNewPlayersRadius < 0)
|
||||
if (GriefPrevention.instance.config_claims_automaticClaimsForNewPlayersRadius < 0)
|
||||
{
|
||||
page1.append(datastore.getMessage(Messages.BookDisabledChestClaims));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,19 +10,19 @@ class WordFinder
|
|||
|
||||
WordFinder(List<String> wordsToFind)
|
||||
{
|
||||
if(wordsToFind.size() == 0) return;
|
||||
if (wordsToFind.size() == 0) return;
|
||||
|
||||
StringBuilder patternBuilder = new StringBuilder();
|
||||
for(String word : wordsToFind)
|
||||
for (String word : wordsToFind)
|
||||
{
|
||||
if(!word.isEmpty() && !word.trim().isEmpty())
|
||||
if (!word.isEmpty() && !word.trim().isEmpty())
|
||||
{
|
||||
patternBuilder.append("|(([^\\w]|^)" + Pattern.quote(word) + "([^\\w]|$))");
|
||||
}
|
||||
}
|
||||
|
||||
String patternString = patternBuilder.toString();
|
||||
if(patternString.length() > 1)
|
||||
if (patternString.length() > 1)
|
||||
{
|
||||
//trim extraneous leading pipe (|)
|
||||
patternString = patternString.substring(1);
|
||||
|
|
@ -33,7 +33,7 @@ class WordFinder
|
|||
|
||||
boolean hasMatch(String input)
|
||||
{
|
||||
if(this.pattern == null) return false;
|
||||
if (this.pattern == null) return false;
|
||||
|
||||
Matcher matcher = this.pattern.matcher(input);
|
||||
return matcher.find();
|
||||
|
|
|
|||
|
|
@ -1,19 +1,18 @@
|
|||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.bukkit.BukkitPlayer;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.internal.permission.RegionPermissionModel;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
class WorldGuardWrapper
|
||||
{
|
||||
|
|
@ -21,7 +20,7 @@ class WorldGuardWrapper
|
|||
|
||||
public WorldGuardWrapper() throws ClassNotFoundException
|
||||
{
|
||||
this.worldGuard = (WorldGuardPlugin)GriefPrevention.instance.getServer().getPluginManager().getPlugin("WorldGuard");
|
||||
this.worldGuard = (WorldGuardPlugin) GriefPrevention.instance.getServer().getPluginManager().getPlugin("WorldGuard");
|
||||
}
|
||||
|
||||
public boolean canBuild(Location lesserCorner, Location greaterCorner, Player creatingPlayer)
|
||||
|
|
@ -31,11 +30,11 @@ class WorldGuardWrapper
|
|||
BukkitPlayer localPlayer = new BukkitPlayer(this.worldGuard, creatingPlayer);
|
||||
World world = WorldGuard.getInstance().getPlatform().getMatcher().getWorldByName(lesserCorner.getWorld().getName());
|
||||
|
||||
if(new RegionPermissionModel(localPlayer).mayIgnoreRegionProtection(world)) return true;
|
||||
if (new RegionPermissionModel(localPlayer).mayIgnoreRegionProtection(world)) return true;
|
||||
|
||||
RegionManager manager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(world);
|
||||
|
||||
if(manager != null)
|
||||
if (manager != null)
|
||||
{
|
||||
ProtectedCuboidRegion tempRegion = new ProtectedCuboidRegion(
|
||||
"GP_TEMP",
|
||||
|
|
@ -43,8 +42,10 @@ class WorldGuardWrapper
|
|||
BlockVector3.at(greaterCorner.getX(), world.getMaxY(), greaterCorner.getZ()));
|
||||
|
||||
ApplicableRegionSet overlaps = manager.getApplicableRegions(tempRegion);
|
||||
for (ProtectedRegion r : overlaps.getRegions()) {
|
||||
if (!manager.getApplicableRegions(r).testState(localPlayer, Flags.BUILD)) {
|
||||
for (ProtectedRegion r : overlaps.getRegions())
|
||||
{
|
||||
if (!manager.getApplicableRegions(r).testState(localPlayer, Flags.BUILD))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,11 +14,15 @@ public class AccrueClaimBlocksEvent extends Event
|
|||
{
|
||||
// Custom Event Requirements
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
public static HandlerList getHandlerList() {
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
|
|
@ -30,7 +34,6 @@ public class AccrueClaimBlocksEvent extends Event
|
|||
/**
|
||||
* @param player Player receiving accruals
|
||||
* @param blocksToAccrue Blocks to accrue
|
||||
*
|
||||
* @deprecated Use {@link #AccrueClaimBlocksEvent(Player, int, boolean)} instead
|
||||
*/
|
||||
public AccrueClaimBlocksEvent(Player player, int blocksToAccrue)
|
||||
|
|
@ -67,7 +70,8 @@ public class AccrueClaimBlocksEvent extends Event
|
|||
/**
|
||||
* @return whether the player was detected as idle (used for idle accrual percentage)
|
||||
*/
|
||||
public boolean isIdle() {
|
||||
public boolean isIdle()
|
||||
{
|
||||
return this.isIdle;
|
||||
}
|
||||
|
||||
|
|
@ -78,6 +82,7 @@ public class AccrueClaimBlocksEvent extends Event
|
|||
|
||||
/**
|
||||
* Modify the amount of claim blocks to deliver to the player for this 10 minute interval
|
||||
*
|
||||
* @param blocksToAccrue blocks to deliver
|
||||
*/
|
||||
public void setBlocksToAccrue(int blocksToAccrue)
|
||||
|
|
@ -87,6 +92,7 @@ public class AccrueClaimBlocksEvent extends Event
|
|||
|
||||
/**
|
||||
* Similar to setBlocksToAccrue(int), but automatically converting from a per-hour rate value to a 10-minute rate value
|
||||
*
|
||||
* @param blocksToAccruePerHour the per-hour rate of blocks to deliver
|
||||
*/
|
||||
|
||||
|
|
|
|||
|
|
@ -13,11 +13,13 @@ import org.bukkit.event.HandlerList;
|
|||
* Created by Narimm on 5/08/2018.
|
||||
*/
|
||||
|
||||
public class ClaimCreatedEvent extends Event implements Cancellable {
|
||||
public class ClaimCreatedEvent extends Event implements Cancellable
|
||||
{
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
|
|
@ -27,23 +29,27 @@ public class ClaimCreatedEvent extends Event implements Cancellable {
|
|||
|
||||
private boolean cancelled = false;
|
||||
|
||||
public ClaimCreatedEvent(Claim claim, CommandSender creator) {
|
||||
public ClaimCreatedEvent(Claim claim, CommandSender creator)
|
||||
{
|
||||
this.claim = claim;
|
||||
this.creator = creator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
public boolean isCancelled()
|
||||
{
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean b) {
|
||||
public void setCancelled(boolean b)
|
||||
{
|
||||
this.cancelled = b;
|
||||
}
|
||||
|
||||
|
|
@ -52,7 +58,8 @@ public class ClaimCreatedEvent extends Event implements Cancellable {
|
|||
*
|
||||
* @return Claim
|
||||
*/
|
||||
public Claim getClaim() {
|
||||
public Claim getClaim()
|
||||
{
|
||||
return claim;
|
||||
}
|
||||
|
||||
|
|
@ -61,7 +68,8 @@ public class ClaimCreatedEvent extends Event implements Cancellable {
|
|||
*
|
||||
* @return the CommandSender
|
||||
*/
|
||||
public CommandSender getCreator() {
|
||||
public CommandSender getCreator()
|
||||
{
|
||||
return creator;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package me.ryanhamshire.GriefPrevention.events;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.Claim;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
|
|
@ -10,20 +9,22 @@ import org.bukkit.event.HandlerList;
|
|||
* not called when a claim is resized.
|
||||
*
|
||||
* @author Tux2
|
||||
*
|
||||
*/
|
||||
public class ClaimDeletedEvent extends Event{
|
||||
public class ClaimDeletedEvent extends Event
|
||||
{
|
||||
|
||||
// Custom Event Requirements
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
private Claim claim;
|
||||
|
||||
public ClaimDeletedEvent(Claim claim) {
|
||||
public ClaimDeletedEvent(Claim claim)
|
||||
{
|
||||
this.claim = claim;
|
||||
}
|
||||
|
||||
|
|
@ -32,12 +33,14 @@ public class ClaimDeletedEvent extends Event{
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
public Claim getClaim() {
|
||||
public Claim getClaim()
|
||||
{
|
||||
return claim;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
package me.ryanhamshire.GriefPrevention.events;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.Claim;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
|
|
|||
|
|
@ -11,24 +11,28 @@ import org.bukkit.event.HandlerList;
|
|||
* a claim has changed. The CommandSender can be null in the event that the modification is called by the plugin itself.
|
||||
* Created by Narimm on 5/08/2018.
|
||||
*/
|
||||
public class ClaimModifiedEvent extends Event {
|
||||
public class ClaimModifiedEvent extends Event
|
||||
{
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
private final Claim claim;
|
||||
private CommandSender modifier;
|
||||
|
||||
public ClaimModifiedEvent(Claim claim, CommandSender modifier) {
|
||||
public ClaimModifiedEvent(Claim claim, CommandSender modifier)
|
||||
{
|
||||
this.claim = claim;
|
||||
this.modifier = modifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
|
|
@ -37,7 +41,8 @@ public class ClaimModifiedEvent extends Event {
|
|||
*
|
||||
* @return the claim
|
||||
*/
|
||||
public Claim getClaim() {
|
||||
public Claim getClaim()
|
||||
{
|
||||
return claim;
|
||||
}
|
||||
|
||||
|
|
@ -46,7 +51,8 @@ public class ClaimModifiedEvent extends Event {
|
|||
*
|
||||
* @return the CommandSender or null
|
||||
*/
|
||||
public CommandSender getModifier() {
|
||||
public CommandSender getModifier()
|
||||
{
|
||||
return modifier;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package me.ryanhamshire.GriefPrevention.events;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.Claim;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package me.ryanhamshire.GriefPrevention.events;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.Claim;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package me.ryanhamshire.GriefPrevention.events;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.Claim;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
|
|
|
|||
|
|
@ -1,23 +1,22 @@
|
|||
package me.ryanhamshire.GriefPrevention.events;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.Claim;
|
||||
import me.ryanhamshire.GriefPrevention.ClaimPermission;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.Claim;
|
||||
import me.ryanhamshire.GriefPrevention.ClaimPermission;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This event is thrown when the trust is changed in one or more claims
|
||||
*
|
||||
* @author roinujnosde
|
||||
*
|
||||
*/
|
||||
public class TrustChangedEvent extends Event implements Cancellable {
|
||||
public class TrustChangedEvent extends Event implements Cancellable
|
||||
{
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
|
|
@ -29,7 +28,8 @@ public class TrustChangedEvent extends Event implements Cancellable {
|
|||
private boolean cancelled;
|
||||
|
||||
public TrustChangedEvent(Player changer, List<Claim> claims, ClaimPermission claimPermission, boolean given,
|
||||
String identifier) {
|
||||
String identifier)
|
||||
{
|
||||
super();
|
||||
this.changer = changer;
|
||||
this.claims = claims;
|
||||
|
|
@ -38,7 +38,8 @@ public class TrustChangedEvent extends Event implements Cancellable {
|
|||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public TrustChangedEvent(Player changer, Claim claim, ClaimPermission claimPermission, boolean given, String identifier) {
|
||||
public TrustChangedEvent(Player changer, Claim claim, ClaimPermission claimPermission, boolean given, String identifier)
|
||||
{
|
||||
this.changer = changer;
|
||||
claims = new ArrayList<>();
|
||||
claims.add(claim);
|
||||
|
|
@ -48,7 +49,8 @@ public class TrustChangedEvent extends Event implements Cancellable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
|
|
@ -57,7 +59,8 @@ public class TrustChangedEvent extends Event implements Cancellable {
|
|||
*
|
||||
* @return the changer
|
||||
*/
|
||||
public Player getChanger() {
|
||||
public Player getChanger()
|
||||
{
|
||||
return changer;
|
||||
}
|
||||
|
||||
|
|
@ -66,7 +69,8 @@ public class TrustChangedEvent extends Event implements Cancellable {
|
|||
*
|
||||
* @return the changed claims
|
||||
*/
|
||||
public List<Claim> getClaims() {
|
||||
public List<Claim> getClaims()
|
||||
{
|
||||
return claims;
|
||||
}
|
||||
|
||||
|
|
@ -75,7 +79,8 @@ public class TrustChangedEvent extends Event implements Cancellable {
|
|||
*
|
||||
* @return the claim permission
|
||||
*/
|
||||
public ClaimPermission getClaimPermission() {
|
||||
public ClaimPermission getClaimPermission()
|
||||
{
|
||||
return claimPermission;
|
||||
}
|
||||
|
||||
|
|
@ -84,7 +89,8 @@ public class TrustChangedEvent extends Event implements Cancellable {
|
|||
*
|
||||
* @return true if given, false if taken
|
||||
*/
|
||||
public boolean isGiven() {
|
||||
public boolean isGiven()
|
||||
{
|
||||
return given;
|
||||
}
|
||||
|
||||
|
|
@ -94,17 +100,20 @@ public class TrustChangedEvent extends Event implements Cancellable {
|
|||
*
|
||||
* @return the identifier
|
||||
*/
|
||||
public String getIdentifier() {
|
||||
public String getIdentifier()
|
||||
{
|
||||
return identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
public boolean isCancelled()
|
||||
{
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
public void setCancelled(boolean cancelled)
|
||||
{
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ import java.util.Collections;
|
|||
/**
|
||||
* Called when GriefPrevention is sending claim visuals to a player
|
||||
*/
|
||||
public class VisualizationEvent extends PlayerEvent {
|
||||
public class VisualizationEvent extends PlayerEvent
|
||||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private final Collection<Claim> claims;
|
||||
private final boolean showSubdivides;
|
||||
|
|
@ -22,7 +23,8 @@ public class VisualizationEvent extends PlayerEvent {
|
|||
* @param player Player receiving visuals
|
||||
* @param claim The claim being visualized (with subdivides), or null if visuals being removed
|
||||
*/
|
||||
public VisualizationEvent(Player player, Claim claim) {
|
||||
public VisualizationEvent(Player player, Claim claim)
|
||||
{
|
||||
super(player);
|
||||
this.claims = Collections.singleton(claim);
|
||||
this.showSubdivides = true;
|
||||
|
|
@ -34,7 +36,8 @@ public class VisualizationEvent extends PlayerEvent {
|
|||
* @param player Player receiving visuals
|
||||
* @param claims Claims being visualized (without subdivides)
|
||||
*/
|
||||
public VisualizationEvent(Player player, Collection<Claim> claims) {
|
||||
public VisualizationEvent(Player player, Collection<Claim> claims)
|
||||
{
|
||||
super(player);
|
||||
this.claims = claims;
|
||||
this.showSubdivides = false;
|
||||
|
|
@ -45,7 +48,8 @@ public class VisualizationEvent extends PlayerEvent {
|
|||
*
|
||||
* @return Claims being visualized
|
||||
*/
|
||||
public Collection<Claim> getClaims() {
|
||||
public Collection<Claim> getClaims()
|
||||
{
|
||||
return claims;
|
||||
}
|
||||
|
||||
|
|
@ -54,16 +58,19 @@ public class VisualizationEvent extends PlayerEvent {
|
|||
*
|
||||
* @return True if subdivide claims are being shown
|
||||
*/
|
||||
public boolean showSubdivides() {
|
||||
public boolean showSubdivides()
|
||||
{
|
||||
return showSubdivides;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
*
|
||||
* @author Ryan
|
||||
*/
|
||||
/**
|
||||
* @author Ryan
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import java.util.concurrent.Callable;
|
|||
public class MetricsHandler
|
||||
{
|
||||
private Metrics metrics;
|
||||
|
||||
public MetricsHandler(GriefPrevention plugin, String dataMode)
|
||||
{
|
||||
metrics = new Metrics(plugin);
|
||||
|
|
@ -23,7 +24,7 @@ public class MetricsHandler
|
|||
addSimplePie("custom_build", plugin.getDescription().getVersion().equals("15.2.2"));
|
||||
addSimplePie("bukkit_impl", plugin.getServer().getVersion().split("-")[1]);
|
||||
}
|
||||
catch (Throwable ignored){}
|
||||
catch (Throwable ignored) {}
|
||||
|
||||
//enums and etc. would be amazing.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user