From be0974bb2540d379e9492491dc3e36a7da2ff8df Mon Sep 17 00:00:00 2001 From: ryanhamshire Date: Fri, 21 Nov 2014 21:35:04 -0800 Subject: [PATCH] Fixes: Non-Vanilla items and offline players. Proactive defense against non-Vanilla items changing claimed parts of the world without permission. Fixed offline player caching not caching all the players it should. --- .../GriefPrevention/GriefPrevention.java | 9 ++++-- .../GriefPrevention/PlayerEventHandler.java | 32 +++++++++++++++++-- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java index 2305a4a..d6b8a94 100644 --- a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java +++ b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java @@ -22,6 +22,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Calendar; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.UUID; @@ -305,7 +306,7 @@ public class GriefPrevention extends JavaPlugin int playersCached = 0; OfflinePlayer [] offlinePlayers = this.getServer().getOfflinePlayers(); long now = System.currentTimeMillis(); - final long WHILEBACK = 1000 * 60 * 60 * 24 * 30; //30 days back + final long millisecondsPerDay = 1000 * 60 * 60 * 24; for(OfflinePlayer player : offlinePlayers) { try @@ -313,10 +314,12 @@ public class GriefPrevention extends JavaPlugin String playerName = player.getName(); UUID playerID = player.getUniqueId(); if(playerName == null || playerID == null) continue; - long absentMilliseconds = now - player.getLastPlayed(); + long lastSeen = player.getLastPlayed(); //if the player has been seen in the last 30 days, cache his name/UUID pair - if(absentMilliseconds < WHILEBACK) + long diff = now - lastSeen; + long daysDiff = diff / millisecondsPerDay; + if(daysDiff <= 30) { this.playerNameToIDMap.put(playerName, playerID); this.playerNameToIDMap.put(playerName.toLowerCase(), playerID); diff --git a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java index 27bf75a..157e808 100644 --- a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java +++ b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java @@ -1195,7 +1195,6 @@ class PlayerEventHandler implements Listener Claim claim = this.dataStore.getClaimAt(clickedBlock.getLocation(), false, playerData.lastClaim); if(claim != null) { - if(playerData == null) playerData = this.dataStore.getPlayerData(player.getUniqueId()); playerData.lastClaim = claim; String noAccessReason = claim.allowAccess(player); @@ -1232,7 +1231,8 @@ class PlayerEventHandler implements Listener if(action != Action.RIGHT_CLICK_BLOCK && action != Action.RIGHT_CLICK_AIR) return; //what's the player holding? - Material materialInHand = player.getItemInHand().getType(); + ItemStack itemInHand = player.getItemInHand(); + Material materialInHand = itemInHand.getType(); //if it's bonemeal, check for build permission (ink sac == bone meal, must be a Bukkit bug?) if(clickedBlock != null && materialInHand == Material.INK_SACK) @@ -1366,6 +1366,33 @@ class PlayerEventHandler implements Listener return; } + //if holding a non-vanilla item + else if(Material.getMaterial(itemInHand.getTypeId()) == null) + { + //assume it's a long range tool and project out ahead + if(action == Action.RIGHT_CLICK_AIR) + { + //try to find a far away non-air block along line of sight + clickedBlock = getTargetBlock(player, 100); + } + + //if target is claimed, require build trust permission + if(playerData == null) playerData = this.dataStore.getPlayerData(player.getUniqueId()); + Claim claim = this.dataStore.getClaimAt(clickedBlock.getLocation(), false, playerData.lastClaim); + if(claim != null) + { + String reason = claim.allowBreak(player, Material.AIR); + if(reason != null) + { + GriefPrevention.sendMessage(player, TextMode.Err, reason); + event.setCancelled(true); + return; + } + } + + return; + } + //if it's a golden shovel else if(materialInHand != GriefPrevention.instance.config_claims_modificationTool) return; @@ -1914,6 +1941,7 @@ class PlayerEventHandler implements Listener if(cachedValue != null) { return cachedValue.booleanValue(); + } else {