feat: add Admin Varo command
This commit is contained in:
parent
d4f37b6ddf
commit
efe372e15b
3 changed files with 75 additions and 0 deletions
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
@ -5,7 +5,9 @@
|
|||
"java.configuration.updateBuildConfiguration": "automatic",
|
||||
"cSpell.words": [
|
||||
"Gamerules",
|
||||
"Mojang",
|
||||
"cliffbreak",
|
||||
"unban",
|
||||
"varo"
|
||||
],
|
||||
"java.format.settings.url": "eclipse-formatter.xml",
|
||||
|
|
|
@ -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<String> bans = (ArrayList<String>) 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -7,4 +7,7 @@ commands:
|
|||
test:
|
||||
description: A command to test certain plugin behaviors.
|
||||
aliases: [t]
|
||||
usage: /<command>
|
||||
varo:
|
||||
description: The Main Varo command.
|
||||
usage: /<command>
|
Loading…
Reference in a new issue