Skip to content
Open
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
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<maven.compiler.target>8</maven.compiler.target>

<build.number>unknown</build.number>
<bungeecord.version>1.20-R0.2-SNAPSHOT</bungeecord.version>
<bungeecord.version>1.21-R0.4-SNAPSHOT</bungeecord.version>
<velocity.version>3.3.0-SNAPSHOT</velocity.version>
<bytebuddy.version>1.11.13</bytebuddy.version>
<data.version>2.4.3</data.version>
Expand All @@ -45,7 +45,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<version>1.18.38</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import dev.simplix.protocolize.api.util.ReflectionUtil;
import dev.simplix.protocolize.bungee.packet.BungeeCordProtocolizePacket;
import dev.simplix.protocolize.bungee.strategy.PacketRegistrationStrategy;
import gnu.trove.map.TIntObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import net.bytebuddy.ByteBuddy;
Expand Down Expand Up @@ -88,7 +88,7 @@ public void registerPacket(List<ProtocolIdMapping> mappings, Protocol protocol,
Preconditions.checkNotNull(packetClass, "Packet class cannot be null");
try {
Class<? extends DefinedPacket> definedPacketClass = generateBungeePacket(packetClass);
TIntObjectMap<Object> protocols = (TIntObjectMap<Object>) protocolsField
Int2ObjectMap<Object> protocols = (Int2ObjectMap<Object>) protocolsField
.get(getDirectionData(bungeeCordProtocol(protocol), direction));
for (ProtocolIdMapping mapping : mappings) {
mappingProvider.registerMapping(new RegisteredPacket(direction, packetClass), mapping);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.google.common.base.Supplier;
import dev.simplix.protocolize.api.util.ReflectionUtil;
import dev.simplix.protocolize.bungee.strategy.PacketRegistrationStrategy;
import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.TObjectIntMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import net.md_5.bungee.api.ProxyServer;

import java.lang.reflect.Field;
Expand All @@ -22,13 +22,13 @@ public class AegisPacketRegistrationStrategy implements PacketRegistrationStrate
private final Field protocolDataPacketMapField = ReflectionUtil.fieldOrNull(protocolDataClass, "packetMap", true);

@Override
public void registerPacket(TIntObjectMap<Object> protocols, int protocolVersion, int packetId, Class<?> clazz) throws IllegalAccessException {
public void registerPacket(Int2ObjectMap<Object> protocols, int protocolVersion, int packetId, Class<?> clazz) throws IllegalAccessException {
final Object protocolData = protocols.get(protocolVersion);
if (protocolData == null) {
ProxyServer.getInstance().getLogger().finest("[Protocolize | DEBUG] Protocol version " + protocolVersion + " is not supported on this aegis version. Skipping registration for that specific version.");
return;
}
((TObjectIntMap<Class<?>>) protocolDataPacketMapField.get(protocolData)).put(clazz, packetId);
((Object2IntMap<Class<?>>) protocolDataPacketMapField.get(protocolData)).put(clazz, packetId);
((Supplier[]) protocolDataConstructorsField.get(protocolData))[packetId] = () -> {
try {
return clazz.getDeclaredConstructor().newInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import dev.simplix.protocolize.api.util.ReflectionUtil;
import dev.simplix.protocolize.bungee.strategy.PacketRegistrationStrategy;
import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.TObjectIntMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Field;
Expand All @@ -22,13 +22,13 @@ public final class BungeeCordPacketRegistrationStrategy implements PacketRegistr
private final Field protocolDataPacketMapField = ReflectionUtil.fieldOrNull(protocolDataClass, "packetMap", true);

@Override
public void registerPacket(TIntObjectMap<Object> protocols, int protocolVersion, int packetId, Class<?> clazz) throws IllegalAccessException {
public void registerPacket(Int2ObjectMap<Object> protocols, int protocolVersion, int packetId, Class<?> clazz) throws IllegalAccessException {
final Object protocolData = protocols.get(protocolVersion);
if (protocolData == null) {
log.debug("[Protocolize | DEBUG] Protocol version {} is not supported on this version. Skipping registration for that specific version.", protocolVersion);
return;
}
((TObjectIntMap<Class<?>>) protocolDataPacketMapField.get(protocolData)).put(clazz, packetId);
((Object2IntMap<Class<?>>) protocolDataPacketMapField.get(protocolData)).put(clazz, packetId);
((Supplier[]) protocolDataConstructorsField.get(protocolData))[packetId] = () -> {
try {
return clazz.getDeclaredConstructor().newInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import dev.simplix.protocolize.api.util.ReflectionUtil;
import dev.simplix.protocolize.bungee.strategy.PacketRegistrationStrategy;
import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.TObjectIntMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import lombok.SneakyThrows;
import net.md_5.bungee.api.ProxyServer;

Expand All @@ -23,13 +23,13 @@ public final class LegacyBungeeCordPacketRegistrationStrategy implements PacketR

@SneakyThrows
@Override
public void registerPacket(TIntObjectMap<Object> protocols, int protocolVersion, int packetId, Class<?> clazz) throws IllegalAccessException {
public void registerPacket(Int2ObjectMap<Object> protocols, int protocolVersion, int packetId, Class<?> clazz) throws IllegalAccessException {
final Object protocolData = protocols.get(protocolVersion);
if (protocolData == null) {
ProxyServer.getInstance().getLogger().finest("[Protocolize | DEBUG] Protocol version " + protocolVersion + " is not supported on this version. Skipping registration for that specific version.");
return;
}
TObjectIntMap<Class<?>> map = ((TObjectIntMap<Class<?>>) protocolDataPacketMapField.get(protocolData));
Object2IntMap<Class<?>> map = ((Object2IntMap<Class<?>>) protocolDataPacketMapField.get(protocolData));
map.put(clazz, packetId);
((Constructor[]) protocolDataConstructorsField.get(protocolData))[packetId] = clazz.getDeclaredConstructor();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.simplix.protocolize.bungee.strategy;

import gnu.trove.map.TIntObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;

/**
* Date: 21.08.2021
Expand All @@ -9,7 +9,7 @@
*/
public interface PacketRegistrationStrategy {

void registerPacket(TIntObjectMap<Object> protocols, int protocolVersion, int packetId, Class<?> clazz) throws IllegalAccessException;
void registerPacket(Int2ObjectMap<Object> protocols, int protocolVersion, int packetId, Class<?> clazz) throws IllegalAccessException;

boolean compatible();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,54 +1,56 @@
package dev.simplix.protocolize.bungee.util;

import net.md_5.bungee.nbt.TypedTag;
import net.md_5.bungee.nbt.NamedTag;
import net.querz.nbt.tag.*;
import se.llbit.nbt.NamedTag;
import se.llbit.nbt.SpecificTag;

import java.util.Map;

public class JoNbtToQuerzNbtMapper {

public static ByteTag convertByteTag(se.llbit.nbt.ByteTag in) {
return new ByteTag((byte) in.value);
public static ByteTag convertByteTag(net.md_5.bungee.nbt.type.ByteTag in) {
return new ByteTag((byte) in.getValue());
}

public static StringTag convertStringTag(se.llbit.nbt.StringTag in) {
return new StringTag(in.value);
public static StringTag convertStringTag(net.md_5.bungee.nbt.type.StringTag in) {
return new StringTag(in.getValue());
}

public static IntTag convertIntTag(se.llbit.nbt.IntTag in) {
return new IntTag(in.value);
public static IntTag convertIntTag(net.md_5.bungee.nbt.type.IntTag in) {
return new IntTag(in.getValue());
}

public static ShortTag convertShortTag(se.llbit.nbt.ShortTag in) {
return new ShortTag(in.value);
public static ShortTag convertShortTag(net.md_5.bungee.nbt.type.ShortTag in) {
return new ShortTag(in.getValue());
}

public static LongTag convertLongTag(se.llbit.nbt.LongTag in) {
return new LongTag(in.value);
public static LongTag convertLongTag(net.md_5.bungee.nbt.type.LongTag in) {
return new LongTag(in.getValue());
}

public static FloatTag convertFloatTag(se.llbit.nbt.FloatTag in) {
return new FloatTag(in.value);
public static FloatTag convertFloatTag(net.md_5.bungee.nbt.type.FloatTag in) {
return new FloatTag(in.getValue());
}

public static DoubleTag convertDoubleTag(se.llbit.nbt.DoubleTag in) {
return new DoubleTag(in.value);
public static DoubleTag convertDoubleTag(net.md_5.bungee.nbt.type.DoubleTag in) {
return new DoubleTag(in.getValue());
}

public static ByteArrayTag convertByteArrayTag(se.llbit.nbt.ByteArrayTag in) {
return new ByteArrayTag(in.value);
public static ByteArrayTag convertByteArrayTag(net.md_5.bungee.nbt.type.ByteArrayTag in) {
return new ByteArrayTag(in.getValue());
}

public static LongArrayTag convertLongArrayTag(se.llbit.nbt.LongArrayTag in) {
return new LongArrayTag(in.value);
public static LongArrayTag convertLongArrayTag(net.md_5.bungee.nbt.type.LongArrayTag in) {
return new LongArrayTag(in.getValue());
}

public static IntArrayTag convertIntArrayTag(se.llbit.nbt.IntArrayTag in) {
return new IntArrayTag(in.value);
public static IntArrayTag convertIntArrayTag(net.md_5.bungee.nbt.type.IntArrayTag in) {
return new IntArrayTag(in.getValue());
}

public static ListTag<?> convertListTag(se.llbit.nbt.ListTag in) {
ListTag tag = new ListTag<>(convertTagType(in.type));
for (SpecificTag stag : in) {
public static ListTag<?> convertListTag(net.md_5.bungee.nbt.type.ListTag in) {
ListTag tag = new ListTag<>(convertTagType(in.getListType()));
for (TypedTag stag : in.getValue()) {
tag.add(convertSpecificTag(stag));
}
return tag;
Expand Down Expand Up @@ -85,44 +87,40 @@ private static Class<? extends Tag<?>> convertTagType(int type) {
}
}

public static Tag<?> convertSpecificTag(SpecificTag in) {
if (in.isCompoundTag()) {
return convertCompoundTag(in.asCompound());
} else if (in instanceof se.llbit.nbt.ByteTag) {
return convertByteTag((se.llbit.nbt.ByteTag) in);
} else if (in instanceof se.llbit.nbt.StringTag) {
return convertStringTag((se.llbit.nbt.StringTag) in);
} else if (in instanceof se.llbit.nbt.IntTag) {
return convertIntTag((se.llbit.nbt.IntTag) in);
} else if (in instanceof se.llbit.nbt.ShortTag) {
return convertShortTag((se.llbit.nbt.ShortTag) in);
} else if (in instanceof se.llbit.nbt.LongTag) {
return convertLongTag((se.llbit.nbt.LongTag) in);
} else if (in instanceof se.llbit.nbt.FloatTag) {
return convertFloatTag((se.llbit.nbt.FloatTag) in);
} else if (in instanceof se.llbit.nbt.DoubleTag) {
return convertDoubleTag((se.llbit.nbt.DoubleTag) in);
} else if (in instanceof se.llbit.nbt.ByteArrayTag) {
return convertByteArrayTag((se.llbit.nbt.ByteArrayTag) in);
} else if (in instanceof se.llbit.nbt.LongArrayTag) {
return convertLongArrayTag((se.llbit.nbt.LongArrayTag) in);
} else if (in instanceof se.llbit.nbt.IntArrayTag) {
return convertIntArrayTag((se.llbit.nbt.IntArrayTag) in);
} else if (in instanceof se.llbit.nbt.ListTag) {
return convertListTag((se.llbit.nbt.ListTag) in);
public static Tag<?> convertSpecificTag(TypedTag in) {
if (in instanceof CompoundTag) {
return convertCompoundTag((net.md_5.bungee.nbt.type.CompoundTag) in);
} else if (in instanceof net.md_5.bungee.nbt.type.ByteTag) {
return convertByteTag((net.md_5.bungee.nbt.type.ByteTag) in);
} else if (in instanceof net.md_5.bungee.nbt.type.StringTag) {
return convertStringTag((net.md_5.bungee.nbt.type.StringTag) in);
} else if (in instanceof net.md_5.bungee.nbt.type.IntTag) {
return convertIntTag((net.md_5.bungee.nbt.type.IntTag) in);
} else if (in instanceof net.md_5.bungee.nbt.type.ShortTag) {
return convertShortTag((net.md_5.bungee.nbt.type.ShortTag) in);
} else if (in instanceof net.md_5.bungee.nbt.type.LongTag) {
return convertLongTag((net.md_5.bungee.nbt.type.LongTag) in);
} else if (in instanceof net.md_5.bungee.nbt.type.FloatTag) {
return convertFloatTag((net.md_5.bungee.nbt.type.FloatTag) in);
} else if (in instanceof net.md_5.bungee.nbt.type.DoubleTag) {
return convertDoubleTag((net.md_5.bungee.nbt.type.DoubleTag) in);
} else if (in instanceof net.md_5.bungee.nbt.type.ByteArrayTag) {
return convertByteArrayTag((net.md_5.bungee.nbt.type.ByteArrayTag) in);
} else if (in instanceof net.md_5.bungee.nbt.type.LongArrayTag) {
return convertLongArrayTag((net.md_5.bungee.nbt.type.LongArrayTag) in);
} else if (in instanceof net.md_5.bungee.nbt.type.IntArrayTag) {
return convertIntArrayTag((net.md_5.bungee.nbt.type.IntArrayTag) in);
} else if (in instanceof net.md_5.bungee.nbt.type.ListTag) {
return convertListTag((net.md_5.bungee.nbt.type.ListTag) in);
} else {
throw new IllegalArgumentException("Unsupported tag type " + in.tagType());
throw new IllegalArgumentException("Unsupported tag type " + in.getClass().getSimpleName());
}
}

public static CompoundTag convertCompoundTag(se.llbit.nbt.CompoundTag in) {
public static CompoundTag convertCompoundTag(net.md_5.bungee.nbt.type.CompoundTag in) {
CompoundTag out = new CompoundTag();
for (NamedTag tag : in) {
if (tag.isCompoundTag()) {
out.put(tag.name(), convertCompoundTag(tag.asCompound()));
} else {
out.put(tag.name(), convertSpecificTag(tag.getTag()));
}
for (Map.Entry<String, TypedTag> tag : in.getValue().entrySet()) {
out.put(tag.getKey(), convertSpecificTag(tag.getValue()));
}
return out;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dev.simplix.protocolize.bungee.util;

import se.llbit.nbt.*;
import net.md_5.bungee.nbt.TypedTag;
import net.md_5.bungee.nbt.type.*;
import net.md_5.bungee.nbt.Tag;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -49,43 +51,43 @@ public static IntArrayTag convertIntArrayTag(net.querz.nbt.tag.IntArrayTag in) {
}

public static ListTag convertListTag(net.querz.nbt.tag.ListTag<?> in) {
List<SpecificTag> tags = new ArrayList<>();
List<TypedTag> tags = new ArrayList<>();
for (net.querz.nbt.tag.Tag<?> stag : in) {
tags.add(convertSpecificTag(stag));
}
return new ListTag(convertTagType(in.getTypeClass()), tags);
return new ListTag(tags, convertTagType(in.getTypeClass()));
}

private static int convertTagType(Class<?> clazz) {
private static byte convertTagType(Class<?> clazz) {
if (clazz.equals(net.querz.nbt.tag.ByteTag.class)) {
return Tag.TAG_BYTE;
return Tag.BYTE;
} else if (clazz.equals(net.querz.nbt.tag.StringTag.class)) {
return Tag.TAG_STRING;
return Tag.STRING;
} else if (clazz.equals(net.querz.nbt.tag.IntTag.class)) {
return Tag.TAG_INT;
return Tag.INT;
} else if (clazz.equals(net.querz.nbt.tag.ShortTag.class)) {
return Tag.TAG_SHORT;
return Tag.SHORT;
} else if (clazz.equals(net.querz.nbt.tag.LongTag.class)) {
return Tag.TAG_LONG;
return Tag.LONG;
} else if (clazz.equals(net.querz.nbt.tag.FloatTag.class)) {
return Tag.TAG_FLOAT;
return Tag.FLOAT;
} else if (clazz.equals(net.querz.nbt.tag.DoubleTag.class)) {
return Tag.TAG_DOUBLE;
return Tag.DOUBLE;
} else if (clazz.equals(net.querz.nbt.tag.ByteArrayTag.class)) {
return Tag.TAG_BYTE_ARRAY;
return Tag.BYTE_ARRAY;
} else if (clazz.equals(net.querz.nbt.tag.LongArrayTag.class)) {
return Tag.TAG_LONG_ARRAY;
return Tag.LONG_ARRAY;
} else if (clazz.equals(net.querz.nbt.tag.IntArrayTag.class)) {
return Tag.TAG_INT_ARRAY;
return Tag.INT_ARRAY;
} else if (clazz.equals(net.querz.nbt.tag.ListTag.class)) {
return Tag.TAG_LIST;
return Tag.LIST;
} else if (clazz.equals(net.querz.nbt.tag.CompoundTag.class)) {
return Tag.TAG_COMPOUND;
return Tag.COMPOUND;
}
throw new IllegalArgumentException("Unsupported tag type " + clazz.getSimpleName());
}

public static SpecificTag convertSpecificTag(net.querz.nbt.tag.Tag<?> in) {
public static TypedTag convertSpecificTag(net.querz.nbt.tag.Tag<?> in) {
if (in instanceof net.querz.nbt.tag.CompoundTag) {
return convertCompoundTag((net.querz.nbt.tag.CompoundTag) in);
} else if (in instanceof net.querz.nbt.tag.ByteTag) {
Expand Down Expand Up @@ -118,7 +120,7 @@ public static SpecificTag convertSpecificTag(net.querz.nbt.tag.Tag<?> in) {
public static CompoundTag convertCompoundTag(net.querz.nbt.tag.CompoundTag in) {
CompoundTag out = new CompoundTag();
for (Map.Entry<String, net.querz.nbt.tag.Tag<?>> tag : in) {
out.add(tag.getKey(), convertSpecificTag(tag.getValue()));
out.getValue().put(tag.getKey(), convertSpecificTag(tag.getValue()));
}
return out;
}
Expand Down