fix(ignis): mask affected-player advancement announcements
Retain event-level masking and add a UUID-gated advancement-only packet backstop for Purpur delivery that uses the pre-event component. Verify real Echo activation and reopen, native delivery branches, system codecs, identity boundaries and plugin registration. Echo recovery and production deployment remain separate.
This commit is contained in:
1 parent
e4bc296ce1
commit
5bfcf36f04
9 files changed
+487
-3
No files matched your search
@@ -14,11 +14,33 @@ public final class AdvancementMasker {
|
||||
private AdvancementMasker() { }
|
||||
|
||||
public static Component mask(Component original) {
|
||||
return maskNameSlots(original, name -> true);
|
||||
}
|
||||
|
||||
/** Packet-only fallback requires a single authenticated player UUID in the name slot, never a text-name guess. */
|
||||
public static Component maskIdentified(Component original, java.util.function.Predicate<java.util.UUID> activated) {
|
||||
return maskNameSlots(original, name -> {
|
||||
var identities = new java.util.HashSet<java.util.UUID>();
|
||||
collectIdentities(name, identities);
|
||||
return identities.size() == 1 && activated.test(identities.iterator().next());
|
||||
});
|
||||
}
|
||||
|
||||
private static void collectIdentities(Component component, java.util.Set<java.util.UUID> identities) {
|
||||
if (component.hoverEvent() != null && component.hoverEvent().value() instanceof net.kyori.adventure.text.event.HoverEvent.ShowEntity entity
|
||||
&& entity.type().equals(net.kyori.adventure.key.Key.key("minecraft:player"))) {
|
||||
identities.add(entity.id());
|
||||
}
|
||||
for (var child : component.children()) { collectIdentities(child, identities); }
|
||||
}
|
||||
|
||||
private static Component maskNameSlots(Component original, java.util.function.Predicate<Component> authorized) {
|
||||
if (original == null) return null;
|
||||
Component result = original;
|
||||
boolean changed = false;
|
||||
if (result instanceof TranslatableComponent translation && KEYS.contains(translation.key())
|
||||
&& !translation.arguments().isEmpty()) {
|
||||
&& !translation.arguments().isEmpty()
|
||||
&& translation.arguments().getFirst().value() instanceof Component name && authorized.test(name)) {
|
||||
var arguments = new ArrayList<ComponentLike>(translation.arguments());
|
||||
arguments.set(0, Component.text("Anonymous").decorate(TextDecoration.OBFUSCATED).insertion(""));
|
||||
result = translation.arguments(arguments);
|
||||
@@ -26,7 +48,7 @@ public final class AdvancementMasker {
|
||||
}
|
||||
var children = new ArrayList<Component>();
|
||||
for (Component child : original.children()) {
|
||||
Component masked = mask(child);
|
||||
Component masked = maskNameSlots(child, authorized);
|
||||
children.add(masked);
|
||||
changed |= masked != child;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package games.dmg.spigotignis;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/** Advancement-only wire backstop for native delivery paths which do not use the event's replacement component. */
|
||||
public final class AnnouncementPacketListener extends PacketAdapter {
|
||||
private final Predicate<UUID> activated;
|
||||
private final Consumer<String> warning;
|
||||
private final java.lang.reflect.Method content, overlay, asAdventure, asVanilla;
|
||||
private final java.lang.reflect.Constructor<?> packet;
|
||||
private final java.util.concurrent.atomic.AtomicBoolean warned = new java.util.concurrent.atomic.AtomicBoolean();
|
||||
|
||||
public AnnouncementPacketListener(Plugin plugin, Predicate<UUID> activated, Consumer<String> warning) {
|
||||
super(plugin, ListenerPriority.HIGHEST, PacketType.Play.Server.SYSTEM_CHAT);
|
||||
this.activated = java.util.Objects.requireNonNull(activated);
|
||||
this.warning = java.util.Objects.requireNonNull(warning);
|
||||
try {
|
||||
var nativeComponent = Class.forName("net.minecraft.network.chat.Component");
|
||||
var packetType = Class.forName("net.minecraft.network.protocol.game.ClientboundSystemChatPacket");
|
||||
var adventure = Class.forName("io.papermc.paper.adventure.PaperAdventure");
|
||||
content = packetType.getMethod("content");
|
||||
overlay = packetType.getMethod("overlay");
|
||||
asAdventure = adventure.getMethod("asAdventure", nativeComponent);
|
||||
asVanilla = adventure.getMethod("asVanilla", net.kyori.adventure.text.Component.class);
|
||||
packet = packetType.getConstructor(nativeComponent, boolean.class);
|
||||
} catch (ReflectiveOperationException failure) { throw new IllegalStateException("Unsupported native announcement packet layout", failure); }
|
||||
}
|
||||
|
||||
@Override public void onPacketSending(PacketEvent event) {
|
||||
if (event.isCancelled()) { return; }
|
||||
try {
|
||||
Object originalPacket = event.getPacket().getHandle();
|
||||
if ((boolean) overlay.invoke(originalPacket)) { return; }
|
||||
var original = (net.kyori.adventure.text.Component) asAdventure.invoke(null, content.invoke(originalPacket));
|
||||
var masked = AdvancementMasker.maskIdentified(original, activated);
|
||||
if (masked != original) {
|
||||
Object projected = packet.newInstance(asVanilla.invoke(null, masked), false);
|
||||
event.setPacket(new com.comphenix.protocol.events.PacketContainer(PacketType.Play.Server.SYSTEM_CHAT, projected));
|
||||
}
|
||||
} catch (ReflectiveOperationException | RuntimeException failure) {
|
||||
if (warned.compareAndSet(false, true)) { warning.accept("Ignis announcement projection unavailable; original delivery retained: " + failure.getClass().getSimpleName()); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
/** Registers gameplay only after durable state initialization succeeds. */
|
||||
public final class SpigotIgnisPlugin extends JavaPlugin {
|
||||
private CompletableFuture<StateService> initialization;
|
||||
private AnnouncementPacketListener announcementPackets;
|
||||
private MaskProgressListener maskProgress;
|
||||
private MaskCrafting maskCrafting;
|
||||
private MaskEffects maskEffects;
|
||||
@@ -33,6 +34,8 @@ public final class SpigotIgnisPlugin extends JavaPlugin {
|
||||
var gameplay = new EchoGameplay(this, service, new EchoItems());
|
||||
getServer().getPluginManager().registerEvents(gameplay, this);
|
||||
getServer().getPluginManager().registerEvents(new AnnouncementListener(gameplay::activated), this);
|
||||
announcementPackets = new AnnouncementPacketListener(this, gameplay::activated, getLogger()::warning);
|
||||
com.comphenix.protocol.ProtocolLibrary.getProtocolManager().addPacketListener(announcementPackets);
|
||||
getServer().getScheduler().runTaskTimer(this, gameplay::retryDeliveries, 1L, 100L);
|
||||
var maskTracker = new InvisibilityProgress(service, System::nanoTime);
|
||||
maskProgress = new MaskProgressListener(this, maskTracker);
|
||||
@@ -94,6 +97,7 @@ public final class SpigotIgnisPlugin extends JavaPlugin {
|
||||
@Override
|
||||
public void onDisable() {
|
||||
try {
|
||||
if (announcementPackets != null) com.comphenix.protocol.ProtocolLibrary.getProtocolManager().removePacketListener(announcementPackets);
|
||||
if (heartEffects != null) heartEffects.close();
|
||||
if (heartCrafting != null) heartCrafting.close();
|
||||
if (maskEffects != null) maskEffects.close();
|
||||
|
||||
Reference in new issue
Block a user