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
denyConnectingDoubleChestsAcrossClaimBoundary(claim, block, player);
if (claim != null)
{
playerData.lastClaim = claim;
@ -861,7 +861,7 @@ public class BlockEventHandler implements Listener
Block block = event.getHitBlock();
// 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;
Claim claim = dataStore.getClaimAt(block.getLocation(), false, null);
@ -871,8 +871,8 @@ public class BlockEventHandler implements Listener
Player shooter = null;
Projectile projectile = event.getEntity();
if (projectile.getShooter() instanceof Player)
shooter = (Player) projectile.getShooter();
if (projectile.getShooter() instanceof Player player)
shooter = player;
if (shooter == null)
{
@ -880,13 +880,20 @@ public class BlockEventHandler implements Listener
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);
GriefPrevention.sendMessage(shooter, TextMode.Err, allowContainer.get());
return;
GriefPrevention.sendMessage(shooter, TextMode.Err, allowAction.get());
}
}

View File

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

View File

@ -2046,13 +2046,14 @@ public class GriefPrevention extends JavaPlugin
if (args.length > 1) return false;
//player whose claims will be listed
OfflinePlayer otherPlayer;
// OfflinePlayer otherPlayer;
UUID uuid;
//if another player isn't specified, assume current player
if (args.length < 1)
{
if (player != null)
otherPlayer = player;
uuid = player.getUniqueId();
else
return false;
}
@ -2067,21 +2068,31 @@ public class GriefPrevention extends JavaPlugin
//otherwise try to find the specified player
else
{
otherPlayer = this.resolvePlayerByName(args[0]);
OfflinePlayer otherPlayer = this.resolvePlayerByName(args[0]);
if (otherPlayer == null)
{
GriefPrevention.sendMessage(player, TextMode.Err, Messages.PlayerNotFound2);
return true;
try {
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
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();
GriefPrevention.sendMessage(player, TextMode.Instr, Messages.StartBlockMath,
String.valueOf(playerData.getAccruedClaimBlocks()),
String.valueOf((playerData.getBonusClaimBlocks() + this.dataStore.getGroupBonusBlocks(otherPlayer.getUniqueId()))),
String.valueOf((playerData.getAccruedClaimBlocks() + playerData.getBonusClaimBlocks() + this.dataStore.getGroupBonusBlocks(otherPlayer.getUniqueId()))));
String.valueOf((playerData.getBonusClaimBlocks() + this.dataStore.getGroupBonusBlocks(uuid))),
String.valueOf((playerData.getAccruedClaimBlocks() + playerData.getBonusClaimBlocks() + this.dataStore.getGroupBonusBlocks(uuid))));
if (claims.size() > 0)
{
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
if (!otherPlayer.isOnline())
this.dataStore.clearCachedPlayerData(otherPlayer.getUniqueId());
if (!Bukkit.getOfflinePlayer(uuid).isOnline())
this.dataStore.clearCachedPlayerData(uuid);
return true;
}

View File

@ -48,6 +48,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Fish;
import org.bukkit.entity.Hanging;
import org.bukkit.entity.Item;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Llama;
import org.bukkit.entity.Mule;
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
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);
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
if (playerData.ignoreClaims) return;