diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8f4726b..9c3f1ea 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,15 @@
# Changelog
+## 0.11.2
+
+- **Death and advancement lines follow circles** (K832). While circles are in use, whatever `presence` says, a line the server would send to everyone about a player goes only to players Posse says may reach that player, and to the console and log. A death line that names whoever dealt the last blow needs both players in reach. Before, a kid's death line reached every adult online, and the other way round. If Posse can't decide (the config couldn't be read at startup, or a player can't be read), only the player themself and players with `posse.bypass` get the line. The player who died still sees the cause on the death screen. Posse acts last (MONITOR), on the line as other plugins left it, so a line another plugin removed stays removed. A team's death message setting and the `show_death_messages` game rule still apply.
+- **Tab offers only names in reach.** While circles are in use, pressing Tab in any command offers only players the asker may reach. Before, Tab after `/msg`, `/tell`, `/w` and their namespaced forms offered every online name, even though the message itself was refused. The server's answer is filtered just before it's sent, so vanilla commands, other plugins' completers and the default online-player list are all covered. Paused, nobody but the asker is offered, unless they have `posse.bypass`. With `presence: reach`, a player the viewer may not see who is in another world is also hidden from the viewer's game, because a real game offers the names it knows without asking the server. Players in the same world stay visible and only leave the player list.
+- **`/list` and the server list follow presence.** With `presence: reach`, `/list` in any form, `minecraft:list` included, answers like `/circles`, except for players with `posse.bypass`. The server list sample is empty and the player count is kept.
+- **A returning player moved on join is announced only after the move.** With home worlds on, a returning player who has to be moved is held like a new kid until the move is done, so their join line goes out for where they end up. If the move fails and they're disconnected, nobody is sent a join or leave line naming them.
+- No config key changed. Not covered: a plugin that sends its own line about a player. On the second server the line naming a disconnected new player came from EssentialsX's new-player welcome (`newbies.announce-format`); turn it off there.
+- Tested: `./gradlew build` (139 unit tests, including the new `AnnouncementsTest` and `NameSuggestionsTest`), and on throwaway Paper 26.1.2, 26.2 and 26.3 the new `reach-leaks.js` bot suite (63 checks: a control with no circles, then refused pairs, allowed pairs, bypass and paused rules for death and advancement lines, Tab after seven commands, the players each game is told about, `/list`, the server list sample, a returning kid moved or disconnected at join, and the dead player's own death screen). On 0.11.1 it failed 27 of 63 on all three versions; on 0.11.2 it passed 63 of 63 on all three. The existing suites passed on all three: suite.js 84/84 (3 skipped, the LanternGraves checks), presence-messages.js 6/6, home-worlds.js 58/58 and book-authors.js 18/18. Not tested: a real game client's own Tab menu (a bot has none, so the test reads which players the bot's game was told about), a death line with a player killer on a server (unit only), and EssentialsX, which the test servers don't run.
+- On a throwaway copy of the main server with its own config (127.0.0.1, offline mode, two made-up kids and two made-up adults, counts only), 0.11.1 offered a name across the kid and adult line in 12 of 12 Tab answers, told each side's game about 2 of 2 players on the other side, sent each advancement line to 2 of 2 players on the other side, and named 4 players in the server list. 0.11.2 brought each of those to 0, with circle-mates still offered and sent their lines. Death lines didn't cross there on either version, because that server has them off in most worlds and some plugin there removes the line in the two hubs where they're on; 0.11.2 left that as it was.
+
## 0.11.1
- **A new kid lands where first-spawn puts them** (D297). With `home-worlds` on, a player's first-ever join is now checked 20 ticks (one second) after they join, not at the join, so WelcomeWagon or Multiverse's first-spawn places them first. A new kid placed in an allowed world, such as the lobby, stays there and is told nothing. One placed anywhere else is moved to their fallback as before. A returning player is still checked at the join itself, so nobody who has played before waits a second in a wrong world. If the player quits before the check, nothing happens. If the move doesn't go through, they are disconnected, as before. The respawn and world-change checks are unchanged.
diff --git a/README.md b/README.md
index 58cbacb..55c7705 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
Chat rules for family and community Paper servers. Players hear people in the same world, plus anyone who shares a "circle" with them, so groups such as families or age groups keep their own conversations across every world.
-**Status:** pre-release. Version 0.11.1 (new kids are checked a second after joining, so first-spawn places them first) passed the unit tests and every bot suite on throwaway Paper 26.1.2, 26.2 and 26.3. Before that, it passed its acceptance tests on throwaway Paper 26.2 and 26.3 servers, using protocol bots with LuckPerms: chat and private messages for every pair of players, who sees whom in the player list and join messages (`presence: reach`), home worlds on rejoin, respawn and teleport, replies, blocked commands, the word filter and its bypass, masking adults' words for kids, books, `/circles`, reloads, a broken config, and 20 bots chatting at once. BlueMapMini's share was tested with a stand-in plugin here; the real BlueMapMini 0.3.0 and Posse 0.5.0 haven't been run together yet. Signs and anvil renames weren't tested. It hasn't been seen in a real game client yet, so the wording and colours haven't been checked by a person. See [the live tests](test/live/README.md) and the [test audit](docs/test-audit.md).
+**Status:** pre-release. Version 0.11.2 (death and advancement lines, Tab, `/list` and the server list follow circles) passed the unit tests and every bot suite on throwaway Paper 26.1.2, 26.2 and 26.3, including a new one for those leaks, which 0.11.1 fails. Before that, it passed its acceptance tests on throwaway Paper 26.2 and 26.3 servers, using protocol bots with LuckPerms: chat and private messages for every pair of players, who sees whom in the player list and join messages (`presence: reach`), home worlds on rejoin, respawn and teleport, replies, blocked commands, the word filter and its bypass, masking adults' words for kids, books, `/circles`, reloads, a broken config, and 20 bots chatting at once. BlueMapMini's share was tested with a stand-in plugin here; the real BlueMapMini 0.3.0 and Posse 0.5.0 haven't been run together yet. Signs and anvil renames weren't tested. It hasn't been seen in a real game client yet, so the wording and colours haven't been checked by a person. See [the live tests](test/live/README.md) and the [test audit](docs/test-audit.md).
- Requires Paper 26.1 or newer and Java 25. Paper 1.21.11 and older aren't supported.
- With no circles set up it changes nothing about who hears whom, so it's safe to install first and configure after.
@@ -26,7 +26,16 @@ Otherwise they can't. A world group is a world with its Nether and End (`surviva
- Commands that would reach the whole server, `/me` and `/teammsg` by default, are off while circles are in use.
- BlueMapMini's `/hud share`, if BlueMapMini is installed, goes only to players who could hear you in chat. BlueMapMini keeps sharing off until Posse is 0.5.0 or newer.
-**Who's online (optional).** With `presence: reach` in `config.yml`, the player list (Tab) and join and leave messages follow the same rule: you only see players you could chat with. A kid and an adult who share no circle don't see each other online. It's checked on join, leave and world change, and every two seconds for circle changes, so no relog is needed. If the config can't be read at startup, nobody is shown to anyone until it's fixed. The default, `presence: everyone`, leaves both as in vanilla. Death and advancement messages and a player's name above their head aren't covered.
+**Who's online (optional).** With `presence: reach` in `config.yml`, the player list (Tab) and join and leave messages follow the same rule: you only see players you could chat with. A kid and an adult who share no circle don't see each other online. It's checked on join, leave and world change, and every two seconds for circle changes, so no relog is needed. If the config can't be read at startup, nobody is shown to anyone until it's fixed. The default, `presence: everyone`, leaves these as in vanilla. With `presence: reach`:
+
+- A player's game is told nothing about a player they may not see who is in another world. The game offers every name it has been told when you press Tab, in chat or after a command, so taking a player off the list isn't enough. Two players in the same world who may not see each other, such as strangers in a circle-only lobby, still see each other walk by, name above the head included. They only leave each other's list.
+- `/list`, in any form, answers like `/circles`: the players who can hear you. Players with `posse.bypass` get the server's own list. Other plugins' list commands under other names, such as `/who` or `/online`, aren't covered. Add those to `blocked-commands`.
+- The server list shows the player count and no names, because Posse can't tell who is looking.
+- A returning player whom home worlds has to move is announced once the move is done, for where they end up. If the move fails and they're disconnected, nobody is told they joined or left.
+
+**Death and advancement lines.** While circles are in use, whatever `presence` says, a line the server would send to everyone about a player goes only to the players who may reach them, and to the console and log. A death line that names whoever dealt the last blow needs both players in reach. If the config can't be read at startup, only the player themself and players with `posse.bypass` get the line. The player who died still sees the cause on the death screen. Posse acts on the line as other plugins left it, so a plugin that removes or replaces death lines keeps doing so. A team's death message setting and the `show_death_messages` game rule still apply.
+
+**Names on Tab.** While circles are in use, pressing Tab in any command offers only the names of players you may reach. That covers `/msg`, `/tell`, `/w` and their namespaced forms such as `minecraft:msg`, and every plugin command that offers online players. It's checked on the finished list the server is about to send, so it doesn't matter which plugin made it. A suggestion that isn't a player but is spelled like the name of one out of reach, such as a warp, is left out too. A game also offers the names it already knows without asking the server, which is what `presence: reach` above closes. With `presence: everyone` every game knows every name, as in vanilla.
**Home worlds (optional).** For a server where a kids' group must never end up in an adults' world. Players rejoin where they logged out, and a world plugin often checks access only when you teleport, not when you join. With a `home-worlds` section in `config.yml`, Posse steps in when someone is in a world their circle doesn't allow:
@@ -106,6 +115,9 @@ if (rules == null || rules.mayReach(from, to)) { /* send it */ }
## Limits
+- A plugin that sends its own line to every player, without going through the server's join, quit, death or advancement events, isn't covered. EssentialsX's welcome for new players (`newbies.announce-format`) is one: turn it off there.
+- Admins and ops without `posse.bypass` aren't offered the names of players out of their reach on Tab either, in any command. They can still type a name in full.
+- A pet's death line goes to its owner as in vanilla, and can name the player who killed it.
- Book pages aren't checked for names, and a book moved into a chest shows its author to anyone else looking at that chest for one tick.
- Signs are readable by anyone who walks past, and a book or named item can be carried to another world. Posse only checks them when they're written.
- Chat plugins that send messages their own way, rather than through Paper's chat event, aren't covered. Add their message commands to `private-message-commands`.
diff --git a/build.gradle.kts b/build.gradle.kts
index 815737b..a7a6c8e 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -4,7 +4,7 @@ plugins {
}
group = "com.extantape"
-version = "0.11.1"
+version = "0.11.2"
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(25))
diff --git a/docs/decisions.md b/docs/decisions.md
index d1c9ff2..50086c0 100644
--- a/docs/decisions.md
+++ b/docs/decisions.md
@@ -43,3 +43,11 @@ After the Trust and Safety review of the rename, the owner chose:
## 2026-11-25: New kids and the lobby
- **Fix it in Posse (owner, D297, "Fix it in Posse (Recommended)"):** with home worlds on, a first-ever join landed in the kids' fallback world instead of the lobby, because Posse moved the kid before WelcomeWagon or Multiverse placed them. A first-ever join is now checked 20 ticks after joining; a returning player is still checked at once. The kid is never left in a world they aren't allowed in: the check still moves or, if it can't, disconnects. Released as 0.11.1.
+
+## 2026-11-27: Names that reach past circles (K832)
+
+- **Every line or suggestion naming a player follows reach (K832).** A bot run on a copy of the second server found three ways a name crossed between kids and adults who share no circle: death lines went to everyone, Tab after `/msg` and the other message commands offered every online name, and a new player disconnected at join was named to everyone. Posse now treats each like chat: a viewer gets the line or the name only if Posse says they may reach that player. The console and log keep every line. When Posse can't decide (rules paused, or a player it can't read), only the player themself and players with `posse.bypass` get it. Released as 0.11.2; no config key changed.
+- Choices made in the build: death and advancement lines follow reach whatever `presence` says, because they can name a kid on any server with circles. A death line that names a killer needs both players in reach. Paper sends one death message to everyone or no one, so Posse takes it off the event and sends it itself, and puts it on the death screen of the player who died. Posse reads the line last (MONITOR), so a line another plugin removed is never brought back. Team death message visibility and the `show_death_messages` game rule still apply.
+- Tab is closed in two places. Paper's `AsyncPlayerSendSuggestionsEvent` filters every list the server sends, for any command and plugin. A real game answers vanilla player arguments from its own list of known players, without asking the server, so with `presence: reach` a player out of sight in another world is hidden from the viewer (`hideEntity`), which takes them out of that list. Players in the same world stay visible and only leave the player list, so nobody turns invisible beside you.
+- With `presence: reach`, `/list` in any namespaced form answers like `/circles`, and the server list sample is empty with the count kept. A returning player who must be moved by home worlds is held like a new kid until the move is done, so a failed move and the disconnect name them to nobody.
+- Not covered by Posse: a plugin that broadcasts its own line about a player. The leak found at join on the second server was EssentialsX's new-player welcome (`newbies.announce-format`), sent by EssentialsX itself. Turning it off there is a server config change, which waits for the owner's go.
diff --git a/docs/test-audit.md b/docs/test-audit.md
index 32d0d34..73c45d5 100644
--- a/docs/test-audit.md
+++ b/docs/test-audit.md
@@ -3,6 +3,25 @@
Kept by this repo's owning session (Minecraft: Plugins Lead), per `~/Code/CLAUDE.md`, "Test self-audits". Newest first.
+## 2026-11-27: names that reach past circles (0.11.2, K832)
+
+| Promise | Covered by |
+| --- | --- |
+| A death line reaches only players who may reach the dead player (refused pair, allowed pair, bypass), and the console keeps it | unit `AnnouncementsTest`; bot `reach-leaks.js`, "Death lines follow reach" (fails on 0.11.1) |
+| A death line naming a killer needs both in reach | unit `AnnouncementsTest.aLineThatNamesAKillerNeedsBothToBeInReach` |
+| An advancement line follows the same rule | unit; bot, "Advancement lines follow reach" (fails on 0.11.1) |
+| Paused or unreadable: only the player and bypass get the line | unit `pausedRulesReachOnlyThePlayerAndBypass`, `aViewerPosseCannotWorkOutGetsNothing`, `aLinePosseCannotWorkOutStillReachesThePlayerAndBypassOnly`; bot, paused part |
+| Tab offers only names in reach, for vanilla, namespaced and plugin commands, any letter case or quoting; bypass gets everyone | unit `NameSuggestionsTest`; bot, "Tab offers only names in reach" over seven commands (fails on 0.11.1) |
+| Paused or unreadable: Tab offers only the asker, unless bypass | unit; bot, paused part |
+| With `presence: reach`, a player's game is told of nobody out of sight in another world; same-world players stay visible and unlisted; circle changes follow within seconds | unit `PresenceTest.aPlayerOutOfSightIsKeptFromTheGame...`; bot, "A player's game is told nothing" (fails on 0.11.1) |
+| `/list` in any form answers like `/circles`, bypass gets the full list; the server list sample is empty | unit `CommandRulesTest.thePlayerListCommandIsRecognizedInEveryForm`; bot, "/list follows reach" and "The server list" (fail on 0.11.1) |
+| A returning player moved on join is announced after the move; a failed move names them to nobody | bot, "A returning player" and "A player disconnected while joining" (the second fails on 0.11.1) |
+| With no circles nothing is filtered | unit `withNoCircles...` in both new tests; bot control part |
+| The dead player's own death screen keeps its cause line | bot, "the kid's own death screen still says how they died" |
+| A death line another plugin removed stays removed (Posse reads it at MONITOR) | a throwaway copy of the main server, where a plugin removes it in the hubs: same counts on 0.11.1 and 0.11.2 (no bot test here, since it needs that plugin) |
+
+Gaps: a bot has no Tab menu of its own, so what a real game offers by itself is read from the players the bot's game was told about, not from a real client. A pet's death line and lines that plugins broadcast themselves (EssentialsX's new-player welcome) aren't Posse's to filter, and are listed as limits. The death line with a player killer is unit-tested only; no bot kills another. Sleep messages carry counts, never names, so they need no test.
+
## 2026-11-25: first join and old nodes (0.11.1, D297)
| Promise | Covered by |
diff --git a/src/main/java/com/extantape/posse/PossePlugin.java b/src/main/java/com/extantape/posse/PossePlugin.java
index fa8474c..6bfc4ad 100644
--- a/src/main/java/com/extantape/posse/PossePlugin.java
+++ b/src/main/java/com/extantape/posse/PossePlugin.java
@@ -38,6 +38,7 @@
public final class PossePlugin extends JavaPlugin implements ReachService {
private com.extantape.posse.listen.PresenceListener presence;
private com.extantape.posse.listen.BookListener books;
+ private PosseCommands commands;
public static final String ADMIN = "posse.admin";
@@ -76,6 +77,8 @@ public void onEnable() {
plugins.registerEvents(new com.extantape.posse.listen.HomeWorldsListener(this), this);
presence = new com.extantape.posse.listen.PresenceListener(this);
plugins.registerEvents(presence, this);
+ plugins.registerEvents(new com.extantape.posse.listen.AnnouncementListener(this), this);
+ plugins.registerEvents(new com.extantape.posse.listen.SuggestionListener(this), this);
Bukkit.getScheduler().runTaskTimer(this, presence::refresh, 40L, 40L);
// Only touch a share event's class when its plugin is installed. The hooks are the only classes that name them.
if (plugins.getPlugin("BlueMapMini") != null) {
@@ -87,13 +90,14 @@ public void onEnable() {
}
}
getServer().getServicesManager().register(ReachService.class, this, this, ServicePriority.Normal);
- PosseCommands commands = new PosseCommands(this);
+ commands = new PosseCommands(this);
getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, event -> commands.register(event.registrar()));
}
@Override
public void onDisable() {
getServer().getServicesManager().unregisterAll(this);
+ if (presence != null) presence.showAll();
partners.clear();
com.extantape.posse.rules.Pending.clear();
}
@@ -102,6 +106,10 @@ public com.extantape.posse.listen.PresenceListener presence() {
return presence;
}
+ public PosseCommands commands() {
+ return commands;
+ }
+
/** Reads the config files again. Returns true if the new rules were applied. */
public boolean reload(CommandSender sender) {
SettingsLoader.Result result = new SettingsLoader(this::getResource).load(getDataFolder().toPath());
diff --git a/src/main/java/com/extantape/posse/command/PosseCommands.java b/src/main/java/com/extantape/posse/command/PosseCommands.java
index ae9c383..1723f21 100644
--- a/src/main/java/com/extantape/posse/command/PosseCommands.java
+++ b/src/main/java/com/extantape/posse/command/PosseCommands.java
@@ -158,7 +158,8 @@ static String homeWorldsSummary(HomeWorlds home) {
return String.join("; ", parts);
}
- private int circles(Player player) {
+ /** Tells the player their circles and who online can hear them. Also the answer to /list while presence is limited. */
+ public int circles(Player player) {
PossePlugin.State state = plugin.state();
if (state == null) {
plugin.tell(player, "chat-paused");
diff --git a/src/main/java/com/extantape/posse/listen/AnnouncementListener.java b/src/main/java/com/extantape/posse/listen/AnnouncementListener.java
new file mode 100644
index 0000000..7243440
--- /dev/null
+++ b/src/main/java/com/extantape/posse/listen/AnnouncementListener.java
@@ -0,0 +1,95 @@
+package com.extantape.posse.listen;
+
+import com.extantape.posse.PossePlugin;
+import com.extantape.posse.rules.Announcements;
+import com.extantape.posse.rules.Reach;
+import com.extantape.posse.rules.Subject;
+import net.kyori.adventure.text.Component;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.bukkit.event.entity.PlayerDeathEvent;
+import org.bukkit.event.player.PlayerAdvancementDoneEvent;
+import org.bukkit.scoreboard.Team;
+
+import java.util.IdentityHashMap;
+import java.util.Map;
+import java.util.function.Predicate;
+
+/**
+ * Death and advancement lines follow the same reach answer as chat (K832). The server would send each to everyone
+ * online, so the line is taken off the event and sent by {@link Announcements} to the players who may reach the one it
+ * names, and to the console. With no circles set up nothing is touched, as in vanilla.
+ *
+ * Both run last, at MONITOR, so they act on the line as other plugins left it. A plugin that removed the line, or
+ * swapped in its own, keeps that choice: Posse never sends a line the server wouldn't have sent, it only narrows who
+ * gets it. Changing the event at MONITOR is unusual, but it changes only the recipients, never whether a line exists.
+ */
+public final class AnnouncementListener implements Listener {
+ private final PossePlugin plugin;
+
+ public AnnouncementListener(PossePlugin plugin) {
+ this.plugin = plugin;
+ }
+
+ /** The current rules, or null while paused. */
+ private Reach reach() {
+ PossePlugin.State state = plugin.state();
+ return state == null ? null : state.settings().reach();
+ }
+
+ private void deliver(Component message, Player about, Player also, Predicate allowed) {
+ Map viewers = new IdentityHashMap<>();
+ for (Player p : Bukkit.getOnlinePlayers()) if (allowed.test(p)) viewers.put(Subject.of(p), p);
+ Announcements.deliver(message, Subject.of(about), also == null ? null : Subject.of(also), viewers.keySet(), reach(),
+ viewer -> viewers.get(viewer).sendMessage(message), m -> Bukkit.getConsoleSender().sendMessage(m));
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
+ public void onDeath(PlayerDeathEvent event) {
+ Reach reach = reach();
+ if (reach != null && !reach.active()) return;
+ Component message = event.deathMessage();
+ if (message == null) return;
+ // The server sends a death line to everyone or to nobody, so it is told nobody, and Posse sends it. The death
+ // screen reads the same line, so it is kept there for the player who died, unless a plugin already set its own.
+ event.deathMessage(null);
+ if (!event.getShowDeathMessages()) return;
+ if (event.deathScreenMessageOverride() == null) event.deathScreenMessageOverride(message);
+ Player dead = event.getEntity();
+ deliver(message, dead, dead.getKiller(), teamAllows(dead));
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR)
+ public void onAdvancement(PlayerAdvancementDoneEvent event) {
+ Reach reach = reach();
+ if (reach != null && !reach.active()) return;
+ Component message = event.message();
+ if (message == null) return;
+ event.message(null);
+ deliver(message, event.getPlayer(), null, viewer -> true);
+ }
+
+ /**
+ * A scoreboard team can narrow who sees its members' death lines. The server applies that when it sends the line
+ * itself, so it's applied here too: Posse never sends a death line to someone vanilla wouldn't have. If the team
+ * can't be read, only the dead player is left.
+ */
+ private static Predicate teamAllows(Player dead) {
+ try {
+ var board = Bukkit.getScoreboardManager().getMainScoreboard();
+ Team team = board.getEntityTeam(dead);
+ if (team == null) return viewer -> true;
+ return switch (team.getOption(Team.Option.DEATH_MESSAGE_VISIBILITY)) {
+ case ALWAYS -> viewer -> true;
+ case NEVER -> viewer -> false;
+ case FOR_OWN_TEAM -> viewer -> team.equals(board.getEntityTeam(viewer));
+ case FOR_OTHER_TEAMS -> viewer -> !team.equals(board.getEntityTeam(viewer));
+ };
+ } catch (RuntimeException e) {
+ return viewer -> viewer.equals(dead);
+ }
+ }
+}
diff --git a/src/main/java/com/extantape/posse/listen/CommandListener.java b/src/main/java/com/extantape/posse/listen/CommandListener.java
index 9678974..c90bbdc 100644
--- a/src/main/java/com/extantape/posse/listen/CommandListener.java
+++ b/src/main/java/com/extantape/posse/listen/CommandListener.java
@@ -2,6 +2,7 @@
import com.extantape.posse.PossePlugin;
import com.extantape.posse.rules.CommandRules;
+import com.extantape.posse.rules.Reach;
import com.extantape.posse.rules.Subject;
import com.extantape.posse.text.Messages;
import org.bukkit.Bukkit;
@@ -14,8 +15,9 @@
import java.util.UUID;
/**
- * Blocked commands, and private messages and replies to players out of reach. Works on the typed command line
- * before any plugin sees it, so it covers other plugins' commands and their namespaced forms.
+ * Blocked commands, private messages and replies to players out of reach, and /list while the player list follows
+ * reach. Works on the typed command line before any plugin sees it, so it covers other plugins' commands and their
+ * namespaced forms.
*/
public final class CommandListener implements Listener {
private final PossePlugin plugin;
@@ -41,7 +43,15 @@ public void onCommand(PlayerCommandPreprocessEvent event) {
return p == null ? null : Subject.of(p);
});
switch (decision.kind()) {
- case PASS -> { }
+ case PASS -> {
+ // /list names everyone online. While the player list follows reach, it answers like /circles: the
+ // players who can hear you. A server's own blocked-commands entry for it, checked above, wins.
+ boolean followsReach = paused || state.settings().presenceByReach() && state.settings().reach().active();
+ if (followsReach && CommandRules.isPlayerList(event.getMessage()) && !from.hasPermission(Reach.BYPASS)) {
+ event.setCancelled(true);
+ plugin.commands().circles(from);
+ }
+ }
case BLOCK -> {
event.setCancelled(true);
if (decision.text() != null) {
diff --git a/src/main/java/com/extantape/posse/listen/HomeWorldsListener.java b/src/main/java/com/extantape/posse/listen/HomeWorldsListener.java
index 8910d70..f194a4b 100644
--- a/src/main/java/com/extantape/posse/listen/HomeWorldsListener.java
+++ b/src/main/java/com/extantape/posse/listen/HomeWorldsListener.java
@@ -62,8 +62,9 @@ private void tell(Player player, HomeWorlds.Move move) {
* A player who has never joined is placed by WelcomeWagon or Multiverse's first-spawn after this event, so the
* check waits {@link HomeWorlds#joinDelayTicks} ticks and then looks at where they ended up (D297). A returning
* player is checked at once. Until the delayed check runs, a player these rules govern is pending: they reach
- * nobody, and nobody reaches them (see {@link Pending}). If they quit first there is nothing to do, and if the
- * move doesn't go through they are disconnected, never left in a world they aren't allowed in.
+ * nobody, and nobody reaches them (see {@link Pending}). The same goes for a returning player while a move is under
+ * way. If they quit first there is nothing to do, and if the move doesn't go through they are disconnected, never
+ * left in a world they aren't allowed in.
*/
@EventHandler(priority = EventPriority.LOW)
public void onJoin(PlayerJoinEvent event) {
@@ -100,18 +101,22 @@ private void release(UUID id) {
if (player != null && plugin.presence() != null) plugin.presence().release(player);
}
- private void checkAfterJoin(Player player, boolean wasPending) {
+ private void checkAfterJoin(Player player, boolean alreadyPending) {
UUID id = player.getUniqueId();
HomeWorlds.Move move = decide(player, player.getWorld().getName());
if (move == null) {
- if (wasPending) release(id);
+ if (alreadyPending) release(id);
return;
}
+ // A returning player who has to be moved is pending too, until the move is done (K832). Otherwise their join
+ // line would go to whoever can reach the world they must not be in, and so would the leave line if the move
+ // fails and they are disconnected. Nobody hears of them until they are where they may be.
+ Pending.begin(id);
player.teleportAsync(spawnOf(move)).thenAccept(ok -> Bukkit.getScheduler().runTask(plugin, () -> {
Player now = Bukkit.getPlayer(id);
if (ok) {
if (now != null) tell(now, move);
- if (wasPending) release(id);
+ release(id);
} else {
// Fail closed: a player who must not stay here and couldn't be moved is sent off, never left in place.
plugin.getLogger().warning("A home-worlds move on join didn't go through, so the player was disconnected instead of being left there.");
diff --git a/src/main/java/com/extantape/posse/listen/PresenceListener.java b/src/main/java/com/extantape/posse/listen/PresenceListener.java
index 8676e91..0d83399 100644
--- a/src/main/java/com/extantape/posse/listen/PresenceListener.java
+++ b/src/main/java/com/extantape/posse/listen/PresenceListener.java
@@ -7,8 +7,13 @@
import com.extantape.posse.rules.Reach;
import com.extantape.posse.rules.Subject;
import net.kyori.adventure.text.Component;
+import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@@ -22,6 +27,11 @@
/**
* Applies {@link Presence} to the player list and to join and leave messages (D283). Checked on join, leave and world
* change, and every two seconds for circle changes made through the permissions plugin.
+ *
+ * A player the viewer may not see is also kept from the viewer's game altogether while they are in different worlds
+ * (K832). Taking a player off the list leaves their name in the game's memory, and the game offers every name it
+ * remembers when Tab is pressed in chat or after a command, without asking the server. Hiding the player removes the
+ * name. Paper's own answers to Tab, and most plugins', also skip a hidden player.
*/
public final class PresenceListener implements Listener {
private final PossePlugin plugin;
@@ -100,17 +110,66 @@ public void onWorld(PlayerChangedWorldEvent event) {
refresh();
}
- /** Lists or unlists every pair of online players to match the rules. Cheap when nothing changed. */
+ /** The server's hiding ends with the connection, so Posse's record of it does too. */
+ @EventHandler(priority = EventPriority.MONITOR)
+ public void forget(PlayerQuitEvent event) {
+ UUID gone = event.getPlayer().getUniqueId();
+ hidden.remove(gone);
+ for (Set from : hidden.values()) from.remove(gone);
+ }
+
+ /**
+ * The server list shows a sample of who is online to anyone who looks, signed in or not. Posse can't tell who is
+ * asking, so while presence is limited the sample is left empty. The player count stays.
+ */
+ @EventHandler(priority = EventPriority.HIGHEST)
+ public void onPing(PaperServerListPingEvent event) {
+ if (limited()) event.getListedPlayers().clear();
+ }
+
+ /** For each viewer, the players Posse has hidden from them. Only Posse's own hiding is ever undone. */
+ private final Map> hidden = new HashMap<>();
+
+ /**
+ * Lists or unlists, and hides or shows, every pair of online players to match the rules. Cheap when nothing
+ * changed. If one pair can't be worked out, that pair is hidden and the rest still run.
+ */
public void refresh() {
var online = Bukkit.getOnlinePlayers();
for (Player viewer : online) {
+ Set mine = hidden.computeIfAbsent(viewer.getUniqueId(), id -> new HashSet<>());
for (Player other : online) {
if (viewer == other) continue;
- boolean see = maySee(viewer, other);
+ boolean see, know;
+ try {
+ see = maySee(viewer, other);
+ know = Presence.mayKnowOf(see, viewer.getWorld().equals(other.getWorld()));
+ } catch (RuntimeException e) {
+ see = false;
+ know = false;
+ }
+ boolean hid = mine.contains(other.getUniqueId());
+ if (!know && !hid) {
+ viewer.hideEntity(plugin, other);
+ mine.add(other.getUniqueId());
+ } else if (know && hid) {
+ viewer.showEntity(plugin, other);
+ mine.remove(other.getUniqueId());
+ }
+ // Hidden from this viewer, by Posse or by another plugin such as a vanish: there is no list entry to set.
+ if (!viewer.canSee(other)) continue;
boolean listed = viewer.isListed(other);
if (see && !listed) viewer.listPlayer(other);
else if (!see && listed) viewer.unlistPlayer(other);
}
}
}
+
+ /** Undoes Posse's own hiding, for when the plugin is turned off. */
+ public void showAll() {
+ for (Player viewer : Bukkit.getOnlinePlayers()) {
+ for (Player other : Bukkit.getOnlinePlayers()) if (viewer != other) viewer.showEntity(plugin, other);
+ }
+ hidden.clear();
+ }
}
diff --git a/src/main/java/com/extantape/posse/listen/SuggestionListener.java b/src/main/java/com/extantape/posse/listen/SuggestionListener.java
new file mode 100644
index 0000000..b6805ec
--- /dev/null
+++ b/src/main/java/com/extantape/posse/listen/SuggestionListener.java
@@ -0,0 +1,57 @@
+package com.extantape.posse.listen;
+
+import com.destroystokyo.paper.event.brigadier.AsyncPlayerSendSuggestionsEvent;
+import com.extantape.posse.PossePlugin;
+import com.extantape.posse.rules.NameSuggestions;
+import com.extantape.posse.rules.Reach;
+import com.extantape.posse.rules.Subject;
+import com.mojang.brigadier.suggestion.Suggestion;
+import com.mojang.brigadier.suggestion.Suggestions;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Tab in a command offers only the names of players the asker may reach (K832). Paper fires this event with the
+ * finished list just before it goes to the player, whichever command made it: a vanilla one, a plugin's own
+ * completer, or the default list of online players. So one check here covers every command and its namespaced forms.
+ * With no circles set up nothing is touched. If anything goes wrong, nothing is offered.
+ *
+ * A real game answers Tab for vanilla player arguments itself, from the players it has been told about, without
+ * asking the server. {@link PresenceListener} covers that half by keeping players out of reach from the game.
+ */
+public final class SuggestionListener implements Listener {
+ private final PossePlugin plugin;
+
+ public SuggestionListener(PossePlugin plugin) {
+ this.plugin = plugin;
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onSuggestions(AsyncPlayerSendSuggestionsEvent event) {
+ try {
+ PossePlugin.State state = plugin.state();
+ Reach reach = state == null ? null : state.settings().reach();
+ if (reach != null && !reach.active()) return;
+ Player asker = event.getPlayer();
+ List online = new ArrayList<>();
+ for (Player p : Bukkit.getOnlinePlayers()) online.add(Subject.of(p));
+ Set withheld = NameSuggestions.withheld(Subject.of(asker), online, reach);
+ if (withheld.isEmpty()) return;
+ Suggestions offered = event.getSuggestions();
+ List kept = new ArrayList<>(offered.getList().size());
+ for (Suggestion s : offered.getList()) if (!NameSuggestions.isWithheld(s.getText(), withheld)) kept.add(s);
+ if (kept.size() == offered.getList().size()) return;
+ if (kept.isEmpty()) event.setCancelled(true);
+ else event.setSuggestions(new Suggestions(offered.getRange(), kept));
+ } catch (RuntimeException e) {
+ event.setCancelled(true);
+ }
+ }
+}
diff --git a/src/main/java/com/extantape/posse/rules/Announcements.java b/src/main/java/com/extantape/posse/rules/Announcements.java
new file mode 100644
index 0000000..4a38b1e
--- /dev/null
+++ b/src/main/java/com/extantape/posse/rules/Announcements.java
@@ -0,0 +1,61 @@
+package com.extantape.posse.rules;
+
+import java.util.Collection;
+import java.util.function.Consumer;
+
+/**
+ * Who gets a line the server would send to everyone about a player, such as a death or advancement line (K832). It
+ * follows the same answer as chat: a viewer gets the line only if they may reach the player it's about, and everyone
+ * else it names, such as whoever dealt the last blow. Kept free of the server so a unit test runs the same path the
+ * listener does.
+ *
+ * Fails closed. While the rules are paused, or if the answer can't be worked out for a viewer, only the player the
+ * line is about and players with posse.bypass get it.
+ */
+public final class Announcements {
+ private Announcements() {}
+
+ /**
+ * @param reach the current rules, or null while paused
+ * @param about who the line is about; they always get it
+ * @param also anyone else the line names, or null
+ */
+ public static boolean mayHear(Subject viewer, Reach reach, Subject about, Subject also) {
+ try {
+ if (viewer.id().equals(about.id())) return true;
+ if (reach == null) return viewer.has(Reach.BYPASS);
+ if (!reach.mayReach(viewer, about)) return false;
+ return also == null || viewer.id().equals(also.id()) || reach.mayReach(viewer, also);
+ } catch (RuntimeException e) {
+ return bypass(viewer);
+ }
+ }
+
+ /** Whether the viewer has posse.bypass, or false if even that can't be read. */
+ private static boolean bypass(Subject viewer) {
+ try {
+ return viewer.has(Reach.BYPASS);
+ } catch (RuntimeException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Sends {@code message} once to each online player who may hear it, and always to the console, so the log keeps it.
+ * A null message, which is what a plugin sets to say "no line", sends nothing at all.
+ *
+ * @return how many players were sent the message
+ */
+ public static int deliver(M message, Subject about, Subject also, Collection extends Subject> online, Reach reach,
+ Consumer toViewer, Consumer toConsole) {
+ if (message == null) return 0;
+ int sent = 0;
+ for (Subject viewer : online) {
+ if (!mayHear(viewer, reach, about, also)) continue;
+ toViewer.accept(viewer);
+ sent++;
+ }
+ toConsole.accept(message);
+ return sent;
+ }
+}
diff --git a/src/main/java/com/extantape/posse/rules/CommandRules.java b/src/main/java/com/extantape/posse/rules/CommandRules.java
index 398abc5..612d6d0 100644
--- a/src/main/java/com/extantape/posse/rules/CommandRules.java
+++ b/src/main/java/com/extantape/posse/rules/CommandRules.java
@@ -139,6 +139,16 @@ private static String slash(String line) {
return line.startsWith("/") ? "/" : "";
}
+ /**
+ * Whether the line is the server's player list command, {@code /list}, in any letter case and any namespaced form
+ * such as {@code minecraft:list}. It names everyone online, so it follows presence (K832).
+ */
+ public static boolean isPlayerList(String line) {
+ String trimmed = line.startsWith("/") ? line.substring(1) : line;
+ String label = trimmed.trim().split("\\s+")[0].toLowerCase(Locale.ROOT);
+ return label.equals("list") || label.endsWith(":list");
+ }
+
static boolean matches(Set entries, String label) {
if (entries.contains(label)) return true;
int colon = label.indexOf(':');
diff --git a/src/main/java/com/extantape/posse/rules/NameSuggestions.java b/src/main/java/com/extantape/posse/rules/NameSuggestions.java
new file mode 100644
index 0000000..e9b3d6d
--- /dev/null
+++ b/src/main/java/com/extantape/posse/rules/NameSuggestions.java
@@ -0,0 +1,62 @@
+package com.extantape.posse.rules;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+
+/**
+ * Which online players' names a player may be offered when they press Tab in a command (K832). It follows the same
+ * answer as chat: a name is offered only if the player asking may reach its owner. It covers every command, since it
+ * works on the names and not on the command.
+ *
+ * Fails closed. While the rules are paused, or if the answer can't be worked out, only the asker's own name is
+ * offered, unless they have posse.bypass.
+ */
+public final class NameSuggestions {
+ private NameSuggestions() {}
+
+ /** @param reach the current rules, or null while paused */
+ public static boolean mayOffer(Subject asker, Subject other, Reach reach) {
+ try {
+ if (asker.id().equals(other.id())) return true;
+ if (reach == null) return asker.has(Reach.BYPASS);
+ return reach.mayReach(asker, other);
+ } catch (RuntimeException e) {
+ return false;
+ }
+ }
+
+ /** The names, in lower case, of the online players {@code asker} may not be offered. */
+ public static Set withheld(Subject asker, Collection extends Subject> online, Reach reach) {
+ Set names = new HashSet<>();
+ for (Subject other : online) {
+ String name;
+ try {
+ name = other.name();
+ } catch (RuntimeException e) {
+ continue;
+ }
+ if (name != null && !mayOffer(asker, other, reach)) names.add(name.toLowerCase(Locale.ROOT));
+ }
+ return names;
+ }
+
+ /** The suggestions left once every one that is a withheld name, quoted or not, in any letter case, is taken out. */
+ public static List keep(List suggestions, Set withheld) {
+ List kept = new ArrayList<>(suggestions.size());
+ for (String text : suggestions) if (!isWithheld(text, withheld)) kept.add(text);
+ return kept;
+ }
+
+ public static boolean isWithheld(String suggestion, Set withheld) {
+ if (suggestion == null) return false;
+ String text = suggestion.trim();
+ if (text.length() >= 2 && (text.startsWith("\"") && text.endsWith("\"") || text.startsWith("'") && text.endsWith("'"))) {
+ text = text.substring(1, text.length() - 1);
+ }
+ return withheld.contains(text.toLowerCase(Locale.ROOT));
+ }
+}
diff --git a/src/main/java/com/extantape/posse/rules/Presence.java b/src/main/java/com/extantape/posse/rules/Presence.java
index 96f9b37..d62b1ff 100644
--- a/src/main/java/com/extantape/posse/rules/Presence.java
+++ b/src/main/java/com/extantape/posse/rules/Presence.java
@@ -18,4 +18,17 @@ public static boolean maySee(Subject viewer, Subject other, boolean byReach, Rea
if (!byReach) return true;
return reach.mayReach(viewer, other);
}
+
+ /**
+ * Whether the viewer's game should know the other player exists at all (K832). A game that knows a player offers
+ * their name when Tab is pressed in chat or after a command, listed or not, so a player the viewer may not see is
+ * kept from it entirely. The one exception is a player standing in the same world: the viewer can see them walk
+ * by, and hiding them would make them invisible, so they stay known and only leave the player list.
+ *
+ * @param maySee the answer from {@link #maySee}
+ * @param sameWorld whether both stand in the very same world right now
+ */
+ public static boolean mayKnowOf(boolean maySee, boolean sameWorld) {
+ return maySee || sameWorld;
+ }
}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 94213c8..dcd0ae1 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -19,6 +19,8 @@ circle-only-worlds: []
# everyone: as in vanilla.
# reach: only players they could chat with under the rules above. A kid and an adult who share no circle don't see
# each other online. If the config can't be read at startup, nobody is shown to anyone until it's fixed.
+# /list then answers like /circles, and the server list shows the player count with no names.
+# Death and advancement lines, and the names Tab offers in commands, follow the circles whatever this says.
presence: everyone
# Keeps players in the worlds their circles belong in, for a server where a kids' group must never end up in an
diff --git a/src/test/java/com/extantape/posse/rules/AnnouncementsTest.java b/src/test/java/com/extantape/posse/rules/AnnouncementsTest.java
new file mode 100644
index 0000000..f0ed5c9
--- /dev/null
+++ b/src/test/java/com/extantape/posse/rules/AnnouncementsTest.java
@@ -0,0 +1,122 @@
+package com.extantape.posse.rules;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import static com.extantape.posse.rules.Players.circle;
+import static com.extantape.posse.rules.Players.pending;
+import static com.extantape.posse.rules.Players.player;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/** K832: who gets a death or advancement line. Kids and adults stand in different worlds and share no circle. */
+class AnnouncementsTest {
+ private final Reach reach = new Reach(List.of("kids", "adults"), Set.of("station"), Map.of(), List.of("_nether", "_the_end"));
+ private final Subject kid = player("kid", "kidland", circle("kids"));
+ private final Subject otherKid = player("otherKid", "kidland_nether", circle("kids"));
+ private final Subject adult = player("adult", "grownups", circle("adults"));
+ private final Subject otherAdult = player("otherAdult", "grownups", circle("adults"));
+ private final Subject visitor = player("visitor", "grownups", circle("adults"), circle("kids"));
+ private final Subject moderator = player("moderator", "grownups", Reach.BYPASS);
+ private final Subject nobody = player("nobody", "station");
+ private final List online = List.of(kid, otherKid, adult, otherAdult, visitor, moderator, nobody);
+
+ private final List console = new ArrayList<>();
+
+ private List receivers(Subject about, Subject also, Reach rules) {
+ List got = new ArrayList<>();
+ Announcements.deliver(about.name() + " died", about, also, online, rules, v -> got.add(v.name()), console::add);
+ got.sort(null);
+ return got;
+ }
+
+ @Test
+ void aKidsDeathLineReachesTheirCircleTheVisitorAndBypassButNoAdult() {
+ assertEquals(List.of("kid", "moderator", "otherKid", "visitor"), receivers(kid, null, reach));
+ }
+
+ @Test
+ void anAdultsDeathLineReachesNoKid() {
+ assertEquals(List.of("adult", "moderator", "otherAdult", "visitor"), receivers(adult, null, reach));
+ }
+
+ @Test
+ void theConsoleAlwaysGetsTheLineOnce() {
+ receivers(kid, null, reach);
+ assertEquals(List.of("kid died"), console);
+ }
+
+ @Test
+ void pausedRulesReachOnlyThePlayerAndBypass() {
+ assertEquals(List.of("kid", "moderator"), receivers(kid, null, null));
+ assertEquals(List.of("kid died"), console);
+ }
+
+ @Test
+ void aNullMessageSendsNothingAnywhere() {
+ List got = new ArrayList<>();
+ assertEquals(0, Announcements.deliver(null, kid, null, online, reach, v -> got.add(v.name()), console::add));
+ assertEquals(List.of(), got);
+ assertEquals(List.of(), console);
+ }
+
+ @Test
+ void aLineThatNamesAKillerNeedsBothToBeInReach() {
+ // The visitor is slain by an adult. The kids share a circle with the visitor, but may not learn the adult's name.
+ assertEquals(List.of("adult", "moderator", "otherAdult", "visitor"), receivers(visitor, adult, reach));
+ // The player it is about always gets it, even when they can't reach whoever it names.
+ assertTrue(Announcements.mayHear(kid, reach, kid, adult));
+ assertTrue(Announcements.mayHear(adult, reach, visitor, adult));
+ }
+
+ @Test
+ void aPendingPlayerHearsOnlyTheirOwnLineAndNobodyHearsTheirs() {
+ Subject fresh = pending("fresh", "kidland", circle("kids"));
+ assertFalse(Announcements.mayHear(fresh, reach, kid, null));
+ assertFalse(Announcements.mayHear(otherKid, reach, fresh, null));
+ assertTrue(Announcements.mayHear(fresh, reach, fresh, null));
+ }
+
+ @Test
+ void aViewerPosseCannotWorkOutGetsNothing() {
+ Subject broken = new Subject() {
+ @Override public UUID id() { return UUID.nameUUIDFromBytes("broken".getBytes()); }
+ @Override public String name() { return "broken"; }
+ @Override public String world() { throw new IllegalStateException("no world"); }
+ @Override public boolean has(String permission) { throw new IllegalStateException("no permissions"); }
+ };
+ assertFalse(Announcements.mayHear(broken, reach, kid, null));
+ assertFalse(Announcements.mayHear(broken, null, kid, null));
+ // The others still get theirs.
+ List got = new ArrayList<>();
+ Announcements.deliver("kid died", kid, null, List.of(broken, otherKid), reach, v -> got.add(v.name()), console::add);
+ assertEquals(List.of("otherKid"), got);
+ }
+
+ @Test
+ void aLinePosseCannotWorkOutStillReachesThePlayerAndBypassOnly() {
+ // The player the line is about can't be read: nobody in their circle can be sure, so only they and bypass get it.
+ Subject unreadable = new Subject() {
+ @Override public UUID id() { return UUID.nameUUIDFromBytes("unreadable".getBytes()); }
+ @Override public String name() { return "unreadable"; }
+ @Override public String world() { throw new IllegalStateException("no world"); }
+ @Override public boolean has(String permission) { throw new IllegalStateException("no permissions"); }
+ };
+ assertTrue(Announcements.mayHear(unreadable, reach, unreadable, null));
+ assertTrue(Announcements.mayHear(moderator, reach, unreadable, null));
+ assertFalse(Announcements.mayHear(otherKid, reach, unreadable, null));
+ assertFalse(Announcements.mayHear(adult, reach, unreadable, null));
+ }
+
+ @Test
+ void withNoCirclesEveryoneHearsAsInVanilla() {
+ Reach off = new Reach(List.of(), Set.of(), Map.of(), List.of());
+ assertEquals(7, receivers(kid, null, off).size());
+ }
+}
diff --git a/src/test/java/com/extantape/posse/rules/CommandRulesTest.java b/src/test/java/com/extantape/posse/rules/CommandRulesTest.java
index d8f1c17..7e2a6e0 100644
--- a/src/test/java/com/extantape/posse/rules/CommandRulesTest.java
+++ b/src/test/java/com/extantape/posse/rules/CommandRulesTest.java
@@ -140,4 +140,15 @@ void maskingIsOffUnlessTurnedOn() {
add(player("Kid", "forest"));
assertNull(run(adult, "/msg Kid heck").rewrite());
}
+
+ @Test
+ void thePlayerListCommandIsRecognizedInEveryForm() {
+ // K832: /list names everyone online, so it follows presence.
+ for (String line : List.of("/list", "list", "/LIST", "/minecraft:list", "/essentials:list", "/list uuids")) {
+ org.junit.jupiter.api.Assertions.assertTrue(CommandRules.isPlayerList(line), line);
+ }
+ for (String line : List.of("/listen", "/playerlist", "/msg list", "/", "")) {
+ org.junit.jupiter.api.Assertions.assertFalse(CommandRules.isPlayerList(line), line);
+ }
+ }
}
diff --git a/src/test/java/com/extantape/posse/rules/NameSuggestionsTest.java b/src/test/java/com/extantape/posse/rules/NameSuggestionsTest.java
new file mode 100644
index 0000000..41eb944
--- /dev/null
+++ b/src/test/java/com/extantape/posse/rules/NameSuggestionsTest.java
@@ -0,0 +1,77 @@
+package com.extantape.posse.rules;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import static com.extantape.posse.rules.Players.circle;
+import static com.extantape.posse.rules.Players.pending;
+import static com.extantape.posse.rules.Players.player;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/** K832: which names Tab may offer. Kids and adults stand in different worlds and share no circle. */
+class NameSuggestionsTest {
+ private final Reach reach = new Reach(List.of("kids", "adults"), Set.of("station"), Map.of(), List.of("_nether", "_the_end"));
+ private final Subject kid = player("Kid", "kidland", circle("kids"));
+ private final Subject otherKid = player("OtherKid", "kidland_nether", circle("kids"));
+ private final Subject adult = player("Adult", "grownups", circle("adults"));
+ private final Subject visitor = player("Visitor", "grownups", circle("adults"), circle("kids"));
+ private final Subject moderator = player("Moderator", "grownups", Reach.BYPASS);
+ private final List online = List.of(kid, otherKid, adult, visitor, moderator);
+
+ @Test
+ void anAdultIsOfferedNoKidAndAKidNoAdult() {
+ assertEquals(Set.of("kid", "otherkid"), NameSuggestions.withheld(adult, online, reach));
+ assertEquals(Set.of("adult"), NameSuggestions.withheld(kid, online, reach));
+ }
+
+ @Test
+ void theVisitorAndBypassAreOfferedEveryone() {
+ assertEquals(Set.of(), NameSuggestions.withheld(visitor, online, reach));
+ assertEquals(Set.of(), NameSuggestions.withheld(moderator, online, reach));
+ }
+
+ @Test
+ void pausedRulesOfferOnlyYourOwnNameUnlessYouHaveBypass() {
+ assertEquals(Set.of("otherkid", "adult", "visitor", "moderator"), NameSuggestions.withheld(kid, online, null));
+ assertEquals(Set.of(), NameSuggestions.withheld(moderator, online, null));
+ }
+
+ @Test
+ void aPendingPlayerIsOfferedToNobodyAndOfferedNobody() {
+ Subject fresh = pending("Fresh", "kidland", circle("kids"));
+ assertTrue(NameSuggestions.withheld(otherKid, List.of(otherKid, fresh), reach).contains("fresh"));
+ assertEquals(Set.of("otherkid"), NameSuggestions.withheld(fresh, List.of(otherKid, fresh), reach));
+ }
+
+ @Test
+ void anAskerPosseCannotWorkOutIsOfferedNobodyElse() {
+ Subject broken = new Subject() {
+ @Override public UUID id() { return UUID.nameUUIDFromBytes("broken".getBytes()); }
+ @Override public String name() { return "Broken"; }
+ @Override public String world() { throw new IllegalStateException("no world"); }
+ @Override public boolean has(String permission) { throw new IllegalStateException("no permissions"); }
+ };
+ assertEquals(Set.of("kid", "otherkid", "adult", "visitor", "moderator"), NameSuggestions.withheld(broken, online, reach));
+ assertEquals(Set.of("kid", "otherkid", "adult", "visitor", "moderator"), NameSuggestions.withheld(broken, online, null));
+ }
+
+ @Test
+ void namesAreTakenOutInAnyLetterCaseAndInQuotesAndEverythingElseStays() {
+ Set withheld = NameSuggestions.withheld(adult, online, reach);
+ List offered = List.of("@a", "Adult", "Kid", "kid", "\"OtherKid\"", "'kid'", "Kidney", "Visitor", "survival");
+ assertEquals(List.of("@a", "Adult", "Kidney", "Visitor", "survival"), NameSuggestions.keep(offered, withheld));
+ assertFalse(NameSuggestions.isWithheld(null, withheld));
+ }
+
+ @Test
+ void withNoCirclesNothingIsWithheld() {
+ Reach off = new Reach(List.of(), Set.of(), Map.of(), List.of());
+ assertEquals(Set.of(), NameSuggestions.withheld(adult, online, off));
+ }
+}
diff --git a/src/test/java/com/extantape/posse/rules/PresenceTest.java b/src/test/java/com/extantape/posse/rules/PresenceTest.java
index 646818f..59ce44c 100644
--- a/src/test/java/com/extantape/posse/rules/PresenceTest.java
+++ b/src/test/java/com/extantape/posse/rules/PresenceTest.java
@@ -64,4 +64,13 @@ void pausedRulesShowNobodyButYourself() {
assertFalse(Presence.maySee(adult, kid, true, null));
assertTrue(Presence.maySee(kid, kid, true, null));
}
+
+ @Test
+ void aPlayerOutOfSightIsKeptFromTheGameUnlessTheyStandInTheSameWorld() {
+ // K832: a game offers every player it knows on Tab, so only someone the viewer may see, or can see walk by, is known.
+ assertTrue(Presence.mayKnowOf(true, false));
+ assertTrue(Presence.mayKnowOf(true, true));
+ assertTrue(Presence.mayKnowOf(false, true));
+ assertFalse(Presence.mayKnowOf(false, false));
+ }
}
diff --git a/test/live/README.md b/test/live/README.md
index e777c7d..c964444 100644
--- a/test/live/README.md
+++ b/test/live/README.md
@@ -42,6 +42,7 @@ It takes about 4 minutes. The summary lists failures and skipped checks. The ful
| Join and leave lines | `presence-messages.js`, run with `POSSE_SUITE=presence-messages.js test/live/run.sh ` (about 1 minute): six made-up players join and leave in turn, first with `presence: everyone` as a control, then `reach`. Each line is read from mineflayer's text events and from the raw chat packets, and both must match. The main suite's presence part also covers it. |
| Book authors | `book-authors.js`, run with `POSSE_SUITE=book-authors.js POSSE_PORT=25733 test/live/run.sh `: a kid's signed book is dropped and picked up by an adult (sees Unknown), a same-circle kid, the visitor in both circles and a player in no circle; a quest-journal-style book with the name in its title; a chest opened by an adult and by a kid; the true author coming back when a circle is granted; the settings. A bot can't read a tooltip, so each check reads the server's own copy of the book, which is what the client is sent. Item frames and lecterns aren't driven. |
| Home worlds | `home-worlds.js`, run with `POSSE_SUITE=home-worlds.js test/live/run.sh ` (about 2 minutes): five made-up players leave in different worlds, then rejoin, die and respawn, and are teleported around. Kids end up only in kids' worlds, the visitor and an adult are left alone, a player with no circle waits in the station, a missing fallback lands in the main world, and with the section removed nothing moves. Run it with a port in your own range, such as `POSSE_PORT=25733`. |
+| Reach leaks (K832) | `reach-leaks.js`, run with `POSSE_SUITE=reach-leaks.js test/live/run.sh ` (about 3 minutes): seven made-up players in a kids' circle, an adults' circle, both, bypass, and no circle. With no circles first as a control, then with circles and `presence: reach`: who is sent a death line and an advancement line, which names Tab offers after seven commands (vanilla, namespaced and a test plugin's own completer), which players each bot's game was told about, `/list` in three forms, the server list sample, a returning kid moved on join, a kid disconnected while joining, and the dead player's own death screen. Each part checks a refused pair, an allowed pair and bypass, and then all of it again with a config Posse can't read, so the rules are paused. `POSSE_JAR=` runs it against an older release; on 0.11.1 the refused checks fail. A bot has no Tab menu of its own, so the names a real game would offer by itself are read from the players the bot's game was told about. |
| `/circles` | Lists your circles and exactly who can hear you, a count without `posse.circles.names`, and an explanation in a circle-only world. |
| Commands | Blocked commands in plain, namespaced and mixed-case forms, unlisted ones passing, `/me` off except with bypass. |
| Replies | `/r` with nobody to reply to, and after the other player moves out of reach. |
@@ -58,4 +59,4 @@ It takes about 4 minutes. The summary lists failures and skipped checks. The ful
## The test-only plugins
-`helper/` makes worlds, moves players, gives items and reports TPS, with one console command, `/mt`. 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. 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.
diff --git a/test/live/helper/src/main/java/com/extantape/posse/livetest/LiveTestHelper.java b/test/live/helper/src/main/java/com/extantape/posse/livetest/LiveTestHelper.java
index 4c92c4b..34d80f9 100644
--- a/test/live/helper/src/main/java/com/extantape/posse/livetest/LiveTestHelper.java
+++ b/test/live/helper/src/main/java/com/extantape/posse/livetest/LiveTestHelper.java
@@ -35,6 +35,8 @@
* mt clear empties the player's inventory
* mt books prints "HRT books /;..." for each written book carried
* mt chest puts the first-slot item in a chest at the player's spot, opens it for them and prints "HRT chest ..."
+ * And one command any player may use, mtwho , which does nothing but offer every online player's name on Tab,
+ * hidden or not: a stand-in for a plugin whose completer knows nothing of Posse (K832).
*/
public final class LiveTestHelper extends JavaPlugin implements Listener {
/** Bots stand still in made-up worlds, so a death only means a bad spawn point. Keep them alive, and say if one dies anyway. */
@@ -94,6 +96,14 @@ public void onStallJoin(org.bukkit.event.player.PlayerJoinEvent event) {
@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
+ getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, event -> event.registrar().register(Commands.literal("mtwho")
+ .then(Commands.argument("name", StringArgumentType.word())
+ .suggests((ctx, builder) -> {
+ for (Player p : Bukkit.getOnlinePlayers()) builder.suggest(p.getName());
+ return builder.buildFuture();
+ })
+ .executes(ctx -> 1))
+ .build()));
getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, event -> event.registrar().register(Commands.literal("mt")
.requires(src -> src.getSender().isOp() || !(src.getSender() instanceof Player))
.then(Commands.literal("world").then(Commands.argument("name", StringArgumentType.word()).executes(ctx -> {
diff --git a/test/live/reach-leaks.js b/test/live/reach-leaks.js
new file mode 100644
index 0000000..1a96f00
--- /dev/null
+++ b/test/live/reach-leaks.js
@@ -0,0 +1,288 @@
+// K832: every way the server would tell one player another's name follows reach. Death and advancement lines, the
+// names Tab offers, the names a player's game is told about, /list, the server list sample, and a player disconnected
+// while joining. See README.md in this folder. Usage: node reach-leaks.js , relative to the work folder.
+// Run it with POSSE_SUITE=reach-leaks.js test/live/run.sh . All names are made up.
+//
+// Each part checks a pair that must be refused, a pair that is allowed, a player with posse.bypass, and Posse unable
+// to decide (the rules paused by a config it can't read). A control with no circles shows the test can see a line
+// when one is sent. On Posse 0.11.1 the refused checks fail: that is the bug this test was written for.
+const mc = require('minecraft-protocol');
+const { sleep, check, section, summary, Server, Bot } = require('./lib.js');
+const [dir, jar, port] = process.argv.slice(2);
+
+const CONFIG = `circles: [kids, adults]
+circle-only-worlds: [station]
+presence: reach
+home-worlds:
+ kids:
+ worlds: [kidland]
+ fallback: kidland
+ no-circle:
+ fallback: station
+`;
+// K = kids' circle, A = adults', V = both, M = an adult moderator with posse.bypass, X = no circle, waiting in the station.
+const PEOPLE = {
+ K1: { circles: ['kids'], world: 'kidland' },
+ K2: { circles: ['kids'], world: 'kidland' },
+ A1: { circles: ['adults'], world: 'grownups' },
+ A2: { circles: ['adults'], world: 'grownups' },
+ V1: { circles: ['kids', 'adults'], world: 'grownups' },
+ M1: { circles: ['adults'], bypass: true, world: 'grownups' },
+ X1: { circles: [], world: 'station' },
+};
+const NAMES = Object.keys(PEOPLE);
+// Two returning kids who logged out in the adults' world before the rules were on. K3's move is blocked, K4's is not.
+const LATE = ['K3', 'K4'];
+let s; const bots = {};
+
+async function join(n) { bots[n] = new Bot(n, +port); await bots[n].spawned; await sleep(1200); }
+async function reload() { return s.run('posse reload', /\[Posse\] (Reloaded|The config has problems, so nothing changed|The config still has problems)[^\n]*/, 10000); }
+async function where(n) { const m = await s.run(`mt where ${n}`, new RegExp(`HRT where ${n} (\\S+)`), 5000); return m ? m[1] : null; }
+async function tp(n, w) { await s.run(`mt tp ${n} ${w}`, new RegExp(`HRT tp ${n} ${w} (true|false)`), 10000); await sleep(1500); }
+const named = (name) => new RegExp(`\\b${name}\\b`);
+const marks = () => Object.fromEntries(NAMES.filter((n) => bots[n]).map((n) => [n, [bots[n].mark(), bots[n].rawMark()]]));
+/** Who was sent any chat line naming the player since the marks: by mineflayer's text and by the raw packets. */
+function sentTo(name, m) {
+ const got = [];
+ for (const n of Object.keys(m)) if (bots[n].heard(named(name), m[n][0]) || bots[n].rawHeard(named(name), m[n][1])) got.push(n);
+ return got.sort();
+}
+/** The first line naming the player that one of the receivers got, so a failure says which line leaked. */
+function lineFor(name, m, got) {
+ for (const n of got) {
+ const t = bots[n].lines(m[n][0]).find((x) => named(name).test(x));
+ if (t) return `${n} got: ${t.slice(0, 120)}`;
+ const r = bots[n].raw.slice(m[n][1]).find((x) => named(name).test(x.m));
+ if (r) return `${n} got ${r.n}: ${r.m.slice(0, 160)}`;
+ }
+ return '';
+}
+const same = (a, b) => a.length === b.length && a.every((x, i) => x === b[i]);
+const without = (list, names) => names.every((n) => !list.includes(n));
+const withAll = (list, names) => names.every((n) => list.includes(n));
+
+/** The names Tab offers after the text, as the server answers. No answer at all counts as nothing offered. */
+async function offered(n, text) {
+ let got = null;
+ try { got = await bots[n].bot.tabComplete(text, false, false, 2500); } catch { got = []; }
+ return (got || []).map((x) => (typeof x === 'string' ? x : x.match || '')).filter((x) => NAMES.includes(x) || LATE.includes(x));
+}
+/** Every player this bot's game has been told about, listed or not. A real game offers all of these on Tab by itself. */
+const knownTo = (n) => Object.keys(bots[n].bot.players).filter((x) => x !== n).sort();
+const listedTo = (viewer, other) => { const p = bots[viewer].bot.players[other]; return !!p && (p.listed === undefined || Boolean(p.listed)); };
+/** Sends a command and returns the lines the player got back. */
+async function ask(n, command, ms = 1800) { const m = bots[n].mark(); bots[n].say(command); await sleep(ms); return bots[n].lines(m).join(' | '); }
+async function sample() {
+ try {
+ const r = await mc.ping({ host: '127.0.0.1', port: +port, version: '1.21.11' });
+ return { online: r.players && r.players.online, names: ((r.players && r.players.sample) || []).map((p) => p.name) };
+ } catch (e) { return { online: null, names: ['PING FAILED ' + e.message] }; }
+}
+async function die(n) {
+ const m = marks(), c = s.mark();
+ let screen = null;
+ const onScreen = (d) => { screen = JSON.stringify(d.message === undefined ? d : d.message); };
+ bots[n].bot._client.on('death_combat_event', onScreen);
+ await s.run(`mt grave ${n} 0`, new RegExp(`HRT planned death ${n}`), 8000);
+ await sleep(3000);
+ bots[n].bot._client.removeListener('death_combat_event', onScreen);
+ return { got: sentTo(n, m), console: new RegExp(`\\b${n} died`).test(s.since(c)), screen };
+}
+async function advance(n) {
+ await s.run(`advancement revoke ${n} only minecraft:story/mine_stone`, null);
+ await sleep(500);
+ const m = marks(), c = s.mark();
+ await s.run(`advancement grant ${n} only minecraft:story/mine_stone`, null);
+ await sleep(2500);
+ return { got: sentTo(n, m), console: new RegExp(`\\b${n} has made the advancement`).test(s.since(c)) };
+}
+const TAB = ['/msg ', '/tell ', '/w ', '/minecraft:msg ', '/minecraft:tell ', '/minecraft:w ', '/mtwho '];
+
+(async () => {
+ s = new Server(dir, jar);
+ await s.start();
+
+ section('Setup: made-up worlds and players, before any circles');
+ for (const w of ['kidland', 'grownups', 'station']) await s.run(`mt world ${w}`, new RegExp(`HRT world (${w}|FAILED)`), 60000);
+ // Paper keeps the server's own /list for ops unless the permission is given. Give it to everyone, as a server might.
+ await s.run('lp group default permission set minecraft.command.list true', null);
+ for (const n of [...NAMES, ...LATE]) await join(n);
+ for (const [n, p] of Object.entries(PEOPLE)) {
+ for (const c of p.circles) await s.run(`lp user ${n} permission set posse.circle.${c} true`, null);
+ if (p.bypass) await s.run(`lp user ${n} permission set posse.bypass true`, null);
+ }
+ for (const n of LATE) await s.run(`lp user ${n} permission set posse.circle.kids true`, null);
+ await sleep(1000);
+ for (const [n, p] of Object.entries(PEOPLE)) await tp(n, p.world);
+ for (const n of LATE) { await tp(n, 'grownups'); bots[n].quit(); delete bots[n]; }
+ await sleep(2500);
+
+ section('Control: with no circles nothing is filtered, and the test sees every line');
+ let d = await die('K1');
+ check('control: a death line reaches everyone', same(d.got, NAMES.slice().sort()), d.got.join(' '));
+ let a = await advance('K1');
+ check('control: an advancement line reaches everyone', same(a.got, NAMES.slice().sort()), a.got.join(' '));
+ let o = await offered('A1', '/msg ');
+ check('control: Tab after /msg offers every player', withAll(o, NAMES), o.join(' '));
+ o = await offered('A1', '/mtwho ');
+ check('control: Tab after a plugin command offers every player', withAll(o, NAMES), o.join(' '));
+ let l = await ask('K1', '/list');
+ check('control: /list names everyone', NAMES.every((n) => named(n).test(l)), l.slice(0, 200));
+ let p = await sample();
+ check('control: the server list sample names players', p.names.some((n) => NAMES.includes(n)) && p.online === NAMES.length, `${p.online} online, ${p.names.length} in the sample`);
+ await tp('K1', 'kidland');
+
+ section('Circles on, presence: reach');
+ s.writeConfig('config.yml', CONFIG);
+ check('reload applies the rules', /Reloaded/.test((await reload() || [''])[0]));
+ await sleep(3000);
+ const m0 = s.mark();
+
+ section('Death lines follow reach');
+ d = await die('K1');
+ check('refused: a kid\'s death line reaches no adult outside their circle, and nobody in no circle', without(d.got, ['A1', 'A2', 'X1']), d.got.join(' '));
+ check('allowed: it reaches the kid, their circle-mate and the visitor in both circles', withAll(d.got, ['K1', 'K2', 'V1']), d.got.join(' '));
+ check('bypass: it reaches a player with posse.bypass', d.got.includes('M1'), d.got.join(' '));
+ check('the console and log keep the kid\'s death line', d.console);
+ check('the kid\'s own death screen still says how they died', !!d.screen && /death\.|died|\bK1\b/.test(d.screen), (d.screen || 'no death screen packet').slice(0, 120));
+ check('the kid respawns in the kids\' world', (await where('K1')) === 'kidland', await where('K1'));
+ d = await die('A1');
+ check('refused: an adult\'s death line reaches no kid, and nobody in no circle', without(d.got, ['K1', 'K2', 'X1']), d.got.join(' '));
+ check('allowed: it reaches the adult, their circle-mate and the visitor', withAll(d.got, ['A1', 'A2', 'V1']), d.got.join(' '));
+ check('the console and log keep the adult\'s death line', d.console);
+ await tp('A1', 'grownups');
+
+ section('Advancement lines follow reach');
+ a = await advance('K2');
+ check('refused: a kid\'s advancement line reaches no adult outside their circle', without(a.got, ['A1', 'A2', 'X1']), a.got.join(' '));
+ check('allowed and bypass: it reaches the kid, their circle-mate, the visitor and bypass', withAll(a.got, ['K1', 'K2', 'V1', 'M1']), a.got.join(' '));
+ check('the console and log keep the advancement line', a.console);
+ a = await advance('A2');
+ check('refused: an adult\'s advancement line reaches no kid', without(a.got, ['K1', 'K2', 'X1']), a.got.join(' '));
+ check('allowed: it reaches the adult, their circle-mate and the visitor', withAll(a.got, ['A1', 'A2', 'V1']), a.got.join(' '));
+
+ section('Tab offers only names in reach, for every command');
+ const bad = [], thin = [];
+ for (const t of TAB) {
+ const forAdult = await offered('A1', t), forKid = await offered('K1', t), forMod = await offered('M1', t);
+ if (!without(forAdult, ['K1', 'K2', 'X1'])) bad.push(`${t}to A1: ${forAdult.join(' ')}`);
+ if (!without(forKid, ['A1', 'A2', 'X1'])) bad.push(`${t}to K1: ${forKid.join(' ')}`);
+ if (!withAll(forAdult, ['A2', 'V1', 'M1'])) thin.push(`${t}to A1: ${forAdult.join(' ')}`);
+ if (!withAll(forKid, ['K2', 'V1', 'M1'])) thin.push(`${t}to K1: ${forKid.join(' ')}`);
+ if (!withAll(forMod, ['K1', 'K2', 'A1', 'A2', 'V1', 'X1'])) thin.push(`${t}to M1: ${forMod.join(' ')}`);
+ }
+ check(`refused: Tab offers an adult no kid, and a kid no adult (${TAB.length} commands, namespaced and a plugin's)`, bad.length === 0, bad.slice(0, 6).join('; '));
+ check('allowed and bypass: the circle-mate, the visitor and bypass are still offered, and bypass is offered everyone', thin.length === 0, thin.slice(0, 6).join('; '));
+
+ section('A player\'s game is told nothing about players out of reach');
+ // A real game offers every player it has been told about when Tab is pressed, in chat or after a command, without
+ // asking the server. A bot has no such menu, so this reads what the bot's game was told.
+ check('refused: an adult\'s game knows no kid and nobody in no circle', without(knownTo('A1'), ['K1', 'K2', 'X1']), knownTo('A1').join(' '));
+ check('refused: a kid\'s game knows no adult outside their circle', without(knownTo('K1'), ['A1', 'A2', 'X1']), knownTo('K1').join(' '));
+ check('allowed: each still knows and lists their circle-mate, the visitor and bypass',
+ ['A2', 'V1', 'M1'].every((n) => listedTo('A1', n)) && ['K2', 'V1', 'M1'].every((n) => listedTo('K1', n)), `A1: ${knownTo('A1').join(' ')}; K1: ${knownTo('K1').join(' ')}`);
+ check('bypass: a player with posse.bypass knows everyone', withAll(knownTo('M1'), NAMES.filter((n) => n !== 'M1')), knownTo('M1').join(' '));
+ await tp('A2', 'station');
+ await sleep(2500);
+ check('in the same circle-only world, a player with no shared circle can be seen but is not listed', knownTo('A2').includes('X1') && !listedTo('A2', 'X1'), knownTo('A2').join(' '));
+ o = await offered('A2', '/msg ');
+ check('and Tab still does not offer them', !o.includes('X1'), o.join(' '));
+ await tp('A2', 'grownups');
+ await sleep(2500);
+ check('back in another world, the game is told to forget them', !knownTo('A2').includes('X1') && listedTo('A2', 'A1'), knownTo('A2').join(' '));
+ await s.run('lp user K2 permission set posse.circle.adults true', null);
+ await sleep(4000);
+ check('a circle granted shows the player within seconds, no relog', listedTo('A1', 'K2') && listedTo('K2', 'A1'));
+ await s.run('lp user K2 permission unset posse.circle.adults', null);
+ await sleep(4000);
+ check('and taking it away removes them again', !knownTo('A1').includes('K2') && !knownTo('K2').includes('A1'), knownTo('A1').join(' '));
+ bots.A2.quit();
+ await sleep(2000);
+ await join('A2');
+ await sleep(1500);
+ check('refused: an adult who joins is told of no kid, and no kid is told of them', without(knownTo('A2'), ['K1', 'K2', 'X1']) && !knownTo('K1').includes('A2') && !knownTo('K2').includes('A2'), `A2: ${knownTo('A2').join(' ')}; K1: ${knownTo('K1').join(' ')}`);
+ check('allowed: they and their circle-mate know and list each other', listedTo('A2', 'A1') && listedTo('A1', 'A2'));
+
+ section('/list follows reach');
+ for (const c of ['/list', '/minecraft:list', '/list uuids']) {
+ l = await ask('K1', c);
+ check(`refused: ${c} names no adult to a kid`, !/\b(A1|A2|X1)\b/.test(l), l.slice(0, 200));
+ check(`allowed: ${c} tells the kid who can hear them`, /can hear you/.test(l) && /\bK2\b/.test(l), l.slice(0, 200));
+ }
+ l = await ask('A1', '/list');
+ check('refused: /list names no kid to an adult', !/\b(K1|K2|X1)\b/.test(l) && /\bA2\b/.test(l), l.slice(0, 200));
+ l = await ask('M1', '/list');
+ check('bypass: /list still names everyone to a player with posse.bypass', NAMES.every((n) => named(n).test(l)), l.slice(0, 200));
+
+ section('The server list shows a count and no names');
+ p = await sample();
+ check('the sample is empty and the count is kept', p.names.length === 0 && p.online === NAMES.length, `${p.online} online, sample: ${p.names.join(' ') || 'empty'}`);
+
+ section('A returning player who must be moved is announced only once they are where they may be');
+ let m = marks();
+ await join('K4');
+ await sleep(2500);
+ check('a returning kid who logged out in the adults\' world is moved to the kids\' world', (await where('K4')) === 'kidland', await where('K4'));
+ let got = sentTo('K4', m);
+ check('refused: no adult outside their circle is told they joined', without(got, ['A1', 'A2', 'X1']), `${got.join(' ')} ${lineFor('K4', m, got.filter((n) => ['A1', 'A2', 'X1'].includes(n)))}`);
+ check('allowed and bypass: their circle, the visitor and bypass are told, after the move', withAll(got, ['K1', 'K2', 'V1', 'M1']), got.join(' '));
+ bots.K4.quit(); delete bots.K4;
+ await sleep(2000);
+
+ section('A player disconnected while joining is never announced');
+ await s.run('mt blocktp K3', /HRT blocktp set/, 5000);
+ m = marks();
+ const km = s.mark();
+ bots.K3 = new Bot('K3', +port); bots.K3.spawned.catch(() => {});
+ const end = Date.now() + 10000;
+ while (Date.now() < end && !bots.K3.ended) await sleep(200);
+ check('a kid whose move out of the adults\' world fails is disconnected with a kind line', !!bots.K3.ended && /join again/.test(bots.K3.kicked || ''), bots.K3.kicked || bots.K3.ended);
+ await sleep(1500);
+ got = sentTo('K3', m);
+ check('refused: nobody at all was sent a join, leave or any other line naming them', got.length === 0, `${got.join(' ')} ${lineFor('K3', m, got)}`);
+ check('no game was told about them', NAMES.every((n) => !knownTo(n).includes('K3')), NAMES.filter((n) => knownTo(n).includes('K3')).join(' '));
+ check('the console and log say what happened', /didn't go through, so the player was disconnected/.test(s.since(km)));
+ delete bots.K3;
+
+ let errors = s.errors(m0).filter((e) => !/home-worlds move on join didn't go through/.test(e));
+ check('no errors in the log', errors.length === 0, errors.slice(0, 4).join(' || '));
+
+ section('Posse unable to decide: a config it can\'t read at startup pauses the rules');
+ NAMES.forEach((n) => bots[n].quit());
+ await sleep(1500);
+ await s.stop();
+ s.writeConfig('config.yml', 'circles: [kids\nnope: : :');
+ await s.start();
+ check('the console explains the pause', /chat and private messages are paused until it's fixed/.test(s.log));
+ // The made-up worlds are loaded by the helper, so load them again before anyone rejoins where they left.
+ for (const w of ['kidland', 'grownups', 'station']) await s.run(`mt world ${w}`, new RegExp(`HRT world (${w}|FAILED)`), 60000);
+ for (const n of NAMES) await join(n);
+ check('everyone is back in their own world', (await where('K2')) === 'kidland' && (await where('A2')) === 'grownups', `${await where('K2')} ${await where('A2')}`);
+ await sleep(3000);
+ const forAdult = [], forMod = [];
+ for (const t of TAB) { forAdult.push(...await offered('A1', t)); forMod.push(...await offered('M1', t)); }
+ check('paused: Tab offers an adult nobody but themself, whatever the command', forAdult.every((n) => n === 'A1'), [...new Set(forAdult)].join(' '));
+ check('paused, bypass: a player with posse.bypass is still offered everyone', withAll(forMod, NAMES), [...new Set(forMod)].join(' '));
+ check('paused: an adult\'s game knows no kid, and a kid\'s no adult', without(knownTo('A2'), ['K1', 'K2', 'X1']) && without(knownTo('K2'), ['A1', 'A2', 'V1', 'M1', 'X1']), `A2: ${knownTo('A2').join(' ')}; K2: ${knownTo('K2').join(' ')}`);
+ check('paused: nobody is listed to anyone else', NAMES.every((v) => NAMES.every((n) => v === n || !listedTo(v, n))));
+ l = await ask('K1', '/list');
+ check('paused: /list names nobody', !NAMES.some((n) => n !== 'K1' && named(n).test(l)) && /paused/.test(l), l.slice(0, 200));
+ p = await sample();
+ check('paused: the server list sample is empty', p.names.length === 0, p.names.join(' '));
+ a = await advance('K2');
+ check('paused: an advancement line reaches only the player and bypass', same(a.got, ['K2', 'M1']), a.got.join(' '));
+ d = await die('K1');
+ check('paused: a death line reaches only the dead player and bypass, not even a circle-mate', same(d.got, ['K1', 'M1']), d.got.join(' '));
+ check('paused: the console and log still keep the death line', d.console);
+ errors = s.errors(0).filter((e) => !/\[Posse\]/.test(e));
+ check('no errors in the log beyond the config problem', errors.length === 0, errors.slice(0, 4).join(' || '));
+
+ NAMES.forEach((n) => bots[n].quit());
+ await s.stop();
+ process.exit(summary() ? 1 : 0);
+})().catch(async (e) => {
+ console.error('CRASHED', e);
+ try { Object.values(bots).forEach((b) => b.quit()); await s.stop(); } catch { }
+ summary();
+ process.exit(1);
+});
diff --git a/test/live/run.sh b/test/live/run.sh
index 1914d6c..9f5ed49 100755
--- a/test/live/run.sh
+++ b/test/live/run.sh
@@ -2,7 +2,8 @@
# Builds one throwaway Paper server on 127.0.0.1, runs the Posse acceptance tests, and deletes it, even when
# a test fails. See README.md in this folder.
# Usage: POSSE_ACCEPT_EULA=1 test/live/run.sh
-# POSSE_SUITE=presence-messages.js runs only the join and leave message check; home-worlds.js runs the home-worlds check; book-authors.js runs the book author check (default suite.js).
+# POSSE_SUITE=presence-messages.js runs only the join and leave message check; home-worlds.js runs the home-worlds check; book-authors.js runs the book author check; reach-leaks.js runs the death line, Tab and /list checks (default suite.js).
+# POSSE_JAR= tests that Posse jar, such as an older release, with this folder's tests (default: the one built here).
set -euo pipefail
HERE=$(cd "$(dirname "$0")" && pwd)
REPO=$(cd "$HERE/../.." && pwd)
@@ -15,7 +16,7 @@ if [ "${POSSE_ACCEPT_EULA:-}" != "1" ]; then
echo "Set POSSE_ACCEPT_EULA=1 to accept it."
exit 2
fi
-JAR=$(ls "$REPO"/build/libs/Posse-*.jar 2>/dev/null | head -1)
+JAR=${POSSE_JAR:-$(ls -t "$REPO"/build/libs/Posse-*.jar 2>/dev/null | head -1)}
HELPER=$REPO/test/live/helper/build/libs/LiveTestHelper.jar
FAKEMAP=$REPO/test/live/fakeminimap/build/libs/LiveTestFakeMinimap.jar
missing=0