2016-03-02 19:28:01 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
2013-05-15 13:23:18 +00:00
|
|
|
|
2018-07-31 07:01:29 +00:00
|
|
|
import java.util.ArrayList;
|
2019-01-29 04:57:41 +00:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
2018-07-31 07:01:29 +00:00
|
|
|
import java.util.List;
|
2016-03-06 15:56:15 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
2014-11-29 19:16:00 +00:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2013-05-15 13:23:18 +00:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.potion.PotionEffectType;
|
|
|
|
|
2019-07-31 00:31:31 +00:00
|
|
|
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH)
|
2018-10-06 18:44:58 +00:00
|
|
|
@CommandParameters(description = "Shows (optionally clears) invisible players", usage = "/<command> [clear]")
|
2015-10-19 17:43:46 +00:00
|
|
|
public class Command_invis extends FreedomCommand
|
2013-07-02 18:31:22 +00:00
|
|
|
{
|
2013-05-15 13:23:18 +00:00
|
|
|
@Override
|
2015-11-22 18:26:47 +00:00
|
|
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
2013-05-15 13:23:18 +00:00
|
|
|
{
|
2016-11-13 15:46:06 +00:00
|
|
|
boolean clear = false;
|
2017-10-13 18:35:11 +00:00
|
|
|
|
2013-05-15 13:23:18 +00:00
|
|
|
if (args.length >= 1)
|
|
|
|
{
|
2016-11-13 15:46:06 +00:00
|
|
|
if (args[0].equalsIgnoreCase("clear"))
|
2013-05-15 13:23:18 +00:00
|
|
|
{
|
2018-07-28 07:11:48 +00:00
|
|
|
FUtil.adminAction(sender.getName(), "Clearing all invisibility potion effects from all players", true);
|
2016-11-13 15:46:06 +00:00
|
|
|
clear = true;
|
2013-05-15 13:23:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-13 18:35:11 +00:00
|
|
|
List<String> players = new ArrayList<String>();
|
2016-11-13 15:46:06 +00:00
|
|
|
int clears = 0;
|
2013-05-15 13:23:18 +00:00
|
|
|
|
2013-08-14 14:01:42 +00:00
|
|
|
for (Player player : server.getOnlinePlayers())
|
2013-05-15 13:23:18 +00:00
|
|
|
{
|
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());
|
2016-11-13 15:46:06 +00:00
|
|
|
if (clear && !plugin.al.isAdmin(player))
|
2013-05-15 13:23:18 +00:00
|
|
|
{
|
2017-10-13 18:35:11 +00:00
|
|
|
player.removePotionEffect((PotionEffectType.INVISIBILITY));
|
2016-11-13 15:46:06 +00:00
|
|
|
clears++;
|
2013-05-15 13:23:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-02 18:31:22 +00:00
|
|
|
if (players.isEmpty())
|
|
|
|
{
|
2018-07-28 07:11:48 +00:00
|
|
|
msg("There are no invisible players");
|
2013-05-15 13:23:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-11-13 15:46:06 +00:00
|
|
|
if (clear)
|
2013-05-15 13:23:18 +00:00
|
|
|
{
|
2018-07-28 07:11:48 +00:00
|
|
|
msg("Cleared " + clears + " players");
|
2013-05-15 13:23:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-28 07:11:48 +00:00
|
|
|
msg("Invisible players (" + players.size() + "): " + StringUtils.join(players, ", "));
|
2013-05-15 13:23:18 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2019-01-29 04:57:41 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
|
|
|
|
{
|
|
|
|
if (args.length == 1 && plugin.al.isAdmin(sender))
|
|
|
|
{
|
|
|
|
return Arrays.asList("clear");
|
|
|
|
}
|
|
|
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
2018-07-28 07:11:48 +00:00
|
|
|
}
|