141 lines
5.0 KiB
Java
141 lines
5.0 KiB
Java
package net.t2code.t2codelib.SPIGOT.system.cmd;
|
|
|
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
|
import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI;
|
|
import net.t2code.t2codelib.SPIGOT.api.bungeePlayers.T2CbungeePlayers;
|
|
import net.t2code.t2codelib.T2CupdateObject;
|
|
import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig;
|
|
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 (!sender.hasPermission("t2code.admin")) {
|
|
T2Csend.sender(sender, "§4No Permission §8t2code.admin");
|
|
return false;
|
|
}
|
|
if (args.length == 0) {
|
|
Commands.info(sender);
|
|
return false;
|
|
}
|
|
switch (args[0].toLowerCase()) {
|
|
case "info":
|
|
case "plugin":
|
|
case "pl":
|
|
case "version":
|
|
case "ver":
|
|
Commands.info(sender);
|
|
return false;
|
|
case "updateinfo":
|
|
Commands.updateInfo(sender,args);
|
|
return false;
|
|
case "reloadconfig":
|
|
SelectLibConfig.onSelect();
|
|
return false;
|
|
case "debug":
|
|
Commands.debug(sender,args);
|
|
return false;
|
|
case "test":
|
|
T2Csend.sender(sender, T2CbungeePlayers.getBungeePlayers().toString());
|
|
return false;
|
|
|
|
default:
|
|
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("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("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;
|
|
}
|
|
}
|