diff --git a/src/main/java/com/nukkitx/proxypass/ProxyPass.java b/src/main/java/com/nukkitx/proxypass/ProxyPass.java index 8096af0..7d47d33 100644 --- a/src/main/java/com/nukkitx/proxypass/ProxyPass.java +++ b/src/main/java/com/nukkitx/proxypass/ProxyPass.java @@ -6,16 +6,16 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; +import com.nukkitx.nbt.NBTInputStream; +import com.nukkitx.nbt.NBTOutputStream; import com.nukkitx.nbt.NbtUtils; -import com.nukkitx.nbt.stream.NBTInputStream; -import com.nukkitx.nbt.stream.NBTOutputStream; -import com.nukkitx.nbt.tag.Tag; import com.nukkitx.protocol.bedrock.BedrockClient; import com.nukkitx.protocol.bedrock.BedrockPacketCodec; import com.nukkitx.protocol.bedrock.BedrockServer; import com.nukkitx.protocol.bedrock.v363.Bedrock_v363; import com.nukkitx.protocol.bedrock.v407.Bedrock_v407; import com.nukkitx.proxypass.network.ProxyBedrockEventHandler; +import io.netty.util.ResourceLeakDetector; import lombok.AccessLevel; import lombok.Getter; import lombok.extern.log4j.Log4j2; @@ -70,6 +70,7 @@ public class ProxyPass { private Path dataDir; public static void main(String[] args) { + ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.PARANOID); ProxyPass proxy = new ProxyPass(); try { proxy.boot(); @@ -154,17 +155,17 @@ public void shutdown() { } } - public void saveNBT(String dataName, Tag dataTag) { + public void saveNBT(String dataName, Object dataTag) { Path path = dataDir.resolve(dataName + ".dat"); try (OutputStream outputStream = Files.newOutputStream(path, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); NBTOutputStream nbtOutputStream = NbtUtils.createNetworkWriter(outputStream)){ - nbtOutputStream.write(dataTag); + nbtOutputStream.writeTag(dataTag); } catch (IOException e) { throw new RuntimeException(e); } } - public Tag loadNBT(String dataName) { + public Object loadNBT(String dataName) { Path path = dataDir.resolve(dataName + ".dat"); try (InputStream inputStream = Files.newInputStream(path); NBTInputStream nbtInputStream = NbtUtils.createNetworkReader(inputStream)){ diff --git a/src/main/java/com/nukkitx/proxypass/network/bedrock/session/DownstreamPacketHandler.java b/src/main/java/com/nukkitx/proxypass/network/bedrock/session/DownstreamPacketHandler.java index 2d64173..dffd66b 100644 --- a/src/main/java/com/nukkitx/proxypass/network/bedrock/session/DownstreamPacketHandler.java +++ b/src/main/java/com/nukkitx/proxypass/network/bedrock/session/DownstreamPacketHandler.java @@ -3,10 +3,11 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.nimbusds.jwt.SignedJWT; -import com.nukkitx.nbt.stream.LittleEndianDataOutputStream; -import com.nukkitx.nbt.stream.NBTOutputStream; -import com.nukkitx.nbt.tag.CompoundTag; -import com.nukkitx.nbt.tag.ListTag; +import com.nukkitx.nbt.NBTOutputStream; +import com.nukkitx.nbt.NbtList; +import com.nukkitx.nbt.NbtMap; +import com.nukkitx.nbt.NbtType; +import com.nukkitx.nbt.util.stream.LittleEndianDataOutputStream; import com.nukkitx.protocol.bedrock.BedrockClientSession; import com.nukkitx.protocol.bedrock.data.inventory.ContainerId; import com.nukkitx.protocol.bedrock.data.inventory.ItemData; @@ -68,25 +69,25 @@ public boolean handle(ServerToClientHandshakePacket packet) { } public boolean handle(AvailableEntityIdentifiersPacket packet) { - proxy.saveNBT("entity_identifiers", packet.getTag()); + proxy.saveNBT("entity_identifiers", packet.getIdentifiers()); return false; } public boolean handle(BiomeDefinitionListPacket packet) { - proxy.saveNBT("biome_definitions", packet.getTag()); + proxy.saveNBT("biome_definitions", packet.getDefinitions()); return false; } public boolean handle(StartGamePacket packet) { Map legacyBlocks = new HashMap<>(); - for (CompoundTag entry : packet.getBlockPalette().getValue()) { + for (NbtMap entry : packet.getBlockPalette()) { legacyBlocks.putIfAbsent(entry.getCompound("block").getString("name"), (int) entry.getShort("id")); } proxy.saveJson("legacy_block_ids.json", sortMap(legacyBlocks)); - List palette = new ArrayList<>(packet.getBlockPalette().getValue()); + List palette = new ArrayList<>(packet.getBlockPalette()); palette.sort(Comparator.comparingInt(value -> value.getShort("id"))); - proxy.saveNBT("runtime_block_states", new ListTag<>("", CompoundTag.class, palette)); + proxy.saveNBT("runtime_block_states", new NbtList<>(NbtType.COMPOUND, palette)); BlockPaletteUtils.convertToJson(proxy, palette); List itemData = new ArrayList<>(); @@ -125,12 +126,12 @@ private void dumpCreativeItems(ItemData[] contents) { int id = data.getId(); Integer damage = data.getDamage() == 0 ? null : (int) data.getDamage(); - CompoundTag tag = data.getTag(); + NbtMap tag = data.getTag(); String tagData = null; if (tag != null) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try (NBTOutputStream stream = new NBTOutputStream(new LittleEndianDataOutputStream(byteArrayOutputStream))) { - stream.write(tag); + stream.writeTag(tag); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/main/java/com/nukkitx/proxypass/network/bedrock/util/BlockPaletteUtils.java b/src/main/java/com/nukkitx/proxypass/network/bedrock/util/BlockPaletteUtils.java index 43e9d99..886926c 100644 --- a/src/main/java/com/nukkitx/proxypass/network/bedrock/util/BlockPaletteUtils.java +++ b/src/main/java/com/nukkitx/proxypass/network/bedrock/util/BlockPaletteUtils.java @@ -1,8 +1,8 @@ package com.nukkitx.proxypass.network.bedrock.util; import com.fasterxml.jackson.annotation.JsonInclude; -import com.nukkitx.nbt.TagType; -import com.nukkitx.nbt.tag.CompoundTag; +import com.nukkitx.nbt.NbtMap; +import com.nukkitx.nbt.NbtType; import com.nukkitx.proxypass.ProxyPass; import lombok.Value; @@ -13,23 +13,23 @@ public class BlockPaletteUtils { - public static void convertToJson(ProxyPass proxy, List tags) { + public static void convertToJson(ProxyPass proxy, List tags) { List palette = new ArrayList<>(tags.size()); - for (CompoundTag tag : tags) { + for (NbtMap tag : tags) { int id = tag.getShort("id"); - CompoundTag blockTag = tag.getCompound("block"); + NbtMap blockTag = tag.getCompound("block"); String name = blockTag.getString("name"); Map states = new LinkedHashMap<>(); - blockTag.getCompound("states").getValue().forEach((key, value) -> { - states.put(key, new BlockState(value.getValue(), TagType.byClass(value.getClass()).getId())); + blockTag.getCompound("states").forEach((key, value) -> { + states.put(key, new BlockState(value, NbtType.byClass(value.getClass()).getId())); }); Integer meta = null; - if (tag.contains("meta")) { + if (tag.containsKey("meta")) { meta = (int) tag.getShort("meta"); } palette.add(new Entry(id, meta, name, states)); diff --git a/src/main/java/com/nukkitx/proxypass/network/bedrock/util/RecipeUtils.java b/src/main/java/com/nukkitx/proxypass/network/bedrock/util/RecipeUtils.java index 9a62ac4..e2c51c9 100644 --- a/src/main/java/com/nukkitx/proxypass/network/bedrock/util/RecipeUtils.java +++ b/src/main/java/com/nukkitx/proxypass/network/bedrock/util/RecipeUtils.java @@ -1,9 +1,9 @@ package com.nukkitx.proxypass.network.bedrock.util; import com.fasterxml.jackson.annotation.JsonInclude; +import com.nukkitx.nbt.NBTOutputStream; +import com.nukkitx.nbt.NbtMap; import com.nukkitx.nbt.NbtUtils; -import com.nukkitx.nbt.stream.NBTOutputStream; -import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.protocol.bedrock.data.inventory.*; import com.nukkitx.protocol.bedrock.packet.CraftingDataPacket; import com.nukkitx.proxypass.ProxyPass; @@ -111,11 +111,11 @@ private static Item[] writeItemArray(ItemData[] inputs, boolean output) { return outputs.toArray(new Item[0]); } - private static String nbtToBase64(CompoundTag tag) { + private static String nbtToBase64(NbtMap tag) { if (tag != null) { ByteArrayOutputStream tagStream = new ByteArrayOutputStream(); try (NBTOutputStream writer = NbtUtils.createWriterLE(tagStream)) { - writer.write(tag); + writer.writeTag(tag); } catch (IOException e) { throw new RuntimeException(e); }