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:
parent
9ceb5b1167
commit
be0974bb25
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
@ -1363,6 +1363,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;
|
||||
}
|
||||
|
||||
|
|
@ -1914,6 +1941,7 @@ class PlayerEventHandler implements Listener
|
|||
if(cachedValue != null)
|
||||
{
|
||||
return cachedValue.booleanValue();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user