From 266104d0a1ad319da9ded75a17c89b1581ba3d8d Mon Sep 17 00:00:00 2001 From: Andreas Troelsen Date: Fri, 24 Aug 2018 19:27:21 +0200 Subject: [PATCH] Re-allow joining from spectator areas. Commit 924a419b47a90fb1e3c9e0ae94e0f1ea24da364e made it impossible to join an arena from a spectator area because the playerLeave method call in JoinCommand was removed. The call is re-introduced in this commit along with similar logic in InvokesSignAction. This means that a spectating player can now join arenas as if they weren't spectating, rather than having to first leave the arena they are spectating. --- .../MobArena/commands/user/JoinCommand.java | 17 ++++++++++++----- .../MobArena/signs/InvokesSignAction.java | 10 ++++++++++ 2 files changed, 22 insertions(+), 5 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 6dfec9b..2c9ae5c 100644 --- a/src/main/java/com/garbagemule/MobArena/commands/user/JoinCommand.java +++ b/src/main/java/com/garbagemule/MobArena/commands/user/JoinCommand.java @@ -30,6 +30,18 @@ public class JoinCommand implements Command 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); if (toArena == null || !canJoin(p, toArena)) { @@ -58,11 +70,6 @@ public class JoinCommand implements Command plugin.getGlobalMessenger().tell(player, Msg.JOIN_ALREADY_PLAYING); return false; } - Arena current = am.getArenaWithPlayer(player); - if (current != null) { - current.getMessenger().tell(player, Msg.JOIN_ALREADY_PLAYING); - return false; - } return arena.canJoin(player); } diff --git a/src/main/java/com/garbagemule/MobArena/signs/InvokesSignAction.java b/src/main/java/com/garbagemule/MobArena/signs/InvokesSignAction.java index e6c89c5..d564362 100644 --- a/src/main/java/com/garbagemule/MobArena/signs/InvokesSignAction.java +++ b/src/main/java/com/garbagemule/MobArena/signs/InvokesSignAction.java @@ -20,6 +20,16 @@ class InvokesSignAction { void invoke(ArenaSign sign, Player player) { if (sign.type.equals("join")) { + Arena current = arenaMaster.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; + } + } withArena(sign, player, arena -> { if (arena.canJoin(player)) { // Join message is sent in playerJoin