From 0815cb0bed9441206dd65023b287c5bd4902f2f4 Mon Sep 17 00:00:00 2001 From: William Date: Sat, 18 Sep 2021 13:46:09 +0100 Subject: [PATCH] Add standing-in-own-town context Signed-off-by: William --- .../luckperms/calculators/PlayerAccessCalculator.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bukkit/src/main/java/me/william278/husktowns/integrations/luckperms/calculators/PlayerAccessCalculator.java b/bukkit/src/main/java/me/william278/husktowns/integrations/luckperms/calculators/PlayerAccessCalculator.java index d1e2f5d4..0017d9a9 100644 --- a/bukkit/src/main/java/me/william278/husktowns/integrations/luckperms/calculators/PlayerAccessCalculator.java +++ b/bukkit/src/main/java/me/william278/husktowns/integrations/luckperms/calculators/PlayerAccessCalculator.java @@ -19,6 +19,7 @@ public class PlayerAccessCalculator implements ContextCalculator { private static final String CAN_PLAYER_BUILD = "husktowns:can-build"; private static final String CAN_PLAYER_OPEN_CONTAINERS = "husktowns:can-open-containers"; private static final String CAN_PLAYER_INTERACT = "husktowns:can-interact"; + private static final String STANDING_IN_OWN_TOWN = "husktowns:standing-in-own-town"; @Override public void calculate(@NonNull Player target, @NonNull ContextConsumer consumer) { @@ -44,10 +45,20 @@ public void calculate(@NonNull Player target, @NonNull ContextConsumer consumer) case CANNOT_PERFORM_ACTION_ADMIN_CLAIM, CANNOT_PERFORM_ACTION_DIFFERENT_TOWN, CANNOT_PERFORM_ACTION_NOT_IN_TOWN, CANNOT_PERFORM_ACTION_RESIDENT -> consumer.accept(CAN_PLAYER_INTERACT, "false"); default -> consumer.accept(CAN_PLAYER_INTERACT, "true"); } + if (playerCache.isPlayerInTown(target.getUniqueId())) { + if (playerCache.getPlayerTown(target.getUniqueId()).equals(chunk.getTown())) { + consumer.accept(STANDING_IN_OWN_TOWN, "true"); + } else { + consumer.accept(STANDING_IN_OWN_TOWN, "false"); + } + } else { + consumer.accept(STANDING_IN_OWN_TOWN, "false"); + } } else { consumer.accept(CAN_PLAYER_BUILD, "true"); consumer.accept(CAN_PLAYER_OPEN_CONTAINERS, "true"); consumer.accept(CAN_PLAYER_INTERACT, "true"); + consumer.accept(STANDING_IN_OWN_TOWN, "false"); } } else { consumer.accept(CAN_PLAYER_BUILD, "false");