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

66 lines
2 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.command;
import java.util.ArrayList;
import java.util.List;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "Shows (optionally clears) invisible players", usage = "/<command> (clear)")
public class Command_invis extends FreedomCommand
2013-07-02 18:31:22 +00:00
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
boolean clear = false;
if (args.length >= 1)
{
if (args[0].equalsIgnoreCase("clear"))
{
FUtil.adminAction(sender.getName(), "Clearing all invisibility potion effects from all players", true);
clear = true;
}
else
{
return false;
}
}
List<String> players = new ArrayList<String>();
int clears = 0;
2013-08-14 14:01:42 +00:00
for (Player player : server.getOnlinePlayers())
{
2013-08-14 14:01:42 +00:00
if (player.hasPotionEffect(PotionEffectType.INVISIBILITY))
2013-07-02 18:31:22 +00:00
{
2013-08-14 14:01:42 +00:00
players.add(player.getName());
if (clear && !plugin.al.isAdmin(player))
{
player.removePotionEffect((PotionEffectType.INVISIBILITY));
clears++;
}
}
}
2013-07-02 18:31:22 +00:00
if (players.isEmpty())
{
msg("There are no invisible players");
return true;
}
if (clear)
{
msg("Cleared " + clears + " players");
}
else
{
msg("Invisible players (" + players.size() + "): " + StringUtils.join(players, ", "));
}
return true;
}
}