diff --git a/varo/src/main/java/de/cliffbreak/varo/Varo.java b/varo/src/main/java/de/cliffbreak/varo/Varo.java index 60b9ad5..bf528f9 100644 --- a/varo/src/main/java/de/cliffbreak/varo/Varo.java +++ b/varo/src/main/java/de/cliffbreak/varo/Varo.java @@ -9,6 +9,7 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.configuration.file.YamlConfiguration; import de.cliffbreak.varo.commands.VaroCommand; +import de.cliffbreak.varo.commands.VaroTabCompleter; import de.cliffbreak.varo.listeners.BannedActionListener; import de.cliffbreak.varo.listeners.BannedItemListener; import de.cliffbreak.varo.listeners.ChatListener; @@ -64,6 +65,7 @@ public class Varo extends JavaPlugin { this.getServer().getPluginManager().registerEvents(new PlayerInteractNPCListener(this), this); this.getCommand("varo").setExecutor(new VaroCommand(this)); + this.getCommand("varo").setTabCompleter(new VaroTabCompleter(this)); this.varoUtils.init(); } diff --git a/varo/src/main/java/de/cliffbreak/varo/commands/VaroCommand.java b/varo/src/main/java/de/cliffbreak/varo/commands/VaroCommand.java index 8812b57..1262959 100644 --- a/varo/src/main/java/de/cliffbreak/varo/commands/VaroCommand.java +++ b/varo/src/main/java/de/cliffbreak/varo/commands/VaroCommand.java @@ -36,7 +36,6 @@ public class VaroCommand implements CommandExecutor { return true; } if (args.length == 2 && args[0].equals("unban")) { - try { final String result = WebUtils.GET("https://api.mojang.com/users/profiles/minecraft/" + args[1]); if (result.isEmpty()) { @@ -55,7 +54,25 @@ public class VaroCommand implements CommandExecutor { "§c§lFehler:§r§c beim Verbinden mit der Mojang-API ist ein Fehler aufgetreten. Eventuell sind die Mojang Server down."); e.printStackTrace(); } - + } else if (args.length == 2 && args[0].equals("ban")) { + try { + final String result = WebUtils.GET("https://api.mojang.com/users/profiles/minecraft/" + args[1]); + if (result.isEmpty()) { + sender.sendMessage("§c§lFehler: §r§cDer Spieler wurde nicht gefunden."); + return true; + } + final JSONObject uuidObject = (JSONObject) JSONValue.parseWithException(result); + if (this.plugin.getPlayerCache().getName(uuidObject.get("id").toString()) == null) { + sender.sendMessage("§c§lFehler: §r§cDer Spieler war noch nie auf diesem Server."); + return true; + } + this.plugin.getBanUtils().addBan(uuidObject.get("id").toString()); + sender.sendMessage("§a§lErfolg: §r§aDer Spieler ist nun gebannt."); + } catch (IOException | ParseException 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 if (args.length == 1 && args[0].equals("start")) { sender.sendMessage("§aStarting..."); for (final Player p : Bukkit.getServer().getOnlinePlayers()) { @@ -104,6 +121,7 @@ public class VaroCommand implements CommandExecutor { } else { sender.sendMessage("\n§6========== §b§lCliffbreak.de VARO §r§6============\n "); sender.sendMessage("§a/varo start: §rStarte das Varo Projekt!"); + sender.sendMessage("§a/varo ban [Spieler]: §rSpieler bannen"); sender.sendMessage("§a/varo unban [Spieler]: §rSpieler wieder auf den Server lassen"); sender.sendMessage("§a/varo portal [enable/disable]: §rAktiviere/Deaktiviere die Portal-Erstellung"); sender.sendMessage("§a/varo teamcolors: §rZeige verfügbare Team-Farben an"); diff --git a/varo/src/main/java/de/cliffbreak/varo/commands/VaroTabCompleter.java b/varo/src/main/java/de/cliffbreak/varo/commands/VaroTabCompleter.java new file mode 100644 index 0000000..2ff3bf0 --- /dev/null +++ b/varo/src/main/java/de/cliffbreak/varo/commands/VaroTabCompleter.java @@ -0,0 +1,55 @@ +package de.cliffbreak.varo.commands; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; + +import de.cliffbreak.varo.Varo; + +public class VaroTabCompleter implements TabCompleter { + + private final Varo plugin; + + public VaroTabCompleter(final Varo plugin) { + this.plugin = plugin; + } + + @Override + public List onTabComplete(final CommandSender sender, final Command command, final String alias, + final String[] args) { + final List list = new ArrayList(); + if (sender.hasPermission("varo.admin")) { + if (args.length == 1) { + list.add("unban"); + list.add("ban"); + list.add("start"); + list.add("teamcolors"); + list.add("portal"); + list.add("test"); + list.add("testremove"); + } else if (args.length == 2 && args[0].equals("unban")) { + final ArrayList bans = this.plugin.getBanUtils().getBans(); + for (String uuid : bans) { + list.add(this.plugin.getPlayerCache().getName(uuid)); + } + } else if (args.length == 2 && args[0].equals("ban")) { + return null; // Return null to show default player autocomplete + } else if (args.length == 2 && args[0].equals("portal")) { + list.add("enable"); + list.add("disable"); + } + final List removeQueue = new ArrayList(); + for (String s : list) { + if (!s.startsWith(args[args.length - 1])) { + removeQueue.add(s); + } + } + list.removeAll(removeQueue); + } + return list; + } + +} \ No newline at end of file diff --git a/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerDeathListener.java b/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerDeathListener.java index b4708bd..06c12d5 100644 --- a/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerDeathListener.java +++ b/varo/src/main/java/de/cliffbreak/varo/listeners/PlayerDeathListener.java @@ -26,7 +26,7 @@ public class PlayerDeathListener implements Listener { }.runTaskLater(this.plugin, 20); e.getEntity().setHealth(20d); // Reset health to prevent death dialog after rejoin (if unbanned) e.getEntity().setGameMode(GameMode.SPECTATOR); - this.plugin.getBanUtils().addBann(e.getEntity().getUniqueId()); + this.plugin.getBanUtils().addBan(e.getEntity().getUniqueId()); } } \ No newline at end of file diff --git a/varo/src/main/java/de/cliffbreak/varo/managers/NPCManager.java b/varo/src/main/java/de/cliffbreak/varo/managers/NPCManager.java index cecc3b9..4b8771b 100644 --- a/varo/src/main/java/de/cliffbreak/varo/managers/NPCManager.java +++ b/varo/src/main/java/de/cliffbreak/varo/managers/NPCManager.java @@ -201,7 +201,7 @@ public class NPCManager { } }.runTask(this.plugin); // Run Task in sync to be thread safe - this.plugin.getBanUtils().addBann(npc.getUniqueID()); + this.plugin.getBanUtils().addBan(npc.getUniqueID()); Bukkit.broadcastMessage("TODO: Player(" + "??" + ") killed AFK Player (" + npc.getName() + ")"); new BukkitRunnable() { diff --git a/varo/src/main/java/de/cliffbreak/varo/uitls/BanUtils.java b/varo/src/main/java/de/cliffbreak/varo/uitls/BanUtils.java index efd1506..760a602 100644 --- a/varo/src/main/java/de/cliffbreak/varo/uitls/BanUtils.java +++ b/varo/src/main/java/de/cliffbreak/varo/uitls/BanUtils.java @@ -23,12 +23,21 @@ public class BanUtils { return bans.contains(compressedUuid); } - public void addBann(final UUID uuid) { + public ArrayList getBans() { @SuppressWarnings("unchecked") final ArrayList bans = (ArrayList) this.plugin.getConfig().get("Varo.Bans"); - final String compressedUUID = uuid.toString().replace("-", ""); - if (!bans.contains(compressedUUID)) { - bans.add(compressedUUID); + return bans; + } + + public void addBan(final UUID uuid) { + addBan(uuid.toString().replace("-", "")); + } + + public void addBan(final String compressedUuid) { + @SuppressWarnings("unchecked") + final ArrayList bans = (ArrayList) this.plugin.getConfig().get("Varo.Bans"); + if (!bans.contains(compressedUuid)) { + bans.add(compressedUuid); this.plugin.getConfig().set("Varo.Bans", bans); this.plugin.saveConfig(); }