reformat code

- Lots of tabs to spaces going on
- That's a lot of changes!

#63
This commit is contained in:
RoboMWM 2020-06-08 21:57:55 -07:00
parent bc05440617
commit 40f554d386
63 changed files with 12745 additions and 12750 deletions

View File

@ -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
{

View File

@ -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;
}
}
@ -217,7 +220,8 @@ public class BlockEventHandler implements Listener
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;
}
@ -660,7 +664,8 @@ public class BlockEventHandler implements Listener
//don't track in worlds where claims are not enabled
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);
// }
@ -757,9 +762,9 @@ public class BlockEventHandler implements Listener
}
//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)
{

View File

@ -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;

View File

@ -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
@ -133,7 +144,8 @@ public class Claim
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++)
{
@ -167,7 +179,8 @@ public class Claim
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++)
{
@ -366,7 +379,8 @@ public class Claim
}
//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;
@ -455,12 +469,10 @@ public class Claim
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;
}
@ -483,7 +495,8 @@ public class Claim
}
//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;
@ -523,7 +536,8 @@ public class Claim
}
//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())
@ -650,12 +664,10 @@ public class Claim
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());
}
@ -753,8 +765,10 @@ public class Claim
//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(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;
@ -822,7 +836,8 @@ public class Claim
}
}
if(totalEntities >= maxEntities) return GriefPrevention.instance.dataStore.getMessage(Messages.TooManyEntitiesInClaim);
if (totalEntities >= maxEntities)
return GriefPrevention.instance.dataStore.getMessage(Messages.TooManyEntitiesInClaim);
return null;
}
@ -833,7 +848,8 @@ public class Claim
//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;
@ -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;
}
@ -901,8 +918,7 @@ public class Claim
if (block.getType() == Material.CHEST && !creativeMode)
{
score += 10;
}
else
} else
{
score += .5;
}
@ -917,12 +933,10 @@ public class Claim
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;
}

View File

@ -18,14 +18,13 @@
package me.ryanhamshire.GriefPrevention;
import java.util.Calendar;
import java.util.Date;
import java.util.Vector;
import me.ryanhamshire.GriefPrevention.events.ClaimExpirationEvent;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import me.ryanhamshire.GriefPrevention.events.ClaimExpirationEvent;
import java.util.Calendar;
import java.util.Date;
import java.util.Vector;
class CleanupUnusedClaimTask implements Runnable
{
@ -106,9 +105,7 @@ class CleanupUnusedClaimTask implements Runnable
}
}
}
}
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;

View File

@ -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");
@ -62,6 +61,7 @@ class CustomLogger
}
private static final Pattern inlineFormatterPattern = Pattern.compile("§.");
void AddEntry(String entry, CustomLogEntryTypes entryType)
{
//if disabled, do nothing
@ -81,11 +81,15 @@ 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.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.MutedChat && !GriefPrevention.instance.config_logs_mutedChatEnabled)
return false;
return true;
}

View File

@ -95,6 +95,7 @@ public abstract class DataStore
//reading and writing the schema version to the data store
abstract int getSchemaVersionFromStorage();
abstract void updateSchemaVersionInStorage(int versionToSet);
//current version of the schema of data in secondary storage
@ -116,8 +117,7 @@ public abstract class DataStore
if (this.currentSchemaVersion >= 0)
{
return this.currentSchemaVersion;
}
else
} else
{
this.currentSchemaVersion = this.getSchemaVersionFromStorage();
return this.currentSchemaVersion;
@ -388,6 +388,7 @@ public abstract class DataStore
super(message);
}
}
synchronized public void changeClaimOwner(Claim claim, UUID newOwnerID)
{
//if it's a subdivision, throw an exception
@ -467,7 +468,8 @@ public abstract class DataStore
}
}
private void addToChunkClaimMap(Claim claim){
private void addToChunkClaimMap(Claim claim)
{
ArrayList<Long> chunkHashes = claim.getChunkHashes();
for (Long chunkHash : chunkHashes)
{
@ -481,7 +483,8 @@ public abstract class DataStore
}
}
private void removeFromChunkClaimMap(Claim claim) {
private void removeFromChunkClaimMap(Claim claim)
{
ArrayList<Long> chunkHashes = claim.getChunkHashes();
for (Long chunkHash : chunkHashes)
{
@ -497,7 +500,8 @@ public abstract class DataStore
break;
}
}
if (claimsInChunk.isEmpty()) { // if nothing's left, remove this chunk's cache
if (claimsInChunk.isEmpty())
{ // if nothing's left, remove this chunk's cache
this.chunksToClaimsMap.remove(chunkHash);
}
}
@ -506,6 +510,7 @@ public abstract class DataStore
//turns a location into a string, useful in data storage
private String locationStringDelimiter = ";";
String locationToString(Location location)
{
StringBuilder stringBuilder = new StringBuilder(location.getWorld().getName());
@ -568,7 +573,8 @@ public abstract class DataStore
this.writeClaimToStorage(claim);
}
private void assignClaimID(Claim claim) {
private void assignClaimID(Claim claim)
{
//ensure a unique identifier for the claim which will be used to name the file on disk
if (claim.id == null || claim.id == -1)
{
@ -716,7 +722,8 @@ public abstract class DataStore
synchronized public Claim getClaimAt(Location location, boolean ignoreHeight, Claim cachedClaim)
{
//check cachedClaim guess first. if it's in the datastore and the location is inside it, we're done
if(cachedClaim != null && cachedClaim.inDataStore && cachedClaim.contains(location, ignoreHeight, true)) return cachedClaim;
if (cachedClaim != null && cachedClaim.inDataStore && cachedClaim.contains(location, ignoreHeight, true))
return cachedClaim;
//find a top level claim
Long chunkID = getChunkHash(location);
@ -732,7 +739,8 @@ public abstract class DataStore
for (int j = 0; j < claim.children.size(); j++)
{
Claim subdivision = claim.children.get(j);
if(subdivision.inDataStore && subdivision.contains(location, ignoreHeight, false)) return subdivision;
if (subdivision.inDataStore && subdivision.contains(location, ignoreHeight, false))
return subdivision;
}
return claim;
@ -768,8 +776,7 @@ public abstract class DataStore
if (chunkClaims != null)
{
return Collections.unmodifiableCollection(chunkClaims);
}
else
} else
{
return Collections.unmodifiableCollection(new ArrayList<Claim>());
}
@ -794,6 +801,7 @@ public abstract class DataStore
{
return createClaim(world, x1, x2, y1, y2, z1, z2, ownerID, parent, id, creatingPlayer, false);
}
//creates a claim.
//if the new claim would overlap an existing claim, returns a failure along with a reference to the existing claim
//if the new claim would overlap a WorldGuard region where the player doesn't have permission to build, returns a failure with NULL for claim
@ -819,8 +827,7 @@ public abstract class DataStore
{
smallx = x1;
bigx = x2;
}
else
} else
{
smallx = x2;
bigx = x1;
@ -830,8 +837,7 @@ public abstract class DataStore
{
smally = y1;
bigy = y2;
}
else
} else
{
smally = y2;
bigy = y1;
@ -841,8 +847,7 @@ public abstract class DataStore
{
smallz = z1;
bigz = z2;
}
else
} else
{
smallz = z2;
bigz = z1;
@ -884,8 +889,7 @@ public abstract class DataStore
if (newClaim.parent != null)
{
claimsToCheck = newClaim.parent.children;
}
else
} else
{
claimsToCheck = this.claims;
}
@ -914,7 +918,8 @@ public abstract class DataStore
return result;
}
}
if (dryRun) {
if (dryRun)
{
// since this is a dry run, just return the unsaved claim as is.
result.succeeded = true;
result.claim = newClaim;
@ -923,7 +928,8 @@ public abstract class DataStore
assignClaimID(newClaim); // assign a claim ID before calling event, in case a plugin wants to know the ID.
ClaimCreatedEvent event = new ClaimCreatedEvent(newClaim, creatingPlayer);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
if (event.isCancelled())
{
result.succeeded = false;
result.claim = null;
return result;
@ -1000,7 +1006,8 @@ public abstract class DataStore
//respects the max depth config variable
synchronized public void extendClaim(Claim claim, int newDepth)
{
if(newDepth < GriefPrevention.instance.config_claims_maxDepth) newDepth = GriefPrevention.instance.config_claims_maxDepth;
if (newDepth < GriefPrevention.instance.config_claims_maxDepth)
newDepth = GriefPrevention.instance.config_claims_maxDepth;
if (claim.parent != null) claim = claim.parent;
@ -1051,19 +1058,16 @@ public abstract class DataStore
if (siegeData.attacker.getName().equals(loserName))
{
winnerName = siegeData.defender.getName();
}
else
} else
{
winnerName = siegeData.attacker.getName();
}
}
else if(winnerName != null && loserName == null)
} else if (winnerName != null && loserName == null)
{
if (siegeData.attacker.getName().equals(winnerName))
{
loserName = siegeData.defender.getName();
}
else
} else
{
loserName = siegeData.attacker.getName();
}
@ -1366,8 +1370,7 @@ public abstract class DataStore
if (ownerID == player.getUniqueId())
{
claimBlocksRemaining = playerData.getRemainingClaimBlocks();
}
else
} else
{
PlayerData ownerData = this.getPlayerData(ownerID);
claimBlocksRemaining = ownerData.getRemainingClaimBlocks();
@ -1408,8 +1411,7 @@ public abstract class DataStore
//clean up
playerData.claimResizing = null;
playerData.lastShovelLocation = null;
}
else
} else
{
if (result.claim != null)
{
@ -1419,8 +1421,7 @@ public abstract class DataStore
//show the player the conflicting claim
Visualization visualization = Visualization.FromClaim(result.claim, player.getEyeLocation().getBlockY(), VisualizationType.ErrorClaim, player.getLocation());
Visualization.Apply(player, visualization);
}
else
} else
{
GriefPrevention.sendMessage(player, TextMode.Err, Messages.ResizeFailOverlapRegion);
}
@ -1433,12 +1434,10 @@ public abstract class DataStore
if (player.hasPermission("griefprevention.adminclaims") && player.hasPermission("griefprevention.adjustclaimblocks"))
{
GriefPrevention.sendMessage(player, TextMode.Info, Messages.AdvertiseACandACB);
}
else if(player.hasPermission("griefprevention.adminclaims"))
} else if (player.hasPermission("griefprevention.adminclaims"))
{
GriefPrevention.sendMessage(player, TextMode.Info, Messages.AdvertiseAdminClaims);
}
else if(player.hasPermission("griefprevention.adjustclaimblocks"))
} else if (player.hasPermission("griefprevention.adjustclaimblocks"))
{
GriefPrevention.sendMessage(player, TextMode.Info, Messages.AdvertiseACB);
}

View File

@ -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
@ -228,7 +241,8 @@ public class DatabaseDataStore extends DataStore
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();
@ -289,8 +303,7 @@ public class DatabaseDataStore extends DataStore
{
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;
}
@ -301,8 +314,7 @@ public class DatabaseDataStore extends DataStore
if (ownerName.isEmpty() || ownerName.startsWith("--"))
{
ownerID = null; //administrative land claim or subdivision
}
else if(this.getSchemaVersion() < 1)
} else if (this.getSchemaVersion() < 1)
{
try
{
@ -313,8 +325,7 @@ public class DatabaseDataStore extends DataStore
GriefPrevention.AddLogEntry("This owner name did not convert to a UUID: " + ownerName + ".");
GriefPrevention.AddLogEntry(" Converted land claim to administrative @ " + lesserBoundaryCorner.toString());
}
}
else
} else
{
try
{
@ -347,13 +358,11 @@ public class DatabaseDataStore extends DataStore
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);
@ -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);
@ -467,7 +477,8 @@ 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();
}
@ -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");
@ -554,7 +566,8 @@ 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();
@ -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);
@ -603,7 +617,8 @@ public class DatabaseDataStore extends DataStore
this.databaseConnection.close();
}
}
catch(SQLException e){};
catch (SQLException e) {}
;
}
this.databaseConnection = null;
@ -633,7 +648,8 @@ 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
@ -661,7 +677,8 @@ 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);
@ -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;
}
}

View File

@ -18,11 +18,11 @@
package me.ryanhamshire.GriefPrevention;
import java.util.Collection;
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

View File

@ -73,9 +73,7 @@ class EntityCleanupTask implements Runnable
{
Boat boat = (Boat) entity;
if (boat.isEmpty()) remove = true;
}
else if(entity instanceof Vehicle)
} else if (entity instanceof Vehicle)
{
Vehicle vehicle = (Vehicle) entity;
@ -106,8 +104,7 @@ class EntityCleanupTask implements Runnable
if (claim != null)
{
cachedClaim = claim;
}
else
} else
{
remove = true;
}

View File

@ -29,6 +29,7 @@ import org.bukkit.World.Environment;
import org.bukkit.block.Block;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Donkey;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Explosive;
@ -38,7 +39,9 @@ import org.bukkit.entity.Horse;
import org.bukkit.entity.Item;
import org.bukkit.entity.LightningStrike;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Llama;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Mule;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Rabbit;
@ -46,9 +49,6 @@ import org.bukkit.entity.Tameable;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.entity.Vehicle;
import org.bukkit.entity.WaterMob;
import org.bukkit.entity.Llama;
import org.bukkit.entity.Donkey;
import org.bukkit.entity.Mule;
import org.bukkit.entity.Wolf;
import org.bukkit.entity.minecart.ExplosiveMinecart;
import org.bukkit.event.EventHandler;
@ -125,7 +125,8 @@ public class EntityEventHandler implements Listener
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onLightningStrike(LightningStrikeEvent event){
public void onLightningStrike(LightningStrikeEvent event)
{
if (event.getCause() == LightningStrikeEvent.Cause.TRIDENT)
event.getLightning().setMetadata("GP_TRIDENT", new FixedMetadataValue(GriefPrevention.instance, event.getLightning().getLocation()));
}
@ -136,18 +137,13 @@ public class EntityEventHandler implements Listener
if (!GriefPrevention.instance.config_endermenMoveBlocks && event.getEntityType() == EntityType.ENDERMAN)
{
event.setCancelled(true);
}
else if(!GriefPrevention.instance.config_silverfishBreakBlocks && event.getEntityType() == EntityType.SILVERFISH)
} else if (!GriefPrevention.instance.config_silverfishBreakBlocks && event.getEntityType() == EntityType.SILVERFISH)
{
event.setCancelled(true);
}
else if(!GriefPrevention.instance.config_rabbitsEatCrops && event.getEntityType() == EntityType.RABBIT)
} else if (!GriefPrevention.instance.config_rabbitsEatCrops && event.getEntityType() == EntityType.RABBIT)
{
event.setCancelled(true);
}
else if(GriefPrevention.instance.config_claims_worldModes.get(event.getBlock().getWorld()) != ClaimsMode.Disabled)
} else if (GriefPrevention.instance.config_claims_worldModes.get(event.getBlock().getWorld()) != ClaimsMode.Disabled)
{
if (event.getEntityType() == EntityType.WITHER)
{
@ -156,9 +152,7 @@ public class EntityEventHandler implements Listener
{
event.setCancelled(true);
}
}
else if (!GriefPrevention.instance.config_claims_ravagersBreakBlocks && event.getEntityType() == EntityType.RAVAGER)
} else if (!GriefPrevention.instance.config_claims_ravagersBreakBlocks && event.getEntityType() == EntityType.RAVAGER)
{
event.setCancelled(true);
}
@ -182,11 +176,14 @@ public class EntityEventHandler implements Listener
}
//Prevent breaking lilypads via collision with a boat. Thanks Jikoo.
else if (event.getEntity() instanceof Vehicle && !event.getEntity().getPassengers().isEmpty()) {
else if (event.getEntity() instanceof Vehicle && !event.getEntity().getPassengers().isEmpty())
{
Entity driver = event.getEntity().getPassengers().get(0);
if (driver instanceof Player) {
if (driver instanceof Player)
{
Block block = event.getBlock();
if (GriefPrevention.instance.allowBreak((Player) driver, block, block.getLocation()) != null) {
if (GriefPrevention.instance.allowBreak((Player) driver, block, block.getLocation()) != null)
{
event.setCancelled(true);
}
}
@ -279,8 +276,7 @@ public class EntityEventHandler implements Listener
if (!GriefPrevention.instance.config_creaturesTrampleCrops)
{
event.setCancelled(true);
}
else
} else
{
Entity rider = event.getEntity().getPassenger();
if (rider != null && rider.getType() == EntityType.PLAYER)
@ -655,7 +651,8 @@ public class EntityEventHandler implements Listener
if (entity instanceof Monster) return true;
EntityType type = entity.getType();
if(type == EntityType.GHAST || type == EntityType.MAGMA_CUBE || type == EntityType.SHULKER || type == EntityType.POLAR_BEAR) return true;
if (type == EntityType.GHAST || type == EntityType.MAGMA_CUBE || type == EntityType.SHULKER || type == EntityType.POLAR_BEAR)
return true;
if (type == EntityType.RABBIT)
{
@ -748,17 +745,18 @@ public class EntityEventHandler implements Listener
if (damageSource.getType() == EntityType.PLAYER)
{
attacker = (Player) damageSource;
}
else if(damageSource instanceof Projectile)
} else if (damageSource instanceof Projectile)
{
arrow = (Projectile) damageSource;
if (arrow.getShooter() instanceof Player)
{
attacker = (Player) arrow.getShooter();
}
}else if(subEvent.getDamager() instanceof Firework) {
} else if (subEvent.getDamager() instanceof Firework)
{
damageSource = subEvent.getDamager();
if(damageSource.hasMetadata("GP_FIREWORK")) {
if (damageSource.hasMetadata("GP_FIREWORK"))
{
List<MetadataValue> data = damageSource.getMetadata("GP_FIREWORK");
if (data != null && data.size() > 0)
{
@ -807,7 +805,8 @@ public class EntityEventHandler implements Listener
if (firework != null && event.getEntityType() == EntityType.PLAYER && !GriefPrevention.instance.pvpRulesApply(attacker.getWorld()))
{
Player defender = (Player) (event.getEntity());
if(attacker != defender) {
if (attacker != defender)
{
event.setCancelled(true);
return;
}
@ -832,14 +831,16 @@ public class EntityEventHandler implements Listener
if (defenderData.pvpImmune)
{
event.setCancelled(true);
if(sendErrorMessagesToPlayers) GriefPrevention.sendMessage(attacker, TextMode.Err, Messages.ThatPlayerPvPImmune);
if (sendErrorMessagesToPlayers)
GriefPrevention.sendMessage(attacker, TextMode.Err, Messages.ThatPlayerPvPImmune);
return;
}
if (attackerData.pvpImmune)
{
event.setCancelled(true);
if(sendErrorMessagesToPlayers) GriefPrevention.sendMessage(attacker, TextMode.Err, Messages.CantFightWhileImmune);
if (sendErrorMessagesToPlayers)
GriefPrevention.sendMessage(attacker, TextMode.Err, Messages.CantFightWhileImmune);
return;
}
}
@ -860,7 +861,8 @@ public class EntityEventHandler implements Listener
if (!pvpEvent.isCancelled())
{
event.setCancelled(true);
if(sendErrorMessagesToPlayers) GriefPrevention.sendMessage(attacker, TextMode.Err, Messages.CantFightWhileImmune);
if (sendErrorMessagesToPlayers)
GriefPrevention.sendMessage(attacker, TextMode.Err, Messages.CantFightWhileImmune);
return;
}
}
@ -876,7 +878,8 @@ public class EntityEventHandler implements Listener
if (!pvpEvent.isCancelled())
{
event.setCancelled(true);
if(sendErrorMessagesToPlayers) GriefPrevention.sendMessage(attacker, TextMode.Err, Messages.PlayerInPvPSafeZone);
if (sendErrorMessagesToPlayers)
GriefPrevention.sendMessage(attacker, TextMode.Err, Messages.PlayerInPvPSafeZone);
return;
}
}
@ -936,7 +939,8 @@ public class EntityEventHandler implements Listener
|| subEvent.getEntityType() == EntityType.ENDER_CRYSTAL)
{
//allow for disabling villager protections in the config
if(subEvent.getEntityType() == EntityType.VILLAGER && !GriefPrevention.instance.config_claims_protectCreatures) return;
if (subEvent.getEntityType() == EntityType.VILLAGER && !GriefPrevention.instance.config_claims_protectCreatures)
return;
//don't protect polar bears, they may be aggressive
if (subEvent.getEntityType() == EntityType.POLAR_BEAR) return;
@ -973,7 +977,8 @@ public class EntityEventHandler implements Listener
if (failureReason != null)
{
event.setCancelled(true);
if(sendErrorMessagesToPlayers) GriefPrevention.sendMessage(attacker, TextMode.Err, failureReason);
if (sendErrorMessagesToPlayers)
GriefPrevention.sendMessage(attacker, TextMode.Err, failureReason);
return;
}
}
@ -1009,7 +1014,8 @@ public class EntityEventHandler implements Listener
String message = GriefPrevention.instance.dataStore.getMessage(Messages.NoDamageClaimedEntity, ownerName);
if (attacker.hasPermission("griefprevention.ignoreclaims"))
message += " " + GriefPrevention.instance.dataStore.getMessage(Messages.IgnoreClaimsAdvertisement);
if(sendErrorMessagesToPlayers) GriefPrevention.sendMessage(attacker, TextMode.Err, message);
if (sendErrorMessagesToPlayers)
GriefPrevention.sendMessage(attacker, TextMode.Err, message);
PreventPvPEvent pvpEvent = new PreventPvPEvent(new Claim(subEvent.getEntity().getLocation(), subEvent.getEntity().getLocation(), null, new ArrayList<String>(), new ArrayList<String>(), new ArrayList<String>(), new ArrayList<String>(), null));
Bukkit.getPluginManager().callEvent(pvpEvent);
if (!pvpEvent.isCancelled())
@ -1022,7 +1028,8 @@ public class EntityEventHandler implements Listener
else if (attackerData.pvpImmune)
{
event.setCancelled(true);
if(sendErrorMessagesToPlayers) GriefPrevention.sendMessage(attacker, TextMode.Err, Messages.CantFightWhileImmune);
if (sendErrorMessagesToPlayers)
GriefPrevention.sendMessage(attacker, TextMode.Err, Messages.CantFightWhileImmune);
return;
}
// disallow players attacking tamed wolves (dogs) unless under attack by said wolf
@ -1110,7 +1117,8 @@ public class EntityEventHandler implements Listener
//kill the arrow to avoid infinite bounce between crowded together animals //RoboMWM: except for tridents
if (arrow != null && arrow.getType() != EntityType.TRIDENT) arrow.remove();
if(damageSource != null && damageSource.getType() == EntityType.FIREWORK && event.getEntity().getType() != EntityType.PLAYER) return;
if (damageSource != null && damageSource.getType() == EntityType.FIREWORK && event.getEntity().getType() != EntityType.PLAYER)
return;
if (sendErrorMessagesToPlayers)
{
@ -1134,8 +1142,10 @@ public class EntityEventHandler implements Listener
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onCrossbowFireWork(EntityShootBowEvent shootEvent) {
if(shootEvent.getEntity() instanceof Player && shootEvent.getProjectile() instanceof Firework) {
public void onCrossbowFireWork(EntityShootBowEvent shootEvent)
{
if (shootEvent.getEntity() instanceof Player && shootEvent.getProjectile() instanceof Firework)
{
shootEvent.getProjectile().setMetadata("GP_FIREWORK", new FixedMetadataValue(GriefPrevention.instance, shootEvent.getEntity()));
}
}
@ -1172,17 +1182,17 @@ public class EntityEventHandler implements Listener
if (damageSource.getType() == EntityType.PLAYER)
{
attacker = (Player) damageSource;
}
else if(damageSource instanceof Projectile)
} else if (damageSource instanceof Projectile)
{
arrow = (Projectile) damageSource;
if (arrow.getShooter() instanceof Player)
{
attacker = (Player) arrow.getShooter();
}
}
else if(damageSource instanceof Firework) {
if(damageSource.hasMetadata("GP_FIREWORK")) {
} else if (damageSource instanceof Firework)
{
if (damageSource.hasMetadata("GP_FIREWORK"))
{
List<MetadataValue> data = damageSource.getMetadata("GP_FIREWORK");
if (data != null && data.size() > 0)
{
@ -1234,17 +1244,17 @@ public class EntityEventHandler implements Listener
if (damageSource.getType() == EntityType.PLAYER)
{
attacker = (Player) damageSource;
}
else if(damageSource instanceof Projectile)
} else if (damageSource instanceof Projectile)
{
Projectile arrow = (Projectile) damageSource;
if (arrow.getShooter() instanceof Player)
{
attacker = (Player) arrow.getShooter();
}
}
else if(damageSource instanceof Firework) {
if(damageSource.hasMetadata("GP_FIREWORK")) {
} else if (damageSource instanceof Firework)
{
if (damageSource.hasMetadata("GP_FIREWORK"))
{
List<MetadataValue> data = damageSource.getMetadata("GP_FIREWORK");
if (data != null && data.size() > 0)
{

View File

@ -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());
@ -61,8 +62,7 @@ class EquipShovelProcessingTask implements Runnable
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);
}

View File

@ -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);
}

View File

@ -206,8 +206,7 @@ public class FlatFileDataStore extends DataStore
if (this.getSchemaVersion() <= 1)
{
this.loadClaimData_Legacy(files);
}
else
} else
{
this.loadClaimData(files);
}
@ -284,8 +283,7 @@ public class FlatFileDataStore extends DataStore
if (ownerName.isEmpty() || ownerName.startsWith("--"))
{
ownerID = null; //administrative land claim or subdivision
}
else if(this.getSchemaVersion() == 0)
} else if (this.getSchemaVersion() == 0)
{
try
{
@ -296,8 +294,7 @@ public class FlatFileDataStore extends DataStore
GriefPrevention.AddLogEntry("Couldn't resolve this name to a UUID: " + ownerName + ".");
GriefPrevention.AddLogEntry(" Converted land claim to administrative @ " + lesserBoundaryCorner.toString());
}
}
else
} else
{
try
{
@ -373,8 +370,7 @@ public class FlatFileDataStore extends DataStore
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));
@ -435,8 +431,7 @@ public class FlatFileDataStore extends DataStore
if (out_parentID.size() == 0 || out_parentID.get(0) == -1)
{
this.addClaim(claim, false);
}
else
} else
{
orphans.put(claim, out_parentID.get(0));
}
@ -448,8 +443,7 @@ public class FlatFileDataStore extends DataStore
if (e.getMessage() != null && e.getMessage().contains("World not found"))
{
files[i].delete();
}
else
} else
{
StringWriter errors = new StringWriter();
e.printStackTrace(new PrintWriter(errors));
@ -903,8 +897,7 @@ public class FlatFileDataStore extends DataStore
catch (IOException exception) {}
return schemaVersion;
}
else
} else
{
this.updateSchemaVersionInStorage(0);
return 0;

View File

@ -18,6 +18,42 @@
package me.ryanhamshire.GriefPrevention;
import me.ryanhamshire.GriefPrevention.DataStore.NoTransferException;
import me.ryanhamshire.GriefPrevention.events.PreventBlockBreakEvent;
import me.ryanhamshire.GriefPrevention.events.SaveTrappedPlayerEvent;
import me.ryanhamshire.GriefPrevention.events.TrustChangedEvent;
import me.ryanhamshire.GriefPrevention.metrics.MetricsHandler;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.BanList;
import org.bukkit.BanList.Type;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.ChunkSnapshot;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.Statistic;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.BlockIterator;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@ -32,42 +68,6 @@ import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import me.ryanhamshire.GriefPrevention.DataStore.NoTransferException;
import me.ryanhamshire.GriefPrevention.events.PreventBlockBreakEvent;
import me.ryanhamshire.GriefPrevention.events.SaveTrappedPlayerEvent;
import me.ryanhamshire.GriefPrevention.events.TrustChangedEvent;
import me.ryanhamshire.GriefPrevention.metrics.MetricsHandler;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
import org.bukkit.ChunkSnapshot;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.Statistic;
import org.bukkit.World;
import org.bukkit.BanList.Type;
import org.bukkit.World.Environment;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.command.*;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.BlockIterator;
public class GriefPrevention extends JavaPlugin
{
//for convenience, a reference to the instance of this plugin
@ -301,8 +301,10 @@ public class GriefPrevention extends JavaPlugin
if (this.dataStore == null)
{
File oldclaimdata = new File(getDataFolder(), "ClaimData");
if(oldclaimdata.exists()) {
if(!FlatFileDataStore.hasData()) {
if (oldclaimdata.exists())
{
if (!FlatFileDataStore.hasData())
{
File claimdata = new File("plugins" + File.separator + "GriefPreventionData" + File.separator + "ClaimData");
oldclaimdata.renameTo(claimdata);
File oldplayerdata = new File(getDataFolder(), "PlayerData");
@ -473,8 +475,7 @@ public class GriefPrevention extends JavaPlugin
this.config_claims_worldModes.put(world, claimsMode);
if (claimsMode == ClaimsMode.Creative) this.config_creativeWorldsExist = true;
continue;
}
else
} else
{
GriefPrevention.AddLogEntry("Error: Invalid claim mode \"" + configSetting + "\". Options are Survival, Creative, and Disabled.");
this.config_claims_worldModes.put(world, ClaimsMode.Creative);
@ -487,9 +488,7 @@ public class GriefPrevention extends JavaPlugin
{
this.config_claims_worldModes.put(world, ClaimsMode.Creative);
this.config_creativeWorldsExist = true;
}
else if(deprecated_claimsEnabledWorldNames.contains(world.getName()))
} else if (deprecated_claimsEnabledWorldNames.contains(world.getName()))
{
this.config_claims_worldModes.put(world, ClaimsMode.Survival);
}
@ -498,9 +497,7 @@ public class GriefPrevention extends JavaPlugin
else if (world.getName().toLowerCase().contains("survival"))
{
this.config_claims_worldModes.put(world, ClaimsMode.Survival);
}
else if(world.getName().toLowerCase().contains("creative"))
} else if (world.getName().toLowerCase().contains("creative"))
{
this.config_claims_worldModes.put(world, ClaimsMode.Creative);
this.config_creativeWorldsExist = true;
@ -511,14 +508,10 @@ public class GriefPrevention extends JavaPlugin
{
this.config_claims_worldModes.put(world, ClaimsMode.Creative);
this.config_creativeWorldsExist = true;
}
else if(world.getEnvironment() == Environment.NORMAL)
} else if (world.getEnvironment() == Environment.NORMAL)
{
this.config_claims_worldModes.put(world, ClaimsMode.Survival);
}
else
} else
{
this.config_claims_worldModes.put(world, ClaimsMode.Disabled);
}
@ -695,8 +688,7 @@ public class GriefPrevention extends JavaPlugin
if (world == null)
{
AddLogEntry("Error: Siege Configuration: There's no world named \"" + worldName + "\". Please update your config.yml.");
}
else
} else
{
this.config_siege_enabledWorlds.add(world);
}
@ -763,8 +755,7 @@ public class GriefPrevention extends JavaPlugin
if (material == null)
{
GriefPrevention.AddLogEntry("Siege Configuration: Material not found: " + blockName + ".");
}
else
} else
{
this.config_siege_blocks.add(material);
}
@ -984,20 +975,16 @@ public class GriefPrevention extends JavaPlugin
if (configSetting.equalsIgnoreCase("Survival"))
{
return ClaimsMode.Survival;
}
else if(configSetting.equalsIgnoreCase("Creative"))
} else if (configSetting.equalsIgnoreCase("Creative"))
{
return ClaimsMode.Creative;
}
else if(configSetting.equalsIgnoreCase("Disabled"))
} else if (configSetting.equalsIgnoreCase("Disabled"))
{
return ClaimsMode.Disabled;
}
else if(configSetting.equalsIgnoreCase("SurvivalRequiringClaims"))
} else if (configSetting.equalsIgnoreCase("SurvivalRequiringClaims"))
{
return ClaimsMode.SurvivalRequiringClaims;
}
else
} else
{
return null;
}
@ -1005,7 +992,8 @@ public class GriefPrevention extends JavaPlugin
//handles slash commands
@SuppressWarnings("deprecation")
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
{
Player player = null;
if (sender instanceof Player)
@ -1073,8 +1061,7 @@ public class GriefPrevention extends JavaPlugin
{
GriefPrevention.sendMessage(player, TextMode.Err, Messages.MinimumRadius, String.valueOf(radius));
return true;
}
else
} else
{
radius = specifiedRadius;
}
@ -1109,13 +1096,11 @@ public class GriefPrevention extends JavaPlugin
Visualization visualization = Visualization.FromClaim(result.claim, player.getEyeLocation().getBlockY(), VisualizationType.ErrorClaim, player.getLocation());
Visualization.Apply(player, visualization);
}
else
} else
{
GriefPrevention.sendMessage(player, TextMode.Err, Messages.CreateClaimFailOverlapRegion);
}
}
else
} else
{
GriefPrevention.sendMessage(player, TextMode.Success, Messages.CreateClaimSuccess);
@ -1123,8 +1108,7 @@ public class GriefPrevention extends JavaPlugin
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);
}
@ -1148,8 +1132,7 @@ public class GriefPrevention extends JavaPlugin
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);
}
@ -1167,8 +1150,7 @@ public class GriefPrevention extends JavaPlugin
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);
}
@ -1228,8 +1210,7 @@ public class GriefPrevention extends JavaPlugin
if (direction.getZ() > 0)
{
newz2 += amount; //north
}
else
} else
{
newz1 -= amount; //south
}
@ -1241,8 +1222,7 @@ public class GriefPrevention extends JavaPlugin
if (direction.getX() > 0)
{
newx2 += amount; //east
}
else
} else
{
newx1 -= amount; //west
}
@ -1254,8 +1234,7 @@ public class GriefPrevention extends JavaPlugin
if (direction.getX() > 0)
{
newx2 += amount;
}
else
} else
{
newx1 -= amount;
}
@ -1263,8 +1242,7 @@ public class GriefPrevention extends JavaPlugin
if (direction.getZ() > 0)
{
newz2 += amount;
}
else
} else
{
newz1 -= amount;
}
@ -1301,8 +1279,7 @@ public class GriefPrevention extends JavaPlugin
if (!playerData.ignoreClaims)
{
GriefPrevention.sendMessage(player, TextMode.Success, Messages.RespectingClaims);
}
else
} else
{
GriefPrevention.sendMessage(player, TextMode.Success, Messages.IgnoringClaims);
}
@ -1564,15 +1541,12 @@ public class GriefPrevention extends JavaPlugin
if (claim == null || claim.allowEdit(player) == null)
{
clearPermissions = true;
}
else
} else
{
GriefPrevention.sendMessage(player, TextMode.Err, Messages.ClearPermsOwnerOnly);
return true;
}
}
else
} else
{
//validate player argument or group argument
if (!args[0].startsWith("[") || !args[0].endsWith("]"))
@ -1605,7 +1579,8 @@ public class GriefPrevention extends JavaPlugin
TrustChangedEvent event = new TrustChangedEvent(player, playerData.getClaims(), null, false, idToDrop);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
if (event.isCancelled())
{
return true;
}
@ -1641,8 +1616,7 @@ public class GriefPrevention extends JavaPlugin
if (!clearPermissions)
{
GriefPrevention.sendMessage(player, TextMode.Success, Messages.UntrustIndividualAllClaims, args[0]);
}
else
} else
{
GriefPrevention.sendMessage(player, TextMode.Success, Messages.UntrustEveryoneAllClaims);
}
@ -1653,8 +1627,7 @@ public class GriefPrevention extends JavaPlugin
{
GriefPrevention.sendMessage(player, TextMode.Err, Messages.NoPermissionTrust, claim.getOwnerName());
return true;
}
else
} else
{
//if clearing all
if (clearPermissions)
@ -1670,7 +1643,8 @@ public class GriefPrevention extends JavaPlugin
TrustChangedEvent event = new TrustChangedEvent(player, claim, null, false, args[0]);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
if (event.isCancelled())
{
return true;
}
@ -1691,14 +1665,14 @@ public class GriefPrevention extends JavaPlugin
{
GriefPrevention.sendMessage(player, TextMode.Err, Messages.ManagersDontUntrustManagers, claim.getOwnerName());
return true;
}
else
} else
{
//calling the event
TrustChangedEvent event = new TrustChangedEvent(player, claim, null, false, idToDrop);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
if (event.isCancelled())
{
return true;
}
@ -1779,8 +1753,7 @@ public class GriefPrevention extends JavaPlugin
{
claim.setSubclaimRestrictions(false);
GriefPrevention.sendMessage(player, TextMode.Success, Messages.SubclaimUnrestricted);
}
else
} else
{
claim.setSubclaimRestrictions(true);
GriefPrevention.sendMessage(player, TextMode.Success, Messages.SubclaimRestricted);
@ -1817,9 +1790,7 @@ public class GriefPrevention extends JavaPlugin
{
GriefPrevention.sendMessage(player, TextMode.Info, Messages.BlockPurchaseCost, String.valueOf(GriefPrevention.instance.config_economy_claimBlocksPurchaseCost), String.valueOf(GriefPrevention.economy.getBalance(player.getName())));
return false;
}
else
} else
{
PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
@ -1991,9 +1962,7 @@ public class GriefPrevention extends JavaPlugin
if (claim == null)
{
GriefPrevention.sendMessage(player, TextMode.Err, Messages.DeleteClaimMissing);
}
else
} else
{
//deleting an admin claim additionally requires the adminclaims permission
if (!claim.isAdminClaim() || player.hasPermission("griefprevention.adminclaims"))
@ -2003,8 +1972,7 @@ public class GriefPrevention extends JavaPlugin
{
GriefPrevention.sendMessage(player, TextMode.Warn, Messages.DeletionSubdivisionWarning);
playerData.warnedAboutMajorDeletion = true;
}
else
} else
{
claim.removeSurfaceFluids(null);
this.dataStore.deleteClaim(claim, true, true);
@ -2023,17 +1991,14 @@ public class GriefPrevention extends JavaPlugin
playerData.warnedAboutMajorDeletion = false;
}
}
else
} else
{
GriefPrevention.sendMessage(player, TextMode.Err, Messages.CantDeleteAdminClaim);
}
}
return true;
}
else if(cmd.getName().equalsIgnoreCase("claimexplosions") && player != null)
} else if (cmd.getName().equalsIgnoreCase("claimexplosions") && player != null)
{
//determine which claim the player is standing in
Claim claim = this.dataStore.getClaimAt(player.getLocation(), true /*ignore height*/, null);
@ -2041,9 +2006,7 @@ public class GriefPrevention extends JavaPlugin
if (claim == null)
{
GriefPrevention.sendMessage(player, TextMode.Err, Messages.DeleteClaimMissing);
}
else
} else
{
String noBuildReason = claim.allowBuild(player, Material.STONE);
if (noBuildReason != null)
@ -2056,8 +2019,7 @@ public class GriefPrevention extends JavaPlugin
{
claim.areExplosivesAllowed = false;
GriefPrevention.sendMessage(player, TextMode.Success, Messages.ExplosivesDisabled);
}
else
} else
{
claim.areExplosivesAllowed = true;
GriefPrevention.sendMessage(player, TextMode.Success, Messages.ExplosivesEnabled);
@ -2094,9 +2056,7 @@ public class GriefPrevention extends JavaPlugin
}
return true;
}
else if(cmd.getName().equalsIgnoreCase("deleteclaimsinworld"))
} else if (cmd.getName().equalsIgnoreCase("deleteclaimsinworld"))
{
//must be executed at the console
if (player != null)
@ -2120,9 +2080,7 @@ public class GriefPrevention extends JavaPlugin
this.dataStore.deleteClaimsInWorld(world, true);
GriefPrevention.AddLogEntry("Deleted all claims in world: " + world.getName() + ".", CustomLogEntryTypes.AdminActivity);
return true;
}
else if(cmd.getName().equalsIgnoreCase("deleteuserclaimsinworld"))
} else if (cmd.getName().equalsIgnoreCase("deleteuserclaimsinworld"))
{
//must be executed at the console
if (player != null)
@ -2160,8 +2118,7 @@ public class GriefPrevention extends JavaPlugin
{
GriefPrevention.sendMessage(player, TextMode.Err, Messages.PlayerNotFound2);
return true;
}
else
} else
{
WelcomeTask task = new WelcomeTask(otherPlayer);
task.run();
@ -2272,8 +2229,7 @@ public class GriefPrevention extends JavaPlugin
playerData = this.dataStore.getPlayerData(otherPlayer.getUniqueId());
GriefPrevention.sendMessage(player, TextMode.Success, Messages.DropUnlockOthersConfirmation, otherPlayer.getName());
}
else
} else
{
playerData = this.dataStore.getPlayerData(player.getUniqueId());
GriefPrevention.sendMessage(player, TextMode.Success, Messages.DropUnlockConfirmation);
@ -2332,7 +2288,8 @@ public class GriefPrevention extends JavaPlugin
int newTotal = this.dataStore.adjustGroupBonusBlocks(permissionIdentifier, adjustment);
GriefPrevention.sendMessage(player, TextMode.Success, Messages.AdjustGroupBlocksSuccess, permissionIdentifier, String.valueOf(adjustment), String.valueOf(newTotal));
if(player != null) GriefPrevention.AddLogEntry(player.getName() + " adjusted " + permissionIdentifier + "'s bonus claim blocks by " + adjustment + ".");
if (player != null)
GriefPrevention.AddLogEntry(player.getName() + " adjusted " + permissionIdentifier + "'s bonus claim blocks by " + adjustment + ".");
return true;
}
@ -2362,7 +2319,8 @@ public class GriefPrevention extends JavaPlugin
this.dataStore.savePlayerData(targetPlayer.getUniqueId(), playerData);
GriefPrevention.sendMessage(player, TextMode.Success, Messages.AdjustBlocksSuccess, targetPlayer.getName(), String.valueOf(adjustment), String.valueOf(playerData.getBonusClaimBlocks()));
if(player != null) GriefPrevention.AddLogEntry(player.getName() + " adjusted " + targetPlayer.getName() + "'s bonus claim blocks by " + adjustment + ".", CustomLogEntryTypes.AdminActivity);
if (player != null)
GriefPrevention.AddLogEntry(player.getName() + " adjusted " + targetPlayer.getName() + "'s bonus claim blocks by " + adjustment + ".", CustomLogEntryTypes.AdminActivity);
return true;
}
@ -2434,7 +2392,8 @@ public class GriefPrevention extends JavaPlugin
this.dataStore.savePlayerData(targetPlayer.getUniqueId(), playerData);
GriefPrevention.sendMessage(player, TextMode.Success, Messages.SetClaimBlocksSuccess);
if(player != null) GriefPrevention.AddLogEntry(player.getName() + " set " + targetPlayer.getName() + "'s accrued claim blocks to " + newAmount + ".", CustomLogEntryTypes.AdminActivity);
if (player != null)
GriefPrevention.AddLogEntry(player.getName() + " set " + targetPlayer.getName() + "'s accrued claim blocks to " + newAmount + ".", CustomLogEntryTypes.AdminActivity);
return true;
}
@ -2539,16 +2498,15 @@ public class GriefPrevention extends JavaPlugin
{
return false;
}
}
else
} else
{
return false;
}
// First off, you cannot siege yourself, that's just
// silly:
if (attacker.getName().equals( defender.getName() )) {
if (attacker.getName().equals(defender.getName()))
{
GriefPrevention.sendMessage(player, TextMode.Err, Messages.NoSiegeYourself);
return true;
}
@ -2620,8 +2578,7 @@ public class GriefPrevention extends JavaPlugin
GriefPrevention.sendMessage(player, TextMode.Success, Messages.SiegeConfirmed, defender.getName());
return true;
}
else if(cmd.getName().equalsIgnoreCase("softmute"))
} else if (cmd.getName().equalsIgnoreCase("softmute"))
{
//requires one parameter
if (args.length != 1) return false;
@ -2646,23 +2603,19 @@ public class GriefPrevention extends JavaPlugin
}
GriefPrevention.AddLogEntry(executorName + " muted " + targetPlayer.getName() + ".", CustomLogEntryTypes.AdminActivity, true);
}
else
} else
{
GriefPrevention.sendMessage(player, TextMode.Success, Messages.UnSoftMuted, targetPlayer.getName());
}
return true;
}
else if(cmd.getName().equalsIgnoreCase("gpreload"))
} else if (cmd.getName().equalsIgnoreCase("gpreload"))
{
this.loadConfig();
if (player != null)
{
GriefPrevention.sendMessage(player, TextMode.Success, "Configuration updated. If you have updated your Grief Prevention JAR, you still need to /reload or reboot your server.");
}
else
} else
{
GriefPrevention.AddLogEntry("Configuration updated. If you have updated your Grief Prevention JAR, you still need to /reload or reboot your server.");
}
@ -2787,8 +2740,7 @@ public class GriefPrevention extends JavaPlugin
if (list.isEmpty())
{
GriefPrevention.sendMessage(player, TextMode.Info, Messages.NotIgnoringAnyone);
}
else
} else
{
GriefPrevention.sendMessage(player, TextMode.Info, list);
}
@ -2861,8 +2813,7 @@ public class GriefPrevention extends JavaPlugin
if (mode == IgnoreMode.None)
{
playerData.ignoredPlayers.remove(ignoree.getUniqueId());
}
else
} else
{
playerData.ignoredPlayers.put(ignoree.getUniqueId(), mode == IgnoreMode.StandardIgnore ? false : true);
}
@ -2875,15 +2826,15 @@ public class GriefPrevention extends JavaPlugin
}
}
public enum IgnoreMode {None, StandardIgnore, AdminIgnore}
public enum IgnoreMode
{None, StandardIgnore, AdminIgnore}
private String trustEntryToPlayerName(String entry)
{
if (entry.startsWith("[") || entry.equals("public"))
{
return entry;
}
else
} else
{
return GriefPrevention.lookupPlayerName(entry);
}
@ -2916,9 +2867,7 @@ public class GriefPrevention extends JavaPlugin
{
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.DeleteTopLevelClaim);
return true;
}
else
} else
{
//delete it
claim.removeSurfaceFluids(null);
@ -2970,14 +2919,10 @@ public class GriefPrevention extends JavaPlugin
GriefPrevention.sendMessage(player, TextMode.Err, Messages.InvalidPermissionID);
return;
}
}
else if(recipientName.contains("."))
} else if (recipientName.contains("."))
{
permission = recipientName;
}
else
} else
{
otherPlayer = this.resolvePlayerByName(recipientName);
if (otherPlayer == null && !recipientName.equals("public") && !recipientName.equals("all"))
@ -2990,8 +2935,7 @@ public class GriefPrevention extends JavaPlugin
{
recipientName = otherPlayer.getName();
recipientID = otherPlayer.getUniqueId();
}
else
} else
{
recipientName = "public";
}
@ -3006,8 +2950,7 @@ public class GriefPrevention extends JavaPlugin
{
targetClaims.add(playerData.getClaims().get(i));
}
}
else
} else
{
//check permission here
if (claim.allowGrantPermission(player) != null)
@ -3066,8 +3009,7 @@ public class GriefPrevention extends JavaPlugin
if (permission != null)
{
identifierToAdd = "[" + permission + "]";
}
else if(recipientID != null)
} else if (recipientID != null)
{
identifierToAdd = recipientID.toString();
}
@ -3076,7 +3018,8 @@ public class GriefPrevention extends JavaPlugin
TrustChangedEvent event = new TrustChangedEvent(player, targetClaims, permissionLevel, true, identifierToAdd);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
if (event.isCancelled())
{
return;
}
@ -3091,8 +3034,7 @@ public class GriefPrevention extends JavaPlugin
{
currentClaim.managers.add(identifierToAdd);
}
}
else
} else
{
currentClaim.setPermission(identifierToAdd, permissionLevel);
}
@ -3105,16 +3047,13 @@ public class GriefPrevention extends JavaPlugin
if (permissionLevel == null)
{
permissionDescription = this.dataStore.getMessage(Messages.PermissionsPermission);
}
else if(permissionLevel == ClaimPermission.Build)
} else if (permissionLevel == ClaimPermission.Build)
{
permissionDescription = this.dataStore.getMessage(Messages.BuildPermission);
}
else if(permissionLevel == ClaimPermission.Access)
} else if (permissionLevel == ClaimPermission.Access)
{
permissionDescription = this.dataStore.getMessage(Messages.AccessPermission);
}
else //ClaimPermission.Inventory
} else //ClaimPermission.Inventory
{
permissionDescription = this.dataStore.getMessage(Messages.ContainersPermission);
}
@ -3123,8 +3062,7 @@ public class GriefPrevention extends JavaPlugin
if (claim == null)
{
location = this.dataStore.getMessage(Messages.LocationAllClaims);
}
else
} else
{
location = this.dataStore.getMessage(Messages.LocationCurrentClaim);
}
@ -3214,8 +3152,7 @@ public class GriefPrevention extends JavaPlugin
if (player.hasPlayedBefore() || player.isOnline())
{
return player.getName();
}
else
} else
{
return "someone(" + playerID.toString() + ")";
}
@ -3383,8 +3320,7 @@ public class GriefPrevention extends JavaPlugin
if (player == null)
{
GriefPrevention.AddLogEntry(color + message);
}
else
} else
{
player.sendMessage(color + message);
}
@ -3398,8 +3334,7 @@ public class GriefPrevention extends JavaPlugin
if (delayInTicks > 0)
{
GriefPrevention.instance.getServer().getScheduler().runTaskLater(GriefPrevention.instance, task, delayInTicks);
}
else
} else
{
task.run();
}
@ -3449,8 +3384,7 @@ public class GriefPrevention extends JavaPlugin
reason += " " + this.dataStore.getMessage(Messages.IgnoreClaimsAdvertisement);
reason += " " + this.dataStore.getMessage(Messages.CreativeBasicsVideo2, DataStore.CREATIVE_VIDEO_URL);
return reason;
}
else
} else
{
return null;
}
@ -3505,8 +3439,7 @@ public class GriefPrevention extends JavaPlugin
{
return null;
}
}
else
} else
{
//cache the claim for later reference
playerData.lastClaim = claim;
@ -3612,8 +3545,7 @@ public class GriefPrevention extends JavaPlugin
if (overrideValue == null || overrideValue == -1)
{
return world.getSeaLevel();
}
else
} else
{
return overrideValue;
}
@ -3701,8 +3633,7 @@ public class GriefPrevention extends JavaPlugin
Bukkit.getServer().dispatchCommand(
Bukkit.getConsoleSender(),
GriefPrevention.instance.config_ban_commandFormat.replace("%name%", player.getName()).replace("%reason%", reason));
}
else
} else
{
BanList bans = Bukkit.getServer().getBanList(Type.NAME);
bans.addBan(player.getName(), reason, null, source);
@ -3788,6 +3719,7 @@ public class GriefPrevention extends JavaPlugin
//Track scheduled "rescues" so we can cancel them if the player happens to teleport elsewhere so we can cancel it.
ConcurrentHashMap<UUID, BukkitTask> portalReturnTaskMap = new ConcurrentHashMap<UUID, BukkitTask>();
public void startRescueTask(Player player, Location location)
{
//Schedule task to reset player's portal cooldown after 30 seconds (Maximum timeout time for client, in case their network is slow and taking forever to load chunks)

View File

@ -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
{

View File

@ -79,8 +79,7 @@ public class MaterialInfo
{
allDataValues = true;
data = 0;
}
else
} else
{
allDataValues = false;
data = Byte.parseByte(parts[1]);

View File

@ -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;

View File

@ -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
{
@ -231,8 +223,7 @@ public class PlayerData
this.accruedClaimBlocks = GriefPrevention.instance.config_claims_initialBlocks;
}
}
else
} else
{
this.accruedClaimBlocks = GriefPrevention.instance.config_claims_initialBlocks;
}
@ -243,8 +234,7 @@ public class PlayerData
if (storageData.bonusClaimBlocks != null)
{
this.bonusClaimBlocks = storageData.bonusClaimBlocks;
}
else
} else
{
this.bonusClaimBlocks = 0;
}

View File

@ -17,6 +17,7 @@
*/
package me.ryanhamshire.GriefPrevention;
import me.ryanhamshire.GriefPrevention.events.VisualizationEvent;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
@ -38,19 +39,19 @@ import org.bukkit.command.Command;
import org.bukkit.entity.AbstractHorse;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Donkey;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Fish;
import org.bukkit.entity.Hanging;
import org.bukkit.entity.Item;
import org.bukkit.entity.Llama;
import org.bukkit.entity.Mule;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Vehicle;
import org.bukkit.entity.minecart.PoweredMinecart;
import org.bukkit.entity.minecart.StorageMinecart;
import org.bukkit.entity.Llama;
import org.bukkit.entity.Donkey;
import org.bukkit.entity.Mule;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -166,8 +167,7 @@ class PlayerEventHandler implements Listener
if (this.dataStore.isSoftMuted(recipient.getUniqueId()))
{
recipientsToKeep.add(recipient);
}
else if(recipient.hasPermission("griefprevention.eavesdrop"))
} else if (recipient.hasPermission("griefprevention.eavesdrop"))
{
recipient.sendMessage(ChatColor.GRAY + notificationMessage);
}
@ -235,8 +235,7 @@ class PlayerEventHandler implements Listener
if (playerData.ignoredPlayers.containsKey(recipient.getUniqueId()))
{
recipientsToRemove.add(recipient);
}
else
} else
{
PlayerData targetPlayerData = this.dataStore.getPlayerData(recipient.getUniqueId());
if (targetPlayerData.ignoredPlayers.containsKey(player.getUniqueId()))
@ -267,8 +266,7 @@ class PlayerEventHandler implements Listener
if (instance.creativeRulesApply(player.getLocation()))
{
instance.sendMessage(player, TextMode.Info, Messages.CreativeBasicsVideo2, 10L, DataStore.CREATIVE_VIDEO_URL);
}
else
} else
{
instance.sendMessage(player, TextMode.Info, Messages.SurvivalBasicsVideo2, 10L, DataStore.SURVIVAL_VIDEO_URL);
}
@ -279,10 +277,12 @@ class PlayerEventHandler implements Listener
String trappedwords = this.dataStore.getMessage(
Messages.TrappedChatKeyword
);
if (!trappedwords.isEmpty()) {
if (!trappedwords.isEmpty())
{
String[] checkWords = trappedwords.split(";");
for (String checkWord : checkWords) {
for (String checkWord : checkWords)
{
if (!message.contains("/trapped")
&& message.contains(checkWord))
{
@ -323,8 +323,7 @@ class PlayerEventHandler implements Listener
{
instance.sendMessage(player, TextMode.Err, Messages.NoChatUntilMove, 10L);
result.muteReason = "pre-movement chat";
}
else
} else
{
playerData.noChatLocation = null;
}
@ -351,8 +350,7 @@ class PlayerEventHandler implements Listener
//kick and ban
PlayerKickBanTask task = new PlayerKickBanTask(player, instance.config_spam_banMessage, "GriefPrevention Anti-Spam", true);
instance.getServer().getScheduler().scheduleSyncDelayedTask(instance, task, 1L);
}
else
} else
{
//log entry
instance.AddLogEntry("Kicking " + player.getName() + " for spam.", CustomLogEntryTypes.AdminActivity);
@ -361,9 +359,7 @@ class PlayerEventHandler implements Listener
PlayerKickBanTask task = new PlayerKickBanTask(player, "", "GriefPrevention Anti-Spam", false);
instance.getServer().getScheduler().scheduleSyncDelayedTask(instance, task, 1L);
}
}
else if(result.shouldWarnChatter)
} else if (result.shouldWarnChatter)
{
//warn and log
instance.sendMessage(player, TextMode.Warn, instance.config_spam_warningMessage, 10L);
@ -534,6 +530,7 @@ class PlayerEventHandler implements Listener
}
private ConcurrentHashMap<String, CommandCategory> commandCategoryMap = new ConcurrentHashMap<String, CommandCategory>();
private CommandCategory getCommandCategory(String commandName)
{
if (commandName.startsWith("/")) commandName = commandName.substring(1);
@ -584,8 +581,7 @@ class PlayerEventHandler implements Listener
if (instance.config_eavesdrop_whisperCommands.contains("/" + alias))
{
category = CommandCategory.Whisper;
}
else if(instance.config_spam_monitorSlashCommands.contains("/" + alias))
} else if (instance.config_spam_monitorSlashCommands.contains("/" + alias))
{
category = CommandCategory.Chat;
}
@ -598,6 +594,7 @@ class PlayerEventHandler implements Listener
}
static int longestNameLength = 10;
static void makeSocialLogEntry(String name, String message)
{
StringBuilder entryBuilder = new StringBuilder(name);
@ -870,6 +867,7 @@ class PlayerEventHandler implements Listener
//when a player dies...
private HashMap<UUID, Long> deathTimestamps = new HashMap<UUID, Long>();
@EventHandler(priority = EventPriority.HIGHEST)
void onPlayerDeath(PlayerDeathEvent event)
{
@ -902,6 +900,7 @@ class PlayerEventHandler implements Listener
//when a player quits...
private HashMap<UUID, Integer> heldLogoutMessages = new HashMap<UUID, Integer>();
@EventHandler(priority = EventPriority.HIGHEST)
void onPlayerQuit(PlayerQuitEvent event)
{
@ -920,8 +919,7 @@ class PlayerEventHandler implements Listener
if (playerData.wasKicked)
{
isBanned = player.isBanned();
}
else
} else
{
isBanned = false;
}
@ -962,7 +960,8 @@ class PlayerEventHandler implements Listener
//if player was involved in a siege, he forfeits
if (playerData.siegeData != null)
{
if(player.getHealth() > 0) player.setHealth(0); //might already be zero from above, this avoids a double death message
if (player.getHealth() > 0)
player.setHealth(0); //might already be zero from above, this avoids a double death message
}
//drop data about this player
@ -1000,8 +999,7 @@ class PlayerEventHandler implements Listener
if (now - notificationTimestamp > ONE_MINUTE)
{
this.recentLoginLogoutNotifications.remove(i--);
}
else
} else
{
break;
}
@ -1186,8 +1184,7 @@ class PlayerEventHandler implements Listener
return;
}
}
}
else //world repair code for a now-fixed GP bug //TODO: necessary anymore?
} else //world repair code for a now-fixed GP bug //TODO: necessary anymore?
{
//ensure this entity can be tamed by players
tameable.setOwner(null);
@ -1421,6 +1418,7 @@ class PlayerEventHandler implements Listener
//block use of buckets within other players' claims
private HashSet<Material> commonAdjacentBlocks_water = new HashSet<Material>(Arrays.asList(Material.WATER, Material.FARMLAND, Material.DIRT, Material.STONE));
private HashSet<Material> commonAdjacentBlocks_lava = new HashSet<Material>(Arrays.asList(Material.LAVA, Material.DIRT, Material.STONE));
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent bucketEvent)
{
@ -1510,10 +1508,13 @@ class PlayerEventHandler implements Listener
}
}
private boolean doesAllowLavaProximityInWorld(World world) {
if (GriefPrevention.instance.pvpRulesApply(world)) {
private boolean doesAllowLavaProximityInWorld(World world)
{
if (GriefPrevention.instance.pvpRulesApply(world))
{
return GriefPrevention.instance.config_pvp_allowLavaNearPlayers;
} else {
} else
{
return GriefPrevention.instance.config_pvp_allowLavaNearPlayers_NonPvp;
}
}
@ -1563,8 +1564,7 @@ class PlayerEventHandler implements Listener
if (clickedBlock != null)
{
clickedBlockType = clickedBlock.getType();
}
else
} else
{
clickedBlockType = Material.AIR;
}
@ -1904,9 +1904,7 @@ class PlayerEventHandler implements Listener
}
return;
}
else if(clickedBlock != null && (
} else if (clickedBlock != null && (
materialInHand == Material.OAK_BOAT ||
materialInHand == Material.SPRUCE_BOAT ||
materialInHand == Material.BIRCH_BOAT ||
@ -2073,7 +2071,8 @@ class PlayerEventHandler implements Listener
Visualization.Apply(player, visualization);
if (player.hasPermission("griefprevention.seeclaimsize")) {
if (player.hasPermission("griefprevention.seeclaimsize"))
{
instance.sendMessage(player, TextMode.Info, " " + claim.getWidth() + "x" + claim.getHeight() + "=" + claim.getArea());
}
@ -2183,12 +2182,10 @@ class PlayerEventHandler implements Listener
if (environment == Environment.NETHER)
{
allowedFillBlocks.add(Material.NETHERRACK);
}
else if(environment == Environment.THE_END)
} else if (environment == Environment.THE_END)
{
allowedFillBlocks.add(Material.END_STONE);
}
else
} else
{
allowedFillBlocks.add(Material.GRASS);
allowedFillBlocks.add(Material.DIRT);
@ -2274,16 +2271,13 @@ class PlayerEventHandler implements Listener
if (allowedFillBlocks.contains(eastBlock.getType()))
{
block.setType(eastBlock.getType());
}
else if(allowedFillBlocks.contains(westBlock.getType()))
} else if (allowedFillBlocks.contains(westBlock.getType()))
{
block.setType(westBlock.getType());
}
else if(allowedFillBlocks.contains(northBlock.getType()))
} else if (allowedFillBlocks.contains(northBlock.getType()))
{
block.setType(northBlock.getType());
}
else if(allowedFillBlocks.contains(southBlock.getType()))
} else if (allowedFillBlocks.contains(southBlock.getType()))
{
block.setType(southBlock.getType());
}
@ -2319,8 +2313,7 @@ class PlayerEventHandler implements Listener
if (playerData.lastShovelLocation.getBlockX() == playerData.claimResizing.getLesserBoundaryCorner().getBlockX())
{
newx1 = clickedBlock.getX();
}
else
} else
{
newx1 = playerData.claimResizing.getLesserBoundaryCorner().getBlockX();
}
@ -2328,8 +2321,7 @@ class PlayerEventHandler implements Listener
if (playerData.lastShovelLocation.getBlockX() == playerData.claimResizing.getGreaterBoundaryCorner().getBlockX())
{
newx2 = clickedBlock.getX();
}
else
} else
{
newx2 = playerData.claimResizing.getGreaterBoundaryCorner().getBlockX();
}
@ -2337,8 +2329,7 @@ class PlayerEventHandler implements Listener
if (playerData.lastShovelLocation.getBlockZ() == playerData.claimResizing.getLesserBoundaryCorner().getBlockZ())
{
newz1 = clickedBlock.getZ();
}
else
} else
{
newz1 = playerData.claimResizing.getLesserBoundaryCorner().getBlockZ();
}
@ -2346,8 +2337,7 @@ class PlayerEventHandler implements Listener
if (playerData.lastShovelLocation.getBlockZ() == playerData.claimResizing.getGreaterBoundaryCorner().getBlockZ())
{
newz2 = clickedBlock.getZ();
}
else
} else
{
newz2 = playerData.claimResizing.getGreaterBoundaryCorner().getBlockZ();
}
@ -2573,8 +2563,7 @@ class PlayerEventHandler implements Listener
instance.dataStore.tryAdvertiseAdminAlternatives(player);
return;
}
}
else
} else
{
playerID = null;
}
@ -2602,8 +2591,7 @@ class PlayerEventHandler implements Listener
Bukkit.getPluginManager().callEvent(new VisualizationEvent(player, result.claim));
Visualization.Apply(player, visualization);
}
else
} else
{
instance.sendMessage(player, TextMode.Err, Messages.CreateClaimFailOverlapRegion);
}
@ -2658,6 +2646,7 @@ class PlayerEventHandler implements Listener
//determines whether a block type is an inventory holder. uses a caching strategy to save cpu time
private ConcurrentHashMap<Material, Boolean> inventoryHolderCache = new ConcurrentHashMap<Material, Boolean>();
private boolean isInventoryHolder(Block clickedBlock)
{
@SuppressWarnings("deprecation")
@ -2667,8 +2656,7 @@ class PlayerEventHandler implements Listener
{
return cachedValue.booleanValue();
}
else
} else
{
boolean isHolder = clickedBlock.getState() instanceof InventoryHolder;
this.inventoryHolderCache.put(cacheKey, isHolder);

View File

@ -62,8 +62,7 @@ class PlayerKickBanTask implements Runnable
{
//ban
GriefPrevention.banPlayer(this.player, this.reason, this.source);
}
else if(this.player.isOnline())
} else if (this.player.isOnline())
{
this.player.kickPlayer(this.reason);
}

View File

@ -63,8 +63,7 @@ class PlayerRescueTask implements Runnable
if (this.destination == null)
{
this.destination = GriefPrevention.instance.ejectPlayer(this.player);
}
else
} else
{
player.teleport(this.destination);
}

View File

@ -45,8 +45,7 @@ class PvPImmunityValidationTask implements Runnable
//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);

View File

@ -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

View File

@ -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
@ -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;
}
@ -442,8 +441,7 @@ class RestoreNatureProcessingTask implements Runnable
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;
}
@ -561,7 +559,8 @@ 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;

View File

@ -18,10 +18,10 @@
package me.ryanhamshire.GriefPrevention;
import java.util.Collection;
import org.bukkit.entity.Player;
import java.util.Collection;
//secures a claim after a siege looting window has closed
class SecureClaimTask implements Runnable
{

View File

@ -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
{

View File

@ -15,6 +15,7 @@ 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);
@ -56,8 +57,7 @@ class SpamDetector
chatterData.spamLevel += ++this.duplicateMessageCount;
spam = true;
result.muteReason = "repeat message";
}
else
} else
{
this.lastChatMessage = message;
this.lastChatMessageTimestamp = timestamp;
@ -135,9 +135,7 @@ class SpamDetector
if (chatterData.spamLevel > 8 && chatterData.spamWarned)
{
result.shouldBanChatter = true;
}
else if(chatterData.spamLevel >= 4)
} else if (chatterData.spamLevel >= 4)
{
if (!chatterData.spamWarned)
{
@ -177,8 +175,7 @@ class SpamDetector
{
shorterString = lastMessage;
longerString = message;
}
else
} else
{
shorterString = message;
longerString = lastMessage;
@ -205,7 +202,8 @@ class SpamDetector
int j;
for (j = 0; j < shorterString.length() - i; j++)
{
if(shorterString.charAt(shorterString.length() - j - 1) == longerString.charAt(longerString.length() - j - 1)) identicalCount++;
if (shorterString.charAt(shorterString.length() - j - 1) == longerString.charAt(longerString.length() - j - 1))
identicalCount++;
if (identicalCount > maxIdenticalCharacters) return true;
}

View File

@ -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,12 +31,14 @@ 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);
}
@ -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);
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);
}
}
@ -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) {
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);

View File

@ -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.
@ -151,27 +151,19 @@ public class Visualization
{
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);

View File

@ -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

View File

@ -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
{
@ -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;
}
}

View File

@ -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
*/

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -1,5 +1,5 @@
/**
*
* @author Ryan
*/
/**
* @author Ryan

View File

@ -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);