2016-06-18 17:16:32 +02:00
|
|
|
package me.libraryaddict.disguise.commands;
|
|
|
|
|
2017-06-19 11:23:02 +02:00
|
|
|
import me.libraryaddict.disguise.DisguiseAPI;
|
|
|
|
import me.libraryaddict.disguise.utilities.TranslateType;
|
2016-06-18 17:16:32 +02:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
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;
|
2016-06-18 17:16:32 +02:00
|
|
|
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-06-18 17:16:32 +02:00
|
|
|
|
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]);
|
|
|
|
}
|
2016-06-18 17:16:32 +02:00
|
|
|
|
|
|
|
@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) {
|
2016-06-18 17:16:32 +02:00
|
|
|
Player p = Bukkit.getPlayer(args[0]);
|
2016-11-28 15:01:06 +01:00
|
|
|
if (p != null) {
|
|
|
|
if (DisguiseAPI.isDisguised(p)) {
|
2016-06-18 17:16:32 +02:00
|
|
|
DisguiseAPI.undisguiseToAll(p);
|
2017-06-19 11:23:02 +02:00
|
|
|
sender.sendMessage(
|
|
|
|
TranslateType.MESSAGE.get(ChatColor.RED + "The player is no longer disguised"));
|
|
|
|
} else {
|
|
|
|
sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "The player is not disguised!"));
|
2016-06-18 17:16:32 +02:00
|
|
|
}
|
2017-06-19 11:23:02 +02:00
|
|
|
} else {
|
|
|
|
sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "Player not found"));
|
2016-06-18 17:16:32 +02:00
|
|
|
}
|
2017-06-19 11:23:02 +02:00
|
|
|
} else {
|
|
|
|
sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "/undisguiseplayer <Name>"));
|
2016-06-18 17:16:32 +02:00
|
|
|
}
|
2017-06-19 11:23:02 +02:00
|
|
|
} else {
|
|
|
|
sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command."));
|
2016-06-18 17:16:32 +02:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
2016-06-18 17:16:32 +02:00
|
|
|
}
|