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

93 lines
3.9 KiB
Java
Raw Normal View History

2017-11-11 17:12:30 +00:00
package me.totalfreedom.totalfreedommod.command;
import java.util.ArrayList;
2017-11-11 17:12:30 +00:00
import me.totalfreedom.totalfreedommod.admin.Admin;
import me.totalfreedom.totalfreedommod.rank.Displayable;
import me.totalfreedom.totalfreedommod.rank.Rank;
2017-11-11 17:12:30 +00:00
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang.StringUtils;
2017-11-11 17:12:30 +00:00
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import static me.totalfreedom.totalfreedommod.util.FUtil.playerMsg;
2017-11-11 17:12:30 +00:00
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Vanish/unvanish yourself.", usage = "/<command> [-s[ilent]]", aliases = "v")
2017-11-11 17:12:30 +00:00
public class Command_vanish extends FreedomCommand
{
2018-06-29 19:36:42 +00:00
public static ArrayList<Player> VANISHED = new ArrayList<>();
public boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole)
{
Displayable display = plugin.rm.getDisplay(playerSender);
2017-11-11 17:12:30 +00:00
String loginMsg = display.getColoredLoginMessage();
String displayName = display.getColor() + playerSender.getName();
String tag = display.getColoredTag();
Admin admin = plugin.al.getAdmin(playerSender);
boolean silent = false;
if (args.length > 0)
{
if (args[0].equalsIgnoreCase("-s") || args[0].equalsIgnoreCase("-silent"))
{
silent = true;
}
}
if (VANISHED.contains(playerSender))
{
msg(ChatColor.GOLD + "You have been unvanished.");
if (admin.hasLoginMessage())
{
2017-11-11 17:12:30 +00:00
loginMsg = FUtil.colorize(admin.getLoginMessage());
}
if (!silent)
{
2018-12-29 19:41:48 +00:00
FUtil.bcastMsg(ChatColor.AQUA + (loginMsg.contains("%name%") ? "" : playerSender.getName() + " is ") + FUtil.colorize(loginMsg).replace("%name%", playerSender.getName()));
FUtil.bcastMsg(playerSender.getName() + " joined the game", ChatColor.YELLOW);
}
if (admin.getTag() != null)
{
tag = FUtil.colorize(admin.getTag());
}
2018-04-19 14:29:19 +00:00
else
{
plugin.pl.getPlayer(playerSender).setTag(tag);
}
2017-11-11 17:12:30 +00:00
FLog.info(playerSender.getName() + " is no longer vanished.");
for (Player player : server.getOnlinePlayers())
{
player.showPlayer(plugin, playerSender);
2017-11-11 17:12:30 +00:00
}
plugin.esb.setVanished(playerSender.getName(), false);
2017-11-11 17:12:30 +00:00
playerSender.removePotionEffect(PotionEffectType.INVISIBILITY);
playerSender.setPlayerListName(StringUtils.substring(displayName, 0, 16));
VANISHED.remove(playerSender);
2017-11-11 17:12:30 +00:00
}
else
{
msg("You have been vanished.", ChatColor.GOLD);
if (!silent)
{
FUtil.bcastMsg(playerSender.getName() + " left the game", ChatColor.YELLOW);
}
2017-11-11 17:12:30 +00:00
FLog.info(playerSender.getName() + " is now vanished.");
for (Player player : server.getOnlinePlayers())
{
{
if (plugin.al.isAdmin(player))
playerMsg(player, ChatColor.YELLOW + sender.getName() + " has vanished and is now only visible to admins." );
if (!plugin.al.isAdmin(player))
player.hidePlayer(plugin, playerSender);
}
2017-11-11 17:12:30 +00:00
}
plugin.esb.setVanished(playerSender.getName(), true);
2018-01-07 19:33:58 +00:00
playerSender.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 1000000, 1, false, true));
VANISHED.add(playerSender);
2017-11-11 17:12:30 +00:00
}
return true;
}
}