From c546641c7ba384256880fbe42ffdc7e11a676ffe Mon Sep 17 00:00:00 2001 From: Andreas Troelsen Date: Tue, 28 Aug 2018 21:30:45 +0200 Subject: [PATCH] Start the join-interrupt-timer from the spectator area. Following the changes in 266104d0a1ad319da9ded75a17c89b1581ba3d8d, this commit gathers the leave-then-join logic and handles it in one fell swoop when joining from the spectator area. This means that the timer will start, and when it runs out, the player leaves the current arena (if any), and then joins. There should be no issues with overlapping timers or anything like that, since the lookup happens when the time is up, not before the timer is started. --- .../MobArena/commands/user/JoinCommand.java | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/garbagemule/MobArena/commands/user/JoinCommand.java b/src/main/java/com/garbagemule/MobArena/commands/user/JoinCommand.java index 2c9ae5c..eac4d0c 100644 --- a/src/main/java/com/garbagemule/MobArena/commands/user/JoinCommand.java +++ b/src/main/java/com/garbagemule/MobArena/commands/user/JoinCommand.java @@ -29,18 +29,6 @@ public class JoinCommand implements Command // Unwrap the sender, grab the argument, if any. Player p = Commands.unwrap(sender); String arg1 = (args.length > 0 ? args[0] : null); - - // If the player is currently in an arena, leave it first - Arena current = am.getArenaWithPlayer(p); - if (current != null) { - if (current.inArena(p) || current.inLobby(p)) { - current.getMessenger().tell(p, Msg.JOIN_ALREADY_PLAYING); - return true; - } - if (!current.playerLeave(p)) { - return true; - } - } // Run some rough sanity checks, and grab the arena to join. Arena toArena = Commands.getArenaToJoinOrSpec(am, p, arg1); @@ -51,14 +39,14 @@ public class JoinCommand implements Command // Join the arena! int seconds = toArena.getSettings().getInt("join-interrupt-timer", 0); if (seconds > 0) { - boolean started = am.getJoinInterruptTimer().start(p, toArena, seconds, () -> tryJoin(p, toArena)); + boolean started = am.getJoinInterruptTimer().start(p, toArena, seconds, () -> tryJoin(am, p, toArena)); if (started) { toArena.getMessenger().tell(p, Msg.JOIN_AFTER_DELAY, String.valueOf(seconds)); } else { toArena.getMessenger().tell(p, Msg.JOIN_ALREADY_PLAYING); } } else { - tryJoin(p, toArena); + tryJoin(am, p, toArena); } return true; } @@ -73,7 +61,18 @@ public class JoinCommand implements Command return arena.canJoin(player); } - private void tryJoin(Player player, Arena arena) { + private void tryJoin(ArenaMaster am, Player player, Arena arena) { + // If the player is currently in an arena, leave it first + Arena current = am.getArenaWithPlayer(player); + if (current != null) { + if (current.inArena(player) || current.inLobby(player)) { + current.getMessenger().tell(player, Msg.JOIN_ALREADY_PLAYING); + return; + } + if (!current.playerLeave(player)) { + return; + } + } if (canJoin(player, arena)) { arena.playerJoin(player, player.getLocation()); }