feat: add tab autocomplete for varo commands
This commit is contained in:
parent
d38d9e3e50
commit
871970f541
6 changed files with 92 additions and 8 deletions
|
@ -9,6 +9,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
import de.cliffbreak.varo.commands.VaroCommand;
|
import de.cliffbreak.varo.commands.VaroCommand;
|
||||||
|
import de.cliffbreak.varo.commands.VaroTabCompleter;
|
||||||
import de.cliffbreak.varo.listeners.BannedActionListener;
|
import de.cliffbreak.varo.listeners.BannedActionListener;
|
||||||
import de.cliffbreak.varo.listeners.BannedItemListener;
|
import de.cliffbreak.varo.listeners.BannedItemListener;
|
||||||
import de.cliffbreak.varo.listeners.ChatListener;
|
import de.cliffbreak.varo.listeners.ChatListener;
|
||||||
|
@ -64,6 +65,7 @@ public class Varo extends JavaPlugin {
|
||||||
this.getServer().getPluginManager().registerEvents(new PlayerInteractNPCListener(this), this);
|
this.getServer().getPluginManager().registerEvents(new PlayerInteractNPCListener(this), this);
|
||||||
|
|
||||||
this.getCommand("varo").setExecutor(new VaroCommand(this));
|
this.getCommand("varo").setExecutor(new VaroCommand(this));
|
||||||
|
this.getCommand("varo").setTabCompleter(new VaroTabCompleter(this));
|
||||||
|
|
||||||
this.varoUtils.init();
|
this.varoUtils.init();
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,6 @@ public class VaroCommand implements CommandExecutor {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args.length == 2 && args[0].equals("unban")) {
|
if (args.length == 2 && args[0].equals("unban")) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final String result = WebUtils.GET("https://api.mojang.com/users/profiles/minecraft/" + args[1]);
|
final String result = WebUtils.GET("https://api.mojang.com/users/profiles/minecraft/" + args[1]);
|
||||||
if (result.isEmpty()) {
|
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.");
|
"§c§lFehler:§r§c beim Verbinden mit der Mojang-API ist ein Fehler aufgetreten. Eventuell sind die Mojang Server down.");
|
||||||
e.printStackTrace();
|
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")) {
|
} else if (args.length == 1 && args[0].equals("start")) {
|
||||||
sender.sendMessage("§aStarting...");
|
sender.sendMessage("§aStarting...");
|
||||||
for (final Player p : Bukkit.getServer().getOnlinePlayers()) {
|
for (final Player p : Bukkit.getServer().getOnlinePlayers()) {
|
||||||
|
@ -104,6 +121,7 @@ public class VaroCommand implements CommandExecutor {
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("\n§6========== §b§lCliffbreak.de VARO §r§6============\n ");
|
sender.sendMessage("\n§6========== §b§lCliffbreak.de VARO §r§6============\n ");
|
||||||
sender.sendMessage("§a/varo start: §rStarte das Varo Projekt!");
|
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 unban [Spieler]: §rSpieler wieder auf den Server lassen");
|
||||||
sender.sendMessage("§a/varo portal [enable/disable]: §rAktiviere/Deaktiviere die Portal-Erstellung");
|
sender.sendMessage("§a/varo portal [enable/disable]: §rAktiviere/Deaktiviere die Portal-Erstellung");
|
||||||
sender.sendMessage("§a/varo teamcolors: §rZeige verfügbare Team-Farben an");
|
sender.sendMessage("§a/varo teamcolors: §rZeige verfügbare Team-Farben an");
|
||||||
|
|
|
@ -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<String> onTabComplete(final CommandSender sender, final Command command, final String alias,
|
||||||
|
final String[] args) {
|
||||||
|
final List<String> list = new ArrayList<String>();
|
||||||
|
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<String> 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<String> removeQueue = new ArrayList<String>();
|
||||||
|
for (String s : list) {
|
||||||
|
if (!s.startsWith(args[args.length - 1])) {
|
||||||
|
removeQueue.add(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list.removeAll(removeQueue);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -26,7 +26,7 @@ public class PlayerDeathListener implements Listener {
|
||||||
}.runTaskLater(this.plugin, 20);
|
}.runTaskLater(this.plugin, 20);
|
||||||
e.getEntity().setHealth(20d); // Reset health to prevent death dialog after rejoin (if unbanned)
|
e.getEntity().setHealth(20d); // Reset health to prevent death dialog after rejoin (if unbanned)
|
||||||
e.getEntity().setGameMode(GameMode.SPECTATOR);
|
e.getEntity().setGameMode(GameMode.SPECTATOR);
|
||||||
this.plugin.getBanUtils().addBann(e.getEntity().getUniqueId());
|
this.plugin.getBanUtils().addBan(e.getEntity().getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -201,7 +201,7 @@ public class NPCManager {
|
||||||
}
|
}
|
||||||
}.runTask(this.plugin); // Run Task in sync to be thread safe
|
}.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() + ")");
|
Bukkit.broadcastMessage("TODO: Player(" + "??" + ") killed AFK Player (" + npc.getName() + ")");
|
||||||
|
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
|
|
|
@ -23,12 +23,21 @@ public class BanUtils {
|
||||||
return bans.contains(compressedUuid);
|
return bans.contains(compressedUuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addBann(final UUID uuid) {
|
public ArrayList<String> getBans() {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final ArrayList<String> bans = (ArrayList<String>) this.plugin.getConfig().get("Varo.Bans");
|
final ArrayList<String> bans = (ArrayList<String>) this.plugin.getConfig().get("Varo.Bans");
|
||||||
final String compressedUUID = uuid.toString().replace("-", "");
|
return bans;
|
||||||
if (!bans.contains(compressedUUID)) {
|
}
|
||||||
bans.add(compressedUUID);
|
|
||||||
|
public void addBan(final UUID uuid) {
|
||||||
|
addBan(uuid.toString().replace("-", ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addBan(final String compressedUuid) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
final ArrayList<String> bans = (ArrayList<String>) this.plugin.getConfig().get("Varo.Bans");
|
||||||
|
if (!bans.contains(compressedUuid)) {
|
||||||
|
bans.add(compressedUuid);
|
||||||
this.plugin.getConfig().set("Varo.Bans", bans);
|
this.plugin.getConfig().set("Varo.Bans", bans);
|
||||||
this.plugin.saveConfig();
|
this.plugin.saveConfig();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue