LibsDisguises/src/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java

90 lines
2.8 KiB
Java
Raw Normal View History

package me.libraryaddict.disguise.commands;
2017-06-19 11:23:02 +02:00
import me.libraryaddict.disguise.DisguiseAPI;
2017-06-19 19:06:35 +02:00
import me.libraryaddict.disguise.utilities.LibsMsg;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
2016-11-28 15:01:06 +01:00
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
2017-06-19 11:23:02 +02:00
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
2016-11-28 15:01:06 +01:00
public class UndisguisePlayerCommand implements CommandExecutor, TabCompleter {
protected ArrayList<String> filterTabs(ArrayList<String> list, String[] origArgs) {
if (origArgs.length == 0)
return list;
Iterator<String> itel = list.iterator();
String label = origArgs[origArgs.length - 1].toLowerCase();
while (itel.hasNext()) {
String name = itel.next();
if (name.toLowerCase().startsWith(label))
continue;
itel.remove();
}
return list;
}
protected String[] getArgs(String[] args) {
2017-06-19 11:23:02 +02:00
ArrayList<String> newArgs = new ArrayList<>();
2016-11-28 15:01:06 +01:00
for (int i = 0; i < args.length - 1; i++) {
String s = args[i];
if (s.trim().isEmpty())
continue;
newArgs.add(s);
}
return newArgs.toArray(new String[0]);
}
@Override
2016-11-28 15:01:06 +01:00
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.hasPermission("libsdisguises.undisguiseplayer")) {
if (args.length > 0) {
Player p = Bukkit.getPlayer(args[0]);
2016-11-28 15:01:06 +01:00
if (p != null) {
if (DisguiseAPI.isDisguised(p)) {
DisguiseAPI.undisguiseToAll(p);
2017-06-19 19:06:35 +02:00
sender.sendMessage(LibsMsg.UNDISG_PLAYER.get(p.getName()));
2017-06-19 11:23:02 +02:00
} else {
2017-06-19 19:06:35 +02:00
sender.sendMessage(LibsMsg.UNDISG_PLAYER_FAIL.get(p.getName()));
}
2017-06-19 11:23:02 +02:00
} else {
2017-06-19 19:06:35 +02:00
sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0]));
}
2017-06-19 11:23:02 +02:00
} else {
2017-06-19 19:06:35 +02:00
sender.sendMessage(LibsMsg.UNDISG_PLAYER_HELP.get());
}
2017-06-19 11:23:02 +02:00
} else {
2017-06-19 19:06:35 +02:00
sender.sendMessage(LibsMsg.NO_PERM.get());
}
return true;
}
2016-11-28 15:01:06 +01:00
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
2017-06-19 11:23:02 +02:00
ArrayList<String> tabs = new ArrayList<>();
2016-11-28 15:01:06 +01:00
String[] args = getArgs(origArgs);
if (args.length != 0)
return filterTabs(tabs, origArgs);
for (Player player : Bukkit.getOnlinePlayers()) {
tabs.add(player.getName());
}
return filterTabs(tabs, origArgs);
}
}