2016-06-18 17:16:32 +02:00
|
|
|
package me.libraryaddict.disguise.commands;
|
|
|
|
|
2018-08-24 00:01:01 +02:00
|
|
|
import me.libraryaddict.disguise.DisguiseConfig;
|
2018-12-16 02:47:42 +01:00
|
|
|
import me.libraryaddict.disguise.LibsDisguises;
|
2020-01-19 20:33:19 +01:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
2020-01-17 04:55:05 +01:00
|
|
|
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
2017-06-08 17:09:28 +02:00
|
|
|
import me.libraryaddict.disguise.utilities.LibsPremium;
|
2020-01-19 20:33:19 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
|
|
|
|
import me.libraryaddict.disguise.utilities.parser.DisguisePermissions;
|
2020-01-17 04:55:05 +01:00
|
|
|
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
|
|
|
import net.md_5.bungee.api.chat.ClickEvent;
|
|
|
|
import net.md_5.bungee.api.chat.ComponentBuilder;
|
|
|
|
import net.md_5.bungee.api.chat.HoverEvent;
|
2020-01-19 20:33:19 +01:00
|
|
|
import org.bukkit.Bukkit;
|
2016-06-18 17:16:32 +02:00
|
|
|
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;
|
2020-01-19 20:33:19 +01:00
|
|
|
import org.bukkit.permissions.Permissible;
|
2016-06-18 17:16:32 +02:00
|
|
|
|
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 LibsDisguisesCommand 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 19:06:35 +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 (args.length == 0) {
|
2018-12-16 02:47:42 +01:00
|
|
|
LibsDisguises disguises = LibsDisguises.getInstance();
|
|
|
|
|
|
|
|
String version = disguises.getDescription().getVersion();
|
|
|
|
|
|
|
|
if (!disguises.isReleaseBuild()) {
|
2018-12-16 05:19:59 +01:00
|
|
|
version += "-";
|
|
|
|
|
|
|
|
if (disguises.isNumberedBuild()) {
|
|
|
|
version += "b";
|
|
|
|
}
|
|
|
|
|
|
|
|
version += disguises.getBuildNo();
|
2018-12-16 02:47:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sender.sendMessage(ChatColor.DARK_GREEN + "This server is running " + "Lib's Disguises v" + version +
|
|
|
|
" by libraryaddict, formerly maintained by Byteflux and NavidK0." +
|
2018-08-24 00:01:01 +02:00
|
|
|
(sender.hasPermission("libsdisguises.reload") ?
|
|
|
|
"\nUse " + ChatColor.GREEN + "/libsdisguises " + "reload" + ChatColor.DARK_GREEN +
|
|
|
|
" to reload the config. All disguises will be blown by doing this" + "." : ""));
|
2016-11-28 22:44:41 +01:00
|
|
|
|
2017-06-08 17:09:28 +02:00
|
|
|
if (LibsPremium.isPremium()) {
|
2016-11-28 22:44:41 +01:00
|
|
|
sender.sendMessage(ChatColor.DARK_GREEN + "This server supports the plugin developer!");
|
|
|
|
}
|
2017-06-19 11:23:02 +02:00
|
|
|
} else if (args.length > 0) {
|
2020-01-17 04:55:05 +01:00
|
|
|
if (args[0].equalsIgnoreCase("reload")) {
|
|
|
|
if (!sender.hasPermission("libsdisguises.reload")) {
|
|
|
|
sender.sendMessage(LibsMsg.NO_PERM.get());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
DisguiseConfig.loadConfig();
|
|
|
|
sender.sendMessage(LibsMsg.RELOADED_CONFIG.get());
|
|
|
|
return true;
|
2020-01-19 20:33:19 +01:00
|
|
|
} else if (args[0].equalsIgnoreCase("permtest")) {
|
|
|
|
if (!sender.hasPermission("libsdisguises.permtest")) {
|
|
|
|
sender.sendMessage(LibsMsg.NO_PERM.get());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Permissible player;
|
|
|
|
|
|
|
|
if (args.length > 1) {
|
|
|
|
player = Bukkit.getPlayer(args[1]);
|
|
|
|
|
|
|
|
if (player == null) {
|
|
|
|
sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[1]));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
player = sender;
|
|
|
|
}
|
|
|
|
|
|
|
|
DisguisePermissions permissions = new DisguisePermissions(player, "disguise");
|
|
|
|
sender.sendMessage(LibsMsg.LIBS_PERM_CHECK_INFO_1.get());
|
|
|
|
sender.sendMessage(LibsMsg.LIBS_PERM_CHECK_INFO_2.get());
|
|
|
|
|
|
|
|
if (player.hasPermission("libsdisguises.disguise.pig")) {
|
|
|
|
sender.sendMessage(LibsMsg.NORMAL_PERM_CHECK_SUCCESS.get());
|
|
|
|
|
|
|
|
if (permissions.isAllowedDisguise(new DisguisePerm(DisguiseType.PIG))) {
|
|
|
|
sender.sendMessage(LibsMsg.LIBS_PERM_CHECK_SUCCESS.get());
|
|
|
|
} else {
|
|
|
|
sender.sendMessage(LibsMsg.LIBS_PERM_CHECK_FAIL.get());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sender.sendMessage(LibsMsg.NORMAL_PERM_CHECK_FAIL.get());
|
|
|
|
}
|
2020-01-17 04:55:05 +01:00
|
|
|
} else if (args[0].equalsIgnoreCase("metainfo") || args[0].equalsIgnoreCase("meta")) {
|
|
|
|
if (!sender.hasPermission("libsdisguises.metainfo")) {
|
|
|
|
sender.sendMessage(LibsMsg.NO_PERM.get());
|
2016-06-18 17:16:32 +02:00
|
|
|
return true;
|
2020-01-17 04:55:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (args.length > 1) {
|
|
|
|
MetaIndex index = MetaIndex.getMetaIndexByName(args[1]);
|
|
|
|
|
|
|
|
if (index == null) {
|
|
|
|
sender.sendMessage(LibsMsg.META_NOT_FOUND.get());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
sender.sendMessage(index.toString());
|
2017-06-19 11:23:02 +02:00
|
|
|
} else {
|
2020-01-17 04:55:05 +01:00
|
|
|
ArrayList<String> names = new ArrayList<>();
|
|
|
|
|
|
|
|
for (MetaIndex index : MetaIndex.values()) {
|
|
|
|
names.add(MetaIndex.getName(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
names.sort(String::compareToIgnoreCase);
|
|
|
|
|
|
|
|
ComponentBuilder builder = new ComponentBuilder("").appendLegacy(LibsMsg.META_VALUES.get());
|
|
|
|
|
|
|
|
Iterator<String> itel = names.iterator();
|
|
|
|
|
|
|
|
while (itel.hasNext()) {
|
|
|
|
String name = itel.next();
|
|
|
|
|
|
|
|
builder.appendLegacy(name);
|
|
|
|
builder.event(
|
|
|
|
new ClickEvent(ClickEvent.Action.RUN_COMMAND, cmd.getName() + " metainfo " + name));
|
|
|
|
builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
|
|
|
new ComponentBuilder("").appendLegacy(LibsMsg.META_CLICK_SHOW.get(name)).create()));
|
|
|
|
|
|
|
|
if (itel.hasNext()) {
|
|
|
|
builder.appendLegacy(LibsMsg.META_VALUE_SEPERATOR.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sender.spigot().sendMessage(builder.create());
|
2016-06-18 17:16:32 +02:00
|
|
|
}
|
2017-06-19 11:23:02 +02:00
|
|
|
} else {
|
2020-01-17 04:55:05 +01:00
|
|
|
sender.sendMessage(LibsMsg.LIBS_COMMAND_WRONG_ARG.get());
|
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)
|
|
|
|
tabs.add("Reload");
|
|
|
|
|
|
|
|
return filterTabs(tabs, origArgs);
|
|
|
|
}
|
2016-06-18 17:16:32 +02:00
|
|
|
}
|