From c8806ac1ed16ff7d946de2fad08fded4e04cce6b Mon Sep 17 00:00:00 2001 From: "Arnaud G. GIBERT" Date: Thu, 29 Apr 2021 15:02:11 +0200 Subject: [PATCH] Add a first version of the command completion Improve list command output (new data, sort, color...) Improve help command output (sort) Rename score board Minor fixing --- src/com/Geekpower14/Quake/Arena/Arena.java | 21 +++++++--- .../Geekpower14/Quake/Arena/ArenaManager.java | 17 +++++++-- .../Quake/Commands/MyCommandExecutor.java | 38 +++++++++++++------ .../Quake/Commands/MyTabCompleter.java | 34 +++++++++++++++++ .../Geekpower14/Quake/Lobby/LobbyManager.java | 2 +- src/com/Geekpower14/Quake/Quake.java | 6 ++- .../Geekpower14/Quake/Trans/Translate.java | 2 +- src/com/Geekpower14/Quake/Utils/ScoreB.java | 5 ++- 8 files changed, 101 insertions(+), 24 deletions(-) create mode 100644 src/com/Geekpower14/Quake/Commands/MyTabCompleter.java diff --git a/src/com/Geekpower14/Quake/Arena/Arena.java b/src/com/Geekpower14/Quake/Arena/Arena.java index 8187bfa..ad15db3 100644 --- a/src/com/Geekpower14/Quake/Arena/Arena.java +++ b/src/com/Geekpower14/Quake/Arena/Arena.java @@ -423,11 +423,22 @@ public abstract class Arena { return null; } - public String getStatus() { - return this._etat <= this._pregame ? (this.getplayers() == this._maxplayer ? ChatColor.DARK_PURPLE + "[FULL]" : - (this._VIP ? ChatColor.AQUA + "[VIP]" : - (this._etat <= this._starting ? ChatColor.GOLD + "[Starting in " + this._etat + "s]" : - ChatColor.GREEN + "[Join]"))) : ChatColor.RED + "[In Game]"; + public String getStatus(Boolean bracket) { + String osb, csb; + + if( bracket) + { + osb="["; + csb="]"; + } else { + osb=""; + csb=""; + } + + return this._etat <= this._pregame ? (this.getplayers() == this._maxplayer ? ChatColor.DARK_PURPLE + osb + "FULL" + csb : + (this._VIP ? ChatColor.AQUA + osb + "VIP" + csb : + (this._etat <= this._starting ? ChatColor.GOLD + osb + "Starting in " + this._etat + "s" + csb : + ChatColor.GREEN + osb + "Join" + csb))) : ChatColor.RED + osb + "In Game" + csb; } } diff --git a/src/com/Geekpower14/Quake/Arena/ArenaManager.java b/src/com/Geekpower14/Quake/Arena/ArenaManager.java index 732c6a2..037ef66 100644 --- a/src/com/Geekpower14/Quake/Arena/ArenaManager.java +++ b/src/com/Geekpower14/Quake/Arena/ArenaManager.java @@ -6,6 +6,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; +import java.util.TreeMap; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.configuration.file.YamlConfiguration; @@ -184,16 +185,26 @@ public class ArenaManager { } else { player.sendMessage(ChatColor.LIGHT_PURPLE +"Arena List:"); - TableGenerator tg = new TableGenerator(TableGenerator.Alignment.RIGHT, TableGenerator.Alignment.LEFT, TableGenerator.Alignment.LEFT, TableGenerator.Alignment.RIGHT); - + player.sendMessage(""); + + TreeMap _ARENAS_sorted = new TreeMap(); for(Arena aren : _ARENAS.values()) { + _ARENAS_sorted.put( aren._ID, aren); + } + + TableGenerator tg = new TableGenerator(TableGenerator.Alignment.RIGHT, TableGenerator.Alignment.LEFT, TableGenerator.Alignment.LEFT, TableGenerator.Alignment.CENTER, TableGenerator.Alignment.RIGHT, TableGenerator.Alignment.CENTER, TableGenerator.Alignment.RIGHT); + tg.addRow( ChatColor.RED + "§nID§r" + ChatColor.WHITE, ChatColor.GREEN + "§nType§r", "§nArena Name§r" + ChatColor.WHITE, ChatColor.GREEN + "§nStatus§r" + ChatColor.WHITE, ChatColor.GOLD + "§nNb P§r", ChatColor.BLUE + "§nMin" + ChatColor.WHITE + "§n/" + ChatColor.RED + "§nMax§r", "§nSpawn§r"); + tg.addRow(); + + for(Arena aren : _ARENAS_sorted.values()) { if(aren instanceof SArena) { type="Solo"; } else { type="Team"; } - tg.addRow( ChatColor.RED + Integer.toString(aren._ID) + ChatColor.WHITE, ChatColor.GREEN + type , aren._name + ChatColor.WHITE, aren.getStatus()); + tg.addRow( ChatColor.RED + Integer.toString(aren._ID) + ChatColor.WHITE, ChatColor.GREEN + type , aren._name + ChatColor.WHITE, aren.getStatus(false), + ChatColor.GOLD + Integer.toString( aren._players.size()), ChatColor.BLUE + Integer.toString( aren._minplayer) + ChatColor.WHITE + " / " + ChatColor.RED + Integer.toString( aren._maxplayer) + ChatColor.WHITE, type == "Solo" ? Integer.toString( aren._spawns.size()) : Integer.toString( aren._spawns_B.size()) + " + " + Integer.toString( aren._spawns_R.size())); } diff --git a/src/com/Geekpower14/Quake/Commands/MyCommandExecutor.java b/src/com/Geekpower14/Quake/Commands/MyCommandExecutor.java index 27b4e19..972294d 100644 --- a/src/com/Geekpower14/Quake/Commands/MyCommandExecutor.java +++ b/src/com/Geekpower14/Quake/Commands/MyCommandExecutor.java @@ -3,7 +3,9 @@ package com.Geekpower14.Quake.Commands; import com.Geekpower14.Quake.Quake; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.stream.Collectors; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -12,7 +14,7 @@ import org.bukkit.entity.Player; public class MyCommandExecutor implements CommandExecutor { public Quake _plugin; - private final HashMap _commands = new HashMap<>(); + private final LinkedHashMap _commands = new LinkedHashMap<>(); public MyCommandExecutor(Quake pl) { _plugin = pl; @@ -36,13 +38,13 @@ public class MyCommandExecutor implements CommandExecutor { _commands.put("leave", new LeaveCommand(_plugin)); _commands.put("start", new StartCommand(_plugin)); _commands.put("stop", new StopCommand(_plugin)); - _commands.put("shop", new ShopCommand(_plugin)); - _commands.put("kill", new UtilsCommand(_plugin, "kill")); - _commands.put("add", new UtilsCommand(_plugin, "add")); - _commands.put("lol", new UtilsCommand(_plugin, "lol")); - _commands.put("reload", new ReloadCommand(_plugin)); _commands.put("team", new ChangeTeamCommand(_plugin)); _commands.put("money", new MoneyCommand(_plugin)); + _commands.put("shop", new ShopCommand(_plugin)); + _commands.put("add", new UtilsCommand(_plugin, "add")); + _commands.put("kill", new UtilsCommand(_plugin, "kill")); + _commands.put("lol", new UtilsCommand(_plugin, "lol")); + _commands.put("reload", new ReloadCommand(_plugin)); } @Override @@ -55,13 +57,13 @@ public class MyCommandExecutor implements CommandExecutor { player = (Player)sender; if(cmd.getName().equalsIgnoreCase("quake")) { if(args == null || args.length < 1) { - player.sendMessage(ChatColor.YELLOW + "Plugin By Geekpower14u / Bl4ckSkull666"); - player.sendMessage(ChatColor.YELLOW + "Updated bt AlkorZ3 ( Obsidia.Rx3.net )"); + player.sendMessage(ChatColor.YELLOW + "Plugin by GeekPower14 / Bl4ckSkull666"); + player.sendMessage(ChatColor.YELLOW + "Updated by AlkorZ3 ( obsidia.rx3.net )"); player.sendMessage(ChatColor.YELLOW + "Version: " + _plugin.getDescription().getVersion()); return true; } - if(args[0].equalsIgnoreCase("help")) { + if(args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("?")) { help(player); return true; } @@ -92,9 +94,21 @@ public class MyCommandExecutor implements CommandExecutor { public void help(Player p) { p.sendMessage("/Quake "); + for (BasicCommand v : _commands.values()) { - p.sendMessage(ChatColor.GRAY + "- " + v.help(p)); + p.sendMessage(ChatColor.AQUA + "- " + v.help(p)); } } -} + public List getCompletionList(String[] args) { + List list = null; + + if( args.length == 1) { + list = _commands.keySet().stream().collect(Collectors.toList()); + list.add( "help"); + list.add( "?"); + } + + return list; + } +} diff --git a/src/com/Geekpower14/Quake/Commands/MyTabCompleter.java b/src/com/Geekpower14/Quake/Commands/MyTabCompleter.java new file mode 100644 index 0000000..7c2094a --- /dev/null +++ b/src/com/Geekpower14/Quake/Commands/MyTabCompleter.java @@ -0,0 +1,34 @@ +package com.Geekpower14.Quake.Commands; + +import com.Geekpower14.Quake.Quake; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +public class MyTabCompleter implements TabCompleter +{ + public Quake _plugin; + + public MyTabCompleter(Quake pl) { + _plugin = pl; + } + + @Override + public List onTabComplete (CommandSender sender, Command cmd, String label, String[] args) { + List list = new ArrayList<>(); + // _plugin.getLogger().info("MTC [" + cmd + "] [" + label + "] [" + args.length + "]"); + + if(cmd.getName().equalsIgnoreCase("quake") && args.length >= 0){ + if(sender instanceof Player){ + list = _plugin._ce.getCompletionList(args); + } + } + return list; + } +} diff --git a/src/com/Geekpower14/Quake/Lobby/LobbyManager.java b/src/com/Geekpower14/Quake/Lobby/LobbyManager.java index f63ebef..7bd32e7 100644 --- a/src/com/Geekpower14/Quake/Lobby/LobbyManager.java +++ b/src/com/Geekpower14/Quake/Lobby/LobbyManager.java @@ -235,7 +235,7 @@ public class LobbyManager { /* String ligne0 = arena._etat <= arena._pregame ? (arena.getplayers() == arena._maxplayer ? ChatColor.DARK_PURPLE + "[FULL]" : (arena._VIP ? ChatColor.AQUA + "[VIP]" : (arena._etat <= arena._starting ? ChatColor.GOLD + "[Starting]" : ChatColor.GREEN + "[Join]"))) : ChatColor.RED + "[InGame]"; */ - String ligne0 = arena.getStatus(); + String ligne0 = arena.getStatus(true); String tmp = ""; if (arena instanceof SArena) { tmp = "S-"; diff --git a/src/com/Geekpower14/Quake/Quake.java b/src/com/Geekpower14/Quake/Quake.java index fabfc77..1ebea6e 100644 --- a/src/com/Geekpower14/Quake/Quake.java +++ b/src/com/Geekpower14/Quake/Quake.java @@ -2,6 +2,7 @@ package com.Geekpower14.Quake; import com.Geekpower14.Quake.Arena.ArenaManager; import com.Geekpower14.Quake.Commands.MyCommandExecutor; +import com.Geekpower14.Quake.Commands.MyTabCompleter; import com.Geekpower14.Quake.Eco.EcoManager; import com.Geekpower14.Quake.Listener.PlayerListener; import com.Geekpower14.Quake.Listener.Weather; @@ -40,6 +41,7 @@ extends JavaPlugin { public static boolean _debug = false; public static String _version = "3.5.0"; public static Version _ver = new Version(_version); + public MyCommandExecutor _ce = null; public ArenaManager _am = null; public LobbyManager _lobby = null; public int _threadlob = 0; @@ -91,7 +93,9 @@ extends JavaPlugin { _stuff = new StuffManager(this); getServer().getPluginManager().registerEvents(new PlayerListener(this), this); getServer().getPluginManager().registerEvents(new Weather(this), this); - getCommand("Quake").setExecutor(new MyCommandExecutor(this)); + _ce=new MyCommandExecutor(this); + getCommand("Quake").setExecutor(_ce); + getCommand("Quake").setTabCompleter(new MyTabCompleter(this)); _am = new ArenaManager(this); _lobby = new LobbyManager(this); _threadlob = Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){ diff --git a/src/com/Geekpower14/Quake/Trans/Translate.java b/src/com/Geekpower14/Quake/Trans/Translate.java index 331bb00..71553f1 100644 --- a/src/com/Geekpower14/Quake/Trans/Translate.java +++ b/src/com/Geekpower14/Quake/Trans/Translate.java @@ -38,7 +38,7 @@ public class Translate { setDefaultConfig("ScoreBoard.Deaths.name", "Deaths"); setDefaultConfig("ScoreBoard.Shots.name", "Shots"); setDefaultConfig("ScoreBoard.Wins.name", "Wins"); - setDefaultConfig("ScoreBoard.name", "Scores"); + setDefaultConfig("ScoreBoard.name", "Quake Scores"); setDefaultConfig("Shop.price", "&r&o&6Price: [PRICE]"); setDefaultConfig("Shop.needToBuy", "&r&o&6Need: [NEED]"); setDefaultConfig("Shop.navigation.previousPage", "&aBack"); diff --git a/src/com/Geekpower14/Quake/Utils/ScoreB.java b/src/com/Geekpower14/Quake/Utils/ScoreB.java index facfecf..229129e 100644 --- a/src/com/Geekpower14/Quake/Utils/ScoreB.java +++ b/src/com/Geekpower14/Quake/Utils/ScoreB.java @@ -7,6 +7,7 @@ import org.bukkit.entity.Player; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Scoreboard; +import org.bukkit.ChatColor; public final class ScoreB { public Quake _plugin; @@ -30,12 +31,13 @@ public final class ScoreB { _board = Bukkit.getScoreboardManager().getNewScoreboard(); _objective = _board.registerNewObjective("Score", "dummy"); _objective.setDisplaySlot(DisplaySlot.SIDEBAR); - _objective.setDisplayName(_plugin._trad.get("ScoreBoard.name")); + _objective.setDisplayName(ChatColor.YELLOW + _plugin._trad.get("ScoreBoard.name")); _objective.getScore(_plugin._trad.get("Shop.Coins.name")).setScore(_Money); _objective.getScore(_plugin._trad.get("ScoreBoard.Kills.name")).setScore(_Kills); _objective.getScore(_plugin._trad.get("ScoreBoard.Deaths.name")).setScore(_Deaths); _objective.getScore(_plugin._trad.get("ScoreBoard.Shots.name")).setScore(_Shots); _objective.getScore(_plugin._trad.get("ScoreBoard.Wins.name")).setScore(_Wins); + if (isScoreWorld(_player.getWorld().getName())) { _player.setScoreboard(_board); } else if (!isScoreWorld(_player.getWorld().getName())) { @@ -57,6 +59,7 @@ public final class ScoreB { _objective.getScore(_plugin._trad.get("ScoreBoard.Deaths.name")).setScore(_Deaths); _objective.getScore(_plugin._trad.get("ScoreBoard.Shots.name")).setScore(_Shots); _objective.getScore(_plugin._trad.get("ScoreBoard.Wins.name")).setScore(_Wins); + if (isScoreWorld(_player.getWorld().getName())) { _player.setScoreboard(_board); } else {