diff --git a/changelog.md b/changelog.md index afebb9e..2591ae7 100644 --- a/changelog.md +++ b/changelog.md @@ -14,6 +14,7 @@ These changes will (most likely) be included in the next version. ### Added - New monster variant `angry-bees` can be used to spawn angry bees. - Pet names are now per-class configurable via the optional `pet-name` property, which defaults to `'s pet` (the `` variable is also supported). +- New per-arena setting `auto-leave-on-end` can be used to automatically "kick" spectators when the current session ends. - (API) MobArena's internal command handler now supports registering pre-instantiated subcommand instances. This should make it easier for extensions to avoid the Singleton anti-pattern for command dependencies. - (API) MobArena now fires MobArenaPreReloadEvent and MobArenaReloadEvent before and after, respectively, reloading its config-file. This should allow extensions and other plugins to better respond to configuration changes. diff --git a/src/main/java/com/garbagemule/MobArena/ArenaImpl.java b/src/main/java/com/garbagemule/MobArena/ArenaImpl.java index 34d9e98..587002d 100644 --- a/src/main/java/com/garbagemule/MobArena/ArenaImpl.java +++ b/src/main/java/com/garbagemule/MobArena/ArenaImpl.java @@ -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 diff --git a/src/main/resources/res/settings.yml b/src/main/resources/res/settings.yml index e2612d9..d2c12d3 100644 --- a/src/main/resources/res/settings.yml +++ b/src/main/resources/res/settings.yml @@ -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