Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.11.4

- **Disabling Posse while the server runs now shuts the server down** (D401). A disabled plugin's listeners stop working, so home worlds, circles, chat limits and the join pause would all lift with players still online. Now, unless the server is already stopping, Posse logs "Posse was disabled while the server was running, so its safety rules no longer apply. Shutting the server down. Start it again to bring the rules back." and asks Paper to shut down, which saves the worlds as a normal stop does. It also disconnects everyone at once with "The server is stopping for a moment. Please come back later.", while its own listeners are still in place, because Paper's stop disables every other plugin before it disconnects anyone and chat runs on its own thread. This includes `/reload`, which disables every plugin first. A normal stop is left alone, and if the server can't say whether it's stopping, it's treated as running. If the shutdown itself fails, the log says so and asks for a manual stop. It can't help if the jar is removed, the plugin never loads, the process is killed, or another plugin unregisters Posse's listeners without disabling it.
- Tested: `./gradlew build` passes, with 275 unit tests and none skipped. Seven are new, covering the order of shutdown, disconnect and log line, a stopping server, an unreadable stopping state, a failed shutdown, a failed disconnect, a failing logger and the wording. `disable-guard.js` is a new bot suite. It uses the test helper's new `/mt disable` to disable Posse on a running server, once with two players online and once while Posse is paused on a broken config. It checks the log line, that the server exits by itself, that each player is disconnected with Posse's own message, that a normal stop says nothing, and that the server starts again and lets players in. It passed 21 of 21 checks on Paper 26.1.2 (build 74), 26.2 (build 135) and 26.3 (build 273). The full `suite.js`, which covers startup, pause and joins, passed 87 of 87 on each of those three, with 3 skipped: sign text and anvil renames need a real client, and graves need a LanternGraves jar. On 26.3 build 273, `suite.js`'s leave line check passes again (it failed on build 272); `presence-messages.js` wasn't rerun.
- **Not tested:** `/reload` itself (the same `onDisable` runs, but no bot drives it), an error that makes Paper disable the plugin, a failed shutdown, and disabling from a thread other than the main one, where Posse leaves disconnecting to the server's stop. No real game client has seen this version.

## 0.11.3

- **Read this before upgrading with home worlds on: an adult circle with no entry becomes restricted until it gets `unlimited: true`.** Before, a player in any circle without an entry was never moved.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Otherwise they can't. A world group is a world with its Nether and End (`surviva
- If another plugin cancels that disconnect, Posse tries again twice a second until the player has gone. Until then they are held: hidden from everyone, with everyone hidden from them, and unable to move, teleport, chat, send messages or commands, write, use or change blocks, take or deal damage through the usual events, drop or pick up items, or use inventories. They reach nobody.
- Only the moved player gets a short line, such as "Welcome! You're in the lobby." (set per entry with `message`). Nobody else is told.

It is off unless the `home-worlds` section is there with something in it, and it needs at least one circle. A section whose only entries can't be used stays on. A mistake in a circle's own entry makes that entry add nothing, with a warning. A circle name that isn't in `circles`, a section or `no-circle` entry that can't be read, and a bad `lobby-world` are config errors, so nothing half-applies. `no-circle` always needs `worlds`. `unlimited` there is ignored with a warning. Not covered: a pending player's screen still shows the world around them, with its signs, builds and animals. The hold works through the server's events, so anything another plugin does for a player without those events isn't stopped. A plugin that also gets in after Posse's last look at a teleport can let it through; the check after the world change then catches it, just after it happens. **If Posse is disabled or removed while the server runs, none of these rules apply.** Posse also can't see a world that another plugin loads after the player joins. A respawn can't be cancelled. If a player has to be disconnected while respawning, Posse points the respawn back at the world they died in when their group may be there. If neither world is allowed, the server may save them where it respawned them. They're held until they leave and checked again when they next join. If the config can't be read at startup, Posse can't tell who is in which circle, so it refuses joins (see below).
It is off unless the `home-worlds` section is there with something in it, and it needs at least one circle. A section whose only entries can't be used stays on. A mistake in a circle's own entry makes that entry add nothing, with a warning. A circle name that isn't in `circles`, a section or `no-circle` entry that can't be read, and a bad `lobby-world` are config errors, so nothing half-applies. `no-circle` always needs `worlds`. `unlimited` there is ignored with a warning. Not covered: a pending player's screen still shows the world around them, with its signs, builds and animals. The hold works through the server's events, so anything another plugin does for a player without those events isn't stopped. A plugin that also gets in after Posse's last look at a teleport can let it through; the check after the world change then catches it, just after it happens. **If Posse is disabled while the server runs, it shuts the server down**, unless the server is already stopping, so nobody plays without these rules. It disconnects everyone straight away with "The server is stopping for a moment. Please come back later." That includes `/reload`. If the jar is removed, the plugin never loads, the process is killed, or another plugin removes Posse's listeners without disabling it, none of these rules apply. Posse also can't see a world that another plugin loads after the player joins. A respawn can't be cancelled. If a player has to be disconnected while respawning, Posse points the respawn back at the world they died in when their group may be there. If neither world is allowed, the server may save them where it respawned them. They're held until they leave and checked again when they next join. If the config can't be read at startup, Posse can't tell who is in which circle, so it refuses joins (see below).

**Book authors.** A written book shows its author only to the author, players who share a circle with them, and players with `posse.bypass`. Everyone else sees "Unknown" (`book-authors.shown-as`), and a title that holds the author's name shows `****` for it. That includes the BetonQuest quest journal, which carries its owner's name. Same world doesn't count, only circles, so a kid and an adult standing together still don't see each other's names. It is on by default; set `book-authors.hide: false` to turn it off. With no circles set up nothing is hidden.

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "com.extantape"
version = "0.11.3"
version = "0.11.4"

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(25))
Expand Down
63 changes: 63 additions & 0 deletions src/main/java/com/extantape/posse/DisableGuard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.extantape.posse;

import java.util.function.BooleanSupplier;
import java.util.function.Consumer;

/**
* What happens when Posse is disabled (D401). A disabled plugin's listeners stop working, so every rule Posse keeps
* (home worlds, circles, chat and the join pause) would lift while players stay on. Unless the server is already
* stopping, Posse shuts it down, so nobody plays without the rules.
*
* <p>Paper's shutdown only asks the main loop to stop. The stop then disables every other plugin before it disconnects
* anyone, and chat runs on its own thread, so players could still reach each other for that whole time. Posse therefore
* disconnects everyone itself, while its own listeners are still in place.
*
* <p>This can't help if the jar is removed, the plugin never loads, the process is killed, or another plugin
* unregisters Posse's listeners without disabling it.
*/
final class DisableGuard {
static final String STOPPING =
"Posse was disabled while the server was running, so its safety rules no longer apply. Shutting the server down. Start it again to bring the rules back.";

static final String SHUTDOWN_FAILED =
"Posse was disabled while the server was running, so its safety rules no longer apply, and the server couldn't be shut down. Stop it now.";

/** What each player sees when they are disconnected. Kept plain, since many players are children. */
static final String DISCONNECTED = "The server is stopping for a moment. Please come back later.";

private DisableGuard() {
}

/**
* Unless the server is already stopping: asks it to shut down, disconnects everyone, then logs why. Each step runs
* even if the one before it failed, and nothing escapes. If the server can't say whether it is stopping, it is
* treated as running. Returns true if a shutdown was asked for.
*/
static boolean onDisable(BooleanSupplier serverStopping, Runnable shutDown, Runnable disconnectEveryone,
Consumer<String> log) {
boolean stopping;
try {
stopping = serverStopping.getAsBoolean();
} catch (Throwable t) {
stopping = false;
}
if (stopping) return false;
String message = STOPPING;
try {
shutDown.run();
} catch (Throwable t) {
message = SHUTDOWN_FAILED;
}
try {
disconnectEveryone.run();
} catch (Throwable ignored) {
// The server's own stop disconnects anyone left.
}
try {
log.accept(message);
} catch (Throwable ignored) {
// Nothing may escape onDisable before the rest of the clean-up runs.
}
return true;
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/extantape/posse/PossePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ private void openJoinsIfSafe() {

@Override
public void onDisable() {
// D401: no playing without the rules. Paper's shutdown only asks the main loop to stop, so it is safe here.
DisableGuard.onDisable(() -> getServer().isStopping(), () -> getServer().shutdown(), this::disconnectEveryone,
getLogger()::severe);
getServer().getServicesManager().unregisterAll(this);
if (presence != null) presence.showAll();
else {
Expand All @@ -190,6 +193,19 @@ public void onDisable() {
com.extantape.posse.rules.Pending.clear();
}

// Kicks only work on the main thread. Off it, the server's own stop disconnects everyone a little later.
private void disconnectEveryone() {
if (!Bukkit.isPrimaryThread()) return;
net.kyori.adventure.text.Component reason = net.kyori.adventure.text.Component.text(DisableGuard.DISCONNECTED);
for (Player player : List.copyOf(Bukkit.getOnlinePlayers())) {
try {
player.kick(reason, org.bukkit.event.player.PlayerKickEvent.Cause.PLUGIN);
} catch (Throwable ignored) {
// One player's kick failing mustn't keep the others on.
}
}
}

public com.extantape.posse.listen.PresenceListener presence() {
return presence;
}
Expand Down
77 changes: 77 additions & 0 deletions src/test/java/com/extantape/posse/DisableGuardTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.extantape.posse;

import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

/** D401: nobody plays without Posse's rules. */
class DisableGuardTest {
private final List<String> steps = new ArrayList<>();

private boolean disable(boolean stopping) {
return DisableGuard.onDisable(() -> stopping, () -> steps.add("shutdown"), () -> steps.add("disconnect"),
line -> steps.add("log: " + line));
}

private static Runnable fails() {
return () -> {
throw new IllegalStateException("made up");
};
}

@Test
void disabledWhileRunningShutsDownThenDisconnectsEveryoneThenSaysWhy() {
assertTrue(disable(false));
assertEquals(List.of("shutdown", "disconnect", "log: " + DisableGuard.STOPPING), steps);
}

@Test
void aServerAlreadyStoppingIsLeftAlone() {
assertFalse(disable(true));
assertEquals(List.of(), steps);
}

@Test
void ifTheServerCannotSayWhetherItIsStoppingItIsTreatedAsRunning() {
assertTrue(DisableGuard.onDisable(() -> {
throw new IllegalStateException("made up");
}, () -> steps.add("shutdown"), () -> steps.add("disconnect"), line -> steps.add("log")));
assertEquals(List.of("shutdown", "disconnect", "log"), steps);
}

@Test
void aShutdownThatFailsStillDisconnectsEveryoneAndIsReported() {
assertTrue(DisableGuard.onDisable(() -> false, fails(), () -> steps.add("disconnect"),
line -> steps.add("log: " + line)));
assertEquals(List.of("disconnect", "log: " + DisableGuard.SHUTDOWN_FAILED), steps);
}

@Test
void aDisconnectThatFailsCannotUndoTheShutdownOrTheLogLine() {
assertTrue(DisableGuard.onDisable(() -> false, () -> steps.add("shutdown"), fails(),
line -> steps.add("log: " + line)));
assertEquals(List.of("shutdown", "log: " + DisableGuard.STOPPING), steps);
}

@Test
void aLoggerThatFailsCannotUndoTheShutdown() {
assertTrue(DisableGuard.onDisable(() -> false, () -> steps.add("shutdown"), () -> steps.add("disconnect"),
line -> {
throw new IllegalStateException("made up");
}));
assertEquals(List.of("shutdown", "disconnect"), steps);
}

@Test
void theMessagesSayWhatHappenedAndWhatToDo() {
assertTrue(DisableGuard.STOPPING.contains("safety rules no longer apply"));
assertTrue(DisableGuard.STOPPING.contains("Start it again"));
assertTrue(DisableGuard.SHUTDOWN_FAILED.contains("Stop it now"));
assertTrue(DisableGuard.DISCONNECTED.contains("come back later"));
}
}
3 changes: 2 additions & 1 deletion test/live/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ It takes about 4 minutes. The summary lists failures and skipped checks. The ful
| Graves (D231) | With a LanternGraves jar (`POSSE_LG_JAR`), real graves from planned deaths: each bot sees the owner's name or "Grave" exactly as an independent model of `mayKnow` says, with the owner in the same group, moved away, sharing a circle, offline, and in a circle-only world. Skipped without the jar. |
| LuckPerms | A circle granted or removed takes effect with no relog. |
| Config | A broken reload keeps the old rules; a broken config at startup refuses joins without `posse.bypass` and pauses chat and private messages, even for players with it, until it's fixed and reloaded. |
| Disabled while running (D401) | `disable-guard.js`, run with `POSSE_SUITE=disable-guard.js test/live/run.sh <version>` (about 1 minute). A normal `stop` logs nothing from Posse about being disabled. With two players online, `/mt disable Posse` makes Posse log why and shut the server down, the process exits by itself, and both players are disconnected with Posse's own message. The same happens while Posse is paused on a broken config. Then the server starts again and lets players in. `/reload` and a plugin error aren't driven. |
| Load | 20 more bots, 300 lines in about 15 seconds: all delivered within their circle, TPS, chat latency, no kicks. |

## The test-only plugins

`helper/` makes worlds, moves players, gives items and reports TPS, with one console command, `/mt`, and has one player command, `/mtwho`, whose Tab offers every online player, as a plugin that knows nothing of Posse would. `/mt blockkick` cancels a player's kicks while it's on, and `/mt allowlogin` allows one refused login again, standing in for another plugin doing either. It also stops test players taking damage, since a bot that spawns inside a block in a made-up Nether would otherwise die and respawn in the wrong world. `fakeminimap/` is the BlueMapMini stand-in. Both are built by `./gradlew build` and never shipped. Never install either on a real server.
`helper/` makes worlds, moves players, gives items and reports TPS, with one console command, `/mt`, and has one player command, `/mtwho`, whose Tab offers every online player, as a plugin that knows nothing of Posse would. `/mt blockkick` cancels a player's kicks while it's on, and `/mt allowlogin` allows one refused login again, standing in for another plugin doing either. `/mt disable <plugin>` disables a plugin on a running server, as an admin tool or a plugin error would. It also stops test players taking damage, since a bot that spawns inside a block in a made-up Nether would otherwise die and respawn in the wrong world. `fakeminimap/` is the BlueMapMini stand-in. Both are built by `./gradlew build` and never shipped. Never install either on a real server.
Loading
Loading