mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-11-21 10:18:36 -05:00
Compare commits
5 commits
a4714d1c05
...
f196c0cef5
Author | SHA1 | Date | |
---|---|---|---|
|
f196c0cef5 | ||
|
e6acb395fb | ||
|
8150091888 | ||
|
88188c5b39 | ||
|
f82aa5bc87 |
4 changed files with 13 additions and 12 deletions
|
@ -19,17 +19,24 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class TcpServer extends AbstractServer {
|
||||
private static final TransportHelper.TransportType TRANSPORT_TYPE = TransportHelper.determineTransportMethod();
|
||||
private static final Logger log = LoggerFactory.getLogger(TcpServer.class);
|
||||
|
||||
private final Supplier<Executor> packetHandlerExecutorFactory;
|
||||
private EventLoopGroup group;
|
||||
private Channel channel;
|
||||
|
||||
public TcpServer(String host, int port, Supplier<? extends PacketProtocol> protocol) {
|
||||
this(host, port, protocol, DefaultPacketHandlerExecutor::createExecutor);
|
||||
}
|
||||
|
||||
public TcpServer(String host, int port, Supplier<? extends PacketProtocol> protocol, Supplier<Executor> packetHandlerExecutorFactory) {
|
||||
super(host, port, protocol);
|
||||
this.packetHandlerExecutorFactory = packetHandlerExecutorFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,7 +64,7 @@ public class TcpServer extends AbstractServer {
|
|||
InetSocketAddress address = (InetSocketAddress) channel.remoteAddress();
|
||||
PacketProtocol protocol = createPacketProtocol();
|
||||
|
||||
TcpSession session = new TcpServerSession(address.getHostName(), address.getPort(), protocol, TcpServer.this);
|
||||
TcpSession session = new TcpServerSession(address.getHostName(), address.getPort(), protocol, TcpServer.this, packetHandlerExecutorFactory.get());
|
||||
session.getPacketProtocol().newServerSession(TcpServer.this, session);
|
||||
|
||||
ChannelPipeline pipeline = channel.pipeline();
|
||||
|
|
|
@ -7,13 +7,14 @@ import org.geysermc.mcprotocollib.network.packet.PacketProtocol;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public class TcpServerSession extends TcpSession {
|
||||
private final TcpServer server;
|
||||
private final PacketCodecHelper codecHelper;
|
||||
|
||||
public TcpServerSession(String host, int port, PacketProtocol protocol, TcpServer server) {
|
||||
super(host, port, protocol, DefaultPacketHandlerExecutor.createExecutor());
|
||||
public TcpServerSession(String host, int port, PacketProtocol protocol, TcpServer server, Executor packetHandlerExecutor) {
|
||||
super(host, port, protocol, packetHandlerExecutor);
|
||||
this.server = server;
|
||||
this.codecHelper = protocol.createHelper();
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ public class DataComponentType<T> {
|
|||
public static final DataComponentType<List<ItemStack>> CONTAINER = new DataComponentType<>(listReader(ItemCodecHelper::readOptionalItemStack), listWriter(MinecraftCodecHelper::writeOptionalItemStack), ObjectDataComponent::new);
|
||||
public static final DataComponentType<BlockStateProperties> BLOCK_STATE = new DataComponentType<>(ItemCodecHelper::readBlockStateProperties, ItemCodecHelper::writeBlockStateProperties, ObjectDataComponent::new);
|
||||
public static final DataComponentType<List<BeehiveOccupant>> BEES = new DataComponentType<>(listReader(ItemCodecHelper::readBeehiveOccupant), listWriter(ItemCodecHelper::writeBeehiveOccupant), ObjectDataComponent::new);
|
||||
public static final DataComponentType<String> LOCK = new DataComponentType<>(ItemCodecHelper::readLock, ItemCodecHelper::writeLock, ObjectDataComponent::new);
|
||||
public static final DataComponentType<NbtMap> LOCK = new DataComponentType<>(ItemCodecHelper::readCompoundTag, ItemCodecHelper::writeAnyTag, ObjectDataComponent::new);
|
||||
public static final DataComponentType<NbtMap> CONTAINER_LOOT = new DataComponentType<>(ItemCodecHelper::readCompoundTag, ItemCodecHelper::writeAnyTag, ObjectDataComponent::new);
|
||||
|
||||
protected final int id;
|
||||
|
|
|
@ -158,6 +158,7 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
|
|||
}
|
||||
|
||||
this.writeNullable(buf, equippable.model(), this::writeResourceLocation);
|
||||
this.writeNullable(buf, equippable.cameraOverlay(), this::writeResourceLocation);
|
||||
this.writeNullable(buf, equippable.allowedEntities(), this::writeHolderSet);
|
||||
buf.writeBoolean(equippable.dispensable());
|
||||
buf.writeBoolean(equippable.swappable());
|
||||
|
@ -637,12 +638,4 @@ public class ItemCodecHelper extends MinecraftCodecHelper {
|
|||
this.writeVarInt(buf, occupant.getTicksInHive());
|
||||
this.writeVarInt(buf, occupant.getMinTicksInHive());
|
||||
}
|
||||
|
||||
public String readLock(ByteBuf buf) {
|
||||
return this.readAnyTag(buf, NbtType.STRING);
|
||||
}
|
||||
|
||||
public void writeLock(ByteBuf buf, String key) {
|
||||
this.writeAnyTag(buf, key);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue