199 lines
7.9 KiB
Java
199 lines
7.9 KiB
Java
package net.t2code.t2codelib.SPIGOT.system.cmd;
|
|
|
|
import net.t2code.t2codelib.SPIGOT.api.debug.T2Cdebug;
|
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
|
import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion;
|
|
import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI;
|
|
import net.t2code.t2codelib.SPIGOT.api.bungeePlayers.T2CbungeePlayers;
|
|
import net.t2code.t2codelib.SPIGOT.system.T2CbungeeCommandSenderReciver;
|
|
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
|
|
import net.t2code.t2codelib.T2CupdateObject;
|
|
import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig;
|
|
import net.t2code.t2codelib.Util;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandExecutor;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.command.TabCompleter;
|
|
import org.bukkit.entity.Player;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
public class CmdExecuter implements CommandExecutor, TabCompleter {
|
|
|
|
@Override
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
if (args.length == 0) {
|
|
if (!sender.hasPermission("t2code.admin")) {
|
|
T2Csend.sender(sender, "§4No Permission §8t2code.admin");
|
|
return false;
|
|
}
|
|
Commands.info(sender);
|
|
return false;
|
|
}
|
|
switch (args[0].toLowerCase()) {
|
|
case "info":
|
|
case "plugin":
|
|
case "pl":
|
|
case "version":
|
|
case "ver":
|
|
if (!sender.hasPermission("t2code.admin")) {
|
|
T2Csend.sender(sender, "§4No Permission §8t2code.admin");
|
|
return false;
|
|
}
|
|
Commands.info(sender);
|
|
return false;
|
|
case "updateinfo":
|
|
if (!sender.hasPermission("t2code.admin")) {
|
|
T2Csend.sender(sender, "§4No Permission §8t2code.admin");
|
|
return false;
|
|
}
|
|
Commands.updateInfo(sender, args);
|
|
return false;
|
|
case "reloadconfig":
|
|
if (!sender.hasPermission("t2code.admin")) {
|
|
T2Csend.sender(sender, "§4No Permission §8t2code.admin");
|
|
return false;
|
|
}
|
|
SelectLibConfig.onSelect();
|
|
T2Csend.sender(sender, Util.getPrefix() + " §2Config successfully reloaded");
|
|
return false;
|
|
case "debug":
|
|
if (!sender.hasPermission("t2code.admin")) {
|
|
T2Csend.sender(sender, "§4No Permission §8t2code.admin");
|
|
return false;
|
|
}
|
|
Commands.debug(sender, args);
|
|
return false;
|
|
case "test":
|
|
if (!sender.hasPermission("t2code.admin")) {
|
|
T2Csend.sender(sender, "§4No Permission §8t2code.admin");
|
|
return false;
|
|
}
|
|
Commands.test(sender, args);
|
|
return false;
|
|
case "serverid":if (!sender.hasPermission("t2code.admin")) {
|
|
T2Csend.sender(sender, "§4No Permission §8t2code.admin");
|
|
return false;
|
|
}
|
|
T2Csend.sender(sender, ("[prefix] <red>T2C ServerID:</red> <gold><hover:show_text:'<yellow>copy</yellow>'>" +
|
|
"<click:copy_to_clipboard:[id]>[id]</click></hover></gold>").replace("[prefix]", Util.getPrefix()).replace("[id]", String.valueOf(Util.getServerUUID())));
|
|
return false;
|
|
case "bcmd":
|
|
if (!sender.hasPermission("t2code.admin")) {
|
|
T2Csend.sender(sender, "§4No Permission §8t2code.admin");
|
|
return false;
|
|
}
|
|
String cmd = "";
|
|
for (String s : args) {
|
|
cmd = cmd + s + " ";
|
|
}
|
|
cmd = cmd.replace("bcmd ", "");
|
|
T2CbungeeCommandSenderReciver.sendToBungee(null, cmd, true);
|
|
T2Cdebug.debug(T2CodeLibMain.getPlugin(), "PluginMessage BCMD: " + cmd);
|
|
return false;
|
|
|
|
default:
|
|
if (!sender.hasPermission("t2code.admin")) {
|
|
T2Csend.sender(sender, "§4No Permission §8t2code.admin");
|
|
return false;
|
|
}
|
|
T2Csend.sender(sender, "§4Use: §7/t2code debug createReportLog");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
//TabCompleter
|
|
private static HashMap<String, String> arg1 = new HashMap<String, String>() {{
|
|
put("debug", "t2code.admin");
|
|
put("info", "t2code.admin");
|
|
put("serverid", "t2code.admin");
|
|
put("bcmd", "t2code.admin");
|
|
put("reloadconfig", "t2code.admin");
|
|
put("updateinfo", "t2code.admin");
|
|
}};
|
|
|
|
@Override
|
|
public List<String> onTabComplete(CommandSender sender, Command cmd, String s, String[] args) {
|
|
List<String> list = new ArrayList<>();
|
|
if (sender instanceof Player) {
|
|
Player p = (Player) sender;
|
|
if (args.length == 1) {
|
|
for (String command : arg1.keySet()) {
|
|
if (hasPermission(p, arg1.get(command)) && passend(command, args[0])) {
|
|
list.add(command);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (args.length == 2 && args[0].equalsIgnoreCase("debug")) {
|
|
if (sender.hasPermission("t2code.admin")) {
|
|
if (hasPermission(p, arg1.get("debug"))) {
|
|
if (passend("createReportLog", args[1])) list.add("createReportLog");
|
|
if (passend("deleteReportLog", args[1])) list.add("deleteReportLog");
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
if (args.length == 2 && args[0].equalsIgnoreCase("bcmd")) {
|
|
if (sender.hasPermission("t2code.admin")) {
|
|
list.add("<command>");
|
|
}
|
|
return list;
|
|
}
|
|
if (args.length == 2 && args[0].equalsIgnoreCase("updateinfo")) {
|
|
if (sender.hasPermission("t2code.admin")) {
|
|
if (hasPermission(p, arg1.get("updateinfo"))) {
|
|
for (Map.Entry<String, T2CupdateObject> pl : T2CupdateAPI.pluginVersions.entrySet()) {
|
|
if (passend(pl.getValue().pluginName, args[1])) list.add(pl.getValue().pluginName);
|
|
}
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
|
|
|
|
if (args.length == 3 && args[0].equalsIgnoreCase("debug") && args[1].equalsIgnoreCase("deleteReportLog")) {
|
|
if (sender.hasPermission("t2code.admin")) {
|
|
if (hasPermission(p, arg1.get("debug"))) {
|
|
for (String st : ReportLogStorage.list) {
|
|
if (passend(st, args[2])) list.add(st);
|
|
}
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
|
|
}
|
|
return list;
|
|
}
|
|
|
|
private static Boolean passend(String command, String arg) {
|
|
for (int i = 0; i < arg.toUpperCase().length(); i++) {
|
|
if (arg.toUpperCase().length() >= command.toUpperCase().length()) {
|
|
return false;
|
|
} else {
|
|
if (arg.toUpperCase().charAt(i) != command.toUpperCase().charAt(i)) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public static boolean hasPermission(Player player, String permission) {
|
|
if (player.isOp()) {
|
|
return true;
|
|
}
|
|
String[] Permissions = permission.split(";");
|
|
for (String perm : Permissions) {
|
|
if (player.hasPermission(perm)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|