mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-11-20 09:25:11 +01:00
Check player distance on clickable hologram lines
This commit is contained in:
parent
7a6ea7b789
commit
32be6b8654
@ -7,6 +7,7 @@ package me.filoghost.holographicdisplays.plugin.hologram.base;
|
|||||||
|
|
||||||
import me.filoghost.fcommons.logging.Log;
|
import me.filoghost.fcommons.logging.Log;
|
||||||
import me.filoghost.holographicdisplays.api.hologram.ClickListener;
|
import me.filoghost.holographicdisplays.api.hologram.ClickListener;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.MustBeInvokedByOverriders;
|
import org.jetbrains.annotations.MustBeInvokedByOverriders;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@ -25,7 +26,7 @@ public abstract class BaseClickableLine extends BaseHologramLine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onClick(Player player) {
|
public void onClick(Player player) {
|
||||||
if (clickListener == null || !canInteract(player)) {
|
if (clickListener == null || !canInteract(player) || !isInClickRange(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,6 +46,17 @@ public abstract class BaseClickableLine extends BaseHologramLine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isInClickRange(Player player) {
|
||||||
|
Location playerLocation = player.getLocation();
|
||||||
|
|
||||||
|
double xDiff = playerLocation.getX() - this.getX();
|
||||||
|
double yDiff = playerLocation.getY() + 1.3 - this.getY(); // Use shoulder height
|
||||||
|
double zDiff = playerLocation.getZ() - this.getZ();
|
||||||
|
|
||||||
|
double distanceSquared = (xDiff * xDiff) + (yDiff * yDiff) + (zDiff * zDiff);
|
||||||
|
return distanceSquared < 5 * 5;
|
||||||
|
}
|
||||||
|
|
||||||
public @Nullable ClickListener getClickListener() {
|
public @Nullable ClickListener getClickListener() {
|
||||||
return clickListener;
|
return clickListener;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user