Add some debug info for #202

Also /really/ make sure it's only called once
This commit is contained in:
Dan Mulloy 2016-05-18 20:47:08 -04:00
parent 411b7a2446
commit c1ae6f14fc
3 changed files with 441 additions and 429 deletions

View File

@ -32,6 +32,10 @@ public class ProtocolLogger {
ProtocolLogger.logger = plugin.getLogger(); ProtocolLogger.logger = plugin.getLogger();
} }
private static boolean isDebugEnabled() {
return ProtocolLibrary.getConfig().isDebug();
}
/** /**
* Logs a message to console with a given level. * Logs a message to console with a given level.
* @param level Logging level * @param level Logging level
@ -60,4 +64,10 @@ public class ProtocolLogger {
public static void log(Level level, String message, Throwable ex) { public static void log(Level level, String message, Throwable ex) {
logger.log(level, message, ex); logger.log(level, message, ex);
} }
public static void debug(String message, Object... args) {
if (isDebugEnabled()) {
log("[Debug] " + message, args);
}
}
} }

View File

@ -1,108 +1,111 @@
/** /**
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2015 dmulloy2 * Copyright (C) 2015 dmulloy2
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 2 of * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * See the GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License along with this program; * You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 02111-1307 USA
*/ */
package com.comphenix.protocol.injector.netty; package com.comphenix.protocol.injector.netty;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.PacketType.Protocol; import com.comphenix.protocol.ProtocolLogger;
import com.comphenix.protocol.PacketType.Sender; import com.comphenix.protocol.PacketType.Protocol;
import com.comphenix.protocol.injector.netty.ProtocolRegistry; import com.comphenix.protocol.PacketType.Sender;
import com.comphenix.protocol.injector.packet.MapContainer; import com.comphenix.protocol.injector.netty.ProtocolRegistry;
import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.injector.packet.MapContainer;
import com.google.common.collect.Maps; import com.comphenix.protocol.reflect.StructureModifier;
import com.google.common.collect.Maps;
/**
* @author dmulloy2 /**
*/ * @author dmulloy2
*/
public class NettyProtocolRegistry extends ProtocolRegistry {
public class NettyProtocolRegistry extends ProtocolRegistry {
public NettyProtocolRegistry() {
super(); public NettyProtocolRegistry() {
} super();
}
@Override
protected synchronized void initialize() { @Override
Object[] protocols = enumProtocol.getEnumConstants(); protected synchronized void initialize() {
ProtocolLogger.debug("NettyProtocolRegistry#initialize()"); // Debug for issue #202
// ID to Packet class maps
Map<Object, Map<Integer, Class<?>>> serverMaps = Maps.newLinkedHashMap(); Object[] protocols = enumProtocol.getEnumConstants();
Map<Object, Map<Integer, Class<?>>> clientMaps = Maps.newLinkedHashMap();
// ID to Packet class maps
Register result = new Register(); Map<Object, Map<Integer, Class<?>>> serverMaps = Maps.newLinkedHashMap();
StructureModifier<Object> modifier = null; Map<Object, Map<Integer, Class<?>>> clientMaps = Maps.newLinkedHashMap();
// Iterate through the protocols Register result = new Register();
for (Object protocol : protocols) { StructureModifier<Object> modifier = null;
if (modifier == null)
modifier = new StructureModifier<Object>(protocol.getClass().getSuperclass(), false); // Iterate through the protocols
StructureModifier<Map<Object, Map<Integer, Class<?>>>> maps = modifier.withTarget(protocol).withType(Map.class); for (Object protocol : protocols) {
for (Entry<Object, Map<Integer, Class<?>>> entry : maps.read(0).entrySet()) { if (modifier == null)
String direction = entry.getKey().toString(); modifier = new StructureModifier<Object>(protocol.getClass().getSuperclass(), false);
if (direction.contains("CLIENTBOUND")) { // Sent by Server StructureModifier<Map<Object, Map<Integer, Class<?>>>> maps = modifier.withTarget(protocol).withType(Map.class);
serverMaps.put(protocol, entry.getValue()); for (Entry<Object, Map<Integer, Class<?>>> entry : maps.read(0).entrySet()) {
} else if (direction.contains("SERVERBOUND")) { // Sent by Client String direction = entry.getKey().toString();
clientMaps.put(protocol, entry.getValue()); if (direction.contains("CLIENTBOUND")) { // Sent by Server
} serverMaps.put(protocol, entry.getValue());
} } else if (direction.contains("SERVERBOUND")) { // Sent by Client
} clientMaps.put(protocol, entry.getValue());
}
// Maps we have to occasionally check have changed }
for (Map<Integer, Class<?>> map : serverMaps.values()) { }
result.containers.add(new MapContainer(map));
} // Maps we have to occasionally check have changed
for (Map<Integer, Class<?>> map : serverMaps.values()) {
for (Map<Integer, Class<?>> map : clientMaps.values()) { result.containers.add(new MapContainer(map));
result.containers.add(new MapContainer(map)); }
}
for (Map<Integer, Class<?>> map : clientMaps.values()) {
for (int i = 0; i < protocols.length; i++) { result.containers.add(new MapContainer(map));
Object protocol = protocols[i]; }
Enum<?> enumProtocol = (Enum<?>) protocol;
Protocol equivalent = Protocol.fromVanilla(enumProtocol); for (int i = 0; i < protocols.length; i++) {
Object protocol = protocols[i];
// Associate known types Enum<?> enumProtocol = (Enum<?>) protocol;
if (serverMaps.containsKey(protocol)) Protocol equivalent = Protocol.fromVanilla(enumProtocol);
associatePackets(result, serverMaps.get(protocol), equivalent, Sender.SERVER);
if (clientMaps.containsKey(protocol)) // Associate known types
associatePackets(result, clientMaps.get(protocol), equivalent, Sender.CLIENT); if (serverMaps.containsKey(protocol))
} associatePackets(result, serverMaps.get(protocol), equivalent, Sender.SERVER);
if (clientMaps.containsKey(protocol))
// Exchange (thread safe, as we have only one writer) associatePackets(result, clientMaps.get(protocol), equivalent, Sender.CLIENT);
this.register = result; }
}
// Exchange (thread safe, as we have only one writer)
@Override this.register = result;
protected void associatePackets(Register register, Map<Integer, Class<?>> lookup, Protocol protocol, Sender sender) { }
for (Entry<Integer, Class<?>> entry : lookup.entrySet()) {
PacketType type = PacketType.fromCurrent(protocol, sender, entry.getKey(), entry.getValue()); @Override
protected void associatePackets(Register register, Map<Integer, Class<?>> lookup, Protocol protocol, Sender sender) {
try { for (Entry<Integer, Class<?>> entry : lookup.entrySet()) {
register.typeToClass.put(type, entry.getValue()); PacketType type = PacketType.fromCurrent(protocol, sender, entry.getKey(), entry.getValue());
if (sender == Sender.SERVER) try {
register.serverPackets.add(type); register.typeToClass.put(type, entry.getValue());
if (sender == Sender.CLIENT)
register.clientPackets.add(type); if (sender == Sender.SERVER)
} catch (IllegalArgumentException ex) { register.serverPackets.add(type);
// Sometimes this happens with fake packets, just ignore it if (sender == Sender.CLIENT)
} register.clientPackets.add(type);
} } catch (IllegalArgumentException ex) {
} // Sometimes this happens with fake packets, just ignore it
} }
}
}
}

View File

@ -1,322 +1,321 @@
/* /*
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol. * ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
* Copyright (C) 2012 Kristian S. Stangeland * Copyright (C) 2012 Kristian S. Stangeland
* *
* This program is free software; you can redistribute it and/or modify it under the terms of the * This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 2 of * GNU General Public License as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. * See the GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License along with this program; * You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA * 02111-1307 USA
*/ */
package com.comphenix.protocol.injector.packet; package com.comphenix.protocol.injector.packet;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.PacketType.Sender; import com.comphenix.protocol.PacketType.Sender;
import com.comphenix.protocol.error.ReportType; import com.comphenix.protocol.error.ReportType;
import com.comphenix.protocol.injector.netty.NettyProtocolRegistry; import com.comphenix.protocol.injector.netty.NettyProtocolRegistry;
import com.comphenix.protocol.injector.netty.ProtocolRegistry; import com.comphenix.protocol.injector.netty.ProtocolRegistry;
import com.comphenix.protocol.reflect.FieldAccessException; import com.comphenix.protocol.reflect.FieldAccessException;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
/** /**
* Static packet registry in Minecraft. * Static packet registry in Minecraft.
* @author Kristian * @author Kristian
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public class PacketRegistry { public class PacketRegistry {
public static final ReportType REPORT_CANNOT_CORRECT_TROVE_MAP = new ReportType("Unable to correct no entry value."); public static final ReportType REPORT_CANNOT_CORRECT_TROVE_MAP = new ReportType("Unable to correct no entry value.");
public static final ReportType REPORT_INSUFFICIENT_SERVER_PACKETS = new ReportType("Too few server packets detected: %s"); public static final ReportType REPORT_INSUFFICIENT_SERVER_PACKETS = new ReportType("Too few server packets detected: %s");
public static final ReportType REPORT_INSUFFICIENT_CLIENT_PACKETS = new ReportType("Too few client packets detected: %s"); public static final ReportType REPORT_INSUFFICIENT_CLIENT_PACKETS = new ReportType("Too few client packets detected: %s");
// Two different packet registry // Two different packet registry
private static volatile ProtocolRegistry NETTY; private static volatile ProtocolRegistry NETTY;
// Cached for Netty // Cached for Netty
private static volatile Set<Integer> LEGACY_SERVER_PACKETS; private static volatile Set<Integer> LEGACY_SERVER_PACKETS;
private static volatile Set<Integer> LEGACY_CLIENT_PACKETS; private static volatile Set<Integer> LEGACY_CLIENT_PACKETS;
private static volatile Map<Integer, Class> LEGACY_PREVIOUS_PACKETS; private static volatile Map<Integer, Class> LEGACY_PREVIOUS_PACKETS;
// Whether or not the registry has // Whether or not the registry has
private static boolean INITIALIZED; private static boolean INITIALIZED;
/** /**
* Initialize the packet registry. * Initializes the packet registry.
*/ */
private static void initialize() { private static void initialize() {
if (INITIALIZED) { if (INITIALIZED) {
// Make sure they were initialized if (NETTY == null) {
if (NETTY == null) throw new IllegalStateException("Failed to initialize packet registry.");
throw new IllegalStateException("No initialized registry."); }
return; }
}
INITIALIZED = true;
// Check for netty NETTY = new NettyProtocolRegistry();
NETTY = new NettyProtocolRegistry(); }
}
/**
/** * Determine if the given packet type is supported on the current server.
* Determine if the given packet type is supported on the current server. * @param type - the type to check.
* @param type - the type to check. * @return TRUE if it is, FALSE otherwise.
* @return TRUE if it is, FALSE otherwise. */
*/ public static boolean isSupported(PacketType type) {
public static boolean isSupported(PacketType type) { initialize();
initialize(); return NETTY.getPacketTypeLookup().containsKey(type);
return NETTY.getPacketTypeLookup().containsKey(type); }
}
/**
/** * Retrieve a map of every packet class to every ID.
* Retrieve a map of every packet class to every ID. * <p>
* <p> * Deprecated: Use {@link #getPacketToType()} instead.
* Deprecated: Use {@link #getPacketToType()} instead. * @return A map of packet classes and their corresponding ID.
* @return A map of packet classes and their corresponding ID. */
*/ @Deprecated
@Deprecated public static Map<Class, Integer> getPacketToID() {
public static Map<Class, Integer> getPacketToID() { initialize();
initialize();
@SuppressWarnings("unchecked")
@SuppressWarnings("unchecked") Map<Class, Integer> result = (Map) Maps.transformValues(
Map<Class, Integer> result = (Map) Maps.transformValues( NETTY.getPacketClassLookup(),
NETTY.getPacketClassLookup(), new Function<PacketType, Integer>() {
new Function<PacketType, Integer>() { @Override
@Override public Integer apply(PacketType type) {
public Integer apply(PacketType type) { return type.getLegacyId();
return type.getLegacyId(); };
}; });
}); return result;
return result; }
}
/**
/** * Retrieve a map of every packet class to the respective packet type.
* Retrieve a map of every packet class to the respective packet type. * @return A map of packet classes and their corresponding packet type.
* @return A map of packet classes and their corresponding packet type. */
*/ public static Map<Class, PacketType> getPacketToType() {
public static Map<Class, PacketType> getPacketToType() { initialize();
initialize();
@SuppressWarnings("unchecked")
@SuppressWarnings("unchecked") Map<Class, PacketType> result = (Map) NETTY.getPacketClassLookup();
Map<Class, PacketType> result = (Map) NETTY.getPacketClassLookup(); return result;
return result; }
}
/**
/** * Retrieve the injected proxy classes handlig each packet ID.
* Retrieve the injected proxy classes handlig each packet ID. * <p>
* <p> * This is not supported in 1.7.2 and later.
* This is not supported in 1.7.2 and later. * @return Injected classes.
* @return Injected classes. */
*/ @Deprecated
@Deprecated public static Map<Integer, Class> getOverwrittenPackets() {
public static Map<Integer, Class> getOverwrittenPackets() { initialize();
initialize(); throw new IllegalStateException("Not supported on Netty.");
throw new IllegalStateException("Not supported on Netty."); }
}
/**
/** * Retrieve the vanilla classes handling each packet ID.
* Retrieve the vanilla classes handling each packet ID. * @return Vanilla classes.
* @return Vanilla classes. */
*/ @Deprecated
@Deprecated public static Map<Integer, Class> getPreviousPackets() {
public static Map<Integer, Class> getPreviousPackets() { initialize();
initialize();
// Construct it first
// Construct it first if (LEGACY_PREVIOUS_PACKETS == null) {
if (LEGACY_PREVIOUS_PACKETS == null) { Map<Integer, Class> map = Maps.newHashMap();
Map<Integer, Class> map = Maps.newHashMap();
for (Entry<PacketType, Class<?>> entry : NETTY.getPacketTypeLookup().entrySet()) {
for (Entry<PacketType, Class<?>> entry : NETTY.getPacketTypeLookup().entrySet()) { map.put(entry.getKey().getLegacyId(), entry.getValue());
map.put(entry.getKey().getLegacyId(), entry.getValue()); }
} LEGACY_PREVIOUS_PACKETS = Collections.unmodifiableMap(map);
LEGACY_PREVIOUS_PACKETS = Collections.unmodifiableMap(map); }
} return LEGACY_PREVIOUS_PACKETS;
return LEGACY_PREVIOUS_PACKETS; }
}
/**
/** * Retrieve every known and supported server packet.
* Retrieve every known and supported server packet. * <p>
* <p> * Deprecated: Use {@link #getServerPacketTypes()} instead.
* Deprecated: Use {@link #getServerPacketTypes()} instead. * @return An immutable set of every known server packet.
* @return An immutable set of every known server packet. * @throws FieldAccessException If we're unable to retrieve the server packet data from Minecraft.
* @throws FieldAccessException If we're unable to retrieve the server packet data from Minecraft. */
*/ @Deprecated
@Deprecated public static Set<Integer> getServerPackets() throws FieldAccessException {
public static Set<Integer> getServerPackets() throws FieldAccessException { initialize();
initialize();
if (LEGACY_SERVER_PACKETS == null) {
if (LEGACY_SERVER_PACKETS == null) { LEGACY_SERVER_PACKETS = toLegacy(NETTY.getServerPackets());
LEGACY_SERVER_PACKETS = toLegacy(NETTY.getServerPackets()); }
} return LEGACY_SERVER_PACKETS;
return LEGACY_SERVER_PACKETS; }
}
/**
/** * Retrieve every known and supported server packet type.
* Retrieve every known and supported server packet type. * @return Every server packet type.
* @return Every server packet type. */
*/ public static Set<PacketType> getServerPacketTypes() {
public static Set<PacketType> getServerPacketTypes() { initialize();
initialize();
NETTY.synchronize();
NETTY.synchronize(); return NETTY.getServerPackets();
return NETTY.getServerPackets(); }
}
/**
/** * Retrieve every known and supported client packet.
* Retrieve every known and supported client packet. * <p>
* <p> * Deprecated: Use {@link #getClientPacketTypes()} instead.
* Deprecated: Use {@link #getClientPacketTypes()} instead. * @return An immutable set of every known client packet.
* @return An immutable set of every known client packet. * @throws FieldAccessException If we're unable to retrieve the client packet data from Minecraft.
* @throws FieldAccessException If we're unable to retrieve the client packet data from Minecraft. */
*/ @Deprecated
@Deprecated public static Set<Integer> getClientPackets() throws FieldAccessException {
public static Set<Integer> getClientPackets() throws FieldAccessException { initialize();
initialize();
if (LEGACY_CLIENT_PACKETS == null) {
if (LEGACY_CLIENT_PACKETS == null) { LEGACY_CLIENT_PACKETS = toLegacy(NETTY.getClientPackets());
LEGACY_CLIENT_PACKETS = toLegacy(NETTY.getClientPackets()); }
} return LEGACY_CLIENT_PACKETS;
return LEGACY_CLIENT_PACKETS; }
}
/**
/** * Retrieve every known and supported server packet type.
* Retrieve every known and supported server packet type. * @return Every server packet type.
* @return Every server packet type. */
*/ public static Set<PacketType> getClientPacketTypes() {
public static Set<PacketType> getClientPacketTypes() { initialize();
initialize();
NETTY.synchronize();
NETTY.synchronize(); return NETTY.getClientPackets();
return NETTY.getClientPackets(); }
}
/**
/** * Convert a set of packet types to a set of integers based on the legacy packet ID.
* Convert a set of packet types to a set of integers based on the legacy packet ID. * @param types - packet type.
* @param types - packet type. * @return Set of integers.
* @return Set of integers. */
*/ public static Set<Integer> toLegacy(Set<PacketType> types) {
public static Set<Integer> toLegacy(Set<PacketType> types) { Set<Integer> result = Sets.newHashSet();
Set<Integer> result = Sets.newHashSet();
for (PacketType type : types)
for (PacketType type : types) result.add(type.getLegacyId());
result.add(type.getLegacyId()); return Collections.unmodifiableSet(result);
return Collections.unmodifiableSet(result); }
}
/**
/** * Convert a set of legacy packet IDs to packet types.
* Convert a set of legacy packet IDs to packet types. * @param ids - legacy packet IDs.
* @param ids - legacy packet IDs. * @return Set of packet types.
* @return Set of packet types. */
*/ public static Set<PacketType> toPacketTypes(Set<Integer> ids) {
public static Set<PacketType> toPacketTypes(Set<Integer> ids) { return toPacketTypes(ids, null);
return toPacketTypes(ids, null); }
}
/**
/** * Convert a set of legacy packet IDs to packet types.
* Convert a set of legacy packet IDs to packet types. * @param ids - legacy packet IDs.
* @param ids - legacy packet IDs. * @param preference - the sender preference, if any.
* @param preference - the sender preference, if any. * @return Set of packet types.
* @return Set of packet types. */
*/ public static Set<PacketType> toPacketTypes(Set<Integer> ids, Sender preference) {
public static Set<PacketType> toPacketTypes(Set<Integer> ids, Sender preference) { Set<PacketType> result = Sets.newHashSet();
Set<PacketType> result = Sets.newHashSet();
for (int id : ids)
for (int id : ids) result.add(PacketType.fromLegacy(id, preference));
result.add(PacketType.fromLegacy(id, preference)); return Collections.unmodifiableSet(result);
return Collections.unmodifiableSet(result); }
}
/**
/** * Retrieves the correct packet class from a given packet ID.
* Retrieves the correct packet class from a given packet ID. * <p>
* <p> * Deprecated: Use {@link #getPacketClassFromType(PacketType)} instead.
* Deprecated: Use {@link #getPacketClassFromType(PacketType)} instead. * @param packetID - the packet ID.
* @param packetID - the packet ID. * @return The associated class.
* @return The associated class. */
*/ @Deprecated
@Deprecated public static Class getPacketClassFromID(int packetID) {
public static Class getPacketClassFromID(int packetID) { initialize();
initialize(); return NETTY.getPacketTypeLookup().get(PacketType.findLegacy(packetID));
return NETTY.getPacketTypeLookup().get(PacketType.findLegacy(packetID)); }
}
/**
/** * Retrieves the correct packet class from a given type.
* Retrieves the correct packet class from a given type. * @param type - the packet type.
* @param type - the packet type. * @return The associated class.
* @return The associated class. */
*/ public static Class getPacketClassFromType(PacketType type) {
public static Class getPacketClassFromType(PacketType type) { return getPacketClassFromType(type, false);
return getPacketClassFromType(type, false); }
}
/**
/** * Retrieves the correct packet class from a given type.
* Retrieves the correct packet class from a given type. * <p>
* <p> * Note that forceVanillla will be ignored on MC 1.7.2 and later.
* Note that forceVanillla will be ignored on MC 1.7.2 and later. * @param type - the packet type.
* @param type - the packet type. * @param forceVanilla - whether or not to look for vanilla classes, not injected classes.
* @param forceVanilla - whether or not to look for vanilla classes, not injected classes. * @return The associated class.
* @return The associated class. */
*/ public static Class getPacketClassFromType(PacketType type, boolean forceVanilla) {
public static Class getPacketClassFromType(PacketType type, boolean forceVanilla) { initialize();
initialize(); return NETTY.getPacketTypeLookup().get(type);
return NETTY.getPacketTypeLookup().get(type); }
}
/**
/** * Retrieves the correct packet class from a given packet ID.
* Retrieves the correct packet class from a given packet ID. * <p>
* <p> * This method has been deprecated.
* This method has been deprecated. * @param packetID - the packet ID.
* @param packetID - the packet ID. * @param forceVanilla - whether or not to look for vanilla classes, not injected classes.
* @param forceVanilla - whether or not to look for vanilla classes, not injected classes. * @return The associated class.
* @return The associated class. */
*/ @Deprecated
@Deprecated public static Class getPacketClassFromID(int packetID, boolean forceVanilla) {
public static Class getPacketClassFromID(int packetID, boolean forceVanilla) { initialize();
initialize(); return getPacketClassFromID(packetID);
return getPacketClassFromID(packetID); }
}
/**
/** * Retrieve the packet ID of a given packet.
* Retrieve the packet ID of a given packet. * <p>
* <p> * Deprecated: Use {@link #getPacketType(Class)}.
* Deprecated: Use {@link #getPacketType(Class)}. * @param packet - the type of packet to check.
* @param packet - the type of packet to check. * @return The legacy ID of the given packet.
* @return The legacy ID of the given packet. * @throws IllegalArgumentException If this is not a valid packet.
* @throws IllegalArgumentException If this is not a valid packet. */
*/ @Deprecated
@Deprecated public static int getPacketID(Class<?> packet) {
public static int getPacketID(Class<?> packet) { initialize();
initialize(); return NETTY.getPacketClassLookup().get(packet).getLegacyId();
return NETTY.getPacketClassLookup().get(packet).getLegacyId(); }
}
/**
/** * Retrieve the packet type of a given packet.
* Retrieve the packet type of a given packet. * @param packet - the class of the packet.
* @param packet - the class of the packet. * @return The packet type, or NULL if not found.
* @return The packet type, or NULL if not found. */
*/ public static PacketType getPacketType(Class<?> packet) {
public static PacketType getPacketType(Class<?> packet) { return getPacketType(packet, null);
return getPacketType(packet, null); }
}
/**
/** * Retrieve the packet type of a given packet.
* Retrieve the packet type of a given packet. * @param packet - the class of the packet.
* @param packet - the class of the packet. * @param sender - the sender of the packet, or NULL.
* @param sender - the sender of the packet, or NULL. * @return The packet type, or NULL if not found.
* @return The packet type, or NULL if not found. */
*/ public static PacketType getPacketType(Class<?> packet, Sender sender) {
public static PacketType getPacketType(Class<?> packet, Sender sender) { initialize();
initialize(); return NETTY.getPacketClassLookup().get(packet);
return NETTY.getPacketClassLookup().get(packet); }
}
} }