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.
This commit is contained in:
ryanhamshire 2014-11-21 21:35:04 -08:00
parent 9ceb5b1167
commit be0974bb25
2 changed files with 36 additions and 5 deletions

View File

@ -22,6 +22,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -305,7 +306,7 @@ public class GriefPrevention extends JavaPlugin
int playersCached = 0; int playersCached = 0;
OfflinePlayer [] offlinePlayers = this.getServer().getOfflinePlayers(); OfflinePlayer [] offlinePlayers = this.getServer().getOfflinePlayers();
long now = System.currentTimeMillis(); 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) for(OfflinePlayer player : offlinePlayers)
{ {
try try
@ -313,10 +314,12 @@ public class GriefPrevention extends JavaPlugin
String playerName = player.getName(); String playerName = player.getName();
UUID playerID = player.getUniqueId(); UUID playerID = player.getUniqueId();
if(playerName == null || playerID == null) continue; 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 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, playerID);
this.playerNameToIDMap.put(playerName.toLowerCase(), playerID); this.playerNameToIDMap.put(playerName.toLowerCase(), playerID);

View File

@ -1195,7 +1195,6 @@ class PlayerEventHandler implements Listener
Claim claim = this.dataStore.getClaimAt(clickedBlock.getLocation(), false, playerData.lastClaim); Claim claim = this.dataStore.getClaimAt(clickedBlock.getLocation(), false, playerData.lastClaim);
if(claim != null) if(claim != null)
{ {
if(playerData == null) playerData = this.dataStore.getPlayerData(player.getUniqueId());
playerData.lastClaim = claim; playerData.lastClaim = claim;
String noAccessReason = claim.allowAccess(player); 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; if(action != Action.RIGHT_CLICK_BLOCK && action != Action.RIGHT_CLICK_AIR) return;
//what's the player holding? //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 it's bonemeal, check for build permission (ink sac == bone meal, must be a Bukkit bug?)
if(clickedBlock != null && materialInHand == Material.INK_SACK) if(clickedBlock != null && materialInHand == Material.INK_SACK)
@ -1366,6 +1366,33 @@ class PlayerEventHandler implements Listener
return; 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 //if it's a golden shovel
else if(materialInHand != GriefPrevention.instance.config_claims_modificationTool) return; else if(materialInHand != GriefPrevention.instance.config_claims_modificationTool) return;
@ -1914,6 +1941,7 @@ class PlayerEventHandler implements Listener
if(cachedValue != null) if(cachedValue != null)
{ {
return cachedValue.booleanValue(); return cachedValue.booleanValue();
} }
else else
{ {