mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-27 05:05:24 +01:00
fix: gracefully fail for unknown protocols
Fixes #3012 Fixes #3001 Fixes #2994
This commit is contained in:
parent
46d40d752e
commit
2cad996252
@ -741,11 +741,7 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
STATUS("Status", "status"),
|
||||
LOGIN("Login", "login"),
|
||||
CONFIGURATION("Configuration", "configuration"),
|
||||
|
||||
/**
|
||||
* Only for packets removed in Minecraft 1.7.2
|
||||
*/
|
||||
LEGACY("", "");
|
||||
UNKNOWN("", "");
|
||||
|
||||
private final String packetName;
|
||||
private final String mojangName;
|
||||
@ -761,14 +757,17 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
* @return The corresponding protocol.
|
||||
*/
|
||||
public static Protocol fromVanilla(Enum<?> vanilla) {
|
||||
if (vanilla == null) {
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
switch (vanilla.name()) {
|
||||
case "HANDSHAKING": return HANDSHAKING;
|
||||
case "PLAY": return PLAY;
|
||||
case "STATUS": return STATUS;
|
||||
case "LOGIN": return LOGIN;
|
||||
case "CONFIGURATION": return CONFIGURATION;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unrecognized vanilla enum " + vanilla);
|
||||
default: return UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,9 +11,6 @@ import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.PacketType.Protocol;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
@ -46,6 +43,8 @@ import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.EventLoop;
|
||||
import io.netty.util.AttributeKey;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class NettyChannelInjector implements Injector {
|
||||
|
||||
@ -583,8 +582,12 @@ public class NettyChannelInjector implements Injector {
|
||||
}
|
||||
|
||||
PacketType.Protocol protocol = this.getCurrentProtocol(PacketType.Sender.SERVER);
|
||||
if (protocol == Protocol.UNKNOWN) {
|
||||
ProtocolLogger.debug("skipping unknown protocol for {0}", packet.getClass());
|
||||
return action;
|
||||
}
|
||||
|
||||
PacketType packetType = PacketRegistry.getPacketType(protocol, packet.getClass());
|
||||
|
||||
if (packetType == null) {
|
||||
ProtocolLogger.debug("skipping unknown outbound packet type for {0}", packet.getClass());
|
||||
return action;
|
||||
|
Loading…
Reference in New Issue
Block a user