Complete command completion implementation

Minor console log fixes (No more French! :D)
This commit is contained in:
Arnaud G. GIBERT 2021-05-04 23:50:35 +02:00
parent b579e75da7
commit dc4f3244df
29 changed files with 196 additions and 70 deletions

View File

@ -192,6 +192,8 @@ public abstract class Arena {
_minplayer = min;
}
public abstract List<String> getSpawnIndexList(String team);
public Location str2loc(String loc) {
if (loc == null) {
return null;

View File

@ -33,8 +33,6 @@ public class ArenaManager {
if(f.getName().endsWith(".yml")) {
String name = f.getName().replaceAll(".yml", "");
Maps.add(name);
_plugin.getLogger().info("Loading: [" + f.getName() + "]");
}
}
if(Maps.isEmpty())

View File

@ -8,6 +8,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.logging.Level;
import java.util.Formatter;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Color;
@ -77,6 +78,7 @@ public class SArena extends Arena {
_potions = l;
if(config.contains("Nombre"))
saveConfig();
_plugin.getLogger().info("Arena loading [" + _name + "]...");
return true;
}
@ -110,7 +112,7 @@ public class SArena extends Arena {
try {
config.save(new File(_plugin.getDataFolder(), "/arenas/" + _name + ".yml"));
} catch (IOException e) {
_plugin.getLogger().warning("save default de " + _name + " impossible !");
_plugin.getLogger().warning("Save default of" + _name + " impossible!");
disable();
}
return true;
@ -119,6 +121,7 @@ public class SArena extends Arena {
@Override
public Boolean saveConfig() {
YamlConfiguration config = YamlConfiguration.loadConfiguration((File)new File(_plugin.getDataFolder(), "/arenas/" + _name + ".yml"));
_plugin.getLogger().info("Save of " + _name + " ...");
config.set("Name", _name);
config.set("Type", "Solo");
config.set("Map", _map);
@ -145,7 +148,7 @@ public class SArena extends Arena {
config.save(new File(_plugin.getDataFolder(), "/arenas/" + _name + ".yml"));
_plugin.saveConfig();
} catch (IOException e) {
_plugin.getLogger().warning("save de " + _name + "impossible !");
_plugin.getLogger().warning("Save of" + _name + "impossible!");
disable();
return false;
}
@ -308,6 +311,17 @@ public class SArena extends Arena {
_spawns.remove(Integer.parseInt(args));
}
@Override
public List<String> getSpawnIndexList(String team) {
List<String> list = new ArrayList();
String format= "%0" + String.valueOf(_spawns.size()).length() + "d";
for (int i = 0; i < _spawns.size(); i++) {
list.add(String.format( format, i));
}
return(list);
}
@Override
public void win(final Player player) {
getGainWin(player);

View File

@ -77,7 +77,7 @@ public class TArena extends Arena {
l.add(StrToPo(popo));
}
_potions = l;
_plugin.getLogger().info("load de " + _name);
_plugin.getLogger().info("Arena loading [" + _name + "]...");
return true;
}
@ -113,7 +113,7 @@ public class TArena extends Arena {
config.save(new File(_plugin.getDataFolder(), "/arenas/" + _name + ".yml"));
}
catch (IOException e) {
_plugin.getLogger().warning("save default de " + _name + " impossible !");
_plugin.getLogger().warning("Save default of " + _name + " impossible!");
disable();
}
return true;
@ -122,7 +122,7 @@ public class TArena extends Arena {
@Override
public Boolean saveConfig() {
YamlConfiguration config = YamlConfiguration.loadConfiguration((File)new File(_plugin.getDataFolder(), "/arenas/" + _name + ".yml"));
_plugin.getLogger().info("save de " + _name);
_plugin.getLogger().info("Save of " + _name + " ...");
config.set("Version", Quake._version);
config.set("Name", _name);
config.set("Type", "Team");
@ -161,7 +161,7 @@ public class TArena extends Arena {
config.save(new File(_plugin.getDataFolder(), "/arenas/" + _name + ".yml"));
_plugin.saveConfig();
} catch (IOException e) {
_plugin.getLogger().warning("save de " + _name + "impossible !");
_plugin.getLogger().warning("Save of " + _name + "impossible!");
disable();
return false;
}
@ -461,6 +461,29 @@ public class TArena extends Arena {
return 0;
}
@Override
public List<String> getSpawnIndexList(String team) {
List<String> list = new ArrayList();
List<Location> spawns;
if (team.equalsIgnoreCase("Blue")) {
spawns= _spawns_B;
} else {
if (team.equalsIgnoreCase("Red")) {
spawns= _spawns_B;
} else {
return null;
}
}
String format= "%0" + String.valueOf(spawns.size()).length() + "d";
for (int i = 0; i < spawns.size(); i++) {
list.add(String.format( format, i));
}
return(list);
}
public void win(ATeam team) {
_finished = true;
nbroadcast(ChatColor.GOLD + "#" + ChatColor.GRAY + "--------------------" + ChatColor.GOLD + "#");

View File

@ -1,6 +1,7 @@
package com.Geekpower14.Quake.Commands;
import com.Geekpower14.Quake.Quake;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
@ -37,8 +38,8 @@ implements BasicCommand {
}
@Override
public List<String> getCompletionList(String[] args) {
List<String> list = null;
public List<String> getCompletionList(Player player, String[] args) {
List<String> list = new ArrayList();
return list;
}

View File

@ -64,16 +64,19 @@ public class AddSpawnCommand implements BasicCommand {
}
@Override
public List<String> getCompletionList(String[] args) {
List<String> list = null;
public List<String> getCompletionList(Player player, String[] args) {
List<String> list;
if( args.length <= 2) {
if( args.length == 2) {
list = _plugin._am.getArenaNameList();
} else {
list = new ArrayList();
list.add(" ");
list.add("TEAM");
Arena arena = _plugin._am.getArenabyName(args[1]);
if ( (arena != null) && (arena instanceof TArena)) {
list.add("Blue");
list.add("Red");
}
}
return list;

View File

@ -16,6 +16,6 @@ public interface BasicCommand {
public String help(Player var1);
public List<String> getCompletionList(String[] args);
public List<String> getCompletionList(Player player, String[] args);
}

View File

@ -4,6 +4,7 @@ import com.Geekpower14.Quake.Arena.Arena;
import com.Geekpower14.Quake.Arena.SArena;
import com.Geekpower14.Quake.Arena.TArena;
import com.Geekpower14.Quake.Quake;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@ -55,8 +56,19 @@ public class ChangeTeamCommand implements BasicCommand {
}
@Override
public List<String> getCompletionList(String[] args) {
List<String> list = null;
public List<String> getCompletionList(Player player, String[] args) {
List<String> list = new ArrayList();
Arena arena = _plugin._am.getArenabyPlayer(player);
if( ( arena != null) && ( arena instanceof TArena)) {
TArena ta = (TArena)arena;
if( ta.getTeam(player).getName() == "Red") {
list.add("Blue");
} else {
list.add("Red");
}
}
return list;
}

View File

@ -50,12 +50,10 @@ public class CreateCommand implements BasicCommand {
}
@Override
public List<String> getCompletionList(String[] args) {
List<String> list = null;
public List<String> getCompletionList(Player player, String[] args) {
List<String> list = new ArrayList();
if( args.length == 3) {
list = new ArrayList();
list.add("Solo");
list.add("Team");
}

View File

@ -2,6 +2,7 @@ package com.Geekpower14.Quake.Commands;
import com.Geekpower14.Quake.Arena.Arena;
import com.Geekpower14.Quake.Quake;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@ -65,11 +66,13 @@ public class JoinCommand implements BasicCommand {
}
@Override
public List<String> getCompletionList(String[] args) {
List<String> list = null;
public List<String> getCompletionList(Player player, String[] args) {
List<String> list;
if( args.length <= 2) {
list = _plugin._am.getArenaNameList();
} else {
list = new ArrayList();
}
return list;

View File

@ -2,6 +2,7 @@ package com.Geekpower14.Quake.Commands;
import com.Geekpower14.Quake.Arena.Arena;
import com.Geekpower14.Quake.Quake;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
@ -41,8 +42,8 @@ public class LeaveCommand implements BasicCommand {
}
@Override
public List<String> getCompletionList(String[] args) {
List<String> list = null;
public List<String> getCompletionList(Player player, String[] args) {
List<String> list = new ArrayList();
return list;
}

View File

@ -84,11 +84,10 @@ public class MoneyCommand implements BasicCommand {
}
@Override
public List<String> getCompletionList(String[] args) {
List<String> list = null;
public List<String> getCompletionList(Player player, String[] args) {
List<String> list = new ArrayList();
if( args.length <= 2) {
list = new ArrayList();
list.add("set");
list.add("add");

View File

@ -100,7 +100,7 @@ public class MyCommandExecutor implements CommandExecutor {
}
}
public List<String> getCompletionList(String[] args) {
public List<String> getCompletionList(Player player, String[] args) {
List<String> list = null;
if( args.length <= 1) {
@ -110,7 +110,7 @@ public class MyCommandExecutor implements CommandExecutor {
}
else {
if(_commands.containsKey(args[0])) {
list = _commands.get(args[0]).getCompletionList(args);
list = _commands.get(args[0]).getCompletionList(player, args);
}
}

View File

@ -5,6 +5,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@ -22,11 +24,16 @@ public class MyTabCompleter implements TabCompleter
@Override
public List<String> onTabComplete (CommandSender sender, Command cmd, String label, String[] args) {
List<String> list = new ArrayList<>();
// _plugin.getLogger().info("MTC [" + cmd + "] [" + label + "] [" + args.length + "]");
_plugin.getLogger().info("MTC [" + cmd + "] [" + label + "] [" + args.length + "] [[" + Arrays.toString(args) + "]] ["+ args[args.length - 1] + "]");
if(cmd.getName().equalsIgnoreCase("quake") && args.length >= 0){
if(sender instanceof Player){
list = _plugin._ce.getCompletionList(args);
list = _plugin._ce.getCompletionList((Player)sender, args);
if( (list != null ) && (args[args.length - 1] != "")) {
Stream<String> s = list.stream().filter(name -> name.startsWith(args[args.length - 1]));
list = s.collect(Collectors.toList());
}
}
}
return list;

View File

@ -1,6 +1,7 @@
package com.Geekpower14.Quake.Commands;
import com.Geekpower14.Quake.Quake;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@ -41,8 +42,8 @@ public class ReloadCommand implements BasicCommand {
}
@Override
public List<String> getCompletionList(String[] args) {
List<String> list = null;
public List<String> getCompletionList(Player player, String[] args) {
List<String> list = new ArrayList();
return list;
}

View File

@ -2,6 +2,7 @@ package com.Geekpower14.Quake.Commands;
import com.Geekpower14.Quake.Arena.Arena;
import com.Geekpower14.Quake.Quake;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@ -54,11 +55,13 @@ public class RemoveCommand implements BasicCommand {
}
@Override
public List<String> getCompletionList(String[] args) {
List<String> list = null;
public List<String> getCompletionList(Player player, String[] args) {
List<String> list;
if( args.length <= 2) {
list = _plugin._am.getArenaNameList();
} else {
list = new ArrayList();
}
return list;

View File

@ -8,6 +8,7 @@
package com.Geekpower14.Quake.Commands;
import com.Geekpower14.Quake.Quake;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@ -50,8 +51,15 @@ public class RemoveLobbyCommand implements BasicCommand {
}
@Override
public List<String> getCompletionList(String[] args) {
List<String> list = null;
public List<String> getCompletionList(Player player, String[] args) {
List<String> list;
if( args.length <= 2) {
list = _plugin._lobby.getLobbyIndexList();
} else {
list = new ArrayList();
}
return list;
}

View File

@ -4,6 +4,8 @@ import com.Geekpower14.Quake.Arena.Arena;
import com.Geekpower14.Quake.Arena.SArena;
import com.Geekpower14.Quake.Arena.TArena;
import com.Geekpower14.Quake.Quake;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@ -27,24 +29,24 @@ public class RemoveSpawnCommand implements BasicCommand {
}
}
if (arena == null) {
player.sendMessage(ChatColor.RED + "Please type a good arena name ! !");
player.sendMessage(ChatColor.RED + "Please type a good arena name!");
return true;
}
if (args.length != 2) {
player.sendMessage(ChatColor.RED + "Please type a number !");
player.sendMessage(ChatColor.RED + "Please type a number!");
return true;
}
if (arena instanceof SArena) {
SArena sa = (SArena)arena;
sa.removespawn(args[1]);
player.sendMessage(ChatColor.GREEN + "Spawn number " + (sa._spawns.size() - 1) + " removed !");
player.sendMessage(ChatColor.GREEN + "Spawn number " + (sa._spawns.size() - 1) + " removed!");
} else if (arena instanceof TArena) {
TArena ta = (TArena)arena;
if (args.length >= 3) {
int nb = ta.removespawn(args[1], args[2]);
player.sendMessage(ChatColor.GREEN + "Spawn number " + (nb - 1) + " removed !");
player.sendMessage(ChatColor.GREEN + "Spawn number " + (nb - 1) + " removed!");
} else {
player.sendMessage(ChatColor.RED + "Please type a team name ! !");
player.sendMessage(ChatColor.RED + "Please type a team name!");
}
}
arena.saveConfig();
@ -62,19 +64,42 @@ public class RemoveSpawnCommand implements BasicCommand {
@Override
public String help(Player p) {
if (Quake.hasPermission(p, getPermission())) {
return "/quake removespawn [Arena] [Number] - Remove a spawn of the arena.";
return "/quake removespawn [Arena] [TEAM|Only for team arena] [Number] - Remove a spawn of the arena.";
}
return "";
}
@Override
public List<String> getCompletionList(String[] args) {
List<String> list = null;
public List<String> getCompletionList(Player player, String[] args) {
List<String> list;
if( args.length <= 2) {
list = _plugin._am.getArenaNameList();
}
else {
list = new ArrayList();
Arena arena = _plugin._am._ARENAS.get(args[1]);
if( arena != null) {
if (arena instanceof SArena) {
if( args.length == 3) {
list = arena.getSpawnIndexList("");
}
} else {
if( args.length == 3) {
list.add("Blue");
list.add("Red");
} else {
if( args[2].equalsIgnoreCase("Blue") || args[2].equalsIgnoreCase("Red")) {
if( args.length == 4) {
list = arena.getSpawnIndexList( args[2]);
}
}
}
}
}
}
return list;
}
}

View File

@ -9,6 +9,7 @@ package com.Geekpower14.Quake.Commands;
import com.Geekpower14.Quake.Arena.Arena;
import com.Geekpower14.Quake.Quake;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@ -57,11 +58,13 @@ public class SaveCommand implements BasicCommand {
}
@Override
public List<String> getCompletionList(String[] args) {
List<String> list = null;
public List<String> getCompletionList(Player player, String[] args) {
List<String> list;
if( args.length <= 2) {
list = _plugin._am.getArenaNameList();
} else {
list = new ArrayList();
}
return list;

View File

@ -8,6 +8,7 @@
package com.Geekpower14.Quake.Commands;
import com.Geekpower14.Quake.Quake;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@ -45,8 +46,8 @@ public class SetLobbySpawnCommand implements BasicCommand {
}
@Override
public List<String> getCompletionList(String[] args) {
List<String> list = null;
public List<String> getCompletionList(Player player, String[] args) {
List<String> list = new ArrayList();
return list;
}

View File

@ -9,6 +9,7 @@ package com.Geekpower14.Quake.Commands;
import com.Geekpower14.Quake.Arena.Arena;
import com.Geekpower14.Quake.Quake;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@ -62,11 +63,13 @@ public class SetMapCommand implements BasicCommand {
}
@Override
public List<String> getCompletionList(String[] args) {
List<String> list = null;
public List<String> getCompletionList(Player player, String[] args) {
List<String> list;
if( args.length <= 2) {
list = _plugin._am.getArenaNameList();
} else {
list = new ArrayList();
}
return list;

View File

@ -9,6 +9,7 @@ package com.Geekpower14.Quake.Commands;
import com.Geekpower14.Quake.Arena.Arena;
import com.Geekpower14.Quake.Quake;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@ -62,11 +63,13 @@ public class SetMaxCommand implements BasicCommand {
}
@Override
public List<String> getCompletionList(String[] args) {
List<String> list = null;
public List<String> getCompletionList(Player player, String[] args) {
List<String> list;
if( args.length <= 2) {
list = _plugin._am.getArenaNameList();
} else {
list = new ArrayList();
}
return list;

View File

@ -9,6 +9,7 @@ package com.Geekpower14.Quake.Commands;
import com.Geekpower14.Quake.Arena.Arena;
import com.Geekpower14.Quake.Quake;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@ -62,11 +63,13 @@ public class SetMinCommand implements BasicCommand {
}
@Override
public List<String> getCompletionList(String[] args) {
List<String> list = null;
public List<String> getCompletionList(Player player, String[] args) {
List<String> list;
if( args.length <= 2) {
list = _plugin._am.getArenaNameList();
} else {
list = new ArrayList();
}
return list;

View File

@ -7,6 +7,7 @@
package com.Geekpower14.Quake.Commands;
import com.Geekpower14.Quake.Quake;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
@ -42,8 +43,8 @@ public class ShopCommand implements BasicCommand {
}
@Override
public List<String> getCompletionList(String[] args) {
List<String> list = null;
public List<String> getCompletionList(Player player, String[] args) {
List<String> list = new ArrayList();
return list;
}

View File

@ -9,6 +9,7 @@ package com.Geekpower14.Quake.Commands;
import com.Geekpower14.Quake.Arena.Arena;
import com.Geekpower14.Quake.Quake;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@ -57,11 +58,13 @@ public class StartCommand implements BasicCommand {
}
@Override
public List<String> getCompletionList(String[] args) {
List<String> list = null;
public List<String> getCompletionList(Player player, String[] args) {
List<String> list;
if( args.length <= 2) {
list = _plugin._am.getArenaNameList();
} else {
list = new ArrayList();
}
return list;

View File

@ -9,6 +9,7 @@ package com.Geekpower14.Quake.Commands;
import com.Geekpower14.Quake.Arena.Arena;
import com.Geekpower14.Quake.Quake;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@ -59,13 +60,15 @@ public class StopCommand implements BasicCommand {
}
@Override
public List<String> getCompletionList(String[] args) {
List<String> list = null;
public List<String> getCompletionList(Player player, String[] args) {
List<String> list;
if( args.length <= 2) {
list = _plugin._am.getArenaNameList();
} else {
list = new ArrayList();
}
return list;
}
}

View File

@ -9,6 +9,7 @@ package com.Geekpower14.Quake.Commands;
import com.Geekpower14.Quake.Arena.APlayer;
import com.Geekpower14.Quake.Arena.Arena;
import com.Geekpower14.Quake.Quake;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
@ -53,8 +54,8 @@ public class UtilsCommand implements BasicCommand {
}
@Override
public List<String> getCompletionList(String[] args) {
List<String> list = null;
public List<String> getCompletionList(Player player, String[] args) {
List<String> list = new ArrayList();
return list;
}

View File

@ -53,7 +53,7 @@ public class LobbyManager {
_locmax.put("lobby" + i, str2loc(nom));
++i;
}
_plugin.getLogger().info("load des Lobby ");
_plugin.getLogger().info("Lobby loading (" + nombre + ")...");
}
public void saveconfig() {
@ -81,7 +81,7 @@ public class LobbyManager {
} catch (IOException l) {
// empty catch block
}
_plugin.getLogger().info("save des Lobby ");
_plugin.getLogger().info("Lobby saving...");
}
public Location str2loc(String loc) {
@ -133,6 +133,13 @@ public class LobbyManager {
return false;
}
public List getLobbyIndexList() {
List<String> list = new ArrayList();
return new ArrayList<>(_locmin.keySet());
}
public Boolean initsign() {
int index = 0;
int i = 0;

View File

@ -9,5 +9,5 @@ website: https://obsidia.rx3.net
commands:
quake:
description: Quake command
usage: /quake
usage: /quake
aliases: [q]