From 4b7ecc29d22232bd7e7f159c699d46f3236e4030 Mon Sep 17 00:00:00 2001 From: UserNugget Date: Wed, 17 Jan 2024 12:57:22 +0300 Subject: [PATCH 1/8] Fix 1.20.2/1.20.3 support --- .../java/net/elytrium/limbohub/LimboHub.java | 6 +++--- .../limbohub/protocol/entities/Player.java | 4 +++- .../EntityMetadataOptionalComponentEntry.java | 4 ++-- .../limbohub/protocol/packets/OpenScreen.java | 3 ++- .../protocol/packets/ScoreboardTeam.java | 9 ++++----- .../protocol/packets/UpdateObjectives.java | 9 ++++++--- .../protocol/packets/UpdateScore.java | 19 ++++++++++++++++--- 7 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/main/java/net/elytrium/limbohub/LimboHub.java b/src/main/java/net/elytrium/limbohub/LimboHub.java index 1ce5393..fd5401f 100644 --- a/src/main/java/net/elytrium/limbohub/LimboHub.java +++ b/src/main/java/net/elytrium/limbohub/LimboHub.java @@ -519,8 +519,8 @@ public void reload() { new PacketMapping(0x10, ProtocolVersion.MINECRAFT_1_19_1, false), new PacketMapping(0x0F, ProtocolVersion.MINECRAFT_1_19_3, false), new PacketMapping(0x10, ProtocolVersion.MINECRAFT_1_19_4, false), - new PacketMapping(0x12, ProtocolVersion.MINECRAFT_1_20_2, true), - new PacketMapping(0x13, ProtocolVersion.MINECRAFT_1_20_3, true), + new PacketMapping(0x12, ProtocolVersion.MINECRAFT_1_20_2, false), + new PacketMapping(0x13, ProtocolVersion.MINECRAFT_1_20_3, false), }) .registerPacket(PacketDirection.SERVERBOUND, ClickContainer.class, ClickContainer::new, new PacketMapping[]{ new PacketMapping(0x0E, ProtocolVersion.MINECRAFT_1_8, false), @@ -534,7 +534,7 @@ public void reload() { new PacketMapping(0x0B, ProtocolVersion.MINECRAFT_1_19_1, false), new PacketMapping(0x0A, ProtocolVersion.MINECRAFT_1_19_3, false), new PacketMapping(0x0B, ProtocolVersion.MINECRAFT_1_19_4, false), - new PacketMapping(0x0D, ProtocolVersion.MINECRAFT_1_20_2, true), + new PacketMapping(0x0D, ProtocolVersion.MINECRAFT_1_20_2, false), }); this.commands.clear(); diff --git a/src/main/java/net/elytrium/limbohub/protocol/entities/Player.java b/src/main/java/net/elytrium/limbohub/protocol/entities/Player.java index 7fd717f..81d101e 100644 --- a/src/main/java/net/elytrium/limbohub/protocol/entities/Player.java +++ b/src/main/java/net/elytrium/limbohub/protocol/entities/Player.java @@ -25,7 +25,9 @@ public class Player { public static int getEntityType(ProtocolVersion version) { - if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) >= 0) { + if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_3) >= 0) { + return 124; + } else if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) >= 0) { return 122; } else { throw new IllegalArgumentException("Player is not supported on versions below Minecraft 1.20.2"); diff --git a/src/main/java/net/elytrium/limbohub/protocol/metadata/EntityMetadataOptionalComponentEntry.java b/src/main/java/net/elytrium/limbohub/protocol/metadata/EntityMetadataOptionalComponentEntry.java index e64581a..f5ba107 100644 --- a/src/main/java/net/elytrium/limbohub/protocol/metadata/EntityMetadataOptionalComponentEntry.java +++ b/src/main/java/net/elytrium/limbohub/protocol/metadata/EntityMetadataOptionalComponentEntry.java @@ -18,7 +18,7 @@ package net.elytrium.limbohub.protocol.metadata; import com.velocitypowered.api.network.ProtocolVersion; -import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder; import io.netty.buffer.ByteBuf; import java.util.Optional; import net.kyori.adventure.text.Component; @@ -35,7 +35,7 @@ public EntityMetadataOptionalComponentEntry(Component component) { public void encode(ByteBuf buf, ProtocolVersion protocolVersion) { buf.writeBoolean(this.component != null); if (this.component != null) { - ProtocolUtils.writeString(buf, ProtocolUtils.getJsonChatSerializer(protocolVersion).serialize(this.component)); + new ComponentHolder(protocolVersion, this.component).write(buf); } } diff --git a/src/main/java/net/elytrium/limbohub/protocol/packets/OpenScreen.java b/src/main/java/net/elytrium/limbohub/protocol/packets/OpenScreen.java index 8e67b6d..38744b7 100644 --- a/src/main/java/net/elytrium/limbohub/protocol/packets/OpenScreen.java +++ b/src/main/java/net/elytrium/limbohub/protocol/packets/OpenScreen.java @@ -21,6 +21,7 @@ import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder; import io.netty.buffer.ByteBuf; import net.elytrium.limbohub.protocol.container.Container; @@ -49,7 +50,7 @@ public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersi } else { ProtocolUtils.writeString(buf, "minecraft:chest"); } - ProtocolUtils.writeString(buf, ProtocolUtils.getJsonChatSerializer(protocolVersion).serialize(this.container.getTitle())); + new ComponentHolder(protocolVersion, this.container.getTitle()).write(buf); if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_13_2) <= 0) { buf.writeByte(this.container.getContents().length); } diff --git a/src/main/java/net/elytrium/limbohub/protocol/packets/ScoreboardTeam.java b/src/main/java/net/elytrium/limbohub/protocol/packets/ScoreboardTeam.java index 996dcd8..2e98be6 100644 --- a/src/main/java/net/elytrium/limbohub/protocol/packets/ScoreboardTeam.java +++ b/src/main/java/net/elytrium/limbohub/protocol/packets/ScoreboardTeam.java @@ -21,10 +21,10 @@ import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder; import io.netty.buffer.ByteBuf; import java.util.List; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; public class ScoreboardTeam implements MinecraftPacket { @@ -64,14 +64,13 @@ public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersi ProtocolUtils.writeString(buf, this.teamName); buf.writeByte(0); if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0) { - GsonComponentSerializer serializer = ProtocolUtils.getJsonChatSerializer(protocolVersion); - ProtocolUtils.writeString(buf, serializer.serialize(Component.empty())); + new ComponentHolder(protocolVersion, Component.empty()).write(buf); buf.writeByte(this.flags); ProtocolUtils.writeString(buf, this.nameTagVisibility); ProtocolUtils.writeString(buf, this.collisionRule); ProtocolUtils.writeVarInt(buf, this.teamColor); - ProtocolUtils.writeString(buf, serializer.serialize(this.teamPrefix)); - ProtocolUtils.writeString(buf, serializer.serialize(this.teamSuffix)); + new ComponentHolder(protocolVersion, this.teamPrefix).write(buf); + new ComponentHolder(protocolVersion, this.teamSuffix).write(buf); } else { LegacyComponentSerializer serializer = LegacyComponentSerializer.legacySection(); buf.writeByte(0); diff --git a/src/main/java/net/elytrium/limbohub/protocol/packets/UpdateObjectives.java b/src/main/java/net/elytrium/limbohub/protocol/packets/UpdateObjectives.java index 508cf56..a866af5 100644 --- a/src/main/java/net/elytrium/limbohub/protocol/packets/UpdateObjectives.java +++ b/src/main/java/net/elytrium/limbohub/protocol/packets/UpdateObjectives.java @@ -21,6 +21,7 @@ import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder; import io.netty.buffer.ByteBuf; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.ComponentSerializer; @@ -54,12 +55,14 @@ public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersi ProtocolUtils.writeString(buf, this.objectiveName); buf.writeByte(this.mode); if (this.mode == 0 || this.mode == 2) { - ComponentSerializer serializer = protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0 - ? ProtocolUtils.getJsonChatSerializer(protocolVersion) : LegacyComponentSerializer.legacySection(); - ProtocolUtils.writeString(buf, serializer.serialize(this.objectiveValue)); if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0) { + new ComponentHolder(protocolVersion, this.objectiveValue).write(buf); ProtocolUtils.writeVarInt(buf, this.type); + if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_20_3) >= 0) { + buf.writeBoolean(false); // no custom format + } } else { + ProtocolUtils.writeString(buf, LegacyComponentSerializer.legacySection().serialize(this.objectiveValue)); if (this.type == 0) { ProtocolUtils.writeString(buf, "integer"); } else if (this.type == 1) { diff --git a/src/main/java/net/elytrium/limbohub/protocol/packets/UpdateScore.java b/src/main/java/net/elytrium/limbohub/protocol/packets/UpdateScore.java index 9d2f872..4fa676d 100644 --- a/src/main/java/net/elytrium/limbohub/protocol/packets/UpdateScore.java +++ b/src/main/java/net/elytrium/limbohub/protocol/packets/UpdateScore.java @@ -17,10 +17,12 @@ package net.elytrium.limbohub.protocol.packets; +import com.google.common.base.Preconditions; import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.ProtocolUtils; +import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder; import io.netty.buffer.ByteBuf; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; @@ -55,10 +57,21 @@ public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersi serializedName = serializedName.substring(0, 40); } ProtocolUtils.writeString(buf, serializedName); - buf.writeByte(this.action); - ProtocolUtils.writeString(buf, this.objectiveName); - if (this.action != 1) { + if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_20_3) >= 0) { + Preconditions.checkState(this.action == 0, "unsupported action"); + ProtocolUtils.writeString(buf, this.objectiveName); ProtocolUtils.writeVarInt(buf, this.value); + + buf.writeBoolean(true); + new ComponentHolder(protocolVersion, this.entityName).write(buf); + + buf.writeBoolean(false); // no custom format + } else { + buf.writeByte(this.action); + ProtocolUtils.writeString(buf, this.objectiveName); + if (this.action != 1) { + ProtocolUtils.writeVarInt(buf, this.value); + } } } From c5460adfa5777c0278c220589a38b4120d7adfa0 Mon Sep 17 00:00:00 2001 From: UserNugget Date: Wed, 17 Jan 2024 18:47:23 +0300 Subject: [PATCH 2/8] Bump version to 1.0.5 --- VERSION | 2 +- build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index a6a3a43..1464c52 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.4 \ No newline at end of file +1.0.5 \ No newline at end of file diff --git a/build.gradle b/build.gradle index 8a8b686..4af761a 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ plugins { } setGroup("net.elytrium") -setVersion("1.0.4") +setVersion("1.0.5") compileJava { getOptions().setEncoding("UTF-8") From 0960f7b8808f7154286cedc2665fdc68ca24d0cf Mon Sep 17 00:00:00 2001 From: UserNugget Date: Wed, 17 Jan 2024 19:18:10 +0300 Subject: [PATCH 3/8] Remove unused import --- .../net/elytrium/limbohub/protocol/packets/UpdateObjectives.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/net/elytrium/limbohub/protocol/packets/UpdateObjectives.java b/src/main/java/net/elytrium/limbohub/protocol/packets/UpdateObjectives.java index a866af5..c4a7ec1 100644 --- a/src/main/java/net/elytrium/limbohub/protocol/packets/UpdateObjectives.java +++ b/src/main/java/net/elytrium/limbohub/protocol/packets/UpdateObjectives.java @@ -24,7 +24,6 @@ import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder; import io.netty.buffer.ByteBuf; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.ComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; public class UpdateObjectives implements MinecraftPacket { From 62dc652190df2e26f931061fe8a4f8c5fdc3994e Mon Sep 17 00:00:00 2001 From: UserNugget Date: Tue, 23 Jan 2024 03:50:22 +0300 Subject: [PATCH 4/8] Velocity b329+ support --- .../net/elytrium/limbohub/entities/NPC.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/elytrium/limbohub/entities/NPC.java b/src/main/java/net/elytrium/limbohub/entities/NPC.java index f2ec428..6f731eb 100644 --- a/src/main/java/net/elytrium/limbohub/entities/NPC.java +++ b/src/main/java/net/elytrium/limbohub/entities/NPC.java @@ -19,9 +19,9 @@ import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.util.GameProfile; -import com.velocitypowered.proxy.protocol.packet.LegacyPlayerListItem; -import com.velocitypowered.proxy.protocol.packet.RemovePlayerInfo; -import com.velocitypowered.proxy.protocol.packet.UpsertPlayerInfo; +import com.velocitypowered.proxy.protocol.packet.LegacyPlayerListItemPacket; +import com.velocitypowered.proxy.protocol.packet.RemovePlayerInfoPacket; +import com.velocitypowered.proxy.protocol.packet.UpsertPlayerInfoPacket; import java.nio.charset.StandardCharsets; import java.util.EnumSet; import java.util.List; @@ -87,22 +87,22 @@ public void spawn(LimboPlayer player) { } if (player.getProxyPlayer().getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_3) >= 0) { - UpsertPlayerInfo.Entry entry = new UpsertPlayerInfo.Entry(this.uuid); + UpsertPlayerInfoPacket.Entry entry = new UpsertPlayerInfoPacket.Entry(this.uuid); entry.setProfile(profile); entry.setListed(false); player.writePacketAndFlush( - new UpsertPlayerInfo( - EnumSet.of(UpsertPlayerInfo.Action.ADD_PLAYER, UpsertPlayerInfo.Action.UPDATE_LISTED), + new UpsertPlayerInfoPacket( + EnumSet.of(UpsertPlayerInfoPacket.Action.ADD_PLAYER, UpsertPlayerInfoPacket.Action.UPDATE_LISTED), List.of(entry) ) ); } else { player.writePacketAndFlush( - new LegacyPlayerListItem( - LegacyPlayerListItem.ADD_PLAYER, + new LegacyPlayerListItemPacket( + LegacyPlayerListItemPacket.ADD_PLAYER, List.of( - new LegacyPlayerListItem.Item(this.uuid) + new LegacyPlayerListItemPacket.Item(this.uuid) .setName(profile.getName()) .setProperties(profile.getProperties()) ) @@ -135,12 +135,12 @@ public void spawn(LimboPlayer player) { public void cleanUp(LimboPlayer player) { if (player.getProxyPlayer().getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_3) >= 0) { - player.writePacketAndFlush(new RemovePlayerInfo(List.of(this.uuid))); + player.writePacketAndFlush(new RemovePlayerInfoPacket(List.of(this.uuid))); } else { player.writePacketAndFlush( - new LegacyPlayerListItem( - LegacyPlayerListItem.REMOVE_PLAYER, - List.of(new LegacyPlayerListItem.Item(this.uuid)) + new LegacyPlayerListItemPacket( + LegacyPlayerListItemPacket.REMOVE_PLAYER, + List.of(new LegacyPlayerListItemPacket.Item(this.uuid)) ) ); } From e6d60a116cc62e2aff77d46da368db67414e3b57 Mon Sep 17 00:00:00 2001 From: UserNugget Date: Tue, 23 Jan 2024 04:59:29 +0300 Subject: [PATCH 5/8] Fix rare race condition --- .../elytrium/limbohub/handler/HubSessionHandler.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/elytrium/limbohub/handler/HubSessionHandler.java b/src/main/java/net/elytrium/limbohub/handler/HubSessionHandler.java index ca4100b..932b07f 100644 --- a/src/main/java/net/elytrium/limbohub/handler/HubSessionHandler.java +++ b/src/main/java/net/elytrium/limbohub/handler/HubSessionHandler.java @@ -21,6 +21,7 @@ import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.scheduler.ScheduledTask; +import com.velocitypowered.api.scheduler.TaskStatus; import java.time.Duration; import java.util.HashSet; import java.util.Optional; @@ -52,6 +53,7 @@ public class HubSessionHandler implements LimboSessionHandler { private LimboPlayer player; private Menu currentMenu; private ScheduledTask bossBarTask; + private ScheduledTask npcTabListTask; private BossBar currentBossBar; public HubSessionHandler(Player proxyPlayer, LimboHub plugin) { @@ -97,7 +99,7 @@ public void onSpawn(Limbo server, LimboPlayer player) { this.currentMenu.getContainer().open(player); } - this.plugin.getServer().getScheduler() + this.npcTabListTask = this.plugin.getServer().getScheduler() .buildTask(this.plugin, () -> this.plugin.getNpcs().values().forEach(npc -> npc.cleanUp(player))) .delay(Settings.IMP.MAIN.SKIN_LOAD_SECONDS, TimeUnit.SECONDS) .schedule(); @@ -132,6 +134,13 @@ public void onDisconnect() { if (this.bossBarTask != null) { this.bossBarTask.cancel(); } + + if (this.npcTabListTask != null) { + if (this.npcTabListTask.status() == TaskStatus.SCHEDULED) { + this.plugin.getNpcs().values().forEach(npc -> npc.cleanUp(this.player)); + } + this.npcTabListTask.cancel(); + } } private void teleportToSpawn() { From ea00cf6d8024fce4c999feee9296b6ba432d5294 Mon Sep 17 00:00:00 2001 From: UserNugget Date: Mon, 11 Mar 2024 13:42:58 +0300 Subject: [PATCH 6/8] Initial 1.20.5 support --- gradle.properties | 2 +- .../java/net/elytrium/limbohub/LimboHub.java | 18 +++++++++ .../protocol/entities/ArmorStand.java | 4 +- .../limbohub/protocol/entities/Player.java | 4 +- .../limbohub/protocol/item/ItemStack.java | 35 +++++++++++++++++ .../protocol/item/meta/AbstractItemMeta.java | 38 +++++++++++++++++++ .../limbohub/protocol/item/meta/ItemMeta.java | 3 ++ 7 files changed, 101 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index cf220f8..98e29ef 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -limboapiVersion=1.1.14 +limboapiVersion=1.1.23 velocityVersion=3.3.0-SNAPSHOT nettyVersion=4.1.86.Final spotbugsVersion=4.7.3 diff --git a/src/main/java/net/elytrium/limbohub/LimboHub.java b/src/main/java/net/elytrium/limbohub/LimboHub.java index fd5401f..3084eb2 100644 --- a/src/main/java/net/elytrium/limbohub/LimboHub.java +++ b/src/main/java/net/elytrium/limbohub/LimboHub.java @@ -29,6 +29,7 @@ import com.velocitypowered.api.plugin.annotation.DataDirectory; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -106,6 +107,9 @@ public class LimboHub { private static Logger LOGGER; @MonotonicNonNull private static Serializer SERIALIZER; + @MonotonicNonNull + @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD") + private static LimboHub INSTANCE; private final Map menus = new HashMap<>(); private final Map commands = new HashMap<>(); @@ -125,6 +129,7 @@ public class LimboHub { @Inject public LimboHub(Logger logger, ProxyServer server, Metrics.Factory metricsFactory, @DataDirectory Path dataDirectory) { + INSTANCE = this; setLogger(logger); this.server = server; @@ -413,6 +418,7 @@ public void reload() { new PacketMapping(0x2C, ProtocolVersion.MINECRAFT_1_19_3, true), new PacketMapping(0x30, ProtocolVersion.MINECRAFT_1_19_4, true), new PacketMapping(0x31, ProtocolVersion.MINECRAFT_1_20_2, true), + new PacketMapping(0x33, ProtocolVersion.MINECRAFT_1_20_5, true), }) .registerPacket(PacketDirection.CLIENTBOUND, SetHeadRotation.class, SetHeadRotation::new, new PacketMapping[]{ new PacketMapping(0x19, ProtocolVersion.MINECRAFT_1_8, true), @@ -431,6 +437,7 @@ public void reload() { new PacketMapping(0x42, ProtocolVersion.MINECRAFT_1_19_4, true), new PacketMapping(0x44, ProtocolVersion.MINECRAFT_1_20_2, true), new PacketMapping(0x46, ProtocolVersion.MINECRAFT_1_20_3, true), + new PacketMapping(0x48, ProtocolVersion.MINECRAFT_1_20_5, true), }) .registerPacket(PacketDirection.CLIENTBOUND, DisplayObjective.class, DisplayObjective::new, new PacketMapping[]{ new PacketMapping(0x3D, ProtocolVersion.MINECRAFT_1_8, true), @@ -446,6 +453,7 @@ public void reload() { new PacketMapping(0x51, ProtocolVersion.MINECRAFT_1_19_4, true), new PacketMapping(0x53, ProtocolVersion.MINECRAFT_1_20_2, true), new PacketMapping(0x55, ProtocolVersion.MINECRAFT_1_20_3, true), + new PacketMapping(0x57, ProtocolVersion.MINECRAFT_1_20_5, true), }) .registerPacket(PacketDirection.CLIENTBOUND, SetEntityMetadata.class, SetEntityMetadata::new, new PacketMapping[]{ new PacketMapping(0x1C, ProtocolVersion.MINECRAFT_1_8, true), @@ -461,6 +469,7 @@ public void reload() { new PacketMapping(0x52, ProtocolVersion.MINECRAFT_1_19_4, true), new PacketMapping(0x54, ProtocolVersion.MINECRAFT_1_20_2, true), new PacketMapping(0x56, ProtocolVersion.MINECRAFT_1_20_3, true), + new PacketMapping(0x58, ProtocolVersion.MINECRAFT_1_20_5, true), }) .registerPacket(PacketDirection.CLIENTBOUND, UpdateObjectives.class, UpdateObjectives::new, new PacketMapping[]{ new PacketMapping(0x3B, ProtocolVersion.MINECRAFT_1_8, true), @@ -476,6 +485,7 @@ public void reload() { new PacketMapping(0x58, ProtocolVersion.MINECRAFT_1_19_4, true), new PacketMapping(0x5A, ProtocolVersion.MINECRAFT_1_20_2, true), new PacketMapping(0x5C, ProtocolVersion.MINECRAFT_1_20_3, true), + new PacketMapping(0x5E, ProtocolVersion.MINECRAFT_1_20_5, true), }) .registerPacket(PacketDirection.CLIENTBOUND, ScoreboardTeam.class, ScoreboardTeam::new, new PacketMapping[]{ new PacketMapping(0x3E, ProtocolVersion.MINECRAFT_1_8, true), @@ -491,6 +501,7 @@ public void reload() { new PacketMapping(0x5A, ProtocolVersion.MINECRAFT_1_19_4, true), new PacketMapping(0x5C, ProtocolVersion.MINECRAFT_1_20_2, true), new PacketMapping(0x5E, ProtocolVersion.MINECRAFT_1_20_3, true), + new PacketMapping(0x60, ProtocolVersion.MINECRAFT_1_20_5, true), }) .registerPacket(PacketDirection.CLIENTBOUND, UpdateScore.class, UpdateScore::new, new PacketMapping[]{ new PacketMapping(0x3C, ProtocolVersion.MINECRAFT_1_8, true), @@ -506,6 +517,7 @@ public void reload() { new PacketMapping(0x5B, ProtocolVersion.MINECRAFT_1_19_4, true), new PacketMapping(0x5D, ProtocolVersion.MINECRAFT_1_20_2, true), new PacketMapping(0x5F, ProtocolVersion.MINECRAFT_1_20_3, true), + new PacketMapping(0x61, ProtocolVersion.MINECRAFT_1_20_5, true), }) .registerPacket(PacketDirection.SERVERBOUND, Interact.class, Interact::new, new PacketMapping[]{ new PacketMapping(0x02, ProtocolVersion.MINECRAFT_1_8, false), @@ -521,6 +533,7 @@ public void reload() { new PacketMapping(0x10, ProtocolVersion.MINECRAFT_1_19_4, false), new PacketMapping(0x12, ProtocolVersion.MINECRAFT_1_20_2, false), new PacketMapping(0x13, ProtocolVersion.MINECRAFT_1_20_3, false), + new PacketMapping(0x16, ProtocolVersion.MINECRAFT_1_20_5, false), }) .registerPacket(PacketDirection.SERVERBOUND, ClickContainer.class, ClickContainer::new, new PacketMapping[]{ new PacketMapping(0x0E, ProtocolVersion.MINECRAFT_1_8, false), @@ -535,6 +548,7 @@ public void reload() { new PacketMapping(0x0A, ProtocolVersion.MINECRAFT_1_19_3, false), new PacketMapping(0x0B, ProtocolVersion.MINECRAFT_1_19_4, false), new PacketMapping(0x0D, ProtocolVersion.MINECRAFT_1_20_2, false), + new PacketMapping(0x0E, ProtocolVersion.MINECRAFT_1_20_5, false), }); this.commands.clear(); @@ -659,6 +673,10 @@ public static Serializer getSerializer() { return SERIALIZER; } + public static LimboHub getInstance() { + return INSTANCE; + } + public static Component buildResetComponent() { return Component.empty().decoration(TextDecoration.ITALIC, false); } diff --git a/src/main/java/net/elytrium/limbohub/protocol/entities/ArmorStand.java b/src/main/java/net/elytrium/limbohub/protocol/entities/ArmorStand.java index 5a770cd..bfecb7c 100644 --- a/src/main/java/net/elytrium/limbohub/protocol/entities/ArmorStand.java +++ b/src/main/java/net/elytrium/limbohub/protocol/entities/ArmorStand.java @@ -29,7 +29,9 @@ public class ArmorStand { public static int getEntityType(ProtocolVersion version) { - if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) { + if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_5) >= 0) { + return 3; + } else if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) { return 2; } else if (version.compareTo(ProtocolVersion.MINECRAFT_1_14) >= 0) { return 1; diff --git a/src/main/java/net/elytrium/limbohub/protocol/entities/Player.java b/src/main/java/net/elytrium/limbohub/protocol/entities/Player.java index 81d101e..db6415d 100644 --- a/src/main/java/net/elytrium/limbohub/protocol/entities/Player.java +++ b/src/main/java/net/elytrium/limbohub/protocol/entities/Player.java @@ -25,7 +25,9 @@ public class Player { public static int getEntityType(ProtocolVersion version) { - if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_3) >= 0) { + if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_5) >= 0) { + return 128; + } else if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_3) >= 0) { return 124; } else if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) >= 0) { return 122; diff --git a/src/main/java/net/elytrium/limbohub/protocol/item/ItemStack.java b/src/main/java/net/elytrium/limbohub/protocol/item/ItemStack.java index 1f020f8..01c85f3 100644 --- a/src/main/java/net/elytrium/limbohub/protocol/item/ItemStack.java +++ b/src/main/java/net/elytrium/limbohub/protocol/item/ItemStack.java @@ -57,6 +57,41 @@ public ItemStack() { } public void encode(ByteBuf buf, ProtocolVersion protocolVersion) { + if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_20_5) >= 0) { + this.encodeModern(buf, protocolVersion); + } else { + this.encodeLegacy(buf, protocolVersion); + } + } + + private void encodeModern(ByteBuf buf, ProtocolVersion protocolVersion) { + if (!this.present) { + ProtocolUtils.writeVarInt(buf, 0); + return; + } + + VirtualItem item = this.items.stream() + .dropWhile(i -> !i.isSupportedOn(protocolVersion)) + .findFirst().orElseThrow(() -> + new IllegalArgumentException("Item " + this.items.get(0).getModernID() + " is not supported on " + protocolVersion)); + + int id = item.getID(protocolVersion); + if (id == 0) { + ProtocolUtils.writeVarInt(buf, 0); + } else { + ProtocolUtils.writeVarInt(buf, this.count); + ProtocolUtils.writeVarInt(buf, id); + + if (this.meta != null) { + this.meta.buildComponents(protocolVersion).write(protocolVersion, buf); + } else { + ProtocolUtils.writeVarInt(buf, 0); + ProtocolUtils.writeVarInt(buf, 0); + } + } + } + + private void encodeLegacy(ByteBuf buf, ProtocolVersion protocolVersion) { if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_13_2) >= 0) { buf.writeBoolean(this.present); } diff --git a/src/main/java/net/elytrium/limbohub/protocol/item/meta/AbstractItemMeta.java b/src/main/java/net/elytrium/limbohub/protocol/item/meta/AbstractItemMeta.java index afdd493..3b7980d 100644 --- a/src/main/java/net/elytrium/limbohub/protocol/item/meta/AbstractItemMeta.java +++ b/src/main/java/net/elytrium/limbohub/protocol/item/meta/AbstractItemMeta.java @@ -18,9 +18,14 @@ package net.elytrium.limbohub.protocol.item.meta; import com.velocitypowered.api.network.ProtocolVersion; +import com.velocitypowered.api.util.GameProfile; +import com.velocitypowered.api.util.GameProfile.Property; import com.velocitypowered.proxy.protocol.ProtocolUtils; import java.util.List; +import java.util.UUID; import java.util.concurrent.ThreadLocalRandom; +import net.elytrium.limboapi.api.protocol.item.ItemComponentMap; +import net.elytrium.limbohub.LimboHub; import net.kyori.adventure.nbt.BinaryTagTypes; import net.kyori.adventure.nbt.CompoundBinaryTag; import net.kyori.adventure.nbt.ListBinaryTag; @@ -140,6 +145,39 @@ public CompoundBinaryTag buildNbt(ProtocolVersion protocolVersion) { return builder.build(); } + @Override + public ItemComponentMap buildComponents(ProtocolVersion protocolVersion) { + ItemComponentMap componentMap = LimboHub.getInstance().getLimboFactory().createItemComponentMap(); + + Component name = this.getName(); + List lore = this.getLore(); + + if (name != null) { + componentMap.add(protocolVersion, "minecraft:item_name", name); + } + + if (lore != null && !lore.isEmpty()) { + componentMap.add(protocolVersion, "minecraft:lore", lore); + } + + if (this.hasColor) { + componentMap.add(protocolVersion, "minecraft:base_color", this.color); + } + + componentMap.add(protocolVersion, "minecraft:hide_additional_tooltip", true); + + if (this.enchanted) { + componentMap.add(protocolVersion, "minecraft:enchantment_glint_override", true); + } + + if (this.skinValue != null) { + componentMap.add(protocolVersion, "minecraft:profile", new GameProfile( + new UUID(0, 0), this.skinName, List.of(new Property("textures", this.skinValue, "")))); + } + + return componentMap; + } + public abstract Component getName(); public abstract List getLore(); diff --git a/src/main/java/net/elytrium/limbohub/protocol/item/meta/ItemMeta.java b/src/main/java/net/elytrium/limbohub/protocol/item/meta/ItemMeta.java index 77b1e78..b538e9d 100644 --- a/src/main/java/net/elytrium/limbohub/protocol/item/meta/ItemMeta.java +++ b/src/main/java/net/elytrium/limbohub/protocol/item/meta/ItemMeta.java @@ -18,9 +18,12 @@ package net.elytrium.limbohub.protocol.item.meta; import com.velocitypowered.api.network.ProtocolVersion; +import net.elytrium.limboapi.api.protocol.item.ItemComponentMap; import net.kyori.adventure.nbt.CompoundBinaryTag; public interface ItemMeta { CompoundBinaryTag buildNbt(ProtocolVersion protocolVersion); + + ItemComponentMap buildComponents(ProtocolVersion protocolVersion); } From 2c0da9a0c0adfea5584cd88506d789d87a7ec97c Mon Sep 17 00:00:00 2001 From: UserNugget Date: Sun, 28 Apr 2024 13:47:39 +0300 Subject: [PATCH 7/8] Also use `dyed_color` for coloring items --- build.gradle | 1 + gradle.properties | 1 + .../elytrium/limbohub/protocol/item/meta/AbstractItemMeta.java | 2 ++ 3 files changed, 4 insertions(+) diff --git a/build.gradle b/build.gradle index 4af761a..6da4c95 100644 --- a/build.gradle +++ b/build.gradle @@ -49,6 +49,7 @@ dependencies { compileOnly("com.velocitypowered:velocity-proxy:$velocityVersion") // From Elytrium Repo. compileOnly("io.netty:netty-codec:$nettyVersion") + compileOnly("it.unimi.dsi:fastutil-core:$fastutilVersion") compileOnly("com.github.spotbugs:spotbugs-annotations:$spotbugsVersion") diff --git a/gradle.properties b/gradle.properties index 98e29ef..e5b0b7b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,7 @@ limboapiVersion=1.1.23 velocityVersion=3.3.0-SNAPSHOT nettyVersion=4.1.86.Final +fastutilVersion=8.5.11 spotbugsVersion=4.7.3 elytriumCommonsVersion=1.2.5-1 bstatsVersion=3.0.0 \ No newline at end of file diff --git a/src/main/java/net/elytrium/limbohub/protocol/item/meta/AbstractItemMeta.java b/src/main/java/net/elytrium/limbohub/protocol/item/meta/AbstractItemMeta.java index 3b7980d..73999ac 100644 --- a/src/main/java/net/elytrium/limbohub/protocol/item/meta/AbstractItemMeta.java +++ b/src/main/java/net/elytrium/limbohub/protocol/item/meta/AbstractItemMeta.java @@ -21,6 +21,7 @@ import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.util.GameProfile.Property; import com.velocitypowered.proxy.protocol.ProtocolUtils; +import it.unimi.dsi.fastutil.Pair; import java.util.List; import java.util.UUID; import java.util.concurrent.ThreadLocalRandom; @@ -162,6 +163,7 @@ public ItemComponentMap buildComponents(ProtocolVersion protocolVersion) { if (this.hasColor) { componentMap.add(protocolVersion, "minecraft:base_color", this.color); + componentMap.add(protocolVersion, "minecraft:dyed_color", Pair.of(this.color, true)); } componentMap.add(protocolVersion, "minecraft:hide_additional_tooltip", true); From 1e9831118c07b5dfb4d0d72fffa8548ae36a41fc Mon Sep 17 00:00:00 2001 From: UserNugget Date: Sat, 1 Jun 2024 16:45:26 +0300 Subject: [PATCH 8/8] Revert "Bump version to 1.0.5" This reverts commit c5460adfa5777c0278c220589a38b4120d7adfa0. --- VERSION | 2 +- build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 1464c52..a6a3a43 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.5 \ No newline at end of file +1.0.4 \ No newline at end of file diff --git a/build.gradle b/build.gradle index 6da4c95..3dfcfdb 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ plugins { } setGroup("net.elytrium") -setVersion("1.0.5") +setVersion("1.0.4") compileJava { getOptions().setEncoding("UTF-8")