TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vanish.java
Paldiu 5c0f77c7c5 Removal of Lombok
Lombok implementation removal.

I have also gone through and replaced things with inline methods and variables, lambdas, and simplified loops down, removed unnecessary guard clauses, and overall cleaned up every single class. This took a long time, please do remember to follow proper naming conventions, don't include unnecessary guard clauses, follow exception rules and comment rules, and please PLEASE remember to use the DIAMOND OPERATOR rather than just inferring RAW TYPES!!!

Thank you!!
2020-12-25 14:46:43 -05:00

113 lines
4.4 KiB
Java

package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.admin.AdminList;
import me.totalfreedom.totalfreedommod.player.PlayerData;
import me.totalfreedom.totalfreedommod.rank.Displayable;
import me.totalfreedom.totalfreedommod.rank.Rank;
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;
import org.bukkit.scheduler.BukkitRunnable;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Vanish/unvanish yourself.", usage = "/<command> [-s[ilent]]", aliases = "v")
public class Command_vanish extends FreedomCommand
{
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);
String displayName = display.getColor() + playerSender.getName();
String tag = display.getColoredTag();
boolean silent = false;
if (args.length > 0)
{
if (args[0].equalsIgnoreCase("-s") || args[0].equalsIgnoreCase("-silent"))
{
silent = true;
}
}
if (plugin.al.isVanished(playerSender.getName()))
{
if (silent)
{
msg(ChatColor.GOLD + "Silently unvanished.");
}
else
{
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.");
plugin.al.messageAllAdmins(ChatColor.YELLOW + sender.getName() + " has unvanished and is now visible to everyone.");
for (Player player : server.getOnlinePlayers())
{
if (!plugin.al.isAdmin(player))
{
player.showPlayer(plugin, playerSender);
}
}
plugin.esb.setVanished(playerSender.getName(), false);
playerSender.setPlayerListName(StringUtils.substring(displayName, 0, 16));
AdminList.vanished.remove(playerSender.getName());
}
else
{
new BukkitRunnable()
{
@Override
public void run()
{
if (plugin.al.isVanished(playerSender.getName()))
{
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.");
plugin.al.messageAllAdmins(ChatColor.YELLOW + sender.getName() + " has vanished and is now only visible to admins.");
for (Player player : server.getOnlinePlayers())
{
if (!plugin.al.isAdmin(player))
{
player.hidePlayer(plugin, playerSender);
}
}
plugin.esb.setVanished(playerSender.getName(), true);
AdminList.vanished.add(playerSender.getName());
}
return true;
}
}