Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 08:30:09 +01:00
javadoc, fix possible NPE
Dieser Commit ist enthalten in:
Ursprung
17115460b7
Commit
b61edb0d8e
@ -483,6 +483,14 @@ public class PacketWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send this packet to the server.
|
||||||
|
*
|
||||||
|
* @param packetProtocol - The protocol version of the packet.
|
||||||
|
* @param skipCurrentPipeline - Skip the current pipeline
|
||||||
|
* @param currentThread - Run in the same thread
|
||||||
|
* @throws Exception if it fails to write
|
||||||
|
*/
|
||||||
public void sendToServer(Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline, boolean currentThread) throws Exception {
|
public void sendToServer(Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline, boolean currentThread) throws Exception {
|
||||||
if (!isCancelled()) {
|
if (!isCancelled()) {
|
||||||
ByteBuf output = constructPacket(packetProtocol, skipCurrentPipeline, Direction.INCOMING);
|
ByteBuf output = constructPacket(packetProtocol, skipCurrentPipeline, Direction.INCOMING);
|
||||||
|
@ -3,8 +3,10 @@ package us.myles.ViaVersion.api.data;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.socket.SocketChannel;
|
import io.netty.channel.socket.SocketChannel;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NonNull;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
@ -19,6 +21,13 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class UserConnection {
|
public class UserConnection {
|
||||||
|
/**
|
||||||
|
* The channel of the user.
|
||||||
|
* /!\ In some unofficial platforms this is a client channel
|
||||||
|
*
|
||||||
|
* TODO - Weak this field to {@link io.netty.channel.Channel}?
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
private final SocketChannel channel;
|
private final SocketChannel channel;
|
||||||
Map<Class, StoredObject> storedObjects = new ConcurrentHashMap<>();
|
Map<Class, StoredObject> storedObjects = new ConcurrentHashMap<>();
|
||||||
private boolean active = true;
|
private boolean active = true;
|
||||||
@ -199,6 +208,12 @@ public class UserConnection {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a raw packet to the server
|
||||||
|
*
|
||||||
|
* @param packet Raw packet to be sent
|
||||||
|
* @param currentThread If {@code true} executes immediately, {@code false} submits a task to EventLoop
|
||||||
|
*/
|
||||||
public void sendRawPacketToServer(final ByteBuf packet, boolean currentThread) {
|
public void sendRawPacketToServer(final ByteBuf packet, boolean currentThread) {
|
||||||
final ByteBuf buf = packet.alloc().buffer();
|
final ByteBuf buf = packet.alloc().buffer();
|
||||||
try {
|
try {
|
||||||
@ -209,17 +224,31 @@ public class UserConnection {
|
|||||||
}
|
}
|
||||||
buf.writeBytes(packet);
|
buf.writeBytes(packet);
|
||||||
packet.release();
|
packet.release();
|
||||||
|
final ChannelHandlerContext context = PipelineUtil.getPreviousContext(Via.getManager().getInjector().getDecoderName(), getChannel().pipeline());
|
||||||
if (currentThread) {
|
if (currentThread) {
|
||||||
PipelineUtil.getPreviousContext(Via.getManager().getInjector().getDecoderName(), getChannel().pipeline()).fireChannelRead(buf);
|
if (context != null) {
|
||||||
|
context.fireChannelRead(buf);
|
||||||
|
} else {
|
||||||
|
getChannel().pipeline().fireChannelRead(buf);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
channel.eventLoop().submit(new Runnable() {
|
channel.eventLoop().submit(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PipelineUtil.getPreviousContext(Via.getManager().getInjector().getDecoderName(), getChannel().pipeline()).fireChannelRead(buf);
|
if (context != null) {
|
||||||
|
context.fireChannelRead(buf);
|
||||||
|
} else {
|
||||||
|
getChannel().pipeline().fireChannelRead(buf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a raw packet to the server. It will submit a task to EventLoop
|
||||||
|
*
|
||||||
|
* @param packet Raw packet to be sent
|
||||||
|
*/
|
||||||
public void sendRawPacketToServer(ByteBuf packet) { sendRawPacketToServer(packet, false); }
|
public void sendRawPacketToServer(ByteBuf packet) { sendRawPacketToServer(packet, false); }
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren