mirror of
https://github.com/funkemunky/AntiVPN.git
synced 2026-05-31 09:31:54 +00:00
Completing 1.1 update
This commit is contained in:
@@ -16,6 +16,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class BukkitPlugin extends JavaPlugin {
|
||||
|
||||
@@ -46,8 +47,8 @@ public class BukkitPlugin extends JavaPlugin {
|
||||
}
|
||||
|
||||
for (Command command : AntiVPN.getInstance().getCommands()) {
|
||||
val newCommand = new org.bukkit.command.Command(command.name(),
|
||||
command.description(), command.usage(), Arrays.asList(command.aliases())) {
|
||||
val newCommand = new org.bukkit.command.Command(command.name(), command.description(), command.usage(),
|
||||
Arrays.asList(command.aliases())) {
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String s, String[] args) {
|
||||
if(!sender.hasPermission("antivpn.command.*")
|
||||
@@ -56,6 +57,26 @@ public class BukkitPlugin extends JavaPlugin {
|
||||
return true;
|
||||
}
|
||||
|
||||
val children = command.children();
|
||||
|
||||
if(children.length > 0 && args.length > 0) {
|
||||
for (Command child : children) {
|
||||
if(child.name().equalsIgnoreCase(args[0])) {
|
||||
if(!sender.hasPermission("antivpn.command.*")
|
||||
&& !sender.hasPermission(child.permission())) {
|
||||
sender.sendMessage(ChatColor.RED + "No permission.");
|
||||
return true;
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||
child.execute(new BukkitCommandExecutor(sender), IntStream
|
||||
.range(0, args.length - 1)
|
||||
.mapToObj(i -> args[i + 1]).toArray(String[]::new))));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&',
|
||||
command.execute(new BukkitCommandExecutor(sender), args)));
|
||||
|
||||
@@ -64,7 +85,7 @@ public class BukkitPlugin extends JavaPlugin {
|
||||
};
|
||||
|
||||
registeredCommands.add(newCommand);
|
||||
commandMap.register("antivpn", newCommand);
|
||||
commandMap.register(pluginInstance.getName(), newCommand);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,8 +96,10 @@ public class BukkitPlugin extends JavaPlugin {
|
||||
|
||||
System.out.println("Unregistering commands...");
|
||||
try {
|
||||
Map<String, org.bukkit.command.Command> knownCommands = (Map<String, org.bukkit.command.Command>)
|
||||
SimpleCommandMap.class.getField("knownCommands").get(commandMap);
|
||||
Field field = SimpleCommandMap.class.getDeclaredField("knownCommands");
|
||||
field.setAccessible(true);
|
||||
Map<String, org.bukkit.command.Command> knownCommands =
|
||||
(Map<String, org.bukkit.command.Command>) field.get(commandMap);
|
||||
|
||||
knownCommands.values().removeAll(registeredCommands);
|
||||
registeredCommands.clear();
|
||||
|
||||
@@ -2,13 +2,7 @@ package dev.brighten.antivpn.bungee;
|
||||
|
||||
import dev.brighten.antivpn.AntiVPN;
|
||||
import dev.brighten.antivpn.bungee.util.Config;
|
||||
import dev.brighten.antivpn.command.Command;
|
||||
import lombok.Getter;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
public class BungeePlugin extends Plugin {
|
||||
@@ -28,7 +22,8 @@ public class BungeePlugin extends Plugin {
|
||||
//Loading plugin
|
||||
AntiVPN.start(new BungeeConfig(), new BungeeListener(), new BungeePlayerExecutor());
|
||||
|
||||
for (Command command : AntiVPN.getInstance().getCommands()) {
|
||||
//TODO Add command functionality for BungeeCord
|
||||
/*for (Command command : AntiVPN.getInstance().getCommands()) {
|
||||
BungeeCord.getInstance().getPluginManager().registerCommand(pluginInstance, new net.md_5.bungee.api.plugin
|
||||
.Command(command.parent() + " " + command.name(), command.permission(), command.aliases()) {
|
||||
@Override
|
||||
@@ -43,7 +38,7 @@ public class BungeePlugin extends Plugin {
|
||||
command.execute(new BungeeCommandExecutor(commandSender), strings);
|
||||
}
|
||||
});
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,6 +15,8 @@ public abstract class Command {
|
||||
public abstract String usage();
|
||||
|
||||
public abstract String parent();
|
||||
|
||||
public abstract Command[] children();
|
||||
|
||||
public abstract String execute(CommandExecutor executor, String[] args);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import dev.brighten.antivpn.AntiVPN;
|
||||
import dev.brighten.antivpn.command.Command;
|
||||
import dev.brighten.antivpn.command.CommandExecutor;
|
||||
import dev.brighten.antivpn.utils.StringUtil;
|
||||
import jdk.nashorn.internal.lookup.Lookup;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -39,6 +40,11 @@ public class AntiVPNCommand extends Command {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Command[] children() {
|
||||
return new Command[] {new LookupCommand()};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute(CommandExecutor uuid, String[] args) {
|
||||
List<String> messages = new ArrayList<>();
|
||||
@@ -47,8 +53,9 @@ public class AntiVPNCommand extends Command {
|
||||
messages.add("&6&lAntiVPN Help Page");
|
||||
messages.add("");
|
||||
for (Command child : AntiVPN.getInstance().getCommands()) {
|
||||
messages.add(String.format("&8/&f%s &8- &7&o%s", "&7antivpn &f" + child.name() + " &7" + child.usage(),
|
||||
description()));
|
||||
messages.add(String.format("&8/&f%s &8- &7&o%s", "&7" + child.parent()
|
||||
+ (child.parent().length() > 0 ? " " : "") + "&f" + child.name() + " &7"
|
||||
+ child.usage(), description()));
|
||||
}
|
||||
messages.add(StringUtil.line("&8"));
|
||||
|
||||
|
||||
@@ -39,10 +39,15 @@ public class LookupCommand extends Command {
|
||||
return "antivpn";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Command[] children() {
|
||||
return new Command[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute(CommandExecutor executor, String[] args) {
|
||||
if(args.length == 0) {
|
||||
return "&cPlease supply a player to check the VPN information of";
|
||||
return "&cPlease supply a player to check.";
|
||||
}
|
||||
|
||||
Optional<APIPlayer> player = AntiVPN.getInstance().getPlayerExecutor().getPlayer(args[0]);
|
||||
@@ -57,7 +62,7 @@ public class LookupCommand extends Command {
|
||||
executor.sendMessage("&cThere was an error trying to find the information of this player.");
|
||||
} else {
|
||||
executor.sendMessage(StringUtil.line("&8"));
|
||||
executor.sendMessage("&6&l" + player.get().getName() + "s &7&lConnection Information");
|
||||
executor.sendMessage("&6&l" + player.get().getName() + "&7&l's Connection Information");
|
||||
executor.sendMessage("");
|
||||
executor.sendMessage(String.format("&e%s&8: &f%s", "Proxy", result.isProxy()
|
||||
? "&a" + result.getMethod() : "&cNo"));
|
||||
|
||||
Reference in New Issue
Block a user