made players who ran /nopvp glow

This commit is contained in:
Martin Dvořák 2026-09-04 10:55:42 +02:00
commit 089b2a9368
2 changed files with 20 additions and 0 deletions

View file

@ -7,6 +7,8 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
public final class NoPvPListener implements Listener {
@ -16,6 +18,16 @@ public final class NoPvPListener implements Listener {
this.manager = manager;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event) {
manager.applyGlow(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerRespawn(PlayerRespawnEvent event) {
manager.applyGlow(event.getPlayer());
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (!(event.getEntity() instanceof Player victim)) {

View file

@ -39,6 +39,7 @@ public final class NoPvPManager {
UUID uuid = player.getUniqueId();
enabled.put(uuid, true);
cooldownUntil.put(uuid, 0L);
player.setGlowing(true);
scheduleSave();
}
@ -46,9 +47,16 @@ public final class NoPvPManager {
UUID uuid = player.getUniqueId();
enabled.put(uuid, false);
cooldownUntil.put(uuid, System.currentTimeMillis() + COOLDOWN_MILLIS);
player.setGlowing(false);
scheduleSave();
}
public void applyGlow(Player player) {
if (isEnabled(player)) {
player.setGlowing(true);
}
}
private void load() {
if (!dataFile.exists()) {
return;