Re-allow joining from spectator areas.

Commit 924a419b47 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.
This commit is contained in:
Andreas Troelsen 2018-08-24 19:27:21 +02:00
parent 934eb2d8cc
commit 266104d0a1
2 changed files with 22 additions and 5 deletions

View File

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

View File

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