Skip to content

Commit

Permalink
1.1.14: Move registerPacket to Limbo interface (Elytrium#96)
Browse files Browse the repository at this point in the history
Former-commit-id: 894784e
  • Loading branch information
JNNGL authored Jul 2, 2023
1 parent 8a1db84 commit 269fdea
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 63 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.13
1.1.14
5 changes: 5 additions & 0 deletions api/src/main/java/net/elytrium/limboapi/api/Limbo.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
import com.velocitypowered.api.command.Command;
import com.velocitypowered.api.command.CommandMeta;
import com.velocitypowered.api.proxy.Player;
import java.util.function.Supplier;
import net.elytrium.limboapi.api.command.LimboCommandMeta;
import net.elytrium.limboapi.api.player.GameMode;
import net.elytrium.limboapi.api.protocol.PacketDirection;
import net.elytrium.limboapi.api.protocol.packets.PacketMapping;

public interface Limbo {

Expand Down Expand Up @@ -47,5 +50,7 @@ public interface Limbo {

Limbo registerCommand(CommandMeta commandMeta, Command command);

Limbo registerPacket(PacketDirection direction, Class<?> packetClass, Supplier<?> packetSupplier, PacketMapping[] packetMappings);

void dispose();
}
2 changes: 2 additions & 0 deletions api/src/main/java/net/elytrium/limboapi/api/LimboFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ public interface LimboFactory {
* @param packetClass Packet class.
* @param packetSupplier Packet supplier to make a new instance. (::new)
* @param packetMappings Packet id mappings.
* @deprecated Use {@link Limbo#registerPacket} instead.
*/
@Deprecated(forRemoval = true)
void registerPacket(PacketDirection direction, Class<?> packetClass, Supplier<?> packetSupplier, PacketMapping[] packetMappings);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ default void onChat(String chat) {
}

/**
* @param packet Any velocity built-in packet or any packet registered via {@link LimboFactory#registerPacket}.
* @param packet Any velocity built-in packet or any packet registered via {@link Limbo#registerPacket}.
*/
default void onGeneric(Object packet) {

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ allprojects {
apply(plugin: "org.cadixdev.licenser")

setGroup("net.elytrium.limboapi")
setVersion("1.1.13")
setVersion("1.1.14")

compileJava {
getOptions().setEncoding("UTF-8")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fastPrepareVersion=1.0.5
fastPrepareVersion=1.0.7
velocityVersion=3.2.0-SNAPSHOT
nettyVersion=4.1.86.Final
fastutilVersion=8.5.11
Expand Down
27 changes: 5 additions & 22 deletions plugin/src/main/java/net/elytrium/limboapi/LimboAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@
@SuppressFBWarnings("MS_EXPOSE_REP")
public class LimboAPI implements LimboFactory {

private static final Map<Class<?>, Class<?>> PRIMITIVE_WRAPPER_MAP = new HashMap<>();
private static final int SUPPORTED_MAXIMUM_PROTOCOL_VERSION_NUMBER = 763;

@MonotonicNonNull
Expand Down Expand Up @@ -435,17 +434,9 @@ public void fixCompressor(ChannelPipeline pipeline, ProtocolVersion version) {
}
}

private Class<?> primitiveToWrapper(Class<?> cls) {
if (cls.isPrimitive()) {
return PRIMITIVE_WRAPPER_MAP.get(cls);
} else {
return cls;
}
}

@Override
public void registerPacket(PacketDirection direction, Class<?> packetClass, Supplier<?> packetSupplier, PacketMapping[] packetMappings) {
LimboProtocol.register(direction, packetClass, packetSupplier, packetMappings);
throw new UnsupportedOperationException();
}

@Override
Expand Down Expand Up @@ -568,6 +559,10 @@ public boolean isCompressionEnabled() {
return this.compressionEnabled;
}

public PreparedPacketFactory getPreparedPacketFactory() {
return this.preparedPacketFactory;
}

public ProtocolVersion getPrepareMinVersion() {
return this.minVersion;
}
Expand All @@ -591,18 +586,6 @@ public WorldFile openWorldFile(BuiltInWorldFileType apiType, CompoundBinaryTag t
return WorldFileTypeRegistry.fromApiType(apiType, tag);
}

static {
PRIMITIVE_WRAPPER_MAP.put(Boolean.TYPE, Boolean.class);
PRIMITIVE_WRAPPER_MAP.put(Byte.TYPE, Byte.class);
PRIMITIVE_WRAPPER_MAP.put(Character.TYPE, Character.class);
PRIMITIVE_WRAPPER_MAP.put(Short.TYPE, Short.class);
PRIMITIVE_WRAPPER_MAP.put(Integer.TYPE, Integer.class);
PRIMITIVE_WRAPPER_MAP.put(Long.TYPE, Long.class);
PRIMITIVE_WRAPPER_MAP.put(Double.TYPE, Double.class);
PRIMITIVE_WRAPPER_MAP.put(Float.TYPE, Float.class);
PRIMITIVE_WRAPPER_MAP.put(Void.TYPE, Void.TYPE);
}

private static void setLogger(Logger logger) {
LOGGER = logger;
}
Expand Down

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions plugin/src/main/java/net/elytrium/limboapi/server/LimboImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.velocitypowered.proxy.network.Connections;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.VelocityConnectionEvent;
import com.velocitypowered.proxy.protocol.packet.AvailableCommands;
import com.velocitypowered.proxy.protocol.packet.JoinGame;
Expand Down Expand Up @@ -70,6 +71,7 @@
import java.util.concurrent.atomic.LongAdder;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Supplier;
import net.elytrium.commons.utils.reflection.ReflectionException;
import net.elytrium.fastprepare.PreparedPacketFactory;
import net.elytrium.limboapi.LimboAPI;
Expand All @@ -81,7 +83,9 @@
import net.elytrium.limboapi.api.chunk.VirtualWorld;
import net.elytrium.limboapi.api.command.LimboCommandMeta;
import net.elytrium.limboapi.api.player.GameMode;
import net.elytrium.limboapi.api.protocol.PacketDirection;
import net.elytrium.limboapi.api.protocol.PreparedPacket;
import net.elytrium.limboapi.api.protocol.packets.PacketMapping;
import net.elytrium.limboapi.injection.packet.MinecraftLimitedCompressDecoder;
import net.elytrium.limboapi.material.Biome;
import net.elytrium.limboapi.protocol.LimboProtocol;
Expand Down Expand Up @@ -143,6 +147,7 @@ public class LimboImpl implements Limbo {
private PreparedPacket firstChunks;
private List<PreparedPacket> delayedChunks;
private PreparedPacket respawnPackets;
private StateRegistry localStateRegistry;
private boolean shouldRespawn = true;
private boolean shouldRejoin = true;
private boolean shouldUpdateTags = true;
Expand All @@ -155,6 +160,7 @@ public class LimboImpl implements Limbo {
public LimboImpl(LimboAPI plugin, VirtualWorld world) {
this.plugin = plugin;
this.world = world;
this.localStateRegistry = LimboProtocol.getLimboStateRegistry();

this.refresh();
}
Expand Down Expand Up @@ -240,8 +246,8 @@ public void spawnPlayer(Player apiPlayer, LimboSessionHandler handler) {

boolean shouldSpawnPlayerImmediately = true;

if (connection.getState() != LimboProtocol.getLimboStateRegistry()) {
connection.eventLoop().execute(() -> connection.setState(LimboProtocol.getLimboStateRegistry()));
if (connection.getState() != this.localStateRegistry) {
connection.eventLoop().execute(() -> connection.setState(this.localStateRegistry));
VelocityServerConnection server = player.getConnectedServer();
if (server != null) {
RegisteredServer previousServer = server.getServer();
Expand Down Expand Up @@ -525,6 +531,17 @@ public Limbo registerCommand(CommandMeta commandMeta, Command command) {
throw new IllegalArgumentException(command + " does not implement a registrable Command sub-interface.");
}

public Limbo registerPacket(PacketDirection direction, Class<?> packetClass, Supplier<?> packetSupplier, PacketMapping[] packetMappings) {
if (this.localStateRegistry == LimboProtocol.getLimboStateRegistry()) {
this.localStateRegistry = LimboProtocol.createLocalStateRegistry();
this.plugin.getPreparedPacketFactory().addStateRegistry(this.localStateRegistry);
}

LimboProtocol.register(this.localStateRegistry, direction, packetClass, packetSupplier, packetMappings);

return this;
}

@Override
public void dispose() {
if (this.getCurrentOnline() == 0) {
Expand Down

0 comments on commit 269fdea

Please sign in to comment.