reformat code
- Lots of tabs to spaces going on - That's a lot of changes! #63
This commit is contained in:
parent
bc05440617
commit
40f554d386
|
|
@ -1,13 +1,13 @@
|
|||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChunkSnapshot;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
//automatically extends a claim downward based on block types detected
|
||||
class AutoExtendClaimTask implements Runnable
|
||||
{
|
||||
|
|
@ -26,7 +26,7 @@ class AutoExtendClaimTask implements Runnable
|
|||
public void run()
|
||||
{
|
||||
int newY = this.getLowestBuiltY();
|
||||
if(newY < this.claim.getLesserBoundaryCorner().getBlockY())
|
||||
if (newY < this.claim.getLesserBoundaryCorner().getBlockY())
|
||||
{
|
||||
Bukkit.getScheduler().runTask(GriefPrevention.instance, new ExecuteExtendClaimTask(claim, newY));
|
||||
}
|
||||
|
|
@ -35,73 +35,73 @@ class AutoExtendClaimTask implements Runnable
|
|||
private int getLowestBuiltY()
|
||||
{
|
||||
int y = this.claim.getLesserBoundaryCorner().getBlockY();
|
||||
|
||||
if(this.yTooSmall(y)) return y;
|
||||
|
||||
if (this.yTooSmall(y)) return y;
|
||||
|
||||
try
|
||||
{
|
||||
for(ChunkSnapshot chunk : this.chunks)
|
||||
for (ChunkSnapshot chunk : this.chunks)
|
||||
{
|
||||
Biome biome = chunk.getBiome(0, 0);
|
||||
Biome biome = chunk.getBiome(0, 0);
|
||||
ArrayList<Material> playerBlockIDs = RestoreNatureProcessingTask.getPlayerBlocks(this.worldType, biome);
|
||||
|
||||
boolean ychanged = true;
|
||||
while(!this.yTooSmall(y) && ychanged)
|
||||
while (!this.yTooSmall(y) && ychanged)
|
||||
{
|
||||
ychanged = false;
|
||||
for(int x = 0; x < 16; x++)
|
||||
for (int x = 0; x < 16; x++)
|
||||
{
|
||||
for(int z = 0; z < 16; z++)
|
||||
for (int z = 0; z < 16; z++)
|
||||
{
|
||||
Material blockType = chunk.getBlockType(x, y, z);
|
||||
while(!this.yTooSmall(y) && playerBlockIDs.contains(blockType))
|
||||
while (!this.yTooSmall(y) && playerBlockIDs.contains(blockType))
|
||||
{
|
||||
ychanged = true;
|
||||
blockType = chunk.getBlockType(x, --y, z);
|
||||
}
|
||||
|
||||
if(this.yTooSmall(y)) return y;
|
||||
if (this.yTooSmall(y)) return y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(this.yTooSmall(y)) return y;
|
||||
if (this.yTooSmall(y)) return y;
|
||||
}
|
||||
}
|
||||
catch (NoSuchMethodError e)
|
||||
{
|
||||
GriefPrevention.instance.getLogger().severe("You are running an outdated build of Craftbukkit/Spigot/Paper. Please update.");
|
||||
for(ChunkSnapshot chunk : this.chunks)
|
||||
for (ChunkSnapshot chunk : this.chunks)
|
||||
{
|
||||
Biome biome = chunk.getBiome(0, 0);
|
||||
Biome biome = chunk.getBiome(0, 0);
|
||||
ArrayList<Material> playerBlockIDs = RestoreNatureProcessingTask.getPlayerBlocks(this.worldType, biome);
|
||||
|
||||
boolean ychanged = true;
|
||||
while(!this.yTooSmall(y) && ychanged)
|
||||
while (!this.yTooSmall(y) && ychanged)
|
||||
{
|
||||
ychanged = false;
|
||||
for(int x = 0; x < 16; x++)
|
||||
for (int x = 0; x < 16; x++)
|
||||
{
|
||||
for(int z = 0; z < 16; z++)
|
||||
for (int z = 0; z < 16; z++)
|
||||
{
|
||||
Material blockType = chunk.getBlockType(x, y, z);
|
||||
while(!this.yTooSmall(y) && playerBlockIDs.contains(blockType))
|
||||
{
|
||||
ychanged = true;
|
||||
blockType = chunk.getBlockType(x, --y, z);
|
||||
}
|
||||
Material blockType = chunk.getBlockType(x, y, z);
|
||||
while (!this.yTooSmall(y) && playerBlockIDs.contains(blockType))
|
||||
{
|
||||
ychanged = true;
|
||||
blockType = chunk.getBlockType(x, --y, z);
|
||||
}
|
||||
|
||||
if(this.yTooSmall(y)) return y;
|
||||
if (this.yTooSmall(y)) return y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(this.yTooSmall(y)) return y;
|
||||
if (this.yTooSmall(y)) return y;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
|
|
@ -109,7 +109,7 @@ class AutoExtendClaimTask implements Runnable
|
|||
{
|
||||
return y == 0 || y <= GriefPrevention.instance.config_claims_maxDepth;
|
||||
}
|
||||
|
||||
|
||||
//runs in the main execution thread, where it can safely change claims and save those changes
|
||||
private class ExecuteExtendClaimTask implements Runnable
|
||||
{
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -24,16 +24,16 @@ import org.bukkit.block.data.BlockData;
|
|||
|
||||
//basically, just a few data points from a block conveniently encapsulated in a class
|
||||
//this is used only by the RestoreNature code
|
||||
public class BlockSnapshot
|
||||
public class BlockSnapshot
|
||||
{
|
||||
public Location location;
|
||||
public Material typeId;
|
||||
public BlockData data;
|
||||
|
||||
public BlockSnapshot(Location location, Material typeId, BlockData data)
|
||||
{
|
||||
this.location = location;
|
||||
this.typeId = typeId;
|
||||
this.data = data;
|
||||
}
|
||||
public Location location;
|
||||
public Material typeId;
|
||||
public BlockData data;
|
||||
|
||||
public BlockSnapshot(Location location, Material typeId, BlockData data)
|
||||
{
|
||||
this.location = location;
|
||||
this.typeId = typeId;
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,25 +15,25 @@
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
//sends a message to all online players
|
||||
//used to send delayed messages, for example a quit message after the player has been gone a while
|
||||
class BroadcastMessageTask implements Runnable
|
||||
class BroadcastMessageTask implements Runnable
|
||||
{
|
||||
private String message;
|
||||
|
||||
public BroadcastMessageTask(String message)
|
||||
{
|
||||
private String message;
|
||||
|
||||
public BroadcastMessageTask(String message)
|
||||
{
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
Bukkit.getServer().broadcastMessage(this.message);
|
||||
}
|
||||
public void run()
|
||||
{
|
||||
Bukkit.getServer().broadcastMessage(this.message);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,13 +15,10 @@
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
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;
|
||||
|
|
@ -31,30 +28,30 @@ import org.bukkit.scheduler.BukkitRunnable;
|
|||
//if that happens, we detect the problem and send them back through the portal.
|
||||
class CheckForPortalTrapTask extends BukkitRunnable
|
||||
{
|
||||
GriefPrevention instance;
|
||||
//player who recently teleported via nether portal
|
||||
private Player player;
|
||||
|
||||
//where to send the player back to if he hasn't left the portal frame
|
||||
private Location returnLocation;
|
||||
|
||||
public CheckForPortalTrapTask(Player player, GriefPrevention plugin, Location locationToReturn)
|
||||
{
|
||||
this.player = player;
|
||||
this.instance = plugin;
|
||||
this.returnLocation = locationToReturn;
|
||||
player.setMetadata("GP_PORTALRESCUE", new FixedMetadataValue(instance, locationToReturn));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if(player.isOnline() && player.getPortalCooldown() >= 10 && player.hasMetadata("GP_PORTALRESCUE"))
|
||||
{
|
||||
instance.AddLogEntry("Rescued " + player.getName() + " from a nether portal.\nTeleported from " + player.getLocation().toString() + " to " + returnLocation.toString(), CustomLogEntryTypes.Debug);
|
||||
player.teleport(returnLocation);
|
||||
player.removeMetadata("GP_PORTALRESCUE", instance);
|
||||
}
|
||||
GriefPrevention instance;
|
||||
//player who recently teleported via nether portal
|
||||
private Player player;
|
||||
|
||||
//where to send the player back to if he hasn't left the portal frame
|
||||
private Location returnLocation;
|
||||
|
||||
public CheckForPortalTrapTask(Player player, GriefPrevention plugin, Location locationToReturn)
|
||||
{
|
||||
this.player = player;
|
||||
this.instance = plugin;
|
||||
this.returnLocation = locationToReturn;
|
||||
player.setMetadata("GP_PORTALRESCUE", new FixedMetadataValue(instance, locationToReturn));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (player.isOnline() && player.getPortalCooldown() >= 10 && player.hasMetadata("GP_PORTALRESCUE"))
|
||||
{
|
||||
instance.AddLogEntry("Rescued " + player.getName() + " from a nether portal.\nTeleported from " + player.getLocation().toString() + " to " + returnLocation.toString(), CustomLogEntryTypes.Debug);
|
||||
player.teleport(returnLocation);
|
||||
player.removeMetadata("GP_PORTALRESCUE", instance);
|
||||
}
|
||||
instance.portalReturnTaskMap.remove(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -15,26 +15,26 @@
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
//basic enum stuff
|
||||
public enum ClaimPermission
|
||||
public enum ClaimPermission
|
||||
{
|
||||
Build,
|
||||
Inventory,
|
||||
Access;
|
||||
Build,
|
||||
Inventory,
|
||||
Access;
|
||||
|
||||
/**
|
||||
* Check if a ClaimPermission is granted by another ClaimPermission.
|
||||
*
|
||||
* @param other the ClaimPermission to compare against
|
||||
* @return true if this ClaimPermission is equal or lesser than the provided ClaimPermission
|
||||
*/
|
||||
public boolean isGrantedBy(ClaimPermission other)
|
||||
{
|
||||
// As this uses declaration order to compare, if trust levels are reordered this method must be rewritten.
|
||||
return other != null && other.ordinal() <= this.ordinal();
|
||||
}
|
||||
/**
|
||||
* Check if a ClaimPermission is granted by another ClaimPermission.
|
||||
*
|
||||
* @param other the ClaimPermission to compare against
|
||||
* @return true if this ClaimPermission is equal or lesser than the provided ClaimPermission
|
||||
*/
|
||||
public boolean isGrantedBy(ClaimPermission other)
|
||||
{
|
||||
// As this uses declaration order to compare, if trust levels are reordered this method must be rewritten.
|
||||
return other != null && other.ordinal() <= this.ordinal();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
|
@ -26,40 +26,40 @@ import java.util.UUID;
|
|||
//asynchronously loads player data without caching it in the datastore, then
|
||||
//passes those data to a claim cleanup task which might decide to delete a claim for inactivity
|
||||
|
||||
class CleanupUnusedClaimPreTask implements Runnable
|
||||
{
|
||||
private UUID ownerID = null;
|
||||
|
||||
CleanupUnusedClaimPreTask(UUID uuid)
|
||||
{
|
||||
this.ownerID = uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
//get the data
|
||||
PlayerData ownerData = GriefPrevention.instance.dataStore.getPlayerDataFromStorage(ownerID);
|
||||
OfflinePlayer ownerInfo = Bukkit.getServer().getOfflinePlayer(ownerID);
|
||||
class CleanupUnusedClaimPreTask implements Runnable
|
||||
{
|
||||
private UUID ownerID = null;
|
||||
|
||||
GriefPrevention.AddLogEntry("Looking for expired claims. Checking data for " + ownerID.toString(), CustomLogEntryTypes.Debug, true);
|
||||
|
||||
//expiration code uses last logout timestamp to decide whether to expire claims
|
||||
//don't expire claims for online players
|
||||
if(ownerInfo.isOnline())
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Player is online. Ignoring.", CustomLogEntryTypes.Debug, true);
|
||||
return;
|
||||
}
|
||||
if(ownerInfo.getLastPlayed() <= 0)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Player is new or not in the server's cached userdata. Ignoring. getLastPlayed = " + ownerInfo.getLastPlayed(), CustomLogEntryTypes.Debug, true);
|
||||
return;
|
||||
}
|
||||
|
||||
//skip claims belonging to exempted players based on block totals in config
|
||||
int bonusBlocks = ownerData.getBonusClaimBlocks();
|
||||
if(bonusBlocks >= GriefPrevention.instance.config_claims_expirationExemptionBonusBlocks || bonusBlocks + ownerData.getAccruedClaimBlocks() >= GriefPrevention.instance.config_claims_expirationExemptionTotalBlocks)
|
||||
CleanupUnusedClaimPreTask(UUID uuid)
|
||||
{
|
||||
this.ownerID = uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
//get the data
|
||||
PlayerData ownerData = GriefPrevention.instance.dataStore.getPlayerDataFromStorage(ownerID);
|
||||
OfflinePlayer ownerInfo = Bukkit.getServer().getOfflinePlayer(ownerID);
|
||||
|
||||
GriefPrevention.AddLogEntry("Looking for expired claims. Checking data for " + ownerID.toString(), CustomLogEntryTypes.Debug, true);
|
||||
|
||||
//expiration code uses last logout timestamp to decide whether to expire claims
|
||||
//don't expire claims for online players
|
||||
if (ownerInfo.isOnline())
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Player is online. Ignoring.", CustomLogEntryTypes.Debug, true);
|
||||
return;
|
||||
}
|
||||
if (ownerInfo.getLastPlayed() <= 0)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Player is new or not in the server's cached userdata. Ignoring. getLastPlayed = " + ownerInfo.getLastPlayed(), CustomLogEntryTypes.Debug, true);
|
||||
return;
|
||||
}
|
||||
|
||||
//skip claims belonging to exempted players based on block totals in config
|
||||
int bonusBlocks = ownerData.getBonusClaimBlocks();
|
||||
if (bonusBlocks >= GriefPrevention.instance.config_claims_expirationExemptionBonusBlocks || bonusBlocks + ownerData.getAccruedClaimBlocks() >= GriefPrevention.instance.config_claims_expirationExemptionTotalBlocks)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Player exempt from claim expiration based on claim block counts vs. config file settings.", CustomLogEntryTypes.Debug, true);
|
||||
return;
|
||||
|
|
@ -67,22 +67,22 @@ class CleanupUnusedClaimPreTask implements Runnable
|
|||
|
||||
Claim claimToExpire = null;
|
||||
|
||||
for (Claim claim : GriefPrevention.instance.dataStore.getClaims())
|
||||
{
|
||||
if (ownerID.equals(claim.ownerID))
|
||||
{
|
||||
claimToExpire = claim;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (Claim claim : GriefPrevention.instance.dataStore.getClaims())
|
||||
{
|
||||
if (ownerID.equals(claim.ownerID))
|
||||
{
|
||||
claimToExpire = claim;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (claimToExpire == null)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Unable to find a claim to expire for " + ownerID.toString(), CustomLogEntryTypes.Debug, false);
|
||||
return;
|
||||
}
|
||||
if (claimToExpire == null)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Unable to find a claim to expire for " + ownerID.toString(), CustomLogEntryTypes.Debug, false);
|
||||
return;
|
||||
}
|
||||
|
||||
//pass it back to the main server thread, where it's safe to delete a claim if needed
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, new CleanupUnusedClaimTask(claimToExpire, ownerData, ownerInfo), 1L);
|
||||
}
|
||||
//pass it back to the main server thread, where it's safe to delete a claim if needed
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, new CleanupUnusedClaimTask(claimToExpire, ownerData, ownerInfo), 1L);
|
||||
}
|
||||
}
|
||||
|
|
@ -15,134 +15,131 @@
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.events.ClaimExpirationEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.events.ClaimExpirationEvent;
|
||||
|
||||
class CleanupUnusedClaimTask implements Runnable
|
||||
{
|
||||
class CleanupUnusedClaimTask implements Runnable
|
||||
{
|
||||
Claim claim;
|
||||
PlayerData ownerData;
|
||||
OfflinePlayer ownerInfo;
|
||||
|
||||
CleanupUnusedClaimTask(Claim claim, PlayerData ownerData, OfflinePlayer ownerInfo)
|
||||
{
|
||||
this.claim = claim;
|
||||
this.ownerData = ownerData;
|
||||
this.ownerInfo = ownerInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
|
||||
|
||||
//determine area of the default chest claim
|
||||
int areaOfDefaultClaim = 0;
|
||||
if(GriefPrevention.instance.config_claims_automaticClaimsForNewPlayersRadius >= 0)
|
||||
{
|
||||
areaOfDefaultClaim = (int)Math.pow(GriefPrevention.instance.config_claims_automaticClaimsForNewPlayersRadius * 2 + 1, 2);
|
||||
}
|
||||
|
||||
//if this claim is a chest claim and those are set to expire
|
||||
if(claim.getArea() <= areaOfDefaultClaim && GriefPrevention.instance.config_claims_chestClaimExpirationDays > 0)
|
||||
{
|
||||
CleanupUnusedClaimTask(Claim claim, PlayerData ownerData, OfflinePlayer ownerInfo)
|
||||
{
|
||||
this.claim = claim;
|
||||
this.ownerData = ownerData;
|
||||
this.ownerInfo = ownerInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
|
||||
|
||||
//determine area of the default chest claim
|
||||
int areaOfDefaultClaim = 0;
|
||||
if (GriefPrevention.instance.config_claims_automaticClaimsForNewPlayersRadius >= 0)
|
||||
{
|
||||
areaOfDefaultClaim = (int) Math.pow(GriefPrevention.instance.config_claims_automaticClaimsForNewPlayersRadius * 2 + 1, 2);
|
||||
}
|
||||
|
||||
//if this claim is a chest claim and those are set to expire
|
||||
if (claim.getArea() <= areaOfDefaultClaim && GriefPrevention.instance.config_claims_chestClaimExpirationDays > 0)
|
||||
{
|
||||
//if the owner has been gone at least a week, and if he has ONLY the new player claim, it will be removed
|
||||
Calendar sevenDaysAgo = Calendar.getInstance();
|
||||
sevenDaysAgo.add(Calendar.DATE, -GriefPrevention.instance.config_claims_chestClaimExpirationDays);
|
||||
boolean newPlayerClaimsExpired = sevenDaysAgo.getTime().after(new Date(ownerInfo.getLastPlayed()));
|
||||
if(newPlayerClaimsExpired && ownerData.getClaims().size() == 1)
|
||||
{
|
||||
if (expireEventCanceled())
|
||||
return;
|
||||
claim.removeSurfaceFluids(null);
|
||||
GriefPrevention.instance.dataStore.deleteClaim(claim, true, true);
|
||||
|
||||
//if configured to do so, restore the land to natural
|
||||
if(GriefPrevention.instance.creativeRulesApply(claim.getLesserBoundaryCorner()) || GriefPrevention.instance.config_claims_survivalAutoNatureRestoration)
|
||||
{
|
||||
GriefPrevention.instance.restoreClaim(claim, 0);
|
||||
}
|
||||
|
||||
GriefPrevention.AddLogEntry(" " + claim.getOwnerName() + "'s new player claim expired.", CustomLogEntryTypes.AdminActivity);
|
||||
}
|
||||
}
|
||||
|
||||
//if configured to always remove claims after some inactivity period without exceptions...
|
||||
else if(GriefPrevention.instance.config_claims_expirationDays > 0)
|
||||
{
|
||||
Calendar earliestPermissibleLastLogin = Calendar.getInstance();
|
||||
earliestPermissibleLastLogin.add(Calendar.DATE, -GriefPrevention.instance.config_claims_expirationDays);
|
||||
|
||||
if(earliestPermissibleLastLogin.getTime().after(new Date(ownerInfo.getLastPlayed())))
|
||||
{
|
||||
if (expireEventCanceled())
|
||||
return;
|
||||
//make a copy of this player's claim list
|
||||
Vector<Claim> claims = new Vector<Claim>();
|
||||
for(int i = 0; i < ownerData.getClaims().size(); i++)
|
||||
{
|
||||
claims.add(ownerData.getClaims().get(i));
|
||||
}
|
||||
|
||||
//delete them
|
||||
GriefPrevention.instance.dataStore.deleteClaimsForPlayer(claim.ownerID, true);
|
||||
GriefPrevention.AddLogEntry(" All of " + claim.getOwnerName() + "'s claims have expired.", CustomLogEntryTypes.AdminActivity);
|
||||
|
||||
for(int i = 0; i < claims.size(); i++)
|
||||
{
|
||||
//if configured to do so, restore the land to natural
|
||||
if(GriefPrevention.instance.creativeRulesApply(claims.get(i).getLesserBoundaryCorner()) || GriefPrevention.instance.config_claims_survivalAutoNatureRestoration)
|
||||
{
|
||||
GriefPrevention.instance.restoreClaim(claims.get(i), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if(GriefPrevention.instance.config_claims_unusedClaimExpirationDays > 0 && GriefPrevention.instance.creativeRulesApply(claim.getLesserBoundaryCorner()))
|
||||
{
|
||||
//avoid scanning large claims and administrative claims
|
||||
if(claim.isAdminClaim() || claim.getWidth() > 25 || claim.getHeight() > 25) return;
|
||||
|
||||
//otherwise scan the claim content
|
||||
int minInvestment = 400;
|
||||
|
||||
long investmentScore = claim.getPlayerInvestmentScore();
|
||||
|
||||
if(investmentScore < minInvestment)
|
||||
{
|
||||
//if the owner has been gone at least a week, and if he has ONLY the new player claim, it will be removed
|
||||
Calendar sevenDaysAgo = Calendar.getInstance();
|
||||
sevenDaysAgo.add(Calendar.DATE, -GriefPrevention.instance.config_claims_unusedClaimExpirationDays);
|
||||
boolean claimExpired = sevenDaysAgo.getTime().after(new Date(ownerInfo.getLastPlayed()));
|
||||
if(claimExpired)
|
||||
{
|
||||
if (expireEventCanceled())
|
||||
return;
|
||||
GriefPrevention.instance.dataStore.deleteClaim(claim, true, true);
|
||||
GriefPrevention.AddLogEntry("Removed " + claim.getOwnerName() + "'s unused claim @ " + GriefPrevention.getfriendlyLocationString(claim.getLesserBoundaryCorner()), CustomLogEntryTypes.AdminActivity);
|
||||
|
||||
//restore the claim area to natural state
|
||||
GriefPrevention.instance.restoreClaim(claim, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Calendar sevenDaysAgo = Calendar.getInstance();
|
||||
sevenDaysAgo.add(Calendar.DATE, -GriefPrevention.instance.config_claims_chestClaimExpirationDays);
|
||||
boolean newPlayerClaimsExpired = sevenDaysAgo.getTime().after(new Date(ownerInfo.getLastPlayed()));
|
||||
if (newPlayerClaimsExpired && ownerData.getClaims().size() == 1)
|
||||
{
|
||||
if (expireEventCanceled())
|
||||
return;
|
||||
claim.removeSurfaceFluids(null);
|
||||
GriefPrevention.instance.dataStore.deleteClaim(claim, true, true);
|
||||
|
||||
public boolean expireEventCanceled()
|
||||
{
|
||||
//see if any other plugins don't want this claim deleted
|
||||
ClaimExpirationEvent event = new ClaimExpirationEvent(this.claim);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
return event.isCancelled();
|
||||
}
|
||||
//if configured to do so, restore the land to natural
|
||||
if (GriefPrevention.instance.creativeRulesApply(claim.getLesserBoundaryCorner()) || GriefPrevention.instance.config_claims_survivalAutoNatureRestoration)
|
||||
{
|
||||
GriefPrevention.instance.restoreClaim(claim, 0);
|
||||
}
|
||||
|
||||
GriefPrevention.AddLogEntry(" " + claim.getOwnerName() + "'s new player claim expired.", CustomLogEntryTypes.AdminActivity);
|
||||
}
|
||||
}
|
||||
|
||||
//if configured to always remove claims after some inactivity period without exceptions...
|
||||
else if (GriefPrevention.instance.config_claims_expirationDays > 0)
|
||||
{
|
||||
Calendar earliestPermissibleLastLogin = Calendar.getInstance();
|
||||
earliestPermissibleLastLogin.add(Calendar.DATE, -GriefPrevention.instance.config_claims_expirationDays);
|
||||
|
||||
if (earliestPermissibleLastLogin.getTime().after(new Date(ownerInfo.getLastPlayed())))
|
||||
{
|
||||
if (expireEventCanceled())
|
||||
return;
|
||||
//make a copy of this player's claim list
|
||||
Vector<Claim> claims = new Vector<Claim>();
|
||||
for (int i = 0; i < ownerData.getClaims().size(); i++)
|
||||
{
|
||||
claims.add(ownerData.getClaims().get(i));
|
||||
}
|
||||
|
||||
//delete them
|
||||
GriefPrevention.instance.dataStore.deleteClaimsForPlayer(claim.ownerID, true);
|
||||
GriefPrevention.AddLogEntry(" All of " + claim.getOwnerName() + "'s claims have expired.", CustomLogEntryTypes.AdminActivity);
|
||||
|
||||
for (int i = 0; i < claims.size(); i++)
|
||||
{
|
||||
//if configured to do so, restore the land to natural
|
||||
if (GriefPrevention.instance.creativeRulesApply(claims.get(i).getLesserBoundaryCorner()) || GriefPrevention.instance.config_claims_survivalAutoNatureRestoration)
|
||||
{
|
||||
GriefPrevention.instance.restoreClaim(claims.get(i), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (GriefPrevention.instance.config_claims_unusedClaimExpirationDays > 0 && GriefPrevention.instance.creativeRulesApply(claim.getLesserBoundaryCorner()))
|
||||
{
|
||||
//avoid scanning large claims and administrative claims
|
||||
if (claim.isAdminClaim() || claim.getWidth() > 25 || claim.getHeight() > 25) return;
|
||||
|
||||
//otherwise scan the claim content
|
||||
int minInvestment = 400;
|
||||
|
||||
long investmentScore = claim.getPlayerInvestmentScore();
|
||||
|
||||
if (investmentScore < minInvestment)
|
||||
{
|
||||
//if the owner has been gone at least a week, and if he has ONLY the new player claim, it will be removed
|
||||
Calendar sevenDaysAgo = Calendar.getInstance();
|
||||
sevenDaysAgo.add(Calendar.DATE, -GriefPrevention.instance.config_claims_unusedClaimExpirationDays);
|
||||
boolean claimExpired = sevenDaysAgo.getTime().after(new Date(ownerInfo.getLastPlayed()));
|
||||
if (claimExpired)
|
||||
{
|
||||
if (expireEventCanceled())
|
||||
return;
|
||||
GriefPrevention.instance.dataStore.deleteClaim(claim, true, true);
|
||||
GriefPrevention.AddLogEntry("Removed " + claim.getOwnerName() + "'s unused claim @ " + GriefPrevention.getfriendlyLocationString(claim.getLesserBoundaryCorner()), CustomLogEntryTypes.AdminActivity);
|
||||
|
||||
//restore the claim area to natural state
|
||||
GriefPrevention.instance.restoreClaim(claim, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean expireEventCanceled()
|
||||
{
|
||||
//see if any other plugins don't want this claim deleted
|
||||
ClaimExpirationEvent event = new ClaimExpirationEvent(this.claim);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
return event.isCancelled();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,12 +18,12 @@
|
|||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
public class CreateClaimResult
|
||||
public class CreateClaimResult
|
||||
{
|
||||
//whether or not the creation succeeded (it would fail if the new claim overlapped another existing claim)
|
||||
public boolean succeeded;
|
||||
|
||||
//when succeeded, this is a reference to the new claim
|
||||
//when failed, this is a reference to the pre-existing, conflicting claim
|
||||
public Claim claim;
|
||||
//whether or not the creation succeeded (it would fail if the new claim overlapped another existing claim)
|
||||
public boolean succeeded;
|
||||
|
||||
//when succeeded, this is a reference to the new claim
|
||||
//when failed, this is a reference to the pre-existing, conflicting claim
|
||||
public Claim claim;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,32 +29,28 @@ 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");
|
||||
private final SimpleDateFormat filenameFormat = new SimpleDateFormat("yyyy_MM_dd");
|
||||
private final String logFolderPath = DataStore.dataLayerFolderPath + File.separator + "Logs";
|
||||
private final int secondsBetweenWrites = 300;
|
||||
|
||||
|
||||
//stringbuilder is not thread safe, stringbuffer is
|
||||
private StringBuffer queuedEntries = new StringBuffer();
|
||||
|
||||
|
||||
CustomLogger()
|
||||
{
|
||||
//ensure log folder exists
|
||||
File logFolder = new File(this.logFolderPath);
|
||||
logFolder.mkdirs();
|
||||
|
||||
|
||||
//delete any outdated log files immediately
|
||||
this.DeleteExpiredLogs();
|
||||
|
||||
|
||||
//unless disabled, schedule recurring tasks
|
||||
int daysToKeepLogs = GriefPrevention.instance.config_logs_daysToKeep;
|
||||
if(daysToKeepLogs > 0)
|
||||
if (daysToKeepLogs > 0)
|
||||
{
|
||||
BukkitScheduler scheduler = GriefPrevention.instance.getServer().getScheduler();
|
||||
final long ticksPerSecond = 20L;
|
||||
|
|
@ -60,33 +59,38 @@ class CustomLogger
|
|||
scheduler.runTaskTimerAsynchronously(GriefPrevention.instance, new ExpiredLogRemover(), ticksPerDay, ticksPerDay);
|
||||
}
|
||||
}
|
||||
|
||||
private static final Pattern inlineFormatterPattern = Pattern.compile("§.");
|
||||
|
||||
private static final Pattern inlineFormatterPattern = Pattern.compile("§.");
|
||||
|
||||
void AddEntry(String entry, CustomLogEntryTypes entryType)
|
||||
{
|
||||
//if disabled, do nothing
|
||||
int daysToKeepLogs = GriefPrevention.instance.config_logs_daysToKeep;
|
||||
if(daysToKeepLogs == 0) return;
|
||||
|
||||
if (daysToKeepLogs == 0) return;
|
||||
|
||||
//if entry type is not enabled, do nothing
|
||||
if(!this.isEnabledType(entryType)) return;
|
||||
|
||||
if (!this.isEnabledType(entryType)) return;
|
||||
|
||||
//otherwise write to the in-memory buffer, after removing formatters
|
||||
Matcher matcher = inlineFormatterPattern.matcher(entry);
|
||||
entry = matcher.replaceAll("");
|
||||
String timestamp = this.timestampFormat.format(new Date());
|
||||
this.queuedEntries.append(timestamp + " " + entry + "\n");
|
||||
}
|
||||
|
||||
|
||||
private boolean isEnabledType(CustomLogEntryTypes entryType)
|
||||
{
|
||||
if(entryType == CustomLogEntryTypes.Exception) return true;
|
||||
if(entryType == CustomLogEntryTypes.SocialActivity && !GriefPrevention.instance.config_logs_socialEnabled) return false;
|
||||
if(entryType == CustomLogEntryTypes.SuspiciousActivity && !GriefPrevention.instance.config_logs_suspiciousEnabled) return false;
|
||||
if(entryType == CustomLogEntryTypes.AdminActivity && !GriefPrevention.instance.config_logs_adminEnabled) return false;
|
||||
if(entryType == CustomLogEntryTypes.Debug && !GriefPrevention.instance.config_logs_debugEnabled) return false;
|
||||
if(entryType == CustomLogEntryTypes.MutedChat && !GriefPrevention.instance.config_logs_mutedChatEnabled) return false;
|
||||
|
||||
if (entryType == CustomLogEntryTypes.Exception) return true;
|
||||
if (entryType == CustomLogEntryTypes.SocialActivity && !GriefPrevention.instance.config_logs_socialEnabled)
|
||||
return false;
|
||||
if (entryType == CustomLogEntryTypes.SuspiciousActivity && !GriefPrevention.instance.config_logs_suspiciousEnabled)
|
||||
return false;
|
||||
if (entryType == CustomLogEntryTypes.AdminActivity && !GriefPrevention.instance.config_logs_adminEnabled)
|
||||
return false;
|
||||
if (entryType == CustomLogEntryTypes.Debug && !GriefPrevention.instance.config_logs_debugEnabled) return false;
|
||||
if (entryType == CustomLogEntryTypes.MutedChat && !GriefPrevention.instance.config_logs_mutedChatEnabled)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -95,73 +99,73 @@ class CustomLogger
|
|||
try
|
||||
{
|
||||
//if nothing to write, stop here
|
||||
if(this.queuedEntries.length() == 0) return;
|
||||
|
||||
if (this.queuedEntries.length() == 0) return;
|
||||
|
||||
//determine filename based on date
|
||||
String filename = this.filenameFormat.format(new Date()) + ".log";
|
||||
String filename = this.filenameFormat.format(new Date()) + ".log";
|
||||
String filepath = this.logFolderPath + File.separator + filename;
|
||||
File logFile = new File(filepath);
|
||||
|
||||
|
||||
//dump content
|
||||
Files.append(this.queuedEntries.toString(), logFile, Charset.forName("UTF-8"));
|
||||
|
||||
|
||||
//in case of a failure to write the above due to exception,
|
||||
//the unwritten entries will remain the buffer for the next write to retry
|
||||
this.queuedEntries.setLength(0);
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void DeleteExpiredLogs()
|
||||
{
|
||||
try
|
||||
{
|
||||
//get list of log files
|
||||
File logFolder = new File(this.logFolderPath);
|
||||
File [] files = logFolder.listFiles();
|
||||
|
||||
File[] files = logFolder.listFiles();
|
||||
|
||||
//delete any created before x days ago
|
||||
int daysToKeepLogs = GriefPrevention.instance.config_logs_daysToKeep;
|
||||
Calendar expirationBoundary = Calendar.getInstance();
|
||||
expirationBoundary.add(Calendar.DATE, -daysToKeepLogs);
|
||||
for(int i = 0; i < files.length; i++)
|
||||
for (int i = 0; i < files.length; i++)
|
||||
{
|
||||
File file = files[i];
|
||||
if(file.isDirectory()) continue; //skip any folders
|
||||
|
||||
if (file.isDirectory()) continue; //skip any folders
|
||||
|
||||
String filename = file.getName().replace(".log", "");
|
||||
String [] dateParts = filename.split("_"); //format is yyyy_MM_dd
|
||||
if(dateParts.length != 3) continue;
|
||||
|
||||
String[] dateParts = filename.split("_"); //format is yyyy_MM_dd
|
||||
if (dateParts.length != 3) continue;
|
||||
|
||||
try
|
||||
{
|
||||
int year = Integer.parseInt(dateParts[0]);
|
||||
int month = Integer.parseInt(dateParts[1]) - 1;
|
||||
int day = Integer.parseInt(dateParts[2]);
|
||||
|
||||
|
||||
Calendar filedate = Calendar.getInstance();
|
||||
filedate.set(year, month, day);
|
||||
if(filedate.before(expirationBoundary))
|
||||
if (filedate.before(expirationBoundary))
|
||||
{
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
catch(NumberFormatException e)
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
//throw this away - effectively ignoring any files without the correct filename format
|
||||
GriefPrevention.AddLogEntry("Ignoring an unexpected file in the abridged logs folder: " + file.getName(), CustomLogEntryTypes.Debug, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//transfers the internal buffer to a log file
|
||||
private class EntryWriter implements Runnable
|
||||
{
|
||||
|
|
@ -171,7 +175,7 @@ class CustomLogger
|
|||
WriteEntries();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class ExpiredLogRemover implements Runnable
|
||||
{
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -18,16 +18,16 @@
|
|||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
public class CustomizableMessage
|
||||
public class CustomizableMessage
|
||||
{
|
||||
public Messages id;
|
||||
public String text;
|
||||
public String notes;
|
||||
|
||||
public CustomizableMessage(Messages id, String text, String notes)
|
||||
{
|
||||
this.id = id;
|
||||
this.text = text;
|
||||
this.notes = notes;
|
||||
}
|
||||
public Messages id;
|
||||
public String text;
|
||||
public String notes;
|
||||
|
||||
public CustomizableMessage(Messages id, String text, String notes)
|
||||
{
|
||||
this.id = id;
|
||||
this.text = text;
|
||||
this.notes = notes;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -16,13 +16,13 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import java.util.Collection;
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.events.AccrueClaimBlocksEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
//FEATURE: give players claim blocks for playing, as long as they're not away from their computer
|
||||
|
||||
//runs every 5 minutes in the main thread, grants blocks per hour / 12 to each online player who appears to be actively playing
|
||||
|
|
@ -43,13 +43,13 @@ class DeliverClaimBlocksTask implements Runnable
|
|||
public void run()
|
||||
{
|
||||
//if no player specified, this task will create a player-specific task for each online player, scheduled one tick apart
|
||||
if(this.player == null)
|
||||
if (this.player == null)
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<Player> players = (Collection<Player>)GriefPrevention.instance.getServer().getOnlinePlayers();
|
||||
Collection<Player> players = (Collection<Player>) GriefPrevention.instance.getServer().getOnlinePlayers();
|
||||
|
||||
long i = 0;
|
||||
for(Player onlinePlayer : players)
|
||||
for (Player onlinePlayer : players)
|
||||
{
|
||||
DeliverClaimBlocksTask newTask = new DeliverClaimBlocksTask(onlinePlayer, instance);
|
||||
instance.getServer().getScheduler().scheduleSyncDelayedTask(instance, newTask, i++);
|
||||
|
|
@ -59,7 +59,7 @@ class DeliverClaimBlocksTask implements Runnable
|
|||
}
|
||||
|
||||
//deliver claim blocks to the specified player
|
||||
if(!this.player.isOnline())
|
||||
if (!this.player.isOnline())
|
||||
{
|
||||
return; //player is not online to receive claim blocks
|
||||
}
|
||||
|
|
@ -76,7 +76,7 @@ class DeliverClaimBlocksTask implements Runnable
|
|||
isIdle = player.isInsideVehicle() || player.getLocation().getBlock().isLiquid() ||
|
||||
!(playerData.lastAfkCheckLocation == null || playerData.lastAfkCheckLocation.distanceSquared(player.getLocation()) > idleThresholdSquared);
|
||||
}
|
||||
catch(IllegalArgumentException ignore) //can't measure distance when to/from are different worlds
|
||||
catch (IllegalArgumentException ignore) //can't measure distance when to/from are different worlds
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -119,7 +119,7 @@ class DeliverClaimBlocksTask implements Runnable
|
|||
//many other operations will cause this player's data to save, including his eventual logout
|
||||
//dataStore.savePlayerData(player.getUniqueIdentifier(), playerData);
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Problem delivering claim blocks to player " + player.getName() + ":");
|
||||
e.printStackTrace();
|
||||
|
|
|
|||
|
|
@ -32,119 +32,116 @@ import java.util.List;
|
|||
|
||||
//this main thread task revisits the location of a partially chopped tree from several minutes ago
|
||||
//if any part of the tree is still there and nothing else has been built in its place, remove the remaining parts
|
||||
class EntityCleanupTask implements Runnable
|
||||
class EntityCleanupTask implements Runnable
|
||||
{
|
||||
//where to start cleaning in the list of entities
|
||||
private double percentageStart;
|
||||
|
||||
public EntityCleanupTask(double percentageStart)
|
||||
{
|
||||
this.percentageStart = percentageStart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
ArrayList<World> worlds = new ArrayList<World>();
|
||||
for(World world : GriefPrevention.instance.getServer().getWorlds())
|
||||
{
|
||||
if(GriefPrevention.instance.config_claims_worldModes.get(world) == ClaimsMode.Creative)
|
||||
{
|
||||
worlds.add(world);
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < worlds.size(); i++)
|
||||
{
|
||||
World world = worlds.get(i);
|
||||
|
||||
List<Entity> entities = world.getEntities();
|
||||
|
||||
//starting and stopping point. each execution of the task scans 10% of the server's (loaded) entities
|
||||
int j = (int)(entities.size() * this.percentageStart);
|
||||
int k = (int)(entities.size() * (this.percentageStart + .1));
|
||||
Claim cachedClaim = null;
|
||||
for(; j < entities.size() && j < k; j++)
|
||||
{
|
||||
Entity entity = entities.get(j);
|
||||
|
||||
boolean remove = false;
|
||||
if(entity instanceof Boat) //boats must be occupied
|
||||
{
|
||||
Boat boat = (Boat)entity;
|
||||
if(boat.isEmpty()) remove = true;
|
||||
}
|
||||
|
||||
else if(entity instanceof Vehicle)
|
||||
{
|
||||
Vehicle vehicle = (Vehicle)entity;
|
||||
|
||||
//minecarts in motion must be occupied by a player
|
||||
if(vehicle.getVelocity().lengthSquared() != 0)
|
||||
{
|
||||
if(vehicle.isEmpty() || !(vehicle.getPassenger() instanceof Player))
|
||||
{
|
||||
remove = true;
|
||||
}
|
||||
}
|
||||
|
||||
//stationary carts must be on rails
|
||||
else
|
||||
{
|
||||
Material material = world.getBlockAt(vehicle.getLocation()).getType();
|
||||
if(material != Material.RAIL && material != Material.POWERED_RAIL && material != Material.DETECTOR_RAIL)
|
||||
{
|
||||
remove = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//all non-player entities must be in claims
|
||||
else if(!(entity instanceof Player))
|
||||
{
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(entity.getLocation(), false, cachedClaim);
|
||||
if(claim != null)
|
||||
{
|
||||
cachedClaim = claim;
|
||||
}
|
||||
else
|
||||
{
|
||||
remove = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(remove)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Removing entity " + entity.getType().name() + " @ " + entity.getLocation(), CustomLogEntryTypes.Debug, true);
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//starting and stopping point. each execution of the task scans 5% of the server's claims
|
||||
List<Claim> claims = GriefPrevention.instance.dataStore.claims;
|
||||
int j = (int)(claims.size() * this.percentageStart);
|
||||
int k = (int)(claims.size() * (this.percentageStart + .05));
|
||||
for(; j < claims.size() && j < k; j++)
|
||||
{
|
||||
Claim claim = claims.get(j);
|
||||
|
||||
//if it's a creative mode claim
|
||||
if(GriefPrevention.instance.creativeRulesApply(claim.getLesserBoundaryCorner()))
|
||||
{
|
||||
//check its entity count and remove any extras
|
||||
claim.allowMoreEntities(true);
|
||||
}
|
||||
}
|
||||
|
||||
//schedule the next run of this task, in 3 minutes (20L is approximately 1 second)
|
||||
double nextRunPercentageStart = this.percentageStart + .05;
|
||||
if(nextRunPercentageStart > .99)
|
||||
{
|
||||
nextRunPercentageStart = 0;
|
||||
}
|
||||
|
||||
EntityCleanupTask task = new EntityCleanupTask(nextRunPercentageStart);
|
||||
GriefPrevention.instance.getServer().getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, task, 20L * 60 * 1);
|
||||
}
|
||||
//where to start cleaning in the list of entities
|
||||
private double percentageStart;
|
||||
|
||||
public EntityCleanupTask(double percentageStart)
|
||||
{
|
||||
this.percentageStart = percentageStart;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
ArrayList<World> worlds = new ArrayList<World>();
|
||||
for (World world : GriefPrevention.instance.getServer().getWorlds())
|
||||
{
|
||||
if (GriefPrevention.instance.config_claims_worldModes.get(world) == ClaimsMode.Creative)
|
||||
{
|
||||
worlds.add(world);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < worlds.size(); i++)
|
||||
{
|
||||
World world = worlds.get(i);
|
||||
|
||||
List<Entity> entities = world.getEntities();
|
||||
|
||||
//starting and stopping point. each execution of the task scans 10% of the server's (loaded) entities
|
||||
int j = (int) (entities.size() * this.percentageStart);
|
||||
int k = (int) (entities.size() * (this.percentageStart + .1));
|
||||
Claim cachedClaim = null;
|
||||
for (; j < entities.size() && j < k; j++)
|
||||
{
|
||||
Entity entity = entities.get(j);
|
||||
|
||||
boolean remove = false;
|
||||
if (entity instanceof Boat) //boats must be occupied
|
||||
{
|
||||
Boat boat = (Boat) entity;
|
||||
if (boat.isEmpty()) remove = true;
|
||||
} else if (entity instanceof Vehicle)
|
||||
{
|
||||
Vehicle vehicle = (Vehicle) entity;
|
||||
|
||||
//minecarts in motion must be occupied by a player
|
||||
if (vehicle.getVelocity().lengthSquared() != 0)
|
||||
{
|
||||
if (vehicle.isEmpty() || !(vehicle.getPassenger() instanceof Player))
|
||||
{
|
||||
remove = true;
|
||||
}
|
||||
}
|
||||
|
||||
//stationary carts must be on rails
|
||||
else
|
||||
{
|
||||
Material material = world.getBlockAt(vehicle.getLocation()).getType();
|
||||
if (material != Material.RAIL && material != Material.POWERED_RAIL && material != Material.DETECTOR_RAIL)
|
||||
{
|
||||
remove = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//all non-player entities must be in claims
|
||||
else if (!(entity instanceof Player))
|
||||
{
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(entity.getLocation(), false, cachedClaim);
|
||||
if (claim != null)
|
||||
{
|
||||
cachedClaim = claim;
|
||||
} else
|
||||
{
|
||||
remove = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (remove)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Removing entity " + entity.getType().name() + " @ " + entity.getLocation(), CustomLogEntryTypes.Debug, true);
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//starting and stopping point. each execution of the task scans 5% of the server's claims
|
||||
List<Claim> claims = GriefPrevention.instance.dataStore.claims;
|
||||
int j = (int) (claims.size() * this.percentageStart);
|
||||
int k = (int) (claims.size() * (this.percentageStart + .05));
|
||||
for (; j < claims.size() && j < k; j++)
|
||||
{
|
||||
Claim claim = claims.get(j);
|
||||
|
||||
//if it's a creative mode claim
|
||||
if (GriefPrevention.instance.creativeRulesApply(claim.getLesserBoundaryCorner()))
|
||||
{
|
||||
//check its entity count and remove any extras
|
||||
claim.allowMoreEntities(true);
|
||||
}
|
||||
}
|
||||
|
||||
//schedule the next run of this task, in 3 minutes (20L is approximately 1 second)
|
||||
double nextRunPercentageStart = this.percentageStart + .05;
|
||||
if (nextRunPercentageStart > .99)
|
||||
{
|
||||
nextRunPercentageStart = 0;
|
||||
}
|
||||
|
||||
EntityCleanupTask task = new EntityCleanupTask(nextRunPercentageStart);
|
||||
GriefPrevention.instance.getServer().getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, task, 20L * 60 * 1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -15,7 +15,7 @@
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
@ -24,55 +24,55 @@ import org.bukkit.inventory.EquipmentSlot;
|
|||
//tells a player about how many claim blocks he has, etc
|
||||
//implemented as a task so that it can be delayed
|
||||
//otherwise, it's spammy when players mouse-wheel past the shovel in their hot bars
|
||||
class EquipShovelProcessingTask implements Runnable
|
||||
class EquipShovelProcessingTask implements Runnable
|
||||
{
|
||||
//player data
|
||||
private Player player;
|
||||
|
||||
public EquipShovelProcessingTask(Player player)
|
||||
{
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
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;
|
||||
|
||||
PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId());
|
||||
|
||||
//player data
|
||||
private Player player;
|
||||
|
||||
public EquipShovelProcessingTask(Player player)
|
||||
{
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
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;
|
||||
|
||||
PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId());
|
||||
|
||||
//reset any work he might have been doing
|
||||
playerData.lastShovelLocation = null;
|
||||
playerData.claimResizing = null;
|
||||
|
||||
//always reset to basic claims mode
|
||||
if(playerData.shovelMode != ShovelMode.Basic)
|
||||
{
|
||||
|
||||
//always reset to basic claims mode
|
||||
if (playerData.shovelMode != ShovelMode.Basic)
|
||||
{
|
||||
playerData.shovelMode = ShovelMode.Basic;
|
||||
GriefPrevention.sendMessage(player, TextMode.Info, Messages.ShovelBasicClaimMode);
|
||||
}
|
||||
|
||||
//tell him how many claim blocks he has available
|
||||
|
||||
//tell him how many claim blocks he has available
|
||||
int remainingBlocks = playerData.getRemainingClaimBlocks();
|
||||
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.RemainingBlocks, String.valueOf(remainingBlocks));
|
||||
|
||||
//link to a video demo of land claiming, based on world type
|
||||
if(GriefPrevention.instance.creativeRulesApply(player.getLocation()))
|
||||
{
|
||||
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.CreativeBasicsVideo2, DataStore.CREATIVE_VIDEO_URL);
|
||||
}
|
||||
else if(GriefPrevention.instance.claimsEnabledForWorld(player.getLocation().getWorld()))
|
||||
{
|
||||
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.SurvivalBasicsVideo2, DataStore.SURVIVAL_VIDEO_URL);
|
||||
}
|
||||
|
||||
//if standing in a claim owned by the player, visualize it
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(player.getLocation(), true, playerData.lastClaim);
|
||||
if(claim != null && claim.allowEdit(player) == null)
|
||||
{
|
||||
playerData.lastClaim = claim;
|
||||
Visualization.Apply(player, Visualization.FromClaim(claim, player.getEyeLocation().getBlockY(), VisualizationType.Claim, player.getLocation()));
|
||||
}
|
||||
}
|
||||
|
||||
//link to a video demo of land claiming, based on world type
|
||||
if (GriefPrevention.instance.creativeRulesApply(player.getLocation()))
|
||||
{
|
||||
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.CreativeBasicsVideo2, DataStore.CREATIVE_VIDEO_URL);
|
||||
} else if (GriefPrevention.instance.claimsEnabledForWorld(player.getLocation().getWorld()))
|
||||
{
|
||||
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.SurvivalBasicsVideo2, DataStore.SURVIVAL_VIDEO_URL);
|
||||
}
|
||||
|
||||
//if standing in a claim owned by the player, visualize it
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(player.getLocation(), true, playerData.lastClaim);
|
||||
if (claim != null && claim.allowEdit(player) == null)
|
||||
{
|
||||
playerData.lastClaim = claim;
|
||||
Visualization.Apply(player, Visualization.FromClaim(claim, player.getEyeLocation().getBlockY(), VisualizationType.Claim, player.getLocation()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,47 +31,49 @@ import java.util.stream.Collectors;
|
|||
//...because the player has been gone a REALLY long time, and that expiration has been configured in config.yml
|
||||
|
||||
//runs every 1 minute in the main thread
|
||||
class FindUnusedClaimsTask implements Runnable
|
||||
class FindUnusedClaimsTask implements Runnable
|
||||
{
|
||||
private List<UUID> claimOwnerUUIDs;
|
||||
private Iterator<UUID> claimOwnerIterator;
|
||||
|
||||
FindUnusedClaimsTask()
|
||||
{
|
||||
refreshUUIDs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
//don't do anything when there are no claims
|
||||
if(claimOwnerUUIDs.isEmpty()) return;
|
||||
private List<UUID> claimOwnerUUIDs;
|
||||
private Iterator<UUID> claimOwnerIterator;
|
||||
|
||||
//wrap search around to beginning
|
||||
if(!claimOwnerIterator.hasNext())
|
||||
{
|
||||
refreshUUIDs();
|
||||
return;
|
||||
}
|
||||
|
||||
GriefPrevention.instance.getServer().getScheduler().runTaskAsynchronously(GriefPrevention.instance, new CleanupUnusedClaimPreTask(claimOwnerIterator.next()));
|
||||
}
|
||||
FindUnusedClaimsTask()
|
||||
{
|
||||
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());
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
//don't do anything when there are no claims
|
||||
if (claimOwnerUUIDs.isEmpty()) return;
|
||||
|
||||
if (!claimOwnerUUIDs.isEmpty()) {
|
||||
// Randomize order
|
||||
Collections.shuffle(claimOwnerUUIDs);
|
||||
}
|
||||
//wrap search around to beginning
|
||||
if (!claimOwnerIterator.hasNext())
|
||||
{
|
||||
refreshUUIDs();
|
||||
return;
|
||||
}
|
||||
|
||||
GriefPrevention.AddLogEntry("The following UUIDs own a claim and will be checked for inactivity in the following order:", CustomLogEntryTypes.Debug, true);
|
||||
GriefPrevention.instance.getServer().getScheduler().runTaskAsynchronously(GriefPrevention.instance, new CleanupUnusedClaimPreTask(claimOwnerIterator.next()));
|
||||
}
|
||||
|
||||
for (UUID uuid : claimOwnerUUIDs)
|
||||
GriefPrevention.AddLogEntry(uuid.toString(), CustomLogEntryTypes.Debug, true);
|
||||
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());
|
||||
|
||||
claimOwnerIterator = claimOwnerUUIDs.iterator();
|
||||
}
|
||||
if (!claimOwnerUUIDs.isEmpty())
|
||||
{
|
||||
// Randomize order
|
||||
Collections.shuffle(claimOwnerUUIDs);
|
||||
}
|
||||
|
||||
GriefPrevention.AddLogEntry("The following UUIDs own a claim and will be checked for inactivity in the following order:", CustomLogEntryTypes.Debug, true);
|
||||
|
||||
for (UUID uuid : claimOwnerUUIDs)
|
||||
GriefPrevention.AddLogEntry(uuid.toString(), CustomLogEntryTypes.Debug, true);
|
||||
|
||||
claimOwnerIterator = claimOwnerUUIDs.iterator();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
|
@ -1,51 +1,51 @@
|
|||
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
|
||||
{
|
||||
private UUID playerToLoad;
|
||||
private ConcurrentHashMap<UUID, Boolean> destinationMap;
|
||||
|
||||
|
||||
IgnoreLoaderThread(UUID playerToLoad, ConcurrentHashMap<UUID, Boolean> destinationMap)
|
||||
{
|
||||
this.playerToLoad = playerToLoad;
|
||||
this.destinationMap = destinationMap;
|
||||
this.setPriority(MIN_PRIORITY);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
File ignoreFile = new File(DataStore.playerDataFolderPath + File.separator + this.playerToLoad + ".ignore");
|
||||
|
||||
|
||||
//if the file doesn't exist, there's nothing to do here
|
||||
if(!ignoreFile.exists()) return;
|
||||
|
||||
if (!ignoreFile.exists()) return;
|
||||
|
||||
boolean needRetry = false;
|
||||
int retriesRemaining = 5;
|
||||
Exception latestException = null;
|
||||
do
|
||||
{
|
||||
try
|
||||
{
|
||||
{
|
||||
needRetry = false;
|
||||
|
||||
|
||||
//read the file content and immediately close it
|
||||
List<String> lines = Files.readLines(ignoreFile, Charset.forName("UTF-8"));
|
||||
|
||||
|
||||
//each line is one ignore. asterisks indicate administrative ignores
|
||||
for(String line : lines)
|
||||
for (String line : lines)
|
||||
{
|
||||
boolean adminIgnore = false;
|
||||
if(line.startsWith("*"))
|
||||
if (line.startsWith("*"))
|
||||
{
|
||||
adminIgnore = true;
|
||||
line = line.substring(1);
|
||||
|
|
@ -55,28 +55,28 @@ class IgnoreLoaderThread extends Thread
|
|||
UUID ignoredUUID = UUID.fromString(line);
|
||||
this.destinationMap.put(ignoredUUID, adminIgnore);
|
||||
}
|
||||
catch(IllegalArgumentException e){} //if a bad UUID, ignore the line
|
||||
catch (IllegalArgumentException e) {} //if a bad UUID, ignore the line
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//if there's any problem with the file's content, retry up to 5 times with 5 milliseconds between
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
latestException = e;
|
||||
needRetry = true;
|
||||
retriesRemaining--;
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
if(needRetry) Thread.sleep(5);
|
||||
if (needRetry) Thread.sleep(5);
|
||||
}
|
||||
catch(InterruptedException exception) {}
|
||||
|
||||
}while(needRetry && retriesRemaining >= 0);
|
||||
|
||||
catch (InterruptedException exception) {}
|
||||
|
||||
} while (needRetry && retriesRemaining >= 0);
|
||||
|
||||
//if last attempt failed, log information about the problem
|
||||
if(needRetry)
|
||||
if (needRetry)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Retry attempts exhausted. Unable to load ignore data for player \"" + playerToLoad.toString() + "\": " + latestException.toString());
|
||||
latestException.printStackTrace();
|
||||
|
|
|
|||
|
|
@ -22,14 +22,14 @@ import java.net.InetAddress;
|
|||
|
||||
public class IpBanInfo
|
||||
{
|
||||
InetAddress address;
|
||||
long expirationTimestamp;
|
||||
String bannedAccountName;
|
||||
|
||||
IpBanInfo(InetAddress address, long expirationTimestamp, String bannedAccountName)
|
||||
{
|
||||
this.address = address;
|
||||
this.expirationTimestamp = expirationTimestamp;
|
||||
this.bannedAccountName = bannedAccountName;
|
||||
}
|
||||
InetAddress address;
|
||||
long expirationTimestamp;
|
||||
String bannedAccountName;
|
||||
|
||||
IpBanInfo(InetAddress address, long expirationTimestamp, String bannedAccountName)
|
||||
{
|
||||
this.address = address;
|
||||
this.expirationTimestamp = expirationTimestamp;
|
||||
this.bannedAccountName = bannedAccountName;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,31 +24,31 @@ import java.util.Set;
|
|||
//ordered list of material info objects, for fast searching
|
||||
public class MaterialCollection
|
||||
{
|
||||
Set<MaterialInfo> materials = new HashSet<MaterialInfo>();
|
||||
|
||||
void Add(MaterialInfo material)
|
||||
{
|
||||
this.materials.add(material);
|
||||
}
|
||||
|
||||
boolean Contains(MaterialInfo material)
|
||||
{
|
||||
return this.materials.contains(material);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return materials.toString();
|
||||
}
|
||||
|
||||
public int size()
|
||||
{
|
||||
return this.materials.size();
|
||||
}
|
||||
Set<MaterialInfo> materials = new HashSet<MaterialInfo>();
|
||||
|
||||
public void clear()
|
||||
{
|
||||
this.materials.clear();
|
||||
}
|
||||
void Add(MaterialInfo material)
|
||||
{
|
||||
this.materials.add(material);
|
||||
}
|
||||
|
||||
boolean Contains(MaterialInfo material)
|
||||
{
|
||||
return this.materials.contains(material);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return materials.toString();
|
||||
}
|
||||
|
||||
public int size()
|
||||
{
|
||||
return this.materials.size();
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
this.materials.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,73 +24,72 @@ import org.bukkit.Material;
|
|||
|
||||
public class MaterialInfo
|
||||
{
|
||||
Material typeID;
|
||||
byte data;
|
||||
boolean allDataValues;
|
||||
String description;
|
||||
|
||||
public MaterialInfo(Material typeID, byte data, String description)
|
||||
{
|
||||
this.typeID = typeID;
|
||||
this.data = data;
|
||||
this.allDataValues = false;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public MaterialInfo(Material typeID, String description)
|
||||
{
|
||||
this.typeID = typeID;
|
||||
this.data = 0;
|
||||
this.allDataValues = true;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
private MaterialInfo(Material typeID, byte data, boolean allDataValues, String description)
|
||||
{
|
||||
this.typeID = typeID;
|
||||
this.data = data;
|
||||
this.allDataValues = allDataValues;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
String returnValue = String.valueOf(this.typeID) + ":" + (this.allDataValues?"*":String.valueOf(this.data));
|
||||
if(this.description != null) returnValue += ":" + this.description;
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
public static MaterialInfo fromString(String string)
|
||||
{
|
||||
if(string == null || string.isEmpty()) return null;
|
||||
|
||||
String [] parts = string.split(":");
|
||||
if(parts.length < 3) return null;
|
||||
|
||||
try
|
||||
{
|
||||
Material typeID = Material.matchMaterial(parts[0]);
|
||||
|
||||
byte data;
|
||||
boolean allDataValues;
|
||||
if(parts[1].equals("*"))
|
||||
{
|
||||
allDataValues = true;
|
||||
data = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
allDataValues = false;
|
||||
data = Byte.parseByte(parts[1]);
|
||||
}
|
||||
|
||||
return new MaterialInfo(typeID, data, allDataValues, parts[2]);
|
||||
}
|
||||
catch(NumberFormatException exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Material typeID;
|
||||
byte data;
|
||||
boolean allDataValues;
|
||||
String description;
|
||||
|
||||
public MaterialInfo(Material typeID, byte data, String description)
|
||||
{
|
||||
this.typeID = typeID;
|
||||
this.data = data;
|
||||
this.allDataValues = false;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public MaterialInfo(Material typeID, String description)
|
||||
{
|
||||
this.typeID = typeID;
|
||||
this.data = 0;
|
||||
this.allDataValues = true;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
private MaterialInfo(Material typeID, byte data, boolean allDataValues, String description)
|
||||
{
|
||||
this.typeID = typeID;
|
||||
this.data = data;
|
||||
this.allDataValues = allDataValues;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
String returnValue = String.valueOf(this.typeID) + ":" + (this.allDataValues ? "*" : String.valueOf(this.data));
|
||||
if (this.description != null) returnValue += ":" + this.description;
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
public static MaterialInfo fromString(String string)
|
||||
{
|
||||
if (string == null || string.isEmpty()) return null;
|
||||
|
||||
String[] parts = string.split(":");
|
||||
if (parts.length < 3) return null;
|
||||
|
||||
try
|
||||
{
|
||||
Material typeID = Material.matchMaterial(parts[0]);
|
||||
|
||||
byte data;
|
||||
boolean allDataValues;
|
||||
if (parts[1].equals("*"))
|
||||
{
|
||||
allDataValues = true;
|
||||
data = 0;
|
||||
} else
|
||||
{
|
||||
allDataValues = false;
|
||||
data = Byte.parseByte(parts[1]);
|
||||
}
|
||||
|
||||
return new MaterialInfo(typeID, data, allDataValues, parts[2]);
|
||||
}
|
||||
catch (NumberFormatException exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,17 @@
|
|||
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;
|
||||
public UUID owner;
|
||||
long expirationTimestamp;
|
||||
ItemStack itemStack;
|
||||
|
||||
|
||||
public PendingItemProtection(Location location, UUID owner, long expirationTimestamp, ItemStack itemStack)
|
||||
{
|
||||
this.location = location;
|
||||
|
|
|
|||
|
|
@ -17,184 +17,176 @@
|
|||
*/
|
||||
|
||||
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
|
||||
public class PlayerData
|
||||
{
|
||||
//the player's ID
|
||||
public UUID playerID;
|
||||
|
||||
//the player's claims
|
||||
private Vector<Claim> claims = null;
|
||||
|
||||
//how many claim blocks the player has earned via play time
|
||||
private Integer accruedClaimBlocks = null;
|
||||
|
||||
//temporary holding area to avoid opening data files too early
|
||||
private int newlyAccruedClaimBlocks = 0;
|
||||
|
||||
//where this player was the last time we checked on him for earning claim blocks
|
||||
public Location lastAfkCheckLocation = null;
|
||||
|
||||
//how many claim blocks the player has been gifted by admins, or purchased via economy integration
|
||||
private Integer bonusClaimBlocks = null;
|
||||
|
||||
//what "mode" the shovel is in determines what it will do when it's used
|
||||
public ShovelMode shovelMode = ShovelMode.Basic;
|
||||
|
||||
//radius for restore nature fill mode
|
||||
int fillRadius = 0;
|
||||
|
||||
//last place the player used the shovel, useful in creating and resizing claims,
|
||||
//because the player must use the shovel twice in those instances
|
||||
public Location lastShovelLocation = null;
|
||||
|
||||
//the claim this player is currently resizing
|
||||
public Claim claimResizing = null;
|
||||
|
||||
//the claim this player is currently subdividing
|
||||
public Claim claimSubdividing = null;
|
||||
|
||||
//whether or not the player has a pending /trapped rescue
|
||||
public boolean pendingTrapped = false;
|
||||
|
||||
//whether this player was recently warned about building outside land claims
|
||||
boolean warnedAboutBuildingOutsideClaims = false;
|
||||
|
||||
//timestamp when last siege ended (where this player was the defender)
|
||||
long lastSiegeEndTimeStamp = 0;
|
||||
|
||||
//whether the player was kicked (set and used during logout)
|
||||
boolean wasKicked = false;
|
||||
|
||||
//visualization
|
||||
public Visualization currentVisualization = null;
|
||||
|
||||
//anti-camping pvp protection
|
||||
public boolean pvpImmune = false;
|
||||
public long lastSpawn = 0;
|
||||
|
||||
//ignore claims mode
|
||||
public boolean ignoreClaims = false;
|
||||
|
||||
//the last claim this player was in, that we know of
|
||||
public Claim lastClaim = null;
|
||||
|
||||
//siege
|
||||
public SiegeData siegeData = null;
|
||||
|
||||
//pvp
|
||||
public long lastPvpTimestamp = 0;
|
||||
public String lastPvpPlayer = "";
|
||||
|
||||
//safety confirmation for deleting multi-subdivision claims
|
||||
public boolean warnedAboutMajorDeletion = false;
|
||||
//the player's ID
|
||||
public UUID playerID;
|
||||
|
||||
public InetAddress ipAddress;
|
||||
//the player's claims
|
||||
private Vector<Claim> claims = null;
|
||||
|
||||
//how many claim blocks the player has earned via play time
|
||||
private Integer accruedClaimBlocks = null;
|
||||
|
||||
//temporary holding area to avoid opening data files too early
|
||||
private int newlyAccruedClaimBlocks = 0;
|
||||
|
||||
//where this player was the last time we checked on him for earning claim blocks
|
||||
public Location lastAfkCheckLocation = null;
|
||||
|
||||
//how many claim blocks the player has been gifted by admins, or purchased via economy integration
|
||||
private Integer bonusClaimBlocks = null;
|
||||
|
||||
//what "mode" the shovel is in determines what it will do when it's used
|
||||
public ShovelMode shovelMode = ShovelMode.Basic;
|
||||
|
||||
//radius for restore nature fill mode
|
||||
int fillRadius = 0;
|
||||
|
||||
//last place the player used the shovel, useful in creating and resizing claims,
|
||||
//because the player must use the shovel twice in those instances
|
||||
public Location lastShovelLocation = null;
|
||||
|
||||
//the claim this player is currently resizing
|
||||
public Claim claimResizing = null;
|
||||
|
||||
//the claim this player is currently subdividing
|
||||
public Claim claimSubdividing = null;
|
||||
|
||||
//whether or not the player has a pending /trapped rescue
|
||||
public boolean pendingTrapped = false;
|
||||
|
||||
//whether this player was recently warned about building outside land claims
|
||||
boolean warnedAboutBuildingOutsideClaims = false;
|
||||
|
||||
//timestamp when last siege ended (where this player was the defender)
|
||||
long lastSiegeEndTimeStamp = 0;
|
||||
|
||||
//whether the player was kicked (set and used during logout)
|
||||
boolean wasKicked = false;
|
||||
|
||||
//visualization
|
||||
public Visualization currentVisualization = null;
|
||||
|
||||
//anti-camping pvp protection
|
||||
public boolean pvpImmune = false;
|
||||
public long lastSpawn = 0;
|
||||
|
||||
//ignore claims mode
|
||||
public boolean ignoreClaims = false;
|
||||
|
||||
//the last claim this player was in, that we know of
|
||||
public Claim lastClaim = null;
|
||||
|
||||
//siege
|
||||
public SiegeData siegeData = null;
|
||||
|
||||
//pvp
|
||||
public long lastPvpTimestamp = 0;
|
||||
public String lastPvpPlayer = "";
|
||||
|
||||
//safety confirmation for deleting multi-subdivision claims
|
||||
public boolean warnedAboutMajorDeletion = false;
|
||||
|
||||
public InetAddress ipAddress;
|
||||
|
||||
//for addons to set per-player claim limits. Any negative value will use config's value
|
||||
private int AccruedClaimBlocksLimit = -1;
|
||||
|
||||
//whether or not this player has received a message about unlocking death drops since his last death
|
||||
boolean receivedDropUnlockAdvertisement = false;
|
||||
boolean receivedDropUnlockAdvertisement = false;
|
||||
|
||||
//whether or not this player's dropped items (on death) are unlocked for other players to pick up
|
||||
boolean dropsAreUnlocked = false;
|
||||
boolean dropsAreUnlocked = false;
|
||||
|
||||
//message to send to player after he respawns
|
||||
String messageOnRespawn = null;
|
||||
String messageOnRespawn = null;
|
||||
|
||||
//player which a pet will be given to when it's right-clicked
|
||||
OfflinePlayer petGiveawayRecipient = null;
|
||||
|
||||
//timestamp for last "you're building outside your land claims" message
|
||||
Long buildWarningTimestamp = null;
|
||||
|
||||
//spot where a player can't talk, used to mute new players until they've moved a little
|
||||
//this is an anti-bot strategy.
|
||||
Location noChatLocation = null;
|
||||
|
||||
//ignore list
|
||||
//true means invisible (admin-forced ignore), false means player-created ignore
|
||||
public ConcurrentHashMap<UUID, Boolean> ignoredPlayers = new ConcurrentHashMap<UUID, Boolean>();
|
||||
public boolean ignoreListChanged = false;
|
||||
OfflinePlayer petGiveawayRecipient = null;
|
||||
|
||||
//timestamp for last "you're building outside your land claims" message
|
||||
Long buildWarningTimestamp = null;
|
||||
|
||||
//spot where a player can't talk, used to mute new players until they've moved a little
|
||||
//this is an anti-bot strategy.
|
||||
Location noChatLocation = null;
|
||||
|
||||
//ignore list
|
||||
//true means invisible (admin-forced ignore), false means player-created ignore
|
||||
public ConcurrentHashMap<UUID, Boolean> ignoredPlayers = new ConcurrentHashMap<UUID, Boolean>();
|
||||
public boolean ignoreListChanged = false;
|
||||
|
||||
//profanity warning, once per play session
|
||||
boolean profanityWarned = false;
|
||||
boolean profanityWarned = false;
|
||||
|
||||
//whether or not this player is "in" pvp combat
|
||||
public boolean inPvpCombat()
|
||||
{
|
||||
if(this.lastPvpTimestamp == 0) return false;
|
||||
|
||||
long now = Calendar.getInstance().getTimeInMillis();
|
||||
|
||||
long elapsed = now - this.lastPvpTimestamp;
|
||||
|
||||
if(elapsed > GriefPrevention.instance.config_pvp_combatTimeoutSeconds * 1000) //X seconds
|
||||
{
|
||||
this.lastPvpTimestamp = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//the number of claim blocks a player has available for claiming land
|
||||
public int getRemainingClaimBlocks()
|
||||
{
|
||||
int remainingBlocks = this.getAccruedClaimBlocks() + this.getBonusClaimBlocks() + GriefPrevention.instance.dataStore.getGroupBonusBlocks(this.playerID);
|
||||
for(int i = 0; i < this.getClaims().size(); i++)
|
||||
{
|
||||
Claim claim = this.getClaims().get(i);
|
||||
remainingBlocks -= claim.getArea();
|
||||
}
|
||||
|
||||
return remainingBlocks;
|
||||
}
|
||||
|
||||
//don't load data from secondary storage until it's needed
|
||||
public synchronized int getAccruedClaimBlocks()
|
||||
{
|
||||
if(this.accruedClaimBlocks == null) this.loadDataFromSecondaryStorage();
|
||||
|
||||
//update claim blocks with any he has accrued during his current play session
|
||||
if(this.newlyAccruedClaimBlocks > 0)
|
||||
{
|
||||
int accruedLimit = this.getAccruedClaimBlocksLimit();
|
||||
|
||||
//if over the limit before adding blocks, leave it as-is, because the limit may have changed AFTER he accrued the blocks
|
||||
if(this.accruedClaimBlocks < accruedLimit)
|
||||
{
|
||||
//move any in the holding area
|
||||
int newTotal = this.accruedClaimBlocks + this.newlyAccruedClaimBlocks;
|
||||
|
||||
//respect limits
|
||||
this.accruedClaimBlocks = Math.min(newTotal, accruedLimit);
|
||||
}
|
||||
|
||||
this.newlyAccruedClaimBlocks = 0;
|
||||
return this.accruedClaimBlocks;
|
||||
}
|
||||
|
||||
return accruedClaimBlocks;
|
||||
//whether or not this player is "in" pvp combat
|
||||
public boolean inPvpCombat()
|
||||
{
|
||||
if (this.lastPvpTimestamp == 0) return false;
|
||||
|
||||
long now = Calendar.getInstance().getTimeInMillis();
|
||||
|
||||
long elapsed = now - this.lastPvpTimestamp;
|
||||
|
||||
if (elapsed > GriefPrevention.instance.config_pvp_combatTimeoutSeconds * 1000) //X seconds
|
||||
{
|
||||
this.lastPvpTimestamp = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//the number of claim blocks a player has available for claiming land
|
||||
public int getRemainingClaimBlocks()
|
||||
{
|
||||
int remainingBlocks = this.getAccruedClaimBlocks() + this.getBonusClaimBlocks() + GriefPrevention.instance.dataStore.getGroupBonusBlocks(this.playerID);
|
||||
for (int i = 0; i < this.getClaims().size(); i++)
|
||||
{
|
||||
Claim claim = this.getClaims().get(i);
|
||||
remainingBlocks -= claim.getArea();
|
||||
}
|
||||
|
||||
return remainingBlocks;
|
||||
}
|
||||
|
||||
//don't load data from secondary storage until it's needed
|
||||
public synchronized int getAccruedClaimBlocks()
|
||||
{
|
||||
if (this.accruedClaimBlocks == null) this.loadDataFromSecondaryStorage();
|
||||
|
||||
//update claim blocks with any he has accrued during his current play session
|
||||
if (this.newlyAccruedClaimBlocks > 0)
|
||||
{
|
||||
int accruedLimit = this.getAccruedClaimBlocksLimit();
|
||||
|
||||
//if over the limit before adding blocks, leave it as-is, because the limit may have changed AFTER he accrued the blocks
|
||||
if (this.accruedClaimBlocks < accruedLimit)
|
||||
{
|
||||
//move any in the holding area
|
||||
int newTotal = this.accruedClaimBlocks + this.newlyAccruedClaimBlocks;
|
||||
|
||||
//respect limits
|
||||
this.accruedClaimBlocks = Math.min(newTotal, accruedLimit);
|
||||
}
|
||||
|
||||
this.newlyAccruedClaimBlocks = 0;
|
||||
return this.accruedClaimBlocks;
|
||||
}
|
||||
|
||||
return accruedClaimBlocks;
|
||||
}
|
||||
|
||||
public void setAccruedClaimBlocks(Integer accruedClaimBlocks)
|
||||
|
|
@ -205,7 +197,7 @@ public class PlayerData
|
|||
|
||||
public int getBonusClaimBlocks()
|
||||
{
|
||||
if(this.bonusClaimBlocks == null) this.loadDataFromSecondaryStorage();
|
||||
if (this.bonusClaimBlocks == null) this.loadDataFromSecondaryStorage();
|
||||
return bonusClaimBlocks;
|
||||
}
|
||||
|
||||
|
|
@ -213,89 +205,87 @@ public class PlayerData
|
|||
{
|
||||
this.bonusClaimBlocks = bonusClaimBlocks;
|
||||
}
|
||||
|
||||
|
||||
private void loadDataFromSecondaryStorage()
|
||||
{
|
||||
//reach out to secondary storage to get any data there
|
||||
PlayerData storageData = GriefPrevention.instance.dataStore.getPlayerDataFromStorage(this.playerID);
|
||||
|
||||
if(this.accruedClaimBlocks == null)
|
||||
|
||||
if (this.accruedClaimBlocks == null)
|
||||
{
|
||||
if(storageData.accruedClaimBlocks != null)
|
||||
if (storageData.accruedClaimBlocks != null)
|
||||
{
|
||||
this.accruedClaimBlocks = storageData.accruedClaimBlocks;
|
||||
|
||||
//ensure at least minimum accrued are accrued (in case of settings changes to increase initial amount)
|
||||
if(GriefPrevention.instance.config_advanced_fixNegativeClaimblockAmounts && (this.accruedClaimBlocks < GriefPrevention.instance.config_claims_initialBlocks))
|
||||
if (GriefPrevention.instance.config_advanced_fixNegativeClaimblockAmounts && (this.accruedClaimBlocks < GriefPrevention.instance.config_claims_initialBlocks))
|
||||
{
|
||||
this.accruedClaimBlocks = GriefPrevention.instance.config_claims_initialBlocks;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
|
||||
} else
|
||||
{
|
||||
this.accruedClaimBlocks = GriefPrevention.instance.config_claims_initialBlocks;
|
||||
}
|
||||
}
|
||||
|
||||
if(this.bonusClaimBlocks == null)
|
||||
|
||||
if (this.bonusClaimBlocks == null)
|
||||
{
|
||||
if(storageData.bonusClaimBlocks != null)
|
||||
if (storageData.bonusClaimBlocks != null)
|
||||
{
|
||||
this.bonusClaimBlocks = storageData.bonusClaimBlocks;
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
this.bonusClaimBlocks = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Vector<Claim> getClaims()
|
||||
{
|
||||
if(this.claims == null)
|
||||
if (this.claims == null)
|
||||
{
|
||||
this.claims = new Vector<Claim>();
|
||||
|
||||
|
||||
//find all the claims belonging to this player and note them for future reference
|
||||
DataStore dataStore = GriefPrevention.instance.dataStore;
|
||||
int totalClaimsArea = 0;
|
||||
for(int i = 0; i < dataStore.claims.size(); i++)
|
||||
for (int i = 0; i < dataStore.claims.size(); i++)
|
||||
{
|
||||
Claim claim = dataStore.claims.get(i);
|
||||
if(!claim.inDataStore)
|
||||
if (!claim.inDataStore)
|
||||
{
|
||||
dataStore.claims.remove(i--);
|
||||
continue;
|
||||
}
|
||||
if(playerID.equals(claim.ownerID))
|
||||
if (playerID.equals(claim.ownerID))
|
||||
{
|
||||
this.claims.add(claim);
|
||||
totalClaimsArea += claim.getArea();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//ensure player has claim blocks for his claims, and at least the minimum accrued
|
||||
this.loadDataFromSecondaryStorage();
|
||||
|
||||
|
||||
//if total claimed area is more than total blocks available
|
||||
int totalBlocks = this.accruedClaimBlocks + this.getBonusClaimBlocks() + GriefPrevention.instance.dataStore.getGroupBonusBlocks(this.playerID);
|
||||
if(GriefPrevention.instance.config_advanced_fixNegativeClaimblockAmounts && totalBlocks < totalClaimsArea)
|
||||
if (GriefPrevention.instance.config_advanced_fixNegativeClaimblockAmounts && totalBlocks < totalClaimsArea)
|
||||
{
|
||||
OfflinePlayer player = GriefPrevention.instance.getServer().getOfflinePlayer(this.playerID);
|
||||
GriefPrevention.AddLogEntry(player.getName() + " has more claimed land than blocks available. Adding blocks to fix.", CustomLogEntryTypes.Debug, true);
|
||||
GriefPrevention.AddLogEntry(player.getName() + " Accrued blocks: " + this.getAccruedClaimBlocks() + " Bonus blocks: " + this.getBonusClaimBlocks(), CustomLogEntryTypes.Debug, true);
|
||||
GriefPrevention.AddLogEntry("Total blocks: " + totalBlocks + " Total claimed area: " + totalClaimsArea, CustomLogEntryTypes.Debug, true);
|
||||
for(Claim claim : this.claims)
|
||||
for (Claim claim : this.claims)
|
||||
{
|
||||
if(!claim.inDataStore) continue;
|
||||
if (!claim.inDataStore) continue;
|
||||
GriefPrevention.AddLogEntry(
|
||||
GriefPrevention.getfriendlyLocationString(claim.getLesserBoundaryCorner()) + " // "
|
||||
+ GriefPrevention.getfriendlyLocationString(claim.getGreaterBoundaryCorner()) + " = "
|
||||
+ claim.getArea()
|
||||
+ GriefPrevention.getfriendlyLocationString(claim.getGreaterBoundaryCorner()) + " = "
|
||||
+ claim.getArea()
|
||||
, CustomLogEntryTypes.Debug, true);
|
||||
}
|
||||
|
||||
|
||||
//try to fix it by adding to accrued blocks
|
||||
this.accruedClaimBlocks = totalClaimsArea; //Set accrued blocks to equal total claims
|
||||
int accruedLimit = this.getAccruedClaimBlocksLimit();
|
||||
|
|
@ -307,7 +297,7 @@ public class PlayerData
|
|||
GriefPrevention.AddLogEntry("New total blocks: " + totalBlocks, CustomLogEntryTypes.Debug, true);
|
||||
|
||||
//if that didn't fix it, then make up the difference with bonus blocks
|
||||
if(totalBlocks < totalClaimsArea)
|
||||
if (totalBlocks < totalClaimsArea)
|
||||
{
|
||||
int bonusBlocksToAdd = totalClaimsArea - totalBlocks;
|
||||
this.bonusClaimBlocks += bonusBlocksToAdd;
|
||||
|
|
@ -320,18 +310,18 @@ public class PlayerData
|
|||
GriefPrevention.AddLogEntry("Remaining claim blocks to use: " + this.getRemainingClaimBlocks() + " (should be 0)", CustomLogEntryTypes.Debug, true);
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < this.claims.size(); i++)
|
||||
|
||||
for (int i = 0; i < this.claims.size(); i++)
|
||||
{
|
||||
if(!claims.get(i).inDataStore)
|
||||
if (!claims.get(i).inDataStore)
|
||||
{
|
||||
claims.remove(i--);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return claims;
|
||||
}
|
||||
|
||||
|
||||
//Limit can be changed by addons
|
||||
public int getAccruedClaimBlocksLimit()
|
||||
{
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -15,7 +15,7 @@
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.events.PlayerKickBanEvent;
|
||||
|
|
@ -25,47 +25,46 @@ import org.bukkit.entity.Player;
|
|||
//kicks or bans a player
|
||||
//need a task for this because async threads (like the chat event handlers) can't kick or ban.
|
||||
//but they CAN schedule a task to run in the main thread to do that job
|
||||
class PlayerKickBanTask implements Runnable
|
||||
class PlayerKickBanTask implements Runnable
|
||||
{
|
||||
//player to kick or ban
|
||||
private Player player;
|
||||
|
||||
//message to send player.
|
||||
private String reason;
|
||||
|
||||
//source of ban
|
||||
private String source;
|
||||
|
||||
//whether to ban
|
||||
private boolean ban;
|
||||
|
||||
public PlayerKickBanTask(Player player, String reason, String source, boolean ban)
|
||||
{
|
||||
this.player = player;
|
||||
this.reason = reason;
|
||||
this.source = source;
|
||||
this.ban = ban;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
PlayerKickBanEvent kickBanEvent = new PlayerKickBanEvent(player, reason, source, ban);
|
||||
Bukkit.getPluginManager().callEvent(kickBanEvent);
|
||||
//player to kick or ban
|
||||
private Player player;
|
||||
|
||||
if (kickBanEvent.isCancelled())
|
||||
{
|
||||
return; // cancelled by a plugin
|
||||
}
|
||||
//message to send player.
|
||||
private String reason;
|
||||
|
||||
if(this.ban)
|
||||
{
|
||||
//ban
|
||||
GriefPrevention.banPlayer(this.player, this.reason, this.source);
|
||||
}
|
||||
else if(this.player.isOnline())
|
||||
{
|
||||
this.player.kickPlayer(this.reason);
|
||||
}
|
||||
}
|
||||
//source of ban
|
||||
private String source;
|
||||
|
||||
//whether to ban
|
||||
private boolean ban;
|
||||
|
||||
public PlayerKickBanTask(Player player, String reason, String source, boolean ban)
|
||||
{
|
||||
this.player = player;
|
||||
this.reason = reason;
|
||||
this.source = source;
|
||||
this.ban = ban;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
PlayerKickBanEvent kickBanEvent = new PlayerKickBanEvent(player, reason, source, ban);
|
||||
Bukkit.getPluginManager().callEvent(kickBanEvent);
|
||||
|
||||
if (kickBanEvent.isCancelled())
|
||||
{
|
||||
return; // cancelled by a plugin
|
||||
}
|
||||
|
||||
if (this.ban)
|
||||
{
|
||||
//ban
|
||||
GriefPrevention.banPlayer(this.player, this.reason, this.source);
|
||||
} else if (this.player.isOnline())
|
||||
{
|
||||
this.player.kickPlayer(this.reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
|
@ -24,52 +24,51 @@ import org.bukkit.entity.Player;
|
|||
//tries to rescue a trapped player from a claim where he doesn't have permission to save himself
|
||||
//related to the /trapped slash command
|
||||
//this does run in the main thread, so it's okay to make non-thread-safe calls
|
||||
class PlayerRescueTask implements Runnable
|
||||
class PlayerRescueTask implements Runnable
|
||||
{
|
||||
//original location where /trapped was used
|
||||
private Location location;
|
||||
|
||||
//rescue destination, may be decided at instantiation or at execution
|
||||
//original location where /trapped was used
|
||||
private Location location;
|
||||
|
||||
//rescue destination, may be decided at instantiation or at execution
|
||||
private Location destination;
|
||||
|
||||
//player data
|
||||
private Player player;
|
||||
|
||||
public PlayerRescueTask(Player player, Location location, Location destination)
|
||||
{
|
||||
this.player = player;
|
||||
this.location = location;
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
//if he logged out, don't do anything
|
||||
if(!player.isOnline()) return;
|
||||
|
||||
//he no longer has a pending /trapped slash command, so he can try to use it again now
|
||||
PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId());
|
||||
playerData.pendingTrapped = false;
|
||||
|
||||
//if the player moved three or more blocks from where he used /trapped, admonish him and don't save him
|
||||
if(player.getLocation().distance(this.location) > 3)
|
||||
{
|
||||
GriefPrevention.sendMessage(player, TextMode.Err, Messages.RescueAbortedMoved);
|
||||
return;
|
||||
}
|
||||
|
||||
//otherwise find a place to teleport him
|
||||
if(this.destination == null)
|
||||
{
|
||||
this.destination = GriefPrevention.instance.ejectPlayer(this.player);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.teleport(this.destination);
|
||||
}
|
||||
|
||||
//log entry, in case admins want to investigate the "trap"
|
||||
GriefPrevention.AddLogEntry("Rescued trapped player " + player.getName() + " from " + GriefPrevention.getfriendlyLocationString(this.location) + " to " + GriefPrevention.getfriendlyLocationString(this.destination) + ".");
|
||||
}
|
||||
|
||||
//player data
|
||||
private Player player;
|
||||
|
||||
public PlayerRescueTask(Player player, Location location, Location destination)
|
||||
{
|
||||
this.player = player;
|
||||
this.location = location;
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
//if he logged out, don't do anything
|
||||
if (!player.isOnline()) return;
|
||||
|
||||
//he no longer has a pending /trapped slash command, so he can try to use it again now
|
||||
PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId());
|
||||
playerData.pendingTrapped = false;
|
||||
|
||||
//if the player moved three or more blocks from where he used /trapped, admonish him and don't save him
|
||||
if (player.getLocation().distance(this.location) > 3)
|
||||
{
|
||||
GriefPrevention.sendMessage(player, TextMode.Err, Messages.RescueAbortedMoved);
|
||||
return;
|
||||
}
|
||||
|
||||
//otherwise find a place to teleport him
|
||||
if (this.destination == null)
|
||||
{
|
||||
this.destination = GriefPrevention.instance.ejectPlayer(this.player);
|
||||
} else
|
||||
{
|
||||
player.teleport(this.destination);
|
||||
}
|
||||
|
||||
//log entry, in case admins want to investigate the "trap"
|
||||
GriefPrevention.AddLogEntry("Rescued trapped player " + player.getName() + " from " + GriefPrevention.getfriendlyLocationString(this.location) + " to " + GriefPrevention.getfriendlyLocationString(this.destination) + ".");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,41 +15,40 @@
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
//sends a message to a player
|
||||
//used to send delayed messages, for example help text triggered by a player's chat
|
||||
class PvPImmunityValidationTask implements Runnable
|
||||
class PvPImmunityValidationTask implements Runnable
|
||||
{
|
||||
private Player player;
|
||||
|
||||
public PvPImmunityValidationTask(Player player)
|
||||
{
|
||||
this.player = player;
|
||||
}
|
||||
private Player player;
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if(!player.isOnline()) return;
|
||||
|
||||
PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId());
|
||||
if(!playerData.pvpImmune) return;
|
||||
|
||||
//check the player's inventory for anything
|
||||
if(!GriefPrevention.isInventoryEmpty(player))
|
||||
{
|
||||
//if found, cancel invulnerability and notify
|
||||
playerData.pvpImmune = false;
|
||||
GriefPrevention.sendMessage(player, TextMode.Warn, Messages.PvPImmunityEnd);
|
||||
}
|
||||
else
|
||||
{
|
||||
//otherwise check again in one minute
|
||||
GriefPrevention.instance.getServer().getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, this, 1200L);
|
||||
}
|
||||
}
|
||||
public PvPImmunityValidationTask(Player player)
|
||||
{
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (!player.isOnline()) return;
|
||||
|
||||
PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId());
|
||||
if (!playerData.pvpImmune) return;
|
||||
|
||||
//check the player's inventory for anything
|
||||
if (!GriefPrevention.isInventoryEmpty(player))
|
||||
{
|
||||
//if found, cancel invulnerability and notify
|
||||
playerData.pvpImmune = false;
|
||||
GriefPrevention.sendMessage(player, TextMode.Warn, Messages.PvPImmunityEnd);
|
||||
} else
|
||||
{
|
||||
//otherwise check again in one minute
|
||||
GriefPrevention.instance.getServer().getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, this, 1200L);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,10 +15,8 @@
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import java.util.ArrayList;
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
|
|
@ -30,101 +28,103 @@ 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
|
||||
class RestoreNatureExecutionTask implements Runnable
|
||||
{
|
||||
//results from processing thread
|
||||
//will be applied to the world
|
||||
private BlockSnapshot[][][] snapshots;
|
||||
|
||||
//boundaries for changes
|
||||
private int miny;
|
||||
private Location lesserCorner;
|
||||
private Location greaterCorner;
|
||||
|
||||
//player who should be notified about the result (will see a visualization when the restoration is complete)
|
||||
private Player player;
|
||||
//results from processing thread
|
||||
//will be applied to the world
|
||||
private BlockSnapshot[][][] snapshots;
|
||||
|
||||
public RestoreNatureExecutionTask(BlockSnapshot[][][] snapshots, int miny, Location lesserCorner, Location greaterCorner, Player player)
|
||||
{
|
||||
this.snapshots = snapshots;
|
||||
this.miny = miny;
|
||||
this.lesserCorner = lesserCorner;
|
||||
this.greaterCorner = greaterCorner;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
//apply changes to the world, but ONLY to unclaimed blocks
|
||||
//note that the edge of the results is not applied (the 1-block-wide band around the outside of the chunk)
|
||||
//those data were sent to the processing thread for referernce purposes, but aren't part of the area selected for restoration
|
||||
Claim cachedClaim = null;
|
||||
for(int x = 1; x < this.snapshots.length - 1; x++)
|
||||
{
|
||||
for(int z = 1; z < this.snapshots[0][0].length - 1; z++)
|
||||
{
|
||||
for(int y = this.miny; y < this.snapshots[0].length; y++)
|
||||
{
|
||||
BlockSnapshot blockUpdate = this.snapshots[x][y][z];
|
||||
Block currentBlock = blockUpdate.location.getBlock();
|
||||
if(blockUpdate.typeId != currentBlock.getType()|| !blockUpdate.data.equals(currentBlock.getBlockData()))
|
||||
{
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(blockUpdate.location, false, cachedClaim);
|
||||
if(claim != null)
|
||||
{
|
||||
cachedClaim = claim;
|
||||
break;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
currentBlock.setType(blockUpdate.typeId, false);
|
||||
// currentBlock.setBlockData(blockUpdate.data, false);
|
||||
}
|
||||
catch(IllegalArgumentException e)
|
||||
{
|
||||
//just don't update this block and continue trying to update other blocks
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//clean up any entities in the chunk, ensure no players are suffocated
|
||||
Chunk chunk = this.lesserCorner.getChunk();
|
||||
Entity [] entities = chunk.getEntities();
|
||||
for(int i = 0; i < entities.length; i++)
|
||||
{
|
||||
Entity entity = entities[i];
|
||||
if(!(entity instanceof Player || entity instanceof Animals))
|
||||
{
|
||||
//hanging entities (paintings, item frames) are protected when they're in land claims
|
||||
if(!(entity instanceof Hanging) || GriefPrevention.instance.dataStore.getClaimAt(entity.getLocation(), false, null) == null)
|
||||
{
|
||||
//everything else is removed
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
|
||||
//for players, always ensure there's air where the player is standing
|
||||
else
|
||||
{
|
||||
Block feetBlock = entity.getLocation().getBlock();
|
||||
feetBlock.setType(Material.AIR);
|
||||
feetBlock.getRelative(BlockFace.UP).setType(Material.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
//show visualization to player who started the restoration
|
||||
if(player != null)
|
||||
{
|
||||
Claim claim = new Claim(lesserCorner, greaterCorner, null, new ArrayList<String>(), new ArrayList<String>(), new ArrayList<String>(), new ArrayList<String>(), null);
|
||||
Visualization visualization = Visualization.FromClaim(claim, player.getLocation().getBlockY(), VisualizationType.RestoreNature, player.getLocation());
|
||||
Visualization.Apply(player, visualization);
|
||||
}
|
||||
}
|
||||
//boundaries for changes
|
||||
private int miny;
|
||||
private Location lesserCorner;
|
||||
private Location greaterCorner;
|
||||
|
||||
//player who should be notified about the result (will see a visualization when the restoration is complete)
|
||||
private Player player;
|
||||
|
||||
public RestoreNatureExecutionTask(BlockSnapshot[][][] snapshots, int miny, Location lesserCorner, Location greaterCorner, Player player)
|
||||
{
|
||||
this.snapshots = snapshots;
|
||||
this.miny = miny;
|
||||
this.lesserCorner = lesserCorner;
|
||||
this.greaterCorner = greaterCorner;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
//apply changes to the world, but ONLY to unclaimed blocks
|
||||
//note that the edge of the results is not applied (the 1-block-wide band around the outside of the chunk)
|
||||
//those data were sent to the processing thread for referernce purposes, but aren't part of the area selected for restoration
|
||||
Claim cachedClaim = null;
|
||||
for (int x = 1; x < this.snapshots.length - 1; x++)
|
||||
{
|
||||
for (int z = 1; z < this.snapshots[0][0].length - 1; z++)
|
||||
{
|
||||
for (int y = this.miny; y < this.snapshots[0].length; y++)
|
||||
{
|
||||
BlockSnapshot blockUpdate = this.snapshots[x][y][z];
|
||||
Block currentBlock = blockUpdate.location.getBlock();
|
||||
if (blockUpdate.typeId != currentBlock.getType() || !blockUpdate.data.equals(currentBlock.getBlockData()))
|
||||
{
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(blockUpdate.location, false, cachedClaim);
|
||||
if (claim != null)
|
||||
{
|
||||
cachedClaim = claim;
|
||||
break;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
currentBlock.setType(blockUpdate.typeId, false);
|
||||
// currentBlock.setBlockData(blockUpdate.data, false);
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
//just don't update this block and continue trying to update other blocks
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//clean up any entities in the chunk, ensure no players are suffocated
|
||||
Chunk chunk = this.lesserCorner.getChunk();
|
||||
Entity[] entities = chunk.getEntities();
|
||||
for (int i = 0; i < entities.length; i++)
|
||||
{
|
||||
Entity entity = entities[i];
|
||||
if (!(entity instanceof Player || entity instanceof Animals))
|
||||
{
|
||||
//hanging entities (paintings, item frames) are protected when they're in land claims
|
||||
if (!(entity instanceof Hanging) || GriefPrevention.instance.dataStore.getClaimAt(entity.getLocation(), false, null) == null)
|
||||
{
|
||||
//everything else is removed
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
|
||||
//for players, always ensure there's air where the player is standing
|
||||
else
|
||||
{
|
||||
Block feetBlock = entity.getLocation().getBlock();
|
||||
feetBlock.setType(Material.AIR);
|
||||
feetBlock.getRelative(BlockFace.UP).setType(Material.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
//show visualization to player who started the restoration
|
||||
if (player != null)
|
||||
{
|
||||
Claim claim = new Claim(lesserCorner, greaterCorner, null, new ArrayList<String>(), new ArrayList<String>(), new ArrayList<String>(), new ArrayList<String>(), null);
|
||||
Visualization visualization = Visualization.FromClaim(claim, player.getLocation().getBlockY(), VisualizationType.RestoreNature, player.getLocation());
|
||||
Visualization.Apply(player, visualization);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -15,44 +15,44 @@
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import java.util.Collection;
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
//secures a claim after a siege looting window has closed
|
||||
class SecureClaimTask implements Runnable
|
||||
class SecureClaimTask implements Runnable
|
||||
{
|
||||
private SiegeData siegeData;
|
||||
|
||||
public SecureClaimTask(SiegeData siegeData)
|
||||
{
|
||||
this.siegeData = siegeData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
//for each claim involved in this siege
|
||||
for(int i = 0; i < this.siegeData.claims.size(); i++)
|
||||
{
|
||||
//lock the doors
|
||||
Claim claim = this.siegeData.claims.get(i);
|
||||
claim.doorsOpen = false;
|
||||
|
||||
//eject bad guys
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<Player> onlinePlayers = (Collection<Player>)GriefPrevention.instance.getServer().getOnlinePlayers();
|
||||
for(Player player : onlinePlayers)
|
||||
{
|
||||
if(claim.contains(player.getLocation(), false, false) && claim.allowAccess(player) != null)
|
||||
{
|
||||
GriefPrevention.sendMessage(player, TextMode.Err, Messages.SiegeDoorsLockedEjection);
|
||||
GriefPrevention.instance.ejectPlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private SiegeData siegeData;
|
||||
|
||||
public SecureClaimTask(SiegeData siegeData)
|
||||
{
|
||||
this.siegeData = siegeData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
//for each claim involved in this siege
|
||||
for (int i = 0; i < this.siegeData.claims.size(); i++)
|
||||
{
|
||||
//lock the doors
|
||||
Claim claim = this.siegeData.claims.get(i);
|
||||
claim.doorsOpen = false;
|
||||
|
||||
//eject bad guys
|
||||
@SuppressWarnings("unchecked")
|
||||
Collection<Player> onlinePlayers = (Collection<Player>) GriefPrevention.instance.getServer().getOnlinePlayers();
|
||||
for (Player player : onlinePlayers)
|
||||
{
|
||||
if (claim.contains(player.getLocation(), false, false) && claim.allowAccess(player) != null)
|
||||
{
|
||||
GriefPrevention.sendMessage(player, TextMode.Err, Messages.SiegeDoorsLockedEjection);
|
||||
GriefPrevention.instance.ejectPlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
|
@ -23,39 +23,39 @@ import org.bukkit.entity.Player;
|
|||
|
||||
//sends a message to a player
|
||||
//used to send delayed messages, for example help text triggered by a player's chat
|
||||
class SendPlayerMessageTask implements Runnable
|
||||
class SendPlayerMessageTask implements Runnable
|
||||
{
|
||||
private Player player;
|
||||
private ChatColor color;
|
||||
private String message;
|
||||
|
||||
public SendPlayerMessageTask(Player player, ChatColor color, String message)
|
||||
{
|
||||
this.player = player;
|
||||
this.color = color;
|
||||
this.message = message;
|
||||
}
|
||||
private Player player;
|
||||
private ChatColor color;
|
||||
private String message;
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if(player == null)
|
||||
{
|
||||
GriefPrevention.AddLogEntry(color + message);
|
||||
return;
|
||||
}
|
||||
|
||||
//if the player is dead, save it for after his respawn
|
||||
if(this.player.isDead())
|
||||
{
|
||||
PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(this.player.getUniqueId());
|
||||
playerData.messageOnRespawn = this.color + this.message;
|
||||
}
|
||||
|
||||
//otherwise send it immediately
|
||||
else
|
||||
{
|
||||
GriefPrevention.sendMessage(this.player, this.color, this.message);
|
||||
}
|
||||
}
|
||||
public SendPlayerMessageTask(Player player, ChatColor color, String message)
|
||||
{
|
||||
this.player = player;
|
||||
this.color = color;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (player == null)
|
||||
{
|
||||
GriefPrevention.AddLogEntry(color + message);
|
||||
return;
|
||||
}
|
||||
|
||||
//if the player is dead, save it for after his respawn
|
||||
if (this.player.isDead())
|
||||
{
|
||||
PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(this.player.getUniqueId());
|
||||
playerData.messageOnRespawn = this.color + this.message;
|
||||
}
|
||||
|
||||
//otherwise send it immediately
|
||||
else
|
||||
{
|
||||
GriefPrevention.sendMessage(this.player, this.color, this.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,16 +15,16 @@
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
//enumeration for golden shovel modes
|
||||
public enum ShovelMode
|
||||
public enum ShovelMode
|
||||
{
|
||||
Basic,
|
||||
Admin,
|
||||
Subdivide,
|
||||
RestoreNature,
|
||||
RestoreNatureAggressive,
|
||||
RestoreNatureFill
|
||||
Basic,
|
||||
Admin,
|
||||
Subdivide,
|
||||
RestoreNature,
|
||||
RestoreNatureAggressive,
|
||||
RestoreNatureFill
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,89 +22,89 @@ import org.bukkit.entity.Player;
|
|||
|
||||
//checks to see whether or not a siege should end based on the locations of the players
|
||||
//for example, defender escaped or attacker gave up and left
|
||||
class SiegeCheckupTask implements Runnable
|
||||
class SiegeCheckupTask implements Runnable
|
||||
{
|
||||
private SiegeData siegeData;
|
||||
|
||||
public SiegeCheckupTask(SiegeData siegeData)
|
||||
{
|
||||
this.siegeData = siegeData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
DataStore dataStore = GriefPrevention.instance.dataStore;
|
||||
Player defender = this.siegeData.defender;
|
||||
Player attacker = this.siegeData.attacker;
|
||||
|
||||
//where is the defender?
|
||||
Claim defenderClaim = dataStore.getClaimAt(defender.getLocation(), false, null);
|
||||
|
||||
//if this is a new claim and he has some permission there, extend the siege to include it
|
||||
if(defenderClaim != null)
|
||||
{
|
||||
String noAccessReason = defenderClaim.allowAccess(defender);
|
||||
if(defenderClaim.canSiege(defender) && noAccessReason == null)
|
||||
{
|
||||
this.siegeData.claims.add(defenderClaim);
|
||||
defenderClaim.siegeData = this.siegeData;
|
||||
}
|
||||
}
|
||||
|
||||
//determine who's close enough to the siege area to be considered "still here"
|
||||
boolean attackerRemains = this.playerRemains(attacker);
|
||||
boolean defenderRemains = this.playerRemains(defender);
|
||||
|
||||
//if they're both here, just plan to come check again later
|
||||
if(attackerRemains && defenderRemains)
|
||||
{
|
||||
this.scheduleAnotherCheck();
|
||||
}
|
||||
|
||||
//otherwise attacker wins if the defender runs away
|
||||
else if(attackerRemains && !defenderRemains)
|
||||
{
|
||||
dataStore.endSiege(this.siegeData, attacker.getName(), defender.getName(), null);
|
||||
}
|
||||
|
||||
//or defender wins if the attacker leaves
|
||||
else if(!attackerRemains && defenderRemains)
|
||||
{
|
||||
dataStore.endSiege(this.siegeData, defender.getName(), attacker.getName(), null);
|
||||
}
|
||||
|
||||
//if they both left, but are still close together, the battle continues (check again later)
|
||||
else if(attacker.getWorld().equals(defender.getWorld()) && attacker.getLocation().distanceSquared(defender.getLocation()) < 2500) //50-block radius for chasing
|
||||
{
|
||||
this.scheduleAnotherCheck();
|
||||
}
|
||||
|
||||
//otherwise they both left and aren't close to each other, so call the attacker the winner (defender escaped, possibly after a chase)
|
||||
else
|
||||
{
|
||||
dataStore.endSiege(this.siegeData, attacker.getName(), defender.getName(), null);
|
||||
}
|
||||
}
|
||||
|
||||
//a player has to be within 25 blocks of the edge of a besieged claim to be considered still in the fight
|
||||
private boolean playerRemains(Player player)
|
||||
{
|
||||
for(int i = 0; i < this.siegeData.claims.size(); i++)
|
||||
{
|
||||
Claim claim = this.siegeData.claims.get(i);
|
||||
if(claim.isNear(player.getLocation(), 25))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//schedules another checkup later
|
||||
private void scheduleAnotherCheck()
|
||||
{
|
||||
this.siegeData.checkupTaskID = GriefPrevention.instance.getServer().getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, this, 20L * 30);
|
||||
}
|
||||
private SiegeData siegeData;
|
||||
|
||||
public SiegeCheckupTask(SiegeData siegeData)
|
||||
{
|
||||
this.siegeData = siegeData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
DataStore dataStore = GriefPrevention.instance.dataStore;
|
||||
Player defender = this.siegeData.defender;
|
||||
Player attacker = this.siegeData.attacker;
|
||||
|
||||
//where is the defender?
|
||||
Claim defenderClaim = dataStore.getClaimAt(defender.getLocation(), false, null);
|
||||
|
||||
//if this is a new claim and he has some permission there, extend the siege to include it
|
||||
if (defenderClaim != null)
|
||||
{
|
||||
String noAccessReason = defenderClaim.allowAccess(defender);
|
||||
if (defenderClaim.canSiege(defender) && noAccessReason == null)
|
||||
{
|
||||
this.siegeData.claims.add(defenderClaim);
|
||||
defenderClaim.siegeData = this.siegeData;
|
||||
}
|
||||
}
|
||||
|
||||
//determine who's close enough to the siege area to be considered "still here"
|
||||
boolean attackerRemains = this.playerRemains(attacker);
|
||||
boolean defenderRemains = this.playerRemains(defender);
|
||||
|
||||
//if they're both here, just plan to come check again later
|
||||
if (attackerRemains && defenderRemains)
|
||||
{
|
||||
this.scheduleAnotherCheck();
|
||||
}
|
||||
|
||||
//otherwise attacker wins if the defender runs away
|
||||
else if (attackerRemains && !defenderRemains)
|
||||
{
|
||||
dataStore.endSiege(this.siegeData, attacker.getName(), defender.getName(), null);
|
||||
}
|
||||
|
||||
//or defender wins if the attacker leaves
|
||||
else if (!attackerRemains && defenderRemains)
|
||||
{
|
||||
dataStore.endSiege(this.siegeData, defender.getName(), attacker.getName(), null);
|
||||
}
|
||||
|
||||
//if they both left, but are still close together, the battle continues (check again later)
|
||||
else if (attacker.getWorld().equals(defender.getWorld()) && attacker.getLocation().distanceSquared(defender.getLocation()) < 2500) //50-block radius for chasing
|
||||
{
|
||||
this.scheduleAnotherCheck();
|
||||
}
|
||||
|
||||
//otherwise they both left and aren't close to each other, so call the attacker the winner (defender escaped, possibly after a chase)
|
||||
else
|
||||
{
|
||||
dataStore.endSiege(this.siegeData, attacker.getName(), defender.getName(), null);
|
||||
}
|
||||
}
|
||||
|
||||
//a player has to be within 25 blocks of the edge of a besieged claim to be considered still in the fight
|
||||
private boolean playerRemains(Player player)
|
||||
{
|
||||
for (int i = 0; i < this.siegeData.claims.size(); i++)
|
||||
{
|
||||
Claim claim = this.siegeData.claims.get(i);
|
||||
if (claim.isNear(player.getLocation(), 25))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//schedules another checkup later
|
||||
private void scheduleAnotherCheck()
|
||||
{
|
||||
this.siegeData.checkupTaskID = GriefPrevention.instance.getServer().getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, this, 20L * 30);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,23 +18,23 @@
|
|||
|
||||
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
|
||||
{
|
||||
public Player defender;
|
||||
public Player attacker;
|
||||
public ArrayList<Claim> claims;
|
||||
public int checkupTaskID;
|
||||
|
||||
public SiegeData(Player attacker, Player defender, Claim claim)
|
||||
{
|
||||
this.defender = defender;
|
||||
this.attacker = attacker;
|
||||
this.claims = new ArrayList<Claim>();
|
||||
this.claims.add(claim);
|
||||
}
|
||||
public Player defender;
|
||||
public Player attacker;
|
||||
public ArrayList<Claim> claims;
|
||||
public int checkupTaskID;
|
||||
|
||||
public SiegeData(Player attacker, Player defender, Claim claim)
|
||||
{
|
||||
this.defender = defender;
|
||||
this.attacker = attacker;
|
||||
this.claims = new ArrayList<Claim>();
|
||||
this.claims.add(claim);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,206 +9,204 @@ class SpamDetector
|
|||
//last chat message shown and its timestamp, regardless of who sent it
|
||||
private String lastChatMessage = "";
|
||||
private long lastChatMessageTimestamp = 0;
|
||||
|
||||
|
||||
//number of identical chat messages in a row
|
||||
private int duplicateMessageCount = 0;
|
||||
|
||||
|
||||
//data for individual chatters
|
||||
ConcurrentHashMap<UUID, ChatterData> dataStore = new ConcurrentHashMap<UUID, ChatterData>();
|
||||
|
||||
private ChatterData getChatterData(UUID chatterID)
|
||||
{
|
||||
ChatterData data = this.dataStore.get(chatterID);
|
||||
if(data == null)
|
||||
if (data == null)
|
||||
{
|
||||
data = new ChatterData();
|
||||
this.dataStore.put(chatterID, data);
|
||||
}
|
||||
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
SpamAnalysisResult AnalyzeMessage(UUID chatterID, String message, long timestamp)
|
||||
{
|
||||
SpamAnalysisResult result = new SpamAnalysisResult();
|
||||
result.finalMessage = message;
|
||||
|
||||
|
||||
//remedy any CAPS SPAM, exception for very short messages which could be emoticons like =D or XD
|
||||
if(message.length() > 4 && this.stringsAreSimilar(message.toUpperCase(), message))
|
||||
if (message.length() > 4 && this.stringsAreSimilar(message.toUpperCase(), message))
|
||||
{
|
||||
message = message.toLowerCase();
|
||||
result.finalMessage = message;
|
||||
}
|
||||
|
||||
|
||||
boolean spam = false;
|
||||
ChatterData chatterData = this.getChatterData(chatterID);
|
||||
|
||||
//mute if total volume of text from this player is too high
|
||||
if(message.length() > 50 && chatterData.getTotalRecentLength(timestamp) > 200)
|
||||
if (message.length() > 50 && chatterData.getTotalRecentLength(timestamp) > 200)
|
||||
{
|
||||
spam = true;
|
||||
result.muteReason = "too much chat sent in 10 seconds";
|
||||
chatterData.spamLevel++;
|
||||
}
|
||||
|
||||
|
||||
//always mute an exact match to the last chat message
|
||||
if(result.finalMessage.equals(this.lastChatMessage) && timestamp - this.lastChatMessageTimestamp < 2000)
|
||||
if (result.finalMessage.equals(this.lastChatMessage) && timestamp - this.lastChatMessageTimestamp < 2000)
|
||||
{
|
||||
chatterData.spamLevel += ++this.duplicateMessageCount;
|
||||
spam = true;
|
||||
result.muteReason = "repeat message";
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
this.lastChatMessage = message;
|
||||
this.lastChatMessageTimestamp = timestamp;
|
||||
this.duplicateMessageCount = 0;
|
||||
}
|
||||
|
||||
|
||||
//check message content and timing
|
||||
long millisecondsSinceLastMessage = timestamp - chatterData.lastMessageTimestamp;
|
||||
|
||||
|
||||
//if the message came too close to the last one
|
||||
if(millisecondsSinceLastMessage < 1500)
|
||||
if (millisecondsSinceLastMessage < 1500)
|
||||
{
|
||||
//increment the spam counter
|
||||
chatterData.spamLevel++;
|
||||
spam = true;
|
||||
}
|
||||
|
||||
|
||||
//if it's exactly the same as the last message from the same player and within 30 seconds
|
||||
if(result.muteReason == null && millisecondsSinceLastMessage < 30000 && result.finalMessage.equalsIgnoreCase(chatterData.lastMessage))
|
||||
if (result.muteReason == null && millisecondsSinceLastMessage < 30000 && result.finalMessage.equalsIgnoreCase(chatterData.lastMessage))
|
||||
{
|
||||
chatterData.spamLevel++;
|
||||
spam = true;
|
||||
result.muteReason = "repeat message";
|
||||
}
|
||||
|
||||
|
||||
//if it's very similar to the last message from the same player and within 10 seconds of that message
|
||||
if(result.muteReason == null && millisecondsSinceLastMessage < 10000 && this.stringsAreSimilar(message.toLowerCase(), chatterData.lastMessage.toLowerCase()))
|
||||
if (result.muteReason == null && millisecondsSinceLastMessage < 10000 && this.stringsAreSimilar(message.toLowerCase(), chatterData.lastMessage.toLowerCase()))
|
||||
{
|
||||
chatterData.spamLevel++;
|
||||
spam = true;
|
||||
if(chatterData.spamLevel > 2)
|
||||
if (chatterData.spamLevel > 2)
|
||||
{
|
||||
result.muteReason = "similar message";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//if the message was mostly non-alpha-numerics or doesn't include much whitespace, consider it a spam (probably ansi art or random text gibberish)
|
||||
if(result.muteReason == null && message.length() > 5)
|
||||
if (result.muteReason == null && message.length() > 5)
|
||||
{
|
||||
int symbolsCount = 0;
|
||||
int whitespaceCount = 0;
|
||||
for(int i = 0; i < message.length(); i++)
|
||||
for (int i = 0; i < message.length(); i++)
|
||||
{
|
||||
char character = message.charAt(i);
|
||||
if(!(Character.isLetterOrDigit(character)))
|
||||
if (!(Character.isLetterOrDigit(character)))
|
||||
{
|
||||
symbolsCount++;
|
||||
}
|
||||
|
||||
if(Character.isWhitespace(character))
|
||||
|
||||
if (Character.isWhitespace(character))
|
||||
{
|
||||
whitespaceCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if(symbolsCount > message.length() / 2 || (message.length() > 15 && whitespaceCount < message.length() / 10))
|
||||
|
||||
if (symbolsCount > message.length() / 2 || (message.length() > 15 && whitespaceCount < message.length() / 10))
|
||||
{
|
||||
spam = true;
|
||||
if(chatterData.spamLevel > 0) result.muteReason = "gibberish";
|
||||
if (chatterData.spamLevel > 0) result.muteReason = "gibberish";
|
||||
chatterData.spamLevel++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//very short messages close together are spam
|
||||
if(result.muteReason == null && message.length() < 5 && millisecondsSinceLastMessage < 3000)
|
||||
if (result.muteReason == null && message.length() < 5 && millisecondsSinceLastMessage < 3000)
|
||||
{
|
||||
spam = true;
|
||||
chatterData.spamLevel++;
|
||||
}
|
||||
|
||||
|
||||
//if the message was determined to be a spam, consider taking action
|
||||
if(spam)
|
||||
{
|
||||
if (spam)
|
||||
{
|
||||
//anything above level 8 for a player which has received a warning... kick or if enabled, ban
|
||||
if(chatterData.spamLevel > 8 && chatterData.spamWarned)
|
||||
if (chatterData.spamLevel > 8 && chatterData.spamWarned)
|
||||
{
|
||||
result.shouldBanChatter = true;
|
||||
}
|
||||
|
||||
else if(chatterData.spamLevel >= 4)
|
||||
} else if (chatterData.spamLevel >= 4)
|
||||
{
|
||||
if(!chatterData.spamWarned)
|
||||
if (!chatterData.spamWarned)
|
||||
{
|
||||
chatterData.spamWarned = true;
|
||||
result.shouldWarnChatter = true;
|
||||
}
|
||||
|
||||
if(result.muteReason == null)
|
||||
|
||||
if (result.muteReason == null)
|
||||
{
|
||||
result.muteReason = "too-frequent text";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//otherwise if not a spam, reduce the spam level for this player
|
||||
else
|
||||
{
|
||||
chatterData.spamLevel = 0;
|
||||
chatterData.spamWarned = false;
|
||||
}
|
||||
|
||||
|
||||
chatterData.AddMessage(message, timestamp);
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//if two strings are 75% identical, they're too close to follow each other in the chat
|
||||
private boolean stringsAreSimilar(String message, String lastMessage)
|
||||
{
|
||||
//ignore differences in only punctuation and whitespace
|
||||
message = message.replaceAll("[^\\p{Alpha}]", "");
|
||||
lastMessage = lastMessage.replaceAll("[^\\p{Alpha}]", "");
|
||||
|
||||
|
||||
//determine which is shorter
|
||||
String shorterString, longerString;
|
||||
if(lastMessage.length() < message.length())
|
||||
if (lastMessage.length() < message.length())
|
||||
{
|
||||
shorterString = lastMessage;
|
||||
longerString = message;
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
shorterString = message;
|
||||
longerString = lastMessage;
|
||||
}
|
||||
|
||||
if(shorterString.length() <= 5) return shorterString.equals(longerString);
|
||||
|
||||
|
||||
if (shorterString.length() <= 5) return shorterString.equals(longerString);
|
||||
|
||||
//set similarity tolerance
|
||||
int maxIdenticalCharacters = longerString.length() - longerString.length() / 4;
|
||||
|
||||
|
||||
//trivial check on length
|
||||
if(shorterString.length() < maxIdenticalCharacters) return false;
|
||||
|
||||
if (shorterString.length() < maxIdenticalCharacters) return false;
|
||||
|
||||
//compare forward
|
||||
int identicalCount = 0;
|
||||
int i;
|
||||
for(i = 0; i < shorterString.length(); i++)
|
||||
for (i = 0; i < shorterString.length(); i++)
|
||||
{
|
||||
if(shorterString.charAt(i) == longerString.charAt(i)) identicalCount++;
|
||||
if(identicalCount > maxIdenticalCharacters) return true;
|
||||
if (shorterString.charAt(i) == longerString.charAt(i)) identicalCount++;
|
||||
if (identicalCount > maxIdenticalCharacters) return true;
|
||||
}
|
||||
|
||||
|
||||
//compare backward
|
||||
int j;
|
||||
for(j = 0; j < shorterString.length() - i; j++)
|
||||
for (j = 0; j < shorterString.length() - i; j++)
|
||||
{
|
||||
if(shorterString.charAt(shorterString.length() - j - 1) == longerString.charAt(longerString.length() - j - 1)) identicalCount++;
|
||||
if(identicalCount > maxIdenticalCharacters) return true;
|
||||
if (shorterString.charAt(shorterString.length() - j - 1) == longerString.charAt(longerString.length() - j - 1))
|
||||
identicalCount++;
|
||||
if (identicalCount > maxIdenticalCharacters) return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -227,17 +225,17 @@ class ChatterData
|
|||
public long lastMessageTimestamp; //last time the player sent a chat message or used a monitored slash command
|
||||
public int spamLevel = 0; //number of consecutive "spams"
|
||||
public boolean spamWarned = false; //whether the player has received a warning recently
|
||||
|
||||
|
||||
//all recent message lengths and their total
|
||||
private ConcurrentLinkedQueue<LengthTimestampPair> recentMessageLengths = new ConcurrentLinkedQueue<LengthTimestampPair>();
|
||||
private int recentTotalLength = 0;
|
||||
|
||||
|
||||
public void AddMessage(String message, long timestamp)
|
||||
{
|
||||
int length = message.length();
|
||||
this.recentMessageLengths.add(new LengthTimestampPair(length, timestamp));
|
||||
this.recentTotalLength += length;
|
||||
|
||||
|
||||
this.lastMessage = message;
|
||||
this.lastMessageTimestamp = timestamp;
|
||||
}
|
||||
|
|
@ -245,13 +243,13 @@ class ChatterData
|
|||
public int getTotalRecentLength(long timestamp)
|
||||
{
|
||||
LengthTimestampPair oldestPair = this.recentMessageLengths.peek();
|
||||
while(oldestPair != null && timestamp - oldestPair.timestamp > 10000)
|
||||
while (oldestPair != null && timestamp - oldestPair.timestamp > 10000)
|
||||
{
|
||||
this.recentMessageLengths.poll();
|
||||
this.recentTotalLength -= oldestPair.length;
|
||||
oldestPair = this.recentMessageLengths.peek();
|
||||
}
|
||||
|
||||
|
||||
return this.recentTotalLength;
|
||||
}
|
||||
}
|
||||
|
|
@ -260,7 +258,7 @@ class LengthTimestampPair
|
|||
{
|
||||
public long timestamp;
|
||||
public int length;
|
||||
|
||||
|
||||
public LengthTimestampPair(int length, long timestamp)
|
||||
{
|
||||
this.length = length;
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ package me.ryanhamshire.GriefPrevention;
|
|||
import org.bukkit.ChatColor;
|
||||
|
||||
//just a few constants for chat color codes
|
||||
public class TextMode
|
||||
{
|
||||
final static ChatColor Info = ChatColor.AQUA;
|
||||
final static ChatColor Instr = ChatColor.YELLOW;
|
||||
final static ChatColor Warn = ChatColor.GOLD;
|
||||
final static ChatColor Err = ChatColor.RED;
|
||||
final static ChatColor Success = ChatColor.GREEN;
|
||||
public class TextMode
|
||||
{
|
||||
final static ChatColor Info = ChatColor.AQUA;
|
||||
final static ChatColor Instr = ChatColor.YELLOW;
|
||||
final static ChatColor Warn = ChatColor.GOLD;
|
||||
final static ChatColor Err = ChatColor.RED;
|
||||
final static ChatColor Success = ChatColor.GREEN;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,93 +7,98 @@ import org.bukkit.OfflinePlayer;
|
|||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
|
||||
class UUIDFetcher {
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
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();
|
||||
private final List<String> names;
|
||||
private final boolean rateLimiting;
|
||||
|
||||
|
||||
//cache for username -> uuid lookups
|
||||
static HashMap<String, UUID> lookupCache;
|
||||
|
||||
|
||||
//record of username -> proper casing updates
|
||||
static HashMap<String, String> correctedNames;
|
||||
|
||||
public UUIDFetcher(List<String> names, boolean rateLimiting) {
|
||||
|
||||
public UUIDFetcher(List<String> names, boolean rateLimiting)
|
||||
{
|
||||
this.names = names;
|
||||
this.rateLimiting = rateLimiting;
|
||||
}
|
||||
|
||||
public UUIDFetcher(List<String> names) {
|
||||
|
||||
public UUIDFetcher(List<String> names)
|
||||
{
|
||||
this(names, true);
|
||||
}
|
||||
|
||||
|
||||
public void call() throws Exception
|
||||
{
|
||||
if(lookupCache == null)
|
||||
if (lookupCache == null)
|
||||
{
|
||||
lookupCache = new HashMap<String, UUID>();
|
||||
}
|
||||
|
||||
if(correctedNames == null)
|
||||
|
||||
if (correctedNames == null)
|
||||
{
|
||||
correctedNames = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
|
||||
GriefPrevention.AddLogEntry("UUID conversion process started. Please be patient - this may take a while.");
|
||||
|
||||
|
||||
GriefPrevention.AddLogEntry("Mining your local world data to save calls to Mojang...");
|
||||
OfflinePlayer [] players = GriefPrevention.instance.getServer().getOfflinePlayers();
|
||||
for(OfflinePlayer player : players)
|
||||
OfflinePlayer[] players = GriefPrevention.instance.getServer().getOfflinePlayers();
|
||||
for (OfflinePlayer player : players)
|
||||
{
|
||||
if(player.getName() != null && player.getUniqueId() != null)
|
||||
if (player.getName() != null && player.getUniqueId() != null)
|
||||
{
|
||||
lookupCache.put(player.getName(), player.getUniqueId());
|
||||
lookupCache.put(player.getName().toLowerCase(), player.getUniqueId());
|
||||
correctedNames.put(player.getName().toLowerCase(), player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//try to get correct casing from local data
|
||||
GriefPrevention.AddLogEntry("Checking local server data to get correct casing for player names...");
|
||||
for(int i = 0; i < names.size(); i++)
|
||||
for (int i = 0; i < names.size(); i++)
|
||||
{
|
||||
String name = names.get(i);
|
||||
String correctCasingName = correctedNames.get(name);
|
||||
if(correctCasingName != null && !name.equals(correctCasingName))
|
||||
if (correctCasingName != null && !name.equals(correctCasingName))
|
||||
{
|
||||
GriefPrevention.AddLogEntry(name + " --> " + correctCasingName);
|
||||
names.set(i, correctCasingName);
|
||||
names.set(i, correctCasingName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//look for local uuid's first
|
||||
GriefPrevention.AddLogEntry("Checking local server data for UUIDs already seen...");
|
||||
for(int i = 0; i < names.size(); i++)
|
||||
for (int i = 0; i < names.size(); i++)
|
||||
{
|
||||
String name = names.get(i);
|
||||
UUID uuid = lookupCache.get(name);
|
||||
if(uuid != null)
|
||||
if (uuid != null)
|
||||
{
|
||||
GriefPrevention.AddLogEntry(name + " --> " + uuid.toString());
|
||||
names.remove(i--);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//for online mode, call Mojang to resolve the rest
|
||||
if(GriefPrevention.instance.getServer().getOnlineMode())
|
||||
if (GriefPrevention.instance.getServer().getOnlineMode())
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Calling Mojang to get UUIDs for remaining unresolved players (this is the slowest step)...");
|
||||
|
||||
|
||||
for (int i = 0; i * PROFILES_PER_REQUEST < names.size(); i++)
|
||||
{
|
||||
boolean retry = false;
|
||||
|
|
@ -109,21 +114,21 @@ class UUIDFetcher {
|
|||
{
|
||||
array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
//in case of error 429 too many requests, pause and then retry later
|
||||
if(e.getMessage().contains("429"))
|
||||
if (e.getMessage().contains("429"))
|
||||
{
|
||||
retry = true;
|
||||
|
||||
|
||||
//if this is the first time we're sending anything, the batch size must be too big
|
||||
//try reducing it
|
||||
if(i == 0 && PROFILES_PER_REQUEST > 1)
|
||||
if (i == 0 && PROFILES_PER_REQUEST > 1)
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Batch size " + PROFILES_PER_REQUEST + " seems too large. Looking for a workable batch size...");
|
||||
PROFILES_PER_REQUEST = Math.max(PROFILES_PER_REQUEST - 5, 1);
|
||||
}
|
||||
|
||||
|
||||
//otherwise, keep the batch size which has worked for previous iterations
|
||||
//but wait a little while before trying again.
|
||||
else
|
||||
|
|
@ -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) {
|
||||
} while (retry);
|
||||
|
||||
for (Object profile : array)
|
||||
{
|
||||
JSONObject jsonProfile = (JSONObject) profile;
|
||||
String id = (String) jsonProfile.get("id");
|
||||
String name = (String) jsonProfile.get("name");
|
||||
|
|
@ -148,18 +153,19 @@ class UUIDFetcher {
|
|||
lookupCache.put(name, uuid);
|
||||
lookupCache.put(name.toLowerCase(), uuid);
|
||||
}
|
||||
if (rateLimiting) {
|
||||
if (rateLimiting)
|
||||
{
|
||||
Thread.sleep(200L);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//for offline mode, generate UUIDs for the rest
|
||||
else
|
||||
{
|
||||
GriefPrevention.AddLogEntry("Generating offline mode UUIDs for remaining unresolved players...");
|
||||
|
||||
for(int i = 0; i < names.size(); i++)
|
||||
|
||||
for (int i = 0; i < names.size(); i++)
|
||||
{
|
||||
String name = names.get(i);
|
||||
UUID uuid = java.util.UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
|
||||
|
|
@ -169,15 +175,17 @@ 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");
|
||||
|
|
@ -187,20 +195,24 @@ class UUIDFetcher {
|
|||
connection.setDoOutput(true);
|
||||
return connection;
|
||||
}
|
||||
|
||||
private static UUID getUUID(String id) {
|
||||
return UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" +id.substring(20, 32));
|
||||
|
||||
private static UUID getUUID(String id)
|
||||
{
|
||||
return UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + id.substring(16, 20) + "-" + id.substring(20, 32));
|
||||
}
|
||||
|
||||
public static byte[] toBytes(UUID uuid) {
|
||||
|
||||
public static byte[] toBytes(UUID uuid)
|
||||
{
|
||||
ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]);
|
||||
byteBuffer.putLong(uuid.getMostSignificantBits());
|
||||
byteBuffer.putLong(uuid.getLeastSignificantBits());
|
||||
return byteBuffer.array();
|
||||
}
|
||||
|
||||
public static UUID fromBytes(byte[] array) {
|
||||
if (array.length != 16) {
|
||||
|
||||
public static UUID fromBytes(byte[] array)
|
||||
{
|
||||
if (array.length != 16)
|
||||
{
|
||||
throw new IllegalArgumentException("Illegal byte array length: " + array.length);
|
||||
}
|
||||
ByteBuffer byteBuffer = ByteBuffer.wrap(array);
|
||||
|
|
@ -208,17 +220,17 @@ class UUIDFetcher {
|
|||
long leastSignificant = byteBuffer.getLong();
|
||||
return new UUID(mostSignificant, leastSignificant);
|
||||
}
|
||||
|
||||
|
||||
public static UUID getUUIDOf(String name) throws Exception
|
||||
{
|
||||
UUID result = lookupCache.get(name);
|
||||
if(result == null)
|
||||
if (result == null)
|
||||
{
|
||||
//throw up our hands and report the problem in the logs
|
||||
//this player will lose his land claim blocks, but claims will stay in place as admin claims
|
||||
throw new IllegalArgumentException(name);
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -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,306 +28,300 @@ 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.
|
||||
public class Visualization
|
||||
public class Visualization
|
||||
{
|
||||
public ArrayList<VisualizationElement> elements = new ArrayList<VisualizationElement>();
|
||||
|
||||
//sends a visualization to a player
|
||||
public static void Apply(Player player, Visualization visualization)
|
||||
{
|
||||
PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId());
|
||||
|
||||
//if he has any current visualization, clear it first
|
||||
if(playerData.currentVisualization != null)
|
||||
{
|
||||
Visualization.Revert(player);
|
||||
}
|
||||
|
||||
//if he's online, create a task to send him the visualization
|
||||
if(player.isOnline() && visualization.elements.size() > 0 && visualization.elements.get(0).location.getWorld().equals(player.getWorld()))
|
||||
{
|
||||
GriefPrevention.instance.getServer().getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, new VisualizationApplicationTask(player, playerData, visualization), 1L);
|
||||
}
|
||||
}
|
||||
|
||||
//reverts a visualization by sending another block change list, this time with the real world block values
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void Revert(Player player)
|
||||
{
|
||||
if(!player.isOnline()) return;
|
||||
|
||||
PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId());
|
||||
|
||||
Visualization visualization = playerData.currentVisualization;
|
||||
|
||||
if(playerData.currentVisualization != null)
|
||||
{
|
||||
//locality
|
||||
int minx = player.getLocation().getBlockX() - 100;
|
||||
int minz = player.getLocation().getBlockZ() - 100;
|
||||
int maxx = player.getLocation().getBlockX() + 100;
|
||||
int maxz = player.getLocation().getBlockZ() + 100;
|
||||
public ArrayList<VisualizationElement> elements = new ArrayList<VisualizationElement>();
|
||||
|
||||
//remove any elements which are too far away
|
||||
visualization.removeElementsOutOfRange(visualization.elements, minx, minz, maxx, maxz);
|
||||
|
||||
//send real block information for any remaining elements
|
||||
for(int i = 0; i < visualization.elements.size(); i++)
|
||||
{
|
||||
VisualizationElement element = visualization.elements.get(i);
|
||||
//sends a visualization to a player
|
||||
public static void Apply(Player player, Visualization visualization)
|
||||
{
|
||||
PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId());
|
||||
|
||||
//check player still in world where visualization exists
|
||||
if(i == 0)
|
||||
{
|
||||
if(!player.getWorld().equals(element.location.getWorld())) return;
|
||||
}
|
||||
//if he has any current visualization, clear it first
|
||||
if (playerData.currentVisualization != null)
|
||||
{
|
||||
Visualization.Revert(player);
|
||||
}
|
||||
|
||||
player.sendBlockChange(element.location, element.realBlock);
|
||||
}
|
||||
//if he's online, create a task to send him the visualization
|
||||
if (player.isOnline() && visualization.elements.size() > 0 && visualization.elements.get(0).location.getWorld().equals(player.getWorld()))
|
||||
{
|
||||
GriefPrevention.instance.getServer().getScheduler().scheduleSyncDelayedTask(GriefPrevention.instance, new VisualizationApplicationTask(player, playerData, visualization), 1L);
|
||||
}
|
||||
}
|
||||
|
||||
playerData.currentVisualization = null;
|
||||
}
|
||||
}
|
||||
|
||||
//convenience method to build a visualization from a claim
|
||||
//visualizationType determines the style (gold blocks, silver, red, diamond, etc)
|
||||
public static Visualization FromClaim(Claim claim, int height, VisualizationType visualizationType, Location locality)
|
||||
{
|
||||
//visualize only top level claims
|
||||
if(claim.parent != null)
|
||||
{
|
||||
return FromClaim(claim.parent, height, visualizationType, locality);
|
||||
}
|
||||
|
||||
Visualization visualization = new Visualization();
|
||||
|
||||
//add subdivisions first
|
||||
for(int i = 0; i < claim.children.size(); i++)
|
||||
{
|
||||
Claim child = claim.children.get(i);
|
||||
if(!child.inDataStore) continue;
|
||||
visualization.addClaimElements(child, height, VisualizationType.Subdivision, locality);
|
||||
}
|
||||
|
||||
//special visualization for administrative land claims
|
||||
if(claim.isAdminClaim() && visualizationType == VisualizationType.Claim)
|
||||
//reverts a visualization by sending another block change list, this time with the real world block values
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void Revert(Player player)
|
||||
{
|
||||
if (!player.isOnline()) return;
|
||||
|
||||
PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId());
|
||||
|
||||
Visualization visualization = playerData.currentVisualization;
|
||||
|
||||
if (playerData.currentVisualization != null)
|
||||
{
|
||||
//locality
|
||||
int minx = player.getLocation().getBlockX() - 100;
|
||||
int minz = player.getLocation().getBlockZ() - 100;
|
||||
int maxx = player.getLocation().getBlockX() + 100;
|
||||
int maxz = player.getLocation().getBlockZ() + 100;
|
||||
|
||||
//remove any elements which are too far away
|
||||
visualization.removeElementsOutOfRange(visualization.elements, minx, minz, maxx, maxz);
|
||||
|
||||
//send real block information for any remaining elements
|
||||
for (int i = 0; i < visualization.elements.size(); i++)
|
||||
{
|
||||
VisualizationElement element = visualization.elements.get(i);
|
||||
|
||||
//check player still in world where visualization exists
|
||||
if (i == 0)
|
||||
{
|
||||
if (!player.getWorld().equals(element.location.getWorld())) return;
|
||||
}
|
||||
|
||||
player.sendBlockChange(element.location, element.realBlock);
|
||||
}
|
||||
|
||||
playerData.currentVisualization = null;
|
||||
}
|
||||
}
|
||||
|
||||
//convenience method to build a visualization from a claim
|
||||
//visualizationType determines the style (gold blocks, silver, red, diamond, etc)
|
||||
public static Visualization FromClaim(Claim claim, int height, VisualizationType visualizationType, Location locality)
|
||||
{
|
||||
//visualize only top level claims
|
||||
if (claim.parent != null)
|
||||
{
|
||||
return FromClaim(claim.parent, height, visualizationType, locality);
|
||||
}
|
||||
|
||||
Visualization visualization = new Visualization();
|
||||
|
||||
//add subdivisions first
|
||||
for (int i = 0; i < claim.children.size(); i++)
|
||||
{
|
||||
Claim child = claim.children.get(i);
|
||||
if (!child.inDataStore) continue;
|
||||
visualization.addClaimElements(child, height, VisualizationType.Subdivision, locality);
|
||||
}
|
||||
|
||||
//special visualization for administrative land claims
|
||||
if (claim.isAdminClaim() && visualizationType == VisualizationType.Claim)
|
||||
{
|
||||
visualizationType = VisualizationType.AdminClaim;
|
||||
}
|
||||
|
||||
//add top level last so that it takes precedence (it shows on top when the child claim boundaries overlap with its boundaries)
|
||||
visualization.addClaimElements(claim, height, visualizationType, locality);
|
||||
|
||||
return visualization;
|
||||
}
|
||||
|
||||
//adds a claim's visualization to the current visualization
|
||||
//handy for combining several visualizations together, as when visualization a top level claim with several subdivisions inside
|
||||
//locality is a performance consideration. only create visualization blocks for around 100 blocks of the locality
|
||||
@SuppressWarnings("deprecation")
|
||||
private void addClaimElements(Claim claim, int height, VisualizationType visualizationType, Location locality)
|
||||
{
|
||||
Location smallXsmallZ = claim.getLesserBoundaryCorner();
|
||||
Location bigXbigZ = claim.getGreaterBoundaryCorner();
|
||||
World world = smallXsmallZ.getWorld();
|
||||
boolean waterIsTransparent = locality.getBlock().getType() == Material.WATER;
|
||||
|
||||
int smallx = smallXsmallZ.getBlockX();
|
||||
int smallz = smallXsmallZ.getBlockZ();
|
||||
int bigx = bigXbigZ.getBlockX();
|
||||
int bigz = bigXbigZ.getBlockZ();
|
||||
|
||||
BlockData cornerBlockData;
|
||||
BlockData accentBlockData;
|
||||
|
||||
ArrayList<VisualizationElement> newElements = new ArrayList<VisualizationElement>();
|
||||
|
||||
if(visualizationType == VisualizationType.Claim)
|
||||
{
|
||||
cornerBlockData = Material.GLOWSTONE.createBlockData();
|
||||
accentBlockData = Material.GOLD_BLOCK.createBlockData();
|
||||
}
|
||||
|
||||
else if(visualizationType == VisualizationType.AdminClaim)
|
||||
{
|
||||
cornerBlockData = Material.GLOWSTONE.createBlockData();
|
||||
accentBlockData = Material.PUMPKIN.createBlockData();
|
||||
}
|
||||
|
||||
else if(visualizationType == VisualizationType.Subdivision)
|
||||
{
|
||||
cornerBlockData = Material.IRON_BLOCK.createBlockData();
|
||||
accentBlockData = Material.WHITE_WOOL.createBlockData();
|
||||
}
|
||||
|
||||
else if(visualizationType == VisualizationType.RestoreNature)
|
||||
{
|
||||
cornerBlockData = Material.DIAMOND_BLOCK.createBlockData();
|
||||
accentBlockData = Material.DIAMOND_BLOCK.createBlockData();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
cornerBlockData = Material.REDSTONE_ORE.createBlockData();
|
||||
((Lightable) cornerBlockData).setLit(true);
|
||||
accentBlockData = Material.NETHERRACK.createBlockData();
|
||||
}
|
||||
|
||||
//initialize visualization elements without Y values and real data
|
||||
//that will be added later for only the visualization elements within visualization range
|
||||
|
||||
//locality
|
||||
int minx = locality.getBlockX() - 75;
|
||||
int minz = locality.getBlockZ() - 75;
|
||||
int maxx = locality.getBlockX() + 75;
|
||||
int maxz = locality.getBlockZ() + 75;
|
||||
|
||||
final int STEP = 10;
|
||||
|
||||
//top line
|
||||
newElements.add(new VisualizationElement(new Location(world, smallx, 0, bigz), cornerBlockData, Material.AIR.createBlockData()));
|
||||
newElements.add(new VisualizationElement(new Location(world, smallx + 1, 0, bigz), accentBlockData, Material.AIR.createBlockData()));
|
||||
for(int x = smallx + STEP; x < bigx - STEP / 2; x += STEP)
|
||||
{
|
||||
if(x > minx && x < maxx)
|
||||
newElements.add(new VisualizationElement(new Location(world, x, 0, bigz), accentBlockData, Material.AIR.createBlockData()));
|
||||
}
|
||||
newElements.add(new VisualizationElement(new Location(world, bigx - 1, 0, bigz), accentBlockData, Material.AIR.createBlockData()));
|
||||
|
||||
//bottom line
|
||||
newElements.add(new VisualizationElement(new Location(world, smallx + 1, 0, smallz), accentBlockData, Material.AIR.createBlockData()));
|
||||
for(int x = smallx + STEP; x < bigx - STEP / 2; x += STEP)
|
||||
{
|
||||
if(x > minx && x < maxx)
|
||||
newElements.add(new VisualizationElement(new Location(world, x, 0, smallz), accentBlockData, Material.AIR.createBlockData()));
|
||||
}
|
||||
newElements.add(new VisualizationElement(new Location(world, bigx - 1, 0, smallz), accentBlockData, Material.AIR.createBlockData()));
|
||||
|
||||
//left line
|
||||
newElements.add(new VisualizationElement(new Location(world, smallx, 0, smallz), cornerBlockData, Material.AIR.createBlockData()));
|
||||
newElements.add(new VisualizationElement(new Location(world, smallx, 0, smallz + 1), accentBlockData, Material.AIR.createBlockData()));
|
||||
for(int z = smallz + STEP; z < bigz - STEP / 2; z += STEP)
|
||||
{
|
||||
if(z > minz && z < maxz)
|
||||
newElements.add(new VisualizationElement(new Location(world, smallx, 0, z), accentBlockData, Material.AIR.createBlockData()));
|
||||
}
|
||||
newElements.add(new VisualizationElement(new Location(world, smallx, 0, bigz - 1), accentBlockData, Material.AIR.createBlockData()));
|
||||
|
||||
//right line
|
||||
newElements.add(new VisualizationElement(new Location(world, bigx, 0, smallz), cornerBlockData, Material.AIR.createBlockData()));
|
||||
newElements.add(new VisualizationElement(new Location(world, bigx, 0, smallz + 1), accentBlockData, Material.AIR.createBlockData()));
|
||||
for(int z = smallz + STEP; z < bigz - STEP / 2; z += STEP)
|
||||
{
|
||||
if(z > minz && z < maxz)
|
||||
newElements.add(new VisualizationElement(new Location(world, bigx, 0, z), accentBlockData, Material.AIR.createBlockData()));
|
||||
}
|
||||
newElements.add(new VisualizationElement(new Location(world, bigx, 0, bigz - 1), accentBlockData, Material.AIR.createBlockData()));
|
||||
newElements.add(new VisualizationElement(new Location(world, bigx, 0, bigz), cornerBlockData, Material.AIR.createBlockData()));
|
||||
|
||||
//remove any out of range elements
|
||||
this.removeElementsOutOfRange(newElements, minx, minz, maxx, maxz);
|
||||
|
||||
//remove any elements outside the claim
|
||||
for(int i = 0; i < newElements.size(); i++)
|
||||
{
|
||||
VisualizationElement element = newElements.get(i);
|
||||
if(!claim.contains(element.location, true, false))
|
||||
{
|
||||
newElements.remove(i--);
|
||||
}
|
||||
}
|
||||
|
||||
//set Y values and real block information for any remaining visualization blocks
|
||||
for(VisualizationElement element : newElements)
|
||||
{
|
||||
Location tempLocation = element.location;
|
||||
element.location = getVisibleLocation(tempLocation.getWorld(), tempLocation.getBlockX(), height, tempLocation.getBlockZ(), waterIsTransparent);
|
||||
height = element.location.getBlockY();
|
||||
element.realBlock = element.location.getBlock().getBlockData();
|
||||
}
|
||||
|
||||
this.elements.addAll(newElements);
|
||||
}
|
||||
|
||||
//removes any elements which are out of visualization range
|
||||
private void removeElementsOutOfRange(ArrayList<VisualizationElement> elements, int minx, int minz, int maxx, int maxz)
|
||||
{
|
||||
for(int i = 0; i < elements.size(); i++)
|
||||
{
|
||||
Location location = elements.get(i).location;
|
||||
if(location.getX() < minx || location.getX() > maxx || location.getZ() < minz || location.getZ() > maxz)
|
||||
{
|
||||
elements.remove(i--);
|
||||
}
|
||||
}
|
||||
|
||||
//add top level last so that it takes precedence (it shows on top when the child claim boundaries overlap with its boundaries)
|
||||
visualization.addClaimElements(claim, height, visualizationType, locality);
|
||||
|
||||
return visualization;
|
||||
}
|
||||
|
||||
//finds a block the player can probably see. this is how visualizations "cling" to the ground or ceiling
|
||||
private static Location getVisibleLocation(World world, int x, int y, int z, boolean waterIsTransparent)
|
||||
{
|
||||
Block block = world.getBlockAt(x, y, z);
|
||||
BlockFace direction = (isTransparent(block, waterIsTransparent)) ? BlockFace.DOWN : BlockFace.UP;
|
||||
//adds a claim's visualization to the current visualization
|
||||
//handy for combining several visualizations together, as when visualization a top level claim with several subdivisions inside
|
||||
//locality is a performance consideration. only create visualization blocks for around 100 blocks of the locality
|
||||
@SuppressWarnings("deprecation")
|
||||
private void addClaimElements(Claim claim, int height, VisualizationType visualizationType, Location locality)
|
||||
{
|
||||
Location smallXsmallZ = claim.getLesserBoundaryCorner();
|
||||
Location bigXbigZ = claim.getGreaterBoundaryCorner();
|
||||
World world = smallXsmallZ.getWorld();
|
||||
boolean waterIsTransparent = locality.getBlock().getType() == Material.WATER;
|
||||
|
||||
while( block.getY() >= 1 &&
|
||||
block.getY() < world.getMaxHeight() - 1 &&
|
||||
(!isTransparent(block.getRelative(BlockFace.UP), waterIsTransparent) || isTransparent(block, waterIsTransparent)))
|
||||
{
|
||||
block = block.getRelative(direction);
|
||||
}
|
||||
|
||||
return block.getLocation();
|
||||
}
|
||||
|
||||
//helper method for above. allows visualization blocks to sit underneath partly transparent blocks like grass and fence
|
||||
private static boolean isTransparent(Block block, boolean waterIsTransparent)
|
||||
{
|
||||
Material blockMaterial = block.getType();
|
||||
//Blacklist
|
||||
switch (blockMaterial)
|
||||
{
|
||||
case SNOW:
|
||||
return false;
|
||||
}
|
||||
int smallx = smallXsmallZ.getBlockX();
|
||||
int smallz = smallXsmallZ.getBlockZ();
|
||||
int bigx = bigXbigZ.getBlockX();
|
||||
int bigz = bigXbigZ.getBlockZ();
|
||||
|
||||
//Whitelist TODO: some of this might already be included in isTransparent()
|
||||
switch (blockMaterial)
|
||||
{
|
||||
case AIR:
|
||||
case OAK_FENCE:
|
||||
case ACACIA_FENCE:
|
||||
case BIRCH_FENCE:
|
||||
case DARK_OAK_FENCE:
|
||||
case JUNGLE_FENCE:
|
||||
case NETHER_BRICK_FENCE:
|
||||
case SPRUCE_FENCE:
|
||||
case OAK_FENCE_GATE:
|
||||
case ACACIA_FENCE_GATE:
|
||||
case BIRCH_FENCE_GATE:
|
||||
case DARK_OAK_FENCE_GATE:
|
||||
case SPRUCE_FENCE_GATE:
|
||||
case JUNGLE_FENCE_GATE:
|
||||
return true;
|
||||
}
|
||||
BlockData cornerBlockData;
|
||||
BlockData accentBlockData;
|
||||
|
||||
if (Tag.SIGNS.isTagged(blockMaterial) || Tag.WALL_SIGNS.isTagged(blockMaterial))
|
||||
return true;
|
||||
ArrayList<VisualizationElement> newElements = new ArrayList<VisualizationElement>();
|
||||
|
||||
return (waterIsTransparent && block.getType() == Material.WATER) ||
|
||||
block.getType().isTransparent();
|
||||
}
|
||||
if (visualizationType == VisualizationType.Claim)
|
||||
{
|
||||
cornerBlockData = Material.GLOWSTONE.createBlockData();
|
||||
accentBlockData = Material.GOLD_BLOCK.createBlockData();
|
||||
} else if (visualizationType == VisualizationType.AdminClaim)
|
||||
{
|
||||
cornerBlockData = Material.GLOWSTONE.createBlockData();
|
||||
accentBlockData = Material.PUMPKIN.createBlockData();
|
||||
} else if (visualizationType == VisualizationType.Subdivision)
|
||||
{
|
||||
cornerBlockData = Material.IRON_BLOCK.createBlockData();
|
||||
accentBlockData = Material.WHITE_WOOL.createBlockData();
|
||||
} else if (visualizationType == VisualizationType.RestoreNature)
|
||||
{
|
||||
cornerBlockData = Material.DIAMOND_BLOCK.createBlockData();
|
||||
accentBlockData = Material.DIAMOND_BLOCK.createBlockData();
|
||||
} else
|
||||
{
|
||||
cornerBlockData = Material.REDSTONE_ORE.createBlockData();
|
||||
((Lightable) cornerBlockData).setLit(true);
|
||||
accentBlockData = Material.NETHERRACK.createBlockData();
|
||||
}
|
||||
|
||||
//initialize visualization elements without Y values and real data
|
||||
//that will be added later for only the visualization elements within visualization range
|
||||
|
||||
//locality
|
||||
int minx = locality.getBlockX() - 75;
|
||||
int minz = locality.getBlockZ() - 75;
|
||||
int maxx = locality.getBlockX() + 75;
|
||||
int maxz = locality.getBlockZ() + 75;
|
||||
|
||||
final int STEP = 10;
|
||||
|
||||
//top line
|
||||
newElements.add(new VisualizationElement(new Location(world, smallx, 0, bigz), cornerBlockData, Material.AIR.createBlockData()));
|
||||
newElements.add(new VisualizationElement(new Location(world, smallx + 1, 0, bigz), accentBlockData, Material.AIR.createBlockData()));
|
||||
for (int x = smallx + STEP; x < bigx - STEP / 2; x += STEP)
|
||||
{
|
||||
if (x > minx && x < maxx)
|
||||
newElements.add(new VisualizationElement(new Location(world, x, 0, bigz), accentBlockData, Material.AIR.createBlockData()));
|
||||
}
|
||||
newElements.add(new VisualizationElement(new Location(world, bigx - 1, 0, bigz), accentBlockData, Material.AIR.createBlockData()));
|
||||
|
||||
//bottom line
|
||||
newElements.add(new VisualizationElement(new Location(world, smallx + 1, 0, smallz), accentBlockData, Material.AIR.createBlockData()));
|
||||
for (int x = smallx + STEP; x < bigx - STEP / 2; x += STEP)
|
||||
{
|
||||
if (x > minx && x < maxx)
|
||||
newElements.add(new VisualizationElement(new Location(world, x, 0, smallz), accentBlockData, Material.AIR.createBlockData()));
|
||||
}
|
||||
newElements.add(new VisualizationElement(new Location(world, bigx - 1, 0, smallz), accentBlockData, Material.AIR.createBlockData()));
|
||||
|
||||
//left line
|
||||
newElements.add(new VisualizationElement(new Location(world, smallx, 0, smallz), cornerBlockData, Material.AIR.createBlockData()));
|
||||
newElements.add(new VisualizationElement(new Location(world, smallx, 0, smallz + 1), accentBlockData, Material.AIR.createBlockData()));
|
||||
for (int z = smallz + STEP; z < bigz - STEP / 2; z += STEP)
|
||||
{
|
||||
if (z > minz && z < maxz)
|
||||
newElements.add(new VisualizationElement(new Location(world, smallx, 0, z), accentBlockData, Material.AIR.createBlockData()));
|
||||
}
|
||||
newElements.add(new VisualizationElement(new Location(world, smallx, 0, bigz - 1), accentBlockData, Material.AIR.createBlockData()));
|
||||
|
||||
//right line
|
||||
newElements.add(new VisualizationElement(new Location(world, bigx, 0, smallz), cornerBlockData, Material.AIR.createBlockData()));
|
||||
newElements.add(new VisualizationElement(new Location(world, bigx, 0, smallz + 1), accentBlockData, Material.AIR.createBlockData()));
|
||||
for (int z = smallz + STEP; z < bigz - STEP / 2; z += STEP)
|
||||
{
|
||||
if (z > minz && z < maxz)
|
||||
newElements.add(new VisualizationElement(new Location(world, bigx, 0, z), accentBlockData, Material.AIR.createBlockData()));
|
||||
}
|
||||
newElements.add(new VisualizationElement(new Location(world, bigx, 0, bigz - 1), accentBlockData, Material.AIR.createBlockData()));
|
||||
newElements.add(new VisualizationElement(new Location(world, bigx, 0, bigz), cornerBlockData, Material.AIR.createBlockData()));
|
||||
|
||||
//remove any out of range elements
|
||||
this.removeElementsOutOfRange(newElements, minx, minz, maxx, maxz);
|
||||
|
||||
//remove any elements outside the claim
|
||||
for (int i = 0; i < newElements.size(); i++)
|
||||
{
|
||||
VisualizationElement element = newElements.get(i);
|
||||
if (!claim.contains(element.location, true, false))
|
||||
{
|
||||
newElements.remove(i--);
|
||||
}
|
||||
}
|
||||
|
||||
//set Y values and real block information for any remaining visualization blocks
|
||||
for (VisualizationElement element : newElements)
|
||||
{
|
||||
Location tempLocation = element.location;
|
||||
element.location = getVisibleLocation(tempLocation.getWorld(), tempLocation.getBlockX(), height, tempLocation.getBlockZ(), waterIsTransparent);
|
||||
height = element.location.getBlockY();
|
||||
element.realBlock = element.location.getBlock().getBlockData();
|
||||
}
|
||||
|
||||
this.elements.addAll(newElements);
|
||||
}
|
||||
|
||||
//removes any elements which are out of visualization range
|
||||
private void removeElementsOutOfRange(ArrayList<VisualizationElement> elements, int minx, int minz, int maxx, int maxz)
|
||||
{
|
||||
for (int i = 0; i < elements.size(); i++)
|
||||
{
|
||||
Location location = elements.get(i).location;
|
||||
if (location.getX() < minx || location.getX() > maxx || location.getZ() < minz || location.getZ() > maxz)
|
||||
{
|
||||
elements.remove(i--);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//finds a block the player can probably see. this is how visualizations "cling" to the ground or ceiling
|
||||
private static Location getVisibleLocation(World world, int x, int y, int z, boolean waterIsTransparent)
|
||||
{
|
||||
Block block = world.getBlockAt(x, y, z);
|
||||
BlockFace direction = (isTransparent(block, waterIsTransparent)) ? BlockFace.DOWN : BlockFace.UP;
|
||||
|
||||
while (block.getY() >= 1 &&
|
||||
block.getY() < world.getMaxHeight() - 1 &&
|
||||
(!isTransparent(block.getRelative(BlockFace.UP), waterIsTransparent) || isTransparent(block, waterIsTransparent)))
|
||||
{
|
||||
block = block.getRelative(direction);
|
||||
}
|
||||
|
||||
return block.getLocation();
|
||||
}
|
||||
|
||||
//helper method for above. allows visualization blocks to sit underneath partly transparent blocks like grass and fence
|
||||
private static boolean isTransparent(Block block, boolean waterIsTransparent)
|
||||
{
|
||||
Material blockMaterial = block.getType();
|
||||
//Blacklist
|
||||
switch (blockMaterial)
|
||||
{
|
||||
case SNOW:
|
||||
return false;
|
||||
}
|
||||
|
||||
//Whitelist TODO: some of this might already be included in isTransparent()
|
||||
switch (blockMaterial)
|
||||
{
|
||||
case AIR:
|
||||
case OAK_FENCE:
|
||||
case ACACIA_FENCE:
|
||||
case BIRCH_FENCE:
|
||||
case DARK_OAK_FENCE:
|
||||
case JUNGLE_FENCE:
|
||||
case NETHER_BRICK_FENCE:
|
||||
case SPRUCE_FENCE:
|
||||
case OAK_FENCE_GATE:
|
||||
case ACACIA_FENCE_GATE:
|
||||
case BIRCH_FENCE_GATE:
|
||||
case DARK_OAK_FENCE_GATE:
|
||||
case SPRUCE_FENCE_GATE:
|
||||
case JUNGLE_FENCE_GATE:
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Tag.SIGNS.isTagged(blockMaterial) || Tag.WALL_SIGNS.isTagged(blockMaterial))
|
||||
return true;
|
||||
|
||||
return (waterIsTransparent && block.getType() == Material.WATER) ||
|
||||
block.getType().isTransparent();
|
||||
}
|
||||
|
||||
public static Visualization fromClaims(Iterable<Claim> claims, int height, VisualizationType type, Location locality)
|
||||
{
|
||||
Visualization visualization = new Visualization();
|
||||
|
||||
for(Claim claim : claims)
|
||||
|
||||
for (Claim claim : claims)
|
||||
{
|
||||
visualization.addClaimElements(claim, height, type, locality);
|
||||
}
|
||||
|
||||
|
||||
return visualization;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,46 +15,46 @@
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
//applies a visualization for a player by sending him block change packets
|
||||
class VisualizationApplicationTask implements Runnable
|
||||
class VisualizationApplicationTask implements Runnable
|
||||
{
|
||||
private Visualization visualization;
|
||||
private Player player;
|
||||
private PlayerData playerData;
|
||||
private Visualization visualization;
|
||||
private Player player;
|
||||
private PlayerData playerData;
|
||||
|
||||
public VisualizationApplicationTask(Player player, PlayerData playerData, Visualization visualization)
|
||||
{
|
||||
this.visualization = visualization;
|
||||
this.playerData = playerData;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public VisualizationApplicationTask(Player player, PlayerData playerData, Visualization visualization)
|
||||
{
|
||||
this.visualization = visualization;
|
||||
this.playerData = playerData;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
//for each element (=block) of the visualization
|
||||
for(int i = 0; i < visualization.elements.size(); i++)
|
||||
{
|
||||
VisualizationElement element = visualization.elements.get(i);
|
||||
|
||||
//send the player a fake block change event
|
||||
if(!element.location.getChunk().isLoaded()) continue; //cheap distance check
|
||||
player.sendBlockChange(element.location, element.visualizedBlock);
|
||||
}
|
||||
|
||||
//remember the visualization applied to this player for later (so it can be inexpensively reverted)
|
||||
playerData.currentVisualization = visualization;
|
||||
|
||||
//schedule automatic visualization reversion in 60 seconds.
|
||||
GriefPrevention.instance.getServer().getScheduler().scheduleSyncDelayedTask(
|
||||
GriefPrevention.instance,
|
||||
new VisualizationReversionTask(player, playerData, visualization),
|
||||
20L * 60); //60 seconds
|
||||
}
|
||||
public void run()
|
||||
{
|
||||
//for each element (=block) of the visualization
|
||||
for (int i = 0; i < visualization.elements.size(); i++)
|
||||
{
|
||||
VisualizationElement element = visualization.elements.get(i);
|
||||
|
||||
//send the player a fake block change event
|
||||
if (!element.location.getChunk().isLoaded()) continue; //cheap distance check
|
||||
player.sendBlockChange(element.location, element.visualizedBlock);
|
||||
}
|
||||
|
||||
//remember the visualization applied to this player for later (so it can be inexpensively reverted)
|
||||
playerData.currentVisualization = visualization;
|
||||
|
||||
//schedule automatic visualization reversion in 60 seconds.
|
||||
GriefPrevention.instance.getServer().getScheduler().scheduleSyncDelayedTask(
|
||||
GriefPrevention.instance,
|
||||
new VisualizationReversionTask(player, playerData, visualization),
|
||||
20L * 60); //60 seconds
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,21 +17,21 @@
|
|||
*/
|
||||
|
||||
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
|
||||
public class VisualizationElement
|
||||
public class VisualizationElement
|
||||
{
|
||||
public Location location;
|
||||
public BlockData visualizedBlock;
|
||||
public BlockData realBlock;
|
||||
|
||||
public VisualizationElement(Location location, BlockData visualizedBlock, BlockData realBlock)
|
||||
{
|
||||
this.location = location;
|
||||
this.visualizedBlock = visualizedBlock;
|
||||
this.realBlock = realBlock;
|
||||
}
|
||||
public Location location;
|
||||
public BlockData visualizedBlock;
|
||||
public BlockData realBlock;
|
||||
|
||||
public VisualizationElement(Location location, BlockData visualizedBlock, BlockData realBlock)
|
||||
{
|
||||
this.location = location;
|
||||
this.visualizedBlock = visualizedBlock;
|
||||
this.realBlock = realBlock;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.events.VisualizationEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
|
|
@ -25,28 +25,28 @@ import org.bukkit.entity.Player;
|
|||
import java.util.Collections;
|
||||
|
||||
//applies a visualization for a player by sending him block change packets
|
||||
class VisualizationReversionTask implements Runnable
|
||||
class VisualizationReversionTask implements Runnable
|
||||
{
|
||||
private Visualization visualization;
|
||||
private Player player;
|
||||
private PlayerData playerData;
|
||||
private Visualization visualization;
|
||||
private Player player;
|
||||
private PlayerData playerData;
|
||||
|
||||
public VisualizationReversionTask(Player player, PlayerData playerData, Visualization visualization)
|
||||
{
|
||||
this.visualization = visualization;
|
||||
this.playerData = playerData;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
//don't do anything if the player's current visualization is different from the one scheduled to revert
|
||||
if(playerData.currentVisualization != visualization) return;
|
||||
public VisualizationReversionTask(Player player, PlayerData playerData, Visualization visualization)
|
||||
{
|
||||
this.visualization = visualization;
|
||||
this.playerData = playerData;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
// alert plugins of a visualization
|
||||
Bukkit.getPluginManager().callEvent(new VisualizationEvent(player, Collections.<Claim>emptySet()));
|
||||
|
||||
Visualization.Revert(player);
|
||||
}
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
//don't do anything if the player's current visualization is different from the one scheduled to revert
|
||||
if (playerData.currentVisualization != visualization) return;
|
||||
|
||||
// alert plugins of a visualization
|
||||
Bukkit.getPluginManager().callEvent(new VisualizationEvent(player, Collections.<Claim>emptySet()));
|
||||
|
||||
Visualization.Revert(player);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,11 +19,11 @@
|
|||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
//just an enumeration of the visualization types, which determine what materials will be for the fake blocks
|
||||
public enum VisualizationType
|
||||
public enum VisualizationType
|
||||
{
|
||||
Claim,
|
||||
Subdivision,
|
||||
ErrorClaim,
|
||||
RestoreNature,
|
||||
AdminClaim
|
||||
Claim,
|
||||
Subdivision,
|
||||
ErrorClaim,
|
||||
RestoreNature,
|
||||
AdminClaim
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,24 +10,24 @@ import org.bukkit.inventory.meta.BookMeta;
|
|||
public class WelcomeTask implements Runnable
|
||||
{
|
||||
private Player player;
|
||||
|
||||
|
||||
public WelcomeTask(Player player)
|
||||
{
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
//abort if player has logged out since this task was scheduled
|
||||
if(!this.player.isOnline()) return;
|
||||
|
||||
if (!this.player.isOnline()) return;
|
||||
|
||||
//offer advice and a helpful link
|
||||
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.AvoidGriefClaimLand);
|
||||
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.SurvivalBasicsVideo2, DataStore.SURVIVAL_VIDEO_URL);
|
||||
|
||||
|
||||
//give the player a reference book for later
|
||||
if(GriefPrevention.instance.config_claims_supplyPlayerManual)
|
||||
if (GriefPrevention.instance.config_claims_supplyPlayerManual)
|
||||
{
|
||||
ItemFactory factory = Bukkit.getItemFactory();
|
||||
BookMeta meta = (BookMeta) factory.getItemMeta(Material.WRITTEN_BOOK);
|
||||
|
|
@ -35,43 +35,43 @@ public class WelcomeTask implements Runnable
|
|||
DataStore datastore = GriefPrevention.instance.dataStore;
|
||||
meta.setAuthor(datastore.getMessage(Messages.BookAuthor));
|
||||
meta.setTitle(datastore.getMessage(Messages.BookTitle));
|
||||
|
||||
|
||||
StringBuilder page1 = new StringBuilder();
|
||||
String URL = datastore.getMessage(Messages.BookLink, DataStore.SURVIVAL_VIDEO_URL);
|
||||
String intro = datastore.getMessage(Messages.BookIntro);
|
||||
|
||||
|
||||
page1.append(URL).append("\n\n");
|
||||
page1.append(intro).append("\n\n");
|
||||
String editToolName = GriefPrevention.instance.config_claims_modificationTool.name().replace('_', ' ').toLowerCase();
|
||||
String infoToolName = GriefPrevention.instance.config_claims_investigationTool.name().replace('_', ' ').toLowerCase();
|
||||
String configClaimTools = datastore.getMessage(Messages.BookTools, editToolName, infoToolName);
|
||||
page1.append(configClaimTools);
|
||||
if(GriefPrevention.instance.config_claims_automaticClaimsForNewPlayersRadius < 0)
|
||||
if (GriefPrevention.instance.config_claims_automaticClaimsForNewPlayersRadius < 0)
|
||||
{
|
||||
page1.append(datastore.getMessage(Messages.BookDisabledChestClaims));
|
||||
}
|
||||
|
||||
|
||||
StringBuilder page2 = new StringBuilder(datastore.getMessage(Messages.BookUsefulCommands)).append("\n\n");
|
||||
page2.append("/Trust /UnTrust /TrustList\n");
|
||||
page2.append("/ClaimsList\n");
|
||||
page2.append("/AbandonClaim\n\n");
|
||||
page2.append("/Claim /ExtendClaim\n");
|
||||
|
||||
|
||||
page2.append("/IgnorePlayer\n\n");
|
||||
|
||||
|
||||
page2.append("/SubdivideClaims\n");
|
||||
page2.append("/AccessTrust\n");
|
||||
page2.append("/ContainerTrust\n");
|
||||
page2.append("/PermissionTrust");
|
||||
|
||||
|
||||
meta.setPages(page1.toString(), page2.toString());
|
||||
|
||||
ItemStack item = new ItemStack(Material.WRITTEN_BOOK);
|
||||
item.setItemMeta(meta);
|
||||
player.getInventory().addItem(item);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,35 +6,35 @@ import java.util.regex.Pattern;
|
|||
|
||||
class WordFinder
|
||||
{
|
||||
private Pattern pattern;
|
||||
|
||||
private Pattern pattern;
|
||||
|
||||
WordFinder(List<String> wordsToFind)
|
||||
{
|
||||
if(wordsToFind.size() == 0) return;
|
||||
|
||||
if (wordsToFind.size() == 0) return;
|
||||
|
||||
StringBuilder patternBuilder = new StringBuilder();
|
||||
for(String word : wordsToFind)
|
||||
for (String word : wordsToFind)
|
||||
{
|
||||
if(!word.isEmpty() && !word.trim().isEmpty())
|
||||
if (!word.isEmpty() && !word.trim().isEmpty())
|
||||
{
|
||||
patternBuilder.append("|(([^\\w]|^)" + Pattern.quote(word) + "([^\\w]|$))");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String patternString = patternBuilder.toString();
|
||||
if(patternString.length() > 1)
|
||||
if (patternString.length() > 1)
|
||||
{
|
||||
//trim extraneous leading pipe (|)
|
||||
patternString = patternString.substring(1);
|
||||
}
|
||||
|
||||
|
||||
this.pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
|
||||
}
|
||||
|
||||
|
||||
boolean hasMatch(String input)
|
||||
{
|
||||
if(this.pattern == null) return false;
|
||||
|
||||
if (this.pattern == null) return false;
|
||||
|
||||
Matcher matcher = this.pattern.matcher(input);
|
||||
return matcher.find();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,18 @@
|
|||
package me.ryanhamshire.GriefPrevention;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.bukkit.BukkitPlayer;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.internal.permission.RegionPermissionModel;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
class WorldGuardWrapper
|
||||
{
|
||||
|
|
@ -21,7 +20,7 @@ class WorldGuardWrapper
|
|||
|
||||
public WorldGuardWrapper() throws ClassNotFoundException
|
||||
{
|
||||
this.worldGuard = (WorldGuardPlugin)GriefPrevention.instance.getServer().getPluginManager().getPlugin("WorldGuard");
|
||||
this.worldGuard = (WorldGuardPlugin) GriefPrevention.instance.getServer().getPluginManager().getPlugin("WorldGuard");
|
||||
}
|
||||
|
||||
public boolean canBuild(Location lesserCorner, Location greaterCorner, Player creatingPlayer)
|
||||
|
|
@ -31,11 +30,11 @@ class WorldGuardWrapper
|
|||
BukkitPlayer localPlayer = new BukkitPlayer(this.worldGuard, creatingPlayer);
|
||||
World world = WorldGuard.getInstance().getPlatform().getMatcher().getWorldByName(lesserCorner.getWorld().getName());
|
||||
|
||||
if(new RegionPermissionModel(localPlayer).mayIgnoreRegionProtection(world)) return true;
|
||||
if (new RegionPermissionModel(localPlayer).mayIgnoreRegionProtection(world)) return true;
|
||||
|
||||
RegionManager manager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(world);
|
||||
RegionManager manager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(world);
|
||||
|
||||
if(manager != null)
|
||||
if (manager != null)
|
||||
{
|
||||
ProtectedCuboidRegion tempRegion = new ProtectedCuboidRegion(
|
||||
"GP_TEMP",
|
||||
|
|
@ -43,8 +42,10 @@ class WorldGuardWrapper
|
|||
BlockVector3.at(greaterCorner.getX(), world.getMaxY(), greaterCorner.getZ()));
|
||||
|
||||
ApplicableRegionSet overlaps = manager.getApplicableRegions(tempRegion);
|
||||
for (ProtectedRegion r : overlaps.getRegions()) {
|
||||
if (!manager.getApplicableRegions(r).testState(localPlayer, Flags.BUILD)) {
|
||||
for (ProtectedRegion r : overlaps.getRegions())
|
||||
{
|
||||
if (!manager.getApplicableRegions(r).testState(localPlayer, Flags.BUILD))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,11 +14,15 @@ public class AccrueClaimBlocksEvent extends Event
|
|||
{
|
||||
// Custom Event Requirements
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
public static HandlerList getHandlerList() {
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
|
|
@ -30,7 +34,6 @@ public class AccrueClaimBlocksEvent extends Event
|
|||
/**
|
||||
* @param player Player receiving accruals
|
||||
* @param blocksToAccrue Blocks to accrue
|
||||
*
|
||||
* @deprecated Use {@link #AccrueClaimBlocksEvent(Player, int, boolean)} instead
|
||||
*/
|
||||
public AccrueClaimBlocksEvent(Player player, int blocksToAccrue)
|
||||
|
|
@ -67,7 +70,8 @@ public class AccrueClaimBlocksEvent extends Event
|
|||
/**
|
||||
* @return whether the player was detected as idle (used for idle accrual percentage)
|
||||
*/
|
||||
public boolean isIdle() {
|
||||
public boolean isIdle()
|
||||
{
|
||||
return this.isIdle;
|
||||
}
|
||||
|
||||
|
|
@ -78,6 +82,7 @@ public class AccrueClaimBlocksEvent extends Event
|
|||
|
||||
/**
|
||||
* Modify the amount of claim blocks to deliver to the player for this 10 minute interval
|
||||
*
|
||||
* @param blocksToAccrue blocks to deliver
|
||||
*/
|
||||
public void setBlocksToAccrue(int blocksToAccrue)
|
||||
|
|
@ -87,6 +92,7 @@ public class AccrueClaimBlocksEvent extends Event
|
|||
|
||||
/**
|
||||
* Similar to setBlocksToAccrue(int), but automatically converting from a per-hour rate value to a 10-minute rate value
|
||||
*
|
||||
* @param blocksToAccruePerHour the per-hour rate of blocks to deliver
|
||||
*/
|
||||
|
||||
|
|
|
|||
|
|
@ -13,11 +13,13 @@ import org.bukkit.event.HandlerList;
|
|||
* Created by Narimm on 5/08/2018.
|
||||
*/
|
||||
|
||||
public class ClaimCreatedEvent extends Event implements Cancellable {
|
||||
public class ClaimCreatedEvent extends Event implements Cancellable
|
||||
{
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
|
|
@ -27,23 +29,27 @@ public class ClaimCreatedEvent extends Event implements Cancellable {
|
|||
|
||||
private boolean cancelled = false;
|
||||
|
||||
public ClaimCreatedEvent(Claim claim, CommandSender creator) {
|
||||
public ClaimCreatedEvent(Claim claim, CommandSender creator)
|
||||
{
|
||||
this.claim = claim;
|
||||
this.creator = creator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
public boolean isCancelled()
|
||||
{
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean b) {
|
||||
public void setCancelled(boolean b)
|
||||
{
|
||||
this.cancelled = b;
|
||||
}
|
||||
|
||||
|
|
@ -52,7 +58,8 @@ public class ClaimCreatedEvent extends Event implements Cancellable {
|
|||
*
|
||||
* @return Claim
|
||||
*/
|
||||
public Claim getClaim() {
|
||||
public Claim getClaim()
|
||||
{
|
||||
return claim;
|
||||
}
|
||||
|
||||
|
|
@ -61,7 +68,8 @@ public class ClaimCreatedEvent extends Event implements Cancellable {
|
|||
*
|
||||
* @return the CommandSender
|
||||
*/
|
||||
public CommandSender getCreator() {
|
||||
public CommandSender getCreator()
|
||||
{
|
||||
return creator;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,43 +1,46 @@
|
|||
package me.ryanhamshire.GriefPrevention.events;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.Claim;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* This event gets called whenever a claim is going to be deleted. This event is
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the claim to be deleted.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Claim getClaim() {
|
||||
public Claim getClaim()
|
||||
{
|
||||
return claim;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
package me.ryanhamshire.GriefPrevention.events;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.Claim;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
|
@ -11,7 +10,7 @@ public class ClaimExpirationEvent extends Event implements Cancellable
|
|||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled = false;
|
||||
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
|
|
@ -34,13 +33,13 @@ public class ClaimExpirationEvent extends Event implements Cancellable
|
|||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isCancelled()
|
||||
{
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ public class PlayerKickBanEvent extends Event
|
|||
/**
|
||||
* @param player Player getting kicked and/or banned
|
||||
* @param reason Reason message for kick/ban
|
||||
* @param source What caused the kick/ban
|
||||
* @param ban True if player is getting banned
|
||||
* @param source What caused the kick/ban
|
||||
* @param ban True if player is getting banned
|
||||
*/
|
||||
public PlayerKickBanEvent(Player player, String reason, String source, boolean ban)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ public class PreventBlockBreakEvent extends Event implements Cancellable
|
|||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled = false;
|
||||
private BlockBreakEvent innerEvent;
|
||||
private BlockBreakEvent innerEvent;
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
|
|
@ -21,7 +21,7 @@ public class PreventBlockBreakEvent extends Event implements Cancellable
|
|||
{
|
||||
this.innerEvent = innerEvent;
|
||||
}
|
||||
|
||||
|
||||
public BlockBreakEvent getInnerEvent()
|
||||
{
|
||||
return this.innerEvent;
|
||||
|
|
@ -32,13 +32,13 @@ public class PreventBlockBreakEvent extends Event implements Cancellable
|
|||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isCancelled()
|
||||
{
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -34,13 +33,13 @@ public class PreventPvPEvent extends Event implements Cancellable
|
|||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isCancelled()
|
||||
{
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -34,13 +33,13 @@ public class ProtectDeathDropsEvent extends Event implements Cancellable
|
|||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isCancelled()
|
||||
{
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -46,13 +45,13 @@ public class SaveTrappedPlayerEvent extends Event implements Cancellable
|
|||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isCancelled()
|
||||
{
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,110 +1,119 @@
|
|||
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
|
||||
*
|
||||
* @author roinujnosde
|
||||
*/
|
||||
public class TrustChangedEvent extends Event implements Cancellable {
|
||||
|
||||
public class TrustChangedEvent extends Event implements Cancellable
|
||||
{
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
|
||||
private final Player changer;
|
||||
private final List<Claim> claims;
|
||||
private final ClaimPermission claimPermission;
|
||||
private final boolean given;
|
||||
private final String identifier;
|
||||
private boolean cancelled;
|
||||
|
||||
public TrustChangedEvent(Player changer, List<Claim> claims, ClaimPermission claimPermission, boolean given,
|
||||
String identifier) {
|
||||
super();
|
||||
this.changer = changer;
|
||||
this.claims = claims;
|
||||
this.claimPermission = claimPermission;
|
||||
this.given = given;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public TrustChangedEvent(Player changer, Claim claim, ClaimPermission claimPermission, boolean given, String identifier) {
|
||||
this.changer = changer;
|
||||
claims = new ArrayList<>();
|
||||
claims.add(claim);
|
||||
this.claimPermission = claimPermission;
|
||||
this.given = given;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
public TrustChangedEvent(Player changer, List<Claim> claims, ClaimPermission claimPermission, boolean given,
|
||||
String identifier)
|
||||
{
|
||||
super();
|
||||
this.changer = changer;
|
||||
this.claims = claims;
|
||||
this.claimPermission = claimPermission;
|
||||
this.given = given;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets who made the change
|
||||
*
|
||||
* @return the changer
|
||||
*/
|
||||
public Player getChanger() {
|
||||
return changer;
|
||||
}
|
||||
public TrustChangedEvent(Player changer, Claim claim, ClaimPermission claimPermission, boolean given, String identifier)
|
||||
{
|
||||
this.changer = changer;
|
||||
claims = new ArrayList<>();
|
||||
claims.add(claim);
|
||||
this.claimPermission = claimPermission;
|
||||
this.given = given;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the changed claims
|
||||
*
|
||||
* @return the changed claims
|
||||
*/
|
||||
public List<Claim> getClaims() {
|
||||
return claims;
|
||||
}
|
||||
@Override
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the claim permission (null if the permission is being taken)
|
||||
*
|
||||
* @return the claim permission
|
||||
*/
|
||||
public ClaimPermission getClaimPermission() {
|
||||
return claimPermission;
|
||||
}
|
||||
/**
|
||||
* Gets who made the change
|
||||
*
|
||||
* @return the changer
|
||||
*/
|
||||
public Player getChanger()
|
||||
{
|
||||
return changer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the trust is being given
|
||||
*
|
||||
* @return true if given, false if taken
|
||||
*/
|
||||
public boolean isGiven() {
|
||||
return given;
|
||||
}
|
||||
/**
|
||||
* Gets the changed claims
|
||||
*
|
||||
* @return the changed claims
|
||||
*/
|
||||
public List<Claim> getClaims()
|
||||
{
|
||||
return claims;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the identifier of the receiver of this action
|
||||
* Can be: "public", "all", a UUID, a permission
|
||||
*
|
||||
* @return the identifier
|
||||
*/
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
/**
|
||||
* Gets the claim permission (null if the permission is being taken)
|
||||
*
|
||||
* @return the claim permission
|
||||
*/
|
||||
public ClaimPermission getClaimPermission()
|
||||
{
|
||||
return claimPermission;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
/**
|
||||
* Checks if the trust is being given
|
||||
*
|
||||
* @return true if given, false if taken
|
||||
*/
|
||||
public boolean isGiven()
|
||||
{
|
||||
return given;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
/**
|
||||
* Gets the identifier of the receiver of this action
|
||||
* Can be: "public", "all", a UUID, a permission
|
||||
*
|
||||
* @return the identifier
|
||||
*/
|
||||
public String getIdentifier()
|
||||
{
|
||||
return identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled()
|
||||
{
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled)
|
||||
{
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ import java.util.Collections;
|
|||
/**
|
||||
* Called when GriefPrevention is sending claim visuals to a player
|
||||
*/
|
||||
public class VisualizationEvent extends PlayerEvent {
|
||||
public class VisualizationEvent extends PlayerEvent
|
||||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private final Collection<Claim> claims;
|
||||
private final boolean showSubdivides;
|
||||
|
|
@ -22,7 +23,8 @@ public class VisualizationEvent extends PlayerEvent {
|
|||
* @param player Player receiving visuals
|
||||
* @param claim The claim being visualized (with subdivides), or null if visuals being removed
|
||||
*/
|
||||
public VisualizationEvent(Player player, Claim claim) {
|
||||
public VisualizationEvent(Player player, Claim claim)
|
||||
{
|
||||
super(player);
|
||||
this.claims = Collections.singleton(claim);
|
||||
this.showSubdivides = true;
|
||||
|
|
@ -34,7 +36,8 @@ public class VisualizationEvent extends PlayerEvent {
|
|||
* @param player Player receiving visuals
|
||||
* @param claims Claims being visualized (without subdivides)
|
||||
*/
|
||||
public VisualizationEvent(Player player, Collection<Claim> claims) {
|
||||
public VisualizationEvent(Player player, Collection<Claim> claims)
|
||||
{
|
||||
super(player);
|
||||
this.claims = claims;
|
||||
this.showSubdivides = false;
|
||||
|
|
@ -45,7 +48,8 @@ public class VisualizationEvent extends PlayerEvent {
|
|||
*
|
||||
* @return Claims being visualized
|
||||
*/
|
||||
public Collection<Claim> getClaims() {
|
||||
public Collection<Claim> getClaims()
|
||||
{
|
||||
return claims;
|
||||
}
|
||||
|
||||
|
|
@ -54,16 +58,19 @@ public class VisualizationEvent extends PlayerEvent {
|
|||
*
|
||||
* @return True if subdivide claims are being shown
|
||||
*/
|
||||
public boolean showSubdivides() {
|
||||
public boolean showSubdivides()
|
||||
{
|
||||
return showSubdivides;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
*
|
||||
* @author Ryan
|
||||
*/
|
||||
/**
|
||||
* @author Ryan
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import java.util.concurrent.Callable;
|
|||
public class MetricsHandler
|
||||
{
|
||||
private Metrics metrics;
|
||||
|
||||
public MetricsHandler(GriefPrevention plugin, String dataMode)
|
||||
{
|
||||
metrics = new Metrics(plugin);
|
||||
|
|
@ -23,7 +24,7 @@ public class MetricsHandler
|
|||
addSimplePie("custom_build", plugin.getDescription().getVersion().equals("15.2.2"));
|
||||
addSimplePie("bukkit_impl", plugin.getServer().getVersion().split("-")[1]);
|
||||
}
|
||||
catch (Throwable ignored){}
|
||||
catch (Throwable ignored) {}
|
||||
|
||||
//enums and etc. would be amazing.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user