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:
@@ -30,6 +30,18 @@ public class JoinCommand implements Command
|
|||||||
Player p = Commands.unwrap(sender);
|
Player p = Commands.unwrap(sender);
|
||||||
String arg1 = (args.length > 0 ? args[0] : null);
|
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.
|
// Run some rough sanity checks, and grab the arena to join.
|
||||||
Arena toArena = Commands.getArenaToJoinOrSpec(am, p, arg1);
|
Arena toArena = Commands.getArenaToJoinOrSpec(am, p, arg1);
|
||||||
if (toArena == null || !canJoin(p, toArena)) {
|
if (toArena == null || !canJoin(p, toArena)) {
|
||||||
@@ -58,11 +70,6 @@ public class JoinCommand implements Command
|
|||||||
plugin.getGlobalMessenger().tell(player, Msg.JOIN_ALREADY_PLAYING);
|
plugin.getGlobalMessenger().tell(player, Msg.JOIN_ALREADY_PLAYING);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Arena current = am.getArenaWithPlayer(player);
|
|
||||||
if (current != null) {
|
|
||||||
current.getMessenger().tell(player, Msg.JOIN_ALREADY_PLAYING);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return arena.canJoin(player);
|
return arena.canJoin(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,16 @@ class InvokesSignAction {
|
|||||||
|
|
||||||
void invoke(ArenaSign sign, Player player) {
|
void invoke(ArenaSign sign, Player player) {
|
||||||
if (sign.type.equals("join")) {
|
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 -> {
|
withArena(sign, player, arena -> {
|
||||||
if (arena.canJoin(player)) {
|
if (arena.canJoin(player)) {
|
||||||
// Join message is sent in playerJoin
|
// Join message is sent in playerJoin
|
||||||
|
|||||||
Reference in New Issue
Block a user