feat(events): audit account aura preferences
Release / release (push) Successful in 14m40s

This commit is contained in:
dmg committed 2026-09-25 09:37:45 -04:00
1 parent ec73018f93
commit 39c58ef4d9
4 files changed
+233 -23

No files matched your search

@@ -47,15 +47,17 @@ public final class PreferenceEventBridge {
var action = new Action(UUID.randomUUID(), clock.instant(), new EventInput.Context(player.getUniqueId(),
player.getName(), record == null ? null : record.id(), record == null ? null : record.name(),
record == null ? null : active.session(), location), key, before,
preferences.savedAllParticlesEnabled(player.getUniqueId()), requested, "player");
key.equals("player-aura-particles") ? preferences.savedPlayerAurasEnabled(player.getUniqueId())
: preferences.savedAllParticlesEnabled(player.getUniqueId()), requested, "player");
emit("action.observed", action, "observed", null, null, before, false);
return action;
}
public void refuseNonPlayer(org.bukkit.command.CommandSender sender) {
public void refuseNonPlayer(org.bukkit.command.CommandSender sender, String key) {
var kind = sender instanceof org.bukkit.command.ConsoleCommandSender ? "console"
: sender instanceof org.bukkit.command.BlockCommandSender ? "command_block" : "system";
var action = new Action(UUID.randomUUID(), clock.instant(), null, "all-particles", true, true, null, kind);
boolean initial = !key.equals("player-aura-particles");
var action = new Action(UUID.randomUUID(), clock.instant(), null, key, initial, initial, null, kind);
emit("action.observed", action, "observed", null, null, true, false);
emit("action.resolved", action, "refused", "player_required", null, true, false);
}
@@ -70,6 +72,7 @@ public final class PreferenceEventBridge {
fields.put("before", Boolean.toString(action.before()));
fields.put("saved_before", Boolean.toString(action.savedBefore()));
fields.put("requested", Boolean.toString(action.requested()));
fields.put("all_enabled", Boolean.toString(preferences.allParticlesEnabled(action.context().playerId())));
if (action.context().characterId() != null) {
fields.put("character", action.context().characterId().toString());
fields.put("character_name", action.context().characterName());
@@ -92,7 +95,8 @@ public final class PreferenceEventBridge {
var row = intent.captured();
UUID account = UUID.fromString(row.get("account"));
if (!"true".equals(row.get("published"))
|| Boolean.parseBoolean(row.get("before")) == Boolean.parseBoolean(row.get("requested"))) return;
|| Boolean.parseBoolean(row.getOrDefault("saved_before", row.get("before")))
== Boolean.parseBoolean(row.get("requested"))) return;
UUID character = row.containsKey("character") ? UUID.fromString(row.get("character")) : null;
EventInput.Location location = row.containsKey("world")
? new EventInput.Location(UUID.fromString(row.get("world")), row.get("world_name"),
@@ -104,8 +108,10 @@ public final class PreferenceEventBridge {
Boolean.parseBoolean(row.get("before")), Boolean.parseBoolean(
row.getOrDefault("saved_before", row.get("before"))),
Boolean.parseBoolean(row.get("requested")), "player");
emit("preference.changed", action, "accepted", "acknowledged", intent.sequence(),
Boolean.parseBoolean(row.get("requested")), true);
boolean after = Boolean.parseBoolean(row.get("requested"));
boolean effective = row.get("key").equals("player-aura-particles")
? after && Boolean.parseBoolean(row.get("all_enabled")) : after;
emit("preference.changed", action, "accepted", "acknowledged", intent.sequence(), effective, true);
} catch (RuntimeException ignored) { /* Invalid pending evidence cannot authorize a preference change. */ }
}
@@ -120,7 +126,7 @@ public final class PreferenceEventBridge {
emit("action.resolved", action, "refused", "superseded", update.sequence(), effective, false);
return;
}
if (action.before() == effective || update.intent() == null) {
if (update.intent() == null || action.savedBefore() == action.requested()) {
if (update.intent() != null) preferences.acknowledgeEvent(action.id());
emit("action.resolved", action, "refused", "unchanged", update.sequence(), effective, false);
return;
@@ -148,25 +154,31 @@ public final class PreferenceEventBridge {
if (action == null) return;
var data = new LinkedHashMap<String, Object>();
data.put("action_kind", "preference_" + (action.requested() == null ? "read" : "change"));
data.put("entry_point", "/fstick particles all");
data.put("entry_point", "/fstick particles "
+ (action.key().equals("player-aura-particles") ? "players" : "all"));
data.put("preference_key", action.key());
if (action.context() == null) { data.put("actor_kind", action.actorKind()); data.put("location_status", "not_applicable"); }
data.put("scope", "account");
data.put("default_value", "true");
data.put("default_value", Boolean.toString(!action.key().equals("player-aura-particles")));
data.put("before", Boolean.toString(action.before()));
data.put("saved_before", Boolean.toString(action.savedBefore()));
data.put("effective_before", Boolean.toString(action.before()));
if (action.requested() != null) data.put("requested", Boolean.toString(action.requested()));
if (action.context() != null) {
boolean latestSaved = type.equals("preference.changed") ? effective
boolean latestSaved = type.equals("preference.changed") ? action.requested()
: preferenceSequence == null ? action.savedBefore()
: preferences.savedAllParticlesEnabled(action.context().playerId());
: action.key().equals("player-aura-particles")
? preferences.savedPlayerAurasEnabled(action.context().playerId())
: preferences.savedAllParticlesEnabled(action.context().playerId());
data.put("saved_value", Boolean.toString(latestSaved));
data.put("effective_value", Boolean.toString(effective));
data.put("effective_after", Boolean.toString(effective));
}
if (preferenceSequence != null) data.put("preference_sequence", Long.toString(preferenceSequence));
data.put("outcome", outcome);
if (reason != null) data.put(type.startsWith("preference.") ? "acknowledgment" : "reason", reason);
if (type.equals("preference.changed")) {
data.put("after", Boolean.toString(effective));
data.put("after", Boolean.toString(action.requested()));
data.put("preference_revision", Long.toString(preferenceSequence));
}
try {
@@ -102,6 +102,11 @@ public final class PlayerFeedbackPreferences implements AutoCloseable {
public synchronized boolean enabled(UUID account) { return value(account, Preference.COMBAT_FEEDBACK); }
public synchronized boolean playerAurasEnabled(UUID account) { return value(account, Preference.PLAYER_AURAS); }
public synchronized boolean allParticlesEnabled(UUID account) { return value(account, Preference.ALL_PARTICLES); }
public synchronized boolean savedPlayerAurasEnabled(UUID account) {
Objects.requireNonNull(account);
return saved.getOrDefault(new AccountPreference(account, Preference.PLAYER_AURAS),
Preference.PLAYER_AURAS.defaultValue);
}
public synchronized boolean savedAllParticlesEnabled(UUID account) {
Objects.requireNonNull(account);
return saved.getOrDefault(new AccountPreference(account, Preference.ALL_PARTICLES),
@@ -124,6 +129,10 @@ public final class PlayerFeedbackPreferences implements AutoCloseable {
return set(account, Preference.PLAYER_AURAS, enabled);
}
public CompletionStage<Update> setPlayerAuras(UUID account, boolean enabled, EventIntent intent) {
return set(account, Preference.PLAYER_AURAS, enabled, intent);
}
/** Shared persisted precedence for the separately delivered all-particles command. */
public CompletionStage<Update> setAllParticles(UUID account, boolean enabled) {
return set(account, Preference.ALL_PARTICLES, enabled);
@@ -32,22 +32,22 @@ public final class FantasyParticlesCommand implements TabExecutor, AutoCloseable
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player player)) {
if (args.length > 0 && args[0].equals("all") && events != null) {
try { events.refuseNonPlayer(sender); } catch (RuntimeException ignored) { }
if (args.length > 0 && (args[0].equals("all") || args[0].equals("players")) && events != null) {
try { events.refuseNonPlayer(sender, key(args[0])); } catch (RuntimeException ignored) { }
}
sender.sendMessage("Fantasy particles are a player-account preference.");
return true;
}
if (args.length == 1 && (args[0].equals("players") || args[0].equals("all"))) {
var action = args[0].equals("all") ? observe(player, null) : null;
var action = observe(player, args[0], null);
player.sendMessage(status(player.getUniqueId(), args[0]));
if (action != null) events.read(action);
return true;
}
if (args.length != 2 || !(args[0].equals("players") || args[0].equals("all"))
|| !(args[1].equals("on") || args[1].equals("off"))) {
if (args.length > 0 && args[0].equals("all")) {
var action = observe(player, null);
if (args.length > 0 && (args[0].equals("all") || args[0].equals("players"))) {
var action = observe(player, args[0], null);
if (action != null) events.refused(action, "invalid_arguments");
}
return false;
@@ -55,10 +55,11 @@ public final class FantasyParticlesCommand implements TabExecutor, AutoCloseable
String route = args[0];
boolean enabled = args[1].equals("on");
UUID account = player.getUniqueId();
var action = route.equals("all") ? observe(player, enabled) : null;
var action = observe(player, route, enabled);
var save = route.equals("players")
? preferences.setPlayerAuras(account, enabled) : action == null
? preferences.setAllParticles(account, enabled)
? action == null ? preferences.setPlayerAuras(account, enabled)
: preferences.setPlayerAuras(account, enabled, events.intent(action))
: action == null ? preferences.setAllParticles(account, enabled)
: preferences.setAllParticles(account, enabled, events.intent(action));
save.whenComplete((saved, failure) -> {
if (failure != null) report(failure);
@@ -76,7 +77,9 @@ public final class FantasyParticlesCommand implements TabExecutor, AutoCloseable
return;
}
boolean published = preferences.publish(saved);
if (action != null) events.saved(action, saved, published, preferences.allParticlesEnabled(account));
if (action != null) events.saved(action, saved, published,
route.equals("players") ? preferences.auraParticlesEnabled(account)
: preferences.allParticlesEnabled(account));
if (player.isOnline()) player.sendMessage(acknowledgement(account, route, published));
});
} catch (RuntimeException rejected) {
@@ -95,13 +98,18 @@ public final class FantasyParticlesCommand implements TabExecutor, AutoCloseable
return List.of();
}
private games.dmg.fantasystick.events.PreferenceEventBridge.Action observe(Player player, Boolean requested) {
private games.dmg.fantasystick.events.PreferenceEventBridge.Action observe(
Player player, String route, Boolean requested) {
var bridge = events;
if (bridge == null) return null;
try { return bridge.begin(player, "all-particles", preferences.allParticlesEnabled(player.getUniqueId()), requested); }
try { return bridge.begin(player, key(route), route.equals("players")
? preferences.auraParticlesEnabled(player.getUniqueId())
: preferences.allParticlesEnabled(player.getUniqueId()), requested); }
catch (RuntimeException ignored) { return null; } // Capture failure cannot refuse gameplay.
}
private static String key(String route) { return route.equals("players") ? "player-aura-particles" : "all-particles"; }
private String status(UUID account, String route) {
if (route.equals("all"))
return "All Fantasy Stick particles are " + state(preferences.allParticlesEnabled(account)) + ".";