mirror of
https://github.com/Shiewk/SModeration.git
synced 2026-04-28 05:54:16 +02:00
Move vanish-related methods to VanishCommand.java
This commit is contained in:
@@ -7,13 +7,11 @@ import de.shiewk.smoderation.event.InvSeeEvents;
|
||||
import de.shiewk.smoderation.listener.PunishmentListener;
|
||||
import de.shiewk.smoderation.listener.VanishListener;
|
||||
import de.shiewk.smoderation.storage.PunishmentContainer;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -21,6 +19,8 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static de.shiewk.smoderation.command.VanishCommand.isVanished;
|
||||
import static de.shiewk.smoderation.command.VanishCommand.toggleVanish;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static org.bukkit.Bukkit.getPluginManager;
|
||||
|
||||
@@ -86,52 +86,4 @@ public final class SModeration extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final ObjectArrayList<Player> vanishedPlayers = new ObjectArrayList<>();
|
||||
|
||||
public static void toggleVanish(Player player){
|
||||
final boolean newStatus = !isVanished(player);
|
||||
if (newStatus){
|
||||
vanishedPlayers.add(player);
|
||||
for (CommandSender sender : container.collectBroadcastTargets()) {
|
||||
sender.sendMessage(CHAT_PREFIX.append(
|
||||
player.displayName()
|
||||
.colorIfAbsent(SECONDARY_COLOR)
|
||||
).append(
|
||||
text()
|
||||
.content(" vanished.")
|
||||
.color(PRIMARY_COLOR)
|
||||
));
|
||||
}
|
||||
player.sendMessage(CHAT_PREFIX.append(text("You are now vanished.").color(PRIMARY_COLOR)));
|
||||
player.setVisibleByDefault(false);
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (onlinePlayer.hasPermission("smod.vanish.see")){
|
||||
onlinePlayer.showEntity(PLUGIN, player);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
vanishedPlayers.remove(player);
|
||||
for (CommandSender sender : container.collectBroadcastTargets()) {
|
||||
sender.sendMessage(CHAT_PREFIX.append(
|
||||
player.displayName()
|
||||
.colorIfAbsent(SECONDARY_COLOR)
|
||||
).append(
|
||||
text()
|
||||
.content(" re-appeared.")
|
||||
.color(PRIMARY_COLOR)
|
||||
));
|
||||
}
|
||||
player.sendMessage(CHAT_PREFIX.append(text("You are no longer vanished.").color(PRIMARY_COLOR)));
|
||||
player.setVisibleByDefault(true);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isVanished(Player player){
|
||||
return vanishedPlayers.contains(player);
|
||||
}
|
||||
|
||||
public static ObjectArrayList<Player> getVanishedPlayers() {
|
||||
return vanishedPlayers.clone();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package de.shiewk.smoderation.command;
|
||||
|
||||
import de.shiewk.smoderation.SModeration;
|
||||
import de.shiewk.smoderation.util.PlayerUtil;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
@@ -11,6 +13,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static de.shiewk.smoderation.SModeration.*;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
public class VanishCommand implements TabExecutor {
|
||||
|
||||
@Override
|
||||
@@ -22,7 +27,7 @@ public class VanishCommand implements TabExecutor {
|
||||
player = (Player) sender;
|
||||
}
|
||||
if (player != null){
|
||||
SModeration.toggleVanish(player);
|
||||
toggleVanish(player);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -36,4 +41,52 @@ public class VanishCommand implements TabExecutor {
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
private static final ObjectArrayList<Player> vanishedPlayers = new ObjectArrayList<>();
|
||||
|
||||
public static void toggleVanish(Player player){
|
||||
final boolean newStatus = !isVanished(player);
|
||||
if (newStatus){
|
||||
vanishedPlayers.add(player);
|
||||
for (CommandSender sender : SModeration.container.collectBroadcastTargets()) {
|
||||
sender.sendMessage(CHAT_PREFIX.append(
|
||||
player.displayName()
|
||||
.colorIfAbsent(SECONDARY_COLOR)
|
||||
).append(
|
||||
text()
|
||||
.content(" vanished.")
|
||||
.color(PRIMARY_COLOR)
|
||||
));
|
||||
}
|
||||
player.sendMessage(CHAT_PREFIX.append(text("You are now vanished.").color(PRIMARY_COLOR)));
|
||||
player.setVisibleByDefault(false);
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (onlinePlayer.hasPermission("smod.vanish.see")){
|
||||
onlinePlayer.showEntity(PLUGIN, player);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
vanishedPlayers.remove(player);
|
||||
for (CommandSender sender : container.collectBroadcastTargets()) {
|
||||
sender.sendMessage(CHAT_PREFIX.append(
|
||||
player.displayName()
|
||||
.colorIfAbsent(SECONDARY_COLOR)
|
||||
).append(
|
||||
text()
|
||||
.content(" re-appeared.")
|
||||
.color(PRIMARY_COLOR)
|
||||
));
|
||||
}
|
||||
player.sendMessage(CHAT_PREFIX.append(text("You are no longer vanished.").color(PRIMARY_COLOR)));
|
||||
player.setVisibleByDefault(true);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isVanished(Player player){
|
||||
return vanishedPlayers.contains(player);
|
||||
}
|
||||
|
||||
public static ObjectArrayList<Player> getVanishedPlayers() {
|
||||
return vanishedPlayers.clone();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.shiewk.smoderation.listener;
|
||||
|
||||
import de.shiewk.smoderation.SModeration;
|
||||
import de.shiewk.smoderation.command.VanishCommand;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -13,10 +14,10 @@ public class VanishListener implements Listener {
|
||||
|
||||
@EventHandler public void onPlayerQuit(PlayerQuitEvent event){
|
||||
final Player player = event.getPlayer();
|
||||
if (SModeration.isVanished(player)){
|
||||
SModeration.toggleVanish(player);
|
||||
if (VanishCommand.isVanished(player)){
|
||||
VanishCommand.toggleVanish(player);
|
||||
}
|
||||
for (Player vanishedPlayer : SModeration.getVanishedPlayers()) {
|
||||
for (Player vanishedPlayer : VanishCommand.getVanishedPlayers()) {
|
||||
// to clean up visibility status
|
||||
player.hideEntity(SModeration.PLUGIN, vanishedPlayer);
|
||||
}
|
||||
@@ -26,7 +27,7 @@ public class VanishListener implements Listener {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(SModeration.PLUGIN, () -> {
|
||||
final Player player = event.getPlayer();
|
||||
if (player.hasPermission("smod.vanish.see")){
|
||||
for (Player vanishedPlayer : SModeration.getVanishedPlayers()) {
|
||||
for (Player vanishedPlayer : VanishCommand.getVanishedPlayers()) {
|
||||
// to show visible vanished players
|
||||
player.showEntity(SModeration.PLUGIN, vanishedPlayer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user