This commit is contained in:
Len 2023-10-31 19:02:49 +01:00
commit 543820ab71
4 changed files with 53 additions and 19 deletions

View File

@ -294,7 +294,7 @@ public class BlockEventHandler implements Listener
//If block is a chest, don't allow a DoubleChest to form across a claim boundary //If block is a chest, don't allow a DoubleChest to form across a claim boundary
denyConnectingDoubleChestsAcrossClaimBoundary(claim, block, player); denyConnectingDoubleChestsAcrossClaimBoundary(claim, block, player);
if (claim != null) if (claim != null)
{ {
playerData.lastClaim = claim; playerData.lastClaim = claim;
@ -861,7 +861,7 @@ public class BlockEventHandler implements Listener
Block block = event.getHitBlock(); Block block = event.getHitBlock();
// Ensure projectile affects block. // Ensure projectile affects block.
if (block == null || block.getType() != Material.CHORUS_FLOWER) if (block == null || !(block.getType() == Material.CHORUS_FLOWER || block.getType() == Material.TARGET))
return; return;
Claim claim = dataStore.getClaimAt(block.getLocation(), false, null); Claim claim = dataStore.getClaimAt(block.getLocation(), false, null);
@ -871,8 +871,8 @@ public class BlockEventHandler implements Listener
Player shooter = null; Player shooter = null;
Projectile projectile = event.getEntity(); Projectile projectile = event.getEntity();
if (projectile.getShooter() instanceof Player) if (projectile.getShooter() instanceof Player player)
shooter = (Player) projectile.getShooter(); shooter = player;
if (shooter == null) if (shooter == null)
{ {
@ -880,13 +880,20 @@ public class BlockEventHandler implements Listener
return; return;
} }
Supplier<String> allowContainer = claim.checkPermission(shooter, ClaimPermission.Inventory, event); Supplier<String> allowAction = claim.checkPermission(
shooter,
switch (block.getType())
{
case CHORUS_FLOWER -> ClaimPermission.Inventory;
case TARGET -> ClaimPermission.Access;
default -> ClaimPermission.Build;
},
event);
if (allowContainer != null) if (allowAction != null)
{ {
event.setCancelled(true); event.setCancelled(true);
GriefPrevention.sendMessage(shooter, TextMode.Err, allowContainer.get()); GriefPrevention.sendMessage(shooter, TextMode.Err, allowAction.get());
return;
} }
} }

View File

@ -630,6 +630,10 @@ public abstract class DataStore
return playerData; return playerData;
} }
synchronized public PlayerData getPlayerDataIfExists(UUID playerID) {
return this.playerNameToPlayerDataMap.get(playerID);
}
abstract PlayerData getPlayerDataFromStorage(UUID playerID); abstract PlayerData getPlayerDataFromStorage(UUID playerID);
//deletes a claim or subdivision //deletes a claim or subdivision

View File

@ -2046,13 +2046,14 @@ public class GriefPrevention extends JavaPlugin
if (args.length > 1) return false; if (args.length > 1) return false;
//player whose claims will be listed //player whose claims will be listed
OfflinePlayer otherPlayer; // OfflinePlayer otherPlayer;
UUID uuid;
//if another player isn't specified, assume current player //if another player isn't specified, assume current player
if (args.length < 1) if (args.length < 1)
{ {
if (player != null) if (player != null)
otherPlayer = player; uuid = player.getUniqueId();
else else
return false; return false;
} }
@ -2067,21 +2068,31 @@ public class GriefPrevention extends JavaPlugin
//otherwise try to find the specified player //otherwise try to find the specified player
else else
{ {
otherPlayer = this.resolvePlayerByName(args[0]); OfflinePlayer otherPlayer = this.resolvePlayerByName(args[0]);
if (otherPlayer == null) if (otherPlayer == null)
{ {
GriefPrevention.sendMessage(player, TextMode.Err, Messages.PlayerNotFound2); try {
return true; uuid = UUID.fromString(args[0]);
} catch (IllegalArgumentException ignored) {
GriefPrevention.sendMessage(player, TextMode.Err, Messages.PlayerNotFound2);
return true;
}
} else {
uuid = otherPlayer.getUniqueId();
} }
} }
//load the target player's data //load the target player's data
PlayerData playerData = this.dataStore.getPlayerData(otherPlayer.getUniqueId()); PlayerData playerData = this.dataStore.getPlayerDataIfExists(uuid);
if (playerData == null) {
GriefPrevention.sendMessage(player, TextMode.Err, Messages.PlayerNotFound2);
return true;
}
Vector<Claim> claims = playerData.getClaims(); Vector<Claim> claims = playerData.getClaims();
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.StartBlockMath, GriefPrevention.sendMessage(player, TextMode.Instr, Messages.StartBlockMath,
String.valueOf(playerData.getAccruedClaimBlocks()), String.valueOf(playerData.getAccruedClaimBlocks()),
String.valueOf((playerData.getBonusClaimBlocks() + this.dataStore.getGroupBonusBlocks(otherPlayer.getUniqueId()))), String.valueOf((playerData.getBonusClaimBlocks() + this.dataStore.getGroupBonusBlocks(uuid))),
String.valueOf((playerData.getAccruedClaimBlocks() + playerData.getBonusClaimBlocks() + this.dataStore.getGroupBonusBlocks(otherPlayer.getUniqueId())))); String.valueOf((playerData.getAccruedClaimBlocks() + playerData.getBonusClaimBlocks() + this.dataStore.getGroupBonusBlocks(uuid))));
if (claims.size() > 0) if (claims.size() > 0)
{ {
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.ClaimsListHeader); GriefPrevention.sendMessage(player, TextMode.Instr, Messages.ClaimsListHeader);
@ -2095,8 +2106,8 @@ public class GriefPrevention extends JavaPlugin
} }
//drop the data we just loaded, if the player isn't online //drop the data we just loaded, if the player isn't online
if (!otherPlayer.isOnline()) if (!Bukkit.getOfflinePlayer(uuid).isOnline())
this.dataStore.clearCachedPlayerData(otherPlayer.getUniqueId()); this.dataStore.clearCachedPlayerData(uuid);
return true; return true;
} }

View File

@ -48,6 +48,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Fish; import org.bukkit.entity.Fish;
import org.bukkit.entity.Hanging; import org.bukkit.entity.Hanging;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Llama; import org.bukkit.entity.Llama;
import org.bukkit.entity.Mule; import org.bukkit.entity.Mule;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -623,7 +624,7 @@ class PlayerEventHandler implements Listener
} }
//don't allow interaction with item frames or armor stands in claimed areas without build permission //don't allow interaction with item frames or armor stands in claimed areas without build permission
if (entity.getType() == EntityType.ARMOR_STAND || entity instanceof Hanging) if (entity.getType() == EntityType.ARMOR_STAND || entity instanceof Hanging && !(entity instanceof ItemFrame))
{ {
String noBuildReason = instance.allowBuild(player, entity.getLocation(), Material.ITEM_FRAME); String noBuildReason = instance.allowBuild(player, entity.getLocation(), Material.ITEM_FRAME);
if (noBuildReason != null) if (noBuildReason != null)
@ -634,6 +635,17 @@ class PlayerEventHandler implements Listener
} }
} }
//don't allow interaction with item frames in claimed areas without container permission
if ((entity instanceof ItemFrame) && !player.getInventory().getItem(event.getHand()).getType().equals(Material.DIAMOND)) {
Claim claim = this.dataStore.getClaimAt(entity.getLocation(), false, playerData.lastClaim);
Supplier<String> stringSupplier = claim.checkPermission(player, ClaimPermission.Access, event);
if (stringSupplier != null) {
instance.sendMessage(player, TextMode.Err, stringSupplier.get());
event.setCancelled(true);
return;
}
}
//always allow interactions when player is in ignore claims mode //always allow interactions when player is in ignore claims mode
if (playerData.ignoreClaims) return; if (playerData.ignoreClaims) return;