Improve command missing arg checking

Fix join command check when a player is allready in an arena
This commit is contained in:
Arnaud G. GIBERT 2021-04-24 12:56:45 +02:00
parent 0506ebc2c2
commit 4a9b80276d
10 changed files with 80 additions and 54 deletions

View File

@ -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 ( 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;

View File

@ -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])) {
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"));
}

View File

@ -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 ( 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;

View File

@ -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 ( 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;

View File

@ -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 ( 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;

View File

@ -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 ( 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;

View File

@ -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 ( 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;

View File

@ -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 ( 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;

View File

@ -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])) {
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;

View File

@ -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])) {
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 ! !");