2020-08-15 22:41:26 +00:00
|
|
|
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;
|
2020-08-15 22:41:26 +00:00
|
|
|
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;
|
2020-08-15 22:41:26 +00:00
|
|
|
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;
|
|
|
|
import static me.totalfreedom.totalfreedommod.util.FUtil.playerMsg;
|
2020-08-15 22:41:26 +00:00
|
|
|
|
2020-08-15 22:58:48 +00:00
|
|
|
@CommandPermissions(level = Rank.TRIAL_MOD, source = SourceType.ONLY_IN_GAME)
|
2020-08-15 22:44:50 +00:00
|
|
|
@CommandParameters(description = "Vanish/unvanish yourself.", usage = "/<command> [-s[ilent]]", aliases = "v")
|
2020-08-15 22:41:26 +00:00
|
|
|
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:41:26 +00:00
|
|
|
{
|
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:41:26 +00:00
|
|
|
{
|
2020-08-15 22:44:50 +00:00
|
|
|
if (args[0].equalsIgnoreCase("-s") || args[0].equalsIgnoreCase("-silent"))
|
2020-08-15 22:41:26 +00:00
|
|
|
{
|
2020-08-15 22:44:50 +00:00
|
|
|
silent = true;
|
2020-08-15 22:41:26 +00:00
|
|
|
}
|
|
|
|
}
|
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:41:26 +00:00
|
|
|
{
|
2020-08-15 22:44:50 +00:00
|
|
|
if (silent)
|
2020-08-15 22:41:26 +00:00
|
|
|
{
|
2020-08-15 22:44:50 +00:00
|
|
|
msg(ChatColor.GOLD + "Silently unvanished.");
|
2020-08-15 22:41:26 +00:00
|
|
|
}
|
|
|
|
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.");
|
|
|
|
|
|
|
|
for (Player player : server.getOnlinePlayers())
|
|
|
|
{
|
2020-08-15 22:58:48 +00:00
|
|
|
if (plugin.sl.isAdmin(player))
|
2020-08-15 22:44:50 +00:00
|
|
|
{
|
|
|
|
playerMsg(player, ChatColor.YELLOW + sender.getName() + " has unvanished and is now visible to everyone.");
|
|
|
|
}
|
2020-08-15 22:58:48 +00:00
|
|
|
if (!plugin.sl.isAdmin(player))
|
2020-08-15 22:44:50 +00:00
|
|
|
{
|
|
|
|
player.showPlayer(plugin, playerSender);
|
|
|
|
}
|
2020-08-15 22:41:26 +00:00
|
|
|
}
|
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());
|
2020-08-15 22:41:26 +00:00
|
|
|
}
|
|
|
|
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.");
|
|
|
|
for (Player player : server.getOnlinePlayers())
|
|
|
|
{
|
|
|
|
{
|
2020-08-15 22:58:48 +00:00
|
|
|
if (plugin.sl.isAdmin(player))
|
2020-08-15 22:44:50 +00:00
|
|
|
{
|
|
|
|
playerMsg(player, ChatColor.YELLOW + sender.getName() + " has vanished and is now only visible to admins.");
|
|
|
|
}
|
2020-08-15 22:58:48 +00:00
|
|
|
if (!plugin.sl.isAdmin(player))
|
2020-08-15 22:44:50 +00:00
|
|
|
{
|
|
|
|
player.hidePlayer(plugin, playerSender);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
plugin.esb.setVanished(playerSender.getName(), true);
|
|
|
|
plugin.sl.vanished.add(playerSender.getName());
|
2020-08-15 22:41:26 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|