From 4a9b80276d805bb96acc4af9d4b8016b717a5c7e Mon Sep 17 00:00:00 2001 From: "Arnaud G. GIBERT" Date: Sat, 24 Apr 2021 12:56:45 +0200 Subject: [PATCH] Improve command missing arg checking Fix join command check when a player is allready in an arena --- .../Quake/Commands/AddSpawnCommand.java | 12 ++++++---- .../Quake/Commands/JoinCommand.java | 24 +++++++++++++------ .../Quake/Commands/RemoveCommand.java | 12 ++++++---- .../Quake/Commands/RemoveSpawnCommand.java | 12 ++++++---- .../Quake/Commands/SaveCommand.java | 12 ++++++---- .../Quake/Commands/SetMapCommand.java | 12 ++++++---- .../Quake/Commands/SetMaxCommand.java | 12 ++++++---- .../Quake/Commands/SetMinCommand.java | 12 ++++++---- .../Quake/Commands/StartCommand.java | 12 ++++++---- .../Quake/Commands/StopCommand.java | 14 +++++------ 10 files changed, 80 insertions(+), 54 deletions(-) diff --git a/src/com/Geekpower14/Quake/Commands/AddSpawnCommand.java b/src/com/Geekpower14/Quake/Commands/AddSpawnCommand.java index d5a86c9..51d3cd3 100644 --- a/src/com/Geekpower14/Quake/Commands/AddSpawnCommand.java +++ b/src/com/Geekpower14/Quake/Commands/AddSpawnCommand.java @@ -18,11 +18,13 @@ public class AddSpawnCommand implements BasicCommand { public boolean onCommand(Player player, String[] args) { if (Quake.hasPermission(player, getPermission())) { Arena arena = null; - if (_plugin._am.exist(args[0])) { - arena = _plugin._am.getArenabyName(args[0]); - } else if (args[0].matches("^\\d*$")) { - arena = _plugin._am.getArenabyID(Integer.valueOf(args[0])); - } + if ( args.length > 0) { + if (_plugin._am.exist(args[0])) { + arena = _plugin._am.getArenabyName(args[0]); + } else if (args[0].matches("^\\d*$")) { + arena = _plugin._am.getArenabyID(Integer.valueOf(args[0])); + } + } if (arena == null) { player.sendMessage(ChatColor.RED + "Please type a good arena name ! !"); return true; diff --git a/src/com/Geekpower14/Quake/Commands/JoinCommand.java b/src/com/Geekpower14/Quake/Commands/JoinCommand.java index f0e27e1..d2dfc02 100644 --- a/src/com/Geekpower14/Quake/Commands/JoinCommand.java +++ b/src/com/Geekpower14/Quake/Commands/JoinCommand.java @@ -16,13 +16,15 @@ public class JoinCommand implements BasicCommand { public boolean onCommand(Player player, String[] args) { if (Quake.hasPermission(player, getPermission())) { Arena arena = null; - if (_plugin._am.exist(args[0])) { - arena = _plugin._am.getArenabyName(args[0]); - } else if (args[0].matches("^\\d*$")) { - arena = _plugin._am.getArenabyID(Integer.valueOf(args[0])); - } + if ( args.length > 0) { + if ( _plugin._am.exist(args[0])) { + arena = _plugin._am.getArenabyName(args[0]); + } else if (args[0].matches("^\\d*$")) { + arena = _plugin._am.getArenabyID(Integer.valueOf(args[0])); + } + } 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 != 1) { @@ -30,10 +32,18 @@ public class JoinCommand implements BasicCommand { return true; } if (arena.isingame(player)) { - player.sendMessage(ChatColor.RED + "You are already in game !"); + player.sendMessage(ChatColor.RED + "You are already in this game !"); return true; } + else { + Arena arena_tmp = _plugin._am.getArenabyPlayer(player); + if ( arena_tmp != null ) { + player.sendMessage(ChatColor.RED + "You are already in the " + arena_tmp._name + " arena !"); + return true; + } + } arena.joinArena(player); + } else { player.sendMessage(_plugin._trad.get("NoPermission")); } diff --git a/src/com/Geekpower14/Quake/Commands/RemoveCommand.java b/src/com/Geekpower14/Quake/Commands/RemoveCommand.java index 19c557b..d9f1ee5 100644 --- a/src/com/Geekpower14/Quake/Commands/RemoveCommand.java +++ b/src/com/Geekpower14/Quake/Commands/RemoveCommand.java @@ -16,11 +16,13 @@ public class RemoveCommand implements BasicCommand { public boolean onCommand(Player player, String[] args) { if (Quake.hasPermission(player, getPermission())) { Arena arena = null; - if (_plugin._am.exist(args[0])) { - arena = _plugin._am.getArenabyName(args[0]); - } else if (args[0].matches("^\\d*$")) { - arena = _plugin._am.getArenabyID(Integer.valueOf(args[0])); - } + if ( args.length > 0) { + if (_plugin._am.exist(args[0])) { + arena = _plugin._am.getArenabyName(args[0]); + } else if (args[0].matches("^\\d*$")) { + arena = _plugin._am.getArenabyID(Integer.valueOf(args[0])); + } + } if (arena == null) { player.sendMessage(ChatColor.RED + "Please type a good arena name ! !"); return true; diff --git a/src/com/Geekpower14/Quake/Commands/RemoveSpawnCommand.java b/src/com/Geekpower14/Quake/Commands/RemoveSpawnCommand.java index 1112b5a..c0db14e 100644 --- a/src/com/Geekpower14/Quake/Commands/RemoveSpawnCommand.java +++ b/src/com/Geekpower14/Quake/Commands/RemoveSpawnCommand.java @@ -18,11 +18,13 @@ public class RemoveSpawnCommand implements BasicCommand { public boolean onCommand(Player player, String[] args) { if (Quake.hasPermission(player, getPermission())) { Arena arena = null; - if (_plugin._am.exist(args[0])) { - arena = _plugin._am.getArenabyName(args[0]); - } else if (args[0].matches("^\\d*$")) { - arena = _plugin._am.getArenabyID(Integer.valueOf(args[0])); - } + if ( args.length > 0) { + if (_plugin._am.exist(args[0])) { + arena = _plugin._am.getArenabyName(args[0]); + } else if (args[0].matches("^\\d*$")) { + arena = _plugin._am.getArenabyID(Integer.valueOf(args[0])); + } + } if (arena == null) { player.sendMessage(ChatColor.RED + "Please type a good arena name ! !"); return true; diff --git a/src/com/Geekpower14/Quake/Commands/SaveCommand.java b/src/com/Geekpower14/Quake/Commands/SaveCommand.java index 02ad375..51c6aa0 100644 --- a/src/com/Geekpower14/Quake/Commands/SaveCommand.java +++ b/src/com/Geekpower14/Quake/Commands/SaveCommand.java @@ -23,11 +23,13 @@ public class SaveCommand implements BasicCommand { public boolean onCommand(Player player, String[] args) { if (Quake.hasPermission(player, getPermission())) { Arena arena = null; - if (_plugin._am.exist(args[0])) { - arena = _plugin._am.getArenabyName(args[0]); - } else if (args[0].matches("^\\d*$")) { - arena = _plugin._am.getArenabyID(Integer.parseInt(args[0])); - } + if ( args.length > 0) { + if (_plugin._am.exist(args[0])) { + arena = _plugin._am.getArenabyName(args[0]); + } else if (args[0].matches("^\\d*$")) { + arena = _plugin._am.getArenabyID(Integer.parseInt(args[0])); + } + } if (arena == null) { player.sendMessage(ChatColor.RED + "Please type a good arena name ! !"); return true; diff --git a/src/com/Geekpower14/Quake/Commands/SetMapCommand.java b/src/com/Geekpower14/Quake/Commands/SetMapCommand.java index a4810b1..c95288b 100644 --- a/src/com/Geekpower14/Quake/Commands/SetMapCommand.java +++ b/src/com/Geekpower14/Quake/Commands/SetMapCommand.java @@ -23,11 +23,13 @@ public class SetMapCommand implements BasicCommand { public boolean onCommand(Player player, String[] args) { if (Quake.hasPermission(player, getPermission())) { Arena arena = null; - if (_plugin._am.exist(args[0])) { - arena = _plugin._am.getArenabyName(args[0]); - } else if (args[0].matches("^\\d*$")) { - arena = _plugin._am.getArenabyID(Integer.parseInt(args[0])); - } + if ( args.length > 0) { + if (_plugin._am.exist(args[0])) { + arena = _plugin._am.getArenabyName(args[0]); + } else if (args[0].matches("^\\d*$")) { + arena = _plugin._am.getArenabyID(Integer.parseInt(args[0])); + } + } if (arena == null) { player.sendMessage(ChatColor.RED + "Please type a good arena name ! !"); return true; diff --git a/src/com/Geekpower14/Quake/Commands/SetMaxCommand.java b/src/com/Geekpower14/Quake/Commands/SetMaxCommand.java index 6bd605f..a617b5d 100644 --- a/src/com/Geekpower14/Quake/Commands/SetMaxCommand.java +++ b/src/com/Geekpower14/Quake/Commands/SetMaxCommand.java @@ -23,11 +23,13 @@ public class SetMaxCommand implements BasicCommand { public boolean onCommand(Player player, String[] args) { if (Quake.hasPermission(player, getPermission())) { Arena arena = null; - if (_plugin._am.exist(args[0])) { - arena = _plugin._am.getArenabyName(args[0]); - } else if (args[0].matches("^\\d*$")) { - arena = _plugin._am.getArenabyID(Integer.parseInt(args[0])); - } + if ( args.length > 0) { + if (_plugin._am.exist(args[0])) { + arena = _plugin._am.getArenabyName(args[0]); + } else if (args[0].matches("^\\d*$")) { + arena = _plugin._am.getArenabyID(Integer.parseInt(args[0])); + } + } if (arena == null) { player.sendMessage(ChatColor.RED + "Please type a good arena name ! !"); return true; diff --git a/src/com/Geekpower14/Quake/Commands/SetMinCommand.java b/src/com/Geekpower14/Quake/Commands/SetMinCommand.java index b4b88b9..299dd5f 100644 --- a/src/com/Geekpower14/Quake/Commands/SetMinCommand.java +++ b/src/com/Geekpower14/Quake/Commands/SetMinCommand.java @@ -23,11 +23,13 @@ public class SetMinCommand implements BasicCommand { public boolean onCommand(Player player, String[] args) { if (Quake.hasPermission(player, getPermission())) { Arena arena = null; - if (_plugin._am.exist(args[0])) { - arena = _plugin._am.getArenabyName(args[0]); - } else if (args[0].matches("^\\d*$")) { - arena = _plugin._am.getArenabyID(Integer.valueOf(args[0])); - } + if ( args.length > 0) { + if (_plugin._am.exist(args[0])) { + arena = _plugin._am.getArenabyName(args[0]); + } else if (args[0].matches("^\\d*$")) { + arena = _plugin._am.getArenabyID(Integer.valueOf(args[0])); + } + } if (arena == null) { player.sendMessage(ChatColor.RED + "Please type a good arena name ! !"); return true; diff --git a/src/com/Geekpower14/Quake/Commands/StartCommand.java b/src/com/Geekpower14/Quake/Commands/StartCommand.java index 547d2cb..3120687 100644 --- a/src/com/Geekpower14/Quake/Commands/StartCommand.java +++ b/src/com/Geekpower14/Quake/Commands/StartCommand.java @@ -23,11 +23,13 @@ public class StartCommand implements BasicCommand { public boolean onCommand(Player player, String[] args) { if(Quake.hasPermission(player, getPermission())) { Arena arena = null; - if (_plugin._am.exist(args[0])) { - arena = _plugin._am.getArenabyName(args[0]); - } else if (args[0].matches("^\\d*$")) { - arena = _plugin._am.getArenabyID(Integer.parseInt(args[0])); - } + if ( args.length > 0) { + if ( _plugin._am.exist(args[0])) { + arena = _plugin._am.getArenabyName(args[0]); + } else if (args[0].matches("^\\d*$")) { + arena = _plugin._am.getArenabyID(Integer.parseInt(args[0])); + } + } if (arena == null) { player.sendMessage(ChatColor.RED + "Please type a good arena name ! !"); return true; diff --git a/src/com/Geekpower14/Quake/Commands/StopCommand.java b/src/com/Geekpower14/Quake/Commands/StopCommand.java index 36beba5..8a0ca91 100644 --- a/src/com/Geekpower14/Quake/Commands/StopCommand.java +++ b/src/com/Geekpower14/Quake/Commands/StopCommand.java @@ -23,13 +23,13 @@ public class StopCommand implements BasicCommand { public boolean onCommand(Player player, String[] args) { if (Quake.hasPermission(player, getPermission())) { Arena arena = null; - if(args.length == 0) { - - } else if (_plugin._am.exist(args[0])) { - arena = _plugin._am.getArenabyName(args[0]); - } else if (args[0].matches("^\\d*$")) { - arena = _plugin._am.getArenabyID(Integer.parseInt(args[0])); - } + if ( args.length > 0) { + if (_plugin._am.exist(args[0])) { + arena = _plugin._am.getArenabyName(args[0]); + } else if (args[0].matches("^\\d*$")) { + arena = _plugin._am.getArenabyID(Integer.parseInt(args[0])); + } + } if (arena == null) { player.sendMessage(ChatColor.RED + "Please type a good arena name ! !");