Update adventure to v4.23.0
This commit is contained in:
5 files changed
+62
-16
No files matched your search
+4
-1
@@ -20,7 +20,9 @@ package com.github.retrooper.packetevents.protocol.chat.clickevent;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.dialog.Dialog;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTEnd;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.adventure.NbtTagHolder;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import net.kyori.adventure.text.event.ClickEvent.Payload;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
@@ -60,9 +62,10 @@ public interface ClickEvent {
|
||||
return new ShowDialogClickEvent((Dialog) ((Payload.Dialog) clickEvent.payload()).dialog());
|
||||
case CUSTOM:
|
||||
Payload.Custom payload = (Payload.Custom) clickEvent.payload();
|
||||
NbtTagHolder nbtTag = (NbtTagHolder) payload.nbt();
|
||||
return new CustomClickEvent(
|
||||
new ResourceLocation(payload.key()),
|
||||
null // TODO parse snbt
|
||||
nbtTag.getTag() instanceof NBTEnd ? null : nbtTag.getTag()
|
||||
);
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unsupported clickevent: " + clickEvent);
|
||||
|
||||
+4
-2
@@ -20,7 +20,9 @@ package com.github.retrooper.packetevents.protocol.chat.clickevent;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBT;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTEnd;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.adventure.NbtTagHolder;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
@@ -56,8 +58,8 @@ public class CustomClickEvent implements ClickEvent {
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.event.ClickEvent asAdventure() {
|
||||
// TODO convert payload to snbt
|
||||
return net.kyori.adventure.text.event.ClickEvent.custom(this.id.key(), null);
|
||||
return net.kyori.adventure.text.event.ClickEvent.custom(
|
||||
this.id.key(), new NbtTagHolder(this.payload != null ? this.payload : NBTEnd.INSTANCE));
|
||||
}
|
||||
|
||||
public ResourceLocation getId() {
|
||||
|
||||
+3
-12
@@ -493,7 +493,7 @@ public class AdventureNBTSerializer implements ComponentSerializer<Component, Co
|
||||
continue;
|
||||
}
|
||||
Key key = Key.key(entry.getKey());
|
||||
map.put(key, new NbtComponentValue(entry.getValue()));
|
||||
map.put(key, new NbtTagHolder(entry.getValue()));
|
||||
}
|
||||
return map;
|
||||
});
|
||||
@@ -625,8 +625,8 @@ public class AdventureNBTSerializer implements ComponentSerializer<Component, Co
|
||||
compsNbt.writeCompound("!" + entry.getKey(), new NBTCompound());
|
||||
continue;
|
||||
}
|
||||
if (entry.getValue() instanceof NbtComponentValue) {
|
||||
NBT compNbt = ((NbtComponentValue) entry.getValue()).nbt;
|
||||
if (entry.getValue() instanceof NbtTagHolder) {
|
||||
NBT compNbt = ((NbtTagHolder) entry.getValue()).getTag();
|
||||
compsNbt.write(entry.getKey().toString(), compNbt);
|
||||
}
|
||||
// unsupported entry component value, skip for now
|
||||
@@ -915,13 +915,4 @@ public class AdventureNBTSerializer implements ComponentSerializer<Component, Co
|
||||
}
|
||||
return (T) nbt;
|
||||
}
|
||||
|
||||
private static final class NbtComponentValue implements DataComponentValue {
|
||||
|
||||
private final NBT nbt;
|
||||
|
||||
public NbtComponentValue(NBT nbt) {
|
||||
this.nbt = nbt;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2025 retrooper and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.util.adventure;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBT;
|
||||
import net.kyori.adventure.nbt.api.BinaryTagHolder;
|
||||
import net.kyori.adventure.util.Codec;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public final class NbtTagHolder implements BinaryTagHolder {
|
||||
|
||||
private final NBT tag;
|
||||
|
||||
public NbtTagHolder(NBT tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String string() {
|
||||
// TODO snbt serialization is currently not supported by packetevents
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, DX extends Exception> @NotNull T get(@NotNull Codec<T, String, DX, ?> codec) throws DX {
|
||||
return codec.decode(this.string());
|
||||
}
|
||||
|
||||
public NBT getTag() {
|
||||
return this.tag;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
[versions]
|
||||
adventure = "4.22.0"
|
||||
adventure = "4.23.0"
|
||||
examination = "1.3.0"
|
||||
netty = "4.1.72.Final"
|
||||
jetbrains-annotations = "23.0.0"
|
||||
|
||||
Reference in new issue
Block a user