Add per-arena setting auto-leave-on-end.

Introduces a new arena setting to force spectators to leave the arena
when the current session ends. If set to `true`, it "overrides" the
behavior of `spectate-on-death: true` when players respawn, such that
they only become spectators if there is an active arena session.

The respawn behavior technically means that it is possible for a player
to begin spectating "the next session" if a new session begins between
them dying and clicking Respawn on the death screen. Ideally, we would
want the player to auto-leave, because the session _they_ participated
in ended, but we don't have a concept of "previous sessions", so this
quirky behavior will have to do.

Closes #682
This commit is contained in:
Andreas Troelsen
2021-08-08 00:56:41 +02:00
parent 52226fa1c9
commit c143cc81c9
3 changed files with 19 additions and 4 deletions
@@ -643,6 +643,11 @@ public class ArenaImpl implements Arena
// Restore enabled status.
enabled = en;
// Auto-leave
if (settings.getBoolean("auto-leave-on-end", false)) {
specPlayers.forEach(this::playerLeave);
}
return true;
}
@@ -903,11 +908,19 @@ public class ArenaImpl implements Arena
specPlayers.add(p);
if (settings.getBoolean("spectate-on-death", true)) {
messenger.tell(p, Msg.SPEC_PLAYER_SPECTATE);
} else {
plugin.getServer().getScheduler()
.scheduleSyncDelayedTask(plugin, () -> playerLeave(p));
// At this point, we know that we want players to become
// spectators when they respawn, but if we also want them
// to auto-leave on arena end, we first need to make sure
// the arena is running. If not, the session has probably
// ended, so we fall through to schedule an auto-leave.
if (!settings.getBoolean("auto-leave-on-end", false) || running) {
messenger.tell(p, Msg.SPEC_PLAYER_SPECTATE);
return;
}
}
plugin.getServer().getScheduler()
.scheduleSyncDelayedTask(plugin, () -> playerLeave(p));
}
@Override
+1
View File
@@ -15,6 +15,7 @@ pvp-enabled: false
monster-infight: false
allow-teleporting: false
spectate-on-death: true
auto-leave-on-end: false
share-items-in-arena: true
min-players: 0
max-players: 0