AlexDev_ committed 2025-11-04 14:44:13 +01:00
1 parent 12ede5bc1e
commit b495a87a57
4 files changed
+59 -13

No files matched your search

+4
View File
@@ -1 +1,5 @@
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.9.0"
}
rootProject.name = "UnlimitedNametags"
@@ -19,10 +19,7 @@ import org.bukkit.event.player.*;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.*;
public class PlayerListener implements PackSendHandler {
@@ -144,9 +141,9 @@ public class PlayerListener implements PackSendHandler {
public void onGameModeChange(@NotNull PlayerGameModeChangeEvent e) {
if (e.getPlayer().getGameMode() == GameMode.SPECTATOR) {
plugin.getNametagManager().unblockPlayer(e.getPlayer());
plugin.getNametagManager().showToTrackedPlayers(e.getPlayer(), plugin.getTrackerManager().getTrackedPlayers().get(e.getPlayer().getUniqueId()));
plugin.getNametagManager().showToTrackedPlayers(e.getPlayer());
} else if (e.getNewGameMode() == GameMode.SPECTATOR) {
plugin.getNametagManager().removeAllViewers(e.getPlayer());
plugin.getTaskScheduler().runTaskLaterAsynchronously(() -> plugin.getNametagManager().removeAllViewers(e.getPlayer()), 2);
}
}
@@ -159,9 +156,17 @@ public class PlayerListener implements PackSendHandler {
@EventHandler
public void onPlayerRespawn(@NotNull PlayerRespawnEvent event) {
diedPlayers.remove(event.getPlayer().getUniqueId());
if (event.getPlayer().getGameMode() == GameMode.SPECTATOR) {
return;
}
plugin.getTaskScheduler().runTaskLaterAsynchronously(() -> {
plugin.getNametagManager().showToTrackedPlayers(event.getPlayer());
}, 2);
final List<UUID> nearbyPlayers = Bukkit.getOnlinePlayers().stream()
.filter(p -> p.getWorld().equals(event.getPlayer().getWorld()) && p.getLocation().distanceSquared(event.getPlayer().getLocation()) <= 6400)
.map(Player::getUniqueId)
.toList();
plugin.getNametagManager().showToTrackedPlayers(event.getPlayer(), nearbyPlayers);
}, 4);
}
@EventHandler
@@ -400,7 +400,6 @@ public class NameTagManager {
//background color, if disabled, set to transparent
display.setBackgroundColor(nameTag.background().getColor());
// display.setTransformation(new Vector3f(0, plugin.getConfigManager().getSettings().getYOffset(), 0));
display.resetOffset(plugin.getConfigManager().getSettings().getYOffset());
display.setViewRange(plugin.getConfigManager().getSettings().getViewDistance());
@@ -528,7 +527,12 @@ public class NameTagManager {
.map(Bukkit::getPlayer)
.filter(Objects::nonNull)
.map(Player::getName)
.toList();
.collect(Collectors.toList());
if (!plugin.getConfigManager().getSettings().isShowCurrentNameTag()) {
viewers.remove(player.getName());
}
final long lastUpdate = display.getLastUpdate();
final Component text = getComponent(display, viewers, player, lastUpdate);
@@ -264,46 +264,79 @@ public class PacketNameTag {
private boolean isEligibleToShow(@NotNull Player player) {
if (!visible) {
if (plugin.getNametagManager().isDebug()) {
plugin.getLogger().info("Nametag is not visible for " + owner.getName());
}
return false;
}
if (plugin.getHook(ViaVersionHook.class).map(h -> h.hasNotTextDisplays(player)).orElse(false)) {
if (plugin.getNametagManager().isDebug()) {
plugin.getLogger().info("Player " + player.getName() + " is on a version that does not support text displays.");
}
return false;
}
if (blocked.contains(player.getUniqueId())) {
if (plugin.getNametagManager().isDebug()) {
plugin.getLogger().info("Player " + player.getName() + " is blocked from seeing nametag of " + owner.getName());
}
return false;
}
if (!player.canSee(owner)) {
if (plugin.getNametagManager().isDebug()) {
plugin.getLogger().info("Player " + player.getName() + " cannot see owner " + owner.getName());
}
return false;
}
if (player.getWorld() != owner.getWorld()) {
if (plugin.getNametagManager().isDebug()) {
plugin.getLogger().info("Player " + player.getName() + " is in a different world than owner " + owner.getName());
}
return false;
}
if (isPlayerChannelNotValid(player) || isPlayerChannelNotValid(owner)) {
if (plugin.getNametagManager().isDebug()) {
plugin.getLogger().info("Player " + player.getName() + " or owner " + owner.getName() + " has an invalid channel/user.");
}
return false;
}
if (!hasRequiredPermissions(player)) {
if (plugin.getNametagManager().isDebug()) {
plugin.getLogger().info("Player " + player.getName() + " does not have required permissions to see nametag of " + owner.getName());
}
return false;
}
if (plugin.getNametagManager().isHiddenOtherNametags(player)) {
if (plugin.getNametagManager().isDebug()) {
plugin.getLogger().info("Player " + player.getName() + " has other nametags hidden.");
}
return false;
}
if (plugin.getConfigManager().getSettings().isShowWhileLooking() &&
!plugin.getNametagManager().isPlayerPointingAt(player, owner)) {
if (plugin.getNametagManager().isDebug()) {
plugin.getLogger().info("Player " + player.getName() + " is not looking at owner " + owner.getName());
}
return false;
}
if (plugin.getConfigManager().getSettings().isShowCurrentNameTag() && player.getUniqueId() == owner.getUniqueId()) {
if (plugin.getNametagManager().isDebug()) {
plugin.getLogger().info("Player " + player.getName() + " is the owner and show current nametag is enabled.");
}
return true;
}
if (plugin.getNametagManager().isDebug() && !getViewers().contains(player.getUniqueId())) {
plugin.getLogger().info("Player " + player.getName() + " is eligible to see nametag of " + owner.getName());
}
return !getViewers().contains(player.getUniqueId());
}
@@ -384,7 +417,7 @@ public class PacketNameTag {
final Location location = owner.getLocation().clone();
location.setPitch(0);
location.setYaw(-180);
location.setY(location.getY() + (1.8) * scale );
location.setY(location.getY() + (1.8) * scale);
return location;
}
@@ -448,7 +481,7 @@ public class PacketNameTag {
public void refresh() {
perPlayerEntity.getEntities().forEach((u, e) -> {
if(blocked.contains(u)) {
if (blocked.contains(u)) {
return;
}
@@ -462,7 +495,7 @@ public class PacketNameTag {
return;
}
if(blocked.contains(player.getUniqueId())) {
if (blocked.contains(player.getUniqueId())) {
return;
}