From 140c25006d8c49c421b20691b6da7a47c5c11a72 Mon Sep 17 00:00:00 2001 From: YouHaveTrouble Date: Sun, 23 Nov 2025 18:47:43 +0100 Subject: [PATCH] add range check --- .../me/youhavetrouble/standin/entity/EntityHandler.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/me/youhavetrouble/standin/entity/EntityHandler.java b/src/main/java/me/youhavetrouble/standin/entity/EntityHandler.java index a09e7fc..bd2a2e1 100644 --- a/src/main/java/me/youhavetrouble/standin/entity/EntityHandler.java +++ b/src/main/java/me/youhavetrouble/standin/entity/EntityHandler.java @@ -12,6 +12,8 @@ import me.youhavetrouble.standin.converter.EntityConverter; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.ClickCallback; import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.attribute.Attribute; +import org.bukkit.attribute.AttributeInstance; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -140,6 +142,12 @@ public abstract class EntityHandler { * @return Boolean representing the allowance state of the action */ public boolean canUseAction(@NotNull Player player, E entity, EntityAction action) { + AttributeInstance rangeInstance = player.getAttribute(Attribute.ENTITY_INTERACTION_RANGE); + if (rangeInstance == null) return false; + double range = rangeInstance.getValue() + 0.5; + if (player.getWorld() != entity.getWorld() || player.getLocation().distanceSquared(entity.getLocation()) > range * range) { + return false; + } String entityTypeName = entity.getType().toString().toLowerCase(Locale.ENGLISH); return switch (action) { case EDIT -> player.hasPermission("standin.edit." + entityTypeName);