mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 12:27:59 +01:00
Adventure
== AT == public net.minecraft.network.chat.HoverEvent$ItemStackInfo item public net.minecraft.network.chat.HoverEvent$ItemStackInfo count public net.minecraft.network.chat.HoverEvent$ItemStackInfo components public net.minecraft.network.chat.contents.TranslatableContents filterAllowedArguments(Ljava/lang/Object;)Lcom/mojang/serialization/DataResult; Co-authored-by: zml <zml@stellardrift.ca> Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
This commit is contained in:
parent
b01c811c2f
commit
66779f5c86
@ -0,0 +1,21 @@
|
||||
--- a/net/minecraft/ChatFormatting.java
|
||||
+++ b/net/minecraft/ChatFormatting.java
|
||||
@@ -112,6 +112,18 @@
|
||||
return name == null ? null : FORMATTING_BY_NAME.get(cleanName(name));
|
||||
}
|
||||
|
||||
+ // Paper start - add method to get by hex value
|
||||
+ @Nullable public static ChatFormatting getByHexValue(int i) {
|
||||
+ for (ChatFormatting value : values()) {
|
||||
+ if (value.getColor() != null && value.getColor() == i) {
|
||||
+ return value;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return null;
|
||||
+ }
|
||||
+ // Paper end - add method to get by hex value
|
||||
+
|
||||
@Nullable
|
||||
public static ChatFormatting getById(int colorIndex) {
|
||||
if (colorIndex < 0) {
|
@ -8,15 +8,16 @@
|
||||
|
||||
public class CommandSourceStack implements ExecutionCommandSource<CommandSourceStack>, SharedSuggestionProvider {
|
||||
|
||||
@@ -65,6 +66,7 @@
|
||||
@@ -65,6 +66,8 @@
|
||||
private final Vec2 rotation;
|
||||
private final CommandSigningContext signingContext;
|
||||
private final TaskChainer chatMessageChainer;
|
||||
+ public volatile CommandNode currentCommand; // CraftBukkit
|
||||
+ public boolean bypassSelectorPermissions = false; // Paper - add bypass for selector permissions
|
||||
|
||||
public CommandSourceStack(CommandSource output, Vec3 pos, Vec2 rot, ServerLevel world, int level, String name, Component displayName, MinecraftServer server, @Nullable Entity entity) {
|
||||
this(output, pos, rot, world, level, name, displayName, server, entity, false, CommandResultCallback.EMPTY, EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(server));
|
||||
@@ -171,8 +173,22 @@
|
||||
@@ -171,9 +174,23 @@
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(int level) {
|
||||
@ -28,18 +29,19 @@
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
return this.permissionLevel >= level;
|
||||
+ }
|
||||
+
|
||||
}
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ public boolean hasPermission(int i, String bukkitPermission) {
|
||||
+ // World is null when loading functions
|
||||
+ return ((this.getLevel() == null || !this.getLevel().getCraftServer().ignoreVanillaPermissions) && this.permissionLevel >= i) || this.getBukkitSender().hasPermission(bukkitPermission);
|
||||
}
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
|
||||
+
|
||||
public Vec3 getPosition() {
|
||||
return this.worldPosition;
|
||||
@@ -302,13 +318,13 @@
|
||||
}
|
||||
@@ -302,13 +319,13 @@
|
||||
while (iterator.hasNext()) {
|
||||
ServerPlayer entityplayer = (ServerPlayer) iterator.next();
|
||||
|
||||
@ -55,7 +57,7 @@
|
||||
this.server.sendSystemMessage(ichatmutablecomponent);
|
||||
}
|
||||
|
||||
@@ -400,4 +416,10 @@
|
||||
@@ -400,4 +417,10 @@
|
||||
public boolean isSilent() {
|
||||
return this.silent;
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
--- a/net/minecraft/commands/arguments/MessageArgument.java
|
||||
+++ b/net/minecraft/commands/arguments/MessageArgument.java
|
||||
@@ -54,17 +54,21 @@
|
||||
private static void resolveSignedMessage(Consumer<PlayerChatMessage> callback, CommandSourceStack source, PlayerChatMessage message) {
|
||||
MinecraftServer minecraftServer = source.getServer();
|
||||
CompletableFuture<FilteredText> completableFuture = filterPlainText(source, message);
|
||||
- Component component = minecraftServer.getChatDecorator().decorate(source.getPlayer(), message.decoratedContent());
|
||||
- source.getChatMessageChainer().append(completableFuture, filtered -> {
|
||||
- PlayerChatMessage playerChatMessage2 = message.withUnsignedContent(component).filter(filtered.mask());
|
||||
+ // Paper start - support asynchronous chat decoration
|
||||
+ CompletableFuture<Component> componentFuture = minecraftServer.getChatDecorator().decorate(source.getPlayer(), source, message.decoratedContent());
|
||||
+ source.getChatMessageChainer().append(CompletableFuture.allOf(completableFuture, componentFuture), filtered -> {
|
||||
+ PlayerChatMessage playerChatMessage2 = message.withUnsignedContent(componentFuture.join()).filter(completableFuture.join().mask());
|
||||
+ // Paper end - support asynchronous chat decoration
|
||||
callback.accept(playerChatMessage2);
|
||||
});
|
||||
}
|
||||
|
||||
private static void resolveDisguisedMessage(Consumer<PlayerChatMessage> callback, CommandSourceStack source, PlayerChatMessage message) {
|
||||
ChatDecorator chatDecorator = source.getServer().getChatDecorator();
|
||||
- Component component = chatDecorator.decorate(source.getPlayer(), message.decoratedContent());
|
||||
- callback.accept(message.withUnsignedContent(component));
|
||||
+ // Paper start - support asynchronous chat decoration
|
||||
+ CompletableFuture<Component> componentFuture = chatDecorator.decorate(source.getPlayer(), source, message.decoratedContent());
|
||||
+ source.getChatMessageChainer().append(componentFuture, (result) -> callback.accept(message.withUnsignedContent(result)));
|
||||
+ // Paper end - support asynchronous chat decoration
|
||||
}
|
||||
|
||||
private static CompletableFuture<FilteredText> filterPlainText(CommandSourceStack source, PlayerChatMessage message) {
|
@ -5,7 +5,7 @@
|
||||
|
||||
private void checkPermissions(CommandSourceStack source) throws CommandSyntaxException {
|
||||
- if (this.usesSelector && !source.hasPermission(2)) {
|
||||
+ if (this.usesSelector && !source.hasPermission(2, "minecraft.command.selector")) { // CraftBukkit
|
||||
+ if (!source.bypassSelectorPermissions && (this.usesSelector && !source.hasPermission(2, "minecraft.command.selector"))) { // CraftBukkit // Paper - add bypass for selector perms
|
||||
throw EntityArgument.ERROR_SELECTORS_NOT_ALLOWED.create();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,40 @@
|
||||
--- a/net/minecraft/network/FriendlyByteBuf.java
|
||||
+++ b/net/minecraft/network/FriendlyByteBuf.java
|
||||
@@ -139,7 +139,7 @@
|
||||
@@ -72,6 +72,7 @@
|
||||
|
||||
public static final int DEFAULT_NBT_QUOTA = 2097152;
|
||||
private final ByteBuf source;
|
||||
+ @Nullable public final java.util.Locale adventure$locale; // Paper - track player's locale for server-side translations
|
||||
public static final short MAX_STRING_LENGTH = Short.MAX_VALUE;
|
||||
public static final int MAX_COMPONENT_STRING_LENGTH = 262144;
|
||||
private static final int PUBLIC_KEY_SIZE = 256;
|
||||
@@ -80,6 +81,7 @@
|
||||
private static final Gson GSON = new Gson();
|
||||
|
||||
public FriendlyByteBuf(ByteBuf parent) {
|
||||
+ this.adventure$locale = PacketEncoder.ADVENTURE_LOCALE.get(); // Paper - track player's locale for server-side translations
|
||||
this.source = parent;
|
||||
}
|
||||
|
||||
@@ -120,11 +122,16 @@
|
||||
}
|
||||
|
||||
public <T> void writeJsonWithCodec(Codec<T> codec, T value) {
|
||||
+ // Paper start - Adventure; add max length parameter
|
||||
+ this.writeJsonWithCodec(codec, value, MAX_STRING_LENGTH);
|
||||
+ }
|
||||
+ public <T> void writeJsonWithCodec(Codec<T> codec, T value, int maxLength) {
|
||||
+ // Paper end - Adventure; add max length parameter
|
||||
DataResult<JsonElement> dataresult = codec.encodeStart(JsonOps.INSTANCE, value);
|
||||
|
||||
this.writeUtf(FriendlyByteBuf.GSON.toJson((JsonElement) dataresult.getOrThrow((s) -> {
|
||||
return new EncoderException("Failed to encode: " + s + " " + String.valueOf(value));
|
||||
- })));
|
||||
+ })), maxLength); // Paper - Adventure; add max length parameter
|
||||
}
|
||||
|
||||
public static <T> IntFunction<T> limitValue(IntFunction<T> applier, int max) {
|
||||
@@ -139,7 +146,7 @@
|
||||
|
||||
public <T, C extends Collection<T>> C readCollection(IntFunction<C> collectionFactory, StreamDecoder<? super FriendlyByteBuf, T> reader) {
|
||||
int i = this.readVarInt();
|
||||
@ -9,7 +43,7 @@
|
||||
|
||||
for (int j = 0; j < i; ++j) {
|
||||
c0.add(reader.decode(this));
|
||||
@@ -150,7 +150,7 @@
|
||||
@@ -150,7 +157,7 @@
|
||||
|
||||
public <T> void writeCollection(Collection<T> collection, StreamEncoder<? super FriendlyByteBuf, T> writer) {
|
||||
this.writeVarInt(collection.size());
|
||||
@ -18,7 +52,7 @@
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
T t0 = iterator.next();
|
||||
@@ -177,12 +177,12 @@
|
||||
@@ -177,12 +184,12 @@
|
||||
|
||||
public void writeIntIdList(IntList list) {
|
||||
this.writeVarInt(list.size());
|
||||
@ -33,7 +67,7 @@
|
||||
|
||||
for (int j = 0; j < i; ++j) {
|
||||
K k0 = keyReader.decode(this);
|
||||
@@ -216,7 +216,7 @@
|
||||
@@ -216,7 +223,7 @@
|
||||
}
|
||||
|
||||
public <E extends Enum<E>> void writeEnumSet(EnumSet<E> enumSet, Class<E> type) {
|
||||
@ -42,7 +76,7 @@
|
||||
BitSet bitset = new BitSet(ae.length);
|
||||
|
||||
for (int i = 0; i < ae.length; ++i) {
|
||||
@@ -227,7 +227,7 @@
|
||||
@@ -227,7 +234,7 @@
|
||||
}
|
||||
|
||||
public <E extends Enum<E>> EnumSet<E> readEnumSet(Class<E> type) {
|
||||
@ -51,7 +85,7 @@
|
||||
BitSet bitset = this.readFixedBitSet(ae.length);
|
||||
EnumSet<E> enumset = EnumSet.noneOf(type);
|
||||
|
||||
@@ -498,7 +498,7 @@
|
||||
@@ -498,7 +505,7 @@
|
||||
}
|
||||
|
||||
public <T extends Enum<T>> T readEnum(Class<T> enumClass) {
|
||||
@ -60,7 +94,7 @@
|
||||
}
|
||||
|
||||
public FriendlyByteBuf writeEnum(Enum<?> instance) {
|
||||
@@ -565,7 +565,7 @@
|
||||
@@ -565,7 +572,7 @@
|
||||
|
||||
try {
|
||||
NbtIo.writeAnyTag((Tag) nbt, new ByteBufOutputStream(buf));
|
||||
|
@ -1,6 +1,19 @@
|
||||
--- a/net/minecraft/network/PacketEncoder.java
|
||||
+++ b/net/minecraft/network/PacketEncoder.java
|
||||
@@ -31,7 +31,7 @@
|
||||
@@ -17,10 +17,12 @@
|
||||
this.protocolInfo = state;
|
||||
}
|
||||
|
||||
+ static final ThreadLocal<java.util.Locale> ADVENTURE_LOCALE = ThreadLocal.withInitial(() -> null); // Paper - adventure; set player's locale
|
||||
protected void encode(ChannelHandlerContext channelHandlerContext, Packet<T> packet, ByteBuf byteBuf) throws Exception {
|
||||
PacketType<? extends Packet<? super T>> packetType = packet.type();
|
||||
|
||||
try {
|
||||
+ ADVENTURE_LOCALE.set(channelHandlerContext.channel().attr(io.papermc.paper.adventure.PaperAdventure.LOCALE_ATTRIBUTE).get()); // Paper - adventure; set player's locale
|
||||
this.protocolInfo.codec().encode(byteBuf, packet);
|
||||
int i = byteBuf.readableBytes();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
@@ -31,7 +33,7 @@
|
||||
|
||||
JvmProfiler.INSTANCE.onPacketSent(this.protocolInfo.id(), packetType, channelHandlerContext.channel().remoteAddress(), i);
|
||||
} catch (Throwable var9) {
|
||||
|
@ -0,0 +1,23 @@
|
||||
--- a/net/minecraft/network/chat/ChatDecorator.java
|
||||
+++ b/net/minecraft/network/chat/ChatDecorator.java
|
||||
@@ -2,10 +2,18 @@
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
+import java.util.concurrent.CompletableFuture; // Paper
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ChatDecorator {
|
||||
- ChatDecorator PLAIN = (sender, message) -> message;
|
||||
+ ChatDecorator PLAIN = (sender, message) -> CompletableFuture.completedFuture(message); // Paper - adventure; support async chat decoration events
|
||||
|
||||
- Component decorate(@Nullable ServerPlayer sender, Component message);
|
||||
+ @io.papermc.paper.annotation.DoNotUse @Deprecated // Paper - adventure; support chat decoration events (callers should use the overload with CommandSourceStack)
|
||||
+ CompletableFuture<Component> decorate(@Nullable ServerPlayer sender, Component message); // Paper - adventure; support async chat decoration events
|
||||
+
|
||||
+ // Paper start - adventure; support async chat decoration events
|
||||
+ default CompletableFuture<Component> decorate(@Nullable ServerPlayer sender, @Nullable net.minecraft.commands.CommandSourceStack commandSourceStack, Component message) {
|
||||
+ throw new UnsupportedOperationException("Must override this implementation");
|
||||
+ }
|
||||
+ // Paper end - adventure; support async chat decoration events
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
--- a/net/minecraft/network/chat/ComponentSerialization.java
|
||||
+++ b/net/minecraft/network/chat/ComponentSerialization.java
|
||||
@@ -37,9 +37,31 @@
|
||||
|
||||
public class ComponentSerialization {
|
||||
public static final Codec<Component> CODEC = Codec.recursive("Component", ComponentSerialization::createCodec);
|
||||
- public static final StreamCodec<RegistryFriendlyByteBuf, Component> STREAM_CODEC = ByteBufCodecs.fromCodecWithRegistries(CODEC);
|
||||
+ public static final StreamCodec<RegistryFriendlyByteBuf, Component> STREAM_CODEC = createTranslationAware(() -> net.minecraft.nbt.NbtAccounter.create(net.minecraft.network.FriendlyByteBuf.DEFAULT_NBT_QUOTA)); // Paper - adventure
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, Optional<Component>> OPTIONAL_STREAM_CODEC = STREAM_CODEC.apply(ByteBufCodecs::optional);
|
||||
- public static final StreamCodec<RegistryFriendlyByteBuf, Component> TRUSTED_STREAM_CODEC = ByteBufCodecs.fromCodecWithRegistriesTrusted(CODEC);
|
||||
+ // Paper start - adventure; use locale from bytebuf for translation
|
||||
+ public static final ThreadLocal<Boolean> DONT_RENDER_TRANSLATABLES = ThreadLocal.withInitial(() -> false);
|
||||
+ public static final StreamCodec<RegistryFriendlyByteBuf, Component> TRUSTED_STREAM_CODEC = createTranslationAware(net.minecraft.nbt.NbtAccounter::unlimitedHeap);
|
||||
+ private static StreamCodec<RegistryFriendlyByteBuf, Component> createTranslationAware(final Supplier<net.minecraft.nbt.NbtAccounter> sizeTracker) {
|
||||
+ return new StreamCodec<>() {
|
||||
+ final StreamCodec<ByteBuf, net.minecraft.nbt.Tag> streamCodec = ByteBufCodecs.tagCodec(sizeTracker);
|
||||
+ @Override
|
||||
+ public Component decode(RegistryFriendlyByteBuf registryFriendlyByteBuf) {
|
||||
+ net.minecraft.nbt.Tag tag = this.streamCodec.decode(registryFriendlyByteBuf);
|
||||
+ RegistryOps<net.minecraft.nbt.Tag> registryOps = registryFriendlyByteBuf.registryAccess().createSerializationContext(net.minecraft.nbt.NbtOps.INSTANCE);
|
||||
+ return CODEC.parse(registryOps, tag).getOrThrow(error -> new io.netty.handler.codec.DecoderException("Failed to decode: " + error + " " + tag));
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void encode(RegistryFriendlyByteBuf registryFriendlyByteBuf, Component object) {
|
||||
+ RegistryOps<net.minecraft.nbt.Tag> registryOps = registryFriendlyByteBuf.registryAccess().createSerializationContext(net.minecraft.nbt.NbtOps.INSTANCE);
|
||||
+ net.minecraft.nbt.Tag tag = (DONT_RENDER_TRANSLATABLES.get() ? CODEC : ComponentSerialization.localizedCodec(registryFriendlyByteBuf.adventure$locale))
|
||||
+ .encodeStart(registryOps, object).getOrThrow(error -> new io.netty.handler.codec.EncoderException("Failed to encode: " + error + " " + object));
|
||||
+ this.streamCodec.encode(registryFriendlyByteBuf, tag);
|
||||
+ }
|
||||
+ };
|
||||
+ }
|
||||
+ // Paper end - adventure; use locale from bytebuf for translation
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, Optional<Component>> TRUSTED_OPTIONAL_STREAM_CODEC = TRUSTED_STREAM_CODEC.apply(
|
||||
ByteBufCodecs::optional
|
||||
);
|
||||
@@ -100,7 +122,27 @@
|
||||
return ExtraCodecs.orCompressed(mapCodec3, mapCodec2);
|
||||
}
|
||||
|
||||
+ // Paper start - adventure; create separate codec for each locale
|
||||
+ private static final java.util.Map<java.util.Locale, Codec<Component>> LOCALIZED_CODECS = new java.util.concurrent.ConcurrentHashMap<>();
|
||||
+
|
||||
+ public static Codec<Component> localizedCodec(final java.util.@org.checkerframework.checker.nullness.qual.Nullable Locale locale) {
|
||||
+ if (locale == null) {
|
||||
+ return CODEC;
|
||||
+ }
|
||||
+ return LOCALIZED_CODECS.computeIfAbsent(locale,
|
||||
+ loc -> Codec.recursive("Component", selfCodec -> createCodec(selfCodec, loc)));
|
||||
+ }
|
||||
+
|
||||
+
|
||||
+ // Paper end - adventure; create separate codec for each locale
|
||||
+
|
||||
private static Codec<Component> createCodec(Codec<Component> selfCodec) {
|
||||
+ // Paper start - adventure; create separate codec for each locale
|
||||
+ return createCodec(selfCodec, null);
|
||||
+ }
|
||||
+
|
||||
+ private static Codec<Component> createCodec(Codec<Component> selfCodec, @javax.annotation.Nullable java.util.Locale locale) {
|
||||
+ // Paper end - adventure; create separate codec for each locale
|
||||
ComponentContents.Type<?>[] types = new ComponentContents.Type[]{
|
||||
PlainTextContents.TYPE, TranslatableContents.TYPE, KeybindContents.TYPE, ScoreContents.TYPE, SelectorContents.TYPE, NbtContents.TYPE
|
||||
};
|
||||
@@ -113,6 +155,34 @@
|
||||
)
|
||||
.apply(instance, MutableComponent::new)
|
||||
);
|
||||
+ // Paper start - adventure; create separate codec for each locale
|
||||
+ final Codec<Component> origCodec = codec;
|
||||
+ codec = new Codec<>() {
|
||||
+ @Override
|
||||
+ public <T> DataResult<com.mojang.datafixers.util.Pair<Component, T>> decode(final DynamicOps<T> ops, final T input) {
|
||||
+ return origCodec.decode(ops, input);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public <T> DataResult<T> encode(final Component input, final DynamicOps<T> ops, final T prefix) {
|
||||
+ final net.kyori.adventure.text.Component adventureComponent;
|
||||
+ if (input instanceof io.papermc.paper.adventure.AdventureComponent adv) {
|
||||
+ adventureComponent = adv.adventure$component();
|
||||
+ } else if (locale != null && input.getContents() instanceof TranslatableContents && io.papermc.paper.adventure.PaperAdventure.hasAnyTranslations()) {
|
||||
+ adventureComponent = io.papermc.paper.adventure.PaperAdventure.asAdventure(input);
|
||||
+ } else {
|
||||
+ return origCodec.encode(input, ops, prefix);
|
||||
+ }
|
||||
+ return io.papermc.paper.adventure.PaperAdventure.localizedCodec(locale)
|
||||
+ .encode(adventureComponent, ops, prefix);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public String toString() {
|
||||
+ return origCodec.toString() + "[AdventureComponentAware]";
|
||||
+ }
|
||||
+ };
|
||||
+ // Paper end - adventure; create separate codec for each locale
|
||||
return Codec.either(Codec.either(Codec.STRING, ExtraCodecs.nonEmptyList(selfCodec.listOf())), codec)
|
||||
.xmap(either -> either.map(either2 -> either2.map(Component::literal, ComponentSerialization::createFromList), text -> (Component)text), text -> {
|
||||
String string = text.tryCollapseToString();
|
@ -0,0 +1,14 @@
|
||||
--- a/net/minecraft/network/chat/ComponentUtils.java
|
||||
+++ b/net/minecraft/network/chat/ComponentUtils.java
|
||||
@@ -41,6 +41,11 @@
|
||||
if (depth > 100) {
|
||||
return text.copy();
|
||||
} else {
|
||||
+ // Paper start - adventure; pass actual vanilla component
|
||||
+ if (text instanceof io.papermc.paper.adventure.AdventureComponent adventureComponent) {
|
||||
+ text = adventureComponent.deepConverted();
|
||||
+ }
|
||||
+ // Paper end - adventure; pass actual vanilla component
|
||||
MutableComponent mutableComponent = text.getContents().resolve(source, sender, depth + 1);
|
||||
|
||||
for (Component component : text.getSiblings()) {
|
@ -0,0 +1,10 @@
|
||||
--- a/net/minecraft/network/chat/MessageSignature.java
|
||||
+++ b/net/minecraft/network/chat/MessageSignature.java
|
||||
@@ -13,6 +13,7 @@
|
||||
import net.minecraft.util.SignatureValidator;
|
||||
|
||||
public record MessageSignature(byte[] bytes) {
|
||||
+ public net.kyori.adventure.chat.SignedMessage.Signature adventure() { return () -> this.bytes; } // Paper - adventure; support signed messages
|
||||
public static final Codec<MessageSignature> CODEC = ExtraCodecs.BASE64_STRING.xmap(MessageSignature::new, MessageSignature::bytes);
|
||||
public static final int BYTES = 256;
|
||||
|
@ -0,0 +1,14 @@
|
||||
--- a/net/minecraft/network/chat/MutableComponent.java
|
||||
+++ b/net/minecraft/network/chat/MutableComponent.java
|
||||
@@ -94,6 +94,11 @@
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
+ // Paper start - make AdventureComponent equivalent
|
||||
+ if (object instanceof io.papermc.paper.adventure.AdventureComponent adventureComponent) {
|
||||
+ object = adventureComponent.deepConverted();
|
||||
+ }
|
||||
+ // Paper end - make AdventureComponent equivalent
|
||||
return this == object
|
||||
|| object instanceof MutableComponent mutableComponent
|
||||
&& this.contents.equals(mutableComponent.contents)
|
@ -0,0 +1,44 @@
|
||||
--- a/net/minecraft/network/chat/OutgoingChatMessage.java
|
||||
+++ b/net/minecraft/network/chat/OutgoingChatMessage.java
|
||||
@@ -7,6 +7,12 @@
|
||||
|
||||
void sendToPlayer(ServerPlayer sender, boolean filterMaskEnabled, ChatType.Bound params);
|
||||
|
||||
+ // Paper start
|
||||
+ default void sendToPlayer(ServerPlayer sender, boolean filterMaskEnabled, ChatType.Bound params, @javax.annotation.Nullable Component unsigned) {
|
||||
+ this.sendToPlayer(sender, filterMaskEnabled, params);
|
||||
+ }
|
||||
+ // Paper end
|
||||
+
|
||||
static OutgoingChatMessage create(PlayerChatMessage message) {
|
||||
return (OutgoingChatMessage)(message.isSystem()
|
||||
? new OutgoingChatMessage.Disguised(message.decoratedContent())
|
||||
@@ -16,8 +22,13 @@
|
||||
public static record Disguised(@Override Component content) implements OutgoingChatMessage {
|
||||
@Override
|
||||
public void sendToPlayer(ServerPlayer sender, boolean filterMaskEnabled, ChatType.Bound params) {
|
||||
- sender.connection.sendDisguisedChatMessage(this.content, params);
|
||||
+ // Paper start
|
||||
+ this.sendToPlayer(sender, filterMaskEnabled, params, null);
|
||||
}
|
||||
+ public void sendToPlayer(ServerPlayer sender, boolean filterMaskEnabled, ChatType.Bound params, @javax.annotation.Nullable Component unsigned) {
|
||||
+ sender.connection.sendDisguisedChatMessage(unsigned != null ? unsigned : this.content, params);
|
||||
+ // Paper end
|
||||
+ }
|
||||
}
|
||||
|
||||
public static record Player(PlayerChatMessage message) implements OutgoingChatMessage {
|
||||
@@ -28,7 +39,13 @@
|
||||
|
||||
@Override
|
||||
public void sendToPlayer(ServerPlayer sender, boolean filterMaskEnabled, ChatType.Bound params) {
|
||||
+ // Paper start
|
||||
+ this.sendToPlayer(sender, filterMaskEnabled, params, null);
|
||||
+ }
|
||||
+ public void sendToPlayer(ServerPlayer sender, boolean filterMaskEnabled, ChatType.Bound params, @javax.annotation.Nullable Component unsigned) {
|
||||
+ // Paper end
|
||||
PlayerChatMessage playerChatMessage = this.message.filter(filterMaskEnabled);
|
||||
+ playerChatMessage = unsigned != null ? playerChatMessage.withUnsignedContent(unsigned) : playerChatMessage; // Paper
|
||||
if (!playerChatMessage.isFullyFiltered()) {
|
||||
sender.connection.sendPlayerChatMessage(playerChatMessage, params);
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
--- a/net/minecraft/network/chat/PlayerChatMessage.java
|
||||
+++ b/net/minecraft/network/chat/PlayerChatMessage.java
|
||||
@@ -17,6 +17,42 @@
|
||||
public record PlayerChatMessage(
|
||||
SignedMessageLink link, @Nullable MessageSignature signature, SignedMessageBody signedBody, @Nullable Component unsignedContent, FilterMask filterMask
|
||||
) {
|
||||
+ // Paper start - adventure; support signed messages
|
||||
+ public final class AdventureView implements net.kyori.adventure.chat.SignedMessage {
|
||||
+ private AdventureView() {
|
||||
+ }
|
||||
+ @Override
|
||||
+ public @org.jetbrains.annotations.NotNull Instant timestamp() {
|
||||
+ return PlayerChatMessage.this.timeStamp();
|
||||
+ }
|
||||
+ @Override
|
||||
+ public long salt() {
|
||||
+ return PlayerChatMessage.this.salt();
|
||||
+ }
|
||||
+ @Override
|
||||
+ public @org.jetbrains.annotations.Nullable Signature signature() {
|
||||
+ return PlayerChatMessage.this.signature == null ? null : PlayerChatMessage.this.signature.adventure();
|
||||
+ }
|
||||
+ @Override
|
||||
+ public net.kyori.adventure.text.@org.jetbrains.annotations.Nullable Component unsignedContent() {
|
||||
+ return PlayerChatMessage.this.unsignedContent() == null ? null : io.papermc.paper.adventure.PaperAdventure.asAdventure(PlayerChatMessage.this.unsignedContent());
|
||||
+ }
|
||||
+ @Override
|
||||
+ public @org.jetbrains.annotations.NotNull String message() {
|
||||
+ return PlayerChatMessage.this.signedContent();
|
||||
+ }
|
||||
+ @Override
|
||||
+ public @org.jetbrains.annotations.NotNull net.kyori.adventure.identity.Identity identity() {
|
||||
+ return net.kyori.adventure.identity.Identity.identity(PlayerChatMessage.this.sender());
|
||||
+ }
|
||||
+ public PlayerChatMessage playerChatMessage() {
|
||||
+ return PlayerChatMessage.this;
|
||||
+ }
|
||||
+ }
|
||||
+ public AdventureView adventureView() {
|
||||
+ return new AdventureView();
|
||||
+ }
|
||||
+ // Paper end - adventure; support signed messages
|
||||
public static final MapCodec<PlayerChatMessage> MAP_CODEC = RecordCodecBuilder.mapCodec(
|
||||
instance -> instance.group(
|
||||
SignedMessageLink.CODEC.fieldOf("link").forGetter(PlayerChatMessage::link),
|
||||
@@ -47,7 +83,14 @@
|
||||
}
|
||||
|
||||
public PlayerChatMessage withUnsignedContent(Component unsignedContent) {
|
||||
- Component component = !unsignedContent.equals(Component.literal(this.signedContent())) ? unsignedContent : null;
|
||||
+ // Paper start - adventure
|
||||
+ final Component component;
|
||||
+ if (unsignedContent instanceof io.papermc.paper.adventure.AdventureComponent advComponent) {
|
||||
+ component = this.signedContent().equals(io.papermc.paper.adventure.AdventureCodecs.tryCollapseToString(advComponent.adventure$component())) ? null : unsignedContent;
|
||||
+ } else {
|
||||
+ component = !unsignedContent.equals(Component.literal(this.signedContent())) ? unsignedContent : null;
|
||||
+ }
|
||||
+ // Paper end - adventure
|
||||
return new PlayerChatMessage(this.link, this.signature, this.signedBody, component, this.filterMask);
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
package net.minecraft.network.protocol.game;
|
||||
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
@@ -12,6 +13,12 @@
|
||||
@@ -12,6 +13,17 @@
|
||||
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundSystemChatPacket> STREAM_CODEC = StreamCodec.composite(ComponentSerialization.TRUSTED_STREAM_CODEC, ClientboundSystemChatPacket::content, ByteBufCodecs.BOOL, ClientboundSystemChatPacket::overlay, ClientboundSystemChatPacket::new);
|
||||
|
||||
@ -14,6 +14,11 @@
|
||||
+ this(org.bukkit.craftbukkit.util.CraftChatMessage.fromJSON(net.md_5.bungee.chat.ComponentSerializer.toString(content)), overlay);
|
||||
+ }
|
||||
+ // Spigot end
|
||||
+ // Paper start
|
||||
+ public ClientboundSystemChatPacket(net.kyori.adventure.text.Component content, boolean overlay) {
|
||||
+ this(io.papermc.paper.adventure.PaperAdventure.asVanilla(content), overlay);
|
||||
+ }
|
||||
+ // Paper end
|
||||
+
|
||||
@Override
|
||||
public PacketType<ClientboundSystemChatPacket> type() {
|
||||
|
@ -0,0 +1,21 @@
|
||||
--- a/net/minecraft/network/protocol/login/ClientboundLoginDisconnectPacket.java
|
||||
+++ b/net/minecraft/network/protocol/login/ClientboundLoginDisconnectPacket.java
|
||||
@@ -18,11 +18,16 @@
|
||||
}
|
||||
|
||||
private ClientboundLoginDisconnectPacket(FriendlyByteBuf buf) {
|
||||
- this.reason = Component.Serializer.fromJsonLenient(buf.readUtf(262144), RegistryAccess.EMPTY);
|
||||
+ this.reason = Component.Serializer.fromJsonLenient(buf.readUtf(FriendlyByteBuf.MAX_COMPONENT_STRING_LENGTH), RegistryAccess.EMPTY); // Paper - diff on change
|
||||
}
|
||||
|
||||
private void write(FriendlyByteBuf buf) {
|
||||
- buf.writeUtf(Component.Serializer.toJson(this.reason, RegistryAccess.EMPTY));
|
||||
+ // Paper start - Adventure
|
||||
+ // buf.writeUtf(Component.Serializer.toJson(this.reason, RegistryAccess.EMPTY));
|
||||
+ // In the login phase, buf.adventure$locale field is most likely null, but plugins may use internals to set it via the channel attribute
|
||||
+ java.util.Locale bufLocale = buf.adventure$locale;
|
||||
+ buf.writeJsonWithCodec(net.minecraft.network.chat.ComponentSerialization.localizedCodec(bufLocale == null ? java.util.Locale.US : bufLocale), this.reason, FriendlyByteBuf.MAX_COMPONENT_STRING_LENGTH);
|
||||
+ // Paper end - Adventure
|
||||
}
|
||||
|
||||
@Override
|
@ -26,7 +26,7 @@
|
||||
import net.minecraft.util.debugchart.RemoteDebugSampleType;
|
||||
import net.minecraft.util.debugchart.SampleLogger;
|
||||
import net.minecraft.util.debugchart.TpsDebugDimensions;
|
||||
@@ -156,37 +146,72 @@
|
||||
@@ -156,37 +146,73 @@
|
||||
import net.minecraft.world.level.biome.BiomeManager;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.FuelValues;
|
||||
@ -99,6 +99,7 @@
|
||||
public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTask> implements ServerInfo, ChunkIOErrorReporter, CommandSource {
|
||||
|
||||
public static final Logger LOGGER = LogUtils.getLogger();
|
||||
+ public static final net.kyori.adventure.text.logger.slf4j.ComponentLogger COMPONENT_LOGGER = net.kyori.adventure.text.logger.slf4j.ComponentLogger.logger(LOGGER.getName()); // Paper
|
||||
public static final String VANILLA_BRAND = "vanilla";
|
||||
private static final float AVERAGE_TICK_TIME_SMOOTHING = 0.8F;
|
||||
private static final int TICK_STATS_SPAN = 100;
|
||||
@ -107,10 +108,21 @@
|
||||
private static final int OVERLOADED_TICKS_THRESHOLD = 20;
|
||||
private static final long OVERLOADED_WARNING_INTERVAL_NANOS = 10L * TimeUtil.NANOSECONDS_PER_SECOND;
|
||||
private static final int OVERLOADED_TICKS_WARNING_INTERVAL = 100;
|
||||
@@ -277,6 +302,26 @@
|
||||
@@ -232,8 +258,7 @@
|
||||
private boolean preventProxyConnections;
|
||||
private boolean pvp;
|
||||
private boolean allowFlight;
|
||||
- @Nullable
|
||||
- private String motd;
|
||||
+ private net.kyori.adventure.text.Component motd; // Paper - Adventure
|
||||
private int playerIdleTimeout;
|
||||
private final long[] tickTimesNanos;
|
||||
private long aggregatedTickTimesNanos;
|
||||
@@ -276,6 +301,26 @@
|
||||
private static final AtomicReference<RuntimeException> fatalException = new AtomicReference();
|
||||
private final SuppressedExceptionCollector suppressedExceptions;
|
||||
private final DiscontinuousFrame tickFrame;
|
||||
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ public final WorldLoader.DataLoadContext worldLoader;
|
||||
+ public org.bukkit.craftbukkit.CraftServer server;
|
||||
@ -130,10 +142,9 @@
|
||||
+ public final double[] recentTps = new double[ 3 ];
|
||||
+ // Spigot end
|
||||
+ public final io.papermc.paper.configuration.PaperConfigurations paperConfigurations; // Paper - add paper configuration files
|
||||
+
|
||||
|
||||
public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) {
|
||||
AtomicReference<S> atomicreference = new AtomicReference();
|
||||
Thread thread = new Thread(() -> {
|
||||
@@ -290,14 +335,14 @@
|
||||
thread.setPriority(8);
|
||||
}
|
||||
@ -723,7 +734,7 @@
|
||||
this.nextTickTimeNanos += k * i;
|
||||
this.lastOverloadWarningNanos = this.nextTickTimeNanos;
|
||||
}
|
||||
+ }
|
||||
}
|
||||
+ // Spigot start
|
||||
+ if ( tickCount++ % MinecraftServer.SAMPLE_INTERVAL == 0 )
|
||||
+ {
|
||||
@ -733,7 +744,7 @@
|
||||
+ this.recentTps[1] = MinecraftServer.calcTps( this.recentTps[1], 0.9835, currentTps ); // 1/exp(5sec/5min)
|
||||
+ this.recentTps[2] = MinecraftServer.calcTps( this.recentTps[2], 0.9945, currentTps ); // 1/exp(5sec/15min)
|
||||
+ tickSection = curTime;
|
||||
}
|
||||
+ }
|
||||
+ // Spigot end
|
||||
|
||||
boolean flag = i == 0L;
|
||||
@ -850,13 +861,23 @@
|
||||
}
|
||||
|
||||
private void logTickMethodTime(long tickStartTime) {
|
||||
@@ -1154,11 +1501,34 @@
|
||||
@@ -1123,7 +1470,7 @@
|
||||
private ServerStatus buildServerStatus() {
|
||||
ServerStatus.Players serverping_serverpingplayersample = this.buildPlayerStatus();
|
||||
|
||||
- return new ServerStatus(Component.nullToEmpty(this.motd), Optional.of(serverping_serverpingplayersample), Optional.of(ServerStatus.Version.current()), Optional.ofNullable(this.statusIcon), this.enforceSecureProfile());
|
||||
+ return new ServerStatus(io.papermc.paper.adventure.PaperAdventure.asVanilla(this.motd), Optional.of(serverping_serverpingplayersample), Optional.of(ServerStatus.Version.current()), Optional.ofNullable(this.statusIcon), this.enforceSecureProfile()); // Paper - Adventure
|
||||
}
|
||||
|
||||
private ServerStatus.Players buildPlayerStatus() {
|
||||
@@ -1154,11 +1501,35 @@
|
||||
this.getPlayerList().getPlayers().forEach((entityplayer) -> {
|
||||
entityplayer.connection.suspendFlushing();
|
||||
});
|
||||
+ SpigotTimings.schedulerTimer.startTiming(); // Spigot
|
||||
+ this.server.getScheduler().mainThreadHeartbeat(); // CraftBukkit
|
||||
+ SpigotTimings.schedulerTimer.stopTiming(); // Spigot
|
||||
+ io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.CALLBACK_MANAGER.handleQueue(this.tickCount); // Paper
|
||||
gameprofilerfiller.push("commandFunctions");
|
||||
+ SpigotTimings.commandFunctionsTimer.startTiming(); // Spigot
|
||||
this.getFunctions().tick();
|
||||
@ -885,7 +906,7 @@
|
||||
while (iterator.hasNext()) {
|
||||
ServerLevel worldserver = (ServerLevel) iterator.next();
|
||||
|
||||
@@ -1167,16 +1537,20 @@
|
||||
@@ -1167,16 +1538,20 @@
|
||||
|
||||
return s + " " + String.valueOf(worldserver.dimension().location());
|
||||
});
|
||||
@ -906,7 +927,7 @@
|
||||
} catch (Throwable throwable) {
|
||||
CrashReport crashreport = CrashReport.forThrowable(throwable, "Exception ticking world");
|
||||
|
||||
@@ -1189,18 +1563,24 @@
|
||||
@@ -1189,18 +1564,24 @@
|
||||
}
|
||||
|
||||
gameprofilerfiller.popPush("connection");
|
||||
@ -931,12 +952,10 @@
|
||||
|
||||
gameprofilerfiller.popPush("send chunks");
|
||||
iterator = this.playerList.getPlayers().iterator();
|
||||
@@ -1265,7 +1645,23 @@
|
||||
@Nullable
|
||||
public ServerLevel getLevel(ResourceKey<Level> key) {
|
||||
@@ -1267,6 +1648,22 @@
|
||||
return (ServerLevel) this.levels.get(key);
|
||||
+ }
|
||||
+
|
||||
}
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ public void addLevel(ServerLevel level) {
|
||||
+ Map<ResourceKey<Level>, ServerLevel> oldLevels = this.levels;
|
||||
@ -950,12 +969,13 @@
|
||||
+ Map<ResourceKey<Level>, ServerLevel> newLevels = Maps.newLinkedHashMap(oldLevels);
|
||||
+ newLevels.remove(level.dimension());
|
||||
+ this.levels = Collections.unmodifiableMap(newLevels);
|
||||
}
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
|
||||
+
|
||||
public Set<ResourceKey<Level>> levelKeys() {
|
||||
return this.levels.keySet();
|
||||
@@ -1296,7 +1692,7 @@
|
||||
}
|
||||
@@ -1296,7 +1693,7 @@
|
||||
|
||||
@DontObfuscate
|
||||
public String getServerModName() {
|
||||
@ -964,7 +984,29 @@
|
||||
}
|
||||
|
||||
public SystemReport fillSystemReport(SystemReport details) {
|
||||
@@ -1507,7 +1903,7 @@
|
||||
@@ -1481,10 +1878,20 @@
|
||||
|
||||
@Override
|
||||
public String getMotd() {
|
||||
- return this.motd;
|
||||
+ return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(this.motd); // Paper - Adventure
|
||||
}
|
||||
|
||||
public void setMotd(String motd) {
|
||||
+ // Paper start - Adventure
|
||||
+ this.motd = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserializeOr(motd, net.kyori.adventure.text.Component.empty());
|
||||
+ }
|
||||
+
|
||||
+ public net.kyori.adventure.text.Component motd() {
|
||||
+ return this.motd;
|
||||
+ }
|
||||
+
|
||||
+ public void motd(net.kyori.adventure.text.Component motd) {
|
||||
+ // Paper end - Adventure
|
||||
this.motd = motd;
|
||||
}
|
||||
|
||||
@@ -1507,7 +1914,7 @@
|
||||
}
|
||||
|
||||
public ServerConnectionListener getConnection() {
|
||||
@ -973,7 +1015,7 @@
|
||||
}
|
||||
|
||||
public boolean isReady() {
|
||||
@@ -1634,11 +2030,11 @@
|
||||
@@ -1634,11 +2041,11 @@
|
||||
|
||||
public CompletableFuture<Void> reloadResources(Collection<String> dataPacks) {
|
||||
CompletableFuture<Void> completablefuture = CompletableFuture.supplyAsync(() -> {
|
||||
@ -987,7 +1029,7 @@
|
||||
}, this).thenCompose((immutablelist) -> {
|
||||
MultiPackResourceManager resourcemanager = new MultiPackResourceManager(PackType.SERVER_DATA, immutablelist);
|
||||
List<Registry.PendingTags<?>> list = TagLoader.loadTagsForExistingRegistries(resourcemanager, this.registries.compositeAccess());
|
||||
@@ -1654,6 +2050,7 @@
|
||||
@@ -1654,6 +2061,7 @@
|
||||
}).thenAcceptAsync((minecraftserver_reloadableresources) -> {
|
||||
this.resources.close();
|
||||
this.resources = minecraftserver_reloadableresources;
|
||||
@ -995,7 +1037,7 @@
|
||||
this.packRepository.setSelected(dataPacks);
|
||||
WorldDataConfiguration worlddataconfiguration = new WorldDataConfiguration(MinecraftServer.getSelectedPacks(this.packRepository, true), this.worldData.enabledFeatures());
|
||||
|
||||
@@ -1952,7 +2349,7 @@
|
||||
@@ -1952,7 +2360,7 @@
|
||||
final List<String> list = Lists.newArrayList();
|
||||
final GameRules gamerules = this.getGameRules();
|
||||
|
||||
@ -1004,7 +1046,7 @@
|
||||
@Override
|
||||
public <T extends GameRules.Value<T>> void visit(GameRules.Key<T> key, GameRules.Type<T> type) {
|
||||
list.add(String.format(Locale.ROOT, "%s=%s\n", key.getId(), gamerules.getRule(key)));
|
||||
@@ -2058,7 +2455,7 @@
|
||||
@@ -2058,7 +2466,7 @@
|
||||
try {
|
||||
label51:
|
||||
{
|
||||
@ -1013,40 +1055,58 @@
|
||||
|
||||
try {
|
||||
arraylist = Lists.newArrayList(NativeModuleLister.listModules());
|
||||
@@ -2105,8 +2502,24 @@
|
||||
@@ -2105,9 +2513,25 @@
|
||||
if (bufferedwriter != null) {
|
||||
bufferedwriter.close();
|
||||
}
|
||||
+
|
||||
+ }
|
||||
+
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ public boolean isDebugging() {
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
}
|
||||
|
||||
+ @Deprecated
|
||||
+ public static MinecraftServer getServer() {
|
||||
+ return (Bukkit.getServer() instanceof CraftServer) ? ((CraftServer) Bukkit.getServer()).getServer() : null;
|
||||
+ }
|
||||
|
||||
+
|
||||
+ @Deprecated
|
||||
+ public static RegistryAccess getDefaultRegistryAccess() {
|
||||
+ return CraftRegistry.getMinecraftRegistry();
|
||||
}
|
||||
+ // CraftBukkit end
|
||||
|
||||
private ProfilerFiller createProfiler() {
|
||||
if (this.willStartRecordingMetrics) {
|
||||
@@ -2235,6 +2648,11 @@
|
||||
|
||||
}
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ public final java.util.concurrent.ExecutorService chatExecutor = java.util.concurrent.Executors.newCachedThreadPool(
|
||||
+ new com.google.common.util.concurrent.ThreadFactoryBuilder().setDaemon(true).setNameFormat("Async Chat Thread - #%d").build());
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
public ChatDecorator getChatDecorator() {
|
||||
return ChatDecorator.PLAIN;
|
||||
private ProfilerFiller createProfiler() {
|
||||
if (this.willStartRecordingMetrics) {
|
||||
this.metricsRecorder = ActiveMetricsRecorder.createStarted(new ServerMetricsSamplersProvider(Util.timeSource, this.isDedicatedServer()), Util.timeSource, Util.ioPool(), new MetricsPersister("server"), this.onMetricsRecordingStopped, (path) -> {
|
||||
@@ -2225,18 +2649,24 @@
|
||||
}
|
||||
|
||||
public void logChatMessage(Component message, ChatType.Bound params, @Nullable String prefix) {
|
||||
- String s1 = params.decorate(message).getString();
|
||||
+ // Paper start
|
||||
+ net.kyori.adventure.text.Component s1 = io.papermc.paper.adventure.PaperAdventure.asAdventure(params.decorate(message));
|
||||
|
||||
if (prefix != null) {
|
||||
- MinecraftServer.LOGGER.info("[{}] {}", prefix, s1);
|
||||
+ MinecraftServer.COMPONENT_LOGGER.info("[{}] {}", prefix, s1);
|
||||
} else {
|
||||
- MinecraftServer.LOGGER.info("{}", s1);
|
||||
+ MinecraftServer.COMPONENT_LOGGER.info("{}", s1);
|
||||
+ // Paper end
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+ public final java.util.concurrent.ExecutorService chatExecutor = java.util.concurrent.Executors.newCachedThreadPool(
|
||||
+ new com.google.common.util.concurrent.ThreadFactoryBuilder().setDaemon(true).setNameFormat("Async Chat Thread - #%d").setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(net.minecraft.server.MinecraftServer.LOGGER)).build()); // Paper
|
||||
+
|
||||
+ public final ChatDecorator improvedChatDecorator = new io.papermc.paper.adventure.ImprovedChatDecorator(this); // Paper - adventure
|
||||
public ChatDecorator getChatDecorator() {
|
||||
- return ChatDecorator.PLAIN;
|
||||
+ return this.improvedChatDecorator; // Paper - support async chat decoration events
|
||||
}
|
||||
|
||||
public boolean logIPs() {
|
||||
|
@ -53,7 +53,7 @@
|
||||
import net.minecraft.world.level.gameevent.GameEvent;
|
||||
import net.minecraft.world.level.portal.TeleportTransition;
|
||||
import net.minecraft.world.level.saveddata.maps.MapId;
|
||||
@@ -179,11 +176,47 @@
|
||||
@@ -179,11 +176,48 @@
|
||||
import net.minecraft.world.scores.PlayerTeam;
|
||||
import net.minecraft.world.scores.ScoreAccess;
|
||||
import net.minecraft.world.scores.ScoreHolder;
|
||||
@ -71,6 +71,7 @@
|
||||
import net.minecraft.world.scores.Team;
|
||||
import net.minecraft.world.scores.criteria.ObjectiveCriteria;
|
||||
-import org.slf4j.Logger;
|
||||
+import io.papermc.paper.adventure.PaperAdventure; // Paper
|
||||
+import org.bukkit.Bukkit;
|
||||
+import org.bukkit.Location;
|
||||
+import org.bukkit.WeatherType;
|
||||
@ -103,23 +104,24 @@
|
||||
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
private static final int NEUTRAL_MOB_DEATH_NOTIFICATION_RADII_XZ = 32;
|
||||
@@ -225,7 +258,7 @@
|
||||
@@ -225,7 +259,8 @@
|
||||
private int levitationStartTime;
|
||||
private boolean disconnected;
|
||||
private int requestedViewDistance;
|
||||
- public String language;
|
||||
+ public String language = "en_us"; // CraftBukkit - default
|
||||
+ public java.util.Locale adventure$locale = java.util.Locale.US; // Paper
|
||||
@Nullable
|
||||
private Vec3 startingToFallPosition;
|
||||
@Nullable
|
||||
@@ -258,6 +291,23 @@
|
||||
private final CommandSource commandSource;
|
||||
@@ -259,6 +294,24 @@
|
||||
private int containerCounter;
|
||||
public boolean wonGame;
|
||||
+
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ public CraftPlayer.TransferCookieConnection transferCookieConnection;
|
||||
+ public String displayName;
|
||||
+ public net.kyori.adventure.text.Component adventure$displayName; // Paper
|
||||
+ public Component listName;
|
||||
+ public int listOrder = 0;
|
||||
+ public org.bukkit.Location compassTarget;
|
||||
@ -133,10 +135,11 @@
|
||||
+ public String kickLeaveMessage = null; // SPIGOT-3034: Forward leave message to PlayerQuitEvent
|
||||
+ // CraftBukkit end
|
||||
+ public boolean isRealPlayer; // Paper
|
||||
|
||||
+
|
||||
public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile, ClientInformation clientOptions) {
|
||||
super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile);
|
||||
@@ -340,6 +390,13 @@
|
||||
this.chatVisibility = ChatVisiblity.FULL;
|
||||
@@ -340,6 +393,13 @@
|
||||
public void sendSystemMessage(Component message) {
|
||||
ServerPlayer.this.sendSystemMessage(message);
|
||||
}
|
||||
@ -150,13 +153,14 @@
|
||||
};
|
||||
this.textFilter = server.createTextFilterForPlayer(this);
|
||||
this.gameMode = server.createGameModeForPlayer(this);
|
||||
@@ -352,14 +409,67 @@
|
||||
@@ -352,14 +412,68 @@
|
||||
this.moveTo(this.adjustSpawnLocation(world, world.getSharedSpawnPos()).getBottomCenter(), 0.0F, 0.0F);
|
||||
this.updateOptions(clientOptions);
|
||||
this.object = null;
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ this.displayName = this.getScoreboardName();
|
||||
+ this.adventure$displayName = net.kyori.adventure.text.Component.text(this.getScoreboardName()); // Paper
|
||||
+ this.bukkitPickUpLoot = true;
|
||||
+ this.maxHealthCache = this.getMaxHealth();
|
||||
+ }
|
||||
@ -219,7 +223,7 @@
|
||||
int i = Math.max(0, this.server.getSpawnRadius(world));
|
||||
int j = Mth.floor(world.getWorldBorder().getDistanceToBorder((double) basePos.getX(), (double) basePos.getZ()));
|
||||
|
||||
@@ -395,14 +505,20 @@
|
||||
@@ -395,14 +509,20 @@
|
||||
|
||||
Objects.requireNonNull(basePos);
|
||||
crashreportsystemdetails.setDetail("Origin", basePos::toString);
|
||||
@ -242,7 +246,7 @@
|
||||
});
|
||||
throw new ReportedException(crashreport);
|
||||
}
|
||||
@@ -440,7 +556,7 @@
|
||||
@@ -440,7 +560,7 @@
|
||||
dataresult = WardenSpawnTracker.CODEC.parse(new Dynamic(NbtOps.INSTANCE, nbt.get("warden_spawn_tracker")));
|
||||
logger = ServerPlayer.LOGGER;
|
||||
Objects.requireNonNull(logger);
|
||||
@ -251,7 +255,7 @@
|
||||
this.wardenSpawnTracker = wardenspawntracker;
|
||||
});
|
||||
}
|
||||
@@ -457,17 +573,26 @@
|
||||
@@ -457,17 +577,26 @@
|
||||
return this.server.getRecipeManager().byKey(resourcekey).isPresent();
|
||||
});
|
||||
}
|
||||
@ -279,7 +283,7 @@
|
||||
Logger logger1 = ServerPlayer.LOGGER;
|
||||
|
||||
Objects.requireNonNull(logger1);
|
||||
@@ -482,7 +607,7 @@
|
||||
@@ -482,7 +611,7 @@
|
||||
dataresult = BlockPos.CODEC.parse(NbtOps.INSTANCE, nbtbase);
|
||||
logger = ServerPlayer.LOGGER;
|
||||
Objects.requireNonNull(logger);
|
||||
@ -288,7 +292,7 @@
|
||||
this.raidOmenPosition = blockposition;
|
||||
});
|
||||
}
|
||||
@@ -492,7 +617,7 @@
|
||||
@@ -492,7 +621,7 @@
|
||||
@Override
|
||||
public void addAdditionalSaveData(CompoundTag nbt) {
|
||||
super.addAdditionalSaveData(nbt);
|
||||
@ -297,7 +301,7 @@
|
||||
Logger logger = ServerPlayer.LOGGER;
|
||||
|
||||
Objects.requireNonNull(logger);
|
||||
@@ -526,6 +651,7 @@
|
||||
@@ -526,6 +655,7 @@
|
||||
nbt.put("SpawnDimension", nbtbase);
|
||||
});
|
||||
}
|
||||
@ -305,7 +309,7 @@
|
||||
|
||||
nbt.putBoolean("spawn_extra_particles_on_fall", this.spawnExtraParticlesOnFall);
|
||||
if (this.raidOmenPosition != null) {
|
||||
@@ -544,7 +670,20 @@
|
||||
@@ -544,7 +674,20 @@
|
||||
Entity entity = this.getRootVehicle();
|
||||
Entity entity1 = this.getVehicle();
|
||||
|
||||
@ -327,7 +331,7 @@
|
||||
CompoundTag nbttagcompound1 = new CompoundTag();
|
||||
CompoundTag nbttagcompound2 = new CompoundTag();
|
||||
|
||||
@@ -598,12 +737,12 @@
|
||||
@@ -598,12 +741,12 @@
|
||||
|
||||
if (!this.isPassenger()) {
|
||||
ServerPlayer.LOGGER.warn("Couldn't reattach entity to player");
|
||||
@ -342,7 +346,7 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -625,7 +764,7 @@
|
||||
@@ -625,7 +768,7 @@
|
||||
CompoundTag nbttagcompound1 = new CompoundTag();
|
||||
|
||||
entityenderpearl.save(nbttagcompound1);
|
||||
@ -351,7 +355,7 @@
|
||||
Logger logger = ServerPlayer.LOGGER;
|
||||
|
||||
Objects.requireNonNull(logger);
|
||||
@@ -651,7 +790,7 @@
|
||||
@@ -651,7 +794,7 @@
|
||||
nbttaglist.forEach((nbtbase1) -> {
|
||||
if (nbtbase1 instanceof CompoundTag nbttagcompound) {
|
||||
if (nbttagcompound.contains("ender_pearl_dimension")) {
|
||||
@ -360,7 +364,7 @@
|
||||
Logger logger = ServerPlayer.LOGGER;
|
||||
|
||||
Objects.requireNonNull(logger);
|
||||
@@ -684,7 +823,30 @@
|
||||
@@ -684,7 +827,30 @@
|
||||
}
|
||||
}
|
||||
|
||||
@ -391,7 +395,7 @@
|
||||
|
||||
public void setExperiencePoints(int points) {
|
||||
float f = (float) this.getXpNeededForNextLevel();
|
||||
@@ -744,6 +906,11 @@
|
||||
@@ -744,6 +910,11 @@
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
@ -403,7 +407,7 @@
|
||||
this.tickClientLoadTimeout();
|
||||
this.gameMode.tick();
|
||||
this.wardenSpawnTracker.tick();
|
||||
@@ -820,7 +987,7 @@
|
||||
@@ -820,7 +991,7 @@
|
||||
}
|
||||
|
||||
if (this.getHealth() != this.lastSentHealth || this.lastSentFood != this.foodData.getFoodLevel() || this.foodData.getSaturationLevel() == 0.0F != this.lastFoodSaturationZero) {
|
||||
@ -412,20 +416,21 @@
|
||||
this.lastSentHealth = this.getHealth();
|
||||
this.lastSentFood = this.foodData.getFoodLevel();
|
||||
this.lastFoodSaturationZero = this.foodData.getSaturationLevel() == 0.0F;
|
||||
@@ -851,6 +1018,12 @@
|
||||
@@ -849,7 +1020,13 @@
|
||||
if (this.totalExperience != this.lastRecordedExperience) {
|
||||
this.lastRecordedExperience = this.totalExperience;
|
||||
this.updateScoreForCriteria(ObjectiveCriteria.EXPERIENCE, Mth.ceil((float) this.lastRecordedExperience));
|
||||
}
|
||||
|
||||
+ }
|
||||
+
|
||||
+ // CraftBukkit start - Force max health updates
|
||||
+ if (this.maxHealthCache != this.getMaxHealth()) {
|
||||
+ this.getBukkitEntity().updateScaledHealth();
|
||||
+ }
|
||||
}
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
|
||||
if (this.experienceLevel != this.lastRecordedLevel) {
|
||||
this.lastRecordedLevel = this.experienceLevel;
|
||||
this.updateScoreForCriteria(ObjectiveCriteria.LEVEL, Mth.ceil((float) this.lastRecordedLevel));
|
||||
@@ -865,6 +1038,20 @@
|
||||
@@ -865,6 +1042,20 @@
|
||||
CriteriaTriggers.LOCATION.trigger(this);
|
||||
}
|
||||
|
||||
@ -446,7 +451,7 @@
|
||||
} catch (Throwable throwable) {
|
||||
CrashReport crashreport = CrashReport.forThrowable(throwable, "Ticking player");
|
||||
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Player being ticked");
|
||||
@@ -893,7 +1080,7 @@
|
||||
@@ -893,7 +1084,7 @@
|
||||
if (this.level().getDifficulty() == Difficulty.PEACEFUL && this.serverLevel().getGameRules().getBoolean(GameRules.RULE_NATURAL_REGENERATION)) {
|
||||
if (this.tickCount % 20 == 0) {
|
||||
if (this.getHealth() < this.getMaxHealth()) {
|
||||
@ -455,7 +460,7 @@
|
||||
}
|
||||
|
||||
float f = this.foodData.getSaturationLevel();
|
||||
@@ -946,7 +1133,8 @@
|
||||
@@ -946,7 +1137,8 @@
|
||||
}
|
||||
|
||||
private void updateScoreForCriteria(ObjectiveCriteria criterion, int score) {
|
||||
@ -465,7 +470,7 @@
|
||||
scoreaccess.set(score);
|
||||
});
|
||||
}
|
||||
@@ -955,9 +1143,47 @@
|
||||
@@ -955,10 +1147,43 @@
|
||||
public void die(DamageSource damageSource) {
|
||||
this.gameEvent(GameEvent.ENTITY_DIE);
|
||||
boolean flag = this.serverLevel().getGameRules().getBoolean(GameRules.RULE_SHOWDEATHMESSAGES);
|
||||
@ -488,7 +493,7 @@
|
||||
+ // SPIGOT-5071: manually add player loot tables (SPIGOT-5195 - ignores keepInventory rule)
|
||||
+ this.dropFromLootTable(this.serverLevel(), damageSource, this.lastHurtByPlayerTime > 0);
|
||||
+ this.dropCustomDeathLoot(this.serverLevel(), damageSource, flag);
|
||||
+
|
||||
|
||||
+ loot.addAll(this.drops);
|
||||
+ this.drops.clear(); // SPIGOT-5188: make sure to clear
|
||||
+
|
||||
@ -496,26 +501,22 @@
|
||||
+
|
||||
+ String deathmessage = defaultMessage.getString();
|
||||
+ this.keepLevel = keepInventory; // SPIGOT-2222: pre-set keepLevel
|
||||
+ org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, damageSource, loot, deathmessage, keepInventory);
|
||||
+ org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, damageSource, loot, PaperAdventure.asAdventure(defaultMessage), keepInventory); // Paper - Adventure
|
||||
+
|
||||
+ // SPIGOT-943 - only call if they have an inventory open
|
||||
+ if (this.containerMenu != this.inventoryMenu) {
|
||||
+ this.closeContainer();
|
||||
+ }
|
||||
+
|
||||
+ String deathMessage = event.getDeathMessage();
|
||||
+ net.kyori.adventure.text.Component deathMessage = event.deathMessage() != null ? event.deathMessage() : net.kyori.adventure.text.Component.empty(); // Paper - Adventure
|
||||
+
|
||||
+ if (deathMessage != null && deathMessage != net.kyori.adventure.text.Component.empty() && flag) { // Paper - Adventure // TODO: allow plugins to override?
|
||||
+ Component ichatbasecomponent = PaperAdventure.asVanilla(deathMessage); // Paper - Adventure
|
||||
+
|
||||
+ if (deathMessage != null && deathMessage.length() > 0 && flag) { // TODO: allow plugins to override?
|
||||
+ Component ichatbasecomponent;
|
||||
+ if (deathMessage.equals(deathmessage)) {
|
||||
+ ichatbasecomponent = this.getCombatTracker().getDeathMessage();
|
||||
+ } else {
|
||||
+ ichatbasecomponent = org.bukkit.craftbukkit.util.CraftChatMessage.fromStringOrNull(deathMessage);
|
||||
+ }
|
||||
|
||||
this.connection.send(new ClientboundPlayerCombatKillPacket(this.getId(), ichatbasecomponent), PacketSendListener.exceptionallySend(() -> {
|
||||
boolean flag1 = true;
|
||||
@@ -988,12 +1214,18 @@
|
||||
String s = ichatbasecomponent.getString(256);
|
||||
@@ -988,12 +1213,18 @@
|
||||
if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_FORGIVE_DEAD_PLAYERS)) {
|
||||
this.tellNeutralMobsThatIDied();
|
||||
}
|
||||
@ -538,7 +539,7 @@
|
||||
LivingEntity entityliving = this.getKillCredit();
|
||||
|
||||
if (entityliving != null) {
|
||||
@@ -1028,10 +1260,12 @@
|
||||
@@ -1028,10 +1259,12 @@
|
||||
public void awardKillScore(Entity entityKilled, DamageSource damageSource) {
|
||||
if (entityKilled != this) {
|
||||
super.awardKillScore(entityKilled, damageSource);
|
||||
@ -554,7 +555,7 @@
|
||||
} else {
|
||||
this.awardStat(Stats.MOB_KILLS);
|
||||
}
|
||||
@@ -1049,7 +1283,8 @@
|
||||
@@ -1049,7 +1282,8 @@
|
||||
int i = scoreboardteam.getColor().getId();
|
||||
|
||||
if (i >= 0 && i < criterions.length) {
|
||||
@ -564,7 +565,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1062,8 +1297,8 @@
|
||||
@@ -1062,8 +1296,8 @@
|
||||
} else {
|
||||
Entity entity = source.getEntity();
|
||||
|
||||
@ -575,7 +576,7 @@
|
||||
|
||||
if (!this.canHarmPlayer(entityhuman)) {
|
||||
return false;
|
||||
@@ -1074,8 +1309,8 @@
|
||||
@@ -1074,8 +1308,8 @@
|
||||
AbstractArrow entityarrow = (AbstractArrow) entity;
|
||||
Entity entity1 = entityarrow.getOwner();
|
||||
|
||||
@ -586,7 +587,7 @@
|
||||
|
||||
if (!this.canHarmPlayer(entityhuman1)) {
|
||||
return false;
|
||||
@@ -1088,33 +1323,63 @@
|
||||
@@ -1088,33 +1322,63 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -657,7 +658,7 @@
|
||||
}
|
||||
|
||||
public static Optional<ServerPlayer.RespawnPosAngle> findRespawnAndUseSpawnBlock(ServerLevel world, BlockPos pos, float spawnAngle, boolean spawnForced, boolean alive) {
|
||||
@@ -1129,11 +1394,11 @@
|
||||
@@ -1129,11 +1393,11 @@
|
||||
}
|
||||
|
||||
return optional.map((vec3d) -> {
|
||||
@ -671,7 +672,7 @@
|
||||
});
|
||||
} else if (!spawnForced) {
|
||||
return Optional.empty();
|
||||
@@ -1142,7 +1407,7 @@
|
||||
@@ -1142,7 +1406,7 @@
|
||||
BlockState iblockdata1 = world.getBlockState(pos.above());
|
||||
boolean flag3 = iblockdata1.getBlock().isPossibleToRespawnInThis(iblockdata1);
|
||||
|
||||
@ -680,7 +681,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1160,6 +1425,7 @@
|
||||
@@ -1160,6 +1424,7 @@
|
||||
@Nullable
|
||||
@Override
|
||||
public ServerPlayer teleport(TeleportTransition teleportTarget) {
|
||||
@ -688,7 +689,7 @@
|
||||
if (this.isRemoved()) {
|
||||
return null;
|
||||
} else {
|
||||
@@ -1169,39 +1435,73 @@
|
||||
@@ -1169,39 +1434,73 @@
|
||||
|
||||
ServerLevel worldserver = teleportTarget.newLevel();
|
||||
ServerLevel worldserver1 = this.serverLevel();
|
||||
@ -770,7 +771,7 @@
|
||||
this.connection.resetPosition();
|
||||
worldserver.addDuringTeleport(this);
|
||||
gameprofilerfiller.pop();
|
||||
@@ -1215,12 +1515,30 @@
|
||||
@@ -1215,12 +1514,30 @@
|
||||
this.lastSentExp = -1;
|
||||
this.lastSentHealth = -1.0F;
|
||||
this.lastSentFood = -1;
|
||||
@ -801,7 +802,7 @@
|
||||
public void forceSetRotation(float yaw, float pitch) {
|
||||
this.connection.send(new ClientboundPlayerRotationPacket(yaw, pitch));
|
||||
}
|
||||
@@ -1228,13 +1546,21 @@
|
||||
@@ -1228,13 +1545,21 @@
|
||||
public void triggerDimensionChangeTriggers(ServerLevel origin) {
|
||||
ResourceKey<Level> resourcekey = origin.dimension();
|
||||
ResourceKey<Level> resourcekey1 = this.level().dimension();
|
||||
@ -826,7 +827,7 @@
|
||||
this.enteredNetherPosition = null;
|
||||
}
|
||||
|
||||
@@ -1251,36 +1577,63 @@
|
||||
@@ -1251,36 +1576,63 @@
|
||||
this.containerMenu.broadcastChanges();
|
||||
}
|
||||
|
||||
@ -905,7 +906,7 @@
|
||||
this.awardStat(Stats.SLEEP_IN_BED);
|
||||
CriteriaTriggers.SLEPT_IN_BED.trigger(this);
|
||||
});
|
||||
@@ -1293,9 +1646,8 @@
|
||||
@@ -1293,9 +1645,8 @@
|
||||
return either;
|
||||
}
|
||||
}
|
||||
@ -916,7 +917,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1322,13 +1674,31 @@
|
||||
@@ -1322,13 +1673,31 @@
|
||||
|
||||
@Override
|
||||
public void stopSleepInBed(boolean skipSleepTimer, boolean updateSleepingPlayers) {
|
||||
@ -949,7 +950,7 @@
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1387,8 +1757,9 @@
|
||||
@@ -1387,8 +1756,9 @@
|
||||
this.connection.send(new ClientboundOpenSignEditorPacket(sign.getBlockPos(), front));
|
||||
}
|
||||
|
||||
@ -960,7 +961,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1396,13 +1767,35 @@
|
||||
@@ -1396,13 +1766,35 @@
|
||||
if (factory == null) {
|
||||
return OptionalInt.empty();
|
||||
} else {
|
||||
@ -996,7 +997,7 @@
|
||||
if (container == null) {
|
||||
if (this.isSpectator()) {
|
||||
this.displayClientMessage(Component.translatable("container.spectatorCantOpen").withStyle(ChatFormatting.RED), true);
|
||||
@@ -1410,9 +1803,11 @@
|
||||
@@ -1410,9 +1802,11 @@
|
||||
|
||||
return OptionalInt.empty();
|
||||
} else {
|
||||
@ -1010,7 +1011,7 @@
|
||||
return OptionalInt.of(this.containerCounter);
|
||||
}
|
||||
}
|
||||
@@ -1425,15 +1820,26 @@
|
||||
@@ -1425,15 +1819,26 @@
|
||||
|
||||
@Override
|
||||
public void openHorseInventory(AbstractHorse horse, Container inventory) {
|
||||
@ -1039,7 +1040,7 @@
|
||||
this.initMenu(this.containerMenu);
|
||||
}
|
||||
|
||||
@@ -1456,6 +1862,7 @@
|
||||
@@ -1456,6 +1861,7 @@
|
||||
|
||||
@Override
|
||||
public void closeContainer() {
|
||||
@ -1047,7 +1048,7 @@
|
||||
this.connection.send(new ClientboundContainerClosePacket(this.containerMenu.containerId));
|
||||
this.doCloseContainer();
|
||||
}
|
||||
@@ -1485,19 +1892,19 @@
|
||||
@@ -1485,19 +1891,19 @@
|
||||
i = Math.round((float) Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ) * 100.0F);
|
||||
if (i > 0) {
|
||||
this.awardStat(Stats.SWIM_ONE_CM, i);
|
||||
@ -1070,7 +1071,7 @@
|
||||
}
|
||||
} else if (this.onClimbable()) {
|
||||
if (deltaY > 0.0D) {
|
||||
@@ -1508,13 +1915,13 @@
|
||||
@@ -1508,13 +1914,13 @@
|
||||
if (i > 0) {
|
||||
if (this.isSprinting()) {
|
||||
this.awardStat(Stats.SPRINT_ONE_CM, i);
|
||||
@ -1087,7 +1088,7 @@
|
||||
}
|
||||
}
|
||||
} else if (this.isFallFlying()) {
|
||||
@@ -1557,7 +1964,7 @@
|
||||
@@ -1557,7 +1963,7 @@
|
||||
@Override
|
||||
public void awardStat(Stat<?> stat, int amount) {
|
||||
this.stats.increment(this, stat, amount);
|
||||
@ -1096,7 +1097,7 @@
|
||||
scoreaccess.add(amount);
|
||||
});
|
||||
}
|
||||
@@ -1565,7 +1972,7 @@
|
||||
@@ -1565,7 +1971,7 @@
|
||||
@Override
|
||||
public void resetStat(Stat<?> stat) {
|
||||
this.stats.setValue(this, stat, 0);
|
||||
@ -1105,7 +1106,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1597,9 +2004,9 @@
|
||||
@@ -1597,9 +2003,9 @@
|
||||
super.jumpFromGround();
|
||||
this.awardStat(Stats.JUMP);
|
||||
if (this.isSprinting()) {
|
||||
@ -1117,7 +1118,7 @@
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1625,6 +2032,7 @@
|
||||
@@ -1625,6 +2031,7 @@
|
||||
|
||||
public void resetSentInfo() {
|
||||
this.lastSentHealth = -1.0E8F;
|
||||
@ -1125,7 +1126,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1661,7 +2069,7 @@
|
||||
@@ -1661,7 +2068,7 @@
|
||||
this.onUpdateAbilities();
|
||||
if (alive) {
|
||||
this.getAttributes().assignBaseValues(oldPlayer.getAttributes());
|
||||
@ -1134,7 +1135,7 @@
|
||||
this.setHealth(oldPlayer.getHealth());
|
||||
this.foodData = oldPlayer.foodData;
|
||||
Iterator iterator = oldPlayer.getActiveEffects().iterator();
|
||||
@@ -1669,7 +2077,7 @@
|
||||
@@ -1669,7 +2076,7 @@
|
||||
while (iterator.hasNext()) {
|
||||
MobEffectInstance mobeffect = (MobEffectInstance) iterator.next();
|
||||
|
||||
@ -1143,7 +1144,7 @@
|
||||
}
|
||||
|
||||
this.getInventory().replaceWith(oldPlayer.getInventory());
|
||||
@@ -1680,7 +2088,7 @@
|
||||
@@ -1680,7 +2087,7 @@
|
||||
this.portalProcess = oldPlayer.portalProcess;
|
||||
} else {
|
||||
this.getAttributes().assignBaseValues(oldPlayer.getAttributes());
|
||||
@ -1152,7 +1153,7 @@
|
||||
if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || oldPlayer.isSpectator()) {
|
||||
this.getInventory().replaceWith(oldPlayer.getInventory());
|
||||
this.experienceLevel = oldPlayer.experienceLevel;
|
||||
@@ -1696,7 +2104,7 @@
|
||||
@@ -1696,7 +2103,7 @@
|
||||
this.lastSentExp = -1;
|
||||
this.lastSentHealth = -1.0F;
|
||||
this.lastSentFood = -1;
|
||||
@ -1161,7 +1162,7 @@
|
||||
this.seenCredits = oldPlayer.seenCredits;
|
||||
this.enteredNetherPosition = oldPlayer.enteredNetherPosition;
|
||||
this.chunkTrackingView = oldPlayer.chunkTrackingView;
|
||||
@@ -1752,19 +2160,19 @@
|
||||
@@ -1752,19 +2159,19 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1185,7 +1186,22 @@
|
||||
}
|
||||
|
||||
return flag1;
|
||||
@@ -1878,6 +2286,16 @@
|
||||
@@ -1861,8 +2268,13 @@
|
||||
}
|
||||
|
||||
public void sendChatMessage(OutgoingChatMessage message, boolean filterMaskEnabled, ChatType.Bound params) {
|
||||
+ // Paper start
|
||||
+ this.sendChatMessage(message, filterMaskEnabled, params, null);
|
||||
+ }
|
||||
+ public void sendChatMessage(OutgoingChatMessage message, boolean filterMaskEnabled, ChatType.Bound params, @Nullable Component unsigned) {
|
||||
+ // Paper end
|
||||
if (this.acceptsChatMessages()) {
|
||||
- message.sendToPlayer(this, filterMaskEnabled, params);
|
||||
+ message.sendToPlayer(this, filterMaskEnabled, params, unsigned); // Paper
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1878,7 +2290,18 @@
|
||||
}
|
||||
|
||||
public void updateOptions(ClientInformation clientOptions) {
|
||||
@ -1200,9 +1216,11 @@
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
this.language = clientOptions.language();
|
||||
+ this.adventure$locale = java.util.Objects.requireNonNullElse(net.kyori.adventure.translation.Translator.parseLocale(this.language), java.util.Locale.US); // Paper
|
||||
this.requestedViewDistance = clientOptions.viewDistance();
|
||||
this.chatVisibility = clientOptions.chatVisibility();
|
||||
@@ -1962,7 +2380,7 @@
|
||||
this.canChatColor = clientOptions.chatColors();
|
||||
@@ -1962,7 +2385,7 @@
|
||||
if (world instanceof ServerLevel) {
|
||||
ServerLevel worldserver = (ServerLevel) world;
|
||||
|
||||
@ -1211,7 +1229,7 @@
|
||||
}
|
||||
|
||||
if (entity != null) {
|
||||
@@ -1999,11 +2417,11 @@
|
||||
@@ -1999,11 +2422,11 @@
|
||||
|
||||
@Nullable
|
||||
public Component getTabListDisplayName() {
|
||||
@ -1225,7 +1243,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2046,17 +2464,43 @@
|
||||
@@ -2046,17 +2469,43 @@
|
||||
}
|
||||
|
||||
public void setRespawnPosition(ResourceKey<Level> dimension, @Nullable BlockPos pos, float angle, boolean forced, boolean sendMessage) {
|
||||
@ -1276,7 +1294,7 @@
|
||||
} else {
|
||||
this.respawnPosition = null;
|
||||
this.respawnDimension = Level.OVERWORLD;
|
||||
@@ -2088,18 +2532,44 @@
|
||||
@@ -2088,18 +2537,44 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1325,7 +1343,7 @@
|
||||
}
|
||||
|
||||
this.awardStat(Stats.DROP);
|
||||
@@ -2375,16 +2845,160 @@
|
||||
@@ -2375,10 +2850,12 @@
|
||||
return TicketType.ENDER_PEARL.timeout();
|
||||
}
|
||||
|
||||
@ -1341,11 +1359,10 @@
|
||||
}
|
||||
|
||||
private static float calculateLookAtYaw(Vec3 respawnPos, BlockPos currentPos) {
|
||||
Vec3 vec3d1 = Vec3.atBottomCenterOf(currentPos).subtract(respawnPos).normalize();
|
||||
|
||||
@@ -2387,4 +2864,146 @@
|
||||
return (float) Mth.wrapDegrees(Mth.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D);
|
||||
+ }
|
||||
+ }
|
||||
}
|
||||
}
|
||||
+
|
||||
+ // CraftBukkit start - Add per-player time and weather.
|
||||
+ public long timeOffset = 0;
|
||||
@ -1358,8 +1375,8 @@
|
||||
+ } else {
|
||||
+ // Adds timeOffset to the beginning of this day.
|
||||
+ return this.level().getDayTime() - (this.level().getDayTime() % 24000) + this.timeOffset;
|
||||
}
|
||||
}
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public WeatherType weather = null;
|
||||
+
|
||||
|
@ -14,7 +14,7 @@
|
||||
import net.minecraft.network.DisconnectionDetails;
|
||||
import net.minecraft.network.PacketSendListener;
|
||||
import net.minecraft.network.chat.Component;
|
||||
@@ -22,15 +24,49 @@
|
||||
@@ -22,22 +24,56 @@
|
||||
import net.minecraft.network.protocol.common.ServerboundPongPacket;
|
||||
import net.minecraft.network.protocol.common.ServerboundResourcePackPacket;
|
||||
import net.minecraft.network.protocol.cookie.ServerboundCookieResponsePacket;
|
||||
@ -65,9 +65,19 @@
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
public static final int LATENCY_CHECK_INTERVAL = 15000;
|
||||
private static final int CLOSED_LISTENER_TIMEOUT = 15000;
|
||||
@@ -47,14 +83,26 @@
|
||||
private static final Component TIMEOUT_DISCONNECTION_MESSAGE = Component.translatable("disconnect.timeout");
|
||||
static final Component DISCONNECT_UNEXPECTED_QUERY = Component.translatable("multiplayer.disconnect.unexpected_query_response");
|
||||
protected final MinecraftServer server;
|
||||
- protected final Connection connection;
|
||||
+ public final Connection connection; // Paper
|
||||
private final boolean transferred;
|
||||
private long keepAliveTime;
|
||||
private boolean keepAlivePending;
|
||||
@@ -46,15 +82,28 @@
|
||||
private boolean closed = false;
|
||||
private int latency;
|
||||
private volatile boolean suspendFlushingOnServerThread = false;
|
||||
+ public final java.util.Map<java.util.UUID, net.kyori.adventure.resource.ResourcePackCallback> packCallbacks = new java.util.concurrent.ConcurrentHashMap<>(); // Paper - adventure resource pack callbacks
|
||||
|
||||
- public ServerCommonPacketListenerImpl(MinecraftServer server, Connection connection, CommonListenerCookie clientData) {
|
||||
- this.server = server;
|
||||
@ -97,7 +107,7 @@
|
||||
private void close() {
|
||||
if (!this.closed) {
|
||||
this.closedListenerTime = Util.getMillis();
|
||||
@@ -80,6 +128,7 @@
|
||||
@@ -80,6 +129,7 @@
|
||||
|
||||
@Override
|
||||
public void handleKeepAlive(ServerboundKeepAlivePacket packet) {
|
||||
@ -105,7 +115,7 @@
|
||||
if (this.keepAlivePending && packet.getId() == this.keepAliveChallenge) {
|
||||
int i = (int) (Util.getMillis() - this.keepAliveTime);
|
||||
|
||||
@@ -94,9 +143,57 @@
|
||||
@@ -94,9 +144,57 @@
|
||||
@Override
|
||||
public void handlePong(ServerboundPongPacket packet) {}
|
||||
|
||||
@ -122,7 +132,7 @@
|
||||
+ PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
+ ResourceLocation identifier = packet.payload().type().id();
|
||||
+ ByteBuf payload = ((DiscardedPayload)packet.payload()).data();
|
||||
+
|
||||
|
||||
+ if (identifier.equals(ServerCommonPacketListenerImpl.CUSTOM_REGISTER)) {
|
||||
+ try {
|
||||
+ String channels = payload.toString(com.google.common.base.Charsets.UTF_8);
|
||||
@ -153,7 +163,7 @@
|
||||
+ this.disconnect(Component.literal("Invalid custom payload!"));
|
||||
+ }
|
||||
+ }
|
||||
|
||||
+
|
||||
+ }
|
||||
+
|
||||
+ public final boolean isDisconnected() {
|
||||
@ -164,10 +174,22 @@
|
||||
@Override
|
||||
public void handleResourcePackResponse(ServerboundResourcePackPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, (BlockableEventLoop) this.server);
|
||||
@@ -104,11 +201,18 @@
|
||||
@@ -104,11 +202,30 @@
|
||||
ServerCommonPacketListenerImpl.LOGGER.info("Disconnecting {} due to resource pack {} rejection", this.playerProfile().getName(), packet.id());
|
||||
this.disconnect((Component) Component.translatable("multiplayer.requiredTexturePrompt.disconnect"));
|
||||
}
|
||||
+ // Paper start - adventure pack callbacks
|
||||
+ // call the callbacks before the previously-existing event so the event has final say
|
||||
+ final net.kyori.adventure.resource.ResourcePackCallback callback;
|
||||
+ if (packet.action().isTerminal()) {
|
||||
+ callback = this.packCallbacks.remove(packet.id());
|
||||
+ } else {
|
||||
+ callback = this.packCallbacks.get(packet.id());
|
||||
+ }
|
||||
+ if (callback != null) {
|
||||
+ callback.packEventReceived(packet.id(), net.kyori.adventure.resource.ResourcePackStatus.valueOf(packet.action().name()), this.getCraftPlayer());
|
||||
+ }
|
||||
+ // Paper end
|
||||
+ this.cserver.getPluginManager().callEvent(new PlayerResourcePackStatusEvent(this.getCraftPlayer(), packet.id(), PlayerResourcePackStatusEvent.Status.values()[packet.action().ordinal()])); // CraftBukkit
|
||||
|
||||
}
|
||||
@ -183,7 +205,7 @@
|
||||
this.disconnect(ServerCommonPacketListenerImpl.DISCONNECT_UNEXPECTED_QUERY);
|
||||
}
|
||||
|
||||
@@ -116,7 +220,7 @@
|
||||
@@ -116,7 +233,7 @@
|
||||
Profiler.get().push("keepAlive");
|
||||
long i = Util.getMillis();
|
||||
|
||||
@ -192,7 +214,7 @@
|
||||
if (this.keepAlivePending) {
|
||||
this.disconnect(ServerCommonPacketListenerImpl.TIMEOUT_DISCONNECTION_MESSAGE);
|
||||
} else if (this.checkIfClosed(i)) {
|
||||
@@ -156,6 +260,14 @@
|
||||
@@ -156,6 +273,14 @@
|
||||
}
|
||||
|
||||
public void send(Packet<?> packet, @Nullable PacketSendListener callbacks) {
|
||||
@ -207,7 +229,18 @@
|
||||
if (packet.isTerminal()) {
|
||||
this.close();
|
||||
}
|
||||
@@ -180,15 +292,61 @@
|
||||
@@ -175,20 +300,72 @@
|
||||
}
|
||||
}
|
||||
|
||||
+ // Paper start - adventure
|
||||
+ public void disconnect(final net.kyori.adventure.text.Component reason) {
|
||||
+ this.disconnect(io.papermc.paper.adventure.PaperAdventure.asVanilla(reason));
|
||||
+ }
|
||||
+ // Paper end - adventure
|
||||
+
|
||||
public void disconnect(Component reason) {
|
||||
this.disconnect(new DisconnectionDetails(reason));
|
||||
}
|
||||
|
||||
public void disconnect(DisconnectionDetails disconnectionInfo) {
|
||||
@ -238,9 +271,9 @@
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ String leaveMessage = ChatFormatting.YELLOW + this.player.getScoreboardName() + " left the game.";
|
||||
+ net.kyori.adventure.text.Component leaveMessage = net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, io.papermc.paper.configuration.GlobalConfiguration.get().messages.useDisplayNameInQuitMessage ? this.player.getBukkitEntity().displayName() : net.kyori.adventure.text.Component.text(this.player.getScoreboardName())); // Paper - Adventure
|
||||
+
|
||||
+ PlayerKickEvent event = new PlayerKickEvent(this.player.getBukkitEntity(), CraftChatMessage.fromComponent(disconnectionInfo.reason()), leaveMessage);
|
||||
+ PlayerKickEvent event = new PlayerKickEvent(this.player.getBukkitEntity(), io.papermc.paper.adventure.PaperAdventure.asAdventure(disconnectionInfo.reason()), leaveMessage); // Paper - adventure
|
||||
+
|
||||
+ if (this.cserver.getServer().isRunning()) {
|
||||
+ this.cserver.getPluginManager().callEvent(event);
|
||||
@ -252,7 +285,7 @@
|
||||
+ }
|
||||
+ this.player.kickLeaveMessage = event.getLeaveMessage(); // CraftBukkit - SPIGOT-3034: Forward leave message to PlayerQuitEvent
|
||||
+ // Send the possibly modified leave message
|
||||
+ this.disconnect0(new DisconnectionDetails(CraftChatMessage.fromString(event.getReason(), true)[0], disconnectionInfo.report(), disconnectionInfo.bugReportLink()));
|
||||
+ this.disconnect0(new DisconnectionDetails(io.papermc.paper.adventure.PaperAdventure.asVanilla(event.reason()), disconnectionInfo.report(), disconnectionInfo.bugReportLink())); // Paper - Adventure
|
||||
+ }
|
||||
+
|
||||
+ private void disconnect0(DisconnectionDetails disconnectiondetails) {
|
||||
|
@ -42,7 +42,15 @@
|
||||
|
||||
if (!serverlinks.isEmpty()) {
|
||||
this.send(new ClientboundServerLinksPacket(serverlinks.untrust()));
|
||||
@@ -143,14 +156,14 @@
|
||||
@@ -107,6 +120,7 @@
|
||||
@Override
|
||||
public void handleClientInformation(ServerboundClientInformationPacket packet) {
|
||||
this.clientInformation = packet.information();
|
||||
+ this.connection.channel.attr(io.papermc.paper.adventure.PaperAdventure.LOCALE_ATTRIBUTE).set(net.kyori.adventure.translation.Translator.parseLocale(packet.information().language())); // Paper
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -143,14 +157,14 @@
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,14 @@
|
||||
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
@@ -65,12 +65,15 @@
|
||||
@@ -45,6 +45,7 @@
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.DisconnectionDetails;
|
||||
import net.minecraft.network.TickablePacketListener;
|
||||
+import net.minecraft.network.chat.ChatDecorator;
|
||||
import net.minecraft.network.chat.ChatType;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.LastSeenMessages;
|
||||
@@ -65,12 +66,15 @@
|
||||
import net.minecraft.network.protocol.game.ClientboundBlockChangedAckPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundCommandSuggestionsPacket;
|
||||
@ -16,7 +24,7 @@
|
||||
import net.minecraft.network.protocol.game.ClientboundSetHeldSlotPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundStartConfigurationPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSystemChatPacket;
|
||||
@@ -148,14 +151,13 @@
|
||||
@@ -148,14 +152,13 @@
|
||||
import net.minecraft.world.entity.ExperienceOrb;
|
||||
import net.minecraft.world.entity.HasCustomInventoryScreen;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
@ -32,7 +40,7 @@
|
||||
import net.minecraft.world.entity.player.PlayerModelPart;
|
||||
import net.minecraft.world.entity.player.ProfilePublicKey;
|
||||
import net.minecraft.world.entity.projectile.AbstractArrow;
|
||||
@@ -176,6 +178,7 @@
|
||||
@@ -176,6 +179,7 @@
|
||||
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||
import net.minecraft.world.item.crafting.RecipeManager;
|
||||
import net.minecraft.world.level.BaseCommandBlock;
|
||||
@ -40,7 +48,7 @@
|
||||
import net.minecraft.world.level.GameRules;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import net.minecraft.world.level.Level;
|
||||
@@ -192,12 +195,70 @@
|
||||
@@ -192,11 +196,71 @@
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
@ -50,8 +58,10 @@
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
+
|
||||
+// CraftBukkit start
|
||||
+import io.papermc.paper.adventure.ChatProcessor; // Paper
|
||||
+import io.papermc.paper.adventure.PaperAdventure; // Paper
|
||||
+import com.mojang.datafixers.util.Pair;
|
||||
+import java.util.Arrays;
|
||||
+import java.util.concurrent.ExecutionException;
|
||||
@ -107,11 +117,10 @@
|
||||
+import org.bukkit.inventory.InventoryView;
|
||||
+import org.bukkit.inventory.SmithingInventory;
|
||||
+// CraftBukkit end
|
||||
+
|
||||
|
||||
public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl implements ServerGamePacketListener, ServerPlayerConnection, TickablePacketListener {
|
||||
|
||||
static final Logger LOGGER = LogUtils.getLogger();
|
||||
@@ -247,7 +308,7 @@
|
||||
@@ -247,7 +311,7 @@
|
||||
private boolean waitingForSwitchToConfig;
|
||||
|
||||
public ServerGamePacketListenerImpl(MinecraftServer server, Connection connection, ServerPlayer player, CommonListenerCookie clientData) {
|
||||
@ -120,14 +129,14 @@
|
||||
this.chunkSender = new PlayerChunkSender(connection.isMemoryConnection());
|
||||
this.player = player;
|
||||
player.connection = this;
|
||||
@@ -256,11 +317,28 @@
|
||||
@@ -256,11 +320,28 @@
|
||||
|
||||
Objects.requireNonNull(server);
|
||||
this.signedMessageDecoder = SignedMessageChain.Decoder.unsigned(uuid, server::enforceSecureProfile);
|
||||
- this.chatMessageChain = new FutureChain(server);
|
||||
+ this.chatMessageChain = new FutureChain(server.chatExecutor); // CraftBukkit - async chat
|
||||
}
|
||||
+
|
||||
|
||||
+ // CraftBukkit start - add fields and methods
|
||||
+ private int lastTick = MinecraftServer.currentTick;
|
||||
+ private int allowedPlayerTicks = 1;
|
||||
@ -143,14 +152,14 @@
|
||||
+ private float lastYaw = Float.MAX_VALUE;
|
||||
+ private boolean justTeleported = false;
|
||||
+ // CraftBukkit end
|
||||
|
||||
+
|
||||
@Override
|
||||
public void tick() {
|
||||
+ org.bukkit.craftbukkit.SpigotTimings.playerConnectionTimer.startTiming(); // Spigot
|
||||
if (this.ackBlockChangesUpTo > -1) {
|
||||
this.send(new ClientboundBlockChangedAckPacket(this.ackBlockChangesUpTo));
|
||||
this.ackBlockChangesUpTo = -1;
|
||||
@@ -313,8 +391,10 @@
|
||||
@@ -313,8 +394,10 @@
|
||||
this.chatSpamThrottler.tick();
|
||||
this.dropSpamThrottler.tick();
|
||||
if (this.player.getLastActionTime() > 0L && this.server.getPlayerIdleTimeout() > 0 && Util.getMillis() - this.player.getLastActionTime() > (long) this.server.getPlayerIdleTimeout() * 1000L * 60L) {
|
||||
@ -161,7 +170,7 @@
|
||||
|
||||
}
|
||||
|
||||
@@ -376,6 +456,12 @@
|
||||
@@ -376,6 +459,12 @@
|
||||
@Override
|
||||
public void handlePlayerInput(ServerboundPlayerInputPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
@ -174,7 +183,7 @@
|
||||
this.player.setLastClientInput(packet.input());
|
||||
}
|
||||
|
||||
@@ -401,6 +487,13 @@
|
||||
@@ -401,6 +490,13 @@
|
||||
|
||||
if (entity != this.player && entity.getControllingPassenger() == this.player && entity == this.lastVehicle) {
|
||||
ServerLevel worldserver = this.player.serverLevel();
|
||||
@ -188,7 +197,7 @@
|
||||
double d0 = entity.getX();
|
||||
double d1 = entity.getY();
|
||||
double d2 = entity.getZ();
|
||||
@@ -415,7 +508,33 @@
|
||||
@@ -415,7 +511,33 @@
|
||||
double d9 = entity.getDeltaMovement().lengthSqr();
|
||||
double d10 = d6 * d6 + d7 * d7 + d8 * d8;
|
||||
|
||||
@ -223,7 +232,7 @@
|
||||
ServerGamePacketListenerImpl.LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", new Object[]{entity.getName().getString(), this.player.getName().getString(), d6, d7, d8});
|
||||
this.send(ClientboundMoveVehiclePacket.fromEntity(entity));
|
||||
return;
|
||||
@@ -449,19 +568,72 @@
|
||||
@@ -449,19 +571,72 @@
|
||||
d10 = d6 * d6 + d7 * d7 + d8 * d8;
|
||||
boolean flag2 = false;
|
||||
|
||||
@ -297,7 +306,7 @@
|
||||
|
||||
this.player.serverLevel().getChunkSource().move(this.player);
|
||||
entity.recordMovementThroughBlocks(new Vec3(d0, d1, d2), entity.position());
|
||||
@@ -499,6 +671,7 @@
|
||||
@@ -499,6 +674,7 @@
|
||||
this.lastGoodZ = this.awaitingPositionFromClient.z;
|
||||
this.player.hasChangedDimension();
|
||||
this.awaitingPositionFromClient = null;
|
||||
@ -305,7 +314,7 @@
|
||||
}
|
||||
|
||||
}
|
||||
@@ -528,6 +701,7 @@
|
||||
@@ -528,6 +704,7 @@
|
||||
@Override
|
||||
public void handleRecipeBookChangeSettingsPacket(ServerboundRecipeBookChangeSettingsPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
@ -313,7 +322,7 @@
|
||||
this.player.getRecipeBook().setBookSetting(packet.getBookType(), packet.isOpen(), packet.isFiltering());
|
||||
}
|
||||
|
||||
@@ -548,6 +722,12 @@
|
||||
@@ -548,6 +725,12 @@
|
||||
@Override
|
||||
public void handleCustomCommandSuggestions(ServerboundCommandSuggestionPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
@ -326,7 +335,7 @@
|
||||
StringReader stringreader = new StringReader(packet.getCommand());
|
||||
|
||||
if (stringreader.canRead() && stringreader.peek() == '/') {
|
||||
@@ -557,6 +737,7 @@
|
||||
@@ -557,6 +740,7 @@
|
||||
ParseResults<CommandSourceStack> parseresults = this.server.getCommands().getDispatcher().parse(stringreader, this.player.createCommandSourceStack());
|
||||
|
||||
this.server.getCommands().getDispatcher().getCompletionSuggestions(parseresults).thenAccept((suggestions) -> {
|
||||
@ -334,7 +343,7 @@
|
||||
Suggestions suggestions1 = suggestions.getList().size() <= 1000 ? suggestions : new Suggestions(suggestions.getRange(), suggestions.getList().subList(0, 1000));
|
||||
|
||||
this.send(new ClientboundCommandSuggestionsPacket(packet.getId(), suggestions1));
|
||||
@@ -668,7 +849,7 @@
|
||||
@@ -668,7 +852,7 @@
|
||||
ItemStack itemstack = iblockdata.getCloneItemStack(worldserver, blockposition, flag);
|
||||
|
||||
if (!itemstack.isEmpty()) {
|
||||
@ -343,7 +352,7 @@
|
||||
ServerGamePacketListenerImpl.addBlockDataToItem(iblockdata, worldserver, blockposition, itemstack);
|
||||
}
|
||||
|
||||
@@ -866,6 +1047,13 @@
|
||||
@@ -866,6 +1050,13 @@
|
||||
AbstractContainerMenu container = this.player.containerMenu;
|
||||
|
||||
if (container instanceof MerchantMenu containermerchant) {
|
||||
@ -357,7 +366,7 @@
|
||||
if (!containermerchant.stillValid(this.player)) {
|
||||
ServerGamePacketListenerImpl.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, containermerchant);
|
||||
return;
|
||||
@@ -879,6 +1067,13 @@
|
||||
@@ -879,6 +1070,13 @@
|
||||
|
||||
@Override
|
||||
public void handleEditBook(ServerboundEditBookPacket packet) {
|
||||
@ -371,7 +380,7 @@
|
||||
int i = packet.slot();
|
||||
|
||||
if (Inventory.isHotbarSlot(i) || i == 40) {
|
||||
@@ -899,12 +1094,16 @@
|
||||
@@ -899,12 +1097,16 @@
|
||||
}
|
||||
|
||||
private void updateBookContents(List<FilteredText> pages, int slotId) {
|
||||
@ -389,7 +398,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -915,12 +1114,13 @@
|
||||
@@ -915,12 +1117,13 @@
|
||||
ItemStack itemstack1 = itemstack.transmuteCopy(Items.WRITTEN_BOOK);
|
||||
|
||||
itemstack1.remove(DataComponents.WRITABLE_BOOK_CONTENT);
|
||||
@ -405,7 +414,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -982,7 +1182,7 @@
|
||||
@@ -982,7 +1185,7 @@
|
||||
} else {
|
||||
ServerLevel worldserver = this.player.serverLevel();
|
||||
|
||||
@ -414,7 +423,7 @@
|
||||
if (this.tickCount == 0) {
|
||||
this.resetPosition();
|
||||
}
|
||||
@@ -997,7 +1197,15 @@
|
||||
@@ -997,7 +1200,15 @@
|
||||
if (this.player.isPassenger()) {
|
||||
this.player.absMoveTo(this.player.getX(), this.player.getY(), this.player.getZ(), f, f1);
|
||||
this.player.serverLevel().getChunkSource().move(this.player);
|
||||
@ -430,7 +439,7 @@
|
||||
double d3 = this.player.getX();
|
||||
double d4 = this.player.getY();
|
||||
double d5 = this.player.getZ();
|
||||
@@ -1019,15 +1227,33 @@
|
||||
@@ -1019,15 +1230,33 @@
|
||||
++this.receivedMovePacketCount;
|
||||
int i = this.receivedMovePacketCount - this.knownMovePacketCount;
|
||||
|
||||
@ -443,20 +452,20 @@
|
||||
+ if (i > Math.max(this.allowedPlayerTicks, 5)) {
|
||||
ServerGamePacketListenerImpl.LOGGER.debug("{} is sending move packets too frequently ({} packets since last tick)", this.player.getName().getString(), i);
|
||||
i = 1;
|
||||
}
|
||||
|
||||
+ }
|
||||
+
|
||||
+ if (packet.hasRot || d10 > 0) {
|
||||
+ this.allowedPlayerTicks -= 1;
|
||||
+ } else {
|
||||
+ this.allowedPlayerTicks = 20;
|
||||
+ }
|
||||
}
|
||||
+ double speed;
|
||||
+ if (this.player.getAbilities().flying) {
|
||||
+ speed = this.player.getAbilities().flyingSpeed * 20f;
|
||||
+ } else {
|
||||
+ speed = this.player.getAbilities().walkingSpeed * 10f;
|
||||
+ }
|
||||
+
|
||||
|
||||
if (this.shouldCheckPlayerMovement(flag)) {
|
||||
float f2 = flag ? 300.0F : 100.0F;
|
||||
|
||||
@ -466,7 +475,7 @@
|
||||
ServerGamePacketListenerImpl.LOGGER.warn("{} moved too quickly! {},{},{}", new Object[]{this.player.getName().getString(), d6, d7, d8});
|
||||
this.teleport(this.player.getX(), this.player.getY(), this.player.getZ(), this.player.getYRot(), this.player.getXRot());
|
||||
return;
|
||||
@@ -1049,6 +1275,7 @@
|
||||
@@ -1049,6 +1278,7 @@
|
||||
boolean flag2 = this.player.verticalCollisionBelow;
|
||||
|
||||
this.player.move(MoverType.PLAYER, new Vec3(d6, d7, d8));
|
||||
@ -474,7 +483,7 @@
|
||||
double d11 = d7;
|
||||
|
||||
d6 = d0 - this.player.getX();
|
||||
@@ -1061,15 +1288,81 @@
|
||||
@@ -1061,15 +1291,81 @@
|
||||
d10 = d6 * d6 + d7 * d7 + d8 * d8;
|
||||
boolean flag3 = false;
|
||||
|
||||
@ -558,7 +567,7 @@
|
||||
this.player.absMoveTo(d0, d1, d2, f, f1);
|
||||
boolean flag4 = this.player.isAutoSpinAttack();
|
||||
|
||||
@@ -1119,6 +1412,7 @@
|
||||
@@ -1119,6 +1415,7 @@
|
||||
this.awaitingTeleportTime = this.tickCount;
|
||||
this.teleport(this.awaitingPositionFromClient.x, this.awaitingPositionFromClient.y, this.awaitingPositionFromClient.z, this.player.getYRot(), this.player.getXRot());
|
||||
}
|
||||
@ -566,7 +575,7 @@
|
||||
|
||||
return true;
|
||||
} else {
|
||||
@@ -1147,23 +1441,83 @@
|
||||
@@ -1147,23 +1444,83 @@
|
||||
}
|
||||
|
||||
public void teleport(double x, double y, double z, float yaw, float pitch) {
|
||||
@ -653,7 +662,7 @@
|
||||
if (this.player.hasClientLoaded()) {
|
||||
BlockPos blockposition = packet.getPos();
|
||||
|
||||
@@ -1175,14 +1529,46 @@
|
||||
@@ -1175,14 +1532,46 @@
|
||||
if (!this.player.isSpectator()) {
|
||||
ItemStack itemstack = this.player.getItemInHand(InteractionHand.OFF_HAND);
|
||||
|
||||
@ -702,7 +711,7 @@
|
||||
this.player.drop(false);
|
||||
}
|
||||
|
||||
@@ -1218,9 +1604,30 @@
|
||||
@@ -1218,9 +1607,30 @@
|
||||
}
|
||||
}
|
||||
|
||||
@ -733,7 +742,7 @@
|
||||
if (this.player.hasClientLoaded()) {
|
||||
this.player.connection.ackBlockChangesUpTo(packet.getSequence());
|
||||
ServerLevel worldserver = this.player.serverLevel();
|
||||
@@ -1244,6 +1651,7 @@
|
||||
@@ -1244,6 +1654,7 @@
|
||||
|
||||
if (blockposition.getY() <= i) {
|
||||
if (this.awaitingPositionFromClient == null && worldserver.mayInteract(this.player, blockposition)) {
|
||||
@ -741,7 +750,7 @@
|
||||
InteractionResult enuminteractionresult = this.player.gameMode.useItemOn(this.player, worldserver, itemstack, enumhand, movingobjectpositionblock);
|
||||
|
||||
if (enuminteractionresult.consumesAction()) {
|
||||
@@ -1281,6 +1689,8 @@
|
||||
@@ -1281,6 +1692,8 @@
|
||||
@Override
|
||||
public void handleUseItem(ServerboundUseItemPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
@ -750,7 +759,7 @@
|
||||
if (this.player.hasClientLoaded()) {
|
||||
this.ackBlockChangesUpTo(packet.getSequence());
|
||||
ServerLevel worldserver = this.player.serverLevel();
|
||||
@@ -1296,6 +1706,47 @@
|
||||
@@ -1296,6 +1709,47 @@
|
||||
this.player.absRotateTo(f, f1);
|
||||
}
|
||||
|
||||
@ -798,7 +807,7 @@
|
||||
InteractionResult enuminteractionresult = this.player.gameMode.useItem(this.player, worldserver, itemstack, enumhand);
|
||||
|
||||
if (enuminteractionresult instanceof InteractionResult.Success) {
|
||||
@@ -1321,7 +1772,7 @@
|
||||
@@ -1321,7 +1775,7 @@
|
||||
Entity entity = packet.getEntity(worldserver);
|
||||
|
||||
if (entity != null) {
|
||||
@ -807,7 +816,7 @@
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1342,6 +1793,13 @@
|
||||
@@ -1342,6 +1796,13 @@
|
||||
|
||||
@Override
|
||||
public void onDisconnect(DisconnectionDetails info) {
|
||||
@ -821,7 +830,7 @@
|
||||
ServerGamePacketListenerImpl.LOGGER.info("{} lost connection: {}", this.player.getName().getString(), info.reason().getString());
|
||||
this.removePlayerFromWorld();
|
||||
super.onDisconnect(info);
|
||||
@@ -1349,10 +1807,18 @@
|
||||
@@ -1349,10 +1810,20 @@
|
||||
|
||||
private void removePlayerFromWorld() {
|
||||
this.chatMessageChain.close();
|
||||
@ -834,15 +843,17 @@
|
||||
+
|
||||
this.player.disconnect();
|
||||
- this.server.getPlayerList().remove(this.player);
|
||||
+ String quitMessage = this.server.getPlayerList().remove(this.player);
|
||||
+ if ((quitMessage != null) && (quitMessage.length() > 0)) {
|
||||
+ this.server.getPlayerList().broadcastMessage(CraftChatMessage.fromString(quitMessage));
|
||||
+ // Paper start - Adventure
|
||||
+ net.kyori.adventure.text.Component quitMessage = this.server.getPlayerList().remove(this.player);
|
||||
+ if ((quitMessage != null) && !quitMessage.equals(net.kyori.adventure.text.Component.empty())) {
|
||||
+ this.server.getPlayerList().broadcastSystemMessage(PaperAdventure.asVanilla(quitMessage), false);
|
||||
+ // Paper end
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
this.player.getTextFilter().leave();
|
||||
}
|
||||
|
||||
@@ -1367,7 +1833,16 @@
|
||||
@@ -1367,7 +1838,16 @@
|
||||
@Override
|
||||
public void handleSetCarriedItem(ServerboundSetCarriedItemPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
@ -859,7 +870,7 @@
|
||||
if (this.player.getInventory().selected != packet.getSlot() && this.player.getUsedItemHand() == InteractionHand.MAIN_HAND) {
|
||||
this.player.stopUsingItem();
|
||||
}
|
||||
@@ -1376,11 +1851,18 @@
|
||||
@@ -1376,11 +1856,18 @@
|
||||
this.player.resetLastActionTime();
|
||||
} else {
|
||||
ServerGamePacketListenerImpl.LOGGER.warn("{} tried to set an invalid carried item", this.player.getName().getString());
|
||||
@ -878,16 +889,19 @@
|
||||
Optional<LastSeenMessages> optional = this.unpackAndApplyLastSeen(packet.lastSeenMessages());
|
||||
|
||||
if (!optional.isEmpty()) {
|
||||
@@ -1394,7 +1876,7 @@
|
||||
@@ -1394,27 +1881,44 @@
|
||||
return;
|
||||
}
|
||||
|
||||
- CompletableFuture<FilteredText> completablefuture = this.filterTextPacket(playerchatmessage.signedContent());
|
||||
- Component ichatbasecomponent = this.server.getChatDecorator().decorate(this.player, playerchatmessage.decoratedContent());
|
||||
+ CompletableFuture<FilteredText> completablefuture = this.filterTextPacket(playerchatmessage.signedContent()).thenApplyAsync(Function.identity(), this.server.chatExecutor); // CraftBukkit - async chat
|
||||
Component ichatbasecomponent = this.server.getChatDecorator().decorate(this.player, playerchatmessage.decoratedContent());
|
||||
+ CompletableFuture<Component> componentFuture = this.server.getChatDecorator().decorate(this.player, null, playerchatmessage.decoratedContent()); // Paper - Adventure
|
||||
|
||||
this.chatMessageChain.append(completablefuture, (filteredtext) -> {
|
||||
@@ -1402,19 +1884,36 @@
|
||||
- this.chatMessageChain.append(completablefuture, (filteredtext) -> {
|
||||
- PlayerChatMessage playerchatmessage1 = playerchatmessage.withUnsignedContent(ichatbasecomponent).filter(filteredtext.mask());
|
||||
+ this.chatMessageChain.append(CompletableFuture.allOf(completablefuture, componentFuture), (filteredtext) -> { // Paper - Adventure
|
||||
+ PlayerChatMessage playerchatmessage1 = playerchatmessage.withUnsignedContent(componentFuture.join()).filter(completablefuture.join().mask()); // Paper - Adventure
|
||||
|
||||
this.broadcastChatMessage(playerchatmessage1);
|
||||
});
|
||||
@ -927,7 +941,7 @@
|
||||
ParseResults<CommandSourceStack> parseresults = this.parseCommand(command);
|
||||
|
||||
if (this.server.enforceSecureProfile() && SignableCommand.hasSignableArguments(parseresults)) {
|
||||
@@ -1431,19 +1930,37 @@
|
||||
@@ -1431,19 +1935,37 @@
|
||||
|
||||
if (!optional.isEmpty()) {
|
||||
this.tryHandleChat(packet.command(), () -> {
|
||||
@ -969,7 +983,7 @@
|
||||
} catch (SignedMessageChain.DecodeException signedmessagechain_a) {
|
||||
this.handleMessageDecodeFailure(signedmessagechain_a);
|
||||
return;
|
||||
@@ -1451,10 +1968,10 @@
|
||||
@@ -1451,10 +1973,10 @@
|
||||
|
||||
CommandSigningContext.SignedArguments commandsigningcontext_a = new CommandSigningContext.SignedArguments(map);
|
||||
|
||||
@ -982,7 +996,7 @@
|
||||
}
|
||||
|
||||
private void handleMessageDecodeFailure(SignedMessageChain.DecodeException exception) {
|
||||
@@ -1530,14 +2047,20 @@
|
||||
@@ -1530,14 +2052,20 @@
|
||||
return com_mojang_brigadier_commanddispatcher.parse(command, this.player.createCommandSourceStack());
|
||||
}
|
||||
|
||||
@ -1007,7 +1021,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1566,6 +2089,121 @@
|
||||
@@ -1566,6 +2094,129 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1022,7 +1036,15 @@
|
||||
+ this.handleCommand(s);
|
||||
+ } else if (this.player.getChatVisibility() == ChatVisiblity.SYSTEM) {
|
||||
+ // Do nothing, this is coming from a plugin
|
||||
+ } else {
|
||||
+ // Paper start
|
||||
+ } else if (true) {
|
||||
+ if (!async && !org.bukkit.Bukkit.isPrimaryThread()) {
|
||||
+ org.spigotmc.AsyncCatcher.catchOp("Asynchronous player chat is not allowed here");
|
||||
+ }
|
||||
+ final ChatProcessor cp = new ChatProcessor(this.server, this.player, original, async);
|
||||
+ cp.process();
|
||||
+ // Paper end
|
||||
+ } else if (false) { // Paper
|
||||
+ Player player = this.getCraftPlayer();
|
||||
+ AsyncPlayerChatEvent event = new AsyncPlayerChatEvent(async, player, s, new LazyPlayerSet(this.server));
|
||||
+ String originalFormat = event.getFormat(), originalMessage = event.getMessage();
|
||||
@ -1129,7 +1151,7 @@
|
||||
private PlayerChatMessage getSignedMessage(ServerboundChatPacket packet, LastSeenMessages lastSeenMessages) throws SignedMessageChain.DecodeException {
|
||||
SignedMessageBody signedmessagebody = new SignedMessageBody(packet.message(), packet.timeStamp(), packet.salt(), lastSeenMessages);
|
||||
|
||||
@@ -1573,13 +2211,42 @@
|
||||
@@ -1573,13 +2224,42 @@
|
||||
}
|
||||
|
||||
private void broadcastChatMessage(PlayerChatMessage message) {
|
||||
@ -1177,7 +1199,7 @@
|
||||
this.disconnect((Component) Component.translatable("disconnect.spam"));
|
||||
}
|
||||
|
||||
@@ -1601,7 +2268,33 @@
|
||||
@@ -1601,7 +2281,33 @@
|
||||
@Override
|
||||
public void handleAnimate(ServerboundSwingPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
@ -1211,7 +1233,7 @@
|
||||
this.player.swing(packet.getHand());
|
||||
}
|
||||
|
||||
@@ -1609,6 +2302,29 @@
|
||||
@@ -1609,6 +2315,29 @@
|
||||
public void handlePlayerCommand(ServerboundPlayerCommandPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
if (this.player.hasClientLoaded()) {
|
||||
@ -1241,7 +1263,7 @@
|
||||
this.player.resetLastActionTime();
|
||||
Entity entity;
|
||||
PlayerRideableJumping ijumpable;
|
||||
@@ -1691,6 +2407,12 @@
|
||||
@@ -1691,6 +2420,12 @@
|
||||
}
|
||||
|
||||
public void sendPlayerChatMessage(PlayerChatMessage message, ChatType.Bound params) {
|
||||
@ -1254,7 +1276,7 @@
|
||||
this.send(new ClientboundPlayerChatPacket(message.link().sender(), message.link().index(), message.signature(), message.signedBody().pack(this.messageSignatureCache), message.unsignedContent(), message.filterMask(), params));
|
||||
this.addPendingMessage(message);
|
||||
}
|
||||
@@ -1703,6 +2425,13 @@
|
||||
@@ -1703,6 +2438,13 @@
|
||||
return this.connection.getRemoteAddress();
|
||||
}
|
||||
|
||||
@ -1268,7 +1290,7 @@
|
||||
public void switchToConfig() {
|
||||
this.waitingForSwitchToConfig = true;
|
||||
this.removePlayerFromWorld();
|
||||
@@ -1718,9 +2447,17 @@
|
||||
@@ -1718,9 +2460,17 @@
|
||||
@Override
|
||||
public void handleInteract(ServerboundInteractPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
@ -1286,7 +1308,7 @@
|
||||
|
||||
this.player.resetLastActionTime();
|
||||
this.player.setShiftKeyDown(packet.isUsingSecondaryAction());
|
||||
@@ -1733,20 +2470,58 @@
|
||||
@@ -1733,20 +2483,58 @@
|
||||
|
||||
if (this.player.canInteractWithEntity(axisalignedbb, 3.0D)) {
|
||||
packet.dispatch(new ServerboundInteractPacket.Handler() {
|
||||
@ -1302,7 +1324,7 @@
|
||||
+ ItemStack itemInHand = ServerGamePacketListenerImpl.this.player.getItemInHand(enumhand);
|
||||
+ boolean triggerLeashUpdate = itemInHand != null && itemInHand.getItem() == Items.LEAD && entity instanceof Mob;
|
||||
+ Item origItem = ServerGamePacketListenerImpl.this.player.getInventory().getSelected() == null ? null : ServerGamePacketListenerImpl.this.player.getInventory().getSelected().getItem();
|
||||
|
||||
+
|
||||
+ ServerGamePacketListenerImpl.this.cserver.getPluginManager().callEvent(event);
|
||||
+
|
||||
+ // Entity in bucket - SPIGOT-4048 and SPIGOT-6859a
|
||||
@ -1331,7 +1353,7 @@
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+ InteractionResult enuminteractionresult = playerconnection_a.run(ServerGamePacketListenerImpl.this.player, entity, enumhand);
|
||||
+
|
||||
|
||||
+ // CraftBukkit start
|
||||
+ if (!itemInHand.isEmpty() && itemInHand.getCount() <= -1) {
|
||||
+ ServerGamePacketListenerImpl.this.player.containerMenu.sendAllDataToRemote();
|
||||
@ -1349,7 +1371,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1755,19 +2530,20 @@
|
||||
@@ -1755,19 +2543,20 @@
|
||||
|
||||
@Override
|
||||
public void onInteraction(InteractionHand hand) {
|
||||
@ -1373,7 +1395,7 @@
|
||||
label23:
|
||||
{
|
||||
if (entity instanceof AbstractArrow) {
|
||||
@@ -1785,6 +2561,11 @@
|
||||
@@ -1785,6 +2574,11 @@
|
||||
}
|
||||
|
||||
ServerGamePacketListenerImpl.this.player.attack(entity);
|
||||
@ -1385,7 +1407,7 @@
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1809,7 +2590,7 @@
|
||||
@@ -1809,7 +2603,7 @@
|
||||
case PERFORM_RESPAWN:
|
||||
if (this.player.wonGame) {
|
||||
this.player.wonGame = false;
|
||||
@ -1394,7 +1416,7 @@
|
||||
this.resetPosition();
|
||||
CriteriaTriggers.CHANGED_DIMENSION.trigger(this.player, Level.END, Level.OVERWORLD);
|
||||
} else {
|
||||
@@ -1817,11 +2598,11 @@
|
||||
@@ -1817,11 +2611,11 @@
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1408,7 +1430,7 @@
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1834,15 +2615,21 @@
|
||||
@@ -1834,15 +2628,21 @@
|
||||
@Override
|
||||
public void handleContainerClose(ServerboundContainerClosePacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
@ -1432,7 +1454,7 @@
|
||||
this.player.containerMenu.sendAllDataToRemote();
|
||||
} else if (!this.player.containerMenu.stillValid(this.player)) {
|
||||
ServerGamePacketListenerImpl.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu);
|
||||
@@ -1855,7 +2642,284 @@
|
||||
@@ -1855,7 +2655,284 @@
|
||||
boolean flag = packet.getStateId() != this.player.containerMenu.getStateId();
|
||||
|
||||
this.player.containerMenu.suppressRemoteUpdates();
|
||||
@ -1718,7 +1740,7 @@
|
||||
ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packet.getChangedSlots()).iterator();
|
||||
|
||||
while (objectiterator.hasNext()) {
|
||||
@@ -1901,8 +2965,22 @@
|
||||
@@ -1901,8 +2978,22 @@
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1742,7 +1764,7 @@
|
||||
if (containerrecipebook_a == RecipeBookMenu.PostPlaceAction.PLACE_GHOST_RECIPE) {
|
||||
this.player.connection.send(new ClientboundPlaceGhostRecipePacket(this.player.containerMenu.containerId, craftingmanager_d.display().display()));
|
||||
}
|
||||
@@ -1917,6 +2995,7 @@
|
||||
@@ -1917,6 +3008,7 @@
|
||||
@Override
|
||||
public void handleContainerButtonClick(ServerboundContainerButtonClickPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
@ -1750,7 +1772,7 @@
|
||||
this.player.resetLastActionTime();
|
||||
if (this.player.containerMenu.containerId == packet.containerId() && !this.player.isSpectator()) {
|
||||
if (!this.player.containerMenu.stillValid(this.player)) {
|
||||
@@ -1945,7 +3024,44 @@
|
||||
@@ -1945,6 +3037,43 @@
|
||||
|
||||
boolean flag1 = packet.slotNum() >= 1 && packet.slotNum() <= 45;
|
||||
boolean flag2 = itemstack.isEmpty() || itemstack.getCount() <= itemstack.getMaxStackSize();
|
||||
@ -1758,7 +1780,7 @@
|
||||
+ // CraftBukkit start - Call click event
|
||||
+ InventoryView inventory = this.player.inventoryMenu.getBukkitView();
|
||||
+ org.bukkit.inventory.ItemStack item = CraftItemStack.asBukkitCopy(packet.itemStack());
|
||||
|
||||
+
|
||||
+ SlotType type = SlotType.QUICKBAR;
|
||||
+ if (flag) {
|
||||
+ type = SlotType.OUTSIDE;
|
||||
@ -1791,11 +1813,10 @@
|
||||
+ }
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
|
||||
if (flag1 && flag2) {
|
||||
this.player.inventoryMenu.getSlot(packet.slotNum()).setByPlayer(itemstack);
|
||||
this.player.inventoryMenu.setRemoteSlot(packet.slotNum(), itemstack);
|
||||
@@ -1972,6 +3088,7 @@
|
||||
@@ -1972,6 +3101,7 @@
|
||||
}
|
||||
|
||||
private void updateSignText(ServerboundSignUpdatePacket packet, List<FilteredText> signText) {
|
||||
@ -1803,7 +1824,7 @@
|
||||
this.player.resetLastActionTime();
|
||||
ServerLevel worldserver = this.player.serverLevel();
|
||||
BlockPos blockposition = packet.getPos();
|
||||
@@ -1993,7 +3110,17 @@
|
||||
@@ -1993,7 +3123,17 @@
|
||||
@Override
|
||||
public void handlePlayerAbilities(ServerboundPlayerAbilitiesPacket packet) {
|
||||
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
||||
@ -1822,7 +1843,15 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2058,7 +3185,7 @@
|
||||
@@ -2002,6 +3142,7 @@
|
||||
boolean flag = this.player.isModelPartShown(PlayerModelPart.HAT);
|
||||
|
||||
this.player.updateOptions(packet.information());
|
||||
+ this.connection.channel.attr(io.papermc.paper.adventure.PaperAdventure.LOCALE_ATTRIBUTE).set(net.kyori.adventure.translation.Translator.parseLocale(packet.information().language())); // Paper
|
||||
if (this.player.isModelPartShown(PlayerModelPart.HAT) != flag) {
|
||||
this.server.getPlayerList().broadcastAll(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_HAT, this.player));
|
||||
}
|
||||
@@ -2058,7 +3199,7 @@
|
||||
if (!this.waitingForSwitchToConfig) {
|
||||
throw new IllegalStateException("Client acknowledged config, but none was requested");
|
||||
} else {
|
||||
@ -1831,7 +1860,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2083,8 +3210,10 @@
|
||||
@@ -2083,8 +3224,10 @@
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -214,7 +214,7 @@
|
||||
+ if (PlayerPreLoginEvent.getHandlerList().getRegisteredListeners().length != 0) {
|
||||
+ final PlayerPreLoginEvent event = new PlayerPreLoginEvent(playerName, address, uniqueId);
|
||||
+ if (asyncEvent.getResult() != PlayerPreLoginEvent.Result.ALLOWED) {
|
||||
+ event.disallow(asyncEvent.getResult(), asyncEvent.getKickMessage());
|
||||
+ event.disallow(asyncEvent.getResult(), asyncEvent.kickMessage()); // Paper - Adventure
|
||||
+ }
|
||||
+ Waitable<PlayerPreLoginEvent.Result> waitable = new Waitable<PlayerPreLoginEvent.Result>() {
|
||||
+ @Override
|
||||
@ -226,12 +226,12 @@
|
||||
+
|
||||
+ ServerLoginPacketListenerImpl.this.server.processQueue.add(waitable);
|
||||
+ if (waitable.get() != PlayerPreLoginEvent.Result.ALLOWED) {
|
||||
+ this.disconnect(event.getKickMessage());
|
||||
+ this.disconnect(io.papermc.paper.adventure.PaperAdventure.asVanilla(event.kickMessage())); // Paper - Adventure
|
||||
+ return;
|
||||
+ }
|
||||
+ } else {
|
||||
+ if (asyncEvent.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
|
||||
+ this.disconnect(asyncEvent.getKickMessage());
|
||||
+ this.disconnect(io.papermc.paper.adventure.PaperAdventure.asVanilla(asyncEvent.kickMessage())); // Paper - Adventure
|
||||
+ return;
|
||||
+ }
|
||||
+ }
|
||||
|
@ -34,7 +34,7 @@
|
||||
+ CraftIconCache icon = server.server.getServerIcon();
|
||||
+
|
||||
+ ServerListPingEvent() {
|
||||
+ super(ServerStatusPacketListenerImpl.this.connection.hostname, ((InetSocketAddress) ServerStatusPacketListenerImpl.this.connection.getRemoteAddress()).getAddress(), server.getMotd(), server.getPlayerList().getMaxPlayers());
|
||||
+ super(ServerStatusPacketListenerImpl.this.connection.hostname, ((InetSocketAddress) ServerStatusPacketListenerImpl.this.connection.getRemoteAddress()).getAddress(), server.server.motd(), server.getPlayerList().getMaxPlayers()); // Paper - Adventure
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
|
@ -177,13 +177,13 @@
|
||||
}
|
||||
+ // CraftBukkit start
|
||||
+ ichatmutablecomponent.withStyle(ChatFormatting.YELLOW);
|
||||
+ String joinMessage = CraftChatMessage.fromComponent(ichatmutablecomponent);
|
||||
+ Component joinMessage = ichatmutablecomponent; // Paper - Adventure
|
||||
|
||||
- this.broadcastSystemMessage(ichatmutablecomponent.withStyle(ChatFormatting.YELLOW), false);
|
||||
playerconnection.teleport(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot());
|
||||
ServerStatus serverping = this.server.getStatus();
|
||||
|
||||
@@ -222,17 +283,71 @@
|
||||
@@ -222,17 +283,70 @@
|
||||
player.sendServerStatus(serverping);
|
||||
}
|
||||
|
||||
@ -201,19 +201,18 @@
|
||||
+ // Ensure that player inventory is populated with its viewer
|
||||
+ player.containerMenu.transferTo(player.containerMenu, bukkitPlayer);
|
||||
+
|
||||
+ PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(bukkitPlayer, joinMessage);
|
||||
+ PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(bukkitPlayer, io.papermc.paper.adventure.PaperAdventure.asAdventure(ichatmutablecomponent)); // Paper - Adventure
|
||||
+ this.cserver.getPluginManager().callEvent(playerJoinEvent);
|
||||
+
|
||||
+ if (!player.connection.isAcceptingMessages()) {
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ joinMessage = playerJoinEvent.getJoinMessage();
|
||||
+ final net.kyori.adventure.text.Component jm = playerJoinEvent.joinMessage();
|
||||
+
|
||||
+ if (joinMessage != null && joinMessage.length() > 0) {
|
||||
+ for (Component line : org.bukkit.craftbukkit.util.CraftChatMessage.fromString(joinMessage)) {
|
||||
+ this.server.getPlayerList().broadcastSystemMessage(line, false);
|
||||
+ }
|
||||
+ if (jm != null && !jm.equals(net.kyori.adventure.text.Component.empty())) { // Paper - Adventure
|
||||
+ joinMessage = io.papermc.paper.adventure.PaperAdventure.asVanilla(jm); // Paper - Adventure
|
||||
+ this.server.getPlayerList().broadcastSystemMessage(joinMessage, false); // Paper - Adventure
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
@ -259,7 +258,7 @@
|
||||
}
|
||||
|
||||
public void updateEntireScoreboard(ServerScoreboard scoreboard, ServerPlayer player) {
|
||||
@@ -269,30 +384,31 @@
|
||||
@@ -269,30 +383,31 @@
|
||||
}
|
||||
|
||||
public void addWorldborderListener(ServerLevel world) {
|
||||
@ -296,7 +295,7 @@
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -319,14 +435,15 @@
|
||||
@@ -319,14 +434,15 @@
|
||||
}
|
||||
|
||||
protected void save(ServerPlayer player) {
|
||||
@ -314,13 +313,13 @@
|
||||
|
||||
if (advancementdataplayer != null) {
|
||||
advancementdataplayer.save();
|
||||
@@ -334,95 +451,176 @@
|
||||
@@ -334,95 +450,176 @@
|
||||
|
||||
}
|
||||
|
||||
- public void remove(ServerPlayer player) {
|
||||
- ServerLevel worldserver = player.serverLevel();
|
||||
+ public String remove(ServerPlayer entityplayer) { // CraftBukkit - return string
|
||||
+ public net.kyori.adventure.text.Component remove(ServerPlayer entityplayer) { // CraftBukkit - return string // Paper - return Component
|
||||
+ ServerLevel worldserver = entityplayer.serverLevel();
|
||||
|
||||
- player.awardStat(Stats.LEAVE_GAME);
|
||||
@ -335,7 +334,7 @@
|
||||
+ entityplayer.closeContainer();
|
||||
+ }
|
||||
+
|
||||
+ PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(entityplayer.getBukkitEntity(), entityplayer.kickLeaveMessage != null ? entityplayer.kickLeaveMessage : "\u00A7e" + entityplayer.getScoreboardName() + " left the game");
|
||||
+ PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(entityplayer.getBukkitEntity(), net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, io.papermc.paper.configuration.GlobalConfiguration.get().messages.useDisplayNameInQuitMessage ? entityplayer.getBukkitEntity().displayName() : io.papermc.paper.adventure.PaperAdventure.asAdventure(entityplayer.getDisplayName()))); // Paper - Adventure
|
||||
+ this.cserver.getPluginManager().callEvent(playerQuitEvent);
|
||||
+ entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage());
|
||||
+
|
||||
@ -410,7 +409,7 @@
|
||||
+ this.cserver.getScoreboardManager().removePlayer(entityplayer.getBukkitEntity());
|
||||
+ // CraftBukkit end
|
||||
+
|
||||
+ return playerQuitEvent.getQuitMessage(); // CraftBukkit
|
||||
+ return playerQuitEvent.quitMessage(); // Paper - Adventure
|
||||
}
|
||||
|
||||
- @Nullable
|
||||
@ -466,11 +465,11 @@
|
||||
- } else if (this.ipBans.isBanned(address)) {
|
||||
- IpBanListEntry ipbanentry = this.ipBans.get(address);
|
||||
+ // return chatmessage;
|
||||
+ event.disallow(PlayerLoginEvent.Result.KICK_BANNED, CraftChatMessage.fromComponent(ichatmutablecomponent));
|
||||
+ event.disallow(PlayerLoginEvent.Result.KICK_BANNED, io.papermc.paper.adventure.PaperAdventure.asAdventure(ichatmutablecomponent)); // Paper - Adventure
|
||||
+ } else if (!this.isWhiteListed(gameprofile)) {
|
||||
+ ichatmutablecomponent = Component.translatable("multiplayer.disconnect.not_whitelisted");
|
||||
+ event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, org.spigotmc.SpigotConfig.whitelistMessage); // Spigot
|
||||
+ } else if (this.ipBans.isBanned(socketaddress)) {
|
||||
+ event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(org.spigotmc.SpigotConfig.whitelistMessage)); // Spigot // Paper - Adventure
|
||||
+ } else if (this.getIpBans().isBanned(socketaddress) && !this.getIpBans().get(socketaddress).hasExpired()) {
|
||||
+ IpBanListEntry ipbanentry = this.ipBans.get(socketaddress);
|
||||
|
||||
ichatmutablecomponent = Component.translatable("multiplayer.disconnect.banned_ip.reason", ipbanentry.getReason());
|
||||
@ -479,20 +478,19 @@
|
||||
}
|
||||
|
||||
- return ichatmutablecomponent;
|
||||
- } else {
|
||||
- return this.players.size() >= this.maxPlayers && !this.canBypassPlayerLimit(profile) ? Component.translatable("multiplayer.disconnect.server_full") : null;
|
||||
+ // return chatmessage;
|
||||
+ event.disallow(PlayerLoginEvent.Result.KICK_BANNED, CraftChatMessage.fromComponent(ichatmutablecomponent));
|
||||
+ } else {
|
||||
+ event.disallow(PlayerLoginEvent.Result.KICK_BANNED, io.papermc.paper.adventure.PaperAdventure.asAdventure(ichatmutablecomponent)); // Paper - Adventure
|
||||
} else {
|
||||
- return this.players.size() >= this.maxPlayers && !this.canBypassPlayerLimit(profile) ? Component.translatable("multiplayer.disconnect.server_full") : null;
|
||||
+ // return this.players.size() >= this.maxPlayers && !this.canBypassPlayerLimit(gameprofile) ? IChatBaseComponent.translatable("multiplayer.disconnect.server_full") : null;
|
||||
+ if (this.players.size() >= this.maxPlayers && !this.canBypassPlayerLimit(gameprofile)) {
|
||||
+ event.disallow(PlayerLoginEvent.Result.KICK_FULL, org.spigotmc.SpigotConfig.serverFullMessage); // Spigot
|
||||
+ event.disallow(PlayerLoginEvent.Result.KICK_FULL, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(org.spigotmc.SpigotConfig.serverFullMessage)); // Spigot // Paper - Adventure
|
||||
+ }
|
||||
}
|
||||
+
|
||||
+ this.cserver.getPluginManager().callEvent(event);
|
||||
+ if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) {
|
||||
+ loginlistener.disconnect(event.getKickMessage());
|
||||
+ loginlistener.disconnect(io.papermc.paper.adventure.PaperAdventure.asVanilla(event.kickMessage())); // Paper - Adventure
|
||||
+ return null;
|
||||
+ }
|
||||
+ return entity;
|
||||
@ -530,7 +528,7 @@
|
||||
|
||||
if (entityplayer1 != null) {
|
||||
set.add(entityplayer1);
|
||||
@@ -431,30 +629,50 @@
|
||||
@@ -431,30 +628,50 @@
|
||||
Iterator iterator1 = set.iterator();
|
||||
|
||||
while (iterator1.hasNext()) {
|
||||
@ -594,7 +592,7 @@
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
String s = (String) iterator.next();
|
||||
@@ -462,41 +680,88 @@
|
||||
@@ -462,41 +679,88 @@
|
||||
entityplayer1.addTag(s);
|
||||
}
|
||||
|
||||
@ -691,7 +689,7 @@
|
||||
return entityplayer1;
|
||||
}
|
||||
|
||||
@@ -524,7 +789,18 @@
|
||||
@@ -524,7 +788,18 @@
|
||||
|
||||
public void tick() {
|
||||
if (++this.sendAllPlayerInfoIn > 600) {
|
||||
@ -711,7 +709,7 @@
|
||||
this.sendAllPlayerInfoIn = 0;
|
||||
}
|
||||
|
||||
@@ -541,6 +817,25 @@
|
||||
@@ -541,6 +816,25 @@
|
||||
|
||||
}
|
||||
|
||||
@ -737,7 +735,7 @@
|
||||
public void broadcastAll(Packet<?> packet, ResourceKey<Level> dimension) {
|
||||
Iterator iterator = this.players.iterator();
|
||||
|
||||
@@ -554,7 +849,7 @@
|
||||
@@ -554,7 +848,7 @@
|
||||
|
||||
}
|
||||
|
||||
@ -746,7 +744,7 @@
|
||||
PlayerTeam scoreboardteam = source.getTeam();
|
||||
|
||||
if (scoreboardteam != null) {
|
||||
@@ -573,7 +868,7 @@
|
||||
@@ -573,7 +867,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@ -755,7 +753,7 @@
|
||||
PlayerTeam scoreboardteam = source.getTeam();
|
||||
|
||||
if (scoreboardteam == null) {
|
||||
@@ -619,7 +914,7 @@
|
||||
@@ -619,7 +913,7 @@
|
||||
}
|
||||
|
||||
public void deop(GameProfile profile) {
|
||||
@ -764,7 +762,7 @@
|
||||
ServerPlayer entityplayer = this.getPlayer(profile.getId());
|
||||
|
||||
if (entityplayer != null) {
|
||||
@@ -643,6 +938,7 @@
|
||||
@@ -643,6 +937,7 @@
|
||||
player.connection.send(new ClientboundEntityEventPacket(player, b0));
|
||||
}
|
||||
|
||||
@ -772,7 +770,7 @@
|
||||
this.server.getCommands().sendCommands(player);
|
||||
}
|
||||
|
||||
@@ -656,23 +952,19 @@
|
||||
@@ -656,23 +951,19 @@
|
||||
|
||||
@Nullable
|
||||
public ServerPlayer getPlayerByName(String name) {
|
||||
@ -804,7 +802,7 @@
|
||||
if (entityplayer != player && entityplayer.level().dimension() == worldKey) {
|
||||
double d4 = x - entityplayer.getX();
|
||||
double d5 = y - entityplayer.getY();
|
||||
@@ -712,15 +1004,19 @@
|
||||
@@ -712,15 +1003,19 @@
|
||||
public void reloadWhiteList() {}
|
||||
|
||||
public void sendLevelInfo(ServerPlayer player, ServerLevel world) {
|
||||
@ -828,7 +826,7 @@
|
||||
}
|
||||
|
||||
player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.LEVEL_CHUNKS_LOAD_START, 0.0F));
|
||||
@@ -729,8 +1025,16 @@
|
||||
@@ -729,8 +1024,16 @@
|
||||
|
||||
public void sendAllPlayerInfo(ServerPlayer player) {
|
||||
player.inventoryMenu.sendAllDataToRemote();
|
||||
@ -846,7 +844,7 @@
|
||||
}
|
||||
|
||||
public int getPlayerCount() {
|
||||
@@ -786,12 +1090,22 @@
|
||||
@@ -786,12 +1089,22 @@
|
||||
}
|
||||
|
||||
public void removeAll() {
|
||||
@ -854,7 +852,7 @@
|
||||
- ((ServerPlayer) this.players.get(i)).connection.disconnect((Component) Component.translatable("multiplayer.disconnect.server_shutdown"));
|
||||
+ // CraftBukkit start - disconnect safely
|
||||
+ for (ServerPlayer player : this.players) {
|
||||
+ player.connection.disconnect(CraftChatMessage.fromStringOrEmpty(this.server.server.getShutdownMessage())); // CraftBukkit - add custom shutdown message
|
||||
+ player.connection.disconnect(java.util.Objects.requireNonNullElseGet(this.server.server.shutdownMessage(), net.kyori.adventure.text.Component::empty)); // CraftBukkit - add custom shutdown message // Paper - Adventure
|
||||
}
|
||||
+ // CraftBukkit end
|
||||
|
||||
@ -871,7 +869,59 @@
|
||||
public void broadcastSystemMessage(Component message, boolean overlay) {
|
||||
this.broadcastSystemMessage(message, (entityplayer) -> {
|
||||
return message;
|
||||
@@ -849,16 +1163,23 @@
|
||||
@@ -819,24 +1132,43 @@
|
||||
}
|
||||
|
||||
public void broadcastChatMessage(PlayerChatMessage message, ServerPlayer sender, ChatType.Bound params) {
|
||||
+ // Paper start
|
||||
+ this.broadcastChatMessage(message, sender, params, null);
|
||||
+ }
|
||||
+ public void broadcastChatMessage(PlayerChatMessage message, ServerPlayer sender, ChatType.Bound params, @Nullable Function<net.kyori.adventure.audience.Audience, Component> unsignedFunction) {
|
||||
+ // Paper end
|
||||
Objects.requireNonNull(sender);
|
||||
- this.broadcastChatMessage(message, sender::shouldFilterMessageTo, sender, params);
|
||||
+ this.broadcastChatMessage(message, sender::shouldFilterMessageTo, sender, params, unsignedFunction); // Paper
|
||||
}
|
||||
|
||||
private void broadcastChatMessage(PlayerChatMessage message, Predicate<ServerPlayer> shouldSendFiltered, @Nullable ServerPlayer sender, ChatType.Bound params) {
|
||||
+ // Paper start
|
||||
+ this.broadcastChatMessage(message, shouldSendFiltered, sender, params, null);
|
||||
+ }
|
||||
+ public void broadcastChatMessage(PlayerChatMessage message, Predicate<ServerPlayer> shouldSendFiltered, @Nullable ServerPlayer sender, ChatType.Bound params, @Nullable Function<net.kyori.adventure.audience.Audience, Component> unsignedFunction) {
|
||||
+ // Paper end
|
||||
boolean flag = this.verifyChatTrusted(message);
|
||||
|
||||
- this.server.logChatMessage(message.decoratedContent(), params, flag ? null : "Not Secure");
|
||||
+ this.server.logChatMessage((unsignedFunction == null ? message.decoratedContent() : unsignedFunction.apply(this.server.console)), params, flag ? null : "Not Secure"); // Paper
|
||||
OutgoingChatMessage outgoingchatmessage = OutgoingChatMessage.create(message);
|
||||
boolean flag1 = false;
|
||||
|
||||
boolean flag2;
|
||||
+ Packet<?> disguised = sender != null && unsignedFunction == null ? new net.minecraft.network.protocol.game.ClientboundDisguisedChatPacket(outgoingchatmessage.content(), params) : null; // Paper - don't send player chat packets from vanished players
|
||||
|
||||
for (Iterator iterator = this.players.iterator(); iterator.hasNext(); flag1 |= flag2 && message.isFullyFiltered()) {
|
||||
ServerPlayer entityplayer1 = (ServerPlayer) iterator.next();
|
||||
|
||||
flag2 = shouldSendFiltered.test(entityplayer1);
|
||||
- entityplayer1.sendChatMessage(outgoingchatmessage, flag2, params);
|
||||
+ // Paper start - don't send player chat packets from vanished players
|
||||
+ if (sender != null && !entityplayer1.getBukkitEntity().canSee(sender.getBukkitEntity())) {
|
||||
+ entityplayer1.connection.send(unsignedFunction != null
|
||||
+ ? new net.minecraft.network.protocol.game.ClientboundDisguisedChatPacket(unsignedFunction.apply(entityplayer1.getBukkitEntity()), params)
|
||||
+ : disguised);
|
||||
+ continue;
|
||||
+ }
|
||||
+ // Paper end
|
||||
+ entityplayer1.sendChatMessage(outgoingchatmessage, flag2, params, unsignedFunction == null ? null : unsignedFunction.apply(entityplayer1.getBukkitEntity())); // Paper
|
||||
}
|
||||
|
||||
if (flag1 && sender != null) {
|
||||
@@ -845,20 +1177,27 @@
|
||||
|
||||
}
|
||||
|
||||
- private boolean verifyChatTrusted(PlayerChatMessage message) {
|
||||
+ public boolean verifyChatTrusted(PlayerChatMessage message) { // Paper - private -> public
|
||||
return message.hasSignature() && !message.hasExpiredServer(Instant.now());
|
||||
}
|
||||
|
||||
@ -899,7 +949,7 @@
|
||||
Path path = file2.toPath();
|
||||
|
||||
if (FileUtil.isPathNormalized(path) && FileUtil.isPathPortable(path) && path.startsWith(file.getPath()) && file2.isFile()) {
|
||||
@@ -867,7 +1188,7 @@
|
||||
@@ -867,7 +1206,7 @@
|
||||
}
|
||||
|
||||
serverstatisticmanager = new ServerStatsCounter(this.server, file1);
|
||||
@ -908,7 +958,7 @@
|
||||
}
|
||||
|
||||
return serverstatisticmanager;
|
||||
@@ -875,13 +1196,13 @@
|
||||
@@ -875,13 +1214,13 @@
|
||||
|
||||
public PlayerAdvancements getPlayerAdvancements(ServerPlayer player) {
|
||||
UUID uuid = player.getUUID();
|
||||
@ -924,7 +974,7 @@
|
||||
}
|
||||
|
||||
advancementdataplayer.setPlayer(player);
|
||||
@@ -932,15 +1253,28 @@
|
||||
@@ -932,15 +1271,28 @@
|
||||
}
|
||||
|
||||
public void reloadResources() {
|
||||
|
@ -0,0 +1,86 @@
|
||||
--- a/net/minecraft/world/BossEvent.java
|
||||
+++ b/net/minecraft/world/BossEvent.java
|
||||
@@ -13,6 +13,7 @@
|
||||
protected boolean darkenScreen;
|
||||
protected boolean playBossMusic;
|
||||
protected boolean createWorldFog;
|
||||
+ public net.kyori.adventure.bossbar.BossBar adventure; // Paper
|
||||
|
||||
public BossEvent(UUID uuid, Component name, BossEvent.BossBarColor color, BossEvent.BossBarOverlay style) {
|
||||
this.id = uuid;
|
||||
@@ -27,61 +28,75 @@
|
||||
}
|
||||
|
||||
public Component getName() {
|
||||
+ if (this.adventure != null) return io.papermc.paper.adventure.PaperAdventure.asVanilla(this.adventure.name()); // Paper
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(Component name) {
|
||||
+ if (this.adventure != null) this.adventure.name(io.papermc.paper.adventure.PaperAdventure.asAdventure(name)); // Paper
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public float getProgress() {
|
||||
+ if (this.adventure != null) return this.adventure.progress(); // Paper
|
||||
return this.progress;
|
||||
}
|
||||
|
||||
public void setProgress(float percent) {
|
||||
+ if (this.adventure != null) this.adventure.progress(percent); // Paper
|
||||
this.progress = percent;
|
||||
}
|
||||
|
||||
public BossEvent.BossBarColor getColor() {
|
||||
+ if (this.adventure != null) return io.papermc.paper.adventure.PaperAdventure.asVanilla(this.adventure.color()); // Paper
|
||||
return this.color;
|
||||
}
|
||||
|
||||
public void setColor(BossEvent.BossBarColor color) {
|
||||
+ if (this.adventure != null) this.adventure.color(io.papermc.paper.adventure.PaperAdventure.asAdventure(color)); // Paper
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public BossEvent.BossBarOverlay getOverlay() {
|
||||
+ if (this.adventure != null) return io.papermc.paper.adventure.PaperAdventure.asVanilla(this.adventure.overlay()); // Paper
|
||||
return this.overlay;
|
||||
}
|
||||
|
||||
public void setOverlay(BossEvent.BossBarOverlay style) {
|
||||
+ if (this.adventure != null) this.adventure.overlay(io.papermc.paper.adventure.PaperAdventure.asAdventure(style)); // Paper
|
||||
this.overlay = style;
|
||||
}
|
||||
|
||||
public boolean shouldDarkenScreen() {
|
||||
+ if (this.adventure != null) return this.adventure.hasFlag(net.kyori.adventure.bossbar.BossBar.Flag.DARKEN_SCREEN); // Paper
|
||||
return this.darkenScreen;
|
||||
}
|
||||
|
||||
public BossEvent setDarkenScreen(boolean darkenSky) {
|
||||
+ if (this.adventure != null) io.papermc.paper.adventure.PaperAdventure.setFlag(this.adventure, net.kyori.adventure.bossbar.BossBar.Flag.DARKEN_SCREEN, darkenSky); // Paper
|
||||
this.darkenScreen = darkenSky;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean shouldPlayBossMusic() {
|
||||
+ if (this.adventure != null) return this.adventure.hasFlag(net.kyori.adventure.bossbar.BossBar.Flag.PLAY_BOSS_MUSIC); // Paper
|
||||
return this.playBossMusic;
|
||||
}
|
||||
|
||||
public BossEvent setPlayBossMusic(boolean dragonMusic) {
|
||||
+ if (this.adventure != null) io.papermc.paper.adventure.PaperAdventure.setFlag(this.adventure, net.kyori.adventure.bossbar.BossBar.Flag.PLAY_BOSS_MUSIC, dragonMusic); // Paper
|
||||
this.playBossMusic = dragonMusic;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BossEvent setCreateWorldFog(boolean thickenFog) {
|
||||
+ if (this.adventure != null) io.papermc.paper.adventure.PaperAdventure.setFlag(this.adventure, net.kyori.adventure.bossbar.BossBar.Flag.CREATE_WORLD_FOG, thickenFog); // Paper
|
||||
this.createWorldFog = thickenFog;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean shouldCreateWorldFog() {
|
||||
+ if (this.adventure != null) return this.adventure.hasFlag(net.kyori.adventure.bossbar.BossBar.Flag.CREATE_WORLD_FOG); // Paper
|
||||
return this.createWorldFog;
|
||||
}
|
||||
|
@ -89,7 +89,7 @@
|
||||
return instance.group(Item.CODEC.fieldOf("id").forGetter(ItemStack::getItemHolder), DataComponentPatch.CODEC.optionalFieldOf("components", DataComponentPatch.EMPTY).forGetter((itemstack) -> {
|
||||
return itemstack.components.asPatch();
|
||||
})).apply(instance, (holder, datacomponentpatch) -> {
|
||||
@@ -132,19 +161,29 @@
|
||||
@@ -132,20 +161,38 @@
|
||||
if (i <= 0) {
|
||||
return ItemStack.EMPTY;
|
||||
} else {
|
||||
@ -120,10 +120,19 @@
|
||||
+ CraftItemStack.setItemMeta(itemstack, CraftItemStack.getItemMeta(itemstack));
|
||||
+ // Spigot end
|
||||
+ ITEM_STREAM_CODEC.encode(registryfriendlybytebuf, itemstack.getItemHolder()); // CraftBukkit - decompile error
|
||||
+ // Paper start - adventure; conditionally render translatable components
|
||||
+ boolean prev = net.minecraft.network.chat.ComponentSerialization.DONT_RENDER_TRANSLATABLES.get();
|
||||
+ try {
|
||||
+ net.minecraft.network.chat.ComponentSerialization.DONT_RENDER_TRANSLATABLES.set(true);
|
||||
DataComponentPatch.STREAM_CODEC.encode(registryfriendlybytebuf, itemstack.components.asPatch());
|
||||
+ } finally {
|
||||
+ net.minecraft.network.chat.ComponentSerialization.DONT_RENDER_TRANSLATABLES.set(prev);
|
||||
+ }
|
||||
+ // Paper end - adventure; conditionally render translatable components
|
||||
}
|
||||
}
|
||||
@@ -187,7 +226,7 @@
|
||||
};
|
||||
@@ -187,7 +234,7 @@
|
||||
|
||||
return dataresult.isError() ? dataresult.map((unit) -> {
|
||||
return stack;
|
||||
@ -132,7 +141,7 @@
|
||||
int i = stack.getCount();
|
||||
|
||||
return "Item stack with stack size of " + i + " was larger than maximum: " + stack.getMaxStackSize();
|
||||
@@ -294,8 +333,9 @@
|
||||
@@ -294,8 +341,9 @@
|
||||
j = itemstack.getMaxStackSize();
|
||||
} while (i <= j);
|
||||
|
||||
@ -143,7 +152,7 @@
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -370,32 +410,190 @@
|
||||
@@ -370,32 +418,190 @@
|
||||
}
|
||||
|
||||
public InteractionResult useOn(UseOnContext context) {
|
||||
@ -339,7 +348,7 @@
|
||||
ItemStack itemstack = this.copy();
|
||||
boolean flag = this.getUseDuration(user) <= 0;
|
||||
InteractionResult enuminteractionresult = this.getItem().use(world, user, hand);
|
||||
@@ -492,7 +690,22 @@
|
||||
@@ -492,7 +698,22 @@
|
||||
|
||||
public void hurtAndBreak(int amount, ServerLevel world, @Nullable ServerPlayer player, Consumer<Item> breakCallback) {
|
||||
int j = this.processDurabilityChange(amount, world, player);
|
||||
@ -362,7 +371,7 @@
|
||||
if (j != 0) {
|
||||
this.applyDamage(this.getDamageValue() + j, player, breakCallback);
|
||||
}
|
||||
@@ -511,6 +724,11 @@
|
||||
@@ -511,6 +732,11 @@
|
||||
this.setDamageValue(damage);
|
||||
if (this.isBroken()) {
|
||||
Item item = this.getItem();
|
||||
@ -374,7 +383,7 @@
|
||||
|
||||
this.shrink(1);
|
||||
breakCallback.accept(item);
|
||||
@@ -518,7 +736,7 @@
|
||||
@@ -518,7 +744,7 @@
|
||||
|
||||
}
|
||||
|
||||
@ -383,7 +392,7 @@
|
||||
if (player instanceof ServerPlayer entityplayer) {
|
||||
int j = this.processDurabilityChange(amount, entityplayer.serverLevel(), entityplayer);
|
||||
|
||||
@@ -580,11 +798,11 @@
|
||||
@@ -580,11 +806,11 @@
|
||||
return this.getItem().getBarColor(this);
|
||||
}
|
||||
|
||||
@ -397,7 +406,7 @@
|
||||
return this.getItem().overrideOtherStackedOnMe(this, stack, slot, clickType, player, cursorStackReference);
|
||||
}
|
||||
|
||||
@@ -592,8 +810,8 @@
|
||||
@@ -592,8 +818,8 @@
|
||||
Item item = this.getItem();
|
||||
|
||||
if (item.hurtEnemy(this, target, user)) {
|
||||
@ -408,7 +417,7 @@
|
||||
|
||||
entityhuman.awardStat(Stats.ITEM_USED.get(item));
|
||||
}
|
||||
@@ -608,7 +826,7 @@
|
||||
@@ -608,7 +834,7 @@
|
||||
this.getItem().postHurtEnemy(this, target, user);
|
||||
}
|
||||
|
||||
@ -417,7 +426,7 @@
|
||||
Item item = this.getItem();
|
||||
|
||||
if (item.mineBlock(this, world, state, pos, miner)) {
|
||||
@@ -617,11 +835,11 @@
|
||||
@@ -617,11 +843,11 @@
|
||||
|
||||
}
|
||||
|
||||
@ -431,7 +440,7 @@
|
||||
return this.getItem().interactLivingEntity(this, user, entity, hand);
|
||||
}
|
||||
|
||||
@@ -736,7 +954,7 @@
|
||||
@@ -736,7 +962,7 @@
|
||||
|
||||
}
|
||||
|
||||
@ -440,7 +449,7 @@
|
||||
player.awardStat(Stats.ITEM_CRAFTED.get(this.getItem()), amount);
|
||||
this.getItem().onCraftedBy(this, world, player);
|
||||
}
|
||||
@@ -768,7 +986,13 @@
|
||||
@@ -768,7 +994,13 @@
|
||||
|
||||
public boolean useOnRelease() {
|
||||
return this.getItem().useOnRelease(this);
|
||||
@ -454,12 +463,10 @@
|
||||
|
||||
@Nullable
|
||||
public <T> T set(DataComponentType<? super T> type, @Nullable T value) {
|
||||
@@ -804,7 +1028,26 @@
|
||||
} else {
|
||||
this.getItem().verifyComponentsAfterLoad(this);
|
||||
@@ -806,6 +1038,25 @@
|
||||
}
|
||||
+ }
|
||||
+
|
||||
}
|
||||
|
||||
+ // Paper start - (this is just a good no conflict location)
|
||||
+ public org.bukkit.inventory.ItemStack asBukkitMirror() {
|
||||
+ return CraftItemStack.asCraftMirror(this);
|
||||
@ -476,12 +483,13 @@
|
||||
+ bukkitStack = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(this);
|
||||
+ }
|
||||
+ return bukkitStack;
|
||||
}
|
||||
+ }
|
||||
+ // Paper end
|
||||
|
||||
+
|
||||
public void applyComponents(DataComponentPatch changes) {
|
||||
this.components.applyPatch(changes);
|
||||
@@ -858,7 +1101,7 @@
|
||||
this.getItem().verifyComponentsAfterLoad(this);
|
||||
@@ -858,7 +1109,7 @@
|
||||
}
|
||||
|
||||
private <T extends TooltipProvider> void addToTooltip(DataComponentType<T> componentType, Item.TooltipContext context, Consumer<Component> textConsumer, TooltipFlag type) {
|
||||
@ -490,7 +498,7 @@
|
||||
|
||||
if (t0 != null) {
|
||||
t0.addToTooltip(context, textConsumer, type);
|
||||
@@ -866,7 +1109,7 @@
|
||||
@@ -866,7 +1117,7 @@
|
||||
|
||||
}
|
||||
|
||||
@ -499,7 +507,7 @@
|
||||
boolean flag = this.getItem().shouldPrintOpWarning(this, player);
|
||||
|
||||
if (!type.isCreative() && this.has(DataComponents.HIDE_TOOLTIP)) {
|
||||
@@ -941,7 +1184,7 @@
|
||||
@@ -941,7 +1192,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@ -508,7 +516,7 @@
|
||||
ItemAttributeModifiers itemattributemodifiers = (ItemAttributeModifiers) this.getOrDefault(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY);
|
||||
|
||||
if (itemattributemodifiers.showInTooltip()) {
|
||||
@@ -966,7 +1209,7 @@
|
||||
@@ -966,7 +1217,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@ -517,7 +525,7 @@
|
||||
double d0 = modifier.amount();
|
||||
boolean flag = false;
|
||||
|
||||
@@ -1091,6 +1334,14 @@
|
||||
@@ -1091,6 +1342,14 @@
|
||||
EnchantmentHelper.forEachModifier(this, slot, attributeModifierConsumer);
|
||||
}
|
||||
|
||||
@ -532,7 +540,7 @@
|
||||
public Component getDisplayName() {
|
||||
MutableComponent ichatmutablecomponent = Component.empty().append(this.getHoverName());
|
||||
|
||||
@@ -1153,7 +1404,7 @@
|
||||
@@ -1153,7 +1412,7 @@
|
||||
}
|
||||
|
||||
public void consume(int amount, @Nullable LivingEntity entity) {
|
||||
|
@ -109,22 +109,22 @@
|
||||
- return text;
|
||||
+ // CraftBukkit start
|
||||
+ Player player = ((ServerPlayer) entityhuman).getBukkitEntity();
|
||||
+ String[] lines = new String[4];
|
||||
+ List<net.kyori.adventure.text.Component> lines = new java.util.ArrayList<>(); // Paper - adventure
|
||||
+
|
||||
+ for (int i = 0; i < list.size(); ++i) {
|
||||
+ lines[i] = CraftChatMessage.fromComponent(signtext.getMessage(i, entityhuman.isTextFilteringEnabled()));
|
||||
+ lines.add(io.papermc.paper.adventure.PaperAdventure.asAdventure(signtext.getMessage(i, entityhuman.isTextFilteringEnabled()))); // Paper - Adventure
|
||||
+ }
|
||||
+
|
||||
+ SignChangeEvent event = new SignChangeEvent(CraftBlock.at(this.level, this.worldPosition), player, lines.clone(), (front) ? Side.FRONT : Side.BACK);
|
||||
+ SignChangeEvent event = new SignChangeEvent(CraftBlock.at(this.level, this.worldPosition), player, new java.util.ArrayList<>(lines), (front) ? Side.FRONT : Side.BACK); // Paper - Adventure
|
||||
+ entityhuman.level().getCraftServer().getPluginManager().callEvent(event);
|
||||
+
|
||||
+ if (event.isCancelled()) {
|
||||
+ return originalText;
|
||||
+ }
|
||||
+
|
||||
+ Component[] components = org.bukkit.craftbukkit.block.CraftSign.sanitizeLines(event.getLines());
|
||||
+ Component[] components = org.bukkit.craftbukkit.block.CraftSign.sanitizeLines(event.lines()); // Paper - Adventure
|
||||
+ for (int i = 0; i < components.length; i++) {
|
||||
+ if (!Objects.equals(lines[i], event.getLine(i))) {
|
||||
+ if (!Objects.equals(lines.get(i), event.line(i))) { // Paper - Adventure
|
||||
+ signtext = signtext.setMessage(i, components[i]);
|
||||
+ }
|
||||
+ }
|
||||
|
@ -1,10 +1,11 @@
|
||||
--- a/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
|
||||
+++ b/net/minecraft/world/level/saveddata/maps/MapItemSavedData.java
|
||||
@@ -47,6 +47,16 @@
|
||||
@@ -47,6 +47,17 @@
|
||||
import net.minecraft.world.level.saveddata.SavedData;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
+// CraftBukkit start
|
||||
+import io.papermc.paper.adventure.PaperAdventure; // Paper
|
||||
+import java.util.UUID;
|
||||
+import org.bukkit.Bukkit;
|
||||
+import org.bukkit.craftbukkit.CraftServer;
|
||||
@ -17,7 +18,7 @@
|
||||
public class MapItemSavedData extends SavedData {
|
||||
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
@@ -70,6 +80,13 @@
|
||||
@@ -70,6 +81,13 @@
|
||||
private final Map<String, MapFrame> frameMarkers = Maps.newHashMap();
|
||||
private int trackedDecorationCount;
|
||||
|
||||
@ -31,7 +32,7 @@
|
||||
public static SavedData.Factory<MapItemSavedData> factory() {
|
||||
return new SavedData.Factory<>(() -> {
|
||||
throw new IllegalStateException("Should never create an empty map saved data");
|
||||
@@ -84,6 +101,10 @@
|
||||
@@ -84,6 +102,10 @@
|
||||
this.trackingPosition = showDecorations;
|
||||
this.unlimitedTracking = unlimitedTracking;
|
||||
this.locked = locked;
|
||||
@ -42,7 +43,7 @@
|
||||
}
|
||||
|
||||
public static MapItemSavedData createFresh(double centerX, double centerZ, byte scale, boolean showDecorations, boolean unlimitedTracking, ResourceKey<Level> dimension) {
|
||||
@@ -101,12 +122,30 @@
|
||||
@@ -101,12 +123,30 @@
|
||||
}
|
||||
|
||||
public static MapItemSavedData load(CompoundTag nbt, HolderLookup.Provider registries) {
|
||||
@ -76,7 +77,7 @@
|
||||
});
|
||||
int i = nbt.getInt("xCenter");
|
||||
int j = nbt.getInt("zCenter");
|
||||
@@ -131,7 +170,8 @@
|
||||
@@ -131,7 +171,8 @@
|
||||
MapBanner mapiconbanner = (MapBanner) iterator.next();
|
||||
|
||||
worldmap.bannerMarkers.put(mapiconbanner.getId(), mapiconbanner);
|
||||
@ -86,7 +87,7 @@
|
||||
}
|
||||
|
||||
ListTag nbttaglist = nbt.getList("frames", 10);
|
||||
@@ -150,13 +190,32 @@
|
||||
@@ -150,13 +191,32 @@
|
||||
|
||||
@Override
|
||||
public CompoundTag save(CompoundTag nbt, HolderLookup.Provider registries) {
|
||||
@ -120,7 +121,7 @@
|
||||
nbt.putInt("xCenter", this.centerX);
|
||||
nbt.putInt("zCenter", this.centerZ);
|
||||
nbt.putByte("scale", this.scale);
|
||||
@@ -443,7 +502,7 @@
|
||||
@@ -443,7 +503,7 @@
|
||||
|
||||
if (!this.isTrackedCountOverLimit(256)) {
|
||||
this.bannerMarkers.put(mapiconbanner.getId(), mapiconbanner);
|
||||
@ -129,7 +130,7 @@
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -554,7 +613,7 @@
|
||||
@@ -554,7 +614,7 @@
|
||||
this.player = entityhuman;
|
||||
}
|
||||
|
||||
@ -138,7 +139,7 @@
|
||||
int i = this.minDirtyX;
|
||||
int j = this.minDirtyY;
|
||||
int k = this.maxDirtyX + 1 - this.minDirtyX;
|
||||
@@ -563,7 +622,7 @@
|
||||
@@ -563,7 +623,7 @@
|
||||
|
||||
for (int i1 = 0; i1 < k; ++i1) {
|
||||
for (int j1 = 0; j1 < l; ++j1) {
|
||||
@ -147,7 +148,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@@ -573,19 +632,29 @@
|
||||
@@ -573,19 +633,29 @@
|
||||
@Nullable
|
||||
Packet<?> nextUpdatePacket(MapId mapId) {
|
||||
MapItemSavedData.MapPatch worldmap_c;
|
||||
@ -172,7 +173,7 @@
|
||||
+
|
||||
+ for (org.bukkit.map.MapCursor cursor : render.cursors) {
|
||||
+ if (cursor.isVisible()) {
|
||||
+ icons.add(new MapDecoration(CraftMapCursor.CraftType.bukkitToMinecraftHolder(cursor.getType()), cursor.getX(), cursor.getY(), cursor.getDirection(), CraftChatMessage.fromStringOrOptional(cursor.getCaption())));
|
||||
+ icons.add(new MapDecoration(CraftMapCursor.CraftType.bukkitToMinecraftHolder(cursor.getType()), cursor.getX(), cursor.getY(), cursor.getDirection(), Optional.ofNullable(PaperAdventure.asVanilla(cursor.caption()))));
|
||||
+ }
|
||||
+ }
|
||||
+ collection = icons;
|
||||
|
@ -0,0 +1,450 @@
|
||||
package io.papermc.paper.adventure;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.datafixers.util.Either;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.DataResult;
|
||||
import com.mojang.serialization.DynamicOps;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.BlockNBTComponent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.EntityNBTComponent;
|
||||
import net.kyori.adventure.text.KeybindComponent;
|
||||
import net.kyori.adventure.text.NBTComponent;
|
||||
import net.kyori.adventure.text.NBTComponentBuilder;
|
||||
import net.kyori.adventure.text.ScoreComponent;
|
||||
import net.kyori.adventure.text.SelectorComponent;
|
||||
import net.kyori.adventure.text.StorageNBTComponent;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
import net.kyori.adventure.text.TranslationArgument;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.DataComponentValue;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import net.minecraft.commands.arguments.selector.SelectorPattern;
|
||||
import net.minecraft.core.UUIDUtil;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.TagParser;
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
import net.minecraft.network.chat.ComponentSerialization;
|
||||
import net.minecraft.network.chat.contents.KeybindContents;
|
||||
import net.minecraft.network.chat.contents.ScoreContents;
|
||||
import net.minecraft.network.chat.contents.TranslatableContents;
|
||||
import net.minecraft.network.codec.ByteBufCodecs;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.util.ExtraCodecs;
|
||||
import net.minecraft.util.StringRepresentable;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.intellij.lang.annotations.Subst;
|
||||
|
||||
import static com.mojang.serialization.Codec.recursive;
|
||||
import static com.mojang.serialization.codecs.RecordCodecBuilder.mapCodec;
|
||||
import static java.util.function.Function.identity;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.TranslationArgument.bool;
|
||||
import static net.kyori.adventure.text.TranslationArgument.component;
|
||||
import static net.kyori.adventure.text.TranslationArgument.numeric;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class AdventureCodecs {
|
||||
|
||||
public static final Codec<Component> COMPONENT_CODEC = recursive("adventure Component", AdventureCodecs::createCodec);
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, Component> STREAM_COMPONENT_CODEC = ByteBufCodecs.fromCodecWithRegistriesTrusted(COMPONENT_CODEC);
|
||||
|
||||
static final Codec<TextColor> TEXT_COLOR_CODEC = Codec.STRING.comapFlatMap(s -> {
|
||||
if (s.startsWith("#")) {
|
||||
@Nullable TextColor value = TextColor.fromHexString(s);
|
||||
return value != null ? DataResult.success(value) : DataResult.error(() -> "Cannot convert " + s + " to adventure TextColor");
|
||||
} else {
|
||||
final @Nullable NamedTextColor value = NamedTextColor.NAMES.value(s);
|
||||
return value != null ? DataResult.success(value) : DataResult.error(() -> "Cannot convert " + s + " to adventure NamedTextColor");
|
||||
}
|
||||
}, textColor -> {
|
||||
if (textColor instanceof NamedTextColor named) {
|
||||
return NamedTextColor.NAMES.keyOrThrow(named);
|
||||
} else {
|
||||
return textColor.asHexString();
|
||||
}
|
||||
});
|
||||
|
||||
static final Codec<Key> KEY_CODEC = Codec.STRING.comapFlatMap(s -> {
|
||||
return Key.parseable(s) ? DataResult.success(Key.key(s)) : DataResult.error(() -> "Cannot convert " + s + " to adventure Key");
|
||||
}, Key::asString);
|
||||
|
||||
static final Codec<ClickEvent.Action> CLICK_EVENT_ACTION_CODEC = Codec.STRING.comapFlatMap(s -> {
|
||||
final ClickEvent.@Nullable Action value = ClickEvent.Action.NAMES.value(s);
|
||||
return value != null ? DataResult.success(value) : DataResult.error(() -> "Cannot convert " + s + " to adventure ClickEvent$Action");
|
||||
}, ClickEvent.Action.NAMES::keyOrThrow);
|
||||
static final Codec<ClickEvent> CLICK_EVENT_CODEC = RecordCodecBuilder.create((instance) -> {
|
||||
return instance.group(
|
||||
CLICK_EVENT_ACTION_CODEC.fieldOf("action").forGetter(ClickEvent::action),
|
||||
Codec.STRING.fieldOf("value").forGetter(ClickEvent::value)
|
||||
).apply(instance, ClickEvent::clickEvent);
|
||||
});
|
||||
|
||||
static Codec<HoverEvent.ShowEntity> showEntityCodec(final Codec<Component> componentCodec) {
|
||||
return RecordCodecBuilder.create((instance) -> {
|
||||
return instance.group(
|
||||
KEY_CODEC.fieldOf("type").forGetter(HoverEvent.ShowEntity::type),
|
||||
UUIDUtil.LENIENT_CODEC.fieldOf("id").forGetter(HoverEvent.ShowEntity::id),
|
||||
componentCodec.lenientOptionalFieldOf("name").forGetter(he -> Optional.ofNullable(he.name()))
|
||||
).apply(instance, (key, uuid, component) -> {
|
||||
return HoverEvent.ShowEntity.showEntity(key, uuid, component.orElse(null));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static Codec<HoverEvent.ShowItem> showItemCodec(final Codec<Component> componentCodec) {
|
||||
return net.minecraft.network.chat.HoverEvent.ItemStackInfo.CODEC.xmap(isi -> {
|
||||
@Subst("key") final String typeKey = isi.item.unwrapKey().orElseThrow().location().toString();
|
||||
return HoverEvent.ShowItem.showItem(Key.key(typeKey), isi.count, PaperAdventure.asAdventure(isi.getItemStack().getComponentsPatch()));
|
||||
}, si -> {
|
||||
final Item itemType = BuiltInRegistries.ITEM.getValue(PaperAdventure.asVanilla(si.item()));
|
||||
final Map<Key, DataComponentValue> dataComponentsMap = si.dataComponents();
|
||||
final ItemStack stack = new ItemStack(BuiltInRegistries.ITEM.wrapAsHolder(itemType), si.count(), PaperAdventure.asVanilla(dataComponentsMap));
|
||||
return new net.minecraft.network.chat.HoverEvent.ItemStackInfo(stack);
|
||||
});
|
||||
}
|
||||
|
||||
static final HoverEventType<HoverEvent.ShowEntity> SHOW_ENTITY_HOVER_EVENT_TYPE = new HoverEventType<>(AdventureCodecs::showEntityCodec, HoverEvent.Action.SHOW_ENTITY, "show_entity", AdventureCodecs::legacyDeserializeEntity);
|
||||
static final HoverEventType<HoverEvent.ShowItem> SHOW_ITEM_HOVER_EVENT_TYPE = new HoverEventType<>(AdventureCodecs::showItemCodec, HoverEvent.Action.SHOW_ITEM, "show_item", AdventureCodecs::legacyDeserializeItem);
|
||||
static final HoverEventType<Component> SHOW_TEXT_HOVER_EVENT_TYPE = new HoverEventType<>(identity(), HoverEvent.Action.SHOW_TEXT, "show_text", (component, registryOps, codec) -> DataResult.success(component));
|
||||
static final Codec<HoverEventType<?>> HOVER_EVENT_TYPE_CODEC = StringRepresentable.fromValues(() -> new HoverEventType<?>[]{ SHOW_ENTITY_HOVER_EVENT_TYPE, SHOW_ITEM_HOVER_EVENT_TYPE, SHOW_TEXT_HOVER_EVENT_TYPE });
|
||||
|
||||
static DataResult<HoverEvent.ShowEntity> legacyDeserializeEntity(final Component component, final @Nullable RegistryOps<?> ops, final Codec<Component> componentCodec) {
|
||||
try {
|
||||
final CompoundTag tag = TagParser.parseTag(PlainTextComponentSerializer.plainText().serialize(component));
|
||||
final DynamicOps<JsonElement> dynamicOps = ops != null ? ops.withParent(JsonOps.INSTANCE) : JsonOps.INSTANCE;
|
||||
final DataResult<Component> entityNameResult = componentCodec.parse(dynamicOps, JsonParser.parseString(tag.getString("name")));
|
||||
@Subst("key") final String keyString = tag.getString("type");
|
||||
final UUID entityUUID = UUID.fromString(tag.getString("id"));
|
||||
return entityNameResult.map(name -> HoverEvent.ShowEntity.showEntity(Key.key(keyString), entityUUID, name));
|
||||
} catch (final Exception ex) {
|
||||
return DataResult.error(() -> "Failed to parse tooltip: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
static DataResult<HoverEvent.ShowItem> legacyDeserializeItem(final Component component, final @Nullable RegistryOps<?> ops, final Codec<Component> componentCodec) {
|
||||
try {
|
||||
final CompoundTag tag = TagParser.parseTag(PlainTextComponentSerializer.plainText().serialize(component));
|
||||
final DynamicOps<Tag> dynamicOps = ops != null ? ops.withParent(NbtOps.INSTANCE) : NbtOps.INSTANCE;
|
||||
final DataResult<ItemStack> stackResult = ItemStack.CODEC.parse(dynamicOps, tag);
|
||||
return stackResult.map(stack -> {
|
||||
@Subst("key:value") final String location = stack.getItemHolder().unwrapKey().orElseThrow().location().toString();
|
||||
return HoverEvent.ShowItem.showItem(Key.key(location), stack.getCount(), PaperAdventure.asAdventure(stack.getComponentsPatch()));
|
||||
});
|
||||
} catch (final CommandSyntaxException ex) {
|
||||
return DataResult.error(() -> "Failed to parse item tag: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface LegacyDeserializer<T> {
|
||||
DataResult<T> apply(Component component, @Nullable RegistryOps<?> ops, Codec<Component> componentCodec);
|
||||
}
|
||||
|
||||
record HoverEventType<V>(Function<Codec<Component>, MapCodec<HoverEvent<V>>> codec, String id, Function<Codec<Component>, MapCodec<HoverEvent<V>>> legacyCodec) implements StringRepresentable {
|
||||
HoverEventType(final Function<Codec<Component>, Codec<V>> contentCodec, final HoverEvent.Action<V> action, final String id, final LegacyDeserializer<V> legacyDeserializer) {
|
||||
this(cc -> contentCodec.apply(cc).xmap(v -> HoverEvent.hoverEvent(action, v), HoverEvent::value).fieldOf("contents"),
|
||||
id,
|
||||
codec -> (new Codec<HoverEvent<V>>() {
|
||||
public <D> DataResult<Pair<HoverEvent<V>, D>> decode(final DynamicOps<D> dynamicOps, final D object) {
|
||||
return codec.decode(dynamicOps, object).flatMap(pair -> {
|
||||
final DataResult<V> dataResult;
|
||||
if (dynamicOps instanceof final RegistryOps<D> registryOps) {
|
||||
dataResult = legacyDeserializer.apply(pair.getFirst(), registryOps, codec);
|
||||
} else {
|
||||
dataResult = legacyDeserializer.apply(pair.getFirst(), null, codec);
|
||||
}
|
||||
|
||||
return dataResult.map(value -> Pair.of(HoverEvent.hoverEvent(action, value), pair.getSecond()));
|
||||
});
|
||||
}
|
||||
|
||||
public <D> DataResult<D> encode(final HoverEvent<V> hoverEvent, final DynamicOps<D> dynamicOps, final D object) {
|
||||
return DataResult.error(() -> "Can't encode in legacy format");
|
||||
}
|
||||
}).fieldOf("value")
|
||||
);
|
||||
}
|
||||
@Override
|
||||
public String getSerializedName() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
|
||||
private static final Function<HoverEvent<?>, HoverEventType<?>> GET_HOVER_EVENT_TYPE = he -> {
|
||||
if (he.action() == HoverEvent.Action.SHOW_ENTITY) {
|
||||
return SHOW_ENTITY_HOVER_EVENT_TYPE;
|
||||
} else if (he.action() == HoverEvent.Action.SHOW_ITEM) {
|
||||
return SHOW_ITEM_HOVER_EVENT_TYPE;
|
||||
} else if (he.action() == HoverEvent.Action.SHOW_TEXT) {
|
||||
return SHOW_TEXT_HOVER_EVENT_TYPE;
|
||||
} else {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
};
|
||||
static final Codec<HoverEvent<?>> HOVER_EVENT_CODEC = Codec.withAlternative(
|
||||
HOVER_EVENT_TYPE_CODEC.<HoverEvent<?>>dispatchMap("action", GET_HOVER_EVENT_TYPE, het -> het.codec.apply(COMPONENT_CODEC)).codec(),
|
||||
HOVER_EVENT_TYPE_CODEC.<HoverEvent<?>>dispatchMap("action", GET_HOVER_EVENT_TYPE, het -> het.legacyCodec.apply(COMPONENT_CODEC)).codec()
|
||||
);
|
||||
|
||||
public static final MapCodec<Style> STYLE_MAP_CODEC = mapCodec((instance) -> {
|
||||
return instance.group(
|
||||
TEXT_COLOR_CODEC.optionalFieldOf("color").forGetter(nullableGetter(Style::color)),
|
||||
Codec.BOOL.optionalFieldOf("bold").forGetter(decorationGetter(TextDecoration.BOLD)),
|
||||
Codec.BOOL.optionalFieldOf("italic").forGetter(decorationGetter(TextDecoration.ITALIC)),
|
||||
Codec.BOOL.optionalFieldOf("underlined").forGetter(decorationGetter(TextDecoration.UNDERLINED)),
|
||||
Codec.BOOL.optionalFieldOf("strikethrough").forGetter(decorationGetter(TextDecoration.STRIKETHROUGH)),
|
||||
Codec.BOOL.optionalFieldOf("obfuscated").forGetter(decorationGetter(TextDecoration.OBFUSCATED)),
|
||||
CLICK_EVENT_CODEC.optionalFieldOf("clickEvent").forGetter(nullableGetter(Style::clickEvent)),
|
||||
HOVER_EVENT_CODEC.optionalFieldOf("hoverEvent").forGetter(nullableGetter(Style::hoverEvent)),
|
||||
Codec.STRING.optionalFieldOf("insertion").forGetter(nullableGetter(Style::insertion)),
|
||||
KEY_CODEC.optionalFieldOf("font").forGetter(nullableGetter(Style::font))
|
||||
).apply(instance, (textColor, bold, italic, underlined, strikethrough, obfuscated, clickEvent, hoverEvent, insertion, font) -> {
|
||||
return Style.style(builder -> {
|
||||
textColor.ifPresent(builder::color);
|
||||
bold.ifPresent(styleBooleanConsumer(builder, TextDecoration.BOLD));
|
||||
italic.ifPresent(styleBooleanConsumer(builder, TextDecoration.ITALIC));
|
||||
underlined.ifPresent(styleBooleanConsumer(builder, TextDecoration.UNDERLINED));
|
||||
strikethrough.ifPresent(styleBooleanConsumer(builder, TextDecoration.STRIKETHROUGH));
|
||||
obfuscated.ifPresent(styleBooleanConsumer(builder, TextDecoration.OBFUSCATED));
|
||||
clickEvent.ifPresent(builder::clickEvent);
|
||||
hoverEvent.ifPresent(builder::hoverEvent);
|
||||
insertion.ifPresent(builder::insertion);
|
||||
font.ifPresent(builder::font);
|
||||
});
|
||||
});
|
||||
});
|
||||
static Consumer<Boolean> styleBooleanConsumer(final Style.Builder builder, final TextDecoration decoration) {
|
||||
return b -> builder.decoration(decoration, b);
|
||||
}
|
||||
|
||||
static Function<Style, Optional<Boolean>> decorationGetter(final TextDecoration decoration) {
|
||||
return style -> Optional.ofNullable(style.decoration(decoration) == TextDecoration.State.NOT_SET ? null : style.decoration(decoration) == TextDecoration.State.TRUE);
|
||||
}
|
||||
|
||||
static <R, T> Function<R, Optional<T>> nullableGetter(final Function<R, @Nullable T> getter) {
|
||||
return style -> Optional.ofNullable(getter.apply(style));
|
||||
}
|
||||
|
||||
static final MapCodec<TextComponent> TEXT_COMPONENT_MAP_CODEC = mapCodec((instance) -> {
|
||||
return instance.group(Codec.STRING.fieldOf("text").forGetter(TextComponent::content)).apply(instance, Component::text);
|
||||
});
|
||||
static final Codec<Object> PRIMITIVE_ARG_CODEC = ExtraCodecs.JAVA.validate(TranslatableContents::filterAllowedArguments);
|
||||
static final Codec<TranslationArgument> ARG_CODEC = Codec.either(PRIMITIVE_ARG_CODEC, COMPONENT_CODEC).flatXmap((primitiveOrComponent) -> {
|
||||
return primitiveOrComponent.map(o -> {
|
||||
final TranslationArgument arg;
|
||||
if (o instanceof String s) {
|
||||
arg = component(text(s));
|
||||
} else if (o instanceof Boolean bool) {
|
||||
arg = bool(bool);
|
||||
} else if (o instanceof Number num) {
|
||||
arg = numeric(num);
|
||||
} else {
|
||||
return DataResult.error(() -> o + " is not a valid translation argument primitive");
|
||||
}
|
||||
return DataResult.success(arg);
|
||||
}, component -> DataResult.success(component(component)));
|
||||
}, translationArgument -> {
|
||||
if (translationArgument.value() instanceof Number || translationArgument.value() instanceof Boolean) {
|
||||
return DataResult.success(Either.left(translationArgument.value()));
|
||||
}
|
||||
final Component component = translationArgument.asComponent();
|
||||
final @Nullable String collapsed = tryCollapseToString(component);
|
||||
if (collapsed != null) {
|
||||
return DataResult.success(Either.left(collapsed)); // attempt to collapse all text components to strings
|
||||
}
|
||||
return DataResult.success(Either.right(component));
|
||||
});
|
||||
static final MapCodec<TranslatableComponent> TRANSLATABLE_COMPONENT_MAP_CODEC = mapCodec((instance) -> {
|
||||
return instance.group(
|
||||
Codec.STRING.fieldOf("translate").forGetter(TranslatableComponent::key),
|
||||
Codec.STRING.lenientOptionalFieldOf("fallback").forGetter(nullableGetter(TranslatableComponent::fallback)),
|
||||
ARG_CODEC.listOf().optionalFieldOf("with").forGetter(c -> c.arguments().isEmpty() ? Optional.empty() : Optional.of(c.arguments()))
|
||||
).apply(instance, (key, fallback, components) -> {
|
||||
return Component.translatable(key, components.orElse(Collections.emptyList())).fallback(fallback.orElse(null));
|
||||
});
|
||||
});
|
||||
|
||||
static final MapCodec<KeybindComponent> KEYBIND_COMPONENT_MAP_CODEC = KeybindContents.CODEC.xmap(k -> Component.keybind(k.getName()), k -> new KeybindContents(k.keybind()));
|
||||
static final MapCodec<ScoreComponent> SCORE_COMPONENT_INNER_MAP_CODEC = ScoreContents.INNER_CODEC.xmap(
|
||||
s -> Component.score(s.name().map(SelectorPattern::pattern, Function.identity()), s.objective()),
|
||||
s -> new ScoreContents(SelectorPattern.parse(s.name()).<Either<SelectorPattern, String>>map(Either::left).result().orElse(Either.right(s.name())), s.objective())
|
||||
); // TODO we might want to ask adventure for a nice way we can avoid parsing and flattening the SelectorPattern on every conversion.
|
||||
static final MapCodec<ScoreComponent> SCORE_COMPONENT_MAP_CODEC = SCORE_COMPONENT_INNER_MAP_CODEC.fieldOf("score");
|
||||
static final MapCodec<SelectorComponent> SELECTOR_COMPONENT_MAP_CODEC = mapCodec((instance) -> {
|
||||
return instance.group(
|
||||
Codec.STRING.fieldOf("selector").forGetter(SelectorComponent::pattern),
|
||||
COMPONENT_CODEC.optionalFieldOf("separator").forGetter(nullableGetter(SelectorComponent::separator))
|
||||
).apply(instance, (selector, component) -> Component.selector(selector, component.orElse(null)));
|
||||
});
|
||||
|
||||
interface NbtComponentDataSource {
|
||||
NBTComponentBuilder<?, ?> builder();
|
||||
|
||||
DataSourceType<?> type();
|
||||
}
|
||||
|
||||
record StorageDataSource(Key storage) implements NbtComponentDataSource {
|
||||
@Override
|
||||
public NBTComponentBuilder<?, ?> builder() {
|
||||
return Component.storageNBT().storage(this.storage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSourceType<?> type() {
|
||||
return STORAGE_DATA_SOURCE_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
record BlockDataSource(String posPattern) implements NbtComponentDataSource {
|
||||
@Override
|
||||
public NBTComponentBuilder<?, ?> builder() {
|
||||
return Component.blockNBT().pos(BlockNBTComponent.Pos.fromString(this.posPattern));
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSourceType<?> type() {
|
||||
return BLOCK_DATA_SOURCE_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
record EntityDataSource(String selectorPattern) implements NbtComponentDataSource {
|
||||
@Override
|
||||
public NBTComponentBuilder<?, ?> builder() {
|
||||
return Component.entityNBT().selector(this.selectorPattern());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSourceType<?> type() {
|
||||
return ENTITY_DATA_SOURCE_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
static final DataSourceType<StorageDataSource> STORAGE_DATA_SOURCE_TYPE = new DataSourceType<>(mapCodec((instance) -> instance.group(KEY_CODEC.fieldOf("storage").forGetter(StorageDataSource::storage)).apply(instance, StorageDataSource::new)), "storage");
|
||||
static final DataSourceType<BlockDataSource> BLOCK_DATA_SOURCE_TYPE = new DataSourceType<>(mapCodec((instance) -> instance.group(Codec.STRING.fieldOf("block").forGetter(BlockDataSource::posPattern)).apply(instance, BlockDataSource::new)), "block");
|
||||
static final DataSourceType<EntityDataSource> ENTITY_DATA_SOURCE_TYPE = new DataSourceType<>(mapCodec((instance) -> instance.group(Codec.STRING.fieldOf("entity").forGetter(EntityDataSource::selectorPattern)).apply(instance, EntityDataSource::new)), "entity");
|
||||
|
||||
static final MapCodec<NbtComponentDataSource> NBT_COMPONENT_DATA_SOURCE_CODEC = ComponentSerialization.createLegacyComponentMatcher(new DataSourceType<?>[]{ENTITY_DATA_SOURCE_TYPE, BLOCK_DATA_SOURCE_TYPE, STORAGE_DATA_SOURCE_TYPE}, DataSourceType::codec, NbtComponentDataSource::type, "source");
|
||||
|
||||
record DataSourceType<D extends NbtComponentDataSource>(MapCodec<D> codec, String id) implements StringRepresentable {
|
||||
@Override
|
||||
public String getSerializedName() {
|
||||
return this.id();
|
||||
}
|
||||
}
|
||||
|
||||
static final MapCodec<NBTComponent<?, ?>> NBT_COMPONENT_MAP_CODEC = mapCodec((instance) -> {
|
||||
return instance.group(
|
||||
Codec.STRING.fieldOf("nbt").forGetter(NBTComponent::nbtPath),
|
||||
Codec.BOOL.lenientOptionalFieldOf("interpret", false).forGetter(NBTComponent::interpret),
|
||||
COMPONENT_CODEC.lenientOptionalFieldOf("separator").forGetter(nullableGetter(NBTComponent::separator)),
|
||||
NBT_COMPONENT_DATA_SOURCE_CODEC.forGetter(nbtComponent -> {
|
||||
if (nbtComponent instanceof final EntityNBTComponent entityNBTComponent) {
|
||||
return new EntityDataSource(entityNBTComponent.selector());
|
||||
} else if (nbtComponent instanceof final BlockNBTComponent blockNBTComponent) {
|
||||
return new BlockDataSource(blockNBTComponent.pos().asString());
|
||||
} else if (nbtComponent instanceof final StorageNBTComponent storageNBTComponent) {
|
||||
return new StorageDataSource(storageNBTComponent.storage());
|
||||
} else {
|
||||
throw new IllegalArgumentException(nbtComponent + " isn't a valid nbt component");
|
||||
}
|
||||
})
|
||||
).apply(instance, (nbtPath, interpret, separator, dataSource) -> {
|
||||
return dataSource.builder().nbtPath(nbtPath).interpret(interpret).separator(separator.orElse(null)).build();
|
||||
});
|
||||
});
|
||||
|
||||
@SuppressWarnings("NonExtendableApiUsage")
|
||||
record ComponentType<C extends Component>(MapCodec<C> codec, Predicate<Component> test, String id) implements StringRepresentable {
|
||||
@Override
|
||||
public String getSerializedName() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
|
||||
static final ComponentType<TextComponent> PLAIN = new ComponentType<>(TEXT_COMPONENT_MAP_CODEC, TextComponent.class::isInstance, "text");
|
||||
static final ComponentType<TranslatableComponent> TRANSLATABLE = new ComponentType<>(TRANSLATABLE_COMPONENT_MAP_CODEC, TranslatableComponent.class::isInstance, "translatable");
|
||||
static final ComponentType<KeybindComponent> KEYBIND = new ComponentType<>(KEYBIND_COMPONENT_MAP_CODEC, KeybindComponent.class::isInstance, "keybind");
|
||||
static final ComponentType<ScoreComponent> SCORE = new ComponentType<>(SCORE_COMPONENT_MAP_CODEC, ScoreComponent.class::isInstance, "score");
|
||||
static final ComponentType<SelectorComponent> SELECTOR = new ComponentType<>(SELECTOR_COMPONENT_MAP_CODEC, SelectorComponent.class::isInstance, "selector");
|
||||
static final ComponentType<NBTComponent<?, ?>> NBT = new ComponentType<>(NBT_COMPONENT_MAP_CODEC, NBTComponent.class::isInstance, "nbt");
|
||||
|
||||
static Codec<Component> createCodec(final Codec<Component> selfCodec) {
|
||||
final ComponentType<?>[] types = new ComponentType<?>[]{PLAIN, TRANSLATABLE, KEYBIND, SCORE, SELECTOR, NBT};
|
||||
final MapCodec<Component> legacyCodec = ComponentSerialization.createLegacyComponentMatcher(types, ComponentType::codec, component -> {
|
||||
for (final ComponentType<?> type : types) {
|
||||
if (type.test().test(component)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("Unexpected component type " + component);
|
||||
}, "type");
|
||||
|
||||
final Codec<Component> directCodec = RecordCodecBuilder.create((instance) -> {
|
||||
return instance.group(
|
||||
legacyCodec.forGetter(identity()),
|
||||
ExtraCodecs.nonEmptyList(selfCodec.listOf()).optionalFieldOf("extra", List.of()).forGetter(Component::children),
|
||||
STYLE_MAP_CODEC.forGetter(Component::style)
|
||||
).apply(instance, (component, children, style) -> {
|
||||
return component.style(style).children(children);
|
||||
});
|
||||
});
|
||||
|
||||
return Codec.either(Codec.either(Codec.STRING, ExtraCodecs.nonEmptyList(selfCodec.listOf())), directCodec).xmap((stringOrListOrComponent) -> {
|
||||
return stringOrListOrComponent.map((stringOrList) -> stringOrList.map(Component::text, AdventureCodecs::createFromList), identity());
|
||||
}, (text) -> {
|
||||
final @Nullable String string = tryCollapseToString(text);
|
||||
return string != null ? Either.left(Either.left(string)) : Either.right(text);
|
||||
});
|
||||
}
|
||||
|
||||
public static @Nullable String tryCollapseToString(final Component component) {
|
||||
if (component instanceof final TextComponent textComponent) {
|
||||
if (component.children().isEmpty() && component.style().isEmpty()) {
|
||||
return textComponent.content();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static Component createFromList(final List<? extends Component> components) {
|
||||
Component component = components.get(0);
|
||||
for (int i = 1; i < components.size(); i++) {
|
||||
component = component.append(components.get(i));
|
||||
}
|
||||
return component;
|
||||
}
|
||||
|
||||
private AdventureCodecs() {
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package io.papermc.paper.adventure;
|
||||
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import net.minecraft.network.chat.ComponentContents;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.network.chat.contents.PlainTextContents;
|
||||
import net.minecraft.util.FormattedCharSequence;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class AdventureComponent implements net.minecraft.network.chat.Component {
|
||||
final Component adventure;
|
||||
private net.minecraft.network.chat.@MonotonicNonNull Component vanilla;
|
||||
|
||||
public AdventureComponent(final Component adventure) {
|
||||
this.adventure = adventure;
|
||||
}
|
||||
|
||||
public net.minecraft.network.chat.Component deepConverted() {
|
||||
net.minecraft.network.chat.Component vanilla = this.vanilla;
|
||||
if (vanilla == null) {
|
||||
vanilla = PaperAdventure.WRAPPER_AWARE_SERIALIZER.serialize(this.adventure);
|
||||
this.vanilla = vanilla;
|
||||
}
|
||||
return vanilla;
|
||||
}
|
||||
|
||||
public net.minecraft.network.chat.@Nullable Component deepConvertedIfPresent() {
|
||||
return this.vanilla;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Style getStyle() {
|
||||
return this.deepConverted().getStyle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComponentContents getContents() {
|
||||
if (this.adventure instanceof TextComponent) {
|
||||
return PlainTextContents.create(((TextComponent) this.adventure).content());
|
||||
} else {
|
||||
return this.deepConverted().getContents();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString() {
|
||||
return PlainTextComponentSerializer.plainText().serialize(this.adventure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<net.minecraft.network.chat.Component> getSiblings() {
|
||||
return this.deepConverted().getSiblings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MutableComponent plainCopy() {
|
||||
return this.deepConverted().plainCopy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MutableComponent copy() {
|
||||
return this.deepConverted().copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormattedCharSequence getVisualOrderText() {
|
||||
return this.deepConverted().getVisualOrderText();
|
||||
}
|
||||
|
||||
public Component adventure$component() {
|
||||
return this.adventure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.deepConverted().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
return this.deepConverted().equals(obj);
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package io.papermc.paper.adventure;
|
||||
|
||||
import com.google.common.collect.Collections2;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import net.kyori.adventure.bossbar.BossBar;
|
||||
import net.kyori.adventure.bossbar.BossBarImplementation;
|
||||
import net.kyori.adventure.bossbar.BossBarViewer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.network.protocol.game.ClientboundBossEventPacket;
|
||||
import net.minecraft.server.level.ServerBossEvent;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.BossEvent;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public final class BossBarImplementationImpl implements BossBar.Listener, BossBarImplementation {
|
||||
private final BossBar bar;
|
||||
private ServerBossEvent vanilla;
|
||||
|
||||
public BossBarImplementationImpl(final BossBar bar) {
|
||||
this.bar = bar;
|
||||
}
|
||||
|
||||
public void playerShow(final CraftPlayer player) {
|
||||
if (this.vanilla == null) {
|
||||
this.vanilla = new ServerBossEvent(
|
||||
PaperAdventure.asVanilla(this.bar.name()),
|
||||
PaperAdventure.asVanilla(this.bar.color()),
|
||||
PaperAdventure.asVanilla(this.bar.overlay())
|
||||
);
|
||||
this.vanilla.adventure = this.bar;
|
||||
this.bar.addListener(this);
|
||||
}
|
||||
this.vanilla.addPlayer(player.getHandle());
|
||||
}
|
||||
|
||||
public void playerHide(final CraftPlayer player) {
|
||||
if (this.vanilla != null) {
|
||||
this.vanilla.removePlayer(player.getHandle());
|
||||
if (this.vanilla.getPlayers().isEmpty()) {
|
||||
this.bar.removeListener(this);
|
||||
this.vanilla = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bossBarNameChanged(final @NonNull BossBar bar, final @NonNull Component oldName, final @NonNull Component newName) {
|
||||
this.maybeBroadcast(ClientboundBossEventPacket::createUpdateNamePacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bossBarProgressChanged(final @NonNull BossBar bar, final float oldProgress, final float newProgress) {
|
||||
this.maybeBroadcast(ClientboundBossEventPacket::createUpdateProgressPacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bossBarColorChanged(final @NonNull BossBar bar, final BossBar.@NonNull Color oldColor, final BossBar.@NonNull Color newColor) {
|
||||
this.maybeBroadcast(ClientboundBossEventPacket::createUpdateStylePacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bossBarOverlayChanged(final @NonNull BossBar bar, final BossBar.@NonNull Overlay oldOverlay, final BossBar.@NonNull Overlay newOverlay) {
|
||||
this.maybeBroadcast(ClientboundBossEventPacket::createUpdateStylePacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bossBarFlagsChanged(final @NonNull BossBar bar, final @NonNull Set<BossBar.Flag> flagsAdded, final @NonNull Set<BossBar.Flag> flagsRemoved) {
|
||||
this.maybeBroadcast(ClientboundBossEventPacket::createUpdatePropertiesPacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Iterable<? extends BossBarViewer> viewers() {
|
||||
return this.vanilla == null ? Set.of() : Collections2.transform(this.vanilla.getPlayers(), ServerPlayer::getBukkitEntity);
|
||||
}
|
||||
|
||||
private void maybeBroadcast(final Function<BossEvent, ClientboundBossEventPacket> fn) {
|
||||
if (this.vanilla != null) {
|
||||
this.vanilla.broadcast(fn);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,376 @@
|
||||
package io.papermc.paper.adventure;
|
||||
|
||||
import io.papermc.paper.chat.ChatRenderer;
|
||||
import io.papermc.paper.event.player.AbstractChatEvent;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import io.papermc.paper.event.player.ChatEvent;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.BitSet;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.function.Function;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.minecraft.Optionull;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.network.chat.ChatType;
|
||||
import net.minecraft.network.chat.OutgoingChatMessage;
|
||||
import net.minecraft.network.chat.PlayerChatMessage;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.util.LazyPlayerSet;
|
||||
import org.bukkit.craftbukkit.util.Waitable;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerChatEvent;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.intellij.lang.annotations.Subst;
|
||||
|
||||
import static net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class ChatProcessor {
|
||||
static final ResourceKey<ChatType> PAPER_RAW = ResourceKey.create(Registries.CHAT_TYPE, ResourceLocation.fromNamespaceAndPath(ResourceLocation.PAPER_NAMESPACE, "raw"));
|
||||
static final String DEFAULT_LEGACY_FORMAT = "<%1$s> %2$s"; // copied from PlayerChatEvent/AsyncPlayerChatEvent
|
||||
final MinecraftServer server;
|
||||
final ServerPlayer player;
|
||||
final PlayerChatMessage message;
|
||||
final boolean async;
|
||||
final String craftbukkit$originalMessage;
|
||||
final Component paper$originalMessage;
|
||||
final OutgoingChatMessage outgoing;
|
||||
|
||||
static final int MESSAGE_CHANGED = 1;
|
||||
static final int FORMAT_CHANGED = 2;
|
||||
static final int SENDER_CHANGED = 3; // Not used
|
||||
private final BitSet flags = new BitSet(3);
|
||||
|
||||
public ChatProcessor(final MinecraftServer server, final ServerPlayer player, final PlayerChatMessage message, final boolean async) {
|
||||
this.server = server;
|
||||
this.player = player;
|
||||
this.message = message;
|
||||
this.async = async;
|
||||
this.craftbukkit$originalMessage = message.unsignedContent() != null ? LegacyComponentSerializer.legacySection().serialize(PaperAdventure.asAdventure(message.unsignedContent())) : message.signedContent();
|
||||
this.paper$originalMessage = PaperAdventure.asAdventure(this.message.decoratedContent());
|
||||
this.outgoing = OutgoingChatMessage.create(this.message);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecated")
|
||||
public void process() {
|
||||
final boolean listenersOnAsyncEvent = canYouHearMe(AsyncPlayerChatEvent.getHandlerList());
|
||||
final boolean listenersOnSyncEvent = canYouHearMe(PlayerChatEvent.getHandlerList());
|
||||
if (listenersOnAsyncEvent || listenersOnSyncEvent) {
|
||||
final CraftPlayer player = this.player.getBukkitEntity();
|
||||
final AsyncPlayerChatEvent ae = new AsyncPlayerChatEvent(this.async, player, this.craftbukkit$originalMessage, new LazyPlayerSet(this.server));
|
||||
this.post(ae);
|
||||
if (listenersOnSyncEvent) {
|
||||
final PlayerChatEvent se = new PlayerChatEvent(player, ae.getMessage(), ae.getFormat(), ae.getRecipients());
|
||||
se.setCancelled(ae.isCancelled()); // propagate cancelled state
|
||||
this.queueIfAsyncOrRunImmediately(new Waitable<Void>() {
|
||||
@Override
|
||||
protected Void evaluate() {
|
||||
ChatProcessor.this.post(se);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
this.readLegacyModifications(se.getMessage(), se.getFormat(), se.getPlayer());
|
||||
this.processModern(
|
||||
this.modernRenderer(se.getFormat()),
|
||||
this.viewersFromLegacy(se.getRecipients()),
|
||||
this.modernMessage(se.getMessage()),
|
||||
se.getPlayer(),
|
||||
se.isCancelled()
|
||||
);
|
||||
} else {
|
||||
this.readLegacyModifications(ae.getMessage(), ae.getFormat(), ae.getPlayer());
|
||||
this.processModern(
|
||||
this.modernRenderer(ae.getFormat()),
|
||||
this.viewersFromLegacy(ae.getRecipients()),
|
||||
this.modernMessage(ae.getMessage()),
|
||||
ae.getPlayer(),
|
||||
ae.isCancelled()
|
||||
);
|
||||
}
|
||||
} else {
|
||||
this.processModern(
|
||||
defaultRenderer(),
|
||||
new LazyChatAudienceSet(this.server),
|
||||
this.paper$originalMessage,
|
||||
this.player.getBukkitEntity(),
|
||||
false
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private ChatRenderer modernRenderer(final String format) {
|
||||
if (this.flags.get(FORMAT_CHANGED)) {
|
||||
return legacyRenderer(format);
|
||||
} else {
|
||||
return defaultRenderer();
|
||||
}
|
||||
}
|
||||
|
||||
private Component modernMessage(final String legacyMessage) {
|
||||
if (this.flags.get(MESSAGE_CHANGED)) {
|
||||
return legacySection().deserialize(legacyMessage);
|
||||
} else {
|
||||
return this.paper$originalMessage;
|
||||
}
|
||||
}
|
||||
|
||||
private void readLegacyModifications(final String message, final String format, final Player playerSender) {
|
||||
this.flags.set(MESSAGE_CHANGED, !message.equals(this.craftbukkit$originalMessage));
|
||||
this.flags.set(FORMAT_CHANGED, !format.equals(DEFAULT_LEGACY_FORMAT));
|
||||
this.flags.set(SENDER_CHANGED, playerSender != this.player.getBukkitEntity());
|
||||
}
|
||||
|
||||
private void processModern(final ChatRenderer renderer, final Set<Audience> viewers, final Component message, final Player player, final boolean cancelled) {
|
||||
final PlayerChatMessage.AdventureView signedMessage = this.message.adventureView();
|
||||
final AsyncChatEvent ae = new AsyncChatEvent(this.async, player, viewers, renderer, message, this.paper$originalMessage, signedMessage);
|
||||
ae.setCancelled(cancelled); // propagate cancelled state
|
||||
this.post(ae);
|
||||
final boolean listenersOnSyncEvent = canYouHearMe(ChatEvent.getHandlerList());
|
||||
if (listenersOnSyncEvent) {
|
||||
this.queueIfAsyncOrRunImmediately(new Waitable<Void>() {
|
||||
@Override
|
||||
protected Void evaluate() {
|
||||
final ChatEvent se = new ChatEvent(player, ae.viewers(), ae.renderer(), ae.message(), ChatProcessor.this.paper$originalMessage/*, ae.usePreviewComponent()*/, signedMessage);
|
||||
se.setCancelled(ae.isCancelled()); // propagate cancelled state
|
||||
ChatProcessor.this.post(se);
|
||||
ChatProcessor.this.readModernModifications(se, renderer);
|
||||
ChatProcessor.this.complete(se);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.readModernModifications(ae, renderer);
|
||||
this.complete(ae);
|
||||
}
|
||||
}
|
||||
|
||||
private void readModernModifications(final AbstractChatEvent chatEvent, final ChatRenderer originalRenderer) {
|
||||
this.flags.set(MESSAGE_CHANGED, !chatEvent.message().equals(this.paper$originalMessage));
|
||||
if (originalRenderer != chatEvent.renderer()) { // don't set to false if it hasn't changed
|
||||
this.flags.set(FORMAT_CHANGED, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void complete(final AbstractChatEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final CraftPlayer player = ((CraftPlayer) event.getPlayer());
|
||||
final Component displayName = displayName(player);
|
||||
final Component message = event.message();
|
||||
final ChatRenderer renderer = event.renderer();
|
||||
|
||||
final Set<Audience> viewers = event.viewers();
|
||||
final ResourceKey<ChatType> chatTypeKey = renderer instanceof ChatRenderer.Default ? ChatType.CHAT : PAPER_RAW;
|
||||
final ChatType.Bound chatType = ChatType.bind(chatTypeKey, this.player.level().registryAccess(), PaperAdventure.asVanilla(displayName(player)));
|
||||
|
||||
OutgoingChat outgoingChat = viewers instanceof LazyChatAudienceSet lazyAudienceSet && lazyAudienceSet.isLazy() ? new ServerOutgoingChat() : new ViewersOutgoingChat();
|
||||
if (this.flags.get(FORMAT_CHANGED)) {
|
||||
if (renderer instanceof ChatRenderer.ViewerUnaware unaware) {
|
||||
outgoingChat.sendFormatChangedViewerUnaware(player, PaperAdventure.asVanilla(unaware.render(player, displayName, message)), viewers, chatType);
|
||||
} else {
|
||||
outgoingChat.sendFormatChangedViewerAware(player, displayName, message, renderer, viewers, chatType);
|
||||
}
|
||||
} else if (this.flags.get(MESSAGE_CHANGED)) {
|
||||
if (!(renderer instanceof ChatRenderer.ViewerUnaware unaware)) {
|
||||
throw new IllegalStateException("BUG: This should be a ViewerUnaware renderer at this point");
|
||||
}
|
||||
final Component renderedComponent = chatTypeKey == ChatType.CHAT ? message : unaware.render(player, displayName, message);
|
||||
outgoingChat.sendMessageChanged(player, PaperAdventure.asVanilla(renderedComponent), viewers, chatType);
|
||||
} else {
|
||||
outgoingChat.sendOriginal(player, viewers, chatType);
|
||||
}
|
||||
}
|
||||
|
||||
interface OutgoingChat {
|
||||
default void sendFormatChangedViewerUnaware(CraftPlayer player, net.minecraft.network.chat.Component renderedMessage, Set<Audience> viewers, ChatType.Bound chatType) {
|
||||
this.sendMessageChanged(player, renderedMessage, viewers, chatType);
|
||||
}
|
||||
|
||||
void sendFormatChangedViewerAware(CraftPlayer player, Component displayName, Component message, ChatRenderer renderer, Set<Audience> viewers, ChatType.Bound chatType);
|
||||
|
||||
void sendMessageChanged(CraftPlayer player, net.minecraft.network.chat.Component renderedMessage, Set<Audience> viewers, ChatType.Bound chatType);
|
||||
|
||||
void sendOriginal(CraftPlayer player, Set<Audience> viewers, ChatType.Bound chatType);
|
||||
}
|
||||
|
||||
final class ServerOutgoingChat implements OutgoingChat {
|
||||
@Override
|
||||
public void sendFormatChangedViewerAware(CraftPlayer player, Component displayName, Component message, ChatRenderer renderer, Set<Audience> viewers, ChatType.Bound chatType) {
|
||||
ChatProcessor.this.server.getPlayerList().broadcastChatMessage(ChatProcessor.this.message, ChatProcessor.this.player, chatType, viewer -> PaperAdventure.asVanilla(renderer.render(player, displayName, message, viewer)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessageChanged(CraftPlayer player, net.minecraft.network.chat.Component renderedMessage, Set<Audience> viewers, ChatType.Bound chatType) {
|
||||
ChatProcessor.this.server.getPlayerList().broadcastChatMessage(ChatProcessor.this.message.withUnsignedContent(renderedMessage), ChatProcessor.this.player, chatType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendOriginal(CraftPlayer player, Set<Audience> viewers, ChatType.Bound chatType) {
|
||||
ChatProcessor.this.server.getPlayerList().broadcastChatMessage(ChatProcessor.this.message, ChatProcessor.this.player, chatType);
|
||||
}
|
||||
}
|
||||
|
||||
final class ViewersOutgoingChat implements OutgoingChat {
|
||||
@Override
|
||||
public void sendFormatChangedViewerAware(CraftPlayer player, Component displayName, Component message, ChatRenderer renderer, Set<Audience> viewers, ChatType.Bound chatType) {
|
||||
this.broadcastToViewers(viewers, chatType, v -> PaperAdventure.asVanilla(renderer.render(player, displayName, message, v)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessageChanged(CraftPlayer player, net.minecraft.network.chat.Component renderedMessage, Set<Audience> viewers, ChatType.Bound chatType) {
|
||||
this.broadcastToViewers(viewers, chatType, $ -> renderedMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendOriginal(CraftPlayer player, Set<Audience> viewers, ChatType.Bound chatType) {
|
||||
this.broadcastToViewers(viewers, chatType, null);
|
||||
}
|
||||
|
||||
private void broadcastToViewers(Collection<Audience> viewers, final ChatType.Bound chatType, final @Nullable Function<Audience, net.minecraft.network.chat.Component> msgFunction) {
|
||||
for (Audience viewer : viewers) {
|
||||
if (acceptsNative(viewer)) {
|
||||
this.sendNative(viewer, chatType, msgFunction);
|
||||
} else {
|
||||
final net.minecraft.network.chat.@Nullable Component unsigned = Optionull.map(msgFunction, f -> f.apply(viewer));
|
||||
final PlayerChatMessage msg = unsigned == null ? ChatProcessor.this.message : ChatProcessor.this.message.withUnsignedContent(unsigned);
|
||||
viewer.sendMessage(msg.adventureView(), this.adventure(chatType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final Map<String, net.kyori.adventure.chat.ChatType> BUILT_IN_CHAT_TYPES = Util.make(() -> {
|
||||
final Map<String, net.kyori.adventure.chat.ChatType> map = new HashMap<>();
|
||||
for (final Field declaredField : net.kyori.adventure.chat.ChatType.class.getDeclaredFields()) {
|
||||
if (Modifier.isStatic(declaredField.getModifiers()) && declaredField.getType().equals(ChatType.class)) {
|
||||
try {
|
||||
final net.kyori.adventure.chat.ChatType type = (net.kyori.adventure.chat.ChatType) declaredField.get(null);
|
||||
map.put(type.key().asString(), type);
|
||||
} catch (final ReflectiveOperationException ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
});
|
||||
|
||||
private net.kyori.adventure.chat.ChatType.Bound adventure(ChatType.Bound chatType) {
|
||||
@Subst("key:value") final String stringKey = Objects.requireNonNull(
|
||||
chatType.chatType().unwrapKey().orElseThrow().location(),
|
||||
() -> "No key for '%s' in CHAT_TYPE registry.".formatted(chatType)
|
||||
).toString();
|
||||
net.kyori.adventure.chat.@Nullable ChatType adventure = BUILT_IN_CHAT_TYPES.get(stringKey);
|
||||
if (adventure == null) {
|
||||
adventure = net.kyori.adventure.chat.ChatType.chatType(Key.key(stringKey));
|
||||
}
|
||||
return adventure.bind(
|
||||
PaperAdventure.asAdventure(chatType.name()),
|
||||
chatType.targetName().map(PaperAdventure::asAdventure).orElse(null)
|
||||
);
|
||||
}
|
||||
|
||||
private static boolean acceptsNative(final Audience viewer) {
|
||||
if (viewer instanceof Player || viewer instanceof ConsoleCommandSender) {
|
||||
return true;
|
||||
}
|
||||
if (viewer instanceof ForwardingAudience.Single single) {
|
||||
return acceptsNative(single.audience());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void sendNative(final Audience viewer, final ChatType.Bound chatType, final @Nullable Function<Audience, net.minecraft.network.chat.Component> msgFunction) {
|
||||
if (viewer instanceof ConsoleCommandSender) {
|
||||
this.sendToServer(chatType, msgFunction);
|
||||
} else if (viewer instanceof CraftPlayer craftPlayer) {
|
||||
craftPlayer.getHandle().sendChatMessage(ChatProcessor.this.outgoing, ChatProcessor.this.player.shouldFilterMessageTo(craftPlayer.getHandle()), chatType, Optionull.map(msgFunction, f -> f.apply(viewer)));
|
||||
} else if (viewer instanceof ForwardingAudience.Single single) {
|
||||
this.sendNative(single.audience(), chatType, msgFunction);
|
||||
} else {
|
||||
throw new IllegalStateException("Should only be a Player or Console or ForwardingAudience.Single pointing to one!");
|
||||
}
|
||||
}
|
||||
|
||||
private void sendToServer(final ChatType.Bound chatType, final @Nullable Function<Audience, net.minecraft.network.chat.Component> msgFunction) {
|
||||
final PlayerChatMessage toConsoleMessage = msgFunction == null ? ChatProcessor.this.message : ChatProcessor.this.message.withUnsignedContent(msgFunction.apply(ChatProcessor.this.server.console));
|
||||
ChatProcessor.this.server.logChatMessage(toConsoleMessage.decoratedContent(), chatType, ChatProcessor.this.server.getPlayerList().verifyChatTrusted(toConsoleMessage) ? null : "Not Secure");
|
||||
}
|
||||
}
|
||||
|
||||
private Set<Audience> viewersFromLegacy(final Set<Player> recipients) {
|
||||
if (recipients instanceof LazyPlayerSet lazyPlayerSet && lazyPlayerSet.isLazy()) {
|
||||
return new LazyChatAudienceSet(this.server);
|
||||
}
|
||||
final HashSet<Audience> viewers = new HashSet<>(recipients);
|
||||
viewers.add(this.server.console);
|
||||
return viewers;
|
||||
}
|
||||
|
||||
static String legacyDisplayName(final CraftPlayer player) {
|
||||
return player.getDisplayName();
|
||||
}
|
||||
|
||||
static Component displayName(final CraftPlayer player) {
|
||||
return player.displayName();
|
||||
}
|
||||
|
||||
private static ChatRenderer.Default defaultRenderer() {
|
||||
return (ChatRenderer.Default) ChatRenderer.defaultRenderer();
|
||||
}
|
||||
|
||||
private static ChatRenderer legacyRenderer(final String format) {
|
||||
if (DEFAULT_LEGACY_FORMAT.equals(format)) {
|
||||
return defaultRenderer();
|
||||
}
|
||||
return ChatRenderer.viewerUnaware((player, sourceDisplayName, message) -> legacySection().deserialize(legacyFormat(format, player, legacySection().serialize(message))));
|
||||
}
|
||||
|
||||
static String legacyFormat(final String format, Player player, String message) {
|
||||
return String.format(format, legacyDisplayName((CraftPlayer) player), message);
|
||||
}
|
||||
|
||||
private void queueIfAsyncOrRunImmediately(final Waitable<Void> waitable) {
|
||||
if (this.async) {
|
||||
this.server.processQueue.add(waitable);
|
||||
} else {
|
||||
waitable.run();
|
||||
}
|
||||
try {
|
||||
waitable.get();
|
||||
} catch (final InterruptedException e) {
|
||||
Thread.currentThread().interrupt(); // tag, you're it
|
||||
} catch (final ExecutionException e) {
|
||||
throw new RuntimeException("Exception processing chat", e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
private void post(final Event event) {
|
||||
this.server.server.getPluginManager().callEvent(event);
|
||||
}
|
||||
|
||||
static boolean canYouHearMe(final HandlerList handlers) {
|
||||
return handlers.getRegisteredListeners().length > 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package io.papermc.paper.adventure;
|
||||
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
|
||||
public final class DisplayNames {
|
||||
private DisplayNames() {
|
||||
}
|
||||
|
||||
public static String getLegacy(final CraftPlayer player) {
|
||||
return getLegacy(player.getHandle());
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation") // Valid suppress due to supporting legacy display name formatting
|
||||
public static String getLegacy(final ServerPlayer player) {
|
||||
final String legacy = player.displayName;
|
||||
if (legacy != null) {
|
||||
// thank you for being worse than wet socks, Bukkit
|
||||
return LegacyComponentSerializer.legacySection().serialize(player.adventure$displayName) + ChatColor.getLastColors(player.displayName);
|
||||
}
|
||||
return LegacyComponentSerializer.legacySection().serialize(player.adventure$displayName);
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package io.papermc.paper.adventure;
|
||||
|
||||
import io.papermc.paper.event.player.AsyncChatCommandDecorateEvent;
|
||||
import io.papermc.paper.event.player.AsyncChatDecorateEvent;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.chat.ChatDecorator;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class ImprovedChatDecorator implements ChatDecorator {
|
||||
private final MinecraftServer server;
|
||||
|
||||
public ImprovedChatDecorator(final MinecraftServer server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Component> decorate(final @Nullable ServerPlayer sender, final Component message) {
|
||||
return decorate(this.server, sender, null, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Component> decorate(final @Nullable ServerPlayer sender, final @Nullable CommandSourceStack commandSourceStack, final Component message) {
|
||||
return decorate(this.server, sender, commandSourceStack, message);
|
||||
}
|
||||
|
||||
private static CompletableFuture<Component> decorate(final MinecraftServer server, final @Nullable ServerPlayer player, final @Nullable CommandSourceStack commandSourceStack, final Component originalMessage) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
final net.kyori.adventure.text.Component initialResult = PaperAdventure.asAdventure(originalMessage);
|
||||
|
||||
final @Nullable CraftPlayer craftPlayer = player == null ? null : player.getBukkitEntity();
|
||||
|
||||
final AsyncChatDecorateEvent event;
|
||||
if (commandSourceStack != null) {
|
||||
// TODO more command decorate context
|
||||
event = new AsyncChatCommandDecorateEvent(craftPlayer, initialResult);
|
||||
} else {
|
||||
event = new AsyncChatDecorateEvent(craftPlayer, initialResult);
|
||||
}
|
||||
|
||||
if (event.callEvent()) {
|
||||
return PaperAdventure.asVanilla(event.result());
|
||||
}
|
||||
|
||||
return originalMessage;
|
||||
}, server.chatExecutor);
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package io.papermc.paper.adventure;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.util.LazyHashSet;
|
||||
import org.bukkit.craftbukkit.util.LazyPlayerSet;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
final class LazyChatAudienceSet extends LazyHashSet<Audience> {
|
||||
private final MinecraftServer server;
|
||||
|
||||
public LazyChatAudienceSet(final MinecraftServer server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<Audience> makeReference() {
|
||||
final Set<Player> playerSet = LazyPlayerSet.makePlayerSet(this.server);
|
||||
final HashSet<Audience> audiences = new HashSet<>(playerSet);
|
||||
audiences.add(Bukkit.getConsoleSender());
|
||||
return audiences;
|
||||
}
|
||||
}
|
@ -0,0 +1,505 @@
|
||||
package io.papermc.paper.adventure;
|
||||
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.serialization.JavaOps;
|
||||
import io.netty.util.AttributeKey;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.StreamSupport;
|
||||
import net.kyori.adventure.bossbar.BossBar;
|
||||
import net.kyori.adventure.inventory.Book;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.nbt.api.BinaryTagHolder;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
import net.kyori.adventure.text.TranslationArgument;
|
||||
import net.kyori.adventure.text.event.DataComponentValue;
|
||||
import net.kyori.adventure.text.event.DataComponentValueConverterRegistry;
|
||||
import net.kyori.adventure.text.flattener.ComponentFlattener;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.serializer.ComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import net.kyori.adventure.translation.GlobalTranslator;
|
||||
import net.kyori.adventure.translation.TranslationRegistry;
|
||||
import net.kyori.adventure.translation.Translator;
|
||||
import net.kyori.adventure.util.Codec;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.component.DataComponentPatch;
|
||||
import net.minecraft.core.component.DataComponentType;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.locale.Language;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.TagParser;
|
||||
import net.minecraft.network.chat.ComponentUtils;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.game.ClientboundSoundEntityPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSoundPacket;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.network.Filterable;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.BossEvent;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.component.WrittenBookContent;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
import org.bukkit.craftbukkit.command.VanillaCommandWrapper;
|
||||
import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||
import org.intellij.lang.annotations.Subst;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
public final class PaperAdventure {
|
||||
private static final Pattern LOCALIZATION_PATTERN = Pattern.compile("%(?:(\\d+)\\$)?s");
|
||||
public static final ComponentFlattener FLATTENER = ComponentFlattener.basic().toBuilder()
|
||||
.complexMapper(TranslatableComponent.class, (translatable, consumer) -> {
|
||||
if (!Language.getInstance().has(translatable.key())) {
|
||||
for (final Translator source : GlobalTranslator.translator().sources()) {
|
||||
if (source instanceof TranslationRegistry registry && registry.contains(translatable.key())) {
|
||||
consumer.accept(GlobalTranslator.render(translatable, Locale.US));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
final @Nullable String fallback = translatable.fallback();
|
||||
final @NotNull String translated = Language.getInstance().getOrDefault(translatable.key(), fallback != null ? fallback : translatable.key());
|
||||
|
||||
final Matcher matcher = LOCALIZATION_PATTERN.matcher(translated);
|
||||
final List<TranslationArgument> args = translatable.arguments();
|
||||
int argPosition = 0;
|
||||
int lastIdx = 0;
|
||||
while (matcher.find()) {
|
||||
// append prior
|
||||
if (lastIdx < matcher.start()) {
|
||||
consumer.accept(Component.text(translated.substring(lastIdx, matcher.start())));
|
||||
}
|
||||
lastIdx = matcher.end();
|
||||
|
||||
final @Nullable String argIdx = matcher.group(1);
|
||||
// calculate argument position
|
||||
if (argIdx != null) {
|
||||
try {
|
||||
final int idx = Integer.parseInt(argIdx) - 1;
|
||||
if (idx < args.size()) {
|
||||
consumer.accept(args.get(idx).asComponent());
|
||||
}
|
||||
} catch (final NumberFormatException ex) {
|
||||
// ignore, drop the format placeholder
|
||||
}
|
||||
} else {
|
||||
final int idx = argPosition++;
|
||||
if (idx < args.size()) {
|
||||
consumer.accept(args.get(idx).asComponent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// append tail
|
||||
if (lastIdx < translated.length()) {
|
||||
consumer.accept(Component.text(translated.substring(lastIdx)));
|
||||
}
|
||||
})
|
||||
.build();
|
||||
public static final AttributeKey<Locale> LOCALE_ATTRIBUTE = AttributeKey.valueOf("adventure:locale"); // init after FLATTENER because classloading triggered here might create a logger
|
||||
@Deprecated
|
||||
public static final PlainComponentSerializer PLAIN = PlainComponentSerializer.builder().flattener(FLATTENER).build();
|
||||
public static final Codec<Tag, String, CommandSyntaxException, RuntimeException> NBT_CODEC = new Codec<>() {
|
||||
@Override
|
||||
public @NotNull Tag decode(final @NotNull String encoded) throws CommandSyntaxException {
|
||||
return new TagParser(new StringReader(encoded)).readValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String encode(final @NotNull Tag decoded) {
|
||||
return decoded.toString();
|
||||
}
|
||||
};
|
||||
public static final ComponentSerializer<Component, Component, net.minecraft.network.chat.Component> WRAPPER_AWARE_SERIALIZER = new WrapperAwareSerializer(() -> CraftRegistry.getMinecraftRegistry().createSerializationContext(JavaOps.INSTANCE));
|
||||
|
||||
private PaperAdventure() {
|
||||
}
|
||||
|
||||
// Key
|
||||
|
||||
public static Key asAdventure(final ResourceLocation key) {
|
||||
return Key.key(key.getNamespace(), key.getPath());
|
||||
}
|
||||
|
||||
public static ResourceLocation asVanilla(final Key key) {
|
||||
return ResourceLocation.fromNamespaceAndPath(key.namespace(), key.value());
|
||||
}
|
||||
|
||||
public static <T> ResourceKey<T> asVanilla(
|
||||
final ResourceKey<? extends net.minecraft.core.Registry<T>> registry,
|
||||
final Key key
|
||||
) {
|
||||
return ResourceKey.create(registry, asVanilla(key));
|
||||
}
|
||||
|
||||
public static Key asAdventureKey(final ResourceKey<?> key) {
|
||||
return asAdventure(key.location());
|
||||
}
|
||||
|
||||
public static @Nullable ResourceLocation asVanillaNullable(final Key key) {
|
||||
if (key == null) {
|
||||
return null;
|
||||
}
|
||||
return asVanilla(key);
|
||||
}
|
||||
|
||||
public static Holder<SoundEvent> resolveSound(final Key key) {
|
||||
ResourceLocation id = asVanilla(key);
|
||||
Optional<Holder.Reference<SoundEvent>> vanilla = BuiltInRegistries.SOUND_EVENT.get(id);
|
||||
if (vanilla.isPresent()) {
|
||||
return vanilla.get();
|
||||
}
|
||||
|
||||
// sound is not known so not in the registry but might be used by the client with a resource pack
|
||||
return Holder.direct(SoundEvent.createVariableRangeEvent(id));
|
||||
}
|
||||
|
||||
// Component
|
||||
|
||||
public static @NotNull Component asAdventure(@Nullable final net.minecraft.network.chat.Component component) {
|
||||
return component == null ? Component.empty() : WRAPPER_AWARE_SERIALIZER.deserialize(component);
|
||||
}
|
||||
|
||||
public static ArrayList<Component> asAdventure(final List<? extends net.minecraft.network.chat.Component> vanillas) {
|
||||
final ArrayList<Component> adventures = new ArrayList<>(vanillas.size());
|
||||
for (final net.minecraft.network.chat.Component vanilla : vanillas) {
|
||||
adventures.add(asAdventure(vanilla));
|
||||
}
|
||||
return adventures;
|
||||
}
|
||||
|
||||
public static ArrayList<Component> asAdventureFromJson(final List<String> jsonStrings) {
|
||||
final ArrayList<Component> adventures = new ArrayList<>(jsonStrings.size());
|
||||
for (final String json : jsonStrings) {
|
||||
adventures.add(GsonComponentSerializer.gson().deserialize(json));
|
||||
}
|
||||
return adventures;
|
||||
}
|
||||
|
||||
public static List<String> asJson(final List<? extends Component> adventures) {
|
||||
final List<String> jsons = new ArrayList<>(adventures.size());
|
||||
for (final Component component : adventures) {
|
||||
jsons.add(GsonComponentSerializer.gson().serialize(component));
|
||||
}
|
||||
return jsons;
|
||||
}
|
||||
|
||||
public static net.minecraft.network.chat.@NotNull Component asVanillaNullToEmpty(final @Nullable Component component) {
|
||||
if (component == null) return net.minecraft.network.chat.CommonComponents.EMPTY;
|
||||
return asVanilla(component);
|
||||
}
|
||||
|
||||
@Contract("null -> null; !null -> !null")
|
||||
public static net.minecraft.network.chat.Component asVanilla(final @Nullable Component component) {
|
||||
if (component == null) return null;
|
||||
if (true) return new AdventureComponent(component);
|
||||
return WRAPPER_AWARE_SERIALIZER.serialize(component);
|
||||
}
|
||||
|
||||
public static List<net.minecraft.network.chat.Component> asVanilla(final List<? extends Component> adventures) {
|
||||
final List<net.minecraft.network.chat.Component> vanillas = new ArrayList<>(adventures.size());
|
||||
for (final Component adventure : adventures) {
|
||||
vanillas.add(asVanilla(adventure));
|
||||
}
|
||||
return vanillas;
|
||||
}
|
||||
|
||||
public static String asJsonString(final Component component, final Locale locale) {
|
||||
return GsonComponentSerializer.gson().serialize(translated(component, locale));
|
||||
}
|
||||
|
||||
public static boolean hasAnyTranslations() {
|
||||
return StreamSupport.stream(GlobalTranslator.translator().sources().spliterator(), false)
|
||||
.anyMatch(t -> t.hasAnyTranslations().toBooleanOrElse(true));
|
||||
}
|
||||
|
||||
private static final Map<Locale, com.mojang.serialization.Codec<Component>> LOCALIZED_CODECS = new ConcurrentHashMap<>();
|
||||
|
||||
public static com.mojang.serialization.Codec<Component> localizedCodec(final @Nullable Locale l) {
|
||||
if (l == null) {
|
||||
return AdventureCodecs.COMPONENT_CODEC;
|
||||
}
|
||||
return LOCALIZED_CODECS.computeIfAbsent(l, locale -> AdventureCodecs.COMPONENT_CODEC.xmap(
|
||||
component -> component, // decode
|
||||
component -> translated(component, locale) // encode
|
||||
));
|
||||
}
|
||||
|
||||
public static String asPlain(final Component component, final Locale locale) {
|
||||
return PlainTextComponentSerializer.plainText().serialize(translated(component, locale));
|
||||
}
|
||||
|
||||
private static Component translated(final Component component, final Locale locale) {
|
||||
//noinspection ConstantValue
|
||||
return GlobalTranslator.render(
|
||||
component,
|
||||
// play it safe
|
||||
locale != null
|
||||
? locale
|
||||
: Locale.US
|
||||
);
|
||||
}
|
||||
|
||||
public static Component resolveWithContext(final @NotNull Component component, final @Nullable CommandSender context, final @Nullable org.bukkit.entity.Entity scoreboardSubject, final boolean bypassPermissions) throws IOException {
|
||||
final CommandSourceStack css = context != null ? VanillaCommandWrapper.getListener(context) : null;
|
||||
Boolean previous = null;
|
||||
if (css != null && bypassPermissions) {
|
||||
previous = css.bypassSelectorPermissions;
|
||||
css.bypassSelectorPermissions = true;
|
||||
}
|
||||
try {
|
||||
return asAdventure(ComponentUtils.updateForEntity(css, asVanilla(component), scoreboardSubject == null ? null : ((CraftEntity) scoreboardSubject).getHandle(), 0));
|
||||
} catch (final CommandSyntaxException e) {
|
||||
throw new IOException(e);
|
||||
} finally {
|
||||
if (css != null && previous != null) {
|
||||
css.bypassSelectorPermissions = previous;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// BossBar
|
||||
|
||||
public static BossEvent.BossBarColor asVanilla(final BossBar.Color color) {
|
||||
return switch (color) {
|
||||
case PINK -> BossEvent.BossBarColor.PINK;
|
||||
case BLUE -> BossEvent.BossBarColor.BLUE;
|
||||
case RED -> BossEvent.BossBarColor.RED;
|
||||
case GREEN -> BossEvent.BossBarColor.GREEN;
|
||||
case YELLOW -> BossEvent.BossBarColor.YELLOW;
|
||||
case PURPLE -> BossEvent.BossBarColor.PURPLE;
|
||||
case WHITE -> BossEvent.BossBarColor.WHITE;
|
||||
};
|
||||
}
|
||||
|
||||
public static BossBar.Color asAdventure(final BossEvent.BossBarColor color) {
|
||||
return switch (color) {
|
||||
case PINK -> BossBar.Color.PINK;
|
||||
case BLUE -> BossBar.Color.BLUE;
|
||||
case RED -> BossBar.Color.RED;
|
||||
case GREEN -> BossBar.Color.GREEN;
|
||||
case YELLOW -> BossBar.Color.YELLOW;
|
||||
case PURPLE -> BossBar.Color.PURPLE;
|
||||
case WHITE -> BossBar.Color.WHITE;
|
||||
};
|
||||
}
|
||||
|
||||
public static BossEvent.BossBarOverlay asVanilla(final BossBar.Overlay overlay) {
|
||||
return switch (overlay) {
|
||||
case PROGRESS -> BossEvent.BossBarOverlay.PROGRESS;
|
||||
case NOTCHED_6 -> BossEvent.BossBarOverlay.NOTCHED_6;
|
||||
case NOTCHED_10 -> BossEvent.BossBarOverlay.NOTCHED_10;
|
||||
case NOTCHED_12 -> BossEvent.BossBarOverlay.NOTCHED_12;
|
||||
case NOTCHED_20 -> BossEvent.BossBarOverlay.NOTCHED_20;
|
||||
};
|
||||
}
|
||||
|
||||
public static BossBar.Overlay asAdventure(final BossEvent.BossBarOverlay overlay) {
|
||||
return switch (overlay) {
|
||||
case PROGRESS -> BossBar.Overlay.PROGRESS;
|
||||
case NOTCHED_6 -> BossBar.Overlay.NOTCHED_6;
|
||||
case NOTCHED_10 -> BossBar.Overlay.NOTCHED_10;
|
||||
case NOTCHED_12 -> BossBar.Overlay.NOTCHED_12;
|
||||
case NOTCHED_20 -> BossBar.Overlay.NOTCHED_20;
|
||||
};
|
||||
}
|
||||
|
||||
public static void setFlag(final BossBar bar, final BossBar.Flag flag, final boolean value) {
|
||||
if (value) {
|
||||
bar.addFlag(flag);
|
||||
} else {
|
||||
bar.removeFlag(flag);
|
||||
}
|
||||
}
|
||||
|
||||
// Book
|
||||
|
||||
public static ItemStack asItemStack(final Book book, final Locale locale) {
|
||||
final ItemStack item = new ItemStack(net.minecraft.world.item.Items.WRITTEN_BOOK, 1);
|
||||
item.set(DataComponents.WRITTEN_BOOK_CONTENT, new WrittenBookContent(
|
||||
Filterable.passThrough(validateField(asPlain(book.title(), locale), WrittenBookContent.TITLE_MAX_LENGTH, "title")),
|
||||
asPlain(book.author(), locale),
|
||||
0,
|
||||
book.pages().stream().map(c -> Filterable.passThrough(PaperAdventure.asVanilla(c))).toList(), // TODO should we validate legnth?
|
||||
false
|
||||
));
|
||||
return item;
|
||||
}
|
||||
|
||||
private static String validateField(final String content, final int length, final String name) {
|
||||
final int actual = content.length();
|
||||
if (actual > length) {
|
||||
throw new IllegalArgumentException("Field '" + name + "' has a maximum length of " + length + " but was passed '" + content + "', which was " + actual + " characters long.");
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
// Sounds
|
||||
|
||||
public static SoundSource asVanilla(final Sound.Source source) {
|
||||
return switch (source) {
|
||||
case MASTER -> SoundSource.MASTER;
|
||||
case MUSIC -> SoundSource.MUSIC;
|
||||
case RECORD -> SoundSource.RECORDS;
|
||||
case WEATHER -> SoundSource.WEATHER;
|
||||
case BLOCK -> SoundSource.BLOCKS;
|
||||
case HOSTILE -> SoundSource.HOSTILE;
|
||||
case NEUTRAL -> SoundSource.NEUTRAL;
|
||||
case PLAYER -> SoundSource.PLAYERS;
|
||||
case AMBIENT -> SoundSource.AMBIENT;
|
||||
case VOICE -> SoundSource.VOICE;
|
||||
};
|
||||
}
|
||||
|
||||
public static @Nullable SoundSource asVanillaNullable(final Sound.@Nullable Source source) {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
return asVanilla(source);
|
||||
}
|
||||
|
||||
public static Packet<?> asSoundPacket(final Sound sound, final double x, final double y, final double z, final long seed, @Nullable BiConsumer<Packet<?>, Float> packetConsumer) {
|
||||
final ResourceLocation name = asVanilla(sound.name());
|
||||
final Optional<SoundEvent> soundEvent = BuiltInRegistries.SOUND_EVENT.getOptional(name);
|
||||
final SoundSource source = asVanilla(sound.source());
|
||||
|
||||
final Holder<SoundEvent> soundEventHolder = soundEvent.map(BuiltInRegistries.SOUND_EVENT::wrapAsHolder).orElseGet(() -> Holder.direct(SoundEvent.createVariableRangeEvent(name)));
|
||||
final Packet<?> packet = new ClientboundSoundPacket(soundEventHolder, source, x, y, z, sound.volume(), sound.pitch(), seed);
|
||||
if (packetConsumer != null) {
|
||||
packetConsumer.accept(packet, soundEventHolder.value().getRange(sound.volume()));
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
|
||||
public static Packet<?> asSoundPacket(final Sound sound, final Entity emitter, final long seed, @Nullable BiConsumer<Packet<?>, Float> packetConsumer) {
|
||||
final ResourceLocation name = asVanilla(sound.name());
|
||||
final Optional<SoundEvent> soundEvent = BuiltInRegistries.SOUND_EVENT.getOptional(name);
|
||||
final SoundSource source = asVanilla(sound.source());
|
||||
|
||||
final Holder<SoundEvent> soundEventHolder = soundEvent.map(BuiltInRegistries.SOUND_EVENT::wrapAsHolder).orElseGet(() -> Holder.direct(SoundEvent.createVariableRangeEvent(name)));
|
||||
final Packet<?> packet = new ClientboundSoundEntityPacket(soundEventHolder, source, emitter, sound.volume(), sound.pitch(), seed);
|
||||
if (packetConsumer != null) {
|
||||
packetConsumer.accept(packet, soundEventHolder.value().getRange(sound.volume()));
|
||||
}
|
||||
return packet;
|
||||
}
|
||||
|
||||
// NBT
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public static Map<Key, ? extends DataComponentValue> asAdventure(
|
||||
final DataComponentPatch patch
|
||||
) {
|
||||
if (patch.isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
final Map<Key, DataComponentValue> map = new HashMap<>();
|
||||
for (final Map.Entry<DataComponentType<?>, Optional<?>> entry : patch.entrySet()) {
|
||||
if (entry.getKey().isTransient()) continue;
|
||||
@Subst("key:value") final String typeKey = requireNonNull(BuiltInRegistries.DATA_COMPONENT_TYPE.getKey(entry.getKey())).toString();
|
||||
if (entry.getValue().isEmpty()) {
|
||||
map.put(Key.key(typeKey), DataComponentValue.removed());
|
||||
} else {
|
||||
map.put(Key.key(typeKey), new DataComponentValueImpl(entry.getKey().codec(), entry.getValue().get()));
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public static DataComponentPatch asVanilla(final Map<? extends Key, ? extends DataComponentValue> map) {
|
||||
if (map.isEmpty()) {
|
||||
return DataComponentPatch.EMPTY;
|
||||
}
|
||||
final DataComponentPatch.Builder builder = DataComponentPatch.builder();
|
||||
map.forEach((key, dataComponentValue) -> {
|
||||
final DataComponentType<?> type = requireNonNull(BuiltInRegistries.DATA_COMPONENT_TYPE.getValue(asVanilla(key)));
|
||||
if (dataComponentValue instanceof DataComponentValue.Removed) {
|
||||
builder.remove(type);
|
||||
return;
|
||||
}
|
||||
final DataComponentValueImpl<?> converted = DataComponentValueConverterRegistry.convert(DataComponentValueImpl.class, key, dataComponentValue);
|
||||
builder.set((DataComponentType) type, (Object) converted.value());
|
||||
});
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public record DataComponentValueImpl<T>(com.mojang.serialization.Codec<T> codec, T value) implements DataComponentValue.TagSerializable {
|
||||
|
||||
@Override
|
||||
public @NotNull BinaryTagHolder asBinaryTag() {
|
||||
return BinaryTagHolder.encode(this.codec.encodeStart(CraftRegistry.getMinecraftRegistry().createSerializationContext(NbtOps.INSTANCE), this.value).getOrThrow(IllegalArgumentException::new), NBT_CODEC);
|
||||
}
|
||||
}
|
||||
|
||||
public static @Nullable BinaryTagHolder asBinaryTagHolder(final @Nullable CompoundTag tag) {
|
||||
if (tag == null) {
|
||||
return null;
|
||||
}
|
||||
return BinaryTagHolder.encode(tag, NBT_CODEC);
|
||||
}
|
||||
|
||||
// Colors
|
||||
|
||||
public static @NotNull TextColor asAdventure(final ChatFormatting formatting) {
|
||||
final Integer color = formatting.getColor();
|
||||
if (color == null) {
|
||||
throw new IllegalArgumentException("Not a valid color");
|
||||
}
|
||||
return TextColor.color(color);
|
||||
}
|
||||
|
||||
public static @Nullable ChatFormatting asVanilla(final TextColor color) {
|
||||
return ChatFormatting.getByHexValue(color.value());
|
||||
}
|
||||
|
||||
// Style
|
||||
|
||||
public static net.minecraft.network.chat.Style asVanilla(final Style style) {
|
||||
final RegistryOps<Object> ops = CraftRegistry.getMinecraftRegistry().createSerializationContext(JavaOps.INSTANCE);
|
||||
final Object encoded = AdventureCodecs.STYLE_MAP_CODEC.codec()
|
||||
.encodeStart(ops, style).getOrThrow(IllegalStateException::new);
|
||||
|
||||
return net.minecraft.network.chat.Style.Serializer.CODEC
|
||||
.parse(ops, encoded).getOrThrow(IllegalStateException::new);
|
||||
}
|
||||
|
||||
public static Style asAdventure(final net.minecraft.network.chat.Style style) {
|
||||
final RegistryOps<Object> ops = CraftRegistry.getMinecraftRegistry().createSerializationContext(JavaOps.INSTANCE);
|
||||
final Object encoded = net.minecraft.network.chat.Style.Serializer.CODEC
|
||||
.encodeStart(ops, style).getOrThrow(IllegalStateException::new);
|
||||
|
||||
return AdventureCodecs.STYLE_MAP_CODEC.codec()
|
||||
.parse(ops, encoded).getOrThrow(IllegalStateException::new);
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package io.papermc.paper.adventure;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.JavaOps;
|
||||
import java.util.function.Supplier;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.ComponentSerializer;
|
||||
import net.minecraft.network.chat.ComponentSerialization;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
|
||||
public final class WrapperAwareSerializer implements ComponentSerializer<Component, Component, net.minecraft.network.chat.Component> {
|
||||
|
||||
private final Supplier<RegistryOps<Object>> javaOps;
|
||||
|
||||
public WrapperAwareSerializer(final Supplier<RegistryOps<Object>> javaOps) {
|
||||
this.javaOps = Suppliers.memoize(javaOps::get);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component deserialize(final net.minecraft.network.chat.Component input) {
|
||||
if (input instanceof AdventureComponent) {
|
||||
return ((AdventureComponent) input).adventure;
|
||||
}
|
||||
final RegistryOps<Object> ops = this.javaOps.get();
|
||||
final Object obj = ComponentSerialization.CODEC.encodeStart(ops, input)
|
||||
.getOrThrow(s -> new RuntimeException("Failed to encode Minecraft Component: " + input + "; " + s));
|
||||
final Pair<Component, Object> converted = AdventureCodecs.COMPONENT_CODEC.decode(ops, obj)
|
||||
.getOrThrow(s -> new RuntimeException("Failed to decode to adventure Component: " + obj + "; " + s));
|
||||
return converted.getFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.minecraft.network.chat.Component serialize(final Component component) {
|
||||
final RegistryOps<Object> ops = this.javaOps.get();
|
||||
final Object obj = AdventureCodecs.COMPONENT_CODEC.encodeStart(ops, component)
|
||||
.getOrThrow(s -> new RuntimeException("Failed to encode adventure Component: " + component + "; " + s));
|
||||
final Pair<net.minecraft.network.chat.Component, Object> converted = ComponentSerialization.CODEC.decode(ops, obj)
|
||||
.getOrThrow(s -> new RuntimeException("Failed to decode to Minecraft Component: " + obj + "; " + s));
|
||||
return converted.getFirst();
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package io.papermc.paper.adventure.providers;
|
||||
|
||||
import io.papermc.paper.adventure.BossBarImplementationImpl;
|
||||
import net.kyori.adventure.bossbar.BossBar;
|
||||
import net.kyori.adventure.bossbar.BossBarImplementation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // permitted provider
|
||||
public class BossBarImplementationProvider implements BossBarImplementation.Provider {
|
||||
@Override
|
||||
public @NotNull BossBarImplementation create(final @NotNull BossBar bar) {
|
||||
return new BossBarImplementationImpl(bar);
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package io.papermc.paper.adventure.providers;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.event.ClickCallback;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // permitted provider
|
||||
public class ClickCallbackProviderImpl implements ClickCallback.Provider {
|
||||
|
||||
public static final CallbackManager CALLBACK_MANAGER = new CallbackManager();
|
||||
|
||||
@Override
|
||||
public @NotNull ClickEvent create(final @NotNull ClickCallback<Audience> callback, final ClickCallback.@NotNull Options options) {
|
||||
return ClickEvent.runCommand("/paper:callback " + CALLBACK_MANAGER.addCallback(callback, options));
|
||||
}
|
||||
|
||||
public static final class CallbackManager {
|
||||
|
||||
private final Map<UUID, StoredCallback> callbacks = new HashMap<>();
|
||||
private final Queue<StoredCallback> queue = new ConcurrentLinkedQueue<>();
|
||||
|
||||
private CallbackManager() {
|
||||
}
|
||||
|
||||
public UUID addCallback(final @NotNull ClickCallback<Audience> callback, final ClickCallback.@NotNull Options options) {
|
||||
final UUID id = UUID.randomUUID();
|
||||
this.queue.add(new StoredCallback(callback, options, id));
|
||||
return id;
|
||||
}
|
||||
|
||||
public void handleQueue(final int currentTick) {
|
||||
// Evict expired entries
|
||||
if (currentTick % 100 == 0) {
|
||||
this.callbacks.values().removeIf(callback -> !callback.valid());
|
||||
}
|
||||
|
||||
// Add entries from queue
|
||||
StoredCallback callback;
|
||||
while ((callback = this.queue.poll()) != null) {
|
||||
this.callbacks.put(callback.id(), callback);
|
||||
}
|
||||
}
|
||||
|
||||
public void runCallback(final @NotNull Audience audience, final UUID id) {
|
||||
final StoredCallback callback = this.callbacks.get(id);
|
||||
if (callback != null && callback.valid()) { //TODO Message if expired/invalid?
|
||||
callback.takeUse();
|
||||
callback.callback.accept(audience);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final class StoredCallback {
|
||||
private final long startedAt = System.nanoTime();
|
||||
private final ClickCallback<Audience> callback;
|
||||
private final long lifetime;
|
||||
private final UUID id;
|
||||
private int remainingUses;
|
||||
|
||||
private StoredCallback(final @NotNull ClickCallback<Audience> callback, final ClickCallback.@NotNull Options options, final UUID id) {
|
||||
this.callback = callback;
|
||||
this.lifetime = options.lifetime().toNanos();
|
||||
this.remainingUses = options.uses();
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void takeUse() {
|
||||
if (this.remainingUses != ClickCallback.UNLIMITED_USES) {
|
||||
this.remainingUses--;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasRemainingUses() {
|
||||
return this.remainingUses == ClickCallback.UNLIMITED_USES || this.remainingUses > 0;
|
||||
}
|
||||
|
||||
public boolean expired() {
|
||||
return System.nanoTime() - this.startedAt >= this.lifetime;
|
||||
}
|
||||
|
||||
public boolean valid() {
|
||||
return hasRemainingUses() && !expired();
|
||||
}
|
||||
|
||||
public UUID id() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package io.papermc.paper.adventure.providers;
|
||||
|
||||
import io.papermc.paper.adventure.PaperAdventure;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
|
||||
import net.kyori.adventure.text.logger.slf4j.ComponentLoggerProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class ComponentLoggerProviderImpl implements ComponentLoggerProvider {
|
||||
@Override
|
||||
public @NotNull ComponentLogger logger(@NotNull LoggerHelper helper, @NotNull String name) {
|
||||
return helper.delegating(LoggerFactory.getLogger(name), this::serialize);
|
||||
}
|
||||
|
||||
private String serialize(final Component message) {
|
||||
return PaperAdventure.asPlain(message, null);
|
||||
}
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package io.papermc.paper.adventure.providers;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.serialization.DynamicOps;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
import io.papermc.paper.adventure.PaperAdventure;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.nbt.api.BinaryTagHolder;
|
||||
import net.kyori.adventure.text.event.DataComponentValue;
|
||||
import net.kyori.adventure.text.event.DataComponentValueConverterRegistry;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonDataComponentValue;
|
||||
import net.minecraft.core.component.DataComponentType;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import org.bukkit.craftbukkit.CraftRegistry;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
import static net.kyori.adventure.text.serializer.gson.GsonDataComponentValue.gsonDataComponentValue;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class DataComponentValueConverterProviderImpl implements DataComponentValueConverterRegistry.Provider {
|
||||
|
||||
static final Key ID = Key.key("adventure", "platform/paper");
|
||||
|
||||
@Override
|
||||
public Key id() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
private static <T> RegistryOps<T> createOps(final DynamicOps<T> delegate) {
|
||||
return CraftRegistry.getMinecraftRegistry().createSerializationContext(delegate);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Override
|
||||
public Iterable<DataComponentValueConverterRegistry.Conversion<?, ?>> conversions() {
|
||||
return List.of(
|
||||
DataComponentValueConverterRegistry.Conversion.convert(
|
||||
PaperAdventure.DataComponentValueImpl.class,
|
||||
GsonDataComponentValue.class,
|
||||
(key, dataComponentValue) -> gsonDataComponentValue((JsonElement) dataComponentValue.codec().encodeStart(createOps(JsonOps.INSTANCE), dataComponentValue.value()).getOrThrow())
|
||||
),
|
||||
DataComponentValueConverterRegistry.Conversion.convert(
|
||||
GsonDataComponentValue.class,
|
||||
PaperAdventure.DataComponentValueImpl.class,
|
||||
(key, dataComponentValue) -> {
|
||||
final @Nullable DataComponentType<?> type = BuiltInRegistries.DATA_COMPONENT_TYPE.getValue(PaperAdventure.asVanilla(key));
|
||||
if (type == null) {
|
||||
throw new IllegalArgumentException("Unknown data component type: " + key);
|
||||
}
|
||||
return new PaperAdventure.DataComponentValueImpl(type.codecOrThrow(), type.codecOrThrow().parse(createOps(JsonOps.INSTANCE), dataComponentValue.element()).getOrThrow(IllegalArgumentException::new));
|
||||
}
|
||||
),
|
||||
DataComponentValueConverterRegistry.Conversion.convert(
|
||||
PaperAdventure.DataComponentValueImpl.class,
|
||||
DataComponentValue.TagSerializable.class,
|
||||
(key, dataComponentValue) -> BinaryTagHolder.encode((Tag) dataComponentValue.codec().encodeStart(createOps(NbtOps.INSTANCE), dataComponentValue.value()).getOrThrow(), PaperAdventure.NBT_CODEC)
|
||||
),
|
||||
DataComponentValueConverterRegistry.Conversion.convert(
|
||||
DataComponentValue.TagSerializable.class,
|
||||
PaperAdventure.DataComponentValueImpl.class,
|
||||
(key, tagSerializable) -> {
|
||||
final @Nullable DataComponentType<?> type = BuiltInRegistries.DATA_COMPONENT_TYPE.getValue(PaperAdventure.asVanilla(key));
|
||||
if (type == null) {
|
||||
throw new IllegalArgumentException("Unknown data component type: " + key);
|
||||
}
|
||||
try {
|
||||
return new PaperAdventure.DataComponentValueImpl(type.codecOrThrow(), type.codecOrThrow().parse(createOps(NbtOps.INSTANCE), tagSerializable.asBinaryTag().get(PaperAdventure.NBT_CODEC)).getOrThrow(IllegalArgumentException::new));
|
||||
} catch (final CommandSyntaxException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package io.papermc.paper.adventure.providers;
|
||||
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // permitted provider
|
||||
public class GsonComponentSerializerProviderImpl implements GsonComponentSerializer.Provider {
|
||||
|
||||
@Override
|
||||
public @NotNull GsonComponentSerializer gson() {
|
||||
return GsonComponentSerializer.builder()
|
||||
.legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.INSTANCE)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull GsonComponentSerializer gsonLegacy() {
|
||||
return GsonComponentSerializer.builder()
|
||||
.legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.INSTANCE)
|
||||
.downsampleColors()
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Consumer<GsonComponentSerializer.Builder> builder() {
|
||||
return builder -> builder.legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.INSTANCE);
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package io.papermc.paper.adventure.providers;
|
||||
|
||||
import io.papermc.paper.adventure.PaperAdventure;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // permitted provider
|
||||
public class LegacyComponentSerializerProviderImpl implements LegacyComponentSerializer.Provider {
|
||||
|
||||
@Override
|
||||
public @NotNull LegacyComponentSerializer legacyAmpersand() {
|
||||
return LegacyComponentSerializer.builder()
|
||||
.flattener(PaperAdventure.FLATTENER)
|
||||
.character(LegacyComponentSerializer.AMPERSAND_CHAR)
|
||||
.hexColors()
|
||||
.useUnusualXRepeatedCharacterHexFormat()
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull LegacyComponentSerializer legacySection() {
|
||||
return LegacyComponentSerializer.builder()
|
||||
.flattener(PaperAdventure.FLATTENER)
|
||||
.character(LegacyComponentSerializer.SECTION_CHAR)
|
||||
.hexColors()
|
||||
.useUnusualXRepeatedCharacterHexFormat()
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Consumer<LegacyComponentSerializer.Builder> legacy() {
|
||||
return builder -> builder.flattener(PaperAdventure.FLATTENER);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package io.papermc.paper.adventure.providers;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // permitted provider
|
||||
public class MiniMessageProviderImpl implements MiniMessage.Provider {
|
||||
|
||||
@Override
|
||||
public @NotNull MiniMessage miniMessage() {
|
||||
return MiniMessage.builder().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Consumer<MiniMessage.Builder> builder() {
|
||||
return builder -> {};
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package io.papermc.paper.adventure.providers;
|
||||
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.nbt.api.BinaryTagHolder;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.serializer.json.LegacyHoverEventSerializer;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import net.kyori.adventure.util.Codec;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.TagParser;
|
||||
import org.intellij.lang.annotations.Subst;
|
||||
|
||||
final class NBTLegacyHoverEventSerializer implements LegacyHoverEventSerializer {
|
||||
public static final NBTLegacyHoverEventSerializer INSTANCE = new NBTLegacyHoverEventSerializer();
|
||||
private static final Codec<CompoundTag, String, CommandSyntaxException, RuntimeException> SNBT_CODEC = Codec.codec(TagParser::parseTag, Tag::toString);
|
||||
|
||||
static final String ITEM_TYPE = "id";
|
||||
static final String ITEM_COUNT = "Count";
|
||||
static final String ITEM_TAG = "tag";
|
||||
|
||||
static final String ENTITY_NAME = "name";
|
||||
static final String ENTITY_TYPE = "type";
|
||||
static final String ENTITY_ID = "id";
|
||||
|
||||
NBTLegacyHoverEventSerializer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public HoverEvent.ShowItem deserializeShowItem(final Component input) throws IOException {
|
||||
final String raw = PlainTextComponentSerializer.plainText().serialize(input);
|
||||
try {
|
||||
final CompoundTag contents = SNBT_CODEC.decode(raw);
|
||||
final CompoundTag tag = contents.getCompound(ITEM_TAG);
|
||||
@Subst("key") final String keyString = contents.getString(ITEM_TYPE);
|
||||
return HoverEvent.ShowItem.showItem(
|
||||
Key.key(keyString),
|
||||
contents.contains(ITEM_COUNT) ? contents.getByte(ITEM_COUNT) : 1,
|
||||
tag.isEmpty() ? null : BinaryTagHolder.encode(tag, SNBT_CODEC)
|
||||
);
|
||||
} catch (final CommandSyntaxException ex) {
|
||||
throw new IOException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HoverEvent.ShowEntity deserializeShowEntity(final Component input, final Codec.Decoder<Component, String, ? extends RuntimeException> componentCodec) throws IOException {
|
||||
final String raw = PlainTextComponentSerializer.plainText().serialize(input);
|
||||
try {
|
||||
final CompoundTag contents = SNBT_CODEC.decode(raw);
|
||||
@Subst("key") final String keyString = contents.getString(ENTITY_TYPE);
|
||||
return HoverEvent.ShowEntity.showEntity(
|
||||
Key.key(keyString),
|
||||
UUID.fromString(contents.getString(ENTITY_ID)),
|
||||
componentCodec.decode(contents.getString(ENTITY_NAME))
|
||||
);
|
||||
} catch (final CommandSyntaxException ex) {
|
||||
throw new IOException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component serializeShowItem(final HoverEvent.ShowItem input) throws IOException {
|
||||
final CompoundTag tag = new CompoundTag();
|
||||
tag.putString(ITEM_TYPE, input.item().asString());
|
||||
tag.putByte(ITEM_COUNT, (byte) input.count());
|
||||
if (input.nbt() != null) {
|
||||
try {
|
||||
tag.put(ITEM_TAG, input.nbt().get(SNBT_CODEC));
|
||||
} catch (final CommandSyntaxException ex) {
|
||||
throw new IOException(ex);
|
||||
}
|
||||
}
|
||||
return Component.text(SNBT_CODEC.encode(tag));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component serializeShowEntity(final HoverEvent.ShowEntity input, final Codec.Encoder<Component, String, ? extends RuntimeException> componentCodec) {
|
||||
final CompoundTag tag = new CompoundTag();
|
||||
tag.putString(ENTITY_ID, input.id().toString());
|
||||
tag.putString(ENTITY_TYPE, input.type().asString());
|
||||
if (input.name() != null) {
|
||||
tag.putString(ENTITY_NAME, componentCodec.encode(input.name()));
|
||||
}
|
||||
return Component.text(SNBT_CODEC.encode(tag));
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package io.papermc.paper.adventure.providers;
|
||||
|
||||
import io.papermc.paper.adventure.PaperAdventure;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage") // permitted provider
|
||||
public class PlainTextComponentSerializerProviderImpl implements PlainTextComponentSerializer.Provider {
|
||||
|
||||
@Override
|
||||
public @NotNull PlainTextComponentSerializer plainTextSimple() {
|
||||
return PlainTextComponentSerializer.builder()
|
||||
.flattener(PaperAdventure.FLATTENER)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Consumer<PlainTextComponentSerializer.Builder> plainText() {
|
||||
return builder -> builder.flattener(PaperAdventure.FLATTENER);
|
||||
}
|
||||
}
|
@ -59,6 +59,7 @@ public class CraftJukeboxSong implements JukeboxSong, Handleable<net.minecraft.w
|
||||
@NotNull
|
||||
@Override
|
||||
public String getTranslationKey() {
|
||||
if (!(this.handle.description().getContents() instanceof TranslatableContents)) throw new UnsupportedOperationException("Description isn't translatable!"); // Paper
|
||||
return ((TranslatableContents) this.handle.description().getContents()).getKey();
|
||||
}
|
||||
}
|
||||
|
@ -648,8 +648,10 @@ public final class CraftServer implements Server {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated // Paper start
|
||||
public int broadcastMessage(String message) {
|
||||
return this.broadcast(message, BROADCAST_CHANNEL_USERS);
|
||||
// Paper end
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1627,7 +1629,15 @@ public final class CraftServer implements Server {
|
||||
return this.configuration.getInt("settings.spawn-radius", -1);
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component shutdownMessage() {
|
||||
String msg = getShutdownMessage();
|
||||
return msg != null ? net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(msg) : null;
|
||||
}
|
||||
// Paper end
|
||||
@Override
|
||||
@Deprecated // Paper
|
||||
public String getShutdownMessage() {
|
||||
return this.configuration.getString("settings.shutdown-message");
|
||||
}
|
||||
@ -1801,7 +1811,20 @@ public final class CraftServer implements Server {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated // Paper
|
||||
public int broadcast(String message, String permission) {
|
||||
// Paper start - Adventure
|
||||
return this.broadcast(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(message), permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int broadcast(net.kyori.adventure.text.Component message) {
|
||||
return this.broadcast(message, BROADCAST_CHANNEL_USERS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int broadcast(net.kyori.adventure.text.Component message, String permission) {
|
||||
// Paper end
|
||||
Set<CommandSender> recipients = new HashSet<>();
|
||||
for (Permissible permissible : this.getPluginManager().getPermissionSubscriptions(permission)) {
|
||||
if (permissible instanceof CommandSender && permissible.hasPermission(permission)) {
|
||||
@ -1809,14 +1832,14 @@ public final class CraftServer implements Server {
|
||||
}
|
||||
}
|
||||
|
||||
BroadcastMessageEvent broadcastMessageEvent = new BroadcastMessageEvent(!Bukkit.isPrimaryThread(), message, recipients);
|
||||
BroadcastMessageEvent broadcastMessageEvent = new BroadcastMessageEvent(!Bukkit.isPrimaryThread(), message, recipients); // Paper - Adventure
|
||||
this.getPluginManager().callEvent(broadcastMessageEvent);
|
||||
|
||||
if (broadcastMessageEvent.isCancelled()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
message = broadcastMessageEvent.getMessage();
|
||||
message = broadcastMessageEvent.message(); // Paper - Adventure
|
||||
|
||||
for (CommandSender recipient : recipients) {
|
||||
recipient.sendMessage(message);
|
||||
@ -2078,6 +2101,14 @@ public final class CraftServer implements Server {
|
||||
return CraftInventoryCreator.INSTANCE.createInventory(owner, type);
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
|
||||
Preconditions.checkArgument(type.isCreatable(), "Cannot open an inventory of type ", type);
|
||||
return CraftInventoryCreator.INSTANCE.createInventory(owner, type, title);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public Inventory createInventory(InventoryHolder owner, InventoryType type, String title) {
|
||||
Preconditions.checkArgument(type != null, "InventoryType cannot be null");
|
||||
@ -2092,13 +2123,28 @@ public final class CraftServer implements Server {
|
||||
return CraftInventoryCreator.INSTANCE.createInventory(owner, size);
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public Inventory createInventory(InventoryHolder owner, int size, net.kyori.adventure.text.Component title) throws IllegalArgumentException {
|
||||
Preconditions.checkArgument(9 <= size && size <= 54 && size % 9 == 0, "Size for custom inventory must be a multiple of 9 between 9 and 54 slots (got " + size + ")");
|
||||
return CraftInventoryCreator.INSTANCE.createInventory(owner, size, title);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public Inventory createInventory(InventoryHolder owner, int size, String title) throws IllegalArgumentException {
|
||||
Preconditions.checkArgument(9 <= size && size <= 54 && size % 9 == 0, "Size for custom inventory must be a multiple of 9 between 9 and 54 slots (got %s)", size);
|
||||
return CraftInventoryCreator.INSTANCE.createInventory(owner, size, title);
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public Merchant createMerchant(net.kyori.adventure.text.Component title) {
|
||||
return new org.bukkit.craftbukkit.inventory.CraftMerchantCustom(title == null ? InventoryType.MERCHANT.defaultTitle() : title);
|
||||
}
|
||||
// Paper end
|
||||
@Override
|
||||
@Deprecated // Paper
|
||||
public Merchant createMerchant(String title) {
|
||||
return new CraftMerchantCustom(title == null ? InventoryType.MERCHANT.getDefaultTitle() : title);
|
||||
}
|
||||
@ -2163,6 +2209,17 @@ public final class CraftServer implements Server {
|
||||
return Thread.currentThread().equals(this.console.serverThread) || this.console.hasStopped() || !org.spigotmc.AsyncCatcher.enabled; // All bets are off if we have shut down (e.g. due to watchdog)
|
||||
}
|
||||
|
||||
// Paper start - Adventure
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component motd() {
|
||||
return this.console.motd();
|
||||
}
|
||||
@Override
|
||||
public void motd(final net.kyori.adventure.text.Component motd) {
|
||||
this.console.motd(motd);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public String getMotd() {
|
||||
return this.console.getMotd();
|
||||
@ -2632,4 +2689,57 @@ public final class CraftServer implements Server {
|
||||
public double[] getTPS() {
|
||||
return new double[]{0, 0, 0}; // TODO
|
||||
}
|
||||
|
||||
// Paper start - adventure sounds
|
||||
@Override
|
||||
public void playSound(final net.kyori.adventure.sound.Sound sound) {
|
||||
if (sound.seed().isEmpty()) org.spigotmc.AsyncCatcher.catchOp("play sound; cannot generate seed with world random"); // Paper
|
||||
final long seed = sound.seed().orElseGet(this.console.overworld().getRandom()::nextLong);
|
||||
for (ServerPlayer player : this.playerList.getPlayers()) {
|
||||
player.connection.send(io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, player.getX(), player.getY(), player.getZ(), seed, null));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(final net.kyori.adventure.sound.Sound sound, final double x, final double y, final double z) {
|
||||
org.spigotmc.AsyncCatcher.catchOp("play sound"); // Paper
|
||||
io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, x, y, z, sound.seed().orElseGet(this.console.overworld().getRandom()::nextLong), this.playSound0(x, y, z, this.console.getAllLevels()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(final net.kyori.adventure.sound.Sound sound, final net.kyori.adventure.sound.Sound.Emitter emitter) {
|
||||
if (sound.seed().isEmpty()) org.spigotmc.AsyncCatcher.catchOp("play sound; cannot generate seed with world random"); // Paper
|
||||
final long seed = sound.seed().orElseGet(this.console.overworld().getRandom()::nextLong);
|
||||
if (emitter == net.kyori.adventure.sound.Sound.Emitter.self()) {
|
||||
for (ServerPlayer player : this.playerList.getPlayers()) {
|
||||
player.connection.send(io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, player, seed, null));
|
||||
}
|
||||
} else if (emitter instanceof org.bukkit.craftbukkit.entity.CraftEntity craftEntity) {
|
||||
org.spigotmc.AsyncCatcher.catchOp("play sound; cannot use entity emitter"); // Paper
|
||||
final net.minecraft.world.entity.Entity entity = craftEntity.getHandle();
|
||||
io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, entity, seed, this.playSound0(entity.getX(), entity.getY(), entity.getZ(), List.of((ServerLevel) entity.level())));
|
||||
} else {
|
||||
throw new IllegalArgumentException("Sound emitter must be an Entity or self(), but was: " + emitter);
|
||||
}
|
||||
}
|
||||
|
||||
private java.util.function.BiConsumer<net.minecraft.network.protocol.Packet<?>, Float> playSound0(final double x, final double y, final double z, final Iterable<ServerLevel> levels) {
|
||||
return (packet, distance) -> {
|
||||
for (final ServerLevel level : levels) {
|
||||
level.getServer().getPlayerList().broadcast(null, x, y, z, distance, level.dimension(), packet);
|
||||
}
|
||||
};
|
||||
}
|
||||
// Paper end
|
||||
|
||||
// Paper start
|
||||
private Iterable<? extends net.kyori.adventure.audience.Audience> adventure$audiences;
|
||||
@Override
|
||||
public Iterable<? extends net.kyori.adventure.audience.Audience> audiences() {
|
||||
if (this.adventure$audiences == null) {
|
||||
this.adventure$audiences = com.google.common.collect.Iterables.concat(java.util.Collections.singleton(this.getConsoleSender()), this.getOnlinePlayers());
|
||||
}
|
||||
return this.adventure$audiences;
|
||||
}
|
||||
// Paper end
|
||||
}
|
||||
|
@ -61,6 +61,19 @@ public class CraftServerLinks implements ServerLinks {
|
||||
return link;
|
||||
}
|
||||
|
||||
// Paper start - Adventure
|
||||
@Override
|
||||
public ServerLink addLink(net.kyori.adventure.text.Component displayName, URI url) {
|
||||
Preconditions.checkArgument(displayName != null, "displayName cannot be null");
|
||||
Preconditions.checkArgument(url != null, "url cannot be null");
|
||||
|
||||
CraftServerLink link = new CraftServerLink(net.minecraft.server.ServerLinks.Entry.custom(io.papermc.paper.adventure.PaperAdventure.asVanilla(displayName), url));
|
||||
this.addLink(link);
|
||||
|
||||
return link;
|
||||
}
|
||||
// Paper end - Adventure
|
||||
|
||||
@Override
|
||||
public ServerLink addLink(String displayName, URI url) {
|
||||
Preconditions.checkArgument(displayName != null, "displayName cannot be null");
|
||||
@ -134,6 +147,13 @@ public class CraftServerLinks implements ServerLinks {
|
||||
return CraftChatMessage.fromComponent(this.handle.displayName());
|
||||
}
|
||||
|
||||
// Paper start - Adventure
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component displayName() {
|
||||
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.handle.displayName());
|
||||
}
|
||||
// Paper end - Adventure
|
||||
|
||||
@Override
|
||||
public URI getUrl() {
|
||||
return this.handle.link();
|
||||
|
@ -167,6 +167,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||
private final BlockMetadataStore blockMetadata = new BlockMetadataStore(this);
|
||||
private final Object2IntOpenHashMap<SpawnCategory> spawnCategoryLimit = new Object2IntOpenHashMap<>();
|
||||
private final CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(CraftWorld.DATA_TYPE_REGISTRY);
|
||||
private net.kyori.adventure.pointer.Pointers adventure$pointers; // Paper - implement pointers
|
||||
|
||||
private static final Random rand = new Random();
|
||||
|
||||
@ -1710,6 +1711,15 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||
entityTracker.broadcastAndSend(packet);
|
||||
}
|
||||
}
|
||||
// Paper start - Adventure
|
||||
@Override
|
||||
public void playSound(final net.kyori.adventure.sound.Sound sound) {
|
||||
org.spigotmc.AsyncCatcher.catchOp("play sound"); // Paper
|
||||
final long seed = sound.seed().orElseGet(this.world.getRandom()::nextLong);
|
||||
for (ServerPlayer player : this.getHandle().players()) {
|
||||
player.connection.send(io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, player.getX(), player.getY(), player.getZ(), seed, null));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(Entity entity, String sound, org.bukkit.SoundCategory category, float volume, float pitch, long seed) {
|
||||
@ -1722,6 +1732,33 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(final net.kyori.adventure.sound.Sound sound, final double x, final double y, final double z) {
|
||||
org.spigotmc.AsyncCatcher.catchOp("play sound"); // Paper
|
||||
io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, x, y, z, sound.seed().orElseGet(this.world.getRandom()::nextLong), this.playSound0(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(final net.kyori.adventure.sound.Sound sound, final net.kyori.adventure.sound.Sound.Emitter emitter) {
|
||||
org.spigotmc.AsyncCatcher.catchOp("play sound"); // Paper
|
||||
final long seed = sound.seed().orElseGet(this.getHandle().getRandom()::nextLong);
|
||||
if (emitter == net.kyori.adventure.sound.Sound.Emitter.self()) {
|
||||
for (ServerPlayer player : this.getHandle().players()) {
|
||||
player.connection.send(io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, player, seed, null));
|
||||
}
|
||||
} else if (emitter instanceof CraftEntity craftEntity) {
|
||||
final net.minecraft.world.entity.Entity entity = craftEntity.getHandle();
|
||||
io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, entity, seed, this.playSound0(entity.getX(), entity.getY(), entity.getZ()));
|
||||
} else {
|
||||
throw new IllegalArgumentException("Sound emitter must be an Entity or self(), but was: " + emitter);
|
||||
}
|
||||
}
|
||||
|
||||
private java.util.function.BiConsumer<net.minecraft.network.protocol.Packet<?>, Float> playSound0(final double x, final double y, final double z) {
|
||||
return (packet, distance) -> this.world.getServer().getPlayerList().broadcast(null, x, y, z, distance, this.world.dimension(), packet);
|
||||
}
|
||||
// Paper end - Adventure
|
||||
|
||||
private Map<String, GameRules.Key<?>> gamerules;
|
||||
public synchronized Map<String, GameRules.Key<?>> getGameRulesNMS() {
|
||||
if (this.gamerules != null) {
|
||||
@ -2161,5 +2198,18 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
||||
public void setSendViewDistance(final int viewDistance) {
|
||||
throw new UnsupportedOperationException("Not implemented yet");
|
||||
}
|
||||
|
||||
// Paper start - implement pointers
|
||||
@Override
|
||||
public net.kyori.adventure.pointer.Pointers pointers() {
|
||||
if (this.adventure$pointers == null) {
|
||||
this.adventure$pointers = net.kyori.adventure.pointer.Pointers.builder()
|
||||
.withDynamic(net.kyori.adventure.identity.Identity.NAME, this::getName)
|
||||
.withDynamic(net.kyori.adventure.identity.Identity.UUID, this::getUID)
|
||||
.build();
|
||||
}
|
||||
|
||||
return this.adventure$pointers;
|
||||
}
|
||||
// Paper end
|
||||
}
|
||||
|
@ -20,6 +20,12 @@ public class Main {
|
||||
public static boolean useConsole = true;
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Paper start
|
||||
final String warnWhenLegacyFormattingDetected = String.join(".", "net", "kyori", "adventure", "text", "warnWhenLegacyFormattingDetected");
|
||||
if (false && System.getProperty(warnWhenLegacyFormattingDetected) == null) {
|
||||
System.setProperty(warnWhenLegacyFormattingDetected, String.valueOf(true));
|
||||
}
|
||||
// Paper end
|
||||
// Todo: Installation script
|
||||
OptionParser parser = new OptionParser() {
|
||||
{
|
||||
|
@ -81,6 +81,19 @@ public class CraftBeacon extends CraftBlockEntityState<BeaconBlockEntity> implem
|
||||
this.getSnapshot().secondaryPower = (effect != null) ? CraftPotionEffectType.bukkitToMinecraftHolder(effect) : null;
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component customName() {
|
||||
final BeaconBlockEntity be = this.getSnapshot();
|
||||
return be.name != null ? io.papermc.paper.adventure.PaperAdventure.asAdventure(be.name) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customName(final net.kyori.adventure.text.Component customName) {
|
||||
this.getSnapshot().setCustomName(customName != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(customName) : null);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public String getCustomName() {
|
||||
BeaconBlockEntity beacon = this.getSnapshot();
|
||||
|
@ -45,4 +45,16 @@ public class CraftCommandBlock extends CraftBlockEntityState<CommandBlockEntity>
|
||||
public CraftCommandBlock copy(Location location) {
|
||||
return new CraftCommandBlock(this, location);
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component name() {
|
||||
return io.papermc.paper.adventure.PaperAdventure.asAdventure(getSnapshot().getCommandBlock().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void name(net.kyori.adventure.text.Component name) {
|
||||
getSnapshot().getCommandBlock().setCustomName(name == null ? net.minecraft.network.chat.Component.literal("@") : io.papermc.paper.adventure.PaperAdventure.asVanilla(name));
|
||||
}
|
||||
// Paper end
|
||||
}
|
||||
|
@ -57,6 +57,19 @@ public abstract class CraftContainer<T extends BaseContainerBlockEntity> extends
|
||||
}
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component customName() {
|
||||
final T be = this.getSnapshot();
|
||||
return be.hasCustomName() ? io.papermc.paper.adventure.PaperAdventure.asAdventure(be.getCustomName()) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customName(final net.kyori.adventure.text.Component customName) {
|
||||
this.getSnapshot().name = (customName != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(customName) : null);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public String getCustomName() {
|
||||
T container = this.getSnapshot();
|
||||
|
@ -16,6 +16,19 @@ public class CraftEnchantingTable extends CraftBlockEntityState<EnchantingTableB
|
||||
super(state, location);
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component customName() {
|
||||
final EnchantingTableBlockEntity be = this.getSnapshot();
|
||||
return be.hasCustomName() ? io.papermc.paper.adventure.PaperAdventure.asAdventure(be.getCustomName()) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customName(final net.kyori.adventure.text.Component customName) {
|
||||
this.getSnapshot().setCustomName(customName != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(customName) : null);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public String getCustomName() {
|
||||
EnchantingTableBlockEntity enchant = this.getSnapshot();
|
||||
|
@ -36,6 +36,23 @@ public class CraftSign<T extends SignBlockEntity> extends CraftBlockEntityState<
|
||||
this.back = new CraftSignSide(this.getSnapshot().getBackText());
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public java.util.@NotNull List<net.kyori.adventure.text.Component> lines() {
|
||||
return this.front.lines();
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.@NotNull Component line(int index) {
|
||||
return this.front.line(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void line(int index, net.kyori.adventure.text.@NotNull Component line) {
|
||||
this.front.line(index, line);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public String[] getLines() {
|
||||
return this.front.getLines();
|
||||
@ -161,6 +178,20 @@ public class CraftSign<T extends SignBlockEntity> extends CraftBlockEntityState<
|
||||
((CraftPlayer) player).getHandle().openTextEdit(handle, Side.FRONT == side);
|
||||
}
|
||||
|
||||
// Paper start
|
||||
public static Component[] sanitizeLines(java.util.List<? extends net.kyori.adventure.text.Component> lines) {
|
||||
Component[] components = new Component[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (i < lines.size() && lines.get(i) != null) {
|
||||
components[i] = io.papermc.paper.adventure.PaperAdventure.asVanilla(lines.get(i));
|
||||
} else {
|
||||
components[i] = net.minecraft.network.chat.Component.literal("");
|
||||
}
|
||||
}
|
||||
return components;
|
||||
}
|
||||
// Paper end
|
||||
|
||||
public static Component[] sanitizeLines(String[] lines) {
|
||||
Component[] components = new Component[4];
|
||||
|
||||
|
@ -12,37 +12,70 @@ import org.jetbrains.annotations.Nullable;
|
||||
public class CraftSignSide implements SignSide {
|
||||
|
||||
// Lazily initialized only if requested:
|
||||
private String[] originalLines = null;
|
||||
private String[] lines = null;
|
||||
// Paper start
|
||||
private java.util.ArrayList<net.kyori.adventure.text.Component> originalLines = null; // ArrayList for RandomAccess
|
||||
private java.util.ArrayList<net.kyori.adventure.text.Component> lines = null; // ArrayList for RandomAccess
|
||||
// Paper end
|
||||
private SignText signText;
|
||||
|
||||
public CraftSignSide(SignText signText) {
|
||||
this.signText = signText;
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public java.util.@NotNull List<net.kyori.adventure.text.Component> lines() {
|
||||
this.loadLines();
|
||||
return this.lines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.@NotNull Component line(final int index) throws IndexOutOfBoundsException {
|
||||
this.loadLines();
|
||||
return this.lines.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void line(final int index, final net.kyori.adventure.text.@NotNull Component line) throws IndexOutOfBoundsException {
|
||||
com.google.common.base.Preconditions.checkArgument(line != null, "Line cannot be null");
|
||||
this.loadLines();
|
||||
this.lines.set(index, line);
|
||||
}
|
||||
|
||||
private void loadLines() {
|
||||
if (this.lines != null) {
|
||||
return;
|
||||
}
|
||||
// Lazy initialization:
|
||||
this.lines = io.papermc.paper.adventure.PaperAdventure.asAdventure(com.google.common.collect.Lists.newArrayList(this.signText.getMessages(false)));
|
||||
this.originalLines = new java.util.ArrayList<>(this.lines);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String[] getLines() {
|
||||
if (this.lines == null) {
|
||||
// Lazy initialization:
|
||||
Component[] messages = this.signText.getMessages(false);
|
||||
this.lines = new String[messages.length];
|
||||
System.arraycopy(CraftSign.revertComponents(messages), 0, this.lines, 0, this.lines.length);
|
||||
this.originalLines = new String[this.lines.length];
|
||||
System.arraycopy(this.lines, 0, this.originalLines, 0, this.originalLines.length);
|
||||
}
|
||||
return this.lines;
|
||||
// Paper start
|
||||
this.loadLines();
|
||||
return this.lines.stream().map(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection()::serialize).toArray(String[]::new); // Paper
|
||||
// Paper end
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getLine(int index) throws IndexOutOfBoundsException {
|
||||
return this.getLines()[index];
|
||||
// Paper start
|
||||
this.loadLines();
|
||||
return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(this.lines.get(index));
|
||||
// Paper end
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLine(int index, @NotNull String line) throws IndexOutOfBoundsException {
|
||||
this.getLines()[index] = line;
|
||||
// Paper start
|
||||
this.loadLines();
|
||||
this.lines.set(index, line != null ? net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(line) : net.kyori.adventure.text.Component.empty());
|
||||
// Paper end
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -68,13 +101,16 @@ public class CraftSignSide implements SignSide {
|
||||
|
||||
public SignText applyLegacyStringToSignSide() {
|
||||
if (this.lines != null) {
|
||||
for (int i = 0; i < this.lines.length; i++) {
|
||||
String line = (this.lines[i] == null) ? "" : this.lines[i];
|
||||
if (line.equals(this.originalLines[i])) {
|
||||
// Paper start
|
||||
for (int i = 0; i < this.lines.size(); ++i) {
|
||||
net.kyori.adventure.text.Component component = this.lines.get(i);
|
||||
net.kyori.adventure.text.Component origComp = this.originalLines.get(i);
|
||||
if (component.equals(origComp)) {
|
||||
continue; // The line contents are still the same, skip.
|
||||
}
|
||||
this.signText = this.signText.setMessage(i, CraftChatMessage.fromString(line)[0]);
|
||||
this.signText = this.signText.setMessage(i, io.papermc.paper.adventure.PaperAdventure.asVanilla(component));
|
||||
}
|
||||
// Paper end
|
||||
}
|
||||
|
||||
return this.signText;
|
||||
|
@ -61,6 +61,18 @@ public class CraftBlockCommandSender extends ServerCommandSender implements Bloc
|
||||
return this.block.getTextName();
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public void sendMessage(net.kyori.adventure.identity.Identity identity, net.kyori.adventure.text.Component message, net.kyori.adventure.audience.MessageType type) {
|
||||
block.source.sendSystemMessage(io.papermc.paper.adventure.PaperAdventure.asVanilla(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component name() {
|
||||
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.block.getDisplayName());
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public boolean isOp() {
|
||||
return CraftBlockCommandSender.SHARED_PERM.isOp();
|
||||
|
@ -46,6 +46,13 @@ public class CraftConsoleCommandSender extends ServerCommandSender implements Co
|
||||
return "CONSOLE";
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component name() {
|
||||
return net.kyori.adventure.text.Component.text(this.getName());
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public boolean isOp() {
|
||||
return true;
|
||||
@ -80,4 +87,11 @@ public class CraftConsoleCommandSender extends ServerCommandSender implements Co
|
||||
public boolean isConversing() {
|
||||
return this.conversationTracker.isConversing();
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public void sendMessage(final net.kyori.adventure.identity.Identity identity, final net.kyori.adventure.text.Component message, final net.kyori.adventure.audience.MessageType type) {
|
||||
this.sendRawMessage(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(message));
|
||||
}
|
||||
// Paper end
|
||||
}
|
||||
|
@ -39,6 +39,13 @@ public class CraftRemoteConsoleCommandSender extends ServerCommandSender impleme
|
||||
return "Rcon";
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component name() {
|
||||
return net.kyori.adventure.text.Component.text(this.getName());
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public boolean isOp() {
|
||||
return true;
|
||||
|
@ -67,6 +67,13 @@ public class ProxiedNativeCommandSender implements ProxiedCommandSender {
|
||||
return this.getCallee().getName();
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component name() {
|
||||
return this.getCallee().name();
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(String name) {
|
||||
return this.getCaller().isPermissionSet(name);
|
||||
|
@ -13,6 +13,7 @@ import org.bukkit.plugin.Plugin;
|
||||
|
||||
public abstract class ServerCommandSender implements CommandSender {
|
||||
private final PermissibleBase perm;
|
||||
private net.kyori.adventure.pointer.Pointers adventure$pointers; // Paper - implement pointers
|
||||
|
||||
protected ServerCommandSender() {
|
||||
this.perm = new PermissibleBase(this);
|
||||
@ -130,4 +131,18 @@ public abstract class ServerCommandSender implements CommandSender {
|
||||
return this.spigot;
|
||||
}
|
||||
// Spigot end
|
||||
|
||||
// Paper start - implement pointers
|
||||
@Override
|
||||
public net.kyori.adventure.pointer.Pointers pointers() {
|
||||
if (this.adventure$pointers == null) {
|
||||
this.adventure$pointers = net.kyori.adventure.pointer.Pointers.builder()
|
||||
.withDynamic(net.kyori.adventure.identity.Identity.DISPLAY_NAME, this::name)
|
||||
.withStatic(net.kyori.adventure.permission.PermissionChecker.POINTER, this::permissionValue)
|
||||
.build();
|
||||
}
|
||||
|
||||
return this.adventure$pointers;
|
||||
}
|
||||
// Paper end
|
||||
}
|
||||
|
@ -145,6 +145,12 @@ public class CraftEnchantment extends Enchantment implements Handleable<net.mine
|
||||
CraftEnchantment ench = (CraftEnchantment) other;
|
||||
return !net.minecraft.world.item.enchantment.Enchantment.areCompatible(this.handle, ench.handle);
|
||||
}
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component displayName(int level) {
|
||||
return io.papermc.paper.adventure.PaperAdventure.asAdventure(getHandle().getFullname(level));
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public String getTranslationKey() {
|
||||
|
@ -70,6 +70,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
||||
private final EntityType entityType;
|
||||
private EntityDamageEvent lastDamageEvent;
|
||||
private final CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(CraftEntity.DATA_TYPE_REGISTRY);
|
||||
protected net.kyori.adventure.pointer.Pointers adventure$pointers; // Paper - implement pointers
|
||||
|
||||
public CraftEntity(final CraftServer server, final Entity entity) {
|
||||
this.server = server;
|
||||
@ -526,6 +527,32 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
||||
return this.getHandle().getVehicle().getBukkitEntity();
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component customName() {
|
||||
final Component name = this.getHandle().getCustomName();
|
||||
return name != null ? io.papermc.paper.adventure.PaperAdventure.asAdventure(name) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customName(final net.kyori.adventure.text.Component customName) {
|
||||
this.getHandle().setCustomName(customName != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(customName) : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.pointer.Pointers pointers() {
|
||||
if (this.adventure$pointers == null) {
|
||||
this.adventure$pointers = net.kyori.adventure.pointer.Pointers.builder()
|
||||
.withDynamic(net.kyori.adventure.identity.Identity.DISPLAY_NAME, this::name)
|
||||
.withDynamic(net.kyori.adventure.identity.Identity.UUID, this::getUniqueId)
|
||||
.withStatic(net.kyori.adventure.permission.PermissionChecker.POINTER, this::permissionValue)
|
||||
.build();
|
||||
}
|
||||
|
||||
return this.adventure$pointers;
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public void setCustomName(String name) {
|
||||
// sane limit for name length
|
||||
@ -622,6 +649,17 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
|
||||
public String getName() {
|
||||
return CraftChatMessage.fromComponent(this.getHandle().getName());
|
||||
}
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.@org.jetbrains.annotations.NotNull Component name() {
|
||||
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.getHandle().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.@org.jetbrains.annotations.NotNull Component teamDisplayName() {
|
||||
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.getHandle().getDisplayName());
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(String name) {
|
||||
|
@ -330,9 +330,12 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||
container = CraftEventFactory.callInventoryOpenEvent(player, container);
|
||||
if (container == null) return;
|
||||
|
||||
String title = container.getBukkitView().getTitle();
|
||||
//String title = container.getBukkitView().getTitle(); // Paper - comment
|
||||
net.kyori.adventure.text.Component adventure$title = container.getBukkitView().title(); // Paper
|
||||
if (adventure$title == null) adventure$title = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(container.getBukkitView().getTitle()); // Paper
|
||||
|
||||
player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0]));
|
||||
//player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0])); // Paper - comment
|
||||
player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, io.papermc.paper.adventure.PaperAdventure.asVanilla(adventure$title))); // Paper
|
||||
player.containerMenu = container;
|
||||
player.initMenu(container);
|
||||
}
|
||||
@ -402,8 +405,12 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||
|
||||
// Now open the window
|
||||
MenuType<?> windowType = CraftContainer.getNotchInventoryType(inventory.getTopInventory());
|
||||
String title = inventory.getTitle();
|
||||
player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0]));
|
||||
|
||||
//String title = inventory.getTitle(); // Paper - comment
|
||||
net.kyori.adventure.text.Component adventure$title = inventory.title(); // Paper
|
||||
if (adventure$title == null) adventure$title = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(inventory.getTitle()); // Paper
|
||||
//player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0])); // Paper - comment
|
||||
player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, io.papermc.paper.adventure.PaperAdventure.asVanilla(adventure$title))); // Paper
|
||||
player.containerMenu = container;
|
||||
player.initMenu(container);
|
||||
}
|
||||
|
@ -59,6 +59,13 @@ public class CraftMinecartCommand extends CraftMinecart implements CommandMineca
|
||||
return CraftChatMessage.fromComponent(this.getHandle().getCommandBlock().getName());
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.@org.jetbrains.annotations.NotNull Component name() {
|
||||
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.getHandle().getCommandBlock().getName());
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public boolean isOp() {
|
||||
return true;
|
||||
|
@ -395,14 +395,40 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
if(true) return io.papermc.paper.adventure.DisplayNames.getLegacy(this); // Paper
|
||||
return this.getHandle().displayName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDisplayName(final String name) {
|
||||
this.getHandle().adventure$displayName = name != null ? net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(name) : net.kyori.adventure.text.Component.text(this.getName()); // Paper
|
||||
this.getHandle().displayName = name == null ? this.getName() : name;
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public void playerListName(net.kyori.adventure.text.Component name) {
|
||||
getHandle().listName = name == null ? null : io.papermc.paper.adventure.PaperAdventure.asVanilla(name);
|
||||
if (getHandle().connection == null) return; // Updates are possible before the player has fully joined
|
||||
for (ServerPlayer player : server.getHandle().players) {
|
||||
if (player.getBukkitEntity().canSee(this)) {
|
||||
player.connection.send(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_DISPLAY_NAME, getHandle()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component playerListName() {
|
||||
return getHandle().listName == null ? net.kyori.adventure.text.Component.text(getName()) : io.papermc.paper.adventure.PaperAdventure.asAdventure(getHandle().listName);
|
||||
}
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component playerListHeader() {
|
||||
return playerListHeader;
|
||||
}
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component playerListFooter() {
|
||||
return playerListFooter;
|
||||
}
|
||||
// Paper end
|
||||
@Override
|
||||
public String getPlayerListName() {
|
||||
return this.getHandle().listName == null ? this.getName() : CraftChatMessage.fromComponent(this.getHandle().listName);
|
||||
@ -414,6 +440,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
name = this.getName();
|
||||
}
|
||||
this.getHandle().listName = name.equals(this.getName()) ? null : CraftChatMessage.fromStringOrNull(name);
|
||||
if (this.getHandle().connection == null) return; // Paper - Updates are possible before the player has fully joined
|
||||
for (ServerPlayer player : (List<ServerPlayer>) this.server.getHandle().players) {
|
||||
if (player.getBukkitEntity().canSee(this)) {
|
||||
player.connection.send(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_DISPLAY_NAME, this.getHandle()));
|
||||
@ -433,42 +460,42 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
this.getHandle().listOrder = order;
|
||||
}
|
||||
|
||||
private Component playerListHeader;
|
||||
private Component playerListFooter;
|
||||
private net.kyori.adventure.text.Component playerListHeader; // Paper - Adventure
|
||||
private net.kyori.adventure.text.Component playerListFooter; // Paper - Adventure
|
||||
|
||||
@Override
|
||||
public String getPlayerListHeader() {
|
||||
return (this.playerListHeader == null) ? null : CraftChatMessage.fromComponent(this.playerListHeader);
|
||||
return (this.playerListHeader == null) ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(this.playerListHeader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerListFooter() {
|
||||
return (this.playerListFooter == null) ? null : CraftChatMessage.fromComponent(this.playerListFooter);
|
||||
return (this.playerListFooter == null) ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(this.playerListFooter); // Paper - Adventure
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerListHeader(String header) {
|
||||
this.playerListHeader = CraftChatMessage.fromStringOrNull(header, true);
|
||||
this.playerListHeader = header == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(header); // Paper - Adventure
|
||||
this.updatePlayerListHeaderFooter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerListFooter(String footer) {
|
||||
this.playerListFooter = CraftChatMessage.fromStringOrNull(footer, true);
|
||||
this.playerListFooter = footer == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(footer); // Paper - Adventure
|
||||
this.updatePlayerListHeaderFooter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerListHeaderFooter(String header, String footer) {
|
||||
this.playerListHeader = CraftChatMessage.fromStringOrNull(header, true);
|
||||
this.playerListFooter = CraftChatMessage.fromStringOrNull(footer, true);
|
||||
this.playerListHeader = header == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(header); // Paper - Adventure
|
||||
this.playerListFooter = footer == null ? null : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(footer); // Paper - Adventure
|
||||
this.updatePlayerListHeaderFooter();
|
||||
}
|
||||
|
||||
private void updatePlayerListHeaderFooter() {
|
||||
if (this.getHandle().connection == null) return;
|
||||
|
||||
ClientboundTabListPacket packet = new ClientboundTabListPacket((this.playerListHeader == null) ? Component.empty() : this.playerListHeader, (this.playerListFooter == null) ? Component.empty() : this.playerListFooter);
|
||||
ClientboundTabListPacket packet = new ClientboundTabListPacket(io.papermc.paper.adventure.PaperAdventure.asVanillaNullToEmpty(this.playerListHeader), io.papermc.paper.adventure.PaperAdventure.asVanillaNullToEmpty(this.playerListFooter)); // Paper - adventure
|
||||
this.getHandle().connection.send(packet);
|
||||
}
|
||||
|
||||
@ -498,6 +525,23 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
this.getHandle().transferCookieConnection.kickPlayer(CraftChatMessage.fromStringOrEmpty(message, true));
|
||||
}
|
||||
|
||||
// Paper start
|
||||
private static final net.kyori.adventure.text.Component DEFAULT_KICK_COMPONENT = net.kyori.adventure.text.Component.translatable("multiplayer.disconnect.kicked");
|
||||
@Override
|
||||
public void kick() {
|
||||
this.kick(DEFAULT_KICK_COMPONENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kick(final net.kyori.adventure.text.Component message) {
|
||||
org.spigotmc.AsyncCatcher.catchOp("player kick");
|
||||
final ServerGamePacketListenerImpl connection = this.getHandle().connection;
|
||||
if (connection != null) {
|
||||
connection.disconnect(message == null ? net.kyori.adventure.text.Component.empty() : message);
|
||||
}
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public void setCompassTarget(Location loc) {
|
||||
Preconditions.checkArgument(loc != null, "Location cannot be null");
|
||||
@ -794,6 +838,24 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
this.getHandle().connection.send(packet);
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public void sendSignChange(Location loc, @Nullable List<? extends net.kyori.adventure.text.Component> lines, DyeColor dyeColor, boolean hasGlowingText) {
|
||||
if (getHandle().connection == null) {
|
||||
return;
|
||||
}
|
||||
if (lines == null) {
|
||||
lines = new java.util.ArrayList<>(4);
|
||||
}
|
||||
Preconditions.checkArgument(loc != null, "Location cannot be null");
|
||||
Preconditions.checkArgument(dyeColor != null, "DyeColor cannot be null");
|
||||
if (lines.size() < 4) {
|
||||
throw new IllegalArgumentException("Must have at least 4 lines");
|
||||
}
|
||||
Component[] components = CraftSign.sanitizeLines(lines);
|
||||
this.sendSignChange0(components, loc, dyeColor, hasGlowingText);
|
||||
}
|
||||
// Paper end
|
||||
@Override
|
||||
public void sendSignChange(Location loc, String[] lines) {
|
||||
this.sendSignChange(loc, lines, DyeColor.BLACK);
|
||||
@ -817,6 +879,12 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
if (this.getHandle().connection == null) return;
|
||||
|
||||
Component[] components = CraftSign.sanitizeLines(lines);
|
||||
// Paper start - adventure
|
||||
this.sendSignChange0(components, loc, dyeColor, hasGlowingText);
|
||||
}
|
||||
|
||||
private void sendSignChange0(Component[] components, Location loc, DyeColor dyeColor, boolean hasGlowingText) {
|
||||
// Paper end
|
||||
SignBlockEntity sign = new SignBlockEntity(CraftLocation.toBlockPosition(loc), Blocks.OAK_SIGN.defaultBlockState());
|
||||
SignText text = sign.getFrontText();
|
||||
text = text.setColor(net.minecraft.world.item.DyeColor.byId(dyeColor.getWoolData()));
|
||||
@ -1843,7 +1911,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
|
||||
@Override
|
||||
public void setResourcePack(String url) {
|
||||
this.setResourcePack(url, null);
|
||||
this.setResourcePack(url, (byte[]) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1858,7 +1926,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
|
||||
@Override
|
||||
public void setResourcePack(String url, byte[] hash, boolean force) {
|
||||
this.setResourcePack(url, hash, null, force);
|
||||
this.setResourcePack(url, hash, (String) null, force);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1895,6 +1963,59 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
this.handlePushResourcePack(new ClientboundResourcePackPushPacket(id, url, hashStr, force, CraftChatMessage.fromStringOrOptional(prompt, true)), false);
|
||||
}
|
||||
|
||||
// Paper start - adventure
|
||||
@Override
|
||||
public void setResourcePack(final UUID uuid, final String url, final byte[] hashBytes, final net.kyori.adventure.text.Component prompt, final boolean force) {
|
||||
Preconditions.checkArgument(uuid != null, "Resource pack UUID cannot be null");
|
||||
Preconditions.checkArgument(url != null, "Resource pack URL cannot be null");
|
||||
final String hash;
|
||||
if (hashBytes != null) {
|
||||
Preconditions.checkArgument(hashBytes.length == 20, "Resource pack hash should be 20 bytes long but was " + hashBytes.length);
|
||||
hash = BaseEncoding.base16().lowerCase().encode(hashBytes);
|
||||
} else {
|
||||
hash = "";
|
||||
}
|
||||
this.getHandle().connection.send(new ClientboundResourcePackPopPacket(Optional.empty()));
|
||||
this.getHandle().connection.send(new ClientboundResourcePackPushPacket(uuid, url, hash, force, Optional.ofNullable(prompt).map(io.papermc.paper.adventure.PaperAdventure::asVanilla)));
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
void sendBundle(final List<? extends net.minecraft.network.protocol.Packet<? extends net.minecraft.network.protocol.common.ClientCommonPacketListener>> packet) {
|
||||
this.getHandle().connection.send(new net.minecraft.network.protocol.game.ClientboundBundlePacket((List) packet));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendResourcePacks(final net.kyori.adventure.resource.ResourcePackRequest request) {
|
||||
if (this.getHandle().connection == null) return;
|
||||
final List<ClientboundResourcePackPushPacket> packs = new java.util.ArrayList<>(request.packs().size());
|
||||
if (request.replace()) {
|
||||
this.clearResourcePacks();
|
||||
}
|
||||
final Component prompt = io.papermc.paper.adventure.PaperAdventure.asVanilla(request.prompt());
|
||||
for (final java.util.Iterator<net.kyori.adventure.resource.ResourcePackInfo> iter = request.packs().iterator(); iter.hasNext();) {
|
||||
final net.kyori.adventure.resource.ResourcePackInfo pack = iter.next();
|
||||
packs.add(new ClientboundResourcePackPushPacket(pack.id(), pack.uri().toASCIIString(), pack.hash(), request.required(), iter.hasNext() ? Optional.empty() : Optional.ofNullable(prompt)));
|
||||
if (request.callback() != net.kyori.adventure.resource.ResourcePackCallback.noOp()) {
|
||||
this.getHandle().connection.packCallbacks.put(pack.id(), request.callback()); // just override if there is a previously existing callback
|
||||
}
|
||||
}
|
||||
this.sendBundle(packs);
|
||||
super.sendResourcePacks(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeResourcePacks(final UUID id, final UUID ... others) {
|
||||
if (this.getHandle().connection == null) return;
|
||||
this.sendBundle(net.kyori.adventure.util.MonkeyBars.nonEmptyArrayToList(pack -> new ClientboundResourcePackPopPacket(Optional.of(pack)), id, others));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearResourcePacks() {
|
||||
if (this.getHandle().connection == null) return;
|
||||
this.getHandle().connection.send(new ClientboundResourcePackPopPacket(Optional.empty()));
|
||||
}
|
||||
// Paper end - adventure
|
||||
|
||||
@Override
|
||||
public void removeResourcePack(UUID id) {
|
||||
Preconditions.checkArgument(id != null, "Resource pack id cannot be null");
|
||||
@ -2300,6 +2421,12 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
return (this.getHandle().requestedViewDistance() == 0) ? Bukkit.getViewDistance() : this.getHandle().requestedViewDistance();
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public java.util.Locale locale() {
|
||||
return getHandle().adventure$locale;
|
||||
}
|
||||
// Paper end
|
||||
@Override
|
||||
public int getPing() {
|
||||
return this.getHandle().connection.latency();
|
||||
@ -2350,6 +2477,248 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
return this.getHandle().allowsListing();
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component displayName() {
|
||||
return this.getHandle().adventure$displayName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayName(final net.kyori.adventure.text.Component displayName) {
|
||||
this.getHandle().adventure$displayName = displayName != null ? displayName : net.kyori.adventure.text.Component.text(this.getName());
|
||||
this.getHandle().displayName = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteMessage(net.kyori.adventure.chat.SignedMessage.Signature signature) {
|
||||
if (getHandle().connection == null) return;
|
||||
net.minecraft.network.chat.MessageSignature sig = new net.minecraft.network.chat.MessageSignature(signature.bytes());
|
||||
|
||||
this.getHandle().connection.send(new net.minecraft.network.protocol.game.ClientboundDeleteChatPacket(new net.minecraft.network.chat.MessageSignature.Packed(sig)));
|
||||
}
|
||||
|
||||
private net.minecraft.network.chat.ChatType.Bound toHandle(net.kyori.adventure.chat.ChatType.Bound boundChatType) {
|
||||
net.minecraft.core.Registry<net.minecraft.network.chat.ChatType> chatTypeRegistry = this.getHandle().level().registryAccess().lookupOrThrow(net.minecraft.core.registries.Registries.CHAT_TYPE);
|
||||
|
||||
return new net.minecraft.network.chat.ChatType.Bound(
|
||||
chatTypeRegistry.getOrThrow(net.minecraft.resources.ResourceKey.create(net.minecraft.core.registries.Registries.CHAT_TYPE, io.papermc.paper.adventure.PaperAdventure.asVanilla(boundChatType.type().key()))),
|
||||
io.papermc.paper.adventure.PaperAdventure.asVanilla(boundChatType.name()),
|
||||
Optional.ofNullable(io.papermc.paper.adventure.PaperAdventure.asVanilla(boundChatType.target()))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(net.kyori.adventure.text.Component message, net.kyori.adventure.chat.ChatType.Bound boundChatType) {
|
||||
if (getHandle().connection == null) return;
|
||||
|
||||
net.minecraft.network.chat.Component component = io.papermc.paper.adventure.PaperAdventure.asVanilla(message);
|
||||
this.getHandle().sendChatMessage(new net.minecraft.network.chat.OutgoingChatMessage.Disguised(component), this.getHandle().isTextFilteringEnabled(), this.toHandle(boundChatType));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(net.kyori.adventure.chat.SignedMessage signedMessage, net.kyori.adventure.chat.ChatType.Bound boundChatType) {
|
||||
if (getHandle().connection == null) return;
|
||||
|
||||
if (signedMessage instanceof PlayerChatMessage.AdventureView view) {
|
||||
this.getHandle().sendChatMessage(net.minecraft.network.chat.OutgoingChatMessage.create(view.playerChatMessage()), this.getHandle().isTextFilteringEnabled(), this.toHandle(boundChatType));
|
||||
return;
|
||||
}
|
||||
net.kyori.adventure.text.Component message = signedMessage.unsignedContent() == null ? net.kyori.adventure.text.Component.text(signedMessage.message()) : signedMessage.unsignedContent();
|
||||
if (signedMessage.isSystem()) {
|
||||
this.sendMessage(message, boundChatType);
|
||||
} else {
|
||||
super.sendMessage(signedMessage, boundChatType);
|
||||
}
|
||||
// net.minecraft.network.chat.PlayerChatMessage playerChatMessage = new net.minecraft.network.chat.PlayerChatMessage(
|
||||
// null, // TODO:
|
||||
// new net.minecraft.network.chat.MessageSignature(signedMessage.signature().bytes()),
|
||||
// null, // TODO
|
||||
// io.papermc.paper.adventure.PaperAdventure.asVanilla(signedMessage.unsignedContent()),
|
||||
// net.minecraft.network.chat.FilterMask.PASS_THROUGH
|
||||
// );
|
||||
//
|
||||
// this.getHandle().sendChatMessage(net.minecraft.network.chat.OutgoingChatMessage.create(playerChatMessage), this.getHandle().isTextFilteringEnabled(), this.toHandle(boundChatType));
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
@Override
|
||||
public void sendMessage(final net.kyori.adventure.identity.Identity identity, final net.kyori.adventure.text.Component message, final net.kyori.adventure.audience.MessageType type) {
|
||||
if (getHandle().connection == null) return;
|
||||
final net.minecraft.core.Registry<net.minecraft.network.chat.ChatType> chatTypeRegistry = this.getHandle().level().registryAccess().lookupOrThrow(net.minecraft.core.registries.Registries.CHAT_TYPE);
|
||||
this.getHandle().connection.send(new net.minecraft.network.protocol.game.ClientboundSystemChatPacket(message, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendActionBar(final net.kyori.adventure.text.Component message) {
|
||||
final net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket packet = new net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket(io.papermc.paper.adventure.PaperAdventure.asVanillaNullToEmpty(message));
|
||||
this.getHandle().connection.send(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPlayerListHeader(final net.kyori.adventure.text.Component header) {
|
||||
this.playerListHeader = header;
|
||||
this.adventure$sendPlayerListHeaderAndFooter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPlayerListFooter(final net.kyori.adventure.text.Component footer) {
|
||||
this.playerListFooter = footer;
|
||||
this.adventure$sendPlayerListHeaderAndFooter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPlayerListHeaderAndFooter(final net.kyori.adventure.text.Component header, final net.kyori.adventure.text.Component footer) {
|
||||
this.playerListHeader = header;
|
||||
this.playerListFooter = footer;
|
||||
this.adventure$sendPlayerListHeaderAndFooter();
|
||||
}
|
||||
|
||||
private void adventure$sendPlayerListHeaderAndFooter() {
|
||||
final ServerGamePacketListenerImpl connection = this.getHandle().connection;
|
||||
if (connection == null) return;
|
||||
final ClientboundTabListPacket packet = new ClientboundTabListPacket(
|
||||
io.papermc.paper.adventure.PaperAdventure.asVanillaNullToEmpty(this.playerListHeader),
|
||||
io.papermc.paper.adventure.PaperAdventure.asVanillaNullToEmpty(this.playerListFooter)
|
||||
);
|
||||
connection.send(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showTitle(final net.kyori.adventure.title.Title title) {
|
||||
final ServerGamePacketListenerImpl connection = this.getHandle().connection;
|
||||
final net.kyori.adventure.title.Title.Times times = title.times();
|
||||
if (times != null) {
|
||||
connection.send(new ClientboundSetTitlesAnimationPacket(ticks(times.fadeIn()), ticks(times.stay()), ticks(times.fadeOut())));
|
||||
}
|
||||
final ClientboundSetSubtitleTextPacket sp = new ClientboundSetSubtitleTextPacket(io.papermc.paper.adventure.PaperAdventure.asVanilla(title.subtitle()));
|
||||
connection.send(sp);
|
||||
final ClientboundSetTitleTextPacket tp = new ClientboundSetTitleTextPacket(io.papermc.paper.adventure.PaperAdventure.asVanilla(title.title()));
|
||||
connection.send(tp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void sendTitlePart(final net.kyori.adventure.title.TitlePart<T> part, T value) {
|
||||
java.util.Objects.requireNonNull(part, "part");
|
||||
java.util.Objects.requireNonNull(value, "value");
|
||||
if (part == net.kyori.adventure.title.TitlePart.TITLE) {
|
||||
final ClientboundSetTitleTextPacket tp = new ClientboundSetTitleTextPacket(io.papermc.paper.adventure.PaperAdventure.asVanilla((net.kyori.adventure.text.Component)value));
|
||||
this.getHandle().connection.send(tp);
|
||||
} else if (part == net.kyori.adventure.title.TitlePart.SUBTITLE) {
|
||||
final ClientboundSetSubtitleTextPacket sp = new ClientboundSetSubtitleTextPacket(io.papermc.paper.adventure.PaperAdventure.asVanilla((net.kyori.adventure.text.Component)value));
|
||||
this.getHandle().connection.send(sp);
|
||||
} else if (part == net.kyori.adventure.title.TitlePart.TIMES) {
|
||||
final net.kyori.adventure.title.Title.Times times = (net.kyori.adventure.title.Title.Times) value;
|
||||
this.getHandle().connection.send(new ClientboundSetTitlesAnimationPacket(ticks(times.fadeIn()), ticks(times.stay()), ticks(times.fadeOut())));
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown TitlePart");
|
||||
}
|
||||
}
|
||||
|
||||
private static int ticks(final java.time.Duration duration) {
|
||||
if (duration == null) {
|
||||
return -1;
|
||||
}
|
||||
return (int) (duration.toMillis() / 50L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearTitle() {
|
||||
this.getHandle().connection.send(new net.minecraft.network.protocol.game.ClientboundClearTitlesPacket(false));
|
||||
}
|
||||
|
||||
// resetTitle implemented above
|
||||
|
||||
private @Nullable Set<net.kyori.adventure.bossbar.BossBar> activeBossBars;
|
||||
|
||||
@Override
|
||||
public @NotNull Iterable<? extends net.kyori.adventure.bossbar.BossBar> activeBossBars() {
|
||||
if (this.activeBossBars != null) {
|
||||
return java.util.Collections.unmodifiableSet(this.activeBossBars);
|
||||
}
|
||||
return Set.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showBossBar(final net.kyori.adventure.bossbar.BossBar bar) {
|
||||
net.kyori.adventure.bossbar.BossBarImplementation.get(bar, io.papermc.paper.adventure.BossBarImplementationImpl.class).playerShow(this);
|
||||
if (this.activeBossBars == null) {
|
||||
this.activeBossBars = new HashSet<>();
|
||||
}
|
||||
this.activeBossBars.add(bar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideBossBar(final net.kyori.adventure.bossbar.BossBar bar) {
|
||||
net.kyori.adventure.bossbar.BossBarImplementation.get(bar, io.papermc.paper.adventure.BossBarImplementationImpl.class).playerHide(this);
|
||||
if (this.activeBossBars != null) {
|
||||
this.activeBossBars.remove(bar);
|
||||
if (this.activeBossBars.isEmpty()) {
|
||||
this.activeBossBars = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(final net.kyori.adventure.sound.Sound sound) {
|
||||
final net.minecraft.world.phys.Vec3 pos = this.getHandle().position();
|
||||
this.playSound(sound, pos.x, pos.y, pos.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(final net.kyori.adventure.sound.Sound sound, final double x, final double y, final double z) {
|
||||
this.getHandle().connection.send(io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, x, y, z, sound.seed().orElseGet(this.getHandle().getRandom()::nextLong), null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(final net.kyori.adventure.sound.Sound sound, final net.kyori.adventure.sound.Sound.Emitter emitter) {
|
||||
final Entity entity;
|
||||
if (emitter == net.kyori.adventure.sound.Sound.Emitter.self()) {
|
||||
entity = this.getHandle();
|
||||
} else if (emitter instanceof CraftEntity craftEntity) {
|
||||
entity = craftEntity.getHandle();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Sound emitter must be an Entity or self(), but was: " + emitter);
|
||||
}
|
||||
this.getHandle().connection.send(io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, entity, sound.seed().orElseGet(this.getHandle().getRandom()::nextLong), null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopSound(final net.kyori.adventure.sound.SoundStop stop) {
|
||||
this.getHandle().connection.send(new ClientboundStopSoundPacket(
|
||||
io.papermc.paper.adventure.PaperAdventure.asVanillaNullable(stop.sound()),
|
||||
io.papermc.paper.adventure.PaperAdventure.asVanillaNullable(stop.source())
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openBook(final net.kyori.adventure.inventory.Book book) {
|
||||
final java.util.Locale locale = this.getHandle().adventure$locale;
|
||||
final net.minecraft.world.item.ItemStack item = io.papermc.paper.adventure.PaperAdventure.asItemStack(book, locale);
|
||||
final ServerPlayer player = this.getHandle();
|
||||
final ServerGamePacketListenerImpl connection = player.connection;
|
||||
final net.minecraft.world.entity.player.Inventory inventory = player.getInventory();
|
||||
final int slot = inventory.items.size() + inventory.selected;
|
||||
final int stateId = getHandle().containerMenu.getStateId();
|
||||
connection.send(new net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket(0, stateId, slot, item));
|
||||
connection.send(new net.minecraft.network.protocol.game.ClientboundOpenBookPacket(net.minecraft.world.InteractionHand.MAIN_HAND));
|
||||
connection.send(new net.minecraft.network.protocol.game.ClientboundContainerSetSlotPacket(0, stateId, slot, inventory.getSelected()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.pointer.Pointers pointers() {
|
||||
if (this.adventure$pointers == null) {
|
||||
this.adventure$pointers = net.kyori.adventure.pointer.Pointers.builder()
|
||||
.withDynamic(net.kyori.adventure.identity.Identity.DISPLAY_NAME, this::displayName)
|
||||
.withDynamic(net.kyori.adventure.identity.Identity.NAME, this::getName)
|
||||
.withDynamic(net.kyori.adventure.identity.Identity.UUID, this::getUniqueId)
|
||||
.withStatic(net.kyori.adventure.permission.PermissionChecker.POINTER, this::permissionValue)
|
||||
.withDynamic(net.kyori.adventure.identity.Identity.LOCALE, this::locale)
|
||||
.build();
|
||||
}
|
||||
|
||||
return this.adventure$pointers;
|
||||
}
|
||||
// Paper end
|
||||
// Spigot start
|
||||
private final Player.Spigot spigot = new Player.Spigot()
|
||||
{
|
||||
|
@ -32,6 +32,17 @@ public class CraftTextDisplay extends CraftDisplay implements TextDisplay {
|
||||
public void setText(String text) {
|
||||
this.getHandle().setText(CraftChatMessage.fromString(text, true)[0]);
|
||||
}
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component text() {
|
||||
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.getHandle().getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void text(net.kyori.adventure.text.Component text) {
|
||||
this.getHandle().setText(text == null ? net.minecraft.network.chat.Component.empty() : io.papermc.paper.adventure.PaperAdventure.asVanilla(text));
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public int getLineWidth() {
|
||||
|
@ -915,7 +915,7 @@ public class CraftEventFactory {
|
||||
return event;
|
||||
}
|
||||
|
||||
public static PlayerDeathEvent callPlayerDeathEvent(ServerPlayer victim, DamageSource damageSource, List<org.bukkit.inventory.ItemStack> drops, String deathMessage, boolean keepInventory) {
|
||||
public static PlayerDeathEvent callPlayerDeathEvent(ServerPlayer victim, DamageSource damageSource, List<org.bukkit.inventory.ItemStack> drops, net.kyori.adventure.text.Component deathMessage, boolean keepInventory) { // Paper - Adventure
|
||||
CraftPlayer entity = victim.getBukkitEntity();
|
||||
CraftDamageSource bukkitDamageSource = new CraftDamageSource(damageSource);
|
||||
PlayerDeathEvent event = new PlayerDeathEvent(entity, bukkitDamageSource, drops, victim.getExpReward(victim.serverLevel(), damageSource.getEntity()), 0, deathMessage);
|
||||
@ -948,7 +948,7 @@ public class CraftEventFactory {
|
||||
* Server methods
|
||||
*/
|
||||
public static ServerListPingEvent callServerListPingEvent(SocketAddress address, String motd, int numPlayers, int maxPlayers) {
|
||||
ServerListPingEvent event = new ServerListPingEvent("", ((InetSocketAddress) address).getAddress(), motd, numPlayers, maxPlayers);
|
||||
ServerListPingEvent event = new ServerListPingEvent("", ((InetSocketAddress) address).getAddress(), Bukkit.getServer().motd(), numPlayers, maxPlayers);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
return event;
|
||||
}
|
||||
|
@ -72,6 +72,13 @@ public class CraftContainer extends AbstractContainerMenu {
|
||||
return inventory.getType();
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component title() {
|
||||
return inventory instanceof CraftInventoryCustom ? ((CraftInventoryCustom.MinecraftInventory) ((CraftInventory) inventory).getInventory()).title() : net.kyori.adventure.text.Component.text(inventory.getType().getDefaultTitle());
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
|
@ -19,6 +19,12 @@ public class CraftInventoryCustom extends CraftInventory {
|
||||
super(new MinecraftInventory(owner, type));
|
||||
}
|
||||
|
||||
// Paper start
|
||||
public CraftInventoryCustom(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
|
||||
super(new MinecraftInventory(owner, type, title));
|
||||
}
|
||||
// Paper end
|
||||
|
||||
public CraftInventoryCustom(InventoryHolder owner, InventoryType type, String title) {
|
||||
super(new MinecraftInventory(owner, type, title));
|
||||
}
|
||||
@ -27,6 +33,12 @@ public class CraftInventoryCustom extends CraftInventory {
|
||||
super(new MinecraftInventory(owner, size));
|
||||
}
|
||||
|
||||
// Paper start
|
||||
public CraftInventoryCustom(InventoryHolder owner, int size, net.kyori.adventure.text.Component title) {
|
||||
super(new MinecraftInventory(owner, size, title));
|
||||
}
|
||||
// Paper end
|
||||
|
||||
public CraftInventoryCustom(InventoryHolder owner, int size, String title) {
|
||||
super(new MinecraftInventory(owner, size, title));
|
||||
}
|
||||
@ -36,9 +48,17 @@ public class CraftInventoryCustom extends CraftInventory {
|
||||
private int maxStack = MAX_STACK;
|
||||
private final List<HumanEntity> viewers;
|
||||
private final String title;
|
||||
private final net.kyori.adventure.text.Component adventure$title; // Paper
|
||||
private InventoryType type;
|
||||
private final InventoryHolder owner;
|
||||
|
||||
// Paper start
|
||||
public MinecraftInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
|
||||
this(owner, type.getDefaultSize(), title);
|
||||
this.type = type;
|
||||
}
|
||||
// Paper end
|
||||
|
||||
public MinecraftInventory(InventoryHolder owner, InventoryType type) {
|
||||
this(owner, type.getDefaultSize(), type.getDefaultTitle());
|
||||
this.type = type;
|
||||
@ -57,11 +77,24 @@ public class CraftInventoryCustom extends CraftInventory {
|
||||
Preconditions.checkArgument(title != null, "title cannot be null");
|
||||
this.items = NonNullList.withSize(size, ItemStack.EMPTY);
|
||||
this.title = title;
|
||||
this.adventure$title = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(title);
|
||||
this.viewers = new ArrayList<HumanEntity>();
|
||||
this.owner = owner;
|
||||
this.type = InventoryType.CHEST;
|
||||
}
|
||||
|
||||
// Paper start
|
||||
public MinecraftInventory(final InventoryHolder owner, final int size, final net.kyori.adventure.text.Component title) {
|
||||
Preconditions.checkArgument(title != null, "Title cannot be null");
|
||||
this.items = NonNullList.withSize(size, ItemStack.EMPTY);
|
||||
this.title = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(title);
|
||||
this.adventure$title = title;
|
||||
this.viewers = new ArrayList<HumanEntity>();
|
||||
this.owner = owner;
|
||||
this.type = InventoryType.CHEST;
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public int getContainerSize() {
|
||||
return this.items.size();
|
||||
@ -183,6 +216,12 @@ public class CraftInventoryCustom extends CraftInventory {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Paper start
|
||||
public net.kyori.adventure.text.Component title() {
|
||||
return this.adventure$title;
|
||||
}
|
||||
// Paper end
|
||||
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
@ -73,6 +73,13 @@ public class CraftInventoryView<T extends AbstractContainerMenu, I extends Inven
|
||||
return CraftItemStack.asCraftMirror(this.container.getSlot(slot).getItem());
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component title() {
|
||||
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.container.getTitle());
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
|
@ -211,4 +211,21 @@ public final class CraftItemFactory implements ItemFactory {
|
||||
Optional<HolderSet.Named<Enchantment>> optional = (allowTreasures) ? Optional.empty() : registry.lookupOrThrow(Registries.ENCHANTMENT).get(EnchantmentTags.IN_ENCHANTING_TABLE);
|
||||
return CraftItemStack.asCraftMirror(EnchantmentHelper.enchantItem(source, craft.handle, level, registry, optional));
|
||||
}
|
||||
|
||||
// Paper start - Adventure
|
||||
@Override
|
||||
public net.kyori.adventure.text.event.HoverEvent<net.kyori.adventure.text.event.HoverEvent.ShowItem> asHoverEvent(final ItemStack item, final java.util.function.UnaryOperator<net.kyori.adventure.text.event.HoverEvent.ShowItem> op) {
|
||||
return net.kyori.adventure.text.event.HoverEvent.showItem(op.apply(
|
||||
net.kyori.adventure.text.event.HoverEvent.ShowItem.showItem(
|
||||
item.getType().getKey(),
|
||||
item.getAmount(),
|
||||
io.papermc.paper.adventure.PaperAdventure.asAdventure(CraftItemStack.unwrap(item).getComponentsPatch())) // unwrap is fine here because the components patch will be safely copied
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.@org.jetbrains.annotations.NotNull Component displayName(@org.jetbrains.annotations.NotNull ItemStack itemStack) {
|
||||
return io.papermc.paper.adventure.PaperAdventure.asAdventure(CraftItemStack.asNMSCopy(itemStack).getDisplayName());
|
||||
}
|
||||
// Paper end - Adventure
|
||||
}
|
||||
|
@ -37,6 +37,12 @@ public class CraftMenuType<V extends InventoryView> implements MenuType.Typed<V>
|
||||
|
||||
@Override
|
||||
public V create(final HumanEntity player, final String title) {
|
||||
// Paper start - adventure
|
||||
return create(player, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(title));
|
||||
}
|
||||
@Override
|
||||
public V create(final HumanEntity player, final net.kyori.adventure.text.Component title) {
|
||||
// Paper end - adventure
|
||||
Preconditions.checkArgument(player != null, "The given player must not be null");
|
||||
Preconditions.checkArgument(title != null, "The given title must not be null");
|
||||
Preconditions.checkArgument(player instanceof CraftHumanEntity, "The given player must be a CraftHumanEntity");
|
||||
@ -45,7 +51,7 @@ public class CraftMenuType<V extends InventoryView> implements MenuType.Typed<V>
|
||||
final ServerPlayer serverPlayer = (ServerPlayer) craftHuman.getHandle();
|
||||
|
||||
final AbstractContainerMenu container = this.typeData.get().menuBuilder().build(serverPlayer, this.handle);
|
||||
container.setTitle(CraftChatMessage.fromString(title)[0]);
|
||||
container.setTitle(io.papermc.paper.adventure.PaperAdventure.asVanilla(title)); // Paper - adventure
|
||||
container.checkReachable = false;
|
||||
return (V) container.getBukkitView();
|
||||
}
|
||||
|
@ -15,10 +15,17 @@ public class CraftMerchantCustom implements CraftMerchant {
|
||||
|
||||
private MinecraftMerchant merchant;
|
||||
|
||||
@Deprecated // Paper - Adventure
|
||||
public CraftMerchantCustom(String title) {
|
||||
this.merchant = new MinecraftMerchant(title);
|
||||
this.getMerchant().craftMerchant = this;
|
||||
}
|
||||
// Paper start
|
||||
public CraftMerchantCustom(net.kyori.adventure.text.Component title) {
|
||||
this.merchant = new MinecraftMerchant(title);
|
||||
getMerchant().craftMerchant = this;
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@ -37,10 +44,17 @@ public class CraftMerchantCustom implements CraftMerchant {
|
||||
private Player tradingPlayer;
|
||||
protected CraftMerchant craftMerchant;
|
||||
|
||||
@Deprecated // Paper - Adventure
|
||||
public MinecraftMerchant(String title) {
|
||||
Preconditions.checkArgument(title != null, "Title cannot be null");
|
||||
this.title = CraftChatMessage.fromString(title)[0];
|
||||
}
|
||||
// Paper start
|
||||
public MinecraftMerchant(net.kyori.adventure.text.Component title) {
|
||||
Preconditions.checkArgument(title != null, "Title cannot be null");
|
||||
this.title = io.papermc.paper.adventure.PaperAdventure.asVanilla(title);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public CraftMerchant getCraftMerchant() {
|
||||
|
@ -2,8 +2,9 @@ package org.bukkit.craftbukkit.inventory;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import com.google.common.collect.ImmutableMap; // Paper
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -170,6 +171,128 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta, WritableBo
|
||||
public void setGeneration(Generation generation) {
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component title() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.meta.BookMeta title(net.kyori.adventure.text.Component title) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component author() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.meta.BookMeta author(net.kyori.adventure.text.Component author) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component page(final int page) {
|
||||
Preconditions.checkArgument(this.isValidPage(page), "Invalid page number (%s/%s)", page, this.getPageCount());
|
||||
return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(this.pages.get(page - 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void page(final int page, net.kyori.adventure.text.Component data) {
|
||||
Preconditions.checkArgument(this.isValidPage(page), "Invalid page number (%s/%s)", page, this.getPageCount());
|
||||
if (data == null) {
|
||||
data = net.kyori.adventure.text.Component.empty();
|
||||
}
|
||||
this.pages.set(page - 1, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(data));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<net.kyori.adventure.text.Component> pages() {
|
||||
if (this.pages == null) return ImmutableList.of();
|
||||
return this.pages.stream().map(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection()::deserialize).collect(ImmutableList.toImmutableList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BookMeta pages(List<net.kyori.adventure.text.Component> pages) {
|
||||
if (this.pages != null) this.pages.clear();
|
||||
for (net.kyori.adventure.text.Component page : pages) {
|
||||
this.addPages(page);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BookMeta pages(net.kyori.adventure.text.Component... pages) {
|
||||
if (this.pages != null) this.pages.clear();
|
||||
this.addPages(pages);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPages(net.kyori.adventure.text.Component... pages) {
|
||||
if (this.pages == null) this.pages = new ArrayList<>();
|
||||
for (net.kyori.adventure.text.Component page : pages) {
|
||||
if (this.pages.size() >= MAX_PAGES) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (page == null) {
|
||||
page = net.kyori.adventure.text.Component.empty();
|
||||
}
|
||||
|
||||
this.pages.add(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(page));
|
||||
}
|
||||
}
|
||||
|
||||
private CraftMetaBook(List<net.kyori.adventure.text.Component> pages) {
|
||||
super((org.bukkit.craftbukkit.inventory.CraftMetaItem) org.bukkit.Bukkit.getItemFactory().getItemMeta(org.bukkit.Material.WRITABLE_BOOK));
|
||||
this.pages = pages.subList(0, Math.min(MAX_PAGES, pages.size())).stream().map(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection()::serialize).collect(java.util.stream.Collectors.toList());
|
||||
}
|
||||
|
||||
static class CraftMetaBookBuilder implements BookMetaBuilder {
|
||||
protected final List<net.kyori.adventure.text.Component> pages = new java.util.ArrayList<>();
|
||||
|
||||
@Override
|
||||
public BookMetaBuilder title(net.kyori.adventure.text.Component title) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BookMetaBuilder author(net.kyori.adventure.text.Component author) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BookMetaBuilder addPage(net.kyori.adventure.text.Component page) {
|
||||
this.pages.add(page);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BookMetaBuilder pages(net.kyori.adventure.text.Component... pages) {
|
||||
java.util.Collections.addAll(this.pages, pages);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BookMetaBuilder pages(java.util.Collection<net.kyori.adventure.text.Component> pages) {
|
||||
this.pages.addAll(pages);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BookMeta build() {
|
||||
return new CraftMetaBook(this.pages);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BookMetaBuilder toBuilder() {
|
||||
return new CraftMetaBookBuilder();
|
||||
}
|
||||
|
||||
// Paper end
|
||||
@Override
|
||||
public String getPage(final int page) {
|
||||
Preconditions.checkArgument(this.isValidPage(page), "Invalid page number (%s)", page);
|
||||
@ -286,7 +409,7 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta, WritableBo
|
||||
}
|
||||
|
||||
@Override
|
||||
Builder<String, Object> serialize(Builder<String, Object> builder) {
|
||||
ImmutableMap.Builder<String, Object> serialize(ImmutableMap.Builder<String, Object> builder) {
|
||||
super.serialize(builder);
|
||||
|
||||
if (this.pages != null) {
|
||||
|
@ -346,7 +346,7 @@ public class CraftMetaBookSigned extends CraftMetaItem implements BookMeta {
|
||||
}
|
||||
|
||||
@Override
|
||||
Builder<String, Object> serialize(Builder<String, Object> builder) {
|
||||
com.google.common.collect.ImmutableMap.Builder<String, Object> serialize(com.google.common.collect.ImmutableMap.Builder<String, Object> builder) { // Paper - adventure - fqn as it conflicts with adventure book builder
|
||||
super.serialize(builder);
|
||||
|
||||
if (this.hasTitle()) {
|
||||
@ -459,4 +459,111 @@ public class CraftMetaBookSigned extends CraftMetaItem implements BookMeta {
|
||||
return this.spigot;
|
||||
}
|
||||
// Spigot end
|
||||
|
||||
// Paper start - adventure
|
||||
public static final net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.builder()
|
||||
.character(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.SECTION_CHAR)
|
||||
.build();
|
||||
private CraftMetaBookSigned(net.kyori.adventure.text.Component title, net.kyori.adventure.text.Component author, java.util.List<net.kyori.adventure.text.Component> pages) {
|
||||
super((org.bukkit.craftbukkit.inventory.CraftMetaItem) org.bukkit.Bukkit.getItemFactory().getItemMeta(Material.WRITABLE_BOOK));
|
||||
this.title = title == null ? null : LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.serialize(title);
|
||||
this.author = author == null ? null : LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.serialize(author);
|
||||
this.pages = io.papermc.paper.adventure.PaperAdventure.asVanilla(pages.subList(0, Math.min(MAX_PAGES, pages.size())));
|
||||
}
|
||||
|
||||
static final class CraftMetaBookSignedBuilder extends CraftMetaBook.CraftMetaBookBuilder {
|
||||
private net.kyori.adventure.text.Component title;
|
||||
private net.kyori.adventure.text.Component author;
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.meta.BookMeta.BookMetaBuilder title(final net.kyori.adventure.text.Component title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.meta.BookMeta.BookMetaBuilder author(final net.kyori.adventure.text.Component author) {
|
||||
this.author = author;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.meta.BookMeta build() {
|
||||
return new CraftMetaBookSigned(this.title, this.author, this.pages);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BookMetaBuilder toBuilder() {
|
||||
return new CraftMetaBookSignedBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component title() {
|
||||
return this.title == null ? null : LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.deserialize(this.title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.meta.BookMeta title(net.kyori.adventure.text.Component title) {
|
||||
this.setTitle(title == null ? null : LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.serialize(title));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component author() {
|
||||
return this.author == null ? null : LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.deserialize(this.author);
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.inventory.meta.BookMeta author(net.kyori.adventure.text.Component author) {
|
||||
this.setAuthor(author == null ? null : LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.serialize(author));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component page(final int page) {
|
||||
Preconditions.checkArgument(this.isValidPage(page), "Invalid page number (%s/%s)", page, this.getPageCount());
|
||||
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.pages.get(page - 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void page(final int page, net.kyori.adventure.text.Component data) {
|
||||
Preconditions.checkArgument(this.isValidPage(page), "Invalid page number (%s/%s)", page, this.getPageCount());
|
||||
this.pages.set(page - 1, io.papermc.paper.adventure.PaperAdventure.asVanillaNullToEmpty(data));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<net.kyori.adventure.text.Component> pages() {
|
||||
if (this.pages == null) return ImmutableList.of();
|
||||
return this.pages.stream().map(io.papermc.paper.adventure.PaperAdventure::asAdventure).collect(ImmutableList.toImmutableList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BookMeta pages(List<net.kyori.adventure.text.Component> pages) {
|
||||
if (this.pages != null) this.pages.clear();
|
||||
for (net.kyori.adventure.text.Component page : pages) {
|
||||
this.addPages(page);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BookMeta pages(net.kyori.adventure.text.Component... pages) {
|
||||
if (this.pages != null) this.pages.clear();
|
||||
this.addPages(pages);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPages(net.kyori.adventure.text.Component... pages) {
|
||||
if (this.pages == null) this.pages = new ArrayList<>();
|
||||
for (net.kyori.adventure.text.Component page : pages) {
|
||||
if (this.pages.size() >= MAX_PAGES) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.pages.add(io.papermc.paper.adventure.PaperAdventure.asVanillaNullToEmpty(page));
|
||||
}
|
||||
}
|
||||
// Paper end
|
||||
}
|
||||
|
@ -1103,6 +1103,18 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
return !(this.hasDisplayName() || this.hasItemName() || this.hasLocalizedName() || this.hasEnchants() || (this.lore != null) || this.hasCustomModelData() || this.hasEnchantable() || this.hasBlockData() || this.hasRepairCost() || !this.unhandledTags.build().isEmpty() || !this.removedTags.isEmpty() || !this.persistentDataContainer.isEmpty() || this.hideFlag != 0 || this.isHideTooltip() || this.hasTooltipStyle() || this.hasItemModel() || this.isUnbreakable() || this.hasEnchantmentGlintOverride() || this.isGlider() || this.hasDamageResistant() || this.hasMaxStackSize() || this.hasRarity() || this.hasUseRemainder() || this.hasUseCooldown() || this.hasFood() || this.hasTool() || this.hasJukeboxPlayable() || this.hasEquippable() || this.hasDamage() || this.hasMaxDamage() || this.hasAttributeModifiers() || this.customTag != null);
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component customName() {
|
||||
return displayName == null ? null : io.papermc.paper.adventure.PaperAdventure.asAdventure(displayName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customName(final net.kyori.adventure.text.Component customName) {
|
||||
this.displayName = customName == null ? null : io.papermc.paper.adventure.PaperAdventure.asVanilla(customName);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return CraftChatMessage.fromComponent(this.displayName);
|
||||
@ -1114,7 +1126,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasDisplayName() {
|
||||
public boolean hasCustomName() {
|
||||
return this.displayName != null;
|
||||
}
|
||||
|
||||
@ -1133,6 +1145,18 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
return this.itemName != null;
|
||||
}
|
||||
|
||||
// Paper start - Adventure
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component itemName() {
|
||||
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.itemName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void itemName(final net.kyori.adventure.text.Component name) {
|
||||
this.itemName = io.papermc.paper.adventure.PaperAdventure.asVanilla(name);
|
||||
}
|
||||
// Paper end - Adventure
|
||||
|
||||
@Override
|
||||
public String getLocalizedName() {
|
||||
return this.getDisplayName();
|
||||
@ -1152,6 +1176,18 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
return this.lore != null && !this.lore.isEmpty();
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public List<net.kyori.adventure.text.Component> lore() {
|
||||
return this.lore != null ? io.papermc.paper.adventure.PaperAdventure.asAdventure(this.lore) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lore(final List<? extends net.kyori.adventure.text.Component> lore) {
|
||||
this.lore = lore != null ? io.papermc.paper.adventure.PaperAdventure.asVanilla(lore) : null;
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public boolean hasRepairCost() {
|
||||
return this.repairCost > 0;
|
||||
|
@ -109,7 +109,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
||||
|
||||
String name = SerializableMeta.getString(map, CraftMetaPotion.CUSTOM_NAME.BUKKIT, true);
|
||||
if (name != null) {
|
||||
this.setCustomName(name);
|
||||
this.setCustomPotionName(name);
|
||||
}
|
||||
|
||||
Iterable<?> rawEffectList = SerializableMeta.getObject(Iterable.class, map, CraftMetaPotion.POTION_EFFECTS.BUKKIT, true);
|
||||
@ -151,7 +151,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
||||
}
|
||||
|
||||
boolean isPotionEmpty() {
|
||||
return (this.type == null) && !(this.hasCustomEffects() || this.hasColor() || this.hasCustomName());
|
||||
return (this.type == null) && !(this.hasCustomEffects() || this.hasColor() || this.hasCustomPotionName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -306,17 +306,17 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName() {
|
||||
public boolean hasCustomPotionName() {
|
||||
return this.customName != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCustomName() {
|
||||
public String getCustomPotionName() {
|
||||
return this.customName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomName(String customName) {
|
||||
public void setCustomPotionName(String customName) {
|
||||
this.customName = customName;
|
||||
}
|
||||
|
||||
@ -330,7 +330,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
||||
if (this.hasColor()) {
|
||||
hash = 73 * hash + this.color.hashCode();
|
||||
}
|
||||
if (this.hasCustomName()) {
|
||||
if (this.hasCustomPotionName()) {
|
||||
hash = 73 * hash + this.customName.hashCode();
|
||||
}
|
||||
if (this.hasCustomEffects()) {
|
||||
@ -350,7 +350,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
||||
return Objects.equals(this.type, that.type)
|
||||
&& (this.hasCustomEffects() ? that.hasCustomEffects() && this.customEffects.equals(that.customEffects) : !that.hasCustomEffects())
|
||||
&& (this.hasColor() ? that.hasColor() && this.color.equals(that.color) : !that.hasColor())
|
||||
&& (this.hasCustomName() ? that.hasCustomName() && this.customName.equals(that.customName) : !that.hasCustomName());
|
||||
&& (this.hasCustomPotionName() ? that.hasCustomPotionName() && this.customName.equals(that.customName) : !that.hasCustomPotionName());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -371,8 +371,8 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
||||
builder.put(CraftMetaPotion.POTION_COLOR.BUKKIT, this.getColor());
|
||||
}
|
||||
|
||||
if (this.hasCustomName()) {
|
||||
builder.put(CraftMetaPotion.CUSTOM_NAME.BUKKIT, this.getCustomName());
|
||||
if (this.hasCustomPotionName()) {
|
||||
builder.put(CraftMetaPotion.CUSTOM_NAME.BUKKIT, this.getCustomPotionName());
|
||||
}
|
||||
|
||||
if (this.hasCustomEffects()) {
|
||||
|
@ -60,6 +60,14 @@ public class CraftTrimMaterial implements TrimMaterial, Handleable<net.minecraft
|
||||
@NotNull
|
||||
@Override
|
||||
public String getTranslationKey() {
|
||||
if (!(this.handle.description().getContents() instanceof TranslatableContents)) throw new UnsupportedOperationException("Description isn't translatable!"); // Paper
|
||||
return ((TranslatableContents) this.handle.description().getContents()).getKey();
|
||||
}
|
||||
|
||||
// Paper start - adventure
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component description() {
|
||||
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.handle.description());
|
||||
}
|
||||
// Paper end - adventure
|
||||
}
|
||||
|
@ -60,6 +60,14 @@ public class CraftTrimPattern implements TrimPattern, Handleable<net.minecraft.w
|
||||
@NotNull
|
||||
@Override
|
||||
public String getTranslationKey() {
|
||||
if (!(this.handle.description().getContents() instanceof TranslatableContents)) throw new UnsupportedOperationException("Description isn't translatable!"); // Paper
|
||||
return ((TranslatableContents) this.handle.description().getContents()).getKey();
|
||||
}
|
||||
|
||||
// Paper start - adventure
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component description() {
|
||||
return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.handle.description());
|
||||
}
|
||||
// Paper end - adventure
|
||||
}
|
||||
|
@ -12,6 +12,13 @@ public class CraftCustomInventoryConverter implements CraftInventoryCreator.Inve
|
||||
return new CraftInventoryCustom(holder, type);
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
|
||||
return new CraftInventoryCustom(owner, type, title);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public Inventory createInventory(InventoryHolder owner, InventoryType type, String title) {
|
||||
return new CraftInventoryCustom(owner, type, title);
|
||||
@ -21,6 +28,12 @@ public class CraftCustomInventoryConverter implements CraftInventoryCreator.Inve
|
||||
return new CraftInventoryCustom(owner, size);
|
||||
}
|
||||
|
||||
// Paper start
|
||||
public Inventory createInventory(InventoryHolder owner, int size, net.kyori.adventure.text.Component title) {
|
||||
return new CraftInventoryCustom(owner, size, title);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
public Inventory createInventory(InventoryHolder owner, int size, String title) {
|
||||
return new CraftInventoryCustom(owner, size, title);
|
||||
}
|
||||
|
@ -45,6 +45,12 @@ public final class CraftInventoryCreator {
|
||||
return this.converterMap.get(type).createInventory(holder, type);
|
||||
}
|
||||
|
||||
// Paper start
|
||||
public Inventory createInventory(InventoryHolder holder, InventoryType type, net.kyori.adventure.text.Component title) {
|
||||
return converterMap.get(type).createInventory(holder, type, title);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) {
|
||||
return this.converterMap.get(type).createInventory(holder, type, title);
|
||||
}
|
||||
@ -53,6 +59,12 @@ public final class CraftInventoryCreator {
|
||||
return this.DEFAULT_CONVERTER.createInventory(holder, size);
|
||||
}
|
||||
|
||||
// Paper start
|
||||
public Inventory createInventory(InventoryHolder holder, int size, net.kyori.adventure.text.Component title) {
|
||||
return DEFAULT_CONVERTER.createInventory(holder, size, title);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
public Inventory createInventory(InventoryHolder holder, int size, String title) {
|
||||
return this.DEFAULT_CONVERTER.createInventory(holder, size, title);
|
||||
}
|
||||
@ -61,6 +73,10 @@ public final class CraftInventoryCreator {
|
||||
|
||||
Inventory createInventory(InventoryHolder holder, InventoryType type);
|
||||
|
||||
// Paper start
|
||||
Inventory createInventory(InventoryHolder holder, InventoryType type, net.kyori.adventure.text.Component title);
|
||||
// Paper end
|
||||
|
||||
Inventory createInventory(InventoryHolder holder, InventoryType type, String title);
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,18 @@ public abstract class CraftTileInventoryConverter implements CraftInventoryCreat
|
||||
return this.getInventory(this.getTileEntity());
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
|
||||
Container te = getTileEntity();
|
||||
if (te instanceof RandomizableContainerBlockEntity) {
|
||||
((RandomizableContainerBlockEntity) te).name = io.papermc.paper.adventure.PaperAdventure.asVanilla(title);
|
||||
}
|
||||
|
||||
return getInventory(te);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) {
|
||||
Container te = this.getTileEntity();
|
||||
@ -53,6 +65,15 @@ public abstract class CraftTileInventoryConverter implements CraftInventoryCreat
|
||||
return furnace;
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
|
||||
Container tileEntity = getTileEntity();
|
||||
((AbstractFurnaceBlockEntity) tileEntity).setCustomName(io.papermc.paper.adventure.PaperAdventure.asVanilla(title));
|
||||
return getInventory(tileEntity);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public Inventory createInventory(InventoryHolder owner, InventoryType type, String title) {
|
||||
Container tileEntity = this.getTileEntity();
|
||||
@ -73,6 +94,18 @@ public abstract class CraftTileInventoryConverter implements CraftInventoryCreat
|
||||
return new BrewingStandBlockEntity(BlockPos.ZERO, Blocks.BREWING_STAND.defaultBlockState());
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public Inventory createInventory(InventoryHolder owner, InventoryType type, net.kyori.adventure.text.Component title) {
|
||||
// BrewingStand does not extend TileEntityLootable
|
||||
Container tileEntity = getTileEntity();
|
||||
if (tileEntity instanceof BrewingStandBlockEntity) {
|
||||
((BrewingStandBlockEntity) tileEntity).name = io.papermc.paper.adventure.PaperAdventure.asVanilla(title);
|
||||
}
|
||||
return getInventory(tileEntity);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public Inventory createInventory(InventoryHolder holder, InventoryType type, String title) {
|
||||
// BrewingStand does not extend TileEntityLootable
|
||||
|
@ -43,7 +43,7 @@ public class CraftMapRenderer extends MapRenderer {
|
||||
}
|
||||
|
||||
MapDecoration decoration = this.worldMap.decorations.get(key);
|
||||
cursors.addCursor(new MapCursor(decoration.x(), decoration.y(), (byte) (decoration.rot() & 15), CraftMapCursor.CraftType.minecraftHolderToBukkit(decoration.type()), true, CraftChatMessage.fromComponent(decoration.name().orElse(null))));
|
||||
cursors.addCursor(new MapCursor(decoration.x(), decoration.y(), (byte) (decoration.rot() & 15), CraftMapCursor.CraftType.minecraftHolderToBukkit(decoration.type()), true, decoration.name().isEmpty() ? null : io.papermc.paper.adventure.PaperAdventure.asAdventure(decoration.name().get()))); // Paper
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,21 @@ final class CraftObjective extends CraftScoreboardComponent implements Objective
|
||||
return this.objective.getName();
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component displayName() throws IllegalStateException {
|
||||
CraftScoreboard scoreboard = checkState();
|
||||
return io.papermc.paper.adventure.PaperAdventure.asAdventure(objective.getDisplayName());
|
||||
}
|
||||
@Override
|
||||
public void displayName(net.kyori.adventure.text.Component displayName) throws IllegalStateException, IllegalArgumentException {
|
||||
if (displayName == null) {
|
||||
displayName = net.kyori.adventure.text.Component.empty();
|
||||
}
|
||||
CraftScoreboard scoreboard = checkState();
|
||||
objective.setDisplayName(io.papermc.paper.adventure.PaperAdventure.asVanilla(displayName));
|
||||
}
|
||||
// Paper end
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
this.checkState();
|
||||
|
@ -29,6 +29,33 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
|
||||
public CraftObjective registerNewObjective(String name, String criteria) {
|
||||
return this.registerNewObjective(name, criteria, name);
|
||||
}
|
||||
// Paper start - Adventure
|
||||
@Override
|
||||
public CraftObjective registerNewObjective(String name, String criteria, net.kyori.adventure.text.Component displayName) {
|
||||
return this.registerNewObjective(name, CraftCriteria.getFromBukkit(criteria), displayName, RenderType.INTEGER);
|
||||
}
|
||||
@Override
|
||||
public CraftObjective registerNewObjective(String name, String criteria, net.kyori.adventure.text.Component displayName, RenderType renderType) {
|
||||
return this.registerNewObjective(name, CraftCriteria.getFromBukkit(criteria), displayName, renderType);
|
||||
}
|
||||
@Override
|
||||
public CraftObjective registerNewObjective(String name, Criteria criteria, net.kyori.adventure.text.Component displayName) throws IllegalArgumentException {
|
||||
return this.registerNewObjective(name, criteria, displayName, RenderType.INTEGER);
|
||||
}
|
||||
@Override
|
||||
public CraftObjective registerNewObjective(String name, Criteria criteria, net.kyori.adventure.text.Component displayName, RenderType renderType) throws IllegalArgumentException {
|
||||
if (displayName == null) {
|
||||
displayName = net.kyori.adventure.text.Component.empty();
|
||||
}
|
||||
Preconditions.checkArgument(name != null, "Objective name cannot be null");
|
||||
Preconditions.checkArgument(criteria != null, "Criteria cannot be null");
|
||||
Preconditions.checkArgument(renderType != null, "RenderType cannot be null");
|
||||
Preconditions.checkArgument(name.length() <= Short.MAX_VALUE, "The name '%s' is longer than the limit of 32767 characters (%s)", name, name.length());
|
||||
Preconditions.checkArgument(this.board.getObjective(name) == null, "An objective of name '%s' already exists", name);
|
||||
net.minecraft.world.scores.Objective objective = this.board.addObjective(name, ((CraftCriteria) criteria).criteria, io.papermc.paper.adventure.PaperAdventure.asVanilla(displayName), CraftScoreboardTranslations.fromBukkitRender(renderType), true, null);
|
||||
return new CraftObjective(this, objective);
|
||||
}
|
||||
// Paper end - Adventure
|
||||
|
||||
@Override
|
||||
public CraftObjective registerNewObjective(String name, String criteria, String displayName) {
|
||||
@ -47,15 +74,7 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
|
||||
|
||||
@Override
|
||||
public CraftObjective registerNewObjective(String name, Criteria criteria, String displayName, RenderType renderType) {
|
||||
Preconditions.checkArgument(name != null, "Objective name cannot be null");
|
||||
Preconditions.checkArgument(criteria != null, "Criteria cannot be null");
|
||||
Preconditions.checkArgument(displayName != null, "Display name cannot be null");
|
||||
Preconditions.checkArgument(renderType != null, "RenderType cannot be null");
|
||||
Preconditions.checkArgument(name.length() <= Short.MAX_VALUE, "The name '%s' is longer than the limit of 32767 characters (%s)", name, name.length());
|
||||
Preconditions.checkArgument(this.board.getObjective(name) == null, "An objective of name '%s' already exists", name);
|
||||
|
||||
net.minecraft.world.scores.Objective objective = this.board.addObjective(name, ((CraftCriteria) criteria).criteria, CraftChatMessage.fromStringOrEmpty(displayName), CraftScoreboardTranslations.fromBukkitRender(renderType), true, null);
|
||||
return new CraftObjective(this, objective);
|
||||
return this.registerNewObjective(name, criteria, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(displayName), renderType); // Paper - Adventure
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -26,6 +26,63 @@ final class CraftTeam extends CraftScoreboardComponent implements Team {
|
||||
|
||||
return this.team.getName();
|
||||
}
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component displayName() throws IllegalStateException {
|
||||
CraftScoreboard scoreboard = checkState();
|
||||
return io.papermc.paper.adventure.PaperAdventure.asAdventure(team.getDisplayName());
|
||||
}
|
||||
@Override
|
||||
public void displayName(net.kyori.adventure.text.Component displayName) throws IllegalStateException, IllegalArgumentException {
|
||||
if (displayName == null) displayName = net.kyori.adventure.text.Component.empty();
|
||||
CraftScoreboard scoreboard = checkState();
|
||||
team.setDisplayName(io.papermc.paper.adventure.PaperAdventure.asVanilla(displayName));
|
||||
}
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component prefix() throws IllegalStateException {
|
||||
CraftScoreboard scoreboard = checkState();
|
||||
return io.papermc.paper.adventure.PaperAdventure.asAdventure(team.getPlayerPrefix());
|
||||
}
|
||||
@Override
|
||||
public void prefix(net.kyori.adventure.text.Component prefix) throws IllegalStateException, IllegalArgumentException {
|
||||
if (prefix == null) prefix = net.kyori.adventure.text.Component.empty();
|
||||
CraftScoreboard scoreboard = checkState();
|
||||
team.setPlayerPrefix(io.papermc.paper.adventure.PaperAdventure.asVanilla(prefix));
|
||||
}
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component suffix() throws IllegalStateException {
|
||||
CraftScoreboard scoreboard = checkState();
|
||||
return io.papermc.paper.adventure.PaperAdventure.asAdventure(team.getPlayerSuffix());
|
||||
}
|
||||
@Override
|
||||
public void suffix(net.kyori.adventure.text.Component suffix) throws IllegalStateException, IllegalArgumentException {
|
||||
if (suffix == null) suffix = net.kyori.adventure.text.Component.empty();
|
||||
CraftScoreboard scoreboard = checkState();
|
||||
team.setPlayerSuffix(io.papermc.paper.adventure.PaperAdventure.asVanilla(suffix));
|
||||
}
|
||||
@Override
|
||||
public boolean hasColor() {
|
||||
CraftScoreboard scoreboard = checkState();
|
||||
return this.team.getColor().getColor() != null;
|
||||
}
|
||||
@Override
|
||||
public net.kyori.adventure.text.format.TextColor color() throws IllegalStateException {
|
||||
CraftScoreboard scoreboard = checkState();
|
||||
if (team.getColor().getColor() == null) throw new IllegalStateException("Team colors must have hex values");
|
||||
net.kyori.adventure.text.format.TextColor color = net.kyori.adventure.text.format.TextColor.color(team.getColor().getColor());
|
||||
if (!(color instanceof net.kyori.adventure.text.format.NamedTextColor)) throw new IllegalStateException("Team doesn't have a NamedTextColor");
|
||||
return (net.kyori.adventure.text.format.NamedTextColor) color;
|
||||
}
|
||||
@Override
|
||||
public void color(net.kyori.adventure.text.format.NamedTextColor color) {
|
||||
CraftScoreboard scoreboard = checkState();
|
||||
if (color == null) {
|
||||
this.team.setColor(net.minecraft.ChatFormatting.RESET);
|
||||
} else {
|
||||
this.team.setColor(io.papermc.paper.adventure.PaperAdventure.asVanilla(color));
|
||||
}
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
@ -303,4 +360,20 @@ final class CraftTeam extends CraftScoreboardComponent implements Team {
|
||||
return !(this.team != other.team && (this.team == null || !this.team.equals(other.team)));
|
||||
}
|
||||
|
||||
// Paper start - make Team extend ForwardingAudience
|
||||
@Override
|
||||
public @org.jetbrains.annotations.NotNull Iterable<? extends net.kyori.adventure.audience.Audience> audiences() {
|
||||
this.checkState();
|
||||
java.util.List<net.kyori.adventure.audience.Audience> audiences = new java.util.ArrayList<>();
|
||||
for (String playerName : this.team.getPlayers()) {
|
||||
org.bukkit.entity.Player player = Bukkit.getPlayerExact(playerName);
|
||||
if (player != null) {
|
||||
audiences.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
return audiences;
|
||||
}
|
||||
// Paper end - make Team extend ForwardingAudience
|
||||
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ public final class CraftChatMessage {
|
||||
this.hex.append(c);
|
||||
|
||||
if (this.hex.length() == 7) {
|
||||
this.modifier = StringMessage.RESET.withColor(TextColor.parseColor(this.hex.toString()).result().get());
|
||||
this.modifier = StringMessage.RESET.withColor(TextColor.parseColor(this.hex.toString()).result().orElse(null)); // Paper
|
||||
this.hex = null;
|
||||
}
|
||||
} else if (format.isFormat() && format != ChatFormatting.RESET) {
|
||||
@ -264,6 +264,7 @@ public final class CraftChatMessage {
|
||||
|
||||
public static String fromComponent(Component component) {
|
||||
if (component == null) return "";
|
||||
if (component instanceof io.papermc.paper.adventure.AdventureComponent) component = ((io.papermc.paper.adventure.AdventureComponent) component).deepConverted();
|
||||
StringBuilder out = new StringBuilder();
|
||||
|
||||
boolean hadFormat = false;
|
||||
|
@ -80,6 +80,43 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
|
||||
private CraftMagicNumbers() {}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public net.kyori.adventure.text.flattener.ComponentFlattener componentFlattener() {
|
||||
return io.papermc.paper.adventure.PaperAdventure.FLATTENER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.serializer.gson.GsonComponentSerializer colorDownsamplingGsonComponentSerializer() {
|
||||
return net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.colorDownsamplingGson();
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.serializer.gson.GsonComponentSerializer gsonComponentSerializer() {
|
||||
return net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson();
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.serializer.plain.PlainComponentSerializer plainComponentSerializer() {
|
||||
return io.papermc.paper.adventure.PaperAdventure.PLAIN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer plainTextSerializer() {
|
||||
return net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer.plainText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer legacyComponentSerializer() {
|
||||
return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component resolveWithContext(final net.kyori.adventure.text.Component component, final org.bukkit.command.CommandSender context, final org.bukkit.entity.Entity scoreboardSubject, final boolean bypassPermissions) throws IOException {
|
||||
return io.papermc.paper.adventure.PaperAdventure.resolveWithContext(component, context, scoreboardSubject, bypassPermissions);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
public static BlockState getBlock(MaterialData material) {
|
||||
return CraftMagicNumbers.getBlock(material.getItemType(), material.getData());
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ public abstract class LazyHashSet<E> implements Set<E> {
|
||||
return this.reference = this.makeReference();
|
||||
}
|
||||
|
||||
abstract Set<E> makeReference();
|
||||
protected abstract Set<E> makeReference(); // Paper - protected
|
||||
|
||||
public boolean isLazy() {
|
||||
return this.reference == null;
|
||||
|
@ -16,9 +16,14 @@ public class LazyPlayerSet extends LazyHashSet<Player> {
|
||||
}
|
||||
|
||||
@Override
|
||||
HashSet<Player> makeReference() {
|
||||
protected HashSet<Player> makeReference() { // Paper - protected
|
||||
Preconditions.checkState(this.reference == null, "Reference already created!");
|
||||
List<ServerPlayer> players = this.server.getPlayerList().players;
|
||||
// Paper start
|
||||
return makePlayerSet(this.server);
|
||||
}
|
||||
public static HashSet<Player> makePlayerSet(final MinecraftServer server) {
|
||||
List<ServerPlayer> players = server.getPlayerList().players;
|
||||
// Paper end
|
||||
HashSet<Player> reference = new HashSet<Player>(players.size());
|
||||
for (ServerPlayer player : players) {
|
||||
reference.add(player.getBukkitEntity());
|
||||
|
@ -0,0 +1 @@
|
||||
io.papermc.paper.adventure.providers.BossBarImplementationProvider
|
@ -0,0 +1 @@
|
||||
io.papermc.paper.adventure.providers.ClickCallbackProviderImpl
|
@ -0,0 +1 @@
|
||||
io.papermc.paper.adventure.providers.DataComponentValueConverterProviderImpl
|
@ -0,0 +1 @@
|
||||
io.papermc.paper.adventure.providers.ComponentLoggerProviderImpl
|
@ -0,0 +1 @@
|
||||
io.papermc.paper.adventure.providers.MiniMessageProviderImpl
|
@ -0,0 +1 @@
|
||||
io.papermc.paper.adventure.providers.GsonComponentSerializerProviderImpl
|
@ -0,0 +1 @@
|
||||
io.papermc.paper.adventure.providers.LegacyComponentSerializerProviderImpl
|
@ -0,0 +1 @@
|
||||
io.papermc.paper.adventure.providers.PlainTextComponentSerializerProviderImpl
|
@ -0,0 +1,14 @@
|
||||
{
|
||||
"chat": {
|
||||
"parameters": [
|
||||
"content"
|
||||
],
|
||||
"translation_key": "%s"
|
||||
},
|
||||
"narration": {
|
||||
"parameters": [
|
||||
"content"
|
||||
],
|
||||
"translation_key": "%s"
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user