packets, fancydialogs: Refactor custom action handling to use a map for additional data

This commit is contained in:
Oliver
2025-06-17 21:50:34 +02:00
parent 31f03ae252
commit d61b3af90b
10 changed files with 65 additions and 29 deletions

View File

@@ -245,7 +245,7 @@ public class ClientboundShowDialogPacketImpl extends FS_ClientboundShowDialogPac
Optional<CompoundTag> additions;
if (customAction.getAdditions() != null) {
CompoundTag tag = new CompoundTag();
tag.putString("data", customAction.getAdditions());
customAction.getAdditions().forEach(tag::putString);
additions = Optional.of(tag);
} else {
additions = Optional.empty();

View File

@@ -13,8 +13,9 @@ import net.minecraft.server.level.ServerPlayer;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import java.util.Map;
public class PacketListenerImpl extends FS_PacketListener {
@@ -75,12 +76,16 @@ public class PacketListenerImpl extends FS_PacketListener {
switch (type) {
case CUSTOM_CLICK_ACTION -> {
ServerboundCustomClickActionPacket customClickActionPacket = (ServerboundCustomClickActionPacket) packet;
Map<String, String> payload = new HashMap<>();
customClickActionPacket.payload().get().asCompound().get().forEach((k, t) -> {
payload.put(k, t.asString().get());
});
return new FS_ServerboundCustomClickActionPacket(
type,
PaperAdventure.asAdventure(customClickActionPacket.id()),
customClickActionPacket.payload().isPresent() ?
customClickActionPacket.payload().get().asCompound().get().getString("data") :
Optional.empty()
payload
);
}
// Add more cases for other packet types as needed