1
mirror of https://github.com/Shiewk/SModeration.git synced 2026-04-28 05:54:16 +02:00

Save vanish state for next join

This commit is contained in:
Shy
2025-05-02 17:55:10 +02:00
parent d863622168
commit 66c113bad2
2 changed files with 77 additions and 8 deletions
@@ -14,6 +14,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectListIterator;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -27,6 +28,8 @@ import static net.kyori.adventure.text.Component.text;
public final class VanishCommand implements CommandProvider {
public static final NamespacedKey KEY_VANISHED = new NamespacedKey("smoderation", "vanished");
@Override
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
return literal("vanish")
@@ -118,6 +121,28 @@ public final class VanishCommand implements CommandProvider {
}
}
public static boolean toggleVanishSilent(Player player, boolean force){
final boolean newStatus = !isVanished(player);
VanishToggleEvent event = new VanishToggleEvent(player, newStatus);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled() && !force){
return false;
}
if (newStatus){
vanishedPlayers.add(player);
player.setVisibleByDefault(false);
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
if (onlinePlayer.hasPermission("smod.vanish.see")){
onlinePlayer.showEntity(PLUGIN, player);
}
}
} else {
vanishedPlayers.remove(player);
player.setVisibleByDefault(true);
}
return true;
}
public static boolean isVanished(Player player){
return vanishedPlayers.contains(player);
}