Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.20.2/.3/.5 support #14

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
limboapiVersion=1.1.14
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
24 changes: 21 additions & 3 deletions src/main/java/net/elytrium/limbohub/LimboHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Menu> menus = new HashMap<>();
private final Map<String, Settings.MAIN.ACTION> commands = new HashMap<>();
Expand All @@ -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;
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -519,8 +531,9 @@ 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),
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),
Expand All @@ -534,7 +547,8 @@ 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),
new PacketMapping(0x0E, ProtocolVersion.MINECRAFT_1_20_5, false),
});

this.commands.clear();
Expand Down Expand Up @@ -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);
}
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/net/elytrium/limbohub/entities/NPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
)
Expand Down Expand Up @@ -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))
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
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_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;
} else {
throw new IllegalArgumentException("Player is not supported on versions below Minecraft 1.20.2");
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/net/elytrium/limbohub/protocol/item/ItemStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@
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 it.unimi.dsi.fastutil.Pair;
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;
Expand Down Expand Up @@ -140,6 +146,40 @@ 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<Component> 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:dyed_color", Pair.of(this.color, true));
}

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<Component> getLore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}

Expand Down
Loading
Loading