TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vanish.java

112 lines
4.4 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.command;
2020-08-15 22:44:50 +00:00
import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.rank.Displayable;
import me.totalfreedom.totalfreedommod.rank.Rank;
2020-08-15 22:44:50 +00:00
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
2020-08-15 22:44:50 +00:00
import org.bukkit.scheduler.BukkitRunnable;
@CommandPermissions(level = Rank.NEW_ADMIN, source = SourceType.ONLY_IN_GAME)
2020-08-15 22:44:50 +00:00
@CommandParameters(description = "Vanish/unvanish yourself.", usage = "/<command> [-s[ilent]]", aliases = "v")
public class Command_vanish extends FreedomCommand
{
2020-08-15 22:44:50 +00:00
public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole)
{
2020-08-15 22:44:50 +00:00
Displayable display = plugin.rm.getDisplay(playerSender);
String displayName = display.getColor() + playerSender.getName();
String tag = display.getColoredTag();
boolean silent = false;
if (args.length > 0)
{
2020-08-15 22:44:50 +00:00
if (args[0].equalsIgnoreCase("-s") || args[0].equalsIgnoreCase("-silent"))
{
2020-08-15 22:44:50 +00:00
silent = true;
}
}
2020-08-15 22:44:50 +00:00
2020-08-15 22:58:48 +00:00
if (plugin.sl.isVanished(playerSender.getName()))
{
2020-08-15 22:44:50 +00:00
if (silent)
{
2020-08-15 22:44:50 +00:00
msg(ChatColor.GOLD + "Silently unvanished.");
}
else
{
2020-08-15 22:44:50 +00:00
msg("You have unvanished.", ChatColor.GOLD);
FUtil.bcastMsg(plugin.rm.craftLoginMessage(playerSender, null));
FUtil.bcastMsg(playerSender.getName() + " joined the game.", ChatColor.YELLOW);
plugin.dc.messageChatChannel("**" + playerSender.getName() + " joined the server" + "**");
}
PlayerData playerData = plugin.pl.getData(playerSender);
if (playerData.getTag() != null)
{
tag = FUtil.colorize(playerData.getTag());
}
plugin.pl.getData(playerSender).setTag(tag);
FLog.info(playerSender.getName() + " is no longer vanished.");
2020-08-19 02:56:32 +00:00
plugin.sl.messageAllStaff(ChatColor.YELLOW + sender.getName() + " has unvanished and is now visible to everyone.");
2020-08-15 22:44:50 +00:00
for (Player player : server.getOnlinePlayers())
{
2020-08-19 02:56:32 +00:00
if (!plugin.sl.isStaff(player))
2020-08-15 22:44:50 +00:00
{
player.showPlayer(plugin, playerSender);
}
}
2020-08-15 22:44:50 +00:00
plugin.esb.setVanished(playerSender.getName(), false);
playerSender.setPlayerListName(StringUtils.substring(displayName, 0, 16));
2020-08-15 22:58:48 +00:00
plugin.sl.vanished.remove(playerSender.getName());
}
else
{
2020-08-15 22:44:50 +00:00
new BukkitRunnable()
{
@Override
public void run()
{
2020-08-15 22:58:48 +00:00
if (plugin.sl.isVanished(playerSender.getName()))
2020-08-15 22:44:50 +00:00
{
playerSender.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(ChatColor.GOLD + "You are hidden from other players."));
}
}
}.runTaskTimer(plugin, 0L, 4L);
if (silent)
{
msg("Silently vanished.", ChatColor.GOLD);
}
else
{
msg ("You have vanished.", ChatColor.GOLD);
FUtil.bcastMsg(playerSender.getName() + " left the game.", ChatColor.YELLOW);
plugin.dc.messageChatChannel("**" + playerSender.getName() + " left the server" + "**");
}
FLog.info(playerSender.getName() + " is now vanished.");
2020-08-19 02:56:32 +00:00
plugin.sl.messageAllStaff(ChatColor.YELLOW + sender.getName() + " has vanished and is now only visible to staff members.");
2020-08-15 22:44:50 +00:00
for (Player player : server.getOnlinePlayers())
{
2020-08-19 02:56:32 +00:00
if (!plugin.sl.isStaff(player))
2020-08-15 22:44:50 +00:00
{
2020-08-19 02:56:32 +00:00
player.hidePlayer(plugin, playerSender);
2020-08-15 22:44:50 +00:00
}
}
plugin.esb.setVanished(playerSender.getName(), true);
plugin.sl.vanished.add(playerSender.getName());
}
return true;
}
}