Don't depend on packet IDs anymore for 1.9

Packet IDs will supposedly be shuffled in 1.9, so they are no longer
reliable for our packet associations. This shouldn't affect plugins,
unless you're using IDs, in which case you should stop doing that.

Addresses #128
This commit is contained in:
Dan Mulloy 2015-11-13 20:05:53 -05:00
parent 7dff86cb48
commit 880cf29fc7
3 changed files with 345 additions and 340 deletions

View File

@ -8,6 +8,7 @@ import java.util.UUID;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import org.apache.commons.lang.WordUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import com.comphenix.protocol.events.ConnectionSide; import com.comphenix.protocol.events.ConnectionSide;
@ -25,8 +26,7 @@ import com.google.common.util.concurrent.Futures;
/** /**
* Represents the type of a packet in a specific protocol. * Represents the type of a packet in a specific protocol.
* <p> * <p>
* Note that vanilla Minecraft reuses packet IDs per protocol (ping, game, login), so you cannot * Note that vanilla Minecraft reuses packet IDs per protocol (ping, game, login) and IDs are subject to change, so they are not reliable.
* rely on IDs alone.
* @author Kristian * @author Kristian
*/ */
public class PacketType implements Serializable, Comparable<PacketType> { public class PacketType implements Serializable, Comparable<PacketType> {
@ -54,7 +54,7 @@ public class PacketType implements Serializable, Comparable<PacketType> {
/** /**
* Legacy name: HANDSHAKE. * Legacy name: HANDSHAKE.
*/ */
public static final PacketType SET_PROTOCOL = new PacketType(PROTOCOL, SENDER, 0x00, 2); public static final PacketType SET_PROTOCOL = new PacketType(PROTOCOL, SENDER, 0x00, 2, "SetProtocol");
private final static Client INSTANCE = new Client(); private final static Client INSTANCE = new Client();
@ -105,89 +105,92 @@ public class PacketType implements Serializable, Comparable<PacketType> {
public static class Server extends ObjectEnum<PacketType> { public static class Server extends ObjectEnum<PacketType> {
private final static Sender SENDER = Sender.SERVER; private final static Sender SENDER = Sender.SERVER;
public static final PacketType KEEP_ALIVE = new PacketType(PROTOCOL, SENDER, 0x00, 0); public static final PacketType KEEP_ALIVE = new PacketType(PROTOCOL, SENDER, 0x00, 0, "KeepAlive");
public static final PacketType LOGIN = new PacketType(PROTOCOL, SENDER, 0x01, 1); public static final PacketType LOGIN = new PacketType(PROTOCOL, SENDER, 0x01, 1, "Login");
public static final PacketType CHAT = new PacketType(PROTOCOL, SENDER, 0x02, 3); public static final PacketType CHAT = new PacketType(PROTOCOL, SENDER, 0x02, 3, "Chat");
public static final PacketType UPDATE_TIME = new PacketType(PROTOCOL, SENDER, 0x03, 4); public static final PacketType UPDATE_TIME = new PacketType(PROTOCOL, SENDER, 0x03, 4, "UpdateTime");
public static final PacketType ENTITY_EQUIPMENT = new PacketType(PROTOCOL, SENDER, 0x04, 5); public static final PacketType ENTITY_EQUIPMENT = new PacketType(PROTOCOL, SENDER, 0x04, 5, "EntityEquipment");
public static final PacketType SPAWN_POSITION = new PacketType(PROTOCOL, SENDER, 0x05, 6); public static final PacketType SPAWN_POSITION = new PacketType(PROTOCOL, SENDER, 0x05, 6, "SpawnPosition");
public static final PacketType UPDATE_HEALTH = new PacketType(PROTOCOL, SENDER, 0x06, 8); public static final PacketType UPDATE_HEALTH = new PacketType(PROTOCOL, SENDER, 0x06, 8, "UpdateHealth");
public static final PacketType RESPAWN = new PacketType(PROTOCOL, SENDER, 0x07, 9); public static final PacketType RESPAWN = new PacketType(PROTOCOL, SENDER, 0x07, 9, "Respawn");
public static final PacketType POSITION = new PacketType(PROTOCOL, SENDER, 0x08, 13); public static final PacketType POSITION = new PacketType(PROTOCOL, SENDER, 0x08, 13, "Position");
public static final PacketType HELD_ITEM_SLOT = new PacketType(PROTOCOL, SENDER, 0x09, 16); public static final PacketType HELD_ITEM_SLOT = new PacketType(PROTOCOL, SENDER, 0x09, 16, "HeldItemSlot");
/** /**
* Note that this was Packets.Server.ENTITY_LOCATION_ACTION. * Note that this was Packets.Server.ENTITY_LOCATION_ACTION.
*/ */
public static final PacketType BED = new PacketType(PROTOCOL, SENDER, 0x0A, 17); public static final PacketType BED = new PacketType(PROTOCOL, SENDER, 0x0A, 17, "Bed");
public static final PacketType ANIMATION = new PacketType(PROTOCOL, SENDER, 0x0B, 18); public static final PacketType ANIMATION = new PacketType(PROTOCOL, SENDER, 0x0B, 18, "Animation");
public static final PacketType NAMED_ENTITY_SPAWN = new PacketType(PROTOCOL, SENDER, 0x0C, 20); public static final PacketType NAMED_ENTITY_SPAWN = new PacketType(PROTOCOL, SENDER, 0x0C, 20, "NamedEntitySpawn");
public static final PacketType COLLECT = new PacketType(PROTOCOL, SENDER, 0x0D, 22); public static final PacketType COLLECT = new PacketType(PROTOCOL, SENDER, 0x0D, 22, "Collect");
public static final PacketType SPAWN_ENTITY = new PacketType(PROTOCOL, SENDER, 0x0E, 23); public static final PacketType SPAWN_ENTITY = new PacketType(PROTOCOL, SENDER, 0x0E, 23, "SpawnEntity");
public static final PacketType SPAWN_ENTITY_LIVING = new PacketType(PROTOCOL, SENDER, 0x0F, 24); public static final PacketType SPAWN_ENTITY_LIVING = new PacketType(PROTOCOL, SENDER, 0x0F, 24, "SpawnEntityLiving");
public static final PacketType SPAWN_ENTITY_PAINTING = new PacketType(PROTOCOL, SENDER, 0x10, 25); public static final PacketType SPAWN_ENTITY_PAINTING = new PacketType(PROTOCOL, SENDER, 0x10, 25, "SpawnEntityPainting");
public static final PacketType SPAWN_ENTITY_EXPERIENCE_ORB = public static final PacketType SPAWN_ENTITY_EXPERIENCE_ORB =
new PacketType(PROTOCOL, SENDER, 0x11, 26); new PacketType(PROTOCOL, SENDER, 0x11, 26, "SpawnEntityExperienceOrb");
public static final PacketType ENTITY_VELOCITY = new PacketType(PROTOCOL, SENDER, 0x12, 28); public static final PacketType ENTITY_VELOCITY = new PacketType(PROTOCOL, SENDER, 0x12, 28, "EntityVelocity");
public static final PacketType ENTITY_DESTROY = new PacketType(PROTOCOL, SENDER, 0x13, 29); public static final PacketType ENTITY_DESTROY = new PacketType(PROTOCOL, SENDER, 0x13, 29, "EntityDestroy");
public static final PacketType ENTITY = new PacketType(PROTOCOL, SENDER, 0x14, 30); public static final PacketType ENTITY = new PacketType(PROTOCOL, SENDER, 0x14, 30, "Entity");
public static final PacketType REL_ENTITY_MOVE = new PacketType(PROTOCOL, SENDER, 0x15, 31); public static final PacketType REL_ENTITY_MOVE = new PacketType(PROTOCOL, SENDER, 0x15, 31, "RelEntityMove");
public static final PacketType ENTITY_LOOK = new PacketType(PROTOCOL, SENDER, 0x16, 32); public static final PacketType ENTITY_LOOK = new PacketType(PROTOCOL, SENDER, 0x16, 32, "EntityLook");
public static final PacketType ENTITY_MOVE_LOOK = new PacketType(PROTOCOL, SENDER, 0x17, 33); public static final PacketType ENTITY_MOVE_LOOK = new PacketType(PROTOCOL, SENDER, 0x17, 33, "RelEntityMoveLook");
public static final PacketType ENTITY_TELEPORT = new PacketType(PROTOCOL, SENDER, 0x18, 34); public static final PacketType ENTITY_TELEPORT = new PacketType(PROTOCOL, SENDER, 0x18, 34, "EntityTeleport");
public static final PacketType ENTITY_HEAD_ROTATION = new PacketType(PROTOCOL, SENDER, 0x19, 35); public static final PacketType ENTITY_HEAD_ROTATION = new PacketType(PROTOCOL, SENDER, 0x19, 35, "EntityHeadRotation");
public static final PacketType ENTITY_STATUS = new PacketType(PROTOCOL, SENDER, 0x1A, 38); public static final PacketType ENTITY_STATUS = new PacketType(PROTOCOL, SENDER, 0x1A, 38, "EntityStatus");
public static final PacketType ATTACH_ENTITY = new PacketType(PROTOCOL, SENDER, 0x1B, 39); public static final PacketType ATTACH_ENTITY = new PacketType(PROTOCOL, SENDER, 0x1B, 39, "AttachEntity");
public static final PacketType ENTITY_METADATA = new PacketType(PROTOCOL, SENDER, 0x1C, 40); public static final PacketType ENTITY_METADATA = new PacketType(PROTOCOL, SENDER, 0x1C, 40, "EntityMetadata");
public static final PacketType ENTITY_EFFECT = new PacketType(PROTOCOL, SENDER, 0x1D, 41); public static final PacketType ENTITY_EFFECT = new PacketType(PROTOCOL, SENDER, 0x1D, 41, "EntityEffect");
public static final PacketType REMOVE_ENTITY_EFFECT = new PacketType(PROTOCOL, SENDER, 0x1E, 42); public static final PacketType REMOVE_ENTITY_EFFECT = new PacketType(PROTOCOL, SENDER, 0x1E, 42, "RemoveEntityEffect");
public static final PacketType EXPERIENCE = new PacketType(PROTOCOL, SENDER, 0x1F, 43); public static final PacketType EXPERIENCE = new PacketType(PROTOCOL, SENDER, 0x1F, 43, "Experience");
public static final PacketType UPDATE_ATTRIBUTES = new PacketType(PROTOCOL, SENDER, 0x20, 44); public static final PacketType UPDATE_ATTRIBUTES = new PacketType(PROTOCOL, SENDER, 0x20, 44, "UpdateAttributes");
public static final PacketType MAP_CHUNK = new PacketType(PROTOCOL, SENDER, 0x21, 51); public static final PacketType MAP_CHUNK = new PacketType(PROTOCOL, SENDER, 0x21, 51, "MapChunk");
public static final PacketType MULTI_BLOCK_CHANGE = new PacketType(PROTOCOL, SENDER, 0x22, 52); public static final PacketType MULTI_BLOCK_CHANGE = new PacketType(PROTOCOL, SENDER, 0x22, 52, "MultiBlockChange");
public static final PacketType BLOCK_CHANGE = new PacketType(PROTOCOL, SENDER, 0x23, 53); public static final PacketType BLOCK_CHANGE = new PacketType(PROTOCOL, SENDER, 0x23, 53, "BlockChange");
public static final PacketType BLOCK_ACTION = new PacketType(PROTOCOL, SENDER, 0x24, 54); public static final PacketType BLOCK_ACTION = new PacketType(PROTOCOL, SENDER, 0x24, 54, "BlockAction");
public static final PacketType BLOCK_BREAK_ANIMATION = new PacketType(PROTOCOL, SENDER, 0x25, 55); public static final PacketType BLOCK_BREAK_ANIMATION = new PacketType(PROTOCOL, SENDER, 0x25, 55, "BlockBreakAnimation");
public static final PacketType MAP_CHUNK_BULK = new PacketType(PROTOCOL, SENDER, 0x26, 56); public static final PacketType MAP_CHUNK_BULK = new PacketType(PROTOCOL, SENDER, 0x26, 56, "MapChunkBulk");
public static final PacketType EXPLOSION = new PacketType(PROTOCOL, SENDER, 0x27, 60); public static final PacketType EXPLOSION = new PacketType(PROTOCOL, SENDER, 0x27, 60, "Explosion");
public static final PacketType WORLD_EVENT = new PacketType(PROTOCOL, SENDER, 0x28, 61); public static final PacketType WORLD_EVENT = new PacketType(PROTOCOL, SENDER, 0x28, 61, "WorldEvent");
public static final PacketType NAMED_SOUND_EFFECT = new PacketType(PROTOCOL, SENDER, 0x29, 62); public static final PacketType NAMED_SOUND_EFFECT = new PacketType(PROTOCOL, SENDER, 0x29, 62, "NamedSoundEffect");
public static final PacketType WORLD_PARTICLES = new PacketType(PROTOCOL, SENDER, 0x2A, 63); public static final PacketType WORLD_PARTICLES = new PacketType(PROTOCOL, SENDER, 0x2A, 63, "WorldParticles");
/** /**
* Note that this was Packets.Server.BED. * Note that this was Packets.Server.BED.
*/ */
public static final PacketType GAME_STATE_CHANGE = new PacketType(PROTOCOL, SENDER, 0x2B, 70); public static final PacketType GAME_STATE_CHANGE = new PacketType(PROTOCOL, SENDER, 0x2B, 70, "GameStateChange");
public static final PacketType SPAWN_ENTITY_WEATHER = new PacketType(PROTOCOL, SENDER, 0x2C, 71); public static final PacketType SPAWN_ENTITY_WEATHER = new PacketType(PROTOCOL, SENDER, 0x2C, 71, "SpawnEntityWeather");
public static final PacketType OPEN_WINDOW = new PacketType(PROTOCOL, SENDER, 0x2D, 100); public static final PacketType OPEN_WINDOW = new PacketType(PROTOCOL, SENDER, 0x2D, 100, "OpenWindow");
public static final PacketType CLOSE_WINDOW = new PacketType(PROTOCOL, SENDER, 0x2E, 101); public static final PacketType CLOSE_WINDOW = new PacketType(PROTOCOL, SENDER, 0x2E, 101, "CloseWindow");
public static final PacketType SET_SLOT = new PacketType(PROTOCOL, SENDER, 0x2F, 103); public static final PacketType SET_SLOT = new PacketType(PROTOCOL, SENDER, 0x2F, 103, "SetSlot");
public static final PacketType WINDOW_ITEMS = new PacketType(PROTOCOL, SENDER, 0x30, 104); public static final PacketType WINDOW_ITEMS = new PacketType(PROTOCOL, SENDER, 0x30, 104, "WindowItems");
public static final PacketType CRAFT_PROGRESS_BAR = new PacketType(PROTOCOL, SENDER, 0x31, 105); /**
public static final PacketType TRANSACTION = new PacketType(PROTOCOL, SENDER, 0x32, 106); * Should be WINDOW_DATA.
public static final PacketType UPDATE_SIGN = new PacketType(PROTOCOL, SENDER, 0x33, 130); */
public static final PacketType MAP = new PacketType(PROTOCOL, SENDER, 0x34, 131); public static final PacketType CRAFT_PROGRESS_BAR = new PacketType(PROTOCOL, SENDER, 0x31, 105, "WindowData");
public static final PacketType TILE_ENTITY_DATA = new PacketType(PROTOCOL, SENDER, 0x35, 132); public static final PacketType TRANSACTION = new PacketType(PROTOCOL, SENDER, 0x32, 106, "Transaction");
public static final PacketType OPEN_SIGN_ENTITY = new PacketType(PROTOCOL, SENDER, 0x36, 133); public static final PacketType UPDATE_SIGN = new PacketType(PROTOCOL, SENDER, 0x33, 130, "UpdateSign");
public static final PacketType STATISTICS = new PacketType(PROTOCOL, SENDER, 0x37, 200); public static final PacketType MAP = new PacketType(PROTOCOL, SENDER, 0x34, 131, "Map");
public static final PacketType PLAYER_INFO = new PacketType(PROTOCOL, SENDER, 0x38, 201); public static final PacketType TILE_ENTITY_DATA = new PacketType(PROTOCOL, SENDER, 0x35, 132, "TileEntityData");
public static final PacketType ABILITIES = new PacketType(PROTOCOL, SENDER, 0x39, 202); public static final PacketType OPEN_SIGN_ENTITY = new PacketType(PROTOCOL, SENDER, 0x36, 133, "OpenSignEditor");
public static final PacketType TAB_COMPLETE = new PacketType(PROTOCOL, SENDER, 0x3A, 203); public static final PacketType STATISTICS = new PacketType(PROTOCOL, SENDER, 0x37, 200, "Statistic");
public static final PacketType SCOREBOARD_OBJECTIVE = new PacketType(PROTOCOL, SENDER, 0x3B, 206); public static final PacketType PLAYER_INFO = new PacketType(PROTOCOL, SENDER, 0x38, 201, "PlayerInfo");
public static final PacketType SCOREBOARD_SCORE = new PacketType(PROTOCOL, SENDER, 0x3C, 207); public static final PacketType ABILITIES = new PacketType(PROTOCOL, SENDER, 0x39, 202, "Abilities");
public static final PacketType TAB_COMPLETE = new PacketType(PROTOCOL, SENDER, 0x3A, 203, "TabComplete");
public static final PacketType SCOREBOARD_OBJECTIVE = new PacketType(PROTOCOL, SENDER, 0x3B, 206, "ScoreboardObjective");
public static final PacketType SCOREBOARD_SCORE = new PacketType(PROTOCOL, SENDER, 0x3C, 207, "ScoreboardScore");
public static final PacketType SCOREBOARD_DISPLAY_OBJECTIVE = public static final PacketType SCOREBOARD_DISPLAY_OBJECTIVE =
new PacketType(PROTOCOL, SENDER, 0x3D, 208); new PacketType(PROTOCOL, SENDER, 0x3D, 208, "ScoreboardDisplayObjective");
public static final PacketType SCOREBOARD_TEAM = new PacketType(PROTOCOL, SENDER, 0x3E, 209); public static final PacketType SCOREBOARD_TEAM = new PacketType(PROTOCOL, SENDER, 0x3E, 209, "ScoreboardTeam");
public static final PacketType CUSTOM_PAYLOAD = new PacketType(PROTOCOL, SENDER, 0x3F, 250); public static final PacketType CUSTOM_PAYLOAD = new PacketType(PROTOCOL, SENDER, 0x3F, 250, "CustomPayload");
public static final PacketType KICK_DISCONNECT = new PacketType(PROTOCOL, SENDER, 0x40, 255); public static final PacketType KICK_DISCONNECT = new PacketType(PROTOCOL, SENDER, 0x40, 255, "KickDisconnect");
public static final PacketType SERVER_DIFFICULTY = new PacketType(PROTOCOL, SENDER, 0x41, -1); public static final PacketType SERVER_DIFFICULTY = new PacketType(PROTOCOL, SENDER, 0x41, -1, "ServerDifficulty");
public static final PacketType COMBAT_EVENT = new PacketType(PROTOCOL, SENDER, 0x42, -1); public static final PacketType COMBAT_EVENT = new PacketType(PROTOCOL, SENDER, 0x42, -1, "CombatEvent");
public static final PacketType CAMERA = new PacketType(PROTOCOL, SENDER, 0x43, -1); public static final PacketType CAMERA = new PacketType(PROTOCOL, SENDER, 0x43, -1, "Camera");
public static final PacketType WORLD_BORDER = new PacketType(PROTOCOL, SENDER, 0x44, -1); public static final PacketType WORLD_BORDER = new PacketType(PROTOCOL, SENDER, 0x44, -1, "WorldBorder");
public static final PacketType TITLE = new PacketType(PROTOCOL, SENDER, 0x45, -1); public static final PacketType TITLE = new PacketType(PROTOCOL, SENDER, 0x45, -1, "Title");
public static final PacketType SET_COMPRESSION = new PacketType(PROTOCOL, SENDER, 0x46, -1); public static final PacketType SET_COMPRESSION = new PacketType(PROTOCOL, SENDER, 0x46, -1, "SetCompression");
public static final PacketType PLAYER_LIST_HEADER_FOOTER = public static final PacketType PLAYER_LIST_HEADER_FOOTER =
new PacketType(PROTOCOL, SENDER, 0x47, -1); new PacketType(PROTOCOL, SENDER, 0x47, -1, "PlayerListHeaderFooter");
public static final PacketType RESOURCE_PACK_SEND = new PacketType(PROTOCOL, SENDER, 0x48, -1); public static final PacketType RESOURCE_PACK_SEND = new PacketType(PROTOCOL, SENDER, 0x48, -1, "ResourcePackSend");
public static final PacketType UPDATE_ENTITY_NBT = new PacketType(PROTOCOL, SENDER, 0x49, -1); public static final PacketType UPDATE_ENTITY_NBT = new PacketType(PROTOCOL, SENDER, 0x49, -1, "UpdateEntityNBT");
// The instance must // The instance must
private final static Server INSTANCE = new Server(); private final static Server INSTANCE = new Server();
@ -210,32 +213,32 @@ public class PacketType implements Serializable, Comparable<PacketType> {
public static class Client extends ObjectEnum<PacketType> { public static class Client extends ObjectEnum<PacketType> {
private final static Sender SENDER = Sender.CLIENT; private final static Sender SENDER = Sender.CLIENT;
public static final PacketType KEEP_ALIVE = new PacketType(PROTOCOL, SENDER, 0x00, 0); public static final PacketType KEEP_ALIVE = new PacketType(PROTOCOL, SENDER, 0x00, 0, "KeepAlive");
public static final PacketType CHAT = new PacketType(PROTOCOL, SENDER, 0x01, 3); public static final PacketType CHAT = new PacketType(PROTOCOL, SENDER, 0x01, 3, "Chat");
public static final PacketType USE_ENTITY = new PacketType(PROTOCOL, SENDER, 0x02, 7); public static final PacketType USE_ENTITY = new PacketType(PROTOCOL, SENDER, 0x02, 7, "UseEntity");
public static final PacketType FLYING = new PacketType(PROTOCOL, SENDER, 0x03, 10); public static final PacketType FLYING = new PacketType(PROTOCOL, SENDER, 0x03, 10, "Flying");
public static final PacketType POSITION = new PacketType(PROTOCOL, SENDER, 0x04, 11); public static final PacketType POSITION = new PacketType(PROTOCOL, SENDER, 0x04, 11, "Position");
public static final PacketType LOOK = new PacketType(PROTOCOL, SENDER, 0x05, 12); public static final PacketType LOOK = new PacketType(PROTOCOL, SENDER, 0x05, 12, "Look");
public static final PacketType POSITION_LOOK = new PacketType(PROTOCOL, SENDER, 0x06, 13); public static final PacketType POSITION_LOOK = new PacketType(PROTOCOL, SENDER, 0x06, 13, "PositionLook");
public static final PacketType BLOCK_DIG = new PacketType(PROTOCOL, SENDER, 0x07, 14); public static final PacketType BLOCK_DIG = new PacketType(PROTOCOL, SENDER, 0x07, 14, "BlockDig");
public static final PacketType BLOCK_PLACE = new PacketType(PROTOCOL, SENDER, 0x08, 15); public static final PacketType BLOCK_PLACE = new PacketType(PROTOCOL, SENDER, 0x08, 15, "BlockPlace");
public static final PacketType HELD_ITEM_SLOT = new PacketType(PROTOCOL, SENDER, 0x09, 16); public static final PacketType HELD_ITEM_SLOT = new PacketType(PROTOCOL, SENDER, 0x09, 16, "HeldItemSlot");
public static final PacketType ARM_ANIMATION = new PacketType(PROTOCOL, SENDER, 0x0A, 18); public static final PacketType ARM_ANIMATION = new PacketType(PROTOCOL, SENDER, 0x0A, 18, "ArmAnimation");
public static final PacketType ENTITY_ACTION = new PacketType(PROTOCOL, SENDER, 0x0B, 19); public static final PacketType ENTITY_ACTION = new PacketType(PROTOCOL, SENDER, 0x0B, 19, "EntityAction");
public static final PacketType STEER_VEHICLE = new PacketType(PROTOCOL, SENDER, 0x0C, 27); public static final PacketType STEER_VEHICLE = new PacketType(PROTOCOL, SENDER, 0x0C, 27, "SteerVehicle");
public static final PacketType CLOSE_WINDOW = new PacketType(PROTOCOL, SENDER, 0x0D, 101); public static final PacketType CLOSE_WINDOW = new PacketType(PROTOCOL, SENDER, 0x0D, 101, "CloseWindow");
public static final PacketType WINDOW_CLICK = new PacketType(PROTOCOL, SENDER, 0x0E, 102); public static final PacketType WINDOW_CLICK = new PacketType(PROTOCOL, SENDER, 0x0E, 102, "WindowClick");
public static final PacketType TRANSACTION = new PacketType(PROTOCOL, SENDER, 0x0F, 106); public static final PacketType TRANSACTION = new PacketType(PROTOCOL, SENDER, 0x0F, 106, "Transaction");
public static final PacketType SET_CREATIVE_SLOT = new PacketType(PROTOCOL, SENDER, 0x10, 107); public static final PacketType SET_CREATIVE_SLOT = new PacketType(PROTOCOL, SENDER, 0x10, 107, "SetCreativeSlot");
public static final PacketType ENCHANT_ITEM = new PacketType(PROTOCOL, SENDER, 0x11, 108); public static final PacketType ENCHANT_ITEM = new PacketType(PROTOCOL, SENDER, 0x11, 108, "EnchantItem");
public static final PacketType UPDATE_SIGN = new PacketType(PROTOCOL, SENDER, 0x12, 130); public static final PacketType UPDATE_SIGN = new PacketType(PROTOCOL, SENDER, 0x12, 130, "UpdateSign");
public static final PacketType ABILITIES = new PacketType(PROTOCOL, SENDER, 0x13, 202); public static final PacketType ABILITIES = new PacketType(PROTOCOL, SENDER, 0x13, 202, "Abilities");
public static final PacketType TAB_COMPLETE = new PacketType(PROTOCOL, SENDER, 0x14, 203); public static final PacketType TAB_COMPLETE = new PacketType(PROTOCOL, SENDER, 0x14, 203, "TabComplete");
public static final PacketType SETTINGS = new PacketType(PROTOCOL, SENDER, 0x15, 204); public static final PacketType SETTINGS = new PacketType(PROTOCOL, SENDER, 0x15, 204, "Settings");
public static final PacketType CLIENT_COMMAND = new PacketType(PROTOCOL, SENDER, 0x16, 205); public static final PacketType CLIENT_COMMAND = new PacketType(PROTOCOL, SENDER, 0x16, 205, "ClientCommand");
public static final PacketType CUSTOM_PAYLOAD = new PacketType(PROTOCOL, SENDER, 0x17, 250); public static final PacketType CUSTOM_PAYLOAD = new PacketType(PROTOCOL, SENDER, 0x17, 250, "CustomPayload");
public static final PacketType SPECTATE = new PacketType(PROTOCOL, SENDER, 0x18, -1); public static final PacketType SPECTATE = new PacketType(PROTOCOL, SENDER, 0x18, -1, "Spectate");
public static final PacketType RESOURCE_PACK_STATUS = new PacketType(PROTOCOL, SENDER, 0x19, -1); public static final PacketType RESOURCE_PACK_STATUS = new PacketType(PROTOCOL, SENDER, 0x19, -1, "ResourcePackStatus");
private final static Client INSTANCE = new Client(); private final static Client INSTANCE = new Client();
@ -269,8 +272,8 @@ public class PacketType implements Serializable, Comparable<PacketType> {
public static class Server extends ObjectEnum<PacketType> { public static class Server extends ObjectEnum<PacketType> {
private final static Sender SENDER = Sender.SERVER; private final static Sender SENDER = Sender.SERVER;
public static final PacketType OUT_SERVER_INFO = new PacketType(PROTOCOL, SENDER, 0x00, 255).forceAsync(true); public static final PacketType OUT_SERVER_INFO = new PacketType(PROTOCOL, SENDER, 0x00, 255, "ServerInfo").forceAsync(true);
public static final PacketType OUT_PING = new PacketType(PROTOCOL, SENDER, 0x01, 230); public static final PacketType OUT_PING = new PacketType(PROTOCOL, SENDER, 0x01, 230, "Pong");
private final static Server INSTANCE = new Server(); private final static Server INSTANCE = new Server();
@ -292,8 +295,8 @@ public class PacketType implements Serializable, Comparable<PacketType> {
public static class Client extends ObjectEnum<PacketType> { public static class Client extends ObjectEnum<PacketType> {
private final static Sender SENDER = Sender.CLIENT; private final static Sender SENDER = Sender.CLIENT;
public static final PacketType IN_START = new PacketType(PROTOCOL, SENDER, 0x00, 254); public static final PacketType IN_START = new PacketType(PROTOCOL, SENDER, 0x00, 254, "Start");
public static final PacketType IN_PING = new PacketType(PROTOCOL, SENDER, 0x01, 230); public static final PacketType IN_PING = new PacketType(PROTOCOL, SENDER, 0x01, 230, "Ping");
private final static Client INSTANCE = new Client(); private final static Client INSTANCE = new Client();
@ -327,10 +330,10 @@ public class PacketType implements Serializable, Comparable<PacketType> {
public static class Server extends ObjectEnum<PacketType> { public static class Server extends ObjectEnum<PacketType> {
private final static Sender SENDER = Sender.SERVER; private final static Sender SENDER = Sender.SERVER;
public static final PacketType DISCONNECT = new PacketType(PROTOCOL, SENDER, 0x00, 255); public static final PacketType DISCONNECT = new PacketType(PROTOCOL, SENDER, 0x00, 255, "Disconnect");
public static final PacketType ENCRYPTION_BEGIN = new PacketType(PROTOCOL, SENDER, 0x01, 253); public static final PacketType ENCRYPTION_BEGIN = new PacketType(PROTOCOL, SENDER, 0x01, 253, "EncryptionBegin");
public static final PacketType SUCCESS = new PacketType(PROTOCOL, SENDER, 0x02, 232); public static final PacketType SUCCESS = new PacketType(PROTOCOL, SENDER, 0x02, 232, "Success");
public static final PacketType SET_COMPRESSION = new PacketType(PROTOCOL, SENDER, 0x03, -1); public static final PacketType SET_COMPRESSION = new PacketType(PROTOCOL, SENDER, 0x03, -1, "SetCompression");
private final static Server INSTANCE = new Server(); private final static Server INSTANCE = new Server();
@ -352,8 +355,8 @@ public class PacketType implements Serializable, Comparable<PacketType> {
public static class Client extends ObjectEnum<PacketType> { public static class Client extends ObjectEnum<PacketType> {
private final static Sender SENDER = Sender.CLIENT; private final static Sender SENDER = Sender.CLIENT;
public static final PacketType START = new PacketType(PROTOCOL, SENDER, 0x00, 231); public static final PacketType START = new PacketType(PROTOCOL, SENDER, 0x00, 231, "Start");
public static final PacketType ENCRYPTION_BEGIN = new PacketType(PROTOCOL, SENDER, 0x01, 252); public static final PacketType ENCRYPTION_BEGIN = new PacketType(PROTOCOL, SENDER, 0x01, 252, "EncryptionBegin");
private final static Client INSTANCE = new Client(); private final static Client INSTANCE = new Client();
@ -474,7 +477,7 @@ public class PacketType implements Serializable, Comparable<PacketType> {
String name = vanilla.name(); String name = vanilla.name();
if ("HANDSHAKING".equals(name)) if ("HANDSHAKING".equals(name))
return HANDSHAKING; return HANDSHAKING;
if ("PLAY".equals(name)) if ("PLAY".equals(name))
return PLAY; return PLAY;
if ("STATUS".equals(name)) if ("STATUS".equals(name))
@ -483,6 +486,10 @@ public class PacketType implements Serializable, Comparable<PacketType> {
return LOGIN; return LOGIN;
throw new IllegalArgumentException("Unrecognized vanilla enum " + vanilla); throw new IllegalArgumentException("Unrecognized vanilla enum " + vanilla);
} }
public String getPacketName() {
return WordUtils.capitalize(name().toLowerCase());
}
} }
/** /**
@ -508,6 +515,10 @@ public class PacketType implements Serializable, Comparable<PacketType> {
public ConnectionSide toSide() { public ConnectionSide toSide() {
return this == CLIENT ? ConnectionSide.CLIENT_SIDE : ConnectionSide.SERVER_SIDE; return this == CLIENT ? ConnectionSide.CLIENT_SIDE : ConnectionSide.SERVER_SIDE;
} }
public String getPacketName() {
return this == CLIENT ? "In" : "Out";
}
} }
// Lookup of packet types // Lookup of packet types
@ -523,6 +534,8 @@ public class PacketType implements Serializable, Comparable<PacketType> {
private final int currentId; private final int currentId;
private final int legacyId; private final int legacyId;
private final MinecraftVersion version; private final MinecraftVersion version;
private final String[] classNames;
private boolean forceAsync; private boolean forceAsync;
private boolean dynamic; private boolean dynamic;
@ -673,19 +686,25 @@ public class PacketType implements Serializable, Comparable<PacketType> {
* @param protocol - the current protocol. * @param protocol - the current protocol.
* @param sender - the sender. * @param sender - the sender.
* @param packetId - the packet ID. Can be UNKNOWN_PACKET. * @param packetId - the packet ID. Can be UNKNOWN_PACKET.
* @param legacyId - the legacy packet ID. Can be UNKNOWN_PACKET. * @param packetClass - the packet class
* @return The corresponding packet type. * @return The corresponding packet type.
*/ */
public static PacketType fromCurrent(Protocol protocol, Sender sender, int packetId, int legacyId) { public static PacketType fromCurrent(Protocol protocol, Sender sender, int packetId, Class<?> packetClass) {
PacketType type = getLookup().getFromCurrent(protocol, sender, packetId); String className = packetClass.getSimpleName();
for (PacketType type : PacketType.values()) {
if (type == null) { for (String name : type.classNames) {
type = new PacketType(protocol, sender, packetId, legacyId, PROTOCOL_VERSION); if (className.equals(name)) {
type.dynamic = true; return type;
}
// Many may be scheduled, but only the first will be executed }
scheduleRegister(type, "Dynamic-" + UUID.randomUUID().toString());
} }
System.out.println("No match for " + className);
PacketType type = new PacketType(protocol, sender, packetId, -1, PROTOCOL_VERSION, className);
type.dynamic = true;
// Many may be scheduled, but only the first will be executed
scheduleRegister(type, "Dynamic-" + UUID.randomUUID().toString());
return type; return type;
} }
@ -787,8 +806,8 @@ public class PacketType implements Serializable, Comparable<PacketType> {
* @param currentId - the current packet ID, or * @param currentId - the current packet ID, or
* @param legacyId - the legacy packet ID. * @param legacyId - the legacy packet ID.
*/ */
public PacketType(Protocol protocol, Sender sender, int currentId, int legacyId) { public PacketType(Protocol protocol, Sender sender, int currentId, int legacyId, String... names) {
this(protocol, sender, currentId, legacyId, PROTOCOL_VERSION); this(protocol, sender, currentId, legacyId, PROTOCOL_VERSION, names);
} }
/** /**
@ -799,12 +818,17 @@ public class PacketType implements Serializable, Comparable<PacketType> {
* @param legacyId - the legacy packet ID. * @param legacyId - the legacy packet ID.
* @param version - the version of the current ID. * @param version - the version of the current ID.
*/ */
public PacketType(Protocol protocol, Sender sender, int currentId, int legacyId, MinecraftVersion version) { public PacketType(Protocol protocol, Sender sender, int currentId, int legacyId, MinecraftVersion version, String... names) {
this.protocol = Preconditions.checkNotNull(protocol, "protocol cannot be NULL"); this.protocol = Preconditions.checkNotNull(protocol, "protocol cannot be NULL");
this.sender = Preconditions.checkNotNull(sender, "sender cannot be NULL"); this.sender = Preconditions.checkNotNull(sender, "sender cannot be NULL");
this.currentId = currentId; this.currentId = currentId;
this.legacyId = legacyId; this.legacyId = legacyId;
this.version = version; this.version = version;
this.classNames = new String[names.length];
for (int i = 0; i < classNames.length; i++) {
classNames[i] = String.format("Packet%s%s%s", protocol.getPacketName(), sender.getPacketName(), names[i]);
}
} }
/** /**
@ -864,7 +888,9 @@ public class PacketType implements Serializable, Comparable<PacketType> {
* <p> * <p>
* It is only unknown if the packet was removed in Minecraft 1.7.2. * It is only unknown if the packet was removed in Minecraft 1.7.2.
* @return The current ID, or {@link #UNKNOWN_PACKET} if unknown. * @return The current ID, or {@link #UNKNOWN_PACKET} if unknown.
* @deprecated IDs are subject to change
*/ */
@Deprecated
public int getCurrentId() { public int getCurrentId() {
return currentId; return currentId;
} }
@ -963,7 +989,7 @@ public class PacketType implements Serializable, Comparable<PacketType> {
Class<?> clazz = getPacketClass(); Class<?> clazz = getPacketClass();
if (clazz == null) if (clazz == null)
return "UNREGISTERED [" + protocol + ", " + sender + ", " + currentId + ", legacy: " + legacyId + "]"; return "UNREGISTERED[" + protocol + ", " + sender + ", " + currentId + ", legacy: " + legacyId + ", classNames: " + Arrays.toString(classNames) + "]";
else else
return clazz.getSimpleName() + "[" + currentId + ", legacy: " + legacyId + "]"; return clazz.getSimpleName() + "[" + currentId + ", legacy: " + legacyId + "]";
} }

View File

@ -66,18 +66,18 @@ import com.google.common.collect.Lists;
public class NettyProtocolInjector implements ProtocolInjector { public class NettyProtocolInjector implements ProtocolInjector {
public static final ReportType REPORT_CANNOT_INJECT_INCOMING_CHANNEL = new ReportType("Unable to inject incoming channel %s."); public static final ReportType REPORT_CANNOT_INJECT_INCOMING_CHANNEL = new ReportType("Unable to inject incoming channel %s.");
private volatile boolean injected; private volatile boolean injected;
private volatile boolean closed; private volatile boolean closed;
// The temporary player factory // The temporary player factory
private TemporaryPlayerFactory playerFactory = new TemporaryPlayerFactory(); private TemporaryPlayerFactory playerFactory = new TemporaryPlayerFactory();
private List<VolatileField> bootstrapFields = Lists.newArrayList(); private List<VolatileField> bootstrapFields = Lists.newArrayList();
// The channel injector factory // The channel injector factory
private NettyInjectionFactory injectionFactory; private NettyInjectionFactory injectionFactory;
// List of network managers // List of network managers
private volatile List<Object> networkManagers; private volatile List<Object> networkManagers;
// Different sending filters // Different sending filters
private PacketTypeSet sendingFilters = new PacketTypeSet(); private PacketTypeSet sendingFilters = new PacketTypeSet();
@ -87,125 +87,123 @@ public class NettyProtocolInjector implements ProtocolInjector {
private PacketTypeSet mainThreadFilters = new PacketTypeSet(); private PacketTypeSet mainThreadFilters = new PacketTypeSet();
// Which packets are buffered // Which packets are buffered
private PacketTypeSet bufferedPackets = new PacketTypeSet(); private PacketTypeSet bufferedPackets = new PacketTypeSet();
private ListenerInvoker invoker; private ListenerInvoker invoker;
// Handle errors // Handle errors
private ErrorReporter reporter; private ErrorReporter reporter;
private boolean debug; private boolean debug;
public NettyProtocolInjector(Plugin plugin, ListenerInvoker invoker, ErrorReporter reporter) { public NettyProtocolInjector(Plugin plugin, ListenerInvoker invoker, ErrorReporter reporter) {
this.injectionFactory = new NettyInjectionFactory(plugin); this.injectionFactory = new NettyInjectionFactory(plugin);
this.invoker = invoker; this.invoker = invoker;
this.reporter = reporter; this.reporter = reporter;
} }
@Override @Override
public boolean isDebug() { public boolean isDebug() {
return debug; return debug;
} }
/** /**
* Set whether or not the debug mode is enabled. * Set whether or not the debug mode is enabled.
* @param debug - TRUE if it is, FALSE otherwise. * @param debug - TRUE if it is, FALSE otherwise.
*/ */
@Override @Override
public void setDebug(boolean debug) { public void setDebug(boolean debug) {
this.debug = debug; this.debug = debug;
} }
/** /**
* Inject into the spigot connection class. * Inject into the spigot connection class.
*/ */
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public synchronized void inject() { public synchronized void inject() {
if (injected) if (injected)
throw new IllegalStateException("Cannot inject twice."); throw new IllegalStateException("Cannot inject twice.");
try { try {
FuzzyReflection fuzzyServer = FuzzyReflection.fromClass(MinecraftReflection.getMinecraftServerClass()); FuzzyReflection fuzzyServer = FuzzyReflection.fromClass(MinecraftReflection.getMinecraftServerClass());
List<Method> serverConnectionMethods = fuzzyServer.getMethodListByParameters(MinecraftReflection.getServerConnectionClass(), new Class[] {}); List<Method> serverConnectionMethods = fuzzyServer.getMethodListByParameters(MinecraftReflection.getServerConnectionClass(), new Class[] {});
// Get the server connection // Get the server connection
Object server = fuzzyServer.getSingleton(); Object server = fuzzyServer.getSingleton();
Object serverConnection = null; Object serverConnection = null;
for (Method method : serverConnectionMethods) { for (Method method : serverConnectionMethods) {
try { try {
serverConnection = method.invoke(server); serverConnection = method.invoke(server);
// Continue until we get a server connection // Continue until we get a server connection
if (serverConnection != null) { if (serverConnection != null) {
break; break;
} }
} catch (Exception e) { } catch (Exception e) {
// Try the next though // Try the next though
e.printStackTrace(); e.printStackTrace();
} }
} }
// Handle connected channels // Handle connected channels
final ChannelInboundHandler endInitProtocol = new ChannelInitializer<Channel>() { final ChannelInboundHandler endInitProtocol = new ChannelInitializer<Channel>() {
@Override @Override
protected void initChannel(Channel channel) throws Exception { protected void initChannel(Channel channel) throws Exception {
try { try {
// This can take a while, so we need to stop the main thread from interfering // This can take a while, so we need to stop the main thread from interfering
synchronized (networkManagers) { synchronized (networkManagers) {
injectionFactory.fromChannel(channel, NettyProtocolInjector.this, playerFactory).inject(); injectionFactory.fromChannel(channel, NettyProtocolInjector.this, playerFactory).inject();
} }
} catch (Exception e) { } catch (Exception e) {
reporter.reportDetailed(NettyProtocolInjector.this, Report.newBuilder(REPORT_CANNOT_INJECT_INCOMING_CHANNEL). reporter.reportDetailed(NettyProtocolInjector.this, Report.newBuilder(REPORT_CANNOT_INJECT_INCOMING_CHANNEL).messageParam(channel).error(e));
messageParam(channel).error(e)); }
} }
} };
};
// This is executed before Minecraft's channel handler // This is executed before Minecraft's channel handler
final ChannelInboundHandler beginInitProtocol = new ChannelInitializer<Channel>() { final ChannelInboundHandler beginInitProtocol = new ChannelInitializer<Channel>() {
@Override @Override
protected void initChannel(Channel channel) throws Exception { protected void initChannel(Channel channel) throws Exception {
// Our only job is to add init protocol // Our only job is to add init protocol
channel.pipeline().addLast(endInitProtocol); channel.pipeline().addLast(endInitProtocol);
} }
}; };
// Add our handler to newly created channels // Add our handler to newly created channels
final ChannelHandler connectionHandler = new ChannelInboundHandlerAdapter() { final ChannelHandler connectionHandler = new ChannelInboundHandlerAdapter() {
@Override @Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
Channel channel = (Channel) msg; Channel channel = (Channel) msg;
// Prepare to initialize ths channel // Prepare to initialize ths channel
channel.pipeline().addFirst(beginInitProtocol); channel.pipeline().addFirst(beginInitProtocol);
ctx.fireChannelRead(msg); ctx.fireChannelRead(msg);
} }
}; };
// Get the current NetworkMananger list // Get the current NetworkMananger list
networkManagers = (List<Object>) FuzzyReflection.fromObject(serverConnection, true). networkManagers = (List<Object>) FuzzyReflection.fromObject(serverConnection, true).invokeMethod(null, "getNetworkManagers", List.class, serverConnection);
invokeMethod(null, "getNetworkManagers", List.class, serverConnection);
// Insert ProtocolLib's connection interceptor // Insert ProtocolLib's connection interceptor
bootstrapFields = getBootstrapFields(serverConnection); bootstrapFields = getBootstrapFields(serverConnection);
for (VolatileField field : bootstrapFields) { for (VolatileField field : bootstrapFields) {
final List<Object> list = (List<Object>) field.getValue(); final List<Object> list = (List<Object>) field.getValue();
// We don't have to override this list // We don't have to override this list
if (list == networkManagers) { if (list == networkManagers) {
continue; continue;
} }
// Synchronize with each list before we attempt to replace them. // Synchronize with each list before we attempt to replace them.
field.setValue(new NettyBootstrapList(list, connectionHandler)); field.setValue(new NettyBootstrapList(list, connectionHandler));
} }
injected = true; injected = true;
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Unable to inject channel futures.", e); throw new RuntimeException("Unable to inject channel futures.", e);
} }
} }
@Override @Override
public boolean hasListener(Class<?> packetClass) { public boolean hasListener(Class<?> packetClass) {
@ -222,52 +220,53 @@ public class NettyProtocolInjector implements ProtocolInjector {
return reporter; return reporter;
} }
/** /**
* Inject our packet handling into a specific player. * Inject our packet handling into a specific player.
* @param player Player to inject into * @param player Player to inject into
*/ */
public void injectPlayer(Player player) { public void injectPlayer(Player player) {
injectionFactory.fromPlayer(player, this).inject(); injectionFactory.fromPlayer(player, this).inject();
} }
private List<VolatileField> getBootstrapFields(Object serverConnection) { private List<VolatileField> getBootstrapFields(Object serverConnection) {
List<VolatileField> result = Lists.newArrayList(); List<VolatileField> result = Lists.newArrayList();
// Find and (possibly) proxy every list // Find and (possibly) proxy every list
for (Field field : FuzzyReflection.fromObject(serverConnection, true).getFieldListByType(List.class)) { for (Field field : FuzzyReflection.fromObject(serverConnection, true).getFieldListByType(List.class)) {
VolatileField volatileField = new VolatileField(field, serverConnection, true).toSynchronized(); VolatileField volatileField = new VolatileField(field, serverConnection, true).toSynchronized();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<Object> list = (List<Object>) volatileField.getValue(); List<Object> list = (List<Object>) volatileField.getValue();
if (list.size() == 0 || list.get(0) instanceof ChannelFuture) { if (list.size() == 0 || list.get(0) instanceof ChannelFuture) {
result.add(volatileField); result.add(volatileField);
} }
} }
return result;
}
/** return result;
* Clean up any remaning injections. }
*/
@Override /**
* Clean up any remaning injections.
*/
@Override
public synchronized void close() { public synchronized void close() {
if (!closed) { if (!closed) {
closed = true; closed = true;
for (VolatileField field : bootstrapFields) { for (VolatileField field : bootstrapFields) {
Object value = field.getValue(); Object value = field.getValue();
// Undo the processed channels, if any // Undo the processed channels, if any
if (value instanceof NettyBootstrapList) { if (value instanceof NettyBootstrapList) {
((NettyBootstrapList) value).close(); ((NettyBootstrapList) value).close();
} }
field.revertValue(); field.revertValue();
} }
// Uninject all the players // Uninject all the players
injectionFactory.close(); injectionFactory.close();
} }
} }
@Override @Override
public PacketEvent onPacketSending(Injector injector, Object packet, NetworkMarker marker) { public PacketEvent onPacketSending(Injector injector, Object packet, NetworkMarker marker) {
@ -277,28 +276,11 @@ public class NettyProtocolInjector implements ProtocolInjector {
try { try {
PacketContainer container = new PacketContainer(PacketRegistry.getPacketType(clazz), packet); PacketContainer container = new PacketContainer(PacketRegistry.getPacketType(clazz), packet);
return packetQueued(container, injector.getPlayer(), marker); return packetQueued(container, injector.getPlayer(), marker);
} catch (LinkageError er) { } catch (LinkageError e) {
// Issue #109 // So far this has been seen when the jar is shared
if (isDebug()) { System.err.println("[ProtocolLib] Encountered a LinkageError. Make sure you\'re not using this jar for multiple server instances!");
try { System.err.println("[ProtocolLib] If you\'re getting this error for other reasons, please report it!");
System.out.println("Encountered a LinkageError in onPacketSending"); e.printStackTrace();
System.out.println("injector=" + injector);
System.out.println("packet=" + packet);
System.out.println("marker=" + marker);
Thread curr = Thread.currentThread();
System.out.println("current thread=" + curr.getName());
System.out.println("class loader=" + curr.getContextClassLoader());
Class<PacketContainer> container = PacketContainer.class;
System.out.println("packet container=" + container);
System.out.println("class loader=" + container.getClassLoader());
} catch (LinkageError e1) {
e1.printStackTrace();
}
}
er.printStackTrace();
} }
} }
@ -399,8 +381,7 @@ public class NettyProtocolInjector implements ProtocolInjector {
@Override @Override
public void sendServerPacket(Player receiver, PacketContainer packet, NetworkMarker marker, boolean filters) throws InvocationTargetException { public void sendServerPacket(Player receiver, PacketContainer packet, NetworkMarker marker, boolean filters) throws InvocationTargetException {
injectionFactory.fromPlayer(receiver, listener). injectionFactory.fromPlayer(receiver, listener).sendServerPacket(packet.getHandle(), marker, filters);
sendServerPacket(packet.getHandle(), marker, filters);
} }
@Override @Override
@ -410,8 +391,7 @@ public class NettyProtocolInjector implements ProtocolInjector {
@Override @Override
public void recieveClientPacket(Player player, Object mcPacket) throws IllegalAccessException, InvocationTargetException { public void recieveClientPacket(Player player, Object mcPacket) throws IllegalAccessException, InvocationTargetException {
injectionFactory.fromPlayer(player, listener). injectionFactory.fromPlayer(player, listener).recieveClientPacket(mcPacket);
recieveClientPacket(mcPacket);
} }
@Override @Override
@ -448,8 +428,7 @@ public class NettyProtocolInjector implements ProtocolInjector {
@Override @Override
public PacketEvent packetRecieved(PacketContainer packet, Player client, byte[] buffered) { public PacketEvent packetRecieved(PacketContainer packet, Player client, byte[] buffered) {
NetworkMarker marker = buffered != null ? new NettyNetworkMarker(ConnectionSide.CLIENT_SIDE, buffered) : null; NetworkMarker marker = buffered != null ? new NettyNetworkMarker(ConnectionSide.CLIENT_SIDE, buffered) : null;
injectionFactory.fromPlayer(client, NettyProtocolInjector.this). injectionFactory.fromPlayer(client, NettyProtocolInjector.this).saveMarker(packet.getHandle(), marker);
saveMarker(packet.getHandle(), marker);
return packetReceived(packet, client, marker); return packetReceived(packet, client, marker);
} }

View File

@ -216,7 +216,7 @@ public class NettyProtocolRegistry {
private void associatePackets(Register register, Map<Integer, Class<?>> lookup, Protocol protocol, Sender sender) { private void associatePackets(Register register, Map<Integer, Class<?>> lookup, Protocol protocol, Sender sender) {
for (Entry<Integer, Class<?>> entry : lookup.entrySet()) { for (Entry<Integer, Class<?>> entry : lookup.entrySet()) {
PacketType type = PacketType.fromCurrent(protocol, sender, entry.getKey(), PacketType.UNKNOWN_PACKET); PacketType type = PacketType.fromCurrent(protocol, sender, entry.getKey(), entry.getValue());
try { try {
register.typeToClass.put(type, entry.getValue()); register.typeToClass.put(type, entry.getValue());