add range check

This commit is contained in:
2025-11-23 18:47:43 +01:00
parent b6ebafff58
commit 140c25006d
@@ -12,6 +12,8 @@ import me.youhavetrouble.standin.converter.EntityConverter;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickCallback; import net.kyori.adventure.text.event.ClickCallback;
import net.kyori.adventure.text.format.NamedTextColor; 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.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -140,6 +142,12 @@ public abstract class EntityHandler<E extends Entity> {
* @return Boolean representing the allowance state of the action * @return Boolean representing the allowance state of the action
*/ */
public boolean canUseAction(@NotNull Player player, E entity, EntityAction 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); String entityTypeName = entity.getType().toString().toLowerCase(Locale.ENGLISH);
return switch (action) { return switch (action) {
case EDIT -> player.hasPermission("standin.edit." + entityTypeName); case EDIT -> player.hasPermission("standin.edit." + entityTypeName);