diff --git a/.vscode/settings.json b/.vscode/settings.json index a02b5c2..33dc01b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,7 +5,9 @@ "java.configuration.updateBuildConfiguration": "automatic", "cSpell.words": [ "Gamerules", + "Mojang", "cliffbreak", + "unban", "varo" ], "java.format.settings.url": "eclipse-formatter.xml", diff --git a/varo/src/main/java/de/cliffbreak/varo/commands/VaroCommand.java b/varo/src/main/java/de/cliffbreak/varo/commands/VaroCommand.java new file mode 100644 index 0000000..9358084 --- /dev/null +++ b/varo/src/main/java/de/cliffbreak/varo/commands/VaroCommand.java @@ -0,0 +1,70 @@ +package de.cliffbreak.varo.commands; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.ArrayList; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.json.simple.JSONObject; +import org.json.simple.JSONValue; +import org.json.simple.parser.ParseException; + +import de.cliffbreak.varo.Varo; + +public class VaroCommand implements CommandExecutor { + + private Varo plugin; + + public VaroCommand(Varo plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length == 2 && args[0].equals("unban")) { + @SuppressWarnings("unchecked") + final ArrayList bans = (ArrayList) this.plugin.config.get("Varo.Bans"); + String url = "https://api.mojang.com/users/profiles/minecraft/" + args[1]; + try { + HttpURLConnection connection = ((HttpURLConnection) (new URL(url)).openConnection()); + connection.setRequestMethod("GET"); + BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String inputLine; + StringBuffer content = new StringBuffer(); + while ((inputLine = in.readLine()) != null) { + content.append(inputLine); + } + in.close(); + connection.disconnect(); + if (content.toString().isEmpty()) { + sender.sendMessage("§c§lFehler: §r§cDer Spieler wurde nicht gefunden."); + return true; + } + JSONObject uuidObject = (JSONObject) JSONValue.parseWithException(content.toString()); + if (!bans.contains(uuidObject.get("id").toString())) { + sender.sendMessage("§c§lFehler: §r§cDer Spieler ist nicht gebannt."); + return true; + } + bans.remove(uuidObject.get("id").toString()); + this.plugin.config.set("Varo.Bans", bans); + this.plugin.saveConfiguration(); + sender.sendMessage("§a§lErfolg: §r§aDer Spieler ist nun nicht mehr gebannt."); + } catch (ParseException | IOException e) { + sender.sendMessage( + "§c§lFehler:§r§c beim Verbinden mit der Mojang-API ist ein Fehler aufgetreten. Eventuell sind die Mojang Server down."); + e.printStackTrace(); + } + } else { + sender.sendMessage("\n§6========== §b§lCliffbreak.de VARO §r§6============\n "); + sender.sendMessage("§a/varo unban [Spieler]: §rSpieler wieder auf den Server lassen"); + sender.sendMessage("\n§6=========================================="); + } + return true; + } + +} \ No newline at end of file diff --git a/varo/src/main/resources/plugin.yml b/varo/src/main/resources/plugin.yml index d7035a1..b8c65f2 100644 --- a/varo/src/main/resources/plugin.yml +++ b/varo/src/main/resources/plugin.yml @@ -7,4 +7,7 @@ commands: test: description: A command to test certain plugin behaviors. aliases: [t] + usage: / + varo: + description: The Main Varo command. usage: / \ No newline at end of file