mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2025-02-13 02:51:59 +01:00
Initial support for 1.16 (#880)
Note that things may not initially work as expected. There are known issues (see #880) relating to dimensions, chat packets, and tile entities. There were also internal changes to attributes, though hopefully those are fixed. As always, report issues on GitHub.
This commit is contained in:
parent
77feaa857e
commit
658da31d46
2
pom.xml
2
pom.xml
@ -17,7 +17,7 @@
|
||||
<project.fullVersion>${project.version}</project.fullVersion>
|
||||
|
||||
<powermock.version>2.0.7</powermock.version>
|
||||
<spigot.version>1.15.2-R0.1-SNAPSHOT</spigot.version>
|
||||
<spigot.version>1.16.1-R0.1-SNAPSHOT</spigot.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
|
@ -51,7 +51,7 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
public static class Client extends PacketTypeEnum {
|
||||
private final static Sender SENDER = Sender.CLIENT;
|
||||
|
||||
public static final PacketType SET_PROTOCOL = new PacketType(PROTOCOL, SENDER, 0x00, 0x00, "SetProtocol", "C00Handshake");
|
||||
public static final PacketType SET_PROTOCOL = new PacketType(PROTOCOL, SENDER, 0x00, "SetProtocol", "C00Handshake");
|
||||
|
||||
private final static Client INSTANCE = new Client();
|
||||
|
||||
@ -102,99 +102,98 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
public static class Server extends PacketTypeEnum {
|
||||
private final static Sender SENDER = Sender.SERVER;
|
||||
|
||||
public static final PacketType SPAWN_ENTITY = new PacketType(PROTOCOL, SENDER, 0x00, 0xFF, "SpawnEntity", "SPacketSpawnObject");
|
||||
public static final PacketType SPAWN_ENTITY_EXPERIENCE_ORB = new PacketType(PROTOCOL, SENDER, 0x01, 0xFF, "SpawnEntityExperienceOrb", "SPacketSpawnExperienceOrb");
|
||||
public static final PacketType SPAWN_ENTITY_WEATHER = new PacketType(PROTOCOL, SENDER, 0x02, 0xFF, "SpawnEntityWeather", "SPacketSpawnGlobalEntity");
|
||||
public static final PacketType SPAWN_ENTITY_LIVING = new PacketType(PROTOCOL, SENDER, 0x03, 0xFF, "SpawnEntityLiving", "SPacketSpawnMob");
|
||||
public static final PacketType SPAWN_ENTITY_PAINTING = new PacketType(PROTOCOL, SENDER, 0x04, 0xFF, "SpawnEntityPainting", "SPacketSpawnPainting");
|
||||
public static final PacketType NAMED_ENTITY_SPAWN = new PacketType(PROTOCOL, SENDER, 0x05, 0xFF, "NamedEntitySpawn", "SPacketSpawnPlayer");
|
||||
public static final PacketType ANIMATION = new PacketType(PROTOCOL, SENDER, 0x06, 0xFF, "Animation", "SPacketAnimation");
|
||||
public static final PacketType STATISTIC = new PacketType(PROTOCOL, SENDER, 0x07, 0xFF, "Statistic", "SPacketStatistics");
|
||||
public static final PacketType BLOCK_BREAK = new PacketType(PROTOCOL, SENDER, 0x08, 0xFF, "BlockBreak");
|
||||
public static final PacketType BLOCK_BREAK_ANIMATION = new PacketType(PROTOCOL, SENDER, 0x09, 0xFF, "BlockBreakAnimation", "SPacketBlockBreakAnim");
|
||||
public static final PacketType TILE_ENTITY_DATA = new PacketType(PROTOCOL, SENDER, 0x0A, 0xFF, "TileEntityData", "SPacketUpdateTileEntity");
|
||||
public static final PacketType BLOCK_ACTION = new PacketType(PROTOCOL, SENDER, 0x0B, 0xFF, "BlockAction", "SPacketBlockAction");
|
||||
public static final PacketType BLOCK_CHANGE = new PacketType(PROTOCOL, SENDER, 0x0C, 0xFF, "BlockChange", "SPacketBlockChange");
|
||||
public static final PacketType BOSS = new PacketType(PROTOCOL, SENDER, 0x0D, 0xFF, "Boss", "SPacketUpdateBossInfo");
|
||||
public static final PacketType SERVER_DIFFICULTY = new PacketType(PROTOCOL, SENDER, 0x0E, 0xFF, "ServerDifficulty", "SPacketServerDifficulty");
|
||||
public static final PacketType CHAT = new PacketType(PROTOCOL, SENDER, 0x0F, 0xFF, "Chat", "SPacketChat");
|
||||
public static final PacketType MULTI_BLOCK_CHANGE = new PacketType(PROTOCOL, SENDER, 0x10, 0xFF, "MultiBlockChange", "SPacketMultiBlockChange");
|
||||
public static final PacketType TAB_COMPLETE = new PacketType(PROTOCOL, SENDER, 0x11, 0xFF, "TabComplete", "SPacketTabComplete");
|
||||
public static final PacketType COMMANDS = new PacketType(PROTOCOL, SENDER, 0x12, 0xFF, "Commands");
|
||||
public static final PacketType TRANSACTION = new PacketType(PROTOCOL, SENDER, 0x13, 0xFF, "Transaction", "SPacketConfirmTransaction");
|
||||
public static final PacketType CLOSE_WINDOW = new PacketType(PROTOCOL, SENDER, 0x14, 0xFF, "CloseWindow", "SPacketCloseWindow");
|
||||
public static final PacketType WINDOW_ITEMS = new PacketType(PROTOCOL, SENDER, 0x15, 0xFF, "WindowItems", "SPacketWindowItems");
|
||||
public static final PacketType WINDOW_DATA = new PacketType(PROTOCOL, SENDER, 0x16, 0xFF, "WindowData", "SPacketWindowProperty");
|
||||
public static final PacketType SET_SLOT = new PacketType(PROTOCOL, SENDER, 0x17, 0xFF, "SetSlot", "SPacketSetSlot");
|
||||
public static final PacketType SET_COOLDOWN = new PacketType(PROTOCOL, SENDER, 0x18, 0xFF, "SetCooldown", "SPacketCooldown");
|
||||
public static final PacketType CUSTOM_PAYLOAD = new PacketType(PROTOCOL, SENDER, 0x19, 0xFF, "CustomPayload", "SPacketCustomPayload");
|
||||
public static final PacketType CUSTOM_SOUND_EFFECT = new PacketType(PROTOCOL, SENDER, 0x1A, 0xFF, "CustomSoundEffect", "SPacketCustomSound");
|
||||
public static final PacketType KICK_DISCONNECT = new PacketType(PROTOCOL, SENDER, 0x1B, 0xFF, "KickDisconnect", "SPacketDisconnect");
|
||||
public static final PacketType ENTITY_STATUS = new PacketType(PROTOCOL, SENDER, 0x1C, 0xFF, "EntityStatus", "SPacketEntityStatus");
|
||||
public static final PacketType EXPLOSION = new PacketType(PROTOCOL, SENDER, 0x1D, 0xFF, "Explosion", "SPacketExplosion");
|
||||
public static final PacketType UNLOAD_CHUNK = new PacketType(PROTOCOL, SENDER, 0x1E, 0xFF, "UnloadChunk", "SPacketUnloadChunk");
|
||||
public static final PacketType GAME_STATE_CHANGE = new PacketType(PROTOCOL, SENDER, 0x1F, 0xFF, "GameStateChange", "SPacketChangeGameState");
|
||||
public static final PacketType OPEN_WINDOW_HORSE = new PacketType(PROTOCOL, SENDER, 0x20, 0xFF, "OpenWindowHorse");
|
||||
public static final PacketType KEEP_ALIVE = new PacketType(PROTOCOL, SENDER, 0x21, 0xFF, "KeepAlive", "SPacketKeepAlive");
|
||||
public static final PacketType MAP_CHUNK = new PacketType(PROTOCOL, SENDER, 0x22, 0xFF, "MapChunk", "SPacketChunkData");
|
||||
public static final PacketType WORLD_EVENT = new PacketType(PROTOCOL, SENDER, 0x23, 0xFF, "WorldEvent", "SPacketEffect");
|
||||
public static final PacketType WORLD_PARTICLES = new PacketType(PROTOCOL, SENDER, 0x24, 0xFF, "WorldParticles", "SPacketParticles");
|
||||
public static final PacketType LIGHT_UPDATE = new PacketType(PROTOCOL, SENDER, 0x25, 0xFF, "LightUpdate");
|
||||
public static final PacketType LOGIN = new PacketType(PROTOCOL, SENDER, 0x26, 0xFF, "Login", "SPacketJoinGame");
|
||||
public static final PacketType MAP = new PacketType(PROTOCOL, SENDER, 0x27, 0xFF, "Map", "SPacketMaps");
|
||||
public static final PacketType OPEN_WINDOW_MERCHANT = new PacketType(PROTOCOL, SENDER, 0x28, 0xFF, "OpenWindowMerchant");
|
||||
public static final PacketType REL_ENTITY_MOVE = new PacketType(PROTOCOL, SENDER, 0x29, 0xFF, "Entity$RelEntityMove", "SPacketEntity$S15PacketEntityRelMove");
|
||||
public static final PacketType REL_ENTITY_MOVE_LOOK = new PacketType(PROTOCOL, SENDER, 0x2A, 0xFF, "Entity$RelEntityMoveLook", "SPacketEntity$S17PacketEntityLookMove");
|
||||
public static final PacketType ENTITY_LOOK = new PacketType(PROTOCOL, SENDER, 0x2B, 0xFF, "Entity$EntityLook", "SPacketEntity$S16PacketEntityLook");
|
||||
public static final PacketType ENTITY = new PacketType(PROTOCOL, SENDER, 0x2C, 0xFF, "Entity", "SPacketEntity");
|
||||
public static final PacketType VEHICLE_MOVE = new PacketType(PROTOCOL, SENDER, 0x2D, 0xFF, "VehicleMove", "SPacketMoveVehicle");
|
||||
public static final PacketType OPEN_BOOK = new PacketType(PROTOCOL, SENDER, 0x2E, 0xFF, "OpenBook");
|
||||
public static final PacketType OPEN_WINDOW = new PacketType(PROTOCOL, SENDER, 0x2F, 0xFF, "OpenWindow", "SPacketOpenWindow");
|
||||
public static final PacketType OPEN_SIGN_EDITOR = new PacketType(PROTOCOL, SENDER, 0x30, 0xFF, "OpenSignEditor", "SPacketSignEditorOpen");
|
||||
public static final PacketType AUTO_RECIPE = new PacketType(PROTOCOL, SENDER, 0x31, 0xFF, "AutoRecipe", "SPacketPlaceGhostRecipe");
|
||||
public static final PacketType ABILITIES = new PacketType(PROTOCOL, SENDER, 0x32, 0xFF, "Abilities", "SPacketPlayerAbilities");
|
||||
public static final PacketType COMBAT_EVENT = new PacketType(PROTOCOL, SENDER, 0x33, 0xFF, "CombatEvent", "SPacketCombatEvent");
|
||||
public static final PacketType PLAYER_INFO = new PacketType(PROTOCOL, SENDER, 0x34, 0xFF, "PlayerInfo", "SPacketPlayerListItem");
|
||||
public static final PacketType LOOK_AT = new PacketType(PROTOCOL, SENDER, 0x35, 0xFF, "LookAt", "SPacketPlayerPosLook");
|
||||
public static final PacketType POSITION = new PacketType(PROTOCOL, SENDER, 0x36, 0xFF, "Position");
|
||||
public static final PacketType RECIPES = new PacketType(PROTOCOL, SENDER, 0x37, 0xFF, "Recipes", "SPacketRecipeBook");
|
||||
public static final PacketType ENTITY_DESTROY = new PacketType(PROTOCOL, SENDER, 0x38, 0xFF, "EntityDestroy", "SPacketDestroyEntities");
|
||||
public static final PacketType REMOVE_ENTITY_EFFECT = new PacketType(PROTOCOL, SENDER, 0x39, 0xFF, "RemoveEntityEffect", "SPacketRemoveEntityEffect");
|
||||
public static final PacketType RESOURCE_PACK_SEND = new PacketType(PROTOCOL, SENDER, 0x3A, 0xFF, "ResourcePackSend", "SPacketResourcePackSend");
|
||||
public static final PacketType RESPAWN = new PacketType(PROTOCOL, SENDER, 0x3B, 0xFF, "Respawn", "SPacketRespawn");
|
||||
public static final PacketType ENTITY_HEAD_ROTATION = new PacketType(PROTOCOL, SENDER, 0x3C, 0xFF, "EntityHeadRotation", "SPacketEntityHeadLook");
|
||||
public static final PacketType SELECT_ADVANCEMENT_TAB = new PacketType(PROTOCOL, SENDER, 0x3D, 0xFF, "SelectAdvancementTab", "SPacketSelectAdvancementsTab");
|
||||
public static final PacketType WORLD_BORDER = new PacketType(PROTOCOL, SENDER, 0x3E, 0xFF, "WorldBorder", "SPacketWorldBorder");
|
||||
public static final PacketType CAMERA = new PacketType(PROTOCOL, SENDER, 0x3F, 0xFF, "Camera", "SPacketCamera");
|
||||
public static final PacketType HELD_ITEM_SLOT = new PacketType(PROTOCOL, SENDER, 0x40, 0xFF, "HeldItemSlot", "SPacketHeldItemChange");
|
||||
public static final PacketType VIEW_CENTRE = new PacketType(PROTOCOL, SENDER, 0x41, 0xFF, "ViewCentre");
|
||||
public static final PacketType VIEW_DISTANCE = new PacketType(PROTOCOL, SENDER, 0x42, 0xFF, "ViewDistance");
|
||||
public static final PacketType SCOREBOARD_DISPLAY_OBJECTIVE = new PacketType(PROTOCOL, SENDER, 0x43, 0xFF, "ScoreboardDisplayObjective", "SPacketDisplayObjective");
|
||||
public static final PacketType ENTITY_METADATA = new PacketType(PROTOCOL, SENDER, 0x44, 0xFF, "EntityMetadata", "SPacketEntityMetadata");
|
||||
public static final PacketType ATTACH_ENTITY = new PacketType(PROTOCOL, SENDER, 0x45, 0xFF, "AttachEntity", "SPacketEntityAttach");
|
||||
public static final PacketType ENTITY_VELOCITY = new PacketType(PROTOCOL, SENDER, 0x46, 0xFF, "EntityVelocity", "SPacketEntityVelocity");
|
||||
public static final PacketType ENTITY_EQUIPMENT = new PacketType(PROTOCOL, SENDER, 0x47, 0xFF, "EntityEquipment", "SPacketEntityEquipment");
|
||||
public static final PacketType EXPERIENCE = new PacketType(PROTOCOL, SENDER, 0x48, 0xFF, "Experience", "SPacketSetExperience");
|
||||
public static final PacketType UPDATE_HEALTH = new PacketType(PROTOCOL, SENDER, 0x49, 0xFF, "UpdateHealth", "SPacketUpdateHealth");
|
||||
public static final PacketType SCOREBOARD_OBJECTIVE = new PacketType(PROTOCOL, SENDER, 0x4A, 0xFF, "ScoreboardObjective", "SPacketScoreboardObjective");
|
||||
public static final PacketType MOUNT = new PacketType(PROTOCOL, SENDER, 0x4B, 0xFF, "Mount", "SPacketSetPassengers");
|
||||
public static final PacketType SCOREBOARD_TEAM = new PacketType(PROTOCOL, SENDER, 0x4C, 0xFF, "ScoreboardTeam", "SPacketTeams");
|
||||
public static final PacketType SCOREBOARD_SCORE = new PacketType(PROTOCOL, SENDER, 0x4D, 0xFF, "ScoreboardScore", "SPacketUpdateScore");
|
||||
public static final PacketType SPAWN_POSITION = new PacketType(PROTOCOL, SENDER, 0x4E, 0xFF, "SpawnPosition", "SPacketSpawnPosition");
|
||||
public static final PacketType UPDATE_TIME = new PacketType(PROTOCOL, SENDER, 0x4F, 0xFF, "UpdateTime", "SPacketTimeUpdate");
|
||||
public static final PacketType TITLE = new PacketType(PROTOCOL, SENDER, 0x50, 0xFF, "Title", "SPacketTitle");
|
||||
public static final PacketType ENTITY_SOUND = new PacketType(PROTOCOL, SENDER, 0x51, 0xFF, "EntitySound", "SPacketSoundEffect");
|
||||
public static final PacketType NAMED_SOUND_EFFECT = new PacketType(PROTOCOL, SENDER, 0x52, 0xFF, "NamedSoundEffect");
|
||||
public static final PacketType STOP_SOUND = new PacketType(PROTOCOL, SENDER, 0x53, 0xFF, "StopSound");
|
||||
public static final PacketType PLAYER_LIST_HEADER_FOOTER = new PacketType(PROTOCOL, SENDER, 0x54, 0xFF, "PlayerListHeaderFooter", "SPacketPlayerListHeaderFooter");
|
||||
public static final PacketType NBT_QUERY = new PacketType(PROTOCOL, SENDER, 0x55, 0xFF, "NBTQuery");
|
||||
public static final PacketType COLLECT = new PacketType(PROTOCOL, SENDER, 0x56, 0xFF, "Collect", "SPacketCollectItem");
|
||||
public static final PacketType ENTITY_TELEPORT = new PacketType(PROTOCOL, SENDER, 0x57, 0xFF, "EntityTeleport", "SPacketEntityTeleport");
|
||||
public static final PacketType ADVANCEMENTS = new PacketType(PROTOCOL, SENDER, 0x58, 0xFF, "Advancements", "SPacketAdvancementInfo");
|
||||
public static final PacketType UPDATE_ATTRIBUTES = new PacketType(PROTOCOL, SENDER, 0x59, 0xFF, "UpdateAttributes", "SPacketEntityProperties");
|
||||
public static final PacketType ENTITY_EFFECT = new PacketType(PROTOCOL, SENDER, 0x5A, 0xFF, "EntityEffect", "SPacketEntityEffect");
|
||||
public static final PacketType RECIPE_UPDATE = new PacketType(PROTOCOL, SENDER, 0x5B, 0xFF, "RecipeUpdate");
|
||||
public static final PacketType TAGS = new PacketType(PROTOCOL, SENDER, 0x5C, 0xFF, "Tags");
|
||||
public static final PacketType SPAWN_ENTITY = new PacketType(PROTOCOL, SENDER, 0x00, "SpawnEntity", "SPacketSpawnObject");
|
||||
public static final PacketType SPAWN_ENTITY_EXPERIENCE_ORB = new PacketType(PROTOCOL, SENDER, 0x01, "SpawnEntityExperienceOrb", "SPacketSpawnExperienceOrb");
|
||||
public static final PacketType SPAWN_ENTITY_LIVING = new PacketType(PROTOCOL, SENDER, 0x02, "SpawnEntityLiving", "SPacketSpawnMob");
|
||||
public static final PacketType SPAWN_ENTITY_PAINTING = new PacketType(PROTOCOL, SENDER, 0x03, "SpawnEntityPainting", "SPacketSpawnPainting");
|
||||
public static final PacketType NAMED_ENTITY_SPAWN = new PacketType(PROTOCOL, SENDER, 0x04, "NamedEntitySpawn", "SPacketSpawnPlayer");
|
||||
public static final PacketType ANIMATION = new PacketType(PROTOCOL, SENDER, 0x05, "Animation", "SPacketAnimation");
|
||||
public static final PacketType STATISTIC = new PacketType(PROTOCOL, SENDER, 0x06, "Statistic", "SPacketStatistics");
|
||||
public static final PacketType BLOCK_BREAK = new PacketType(PROTOCOL, SENDER, 0x07, "BlockBreak");
|
||||
public static final PacketType BLOCK_BREAK_ANIMATION = new PacketType(PROTOCOL, SENDER, 0x08, "BlockBreakAnimation", "SPacketBlockBreakAnim");
|
||||
public static final PacketType TILE_ENTITY_DATA = new PacketType(PROTOCOL, SENDER, 0x09, "TileEntityData", "SPacketUpdateTileEntity");
|
||||
public static final PacketType BLOCK_ACTION = new PacketType(PROTOCOL, SENDER, 0x0A, "BlockAction", "SPacketBlockAction");
|
||||
public static final PacketType BLOCK_CHANGE = new PacketType(PROTOCOL, SENDER, 0x0B, "BlockChange", "SPacketBlockChange");
|
||||
public static final PacketType BOSS = new PacketType(PROTOCOL, SENDER, 0x0C, "Boss", "SPacketUpdateBossInfo");
|
||||
public static final PacketType SERVER_DIFFICULTY = new PacketType(PROTOCOL, SENDER, 0x0D, "ServerDifficulty", "SPacketServerDifficulty");
|
||||
public static final PacketType CHAT = new PacketType(PROTOCOL, SENDER, 0x0E, "Chat", "SPacketChat");
|
||||
public static final PacketType MULTI_BLOCK_CHANGE = new PacketType(PROTOCOL, SENDER, 0x0F, "MultiBlockChange", "SPacketMultiBlockChange");
|
||||
public static final PacketType TAB_COMPLETE = new PacketType(PROTOCOL, SENDER, 0x10, "TabComplete", "SPacketTabComplete");
|
||||
public static final PacketType COMMANDS = new PacketType(PROTOCOL, SENDER, 0x11, "Commands");
|
||||
public static final PacketType TRANSACTION = new PacketType(PROTOCOL, SENDER, 0x12, "Transaction", "SPacketConfirmTransaction");
|
||||
public static final PacketType CLOSE_WINDOW = new PacketType(PROTOCOL, SENDER, 0x13, "CloseWindow", "SPacketCloseWindow");
|
||||
public static final PacketType WINDOW_ITEMS = new PacketType(PROTOCOL, SENDER, 0x14, "WindowItems", "SPacketWindowItems");
|
||||
public static final PacketType WINDOW_DATA = new PacketType(PROTOCOL, SENDER, 0x15, "WindowData", "SPacketWindowProperty");
|
||||
public static final PacketType SET_SLOT = new PacketType(PROTOCOL, SENDER, 0x16, "SetSlot", "SPacketSetSlot");
|
||||
public static final PacketType SET_COOLDOWN = new PacketType(PROTOCOL, SENDER, 0x17, "SetCooldown", "SPacketCooldown");
|
||||
public static final PacketType CUSTOM_PAYLOAD = new PacketType(PROTOCOL, SENDER, 0x18, "CustomPayload", "SPacketCustomPayload");
|
||||
public static final PacketType CUSTOM_SOUND_EFFECT = new PacketType(PROTOCOL, SENDER, 0x19, "CustomSoundEffect", "SPacketCustomSound");
|
||||
public static final PacketType KICK_DISCONNECT = new PacketType(PROTOCOL, SENDER, 0x1A, "KickDisconnect", "SPacketDisconnect");
|
||||
public static final PacketType ENTITY_STATUS = new PacketType(PROTOCOL, SENDER, 0x1B, "EntityStatus", "SPacketEntityStatus");
|
||||
public static final PacketType EXPLOSION = new PacketType(PROTOCOL, SENDER, 0x1C, "Explosion", "SPacketExplosion");
|
||||
public static final PacketType UNLOAD_CHUNK = new PacketType(PROTOCOL, SENDER, 0x1D, "UnloadChunk", "SPacketUnloadChunk");
|
||||
public static final PacketType GAME_STATE_CHANGE = new PacketType(PROTOCOL, SENDER, 0x1E, "GameStateChange", "SPacketChangeGameState");
|
||||
public static final PacketType OPEN_WINDOW_HORSE = new PacketType(PROTOCOL, SENDER, 0x1F, "OpenWindowHorse");
|
||||
public static final PacketType KEEP_ALIVE = new PacketType(PROTOCOL, SENDER, 0x20, "KeepAlive", "SPacketKeepAlive");
|
||||
public static final PacketType MAP_CHUNK = new PacketType(PROTOCOL, SENDER, 0x21, "MapChunk", "SPacketChunkData");
|
||||
public static final PacketType WORLD_EVENT = new PacketType(PROTOCOL, SENDER, 0x22, "WorldEvent", "SPacketEffect");
|
||||
public static final PacketType WORLD_PARTICLES = new PacketType(PROTOCOL, SENDER, 0x23, "WorldParticles", "SPacketParticles");
|
||||
public static final PacketType LIGHT_UPDATE = new PacketType(PROTOCOL, SENDER, 0x24, "LightUpdate");
|
||||
public static final PacketType LOGIN = new PacketType(PROTOCOL, SENDER, 0x25, "Login", "SPacketJoinGame");
|
||||
public static final PacketType MAP = new PacketType(PROTOCOL, SENDER, 0x26, "Map", "SPacketMaps");
|
||||
public static final PacketType OPEN_WINDOW_MERCHANT = new PacketType(PROTOCOL, SENDER, 0x27, "OpenWindowMerchant");
|
||||
public static final PacketType REL_ENTITY_MOVE = new PacketType(PROTOCOL, SENDER, 0x28, "Entity$RelEntityMove", "SPacketEntity$S15PacketEntityRelMove");
|
||||
public static final PacketType REL_ENTITY_MOVE_LOOK = new PacketType(PROTOCOL, SENDER, 0x29, "Entity$RelEntityMoveLook", "SPacketEntity$S17PacketEntityLookMove");
|
||||
public static final PacketType ENTITY_LOOK = new PacketType(PROTOCOL, SENDER, 0x2A, "Entity$EntityLook", "SPacketEntity$S16PacketEntityLook");
|
||||
public static final PacketType ENTITY = new PacketType(PROTOCOL, SENDER, 0x2B, "Entity", "SPacketEntity");
|
||||
public static final PacketType VEHICLE_MOVE = new PacketType(PROTOCOL, SENDER, 0x2C, "VehicleMove", "SPacketMoveVehicle");
|
||||
public static final PacketType OPEN_BOOK = new PacketType(PROTOCOL, SENDER, 0x2D, "OpenBook");
|
||||
public static final PacketType OPEN_WINDOW = new PacketType(PROTOCOL, SENDER, 0x2E, "OpenWindow", "SPacketOpenWindow");
|
||||
public static final PacketType OPEN_SIGN_EDITOR = new PacketType(PROTOCOL, SENDER, 0x2F, "OpenSignEditor", "SPacketSignEditorOpen");
|
||||
public static final PacketType AUTO_RECIPE = new PacketType(PROTOCOL, SENDER, 0x30, "AutoRecipe", "SPacketPlaceGhostRecipe");
|
||||
public static final PacketType ABILITIES = new PacketType(PROTOCOL, SENDER, 0x31, "Abilities", "SPacketPlayerAbilities");
|
||||
public static final PacketType COMBAT_EVENT = new PacketType(PROTOCOL, SENDER, 0x32, "CombatEvent", "SPacketCombatEvent");
|
||||
public static final PacketType PLAYER_INFO = new PacketType(PROTOCOL, SENDER, 0x33, "PlayerInfo", "SPacketPlayerListItem");
|
||||
public static final PacketType LOOK_AT = new PacketType(PROTOCOL, SENDER, 0x34, "LookAt", "SPacketPlayerPosLook");
|
||||
public static final PacketType POSITION = new PacketType(PROTOCOL, SENDER, 0x35, "Position");
|
||||
public static final PacketType RECIPES = new PacketType(PROTOCOL, SENDER, 0x36, "Recipes", "SPacketRecipeBook");
|
||||
public static final PacketType ENTITY_DESTROY = new PacketType(PROTOCOL, SENDER, 0x37, "EntityDestroy", "SPacketDestroyEntities");
|
||||
public static final PacketType REMOVE_ENTITY_EFFECT = new PacketType(PROTOCOL, SENDER, 0x38, "RemoveEntityEffect", "SPacketRemoveEntityEffect");
|
||||
public static final PacketType RESOURCE_PACK_SEND = new PacketType(PROTOCOL, SENDER, 0x39, "ResourcePackSend", "SPacketResourcePackSend");
|
||||
public static final PacketType RESPAWN = new PacketType(PROTOCOL, SENDER, 0x3A, "Respawn", "SPacketRespawn");
|
||||
public static final PacketType ENTITY_HEAD_ROTATION = new PacketType(PROTOCOL, SENDER, 0x3B, "EntityHeadRotation", "SPacketEntityHeadLook");
|
||||
public static final PacketType SELECT_ADVANCEMENT_TAB = new PacketType(PROTOCOL, SENDER, 0x3C, "SelectAdvancementTab", "SPacketSelectAdvancementsTab");
|
||||
public static final PacketType WORLD_BORDER = new PacketType(PROTOCOL, SENDER, 0x3D, "WorldBorder", "SPacketWorldBorder");
|
||||
public static final PacketType CAMERA = new PacketType(PROTOCOL, SENDER, 0x3E, "Camera", "SPacketCamera");
|
||||
public static final PacketType HELD_ITEM_SLOT = new PacketType(PROTOCOL, SENDER, 0x3F, "HeldItemSlot", "SPacketHeldItemChange");
|
||||
public static final PacketType VIEW_CENTRE = new PacketType(PROTOCOL, SENDER, 0x40, "ViewCentre");
|
||||
public static final PacketType VIEW_DISTANCE = new PacketType(PROTOCOL, SENDER, 0x41, "ViewDistance");
|
||||
public static final PacketType SPAWN_POSITION = new PacketType(PROTOCOL, SENDER, 0x42, "SpawnPosition", "SPacketSpawnPosition");
|
||||
public static final PacketType SCOREBOARD_DISPLAY_OBJECTIVE = new PacketType(PROTOCOL, SENDER, 0x43, "ScoreboardDisplayObjective", "SPacketDisplayObjective");
|
||||
public static final PacketType ENTITY_METADATA = new PacketType(PROTOCOL, SENDER, 0x44, "EntityMetadata", "SPacketEntityMetadata");
|
||||
public static final PacketType ATTACH_ENTITY = new PacketType(PROTOCOL, SENDER, 0x45, "AttachEntity", "SPacketEntityAttach");
|
||||
public static final PacketType ENTITY_VELOCITY = new PacketType(PROTOCOL, SENDER, 0x46, "EntityVelocity", "SPacketEntityVelocity");
|
||||
public static final PacketType ENTITY_EQUIPMENT = new PacketType(PROTOCOL, SENDER, 0x47, "EntityEquipment", "SPacketEntityEquipment");
|
||||
public static final PacketType EXPERIENCE = new PacketType(PROTOCOL, SENDER, 0x48, "Experience", "SPacketSetExperience");
|
||||
public static final PacketType UPDATE_HEALTH = new PacketType(PROTOCOL, SENDER, 0x49, "UpdateHealth", "SPacketUpdateHealth");
|
||||
public static final PacketType SCOREBOARD_OBJECTIVE = new PacketType(PROTOCOL, SENDER, 0x4A, "ScoreboardObjective", "SPacketScoreboardObjective");
|
||||
public static final PacketType MOUNT = new PacketType(PROTOCOL, SENDER, 0x4B, "Mount", "SPacketSetPassengers");
|
||||
public static final PacketType SCOREBOARD_TEAM = new PacketType(PROTOCOL, SENDER, 0x4C, "ScoreboardTeam", "SPacketTeams");
|
||||
public static final PacketType SCOREBOARD_SCORE = new PacketType(PROTOCOL, SENDER, 0x4D, "ScoreboardScore", "SPacketUpdateScore");
|
||||
public static final PacketType UPDATE_TIME = new PacketType(PROTOCOL, SENDER, 0x4E, "UpdateTime", "SPacketTimeUpdate");
|
||||
public static final PacketType TITLE = new PacketType(PROTOCOL, SENDER, 0x4F, "Title", "SPacketTitle");
|
||||
public static final PacketType ENTITY_SOUND = new PacketType(PROTOCOL, SENDER, 0x50, "EntitySound", "SPacketSoundEffect");
|
||||
public static final PacketType NAMED_SOUND_EFFECT = new PacketType(PROTOCOL, SENDER, 0x51, "NamedSoundEffect");
|
||||
public static final PacketType STOP_SOUND = new PacketType(PROTOCOL, SENDER, 0x52, "StopSound");
|
||||
public static final PacketType PLAYER_LIST_HEADER_FOOTER = new PacketType(PROTOCOL, SENDER, 0x53, "PlayerListHeaderFooter", "SPacketPlayerListHeaderFooter");
|
||||
public static final PacketType NBT_QUERY = new PacketType(PROTOCOL, SENDER, 0x54, "NBTQuery");
|
||||
public static final PacketType COLLECT = new PacketType(PROTOCOL, SENDER, 0x55, "Collect", "SPacketCollectItem");
|
||||
public static final PacketType ENTITY_TELEPORT = new PacketType(PROTOCOL, SENDER, 0x56, "EntityTeleport", "SPacketEntityTeleport");
|
||||
public static final PacketType ADVANCEMENTS = new PacketType(PROTOCOL, SENDER, 0x57, "Advancements", "SPacketAdvancementInfo");
|
||||
public static final PacketType UPDATE_ATTRIBUTES = new PacketType(PROTOCOL, SENDER, 0x58, "UpdateAttributes", "SPacketEntityProperties");
|
||||
public static final PacketType ENTITY_EFFECT = new PacketType(PROTOCOL, SENDER, 0x59, "EntityEffect", "SPacketEntityEffect");
|
||||
public static final PacketType RECIPE_UPDATE = new PacketType(PROTOCOL, SENDER, 0x5A, "RecipeUpdate");
|
||||
public static final PacketType TAGS = new PacketType(PROTOCOL, SENDER, 0x5B, "Tags");
|
||||
|
||||
// ---- Removed in 1.9
|
||||
|
||||
@ -202,19 +201,19 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
* @deprecated Removed in 1.9
|
||||
*/
|
||||
@Deprecated
|
||||
public static final PacketType MAP_CHUNK_BULK = new PacketType(PROTOCOL, SENDER, 255, 255, "MapChunkBulk");
|
||||
public static final PacketType MAP_CHUNK_BULK = new PacketType(PROTOCOL, SENDER, 255, "MapChunkBulk");
|
||||
|
||||
/**
|
||||
* @deprecated Removed in 1.9
|
||||
*/
|
||||
@Deprecated
|
||||
public static final PacketType SET_COMPRESSION = new PacketType(PROTOCOL, SENDER, 254, 254, "SetCompression");
|
||||
public static final PacketType SET_COMPRESSION = new PacketType(PROTOCOL, SENDER, 254, "SetCompression");
|
||||
|
||||
/**
|
||||
* @deprecated Removed in 1.9
|
||||
*/
|
||||
@Deprecated
|
||||
public static final PacketType UPDATE_ENTITY_NBT = new PacketType(PROTOCOL, SENDER, 253, 253, "UpdateEntityNBT");
|
||||
public static final PacketType UPDATE_ENTITY_NBT = new PacketType(PROTOCOL, SENDER, 253, "UpdateEntityNBT");
|
||||
|
||||
// ----- Renamed packets
|
||||
|
||||
@ -248,7 +247,7 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
* @deprecated Replaced by {@link #TILE_ENTITY_DATA}
|
||||
*/
|
||||
@Deprecated
|
||||
public static final PacketType UPDATE_SIGN = MinecraftReflection.signUpdateExists() ? new PacketType(PROTOCOL, SENDER, 252, 252, "UpdateSign") :
|
||||
public static final PacketType UPDATE_SIGN = MinecraftReflection.signUpdateExists() ? new PacketType(PROTOCOL, SENDER, 252, "UpdateSign") :
|
||||
TILE_ENTITY_DATA.clone();
|
||||
|
||||
// ---- Removed in 1.14
|
||||
@ -257,7 +256,7 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
* @deprecated Removed in 1.14
|
||||
*/
|
||||
@Deprecated
|
||||
public static final PacketType BED = new PacketType(PROTOCOL, SENDER, 0x33, 0x33, "Bed", "SPacketUseBed");
|
||||
public static final PacketType BED = new PacketType(PROTOCOL, SENDER, 0x33, "Bed", "SPacketUseBed");
|
||||
|
||||
/**
|
||||
* @deprecated Renamed to {@link #BED}
|
||||
@ -265,6 +264,12 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
@Deprecated
|
||||
public static final PacketType USE_BED = BED.clone();
|
||||
|
||||
/**
|
||||
* @deprecated Removed in 1.16
|
||||
*/
|
||||
@Deprecated
|
||||
public static final PacketType SPAWN_ENTITY_WEATHER = new PacketType(PROTOCOL, SENDER, 0x02, "SpawnEntityWeather", "SPacketSpawnGlobalEntity");
|
||||
|
||||
private final static Server INSTANCE = new Server();
|
||||
|
||||
// Prevent accidental construction
|
||||
@ -285,52 +290,53 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
public static class Client extends PacketTypeEnum {
|
||||
private final static Sender SENDER = Sender.CLIENT;
|
||||
|
||||
public static final PacketType TELEPORT_ACCEPT = new PacketType(PROTOCOL, SENDER, 0x00, 0xFF, "TeleportAccept", "CPacketConfirmTeleport");
|
||||
public static final PacketType TILE_NBT_QUERY = new PacketType(PROTOCOL, SENDER, 0x01, 0xFF, "TileNBTQuery");
|
||||
public static final PacketType DIFFICULTY_CHANGE = new PacketType(PROTOCOL, SENDER, 0x02, 0xFF, "DifficultyChange");
|
||||
public static final PacketType CHAT = new PacketType(PROTOCOL, SENDER, 0x03, 0xFF, "Chat", "CPacketChatMessage");
|
||||
public static final PacketType CLIENT_COMMAND = new PacketType(PROTOCOL, SENDER, 0x04, 0xFF, "ClientCommand", "CPacketClientStatus");
|
||||
public static final PacketType SETTINGS = new PacketType(PROTOCOL, SENDER, 0x05, 0xFF, "Settings", "CPacketClientSettings");
|
||||
public static final PacketType TAB_COMPLETE = new PacketType(PROTOCOL, SENDER, 0x06, 0xFF, "TabComplete", "CPacketTabComplete");
|
||||
public static final PacketType TRANSACTION = new PacketType(PROTOCOL, SENDER, 0x07, 0xFF, "Transaction", "CPacketConfirmTransaction");
|
||||
public static final PacketType ENCHANT_ITEM = new PacketType(PROTOCOL, SENDER, 0x08, 0xFF, "EnchantItem", "CPacketEnchantItem");
|
||||
public static final PacketType WINDOW_CLICK = new PacketType(PROTOCOL, SENDER, 0x09, 0xFF, "WindowClick", "CPacketClickWindow");
|
||||
public static final PacketType CLOSE_WINDOW = new PacketType(PROTOCOL, SENDER, 0x0A, 0xFF, "CloseWindow", "CPacketCloseWindow");
|
||||
public static final PacketType CUSTOM_PAYLOAD = new PacketType(PROTOCOL, SENDER, 0x0B, 0xFF, "CustomPayload", "CPacketCustomPayload");
|
||||
public static final PacketType B_EDIT = new PacketType(PROTOCOL, SENDER, 0x0C, 0xFF, "BEdit");
|
||||
public static final PacketType ENTITY_NBT_QUERY = new PacketType(PROTOCOL, SENDER, 0x0D, 0xFF, "EntityNBTQuery");
|
||||
public static final PacketType USE_ENTITY = new PacketType(PROTOCOL, SENDER, 0x0E, 0xFF, "UseEntity", "CPacketUseEntity");
|
||||
public static final PacketType KEEP_ALIVE = new PacketType(PROTOCOL, SENDER, 0x0F, 0xFF, "KeepAlive", "CPacketKeepAlive");
|
||||
public static final PacketType DIFFICULTY_LOCK = new PacketType(PROTOCOL, SENDER, 0x10, 0xFF, "DifficultyLock");
|
||||
public static final PacketType POSITION = new PacketType(PROTOCOL, SENDER, 0x11, 0xFF, "Flying$Position", "CPacketPlayer$Position");
|
||||
public static final PacketType POSITION_LOOK = new PacketType(PROTOCOL, SENDER, 0x12, 0xFF, "Flying$PositionLook", "CPacketPlayer$PositionRotation");
|
||||
public static final PacketType LOOK = new PacketType(PROTOCOL, SENDER, 0x13, 0xFF, "Flying$Look", "CPacketPlayer$Rotation");
|
||||
public static final PacketType FLYING = new PacketType(PROTOCOL, SENDER, 0x14, 0xFF, "Flying", "CPacketPlayer");
|
||||
public static final PacketType VEHICLE_MOVE = new PacketType(PROTOCOL, SENDER, 0x15, 0xFF, "VehicleMove", "CPacketVehicleMove");
|
||||
public static final PacketType BOAT_MOVE = new PacketType(PROTOCOL, SENDER, 0x16, 0xFF, "BoatMove", "CPacketSteerBoat");
|
||||
public static final PacketType PICK_ITEM = new PacketType(PROTOCOL, SENDER, 0x17, 0xFF, "PickItem");
|
||||
public static final PacketType AUTO_RECIPE = new PacketType(PROTOCOL, SENDER, 0x18, 0xFF, "AutoRecipe", "CPacketPlaceRecipe");
|
||||
public static final PacketType ABILITIES = new PacketType(PROTOCOL, SENDER, 0x19, 0xFF, "Abilities", "CPacketPlayerAbilities");
|
||||
public static final PacketType BLOCK_DIG = new PacketType(PROTOCOL, SENDER, 0x1A, 0xFF, "BlockDig", "CPacketPlayerDigging");
|
||||
public static final PacketType ENTITY_ACTION = new PacketType(PROTOCOL, SENDER, 0x1B, 0xFF, "EntityAction", "CPacketEntityAction");
|
||||
public static final PacketType STEER_VEHICLE = new PacketType(PROTOCOL, SENDER, 0x1C, 0xFF, "SteerVehicle", "CPacketInput");
|
||||
public static final PacketType RECIPE_DISPLAYED = new PacketType(PROTOCOL, SENDER, 0x1D, 0xFF, "RecipeDisplayed", "CPacketRecipeInfo");
|
||||
public static final PacketType ITEM_NAME = new PacketType(PROTOCOL, SENDER, 0x1E, 0xFF, "ItemName");
|
||||
public static final PacketType RESOURCE_PACK_STATUS = new PacketType(PROTOCOL, SENDER, 0x1F, 0xFF, "ResourcePackStatus", "CPacketResourcePackStatus");
|
||||
public static final PacketType ADVANCEMENTS = new PacketType(PROTOCOL, SENDER, 0x20, 0xFF, "Advancements", "CPacketSeenAdvancements");
|
||||
public static final PacketType TR_SEL = new PacketType(PROTOCOL, SENDER, 0x21, 0xFF, "TrSel");
|
||||
public static final PacketType BEACON = new PacketType(PROTOCOL, SENDER, 0x22, 0xFF, "Beacon");
|
||||
public static final PacketType HELD_ITEM_SLOT = new PacketType(PROTOCOL, SENDER, 0x23, 0xFF, "HeldItemSlot", "CPacketHeldItemChange");
|
||||
public static final PacketType SET_COMMAND_BLOCK = new PacketType(PROTOCOL, SENDER, 0x24, 0xFF, "SetCommandBlock");
|
||||
public static final PacketType SET_COMMAND_MINECART = new PacketType(PROTOCOL, SENDER, 0x25, 0xFF, "SetCommandMinecart");
|
||||
public static final PacketType SET_CREATIVE_SLOT = new PacketType(PROTOCOL, SENDER, 0x26, 0xFF, "SetCreativeSlot", "CPacketCreativeInventoryAction");
|
||||
public static final PacketType SET_JIGSAW = new PacketType(PROTOCOL, SENDER, 0x27, 0xFF, "SetJigsaw");
|
||||
public static final PacketType STRUCT = new PacketType(PROTOCOL, SENDER, 0x28, 0xFF, "Struct");
|
||||
public static final PacketType UPDATE_SIGN = new PacketType(PROTOCOL, SENDER, 0x29, 0xFF, "UpdateSign", "CPacketUpdateSign");
|
||||
public static final PacketType ARM_ANIMATION = new PacketType(PROTOCOL, SENDER, 0x2A, 0xFF, "ArmAnimation", "CPacketAnimation");
|
||||
public static final PacketType SPECTATE = new PacketType(PROTOCOL, SENDER, 0x2B, 0xFF, "Spectate", "CPacketSpectate");
|
||||
public static final PacketType USE_ITEM = new PacketType(PROTOCOL, SENDER, 0x2C, 0xFF, "UseItem", "CPacketPlayerTryUseItemOnBlock");
|
||||
public static final PacketType BLOCK_PLACE = new PacketType(PROTOCOL, SENDER, 0x2D, 0xFF, "BlockPlace", "CPacketPlayerTryUseItem");
|
||||
public static final PacketType TELEPORT_ACCEPT = new PacketType(PROTOCOL, SENDER, 0x00, "TeleportAccept", "CPacketConfirmTeleport");
|
||||
public static final PacketType TILE_NBT_QUERY = new PacketType(PROTOCOL, SENDER, 0x01, "TileNBTQuery");
|
||||
public static final PacketType DIFFICULTY_CHANGE = new PacketType(PROTOCOL, SENDER, 0x02, "DifficultyChange");
|
||||
public static final PacketType CHAT = new PacketType(PROTOCOL, SENDER, 0x03, "Chat", "CPacketChatMessage");
|
||||
public static final PacketType CLIENT_COMMAND = new PacketType(PROTOCOL, SENDER, 0x04, "ClientCommand", "CPacketClientStatus");
|
||||
public static final PacketType SETTINGS = new PacketType(PROTOCOL, SENDER, 0x05, "Settings", "CPacketClientSettings");
|
||||
public static final PacketType TAB_COMPLETE = new PacketType(PROTOCOL, SENDER, 0x06, "TabComplete", "CPacketTabComplete");
|
||||
public static final PacketType TRANSACTION = new PacketType(PROTOCOL, SENDER, 0x07, "Transaction", "CPacketConfirmTransaction");
|
||||
public static final PacketType ENCHANT_ITEM = new PacketType(PROTOCOL, SENDER, 0x08, "EnchantItem", "CPacketEnchantItem");
|
||||
public static final PacketType WINDOW_CLICK = new PacketType(PROTOCOL, SENDER, 0x09, "WindowClick", "CPacketClickWindow");
|
||||
public static final PacketType CLOSE_WINDOW = new PacketType(PROTOCOL, SENDER, 0x0A, "CloseWindow", "CPacketCloseWindow");
|
||||
public static final PacketType CUSTOM_PAYLOAD = new PacketType(PROTOCOL, SENDER, 0x0B, "CustomPayload", "CPacketCustomPayload");
|
||||
public static final PacketType B_EDIT = new PacketType(PROTOCOL, SENDER, 0x0C, "BEdit");
|
||||
public static final PacketType ENTITY_NBT_QUERY = new PacketType(PROTOCOL, SENDER, 0x0D, "EntityNBTQuery");
|
||||
public static final PacketType USE_ENTITY = new PacketType(PROTOCOL, SENDER, 0x0E, "UseEntity", "CPacketUseEntity");
|
||||
public static final PacketType JIGSAW_GENERATE = new PacketType(PROTOCOL, SENDER, 0x0F, "JigsawGenerate");
|
||||
public static final PacketType KEEP_ALIVE = new PacketType(PROTOCOL, SENDER, 0x10, "KeepAlive", "CPacketKeepAlive");
|
||||
public static final PacketType DIFFICULTY_LOCK = new PacketType(PROTOCOL, SENDER, 0x11, "DifficultyLock");
|
||||
public static final PacketType POSITION = new PacketType(PROTOCOL, SENDER, 0x12, "Flying$Position", "CPacketPlayer$Position");
|
||||
public static final PacketType POSITION_LOOK = new PacketType(PROTOCOL, SENDER, 0x13, "Flying$PositionLook", "CPacketPlayer$PositionRotation");
|
||||
public static final PacketType LOOK = new PacketType(PROTOCOL, SENDER, 0x14, "Flying$Look", "CPacketPlayer$Rotation");
|
||||
public static final PacketType FLYING = new PacketType(PROTOCOL, SENDER, 0x15, "Flying", "CPacketPlayer");
|
||||
public static final PacketType VEHICLE_MOVE = new PacketType(PROTOCOL, SENDER, 0x16, "VehicleMove", "CPacketVehicleMove");
|
||||
public static final PacketType BOAT_MOVE = new PacketType(PROTOCOL, SENDER, 0x17, "BoatMove", "CPacketSteerBoat");
|
||||
public static final PacketType PICK_ITEM = new PacketType(PROTOCOL, SENDER, 0x18, "PickItem");
|
||||
public static final PacketType AUTO_RECIPE = new PacketType(PROTOCOL, SENDER, 0x19, "AutoRecipe", "CPacketPlaceRecipe");
|
||||
public static final PacketType ABILITIES = new PacketType(PROTOCOL, SENDER, 0x1A, "Abilities", "CPacketPlayerAbilities");
|
||||
public static final PacketType BLOCK_DIG = new PacketType(PROTOCOL, SENDER, 0x1B, "BlockDig", "CPacketPlayerDigging");
|
||||
public static final PacketType ENTITY_ACTION = new PacketType(PROTOCOL, SENDER, 0x1C, "EntityAction", "CPacketEntityAction");
|
||||
public static final PacketType STEER_VEHICLE = new PacketType(PROTOCOL, SENDER, 0x1D, "SteerVehicle", "CPacketInput");
|
||||
public static final PacketType RECIPE_DISPLAYED = new PacketType(PROTOCOL, SENDER, 0x1E, "RecipeDisplayed", "CPacketRecipeInfo");
|
||||
public static final PacketType ITEM_NAME = new PacketType(PROTOCOL, SENDER, 0x1F, "ItemName");
|
||||
public static final PacketType RESOURCE_PACK_STATUS = new PacketType(PROTOCOL, SENDER, 0x20, "ResourcePackStatus", "CPacketResourcePackStatus");
|
||||
public static final PacketType ADVANCEMENTS = new PacketType(PROTOCOL, SENDER, 0x21, "Advancements", "CPacketSeenAdvancements");
|
||||
public static final PacketType TR_SEL = new PacketType(PROTOCOL, SENDER, 0x22, "TrSel");
|
||||
public static final PacketType BEACON = new PacketType(PROTOCOL, SENDER, 0x23, "Beacon");
|
||||
public static final PacketType HELD_ITEM_SLOT = new PacketType(PROTOCOL, SENDER, 0x24, "HeldItemSlot", "CPacketHeldItemChange");
|
||||
public static final PacketType SET_COMMAND_BLOCK = new PacketType(PROTOCOL, SENDER, 0x25, "SetCommandBlock");
|
||||
public static final PacketType SET_COMMAND_MINECART = new PacketType(PROTOCOL, SENDER, 0x26, "SetCommandMinecart");
|
||||
public static final PacketType SET_CREATIVE_SLOT = new PacketType(PROTOCOL, SENDER, 0x27, "SetCreativeSlot", "CPacketCreativeInventoryAction");
|
||||
public static final PacketType SET_JIGSAW = new PacketType(PROTOCOL, SENDER, 0x28, "SetJigsaw");
|
||||
public static final PacketType STRUCT = new PacketType(PROTOCOL, SENDER, 0x29, "Struct");
|
||||
public static final PacketType UPDATE_SIGN = new PacketType(PROTOCOL, SENDER, 0x2A, "UpdateSign", "CPacketUpdateSign");
|
||||
public static final PacketType ARM_ANIMATION = new PacketType(PROTOCOL, SENDER, 0x2B, "ArmAnimation", "CPacketAnimation");
|
||||
public static final PacketType SPECTATE = new PacketType(PROTOCOL, SENDER, 0x2C, "Spectate", "CPacketSpectate");
|
||||
public static final PacketType USE_ITEM = new PacketType(PROTOCOL, SENDER, 0x2D, "UseItem", "CPacketPlayerTryUseItemOnBlock");
|
||||
public static final PacketType BLOCK_PLACE = new PacketType(PROTOCOL, SENDER, 0x2E, "BlockPlace", "CPacketPlayerTryUseItem");
|
||||
|
||||
private final static Client INSTANCE = new Client();
|
||||
|
||||
@ -365,8 +371,8 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
private final static Sender SENDER = Sender.SERVER;
|
||||
|
||||
@ForceAsync
|
||||
public static final PacketType SERVER_INFO = new PacketType(PROTOCOL, SENDER, 0x00, 0xFF, "ServerInfo", "SPacketServerInfo");
|
||||
public static final PacketType PONG = new PacketType(PROTOCOL, SENDER, 0x01, 0xFF, "Pong", "SPacketPong");
|
||||
public static final PacketType SERVER_INFO = new PacketType(PROTOCOL, SENDER, 0x00, "ServerInfo", "SPacketServerInfo");
|
||||
public static final PacketType PONG = new PacketType(PROTOCOL, SENDER, 0x01, "Pong", "SPacketPong");
|
||||
|
||||
/**
|
||||
* @deprecated Renamed to {@link #SERVER_INFO}
|
||||
@ -395,8 +401,8 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
public static class Client extends PacketTypeEnum {
|
||||
private final static Sender SENDER = Sender.CLIENT;
|
||||
|
||||
public static final PacketType START = new PacketType(PROTOCOL, SENDER, 0x00, 0xFF, "Start", "CPacketServerQuery");
|
||||
public static final PacketType PING = new PacketType(PROTOCOL, SENDER, 0x01, 0xFF, "Ping", "CPacketPing");
|
||||
public static final PacketType START = new PacketType(PROTOCOL, SENDER, 0x00, "Start", "CPacketServerQuery");
|
||||
public static final PacketType PING = new PacketType(PROTOCOL, SENDER, 0x01, "Ping", "CPacketPing");
|
||||
|
||||
private final static Client INSTANCE = new Client();
|
||||
|
||||
@ -430,11 +436,11 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
public static class Server extends PacketTypeEnum {
|
||||
private final static Sender SENDER = Sender.SERVER;
|
||||
|
||||
public static final PacketType DISCONNECT = new PacketType(PROTOCOL, SENDER, 0x00, 0xFF, "Disconnect", "SPacketDisconnect");
|
||||
public static final PacketType ENCRYPTION_BEGIN = new PacketType(PROTOCOL, SENDER, 0x01, 0xFF, "EncryptionBegin", "SPacketEncryptionRequest");
|
||||
public static final PacketType SUCCESS = new PacketType(PROTOCOL, SENDER, 0x02, 0xFF, "Success", "SPacketLoginSuccess");
|
||||
public static final PacketType SET_COMPRESSION = new PacketType(PROTOCOL, SENDER, 0x03, 0xFF, "SetCompression", "SPacketEnableCompression");
|
||||
public static final PacketType CUSTOM_PAYLOAD = new PacketType(PROTOCOL, SENDER, 0x04, 0xFF, "CustomPayload", "SPacketCustomPayload");
|
||||
public static final PacketType DISCONNECT = new PacketType(PROTOCOL, SENDER, 0x00, "Disconnect", "SPacketDisconnect");
|
||||
public static final PacketType ENCRYPTION_BEGIN = new PacketType(PROTOCOL, SENDER, 0x01, "EncryptionBegin", "SPacketEncryptionRequest");
|
||||
public static final PacketType SUCCESS = new PacketType(PROTOCOL, SENDER, 0x02, "Success", "SPacketLoginSuccess");
|
||||
public static final PacketType SET_COMPRESSION = new PacketType(PROTOCOL, SENDER, 0x03, "SetCompression", "SPacketEnableCompression");
|
||||
public static final PacketType CUSTOM_PAYLOAD = new PacketType(PROTOCOL, SENDER, 0x04, "CustomPayload", "SPacketCustomPayload");
|
||||
|
||||
private final static Server INSTANCE = new Server();
|
||||
|
||||
@ -456,86 +462,9 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
public static class Client extends PacketTypeEnum {
|
||||
private final static Sender SENDER = Sender.CLIENT;
|
||||
|
||||
public static final PacketType START = new PacketType(PROTOCOL, SENDER, 0x00, 0xFF, "Start", "CPacketLoginStart");
|
||||
public static final PacketType ENCRYPTION_BEGIN = new PacketType(PROTOCOL, SENDER, 0x01, 0xFF, "EncryptionBegin", "CPacketEncryptionResponse");
|
||||
public static final PacketType CUSTOM_PAYLOAD = new PacketType(PROTOCOL, SENDER, 0x02, 0xFF, "CustomPayload", "CPacketCustomPayload");
|
||||
|
||||
private final static Client INSTANCE = new Client();
|
||||
|
||||
// Prevent accidental construction
|
||||
private Client() { super(); }
|
||||
|
||||
public static Sender getSender() {
|
||||
return SENDER;
|
||||
}
|
||||
public static Client getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
public static Protocol getProtocol() {
|
||||
return PROTOCOL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains every packet Minecraft 1.6.4 packet removed in Minecraft 1.7.2.
|
||||
* @author Kristian
|
||||
*/
|
||||
public static class Legacy {
|
||||
private static final Protocol PROTOCOL = Protocol.LEGACY;
|
||||
|
||||
/**
|
||||
* Outgoing packets.
|
||||
* @author Kristian
|
||||
*/
|
||||
// Missing server packets: [10, 11, 12, 21, 107, 252]
|
||||
public static class Server extends PacketTypeEnum {
|
||||
private final static Sender SENDER = Sender.SERVER;
|
||||
|
||||
public static final PacketType PLAYER_FLYING = PacketType.newLegacy(SENDER, 10);
|
||||
public static final PacketType PLAYER_POSITION = PacketType.newLegacy(SENDER, 11);
|
||||
public static final PacketType PLAYER_POSITON_LOOK = PacketType.newLegacy(SENDER, 12);
|
||||
/**
|
||||
* Removed in Minecraft 1.4.6.
|
||||
*/
|
||||
public static final PacketType PICKUP_SPAWN = PacketType.newLegacy(SENDER, 21);
|
||||
/**
|
||||
* Removed in Minecraft 1.7.2
|
||||
*/
|
||||
public static final PacketType SET_CREATIVE_SLOT = PacketType.newLegacy(SENDER, 107);
|
||||
|
||||
/**
|
||||
* Removed in Minecraft 1.7.2
|
||||
*/
|
||||
public static final PacketType KEY_RESPONSE = PacketType.newLegacy(SENDER, 252);
|
||||
|
||||
private final static Server INSTANCE = new Server();
|
||||
|
||||
// Prevent accidental construction
|
||||
private Server() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static Sender getSender() {
|
||||
return SENDER;
|
||||
}
|
||||
public static Server getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Incoming packets.
|
||||
* @author Kristian
|
||||
*/
|
||||
// Missing client packets: [1, 9, 255]
|
||||
public static class Client extends PacketTypeEnum {
|
||||
private final static Sender SENDER = Sender.CLIENT;
|
||||
|
||||
public static final PacketType LOGIN = PacketType.newLegacy(SENDER, 1);
|
||||
public static final PacketType RESPAWN = PacketType.newLegacy(SENDER, 9);
|
||||
public static final PacketType DISCONNECT = PacketType.newLegacy(SENDER, 255);
|
||||
public static final PacketType START = new PacketType(PROTOCOL, SENDER, 0x00, "Start", "CPacketLoginStart");
|
||||
public static final PacketType ENCRYPTION_BEGIN = new PacketType(PROTOCOL, SENDER, 0x01, "EncryptionBegin", "CPacketEncryptionResponse");
|
||||
public static final PacketType CUSTOM_PAYLOAD = new PacketType(PROTOCOL, SENDER, 0x02, "CustomPayload", "CPacketCustomPayload");
|
||||
|
||||
private final static Client INSTANCE = new Client();
|
||||
|
||||
@ -644,12 +573,11 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
/**
|
||||
* Protocol version of all the current IDs.
|
||||
*/
|
||||
private static final MinecraftVersion PROTOCOL_VERSION = MinecraftVersion.VILLAGE_UPDATE;
|
||||
private static final MinecraftVersion PROTOCOL_VERSION = MinecraftVersion.NETHER_UPDATE;
|
||||
|
||||
private final Protocol protocol;
|
||||
private final Sender sender;
|
||||
private final int currentId;
|
||||
private final int legacyId;
|
||||
private final MinecraftVersion version;
|
||||
private final String[] classNames;
|
||||
String[] names;
|
||||
@ -675,9 +603,7 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
addPacketTypes(Status.Client.getInstance()).
|
||||
addPacketTypes(Status.Server.getInstance()).
|
||||
addPacketTypes(Login.Client.getInstance()).
|
||||
addPacketTypes(Login.Server.getInstance()).
|
||||
addPacketTypes(Legacy.Client.getInstance()).
|
||||
addPacketTypes(Legacy.Server.getInstance());
|
||||
addPacketTypes(Login.Server.getInstance());
|
||||
}
|
||||
return LOOKUP;
|
||||
}
|
||||
@ -697,11 +623,6 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
sources.add(Login.Client.getInstance());
|
||||
sources.add(Login.Server.getInstance());
|
||||
|
||||
// Add the missing types in earlier versions
|
||||
if (!MinecraftReflection.isUsingNetty()) {
|
||||
sources.add(Legacy.Client.getInstance());
|
||||
sources.add(Legacy.Server.getInstance());
|
||||
}
|
||||
return Iterables.concat(sources);
|
||||
}
|
||||
|
||||
@ -824,31 +745,6 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
return getLookup().getFromCurrent(protocol, sender, packetId) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a packet type from a legacy ID.
|
||||
* <p>
|
||||
* If no associated packet type could be found, a new will be registered under LEGACY.
|
||||
* @param id - the legacy ID.
|
||||
* @param sender - the sender of the packet, or NULL if unknown.
|
||||
* @return The packet type.
|
||||
* @throws IllegalArgumentException If the sender is NULL and the packet doesn't exist.
|
||||
* @deprecated Legacy IDs haven't functioned properly for some time
|
||||
*/
|
||||
@Deprecated
|
||||
public static PacketType fromLegacy(int id, Sender sender) {
|
||||
PacketType type = getLookup().getFromLegacy(id, sender);
|
||||
|
||||
if (type == null) {
|
||||
if (sender == null)
|
||||
throw new IllegalArgumentException("Cannot find legacy packet " + id);
|
||||
type = newLegacy(sender, id);
|
||||
|
||||
// As below
|
||||
scheduleRegister(type, "Dynamic-" + UUID.randomUUID().toString());
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a packet type from a protocol, sender and packet ID, for pre-1.8.
|
||||
* <p>
|
||||
@ -863,7 +759,7 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
PacketType type = getLookup().getFromCurrent(protocol, sender, packetId);
|
||||
|
||||
if (type == null) {
|
||||
type = new PacketType(protocol, sender, packetId, -1, PROTOCOL_VERSION, packetClass.getName());
|
||||
type = new PacketType(protocol, sender, packetId, PROTOCOL_VERSION, packetClass.getName());
|
||||
type.dynamic = true;
|
||||
|
||||
// Many may be scheduled, but only the first will be executed
|
||||
@ -894,7 +790,7 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
PacketType type = find(map, className);
|
||||
if (type == null) {
|
||||
// Guess we don't support this packet :/
|
||||
type = new PacketType(protocol, sender, packetId, -1, PROTOCOL_VERSION, className);
|
||||
type = new PacketType(protocol, sender, packetId, PROTOCOL_VERSION, className);
|
||||
type.dynamic = true;
|
||||
|
||||
// Many may be scheduled, but only the first will be executed
|
||||
@ -1006,8 +902,6 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
return type.isClient() ? Status.Client.getInstance() : Status.Server.getInstance();
|
||||
case LOGIN:
|
||||
return type.isClient() ? Login.Client.getInstance() : Login.Server.getInstance();
|
||||
case LEGACY:
|
||||
return type.isClient() ? Legacy.Client.getInstance() : Legacy.Server.getInstance();
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected protocol: " + type.getProtocol());
|
||||
}
|
||||
@ -1018,10 +912,9 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
* @param protocol - the current protocol.
|
||||
* @param sender - client or server.
|
||||
* @param currentId - the current packet ID, or
|
||||
* @param legacyId - the legacy packet ID.
|
||||
*/
|
||||
public PacketType(Protocol protocol, Sender sender, int currentId, int legacyId, String... names) {
|
||||
this(protocol, sender, currentId, legacyId, PROTOCOL_VERSION, names);
|
||||
public PacketType(Protocol protocol, Sender sender, int currentId, String... names) {
|
||||
this(protocol, sender, currentId, PROTOCOL_VERSION, names);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1029,14 +922,12 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
* @param protocol - the current protocol.
|
||||
* @param sender - client or server.
|
||||
* @param currentId - the current packet ID.
|
||||
* @param legacyId - the legacy packet ID.
|
||||
* @param version - the version of the current ID.
|
||||
*/
|
||||
public PacketType(Protocol protocol, Sender sender, int currentId, int legacyId, MinecraftVersion version, String... names) {
|
||||
public PacketType(Protocol protocol, Sender sender, int currentId, MinecraftVersion version, String... names) {
|
||||
this.protocol = Preconditions.checkNotNull(protocol, "protocol cannot be NULL");
|
||||
this.sender = Preconditions.checkNotNull(sender, "sender cannot be NULL");
|
||||
this.currentId = currentId;
|
||||
this.legacyId = legacyId;
|
||||
this.version = version;
|
||||
|
||||
this.classNames = new String[names.length];
|
||||
@ -1051,16 +942,6 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
this.names = names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a legacy packet type.
|
||||
* @param sender - client or server.
|
||||
* @param legacyId - the legacy packet ID.
|
||||
* @return Legacy packet type
|
||||
*/
|
||||
public static PacketType newLegacy(Sender sender, int legacyId) {
|
||||
return new PacketType(Protocol.LEGACY, sender, PacketType.UNKNOWN_PACKET, legacyId, MinecraftVersion.WORLD_UPDATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this packet is supported on the current server.
|
||||
* @return Whether or not the packet is supported.
|
||||
@ -1182,18 +1063,6 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the legacy (1.6.4 or below) protocol ID of the packet type.
|
||||
* <p>
|
||||
* This ID is globally unique.
|
||||
* @return The legacy ID, or {@link #UNKNOWN_PACKET} if unknown.
|
||||
* @deprecated Legacy IDs haven't functioned properly for some time
|
||||
*/
|
||||
@Deprecated
|
||||
public int getLegacyId() {
|
||||
return legacyId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not this packet was dynamically created (i.e. we don't have it registered)
|
||||
* @return True if dnyamic, false if not.
|
||||
|
@ -105,16 +105,6 @@ class PacketTypeLookup {
|
||||
Preconditions.checkNotNull(types, "types cannot be NULL");
|
||||
|
||||
for (PacketType type : types) {
|
||||
int legacy = type.getLegacyId();
|
||||
|
||||
// Skip unknown legacy packets
|
||||
if (legacy != PacketType.UNKNOWN_PACKET) {
|
||||
if (type.isServer())
|
||||
serverLookup.put(type.getLegacyId(), type);
|
||||
if (type.isClient())
|
||||
clientLookup.put(type.getLegacyId(), type);
|
||||
legacyLookup.put(type.getLegacyId(), type);
|
||||
}
|
||||
// Skip unknown current packets
|
||||
if (type.getCurrentId() != PacketType.UNKNOWN_PACKET) {
|
||||
idLookup.getMap(type.getProtocol(), type.getSender()).put(type.getCurrentId(), type);
|
||||
|
@ -38,12 +38,12 @@ public class ProtocolLibrary {
|
||||
/**
|
||||
* The maximum version ProtocolLib has been tested with.
|
||||
*/
|
||||
public static final String MAXIMUM_MINECRAFT_VERSION = "1.15.1";
|
||||
public static final String MAXIMUM_MINECRAFT_VERSION = "1.16.1";
|
||||
|
||||
/**
|
||||
* The date (with ISO 8601 or YYYY-MM-DD) when the most recent version (1.14.4) was released.
|
||||
* The date (with ISO 8601 or YYYY-MM-DD) when the most recent version (1.16.1) was released.
|
||||
*/
|
||||
public static final String MINECRAFT_LAST_RELEASE_DATE = "2019-12-17";
|
||||
public static final String MINECRAFT_LAST_RELEASE_DATE = "2020-06-25";
|
||||
|
||||
/**
|
||||
* Plugins that are currently incompatible with ProtocolLib.
|
||||
|
@ -77,7 +77,7 @@ public class PacketRegistry {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<Class, Integer> result = (Map) Maps.transformValues(
|
||||
NETTY.getPacketClassLookup(), type -> type.getLegacyId());
|
||||
NETTY.getPacketClassLookup(), PacketType::getCurrentId);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -159,8 +159,7 @@ public class PacketRegistry {
|
||||
try {
|
||||
clazz = MinecraftReflection.getMinecraftClass(name);
|
||||
break;
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
} catch (Exception ignored) { }
|
||||
}
|
||||
|
||||
// TODO Cache the result?
|
||||
@ -192,7 +191,7 @@ public class PacketRegistry {
|
||||
@Deprecated
|
||||
public static int getPacketID(Class<?> packet) {
|
||||
initialize();
|
||||
return NETTY.getPacketClassLookup().get(packet).getLegacyId();
|
||||
return NETTY.getPacketClassLookup().get(packet).getCurrentId();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -81,7 +81,7 @@ public class StructureModifier<TField> {
|
||||
providers.addAll(DefaultInstances.DEFAULT.getRegistered());
|
||||
return DefaultInstances.fromCollection(providers);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a structure modifier.
|
||||
* @param targetType - the structure to modify.
|
||||
|
@ -78,6 +78,10 @@ public class ImmutableDetector implements Cloner {
|
||||
|
||||
// TODO automatically detect the technically-not-an-enum enums that Mojang is so fond of
|
||||
// Would also probably go in tandem with having the FieldCloner use this
|
||||
|
||||
if (MinecraftVersion.atOrAbove(MinecraftVersion.NETHER_UPDATE)) {
|
||||
add("IRegistry");
|
||||
}
|
||||
}
|
||||
|
||||
private static void add(Supplier<Class<?>> getClass) {
|
||||
|
@ -20,6 +20,7 @@ package com.comphenix.protocol.reflect.instances;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@ -37,14 +38,16 @@ import com.google.common.collect.ImmutableList;
|
||||
*/
|
||||
public class DefaultInstances implements InstanceProvider {
|
||||
|
||||
public static final InstanceProvider UUID_GENERATOR = type -> type == UUID.class ? new UUID(0L, 0L) : null;
|
||||
|
||||
/**
|
||||
* Standard default instance provider.
|
||||
*/
|
||||
public static final DefaultInstances DEFAULT = DefaultInstances.fromArray(
|
||||
PrimitiveGenerator.INSTANCE, CollectionGenerator.INSTANCE);
|
||||
|
||||
PrimitiveGenerator.INSTANCE, CollectionGenerator.INSTANCE, UUID_GENERATOR);
|
||||
|
||||
/**
|
||||
* The maximum height of the hierachy of creates types. Used to prevent cycles.
|
||||
* The maximum height of the heirarchy of creates types. Used to prevent cycles.
|
||||
*/
|
||||
private int maximumRecursion = 20;
|
||||
|
||||
@ -272,6 +275,8 @@ public class DefaultInstances implements InstanceProvider {
|
||||
Constructor<T> minimum = getMinimumConstructor(type, providers, recursionLevel + 1);
|
||||
|
||||
// Create the type with this constructor using default values. This might fail, though.
|
||||
// TODO every packet has a zero-args constructor
|
||||
|
||||
try {
|
||||
if (minimum != null) {
|
||||
int parameterCount = minimum.getParameterTypes().length;
|
||||
|
@ -113,7 +113,7 @@ public class TimingReportGenerator {
|
||||
}
|
||||
|
||||
private String getPacketId(PacketType type) {
|
||||
return Strings.padStart(Integer.toString(type.getCurrentId()), 2, '0') + " (Legacy: " + type.getLegacyId() + ")";
|
||||
return Strings.padStart(Integer.toString(type.getCurrentId()), 2, '0');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -21,10 +21,10 @@ package com.comphenix.protocol.utility;
|
||||
*/
|
||||
|
||||
public final class Constants {
|
||||
public static final String PACKAGE_VERSION = "v1_15_R1";
|
||||
public static final String PACKAGE_VERSION = "v1_16_R1";
|
||||
public static final String NMS = "net.minecraft.server." + PACKAGE_VERSION;
|
||||
public static final String OBC = "org.bukkit.craftbukkit." + PACKAGE_VERSION;
|
||||
public static final MinecraftVersion CURRENT_VERSION = MinecraftVersion.BEE_UPDATE;
|
||||
public static final MinecraftVersion CURRENT_VERSION = MinecraftVersion.NETHER_UPDATE;
|
||||
|
||||
public static void init() {
|
||||
MinecraftReflection.setMinecraftPackage(NMS, OBC);
|
||||
|
@ -37,20 +37,38 @@ public class MinecraftProtocolVersion {
|
||||
// After Netty
|
||||
map.put(new MinecraftVersion(1, 7, 1), 4);
|
||||
map.put(new MinecraftVersion(1, 7, 6), 5);
|
||||
|
||||
map.put(new MinecraftVersion(1, 8, 0), 47);
|
||||
|
||||
map.put(new MinecraftVersion(1, 9, 0), 107);
|
||||
map.put(new MinecraftVersion(1, 9, 2), 109);
|
||||
map.put(new MinecraftVersion(1, 9, 4), 110);
|
||||
|
||||
map.put(new MinecraftVersion(1, 10, 0), 210);
|
||||
|
||||
map.put(new MinecraftVersion(1, 11, 0), 315);
|
||||
map.put(new MinecraftVersion(1, 11, 1), 316);
|
||||
|
||||
map.put(new MinecraftVersion(1, 12, 0), 335);
|
||||
map.put(new MinecraftVersion(1, 12, 1), 338);
|
||||
map.put(new MinecraftVersion(1, 12, 2), 340);
|
||||
|
||||
map.put(new MinecraftVersion(1, 13, 0), 393);
|
||||
map.put(new MinecraftVersion(1, 13, 1), 401);
|
||||
map.put(new MinecraftVersion(1, 13, 2), 404);
|
||||
|
||||
map.put(new MinecraftVersion(1, 14, 0), 477);
|
||||
map.put(new MinecraftVersion(1, 14, 1), 480);
|
||||
map.put(new MinecraftVersion(1, 14, 2), 485);
|
||||
map.put(new MinecraftVersion(1, 14, 3), 490);
|
||||
map.put(new MinecraftVersion(1, 14, 4), 498);
|
||||
|
||||
map.put(new MinecraftVersion(1, 15, 0), 573);
|
||||
map.put(new MinecraftVersion(1, 15, 1), 575);
|
||||
map.put(new MinecraftVersion(1, 15, 2), 578);
|
||||
|
||||
map.put(new MinecraftVersion(1, 16, 0), 735);
|
||||
map.put(new MinecraftVersion(1, 16, 1), 736);
|
||||
return map;
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,12 @@ public class MinecraftVersion implements Comparable<MinecraftVersion>, Serializa
|
||||
private static final Pattern VERSION_PATTERN = Pattern.compile(".*\\(.*MC.\\s*([a-zA-z0-9\\-.]+).*");
|
||||
|
||||
/**
|
||||
* Version 1.15 - the bee upate
|
||||
* Version 1.16 - the nether update
|
||||
*/
|
||||
public static final MinecraftVersion NETHER_UPDATE = new MinecraftVersion("1.16");
|
||||
|
||||
/**
|
||||
* Version 1.15 - the bee update
|
||||
*/
|
||||
public static final MinecraftVersion BEE_UPDATE = new MinecraftVersion("1.15");
|
||||
|
||||
|
@ -98,8 +98,8 @@ public class AutoWrapper<T> implements EquivalentConverter<T> {
|
||||
value = wrappers.get(i).apply(value);
|
||||
|
||||
wrapperField.set(instance, value);
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
throw new InvalidWrapperException("Failed to wrap field", ex);
|
||||
} catch (Exception ex) {
|
||||
throw new InvalidWrapperException("Failed to wrap field at index " + i, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,8 +61,10 @@ import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import static com.comphenix.protocol.utility.MinecraftReflection.*;
|
||||
import static com.comphenix.protocol.wrappers.Converters.*;
|
||||
import static com.comphenix.protocol.utility.MinecraftReflection.getCraftBukkitClass;
|
||||
import static com.comphenix.protocol.utility.MinecraftReflection.getMinecraftClass;
|
||||
import static com.comphenix.protocol.wrappers.Converters.handle;
|
||||
import static com.comphenix.protocol.wrappers.Converters.ignoreNull;
|
||||
|
||||
/**
|
||||
* Contains several useful equivalent converters for normal Bukkit types.
|
||||
|
@ -1,35 +1,58 @@
|
||||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import java.util.*;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
|
||||
import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
import com.comphenix.protocol.wrappers.collection.CachedSet;
|
||||
import com.comphenix.protocol.wrappers.collection.ConvertedSet;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a single attribute sent in packet 44.
|
||||
* @author Kristian
|
||||
*/
|
||||
public class WrappedAttribute extends AbstractWrapper {
|
||||
public static boolean KEY_WRAPPED = MinecraftVersion.NETHER_UPDATE.atOrAbove();
|
||||
|
||||
// Shared structure modifier
|
||||
private static StructureModifier<Object> ATTRIBUTE_MODIFIER;
|
||||
|
||||
// The one constructor
|
||||
private static Constructor<?> ATTRIBUTE_CONSTRUCTOR;
|
||||
|
||||
private static Object REGISTRY = null;
|
||||
private static MethodAccessor REGISTRY_GET = null;
|
||||
|
||||
private static final Map<String, String> REMAP;
|
||||
|
||||
static {
|
||||
Map<String, String> remap = new HashMap<>();
|
||||
remap.put("generic.maxHealth", "generic.max_health");
|
||||
remap.put("generic.followRange", "generic.follow_range");
|
||||
remap.put("generic.knockbackResistance", "generic.knockback_resistance");
|
||||
remap.put("generic.movementSpeed", "generic.movement_speed");
|
||||
remap.put("generic.attackDamage", "generic.attack_damage");
|
||||
remap.put("generic.attackSpeed", "generic.attack_speed");
|
||||
remap.put("generic.armorToughness", "generic.armor_toughness");
|
||||
remap.put("generic.attackKnockback", "generic.attack_knockback");
|
||||
remap.put("horse.jumpStrength", "horse.jump_strength");
|
||||
remap.put("zombie.spawnReinforcements", "zombie.spawn_reinforcements");
|
||||
REMAP = ImmutableMap.copyOf(remap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reference to the underlying attribute snapshot.
|
||||
@ -85,7 +108,19 @@ public class WrappedAttribute extends AbstractWrapper {
|
||||
public static Builder newBuilder(@Nonnull WrappedAttribute template) {
|
||||
return new Builder(Preconditions.checkNotNull(template, "template cannot be NULL."));
|
||||
}
|
||||
|
||||
|
||||
public static class WrappedAttributeBase {
|
||||
public double defaultValue;
|
||||
public boolean unknown;
|
||||
public String key;
|
||||
}
|
||||
|
||||
private static final Class<?> ATTRIBUTE_BASE_CLASS = MinecraftReflection.getNullableNMS("AttributeBase");
|
||||
|
||||
private static final AutoWrapper<WrappedAttributeBase> ATTRIBUTE_BASE = AutoWrapper.wrap(
|
||||
WrappedAttributeBase.class, ATTRIBUTE_BASE_CLASS
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve the unique attribute key that identifies its function.
|
||||
* <p>
|
||||
@ -93,7 +128,21 @@ public class WrappedAttribute extends AbstractWrapper {
|
||||
* @return The attribute key.
|
||||
*/
|
||||
public String getAttributeKey() {
|
||||
return (String) modifier.withType(String.class).read(0);
|
||||
if (KEY_WRAPPED) {
|
||||
WrappedAttributeBase base = modifier.withType(ATTRIBUTE_BASE_CLASS, ATTRIBUTE_BASE).read(0);
|
||||
return base.key.replace("attribute.name.", ""); // TODO not entirely sure why this happens
|
||||
} else {
|
||||
return (String) modifier.withType(String.class).read(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the attribute base instance. New in 1.16.
|
||||
*
|
||||
* @return The attribute base
|
||||
*/
|
||||
public WrappedAttributeBase getBase() {
|
||||
return modifier.withType(WrappedAttributeBase.class, ATTRIBUTE_BASE).readSafely(0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -372,18 +421,43 @@ public class WrappedAttribute extends AbstractWrapper {
|
||||
|
||||
// Retrieve the correct constructor
|
||||
if (ATTRIBUTE_CONSTRUCTOR == null) {
|
||||
ATTRIBUTE_CONSTRUCTOR = FuzzyReflection.fromClass(MinecraftReflection.getAttributeSnapshotClass(), true).getConstructor(
|
||||
FuzzyMethodContract.newBuilder().parameterCount(4).
|
||||
parameterDerivedOf(MinecraftReflection.getPacketClass(), 0).
|
||||
parameterExactType(String.class, 1).
|
||||
parameterExactType(double.class, 2).
|
||||
parameterDerivedOf(Collection.class, 3).
|
||||
build()
|
||||
);
|
||||
ATTRIBUTE_CONSTRUCTOR = FuzzyReflection.fromClass(MinecraftReflection.getAttributeSnapshotClass(), true)
|
||||
.getConstructor(FuzzyMethodContract.newBuilder().parameterCount(4)
|
||||
.parameterDerivedOf(MinecraftReflection.getPacketClass(), 0)
|
||||
.parameterExactType(double.class, 2).parameterDerivedOf(Collection.class, 3)
|
||||
.build()
|
||||
);
|
||||
// Just in case
|
||||
ATTRIBUTE_CONSTRUCTOR.setAccessible(true);
|
||||
}
|
||||
|
||||
Object attributeKey;
|
||||
if (KEY_WRAPPED) {
|
||||
if (REGISTRY == null) {
|
||||
Class<?> iRegistry = MinecraftReflection.getMinecraftClass("IRegistry");
|
||||
try {
|
||||
REGISTRY = iRegistry.getDeclaredField("ATTRIBUTE").get(null);
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
throw new RuntimeException("Failed to obtain ATTRIBUTE registry", ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (REGISTRY_GET == null) {
|
||||
Class<?> keyClass = MinecraftReflection.getMinecraftKeyClass();
|
||||
REGISTRY_GET = Accessors.getMethodAccessor(REGISTRY.getClass(), "get", keyClass);
|
||||
}
|
||||
|
||||
String strKey = REMAP.getOrDefault(this.attributeKey, this.attributeKey);
|
||||
Object key = MinecraftKey.getConverter().getGeneric(new MinecraftKey(strKey));
|
||||
attributeKey = REGISTRY_GET.invoke(REGISTRY, key);
|
||||
|
||||
if (attributeKey == null) {
|
||||
throw new IllegalArgumentException("Invalid attribute name: " + this.attributeKey);
|
||||
}
|
||||
} else {
|
||||
attributeKey = this.attributeKey;
|
||||
}
|
||||
|
||||
try {
|
||||
Object handle = ATTRIBUTE_CONSTRUCTOR.newInstance(
|
||||
packet.getHandle(),
|
||||
|
@ -319,7 +319,7 @@ public class WrappedAttributeModifier extends AbstractWrapper {
|
||||
* @return TRUE if it is, FALSE otherwise.
|
||||
*/
|
||||
public boolean isPendingSynchronization() {
|
||||
return (Boolean) modifier.withType(boolean.class).read(0);
|
||||
return (Boolean) modifier.withType(boolean.class).optionRead(0).orElse(false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,94 +1,94 @@
|
||||
package com.comphenix.protocol;
|
||||
|
||||
import com.comphenix.protocol.utility.Constants;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
|
||||
import net.minecraft.server.v1_15_R1.DispenserRegistry;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemFactory;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.util.Versioning;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Used to ensure that ProtocolLib and Bukkit is prepared to be tested.
|
||||
*
|
||||
* @author Kristian
|
||||
*/
|
||||
public class BukkitInitialization {
|
||||
private static final BukkitInitialization instance = new BukkitInitialization();
|
||||
|
||||
private BukkitInitialization() {
|
||||
System.out.println("Created new BukkitInitialization on " + Thread.currentThread().getName());
|
||||
}
|
||||
|
||||
private boolean initialized;
|
||||
private boolean packaged;
|
||||
|
||||
public static synchronized void initializePackage() {
|
||||
instance.setPackage();
|
||||
}
|
||||
|
||||
public static synchronized void initializeItemMeta() {
|
||||
instance.initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize Bukkit and ProtocolLib such that we can perfrom unit testing
|
||||
*/
|
||||
private void initialize() {
|
||||
if (!initialized) {
|
||||
// Denote that we're done
|
||||
initialized = true;
|
||||
|
||||
initializePackage();
|
||||
|
||||
try {
|
||||
LogManager.getLogger();
|
||||
} catch (Throwable ex) {
|
||||
// Happens only on my Jenkins, but if it errors here it works when it matters
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
DispenserRegistry.init();
|
||||
|
||||
// Mock the server object
|
||||
Server mockedServer = mock(Server.class);
|
||||
|
||||
when(mockedServer.getLogger()).thenReturn(java.util.logging.Logger.getLogger("Minecraft"));
|
||||
when(mockedServer.getName()).thenReturn("Mock Server");
|
||||
when(mockedServer.getVersion()).thenReturn(CraftServer.class.getPackage().getImplementationVersion());
|
||||
when(mockedServer.getBukkitVersion()).thenReturn(Versioning.getBukkitVersion());
|
||||
|
||||
when(mockedServer.getItemFactory()).thenReturn(CraftItemFactory.instance());
|
||||
when(mockedServer.isPrimaryThread()).thenReturn(true);
|
||||
|
||||
// Inject this fake server
|
||||
Bukkit.setServer(mockedServer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that package names are correctly set up.
|
||||
*/
|
||||
private void setPackage() {
|
||||
if (!packaged) {
|
||||
packaged = true;
|
||||
|
||||
try {
|
||||
LogManager.getLogger();
|
||||
} catch (Throwable ex) {
|
||||
// Happens only on my Jenkins, but if it errors here it works when it matters
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
Constants.init();
|
||||
}
|
||||
}
|
||||
package com.comphenix.protocol;
|
||||
|
||||
import com.comphenix.protocol.utility.Constants;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
|
||||
import net.minecraft.server.v1_16_R1.DispenserRegistry;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemFactory;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.util.Versioning;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Used to ensure that ProtocolLib and Bukkit is prepared to be tested.
|
||||
*
|
||||
* @author Kristian
|
||||
*/
|
||||
public class BukkitInitialization {
|
||||
private static final BukkitInitialization instance = new BukkitInitialization();
|
||||
|
||||
private BukkitInitialization() {
|
||||
System.out.println("Created new BukkitInitialization on " + Thread.currentThread().getName());
|
||||
}
|
||||
|
||||
private boolean initialized;
|
||||
private boolean packaged;
|
||||
|
||||
public static synchronized void initializePackage() {
|
||||
instance.setPackage();
|
||||
}
|
||||
|
||||
public static synchronized void initializeItemMeta() {
|
||||
instance.initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize Bukkit and ProtocolLib such that we can perfrom unit testing
|
||||
*/
|
||||
private void initialize() {
|
||||
if (!initialized) {
|
||||
// Denote that we're done
|
||||
initialized = true;
|
||||
|
||||
initializePackage();
|
||||
|
||||
try {
|
||||
LogManager.getLogger();
|
||||
} catch (Throwable ex) {
|
||||
// Happens only on my Jenkins, but if it errors here it works when it matters
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
DispenserRegistry.init();
|
||||
|
||||
// Mock the server object
|
||||
Server mockedServer = mock(Server.class);
|
||||
|
||||
when(mockedServer.getLogger()).thenReturn(java.util.logging.Logger.getLogger("Minecraft"));
|
||||
when(mockedServer.getName()).thenReturn("Mock Server");
|
||||
when(mockedServer.getVersion()).thenReturn(CraftServer.class.getPackage().getImplementationVersion());
|
||||
when(mockedServer.getBukkitVersion()).thenReturn(Versioning.getBukkitVersion());
|
||||
|
||||
when(mockedServer.getItemFactory()).thenReturn(CraftItemFactory.instance());
|
||||
when(mockedServer.isPrimaryThread()).thenReturn(true);
|
||||
|
||||
// Inject this fake server
|
||||
Bukkit.setServer(mockedServer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that package names are correctly set up.
|
||||
*/
|
||||
private void setPackage() {
|
||||
if (!packaged) {
|
||||
packaged = true;
|
||||
|
||||
try {
|
||||
LogManager.getLogger();
|
||||
} catch (Throwable ex) {
|
||||
// Happens only on my Jenkins, but if it errors here it works when it matters
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
Constants.init();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,266 +1,283 @@
|
||||
/**
|
||||
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
||||
* Copyright (C) 2016 dmulloy2
|
||||
* <p>
|
||||
* 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
|
||||
* the License, or (at your option) any later version.
|
||||
* <p>
|
||||
* 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.
|
||||
* See the GNU General Public License for more details.
|
||||
* <p>
|
||||
* 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
|
||||
* 02111-1307 USA
|
||||
*/
|
||||
package com.comphenix.protocol;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.comphenix.protocol.PacketType.Protocol;
|
||||
import com.comphenix.protocol.PacketType.Sender;
|
||||
import com.comphenix.protocol.injector.packet.PacketRegistry;
|
||||
import com.comphenix.protocol.utility.Constants;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
|
||||
import net.minecraft.server.v1_15_R1.EnumProtocol;
|
||||
import net.minecraft.server.v1_15_R1.EnumProtocolDirection;
|
||||
import net.minecraft.server.v1_15_R1.PacketLoginInStart;
|
||||
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author dmulloy2
|
||||
*/
|
||||
public class PacketTypeTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
// I'm well aware this is jank, but it does in fact work correctly and give the desired result
|
||||
PacketType.onDynamicCreate = className -> {
|
||||
throw new RuntimeException("Dynamically generated packet " + className);
|
||||
};
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void main(String[] args) throws Exception {
|
||||
Constants.init();
|
||||
|
||||
EnumProtocol[] protocols = EnumProtocol.values();
|
||||
for (EnumProtocol protocol : protocols) {
|
||||
System.out.println(WordUtils.capitalize(protocol.name().toLowerCase()));
|
||||
|
||||
Field field = EnumProtocol.class.getDeclaredField("h");
|
||||
field.setAccessible(true);
|
||||
|
||||
Map<EnumProtocolDirection, Object> map = (Map<EnumProtocolDirection, Object>) field.get(protocol);
|
||||
for (Entry<EnumProtocolDirection, Object> entry : map.entrySet()) {
|
||||
Field mapField = entry.getValue().getClass().getDeclaredField("a");
|
||||
mapField.setAccessible(true);
|
||||
|
||||
Map<Class<?>, Integer> reverseMap = (Map<Class<?>, Integer>) mapField.get(entry.getValue());
|
||||
|
||||
Map<Integer, Class<?>> treeMap = new TreeMap<>();
|
||||
for (Entry<Class<?>, Integer> entry1 : reverseMap.entrySet()) {
|
||||
treeMap.put(entry1.getValue(), entry1.getKey());
|
||||
}
|
||||
|
||||
System.out.println(" " + entry.getKey());
|
||||
for (Entry<Integer, Class<?>> entry1 : treeMap.entrySet()) {
|
||||
System.out.println(generateNewType(entry1.getKey(), entry1.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String formatHex(int dec) {
|
||||
if (dec < 0) {
|
||||
return "0xFF";
|
||||
}
|
||||
|
||||
String hex = Integer.toHexString(dec).toUpperCase();
|
||||
return "0x" + (hex.length() < 2 ? "0" : "") + hex;
|
||||
}
|
||||
|
||||
private static List<String> splitOnCaps(String string) {
|
||||
List<String> list = new ArrayList<>();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
char[] chars = string.toCharArray();
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
char c = chars[i];
|
||||
if (i != 0 && Character.isUpperCase(c)) {
|
||||
list.add(builder.toString());
|
||||
builder = new StringBuilder();
|
||||
}
|
||||
|
||||
builder.append(c);
|
||||
}
|
||||
|
||||
list.add(builder.toString());
|
||||
return list;
|
||||
}
|
||||
|
||||
private static String generateNewType(int packetId, Class<?> clazz) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("\t\t\t");
|
||||
builder.append("public static final PacketType ");
|
||||
|
||||
String fullName = clazz.getName();
|
||||
fullName = fullName.substring(fullName.lastIndexOf(".") + 1);
|
||||
|
||||
List<String> classNames = new ArrayList<>(2);
|
||||
for (String name : fullName.split("\\$")) {
|
||||
List<String> split = splitOnCaps(name);
|
||||
StringBuilder nameBuilder = new StringBuilder();
|
||||
for (int i = 3; i < split.size(); i++) {
|
||||
nameBuilder.append(split.get(i));
|
||||
}
|
||||
classNames.add(nameBuilder.toString());
|
||||
}
|
||||
|
||||
String className = classNames.get(classNames.size() - 1);
|
||||
|
||||
// Format it like SET_PROTOCOL
|
||||
StringBuilder fieldName = new StringBuilder();
|
||||
char[] chars = className.toCharArray();
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
char c = chars[i];
|
||||
if (i != 0 && Character.isUpperCase(c)) {
|
||||
fieldName.append("_");
|
||||
}
|
||||
fieldName.append(Character.toUpperCase(c));
|
||||
}
|
||||
|
||||
|
||||
|
||||
builder.append(fieldName.toString().replace("N_B_T", "NBT"));
|
||||
builder.append(" = ");
|
||||
|
||||
// Add spacing
|
||||
if (builder.length() > 65) {
|
||||
builder.append("\n");
|
||||
} else {
|
||||
while (builder.length() < 65) {
|
||||
builder.append(" ");
|
||||
}
|
||||
}
|
||||
builder.append("new ");
|
||||
builder.append("PacketType(PROTOCOL, SENDER, ");
|
||||
|
||||
int legacy = -1;
|
||||
|
||||
builder.append(formatHex(packetId));
|
||||
builder.append(", ");
|
||||
builder.append(formatHex(legacy));
|
||||
builder.append(", ");
|
||||
//if (legacy == -1) {
|
||||
// builder.append(" ");
|
||||
//}
|
||||
builder.append("\"");
|
||||
|
||||
StringBuilder nameBuilder = new StringBuilder();
|
||||
for (int i = 0; i < classNames.size(); i++) {
|
||||
if (i != 0) {
|
||||
nameBuilder.append("$");
|
||||
}
|
||||
nameBuilder.append(classNames.get(i));
|
||||
}
|
||||
|
||||
String name = nameBuilder.toString();
|
||||
builder.append(name);
|
||||
builder.append("\"");
|
||||
|
||||
List<String> aliases = aliases(clazz, name);
|
||||
if (aliases != null) {
|
||||
System.out.println("!!! Aliases found !!!");
|
||||
System.out.println(aliases);
|
||||
}
|
||||
|
||||
builder.append(");");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static List<String> aliases(Class<?> packetClass, String newName) {
|
||||
PacketType type = PacketType.fromClass(packetClass);
|
||||
if (type.names.length > 1) {
|
||||
List<String> aliases = new ArrayList<>();
|
||||
for (String alias : type.names) {
|
||||
if (!alias.equals(newName)) {
|
||||
aliases.add(alias);
|
||||
}
|
||||
}
|
||||
|
||||
return aliases;
|
||||
} else if (!type.names[0].equals(newName)) {
|
||||
return Collections.singletonList(type.names[0]);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void initializeReflection() {
|
||||
BukkitInitialization.initializePackage();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindCurrent() {
|
||||
assertEquals(PacketType.Play.Client.STEER_VEHICLE, PacketType.findCurrent(Protocol.PLAY, Sender.CLIENT, "SteerVehicle"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoginStart() {
|
||||
// This packet is critical for handleLoin
|
||||
assertEquals(PacketLoginInStart.class, PacketType.Login.Client.START.getPacketClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeprecation() {
|
||||
assertTrue("Packet isn't properly deprecated", PacketType.Status.Server.OUT_SERVER_INFO.isDeprecated());
|
||||
assertTrue("Deprecated packet isn't properly included",
|
||||
PacketRegistry.getServerPacketTypes().contains(PacketType.Status.Server.OUT_SERVER_INFO));
|
||||
assertFalse("Packet isn't properly deprecated", PacketType.Play.Server.CHAT.isDeprecated());
|
||||
assertEquals("Deprecated packets aren't equal", PacketType.Status.Server.OUT_SERVER_INFO,
|
||||
PacketType.Status.Server.SERVER_INFO);
|
||||
}
|
||||
|
||||
// TODO They rewrote EnumProtocol, so this needs to be fixed
|
||||
// I just generated the new types so everything's good there
|
||||
|
||||
// @Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void ensureTypesAreCorrect() throws Exception {
|
||||
boolean fail = false;
|
||||
|
||||
EnumProtocol[] protocols = EnumProtocol.values();
|
||||
for (EnumProtocol protocol : protocols) {
|
||||
Field field = EnumProtocol.class.getDeclaredField("h");
|
||||
field.setAccessible(true);
|
||||
|
||||
Map<EnumProtocolDirection, Map<Integer, Class<?>>> map = (Map<EnumProtocolDirection, Map<Integer, Class<?>>>) field.get(protocol);
|
||||
for (Entry<EnumProtocolDirection, Map<Integer, Class<?>>> entry : map.entrySet()) {
|
||||
Map<Integer, Class<?>> treeMap = new TreeMap<>(entry.getValue());
|
||||
for (Entry<Integer, Class<?>> entry1 : treeMap.entrySet()) {
|
||||
try {
|
||||
PacketType type = PacketType.fromClass(entry1.getValue());
|
||||
if (type.getCurrentId() != entry1.getKey())
|
||||
throw new IllegalStateException("Packet ID for " + type + " is incorrect. Expected " + entry1.getKey() + ", but got " + type.getCurrentId());
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
fail = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue("Packet type(s) were incorrect!", !fail);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
||||
* Copyright (C) 2016 dmulloy2
|
||||
* <p>
|
||||
* 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
|
||||
* the License, or (at your option) any later version.
|
||||
* <p>
|
||||
* 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.
|
||||
* See the GNU General Public License for more details.
|
||||
* <p>
|
||||
* 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
|
||||
* 02111-1307 USA
|
||||
*/
|
||||
package com.comphenix.protocol;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.comphenix.protocol.PacketType.Protocol;
|
||||
import com.comphenix.protocol.PacketType.Sender;
|
||||
import com.comphenix.protocol.injector.packet.PacketRegistry;
|
||||
import com.comphenix.protocol.utility.Constants;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
|
||||
import net.minecraft.server.v1_16_R1.EnumProtocol;
|
||||
import net.minecraft.server.v1_16_R1.EnumProtocolDirection;
|
||||
import net.minecraft.server.v1_16_R1.PacketLoginInStart;
|
||||
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author dmulloy2
|
||||
*/
|
||||
public class PacketTypeTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
// I'm well aware this is jank, but it does in fact work correctly and give the desired result
|
||||
PacketType.onDynamicCreate = className -> {
|
||||
throw new RuntimeException("Dynamically generated packet " + className);
|
||||
};
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void main(String[] args) throws Exception {
|
||||
Constants.init();
|
||||
|
||||
Set<Class<?>> allTypes = new HashSet<>();
|
||||
List<Class<?>> newTypes = new ArrayList<>();
|
||||
|
||||
EnumProtocol[] protocols = EnumProtocol.values();
|
||||
for (EnumProtocol protocol : protocols) {
|
||||
System.out.println(WordUtils.capitalize(protocol.name().toLowerCase()));
|
||||
|
||||
Field field = EnumProtocol.class.getDeclaredField("h");
|
||||
field.setAccessible(true);
|
||||
|
||||
Map<EnumProtocolDirection, Object> map = (Map<EnumProtocolDirection, Object>) field.get(protocol);
|
||||
for (Entry<EnumProtocolDirection, Object> entry : map.entrySet()) {
|
||||
Field mapField = entry.getValue().getClass().getDeclaredField("a");
|
||||
mapField.setAccessible(true);
|
||||
|
||||
Map<Class<?>, Integer> reverseMap = (Map<Class<?>, Integer>) mapField.get(entry.getValue());
|
||||
|
||||
Map<Integer, Class<?>> treeMap = new TreeMap<>();
|
||||
for (Entry<Class<?>, Integer> entry1 : reverseMap.entrySet()) {
|
||||
treeMap.put(entry1.getValue(), entry1.getKey());
|
||||
}
|
||||
|
||||
System.out.println(" " + entry.getKey());
|
||||
for (Entry<Integer, Class<?>> entry1 : treeMap.entrySet()) {
|
||||
System.out.println(generateNewType(entry1.getKey(), entry1.getValue()));
|
||||
allTypes.add(entry1.getValue());
|
||||
|
||||
try {
|
||||
PacketType.fromClass(entry1.getValue());
|
||||
} catch (Exception ex) {
|
||||
newTypes.add(entry1.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("New types: " + newTypes);
|
||||
|
||||
for (PacketType type : PacketType.values()) {
|
||||
if (type.isDeprecated()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!allTypes.contains(type.getPacketClass())) {
|
||||
System.out.println(type + " was removed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String formatHex(int dec) {
|
||||
if (dec < 0) {
|
||||
return "0xFF";
|
||||
}
|
||||
|
||||
String hex = Integer.toHexString(dec).toUpperCase();
|
||||
return "0x" + (hex.length() < 2 ? "0" : "") + hex;
|
||||
}
|
||||
|
||||
private static List<String> splitOnCaps(String string) {
|
||||
List<String> list = new ArrayList<>();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
char[] chars = string.toCharArray();
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
char c = chars[i];
|
||||
if (i != 0 && Character.isUpperCase(c)) {
|
||||
list.add(builder.toString());
|
||||
builder = new StringBuilder();
|
||||
}
|
||||
|
||||
builder.append(c);
|
||||
}
|
||||
|
||||
list.add(builder.toString());
|
||||
return list;
|
||||
}
|
||||
|
||||
private static String generateNewType(int packetId, Class<?> clazz) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("\t\t\t");
|
||||
builder.append("public static final PacketType ");
|
||||
|
||||
String fullName = clazz.getName();
|
||||
fullName = fullName.substring(fullName.lastIndexOf(".") + 1);
|
||||
|
||||
List<String> classNames = new ArrayList<>(2);
|
||||
for (String name : fullName.split("\\$")) {
|
||||
List<String> split = splitOnCaps(name);
|
||||
StringBuilder nameBuilder = new StringBuilder();
|
||||
for (int i = 3; i < split.size(); i++) {
|
||||
nameBuilder.append(split.get(i));
|
||||
}
|
||||
classNames.add(nameBuilder.toString());
|
||||
}
|
||||
|
||||
String className = classNames.get(classNames.size() - 1);
|
||||
|
||||
// Format it like SET_PROTOCOL
|
||||
StringBuilder fieldName = new StringBuilder();
|
||||
char[] chars = className.toCharArray();
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
char c = chars[i];
|
||||
if (i != 0 && Character.isUpperCase(c)) {
|
||||
fieldName.append("_");
|
||||
}
|
||||
fieldName.append(Character.toUpperCase(c));
|
||||
}
|
||||
|
||||
builder.append(fieldName.toString().replace("N_B_T", "NBT"));
|
||||
builder.append(" = ");
|
||||
|
||||
// Add spacing
|
||||
if (builder.length() > 65) {
|
||||
builder.append("\n");
|
||||
} else {
|
||||
while (builder.length() < 65) {
|
||||
builder.append(" ");
|
||||
}
|
||||
}
|
||||
builder.append("new ");
|
||||
builder.append("PacketType(PROTOCOL, SENDER, ");
|
||||
|
||||
builder.append(formatHex(packetId));
|
||||
builder.append(", ");
|
||||
|
||||
StringBuilder nameBuilder = new StringBuilder();
|
||||
for (int i = 0; i < classNames.size(); i++) {
|
||||
if (i != 0) {
|
||||
nameBuilder.append("$");
|
||||
}
|
||||
nameBuilder.append(classNames.get(i));
|
||||
}
|
||||
|
||||
String name = nameBuilder.toString();
|
||||
String namesArg = listToString(getAllNames(clazz, name));
|
||||
|
||||
builder.append(namesArg);
|
||||
builder.append(");");
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static List<String> getAllNames(Class<?> packetClass, String newName) {
|
||||
List<String> names = new ArrayList<>();
|
||||
names.add(newName);
|
||||
|
||||
try {
|
||||
PacketType type = PacketType.fromClass(packetClass);
|
||||
for (String alias : type.names) {
|
||||
if (!names.contains(alias)) {
|
||||
names.add(alias);
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) { }
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
private static String listToString(List<String> list) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
if (i != 0) {
|
||||
builder.append(", ");
|
||||
}
|
||||
builder.append("\"").append(list.get(i)).append("\"");
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void initializeReflection() {
|
||||
BukkitInitialization.initializePackage();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindCurrent() {
|
||||
assertEquals(PacketType.Play.Client.STEER_VEHICLE, PacketType.findCurrent(Protocol.PLAY, Sender.CLIENT, "SteerVehicle"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoginStart() {
|
||||
// This packet is critical for handleLoin
|
||||
assertEquals(PacketLoginInStart.class, PacketType.Login.Client.START.getPacketClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeprecation() {
|
||||
assertTrue("Packet isn't properly deprecated", PacketType.Status.Server.OUT_SERVER_INFO.isDeprecated());
|
||||
assertTrue("Deprecated packet isn't properly included",
|
||||
PacketRegistry.getServerPacketTypes().contains(PacketType.Status.Server.OUT_SERVER_INFO));
|
||||
assertFalse("Packet isn't properly deprecated", PacketType.Play.Server.CHAT.isDeprecated());
|
||||
assertEquals("Deprecated packets aren't equal", PacketType.Status.Server.OUT_SERVER_INFO,
|
||||
PacketType.Status.Server.SERVER_INFO);
|
||||
}
|
||||
|
||||
// TODO They rewrote EnumProtocol, so this needs to be fixed
|
||||
// I just generated the new types so everything's good there
|
||||
|
||||
// @Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void ensureTypesAreCorrect() throws Exception {
|
||||
boolean fail = false;
|
||||
|
||||
EnumProtocol[] protocols = EnumProtocol.values();
|
||||
for (EnumProtocol protocol : protocols) {
|
||||
Field field = EnumProtocol.class.getDeclaredField("h");
|
||||
field.setAccessible(true);
|
||||
|
||||
Map<EnumProtocolDirection, Map<Integer, Class<?>>> map = (Map<EnumProtocolDirection, Map<Integer, Class<?>>>) field.get(protocol);
|
||||
for (Entry<EnumProtocolDirection, Map<Integer, Class<?>>> entry : map.entrySet()) {
|
||||
Map<Integer, Class<?>> treeMap = new TreeMap<>(entry.getValue());
|
||||
for (Entry<Integer, Class<?>> entry1 : treeMap.entrySet()) {
|
||||
try {
|
||||
PacketType type = PacketType.fromClass(entry1.getValue());
|
||||
if (type.getCurrentId() != entry1.getKey())
|
||||
throw new IllegalStateException("Packet ID for " + type + " is incorrect. Expected " + entry1.getKey() + ", but got " + type.getCurrentId());
|
||||
} catch (Throwable ex) {
|
||||
ex.printStackTrace();
|
||||
fail = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue("Packet type(s) were incorrect!", !fail);
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -3,16 +3,16 @@ package com.comphenix.protocol.injector;
|
||||
import com.comphenix.protocol.BukkitInitialization;
|
||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
|
||||
import net.minecraft.server.v1_15_R1.ChunkProviderServer;
|
||||
import net.minecraft.server.v1_15_R1.Entity;
|
||||
import net.minecraft.server.v1_15_R1.PlayerChunkMap;
|
||||
import net.minecraft.server.v1_15_R1.PlayerChunkMap.EntityTracker;
|
||||
import net.minecraft.server.v1_15_R1.WorldServer;
|
||||
import net.minecraft.server.v1_16_R1.ChunkProviderServer;
|
||||
import net.minecraft.server.v1_16_R1.Entity;
|
||||
import net.minecraft.server.v1_16_R1.PlayerChunkMap;
|
||||
import net.minecraft.server.v1_16_R1.PlayerChunkMap.EntityTracker;
|
||||
import net.minecraft.server.v1_16_R1.WorldServer;
|
||||
|
||||
import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -3,6 +3,8 @@
|
||||
*/
|
||||
package com.comphenix.protocol.injector;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@ -31,6 +33,7 @@ public class WirePacketTest {
|
||||
public void testPackets() {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.CHAT);
|
||||
packet.getChatTypes().write(0, ChatType.CHAT);
|
||||
packet.getUUIDs().write(0, new UUID(0L, 0L));
|
||||
|
||||
WirePacket wire = WirePacket.fromPacket(packet);
|
||||
WirePacket handle = WirePacket.fromPacket(packet.getHandle());
|
||||
|
@ -1,47 +1,47 @@
|
||||
package com.comphenix.protocol.reflect.cloning;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.server.v1_15_R1.ItemStack;
|
||||
import net.minecraft.server.v1_15_R1.NonNullList;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.comphenix.protocol.BukkitInitialization;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
|
||||
public class AggregateClonerTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void initializeBukkit() {
|
||||
BukkitInitialization.initializePackage();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrays() {
|
||||
List<Integer> input = Arrays.asList(1, 2, 3);
|
||||
assertEquals(input, AggregateCloner.DEFAULT.clone(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonNullList() {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.WINDOW_ITEMS);
|
||||
|
||||
NonNullList<ItemStack> list = NonNullList.a(16, ItemStack.a);
|
||||
packet.getModifier().write(1, list);
|
||||
|
||||
PacketContainer cloned = packet.deepClone();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
NonNullList<ItemStack> list1 = (NonNullList<ItemStack>) cloned.getModifier().read(1);
|
||||
|
||||
assertEquals(list.size(), list1.size());
|
||||
assertArrayEquals(list.toArray(), list1.toArray());
|
||||
}
|
||||
}
|
||||
package com.comphenix.protocol.reflect.cloning;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.server.v1_16_R1.ItemStack;
|
||||
import net.minecraft.server.v1_16_R1.NonNullList;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.comphenix.protocol.BukkitInitialization;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
|
||||
public class AggregateClonerTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void initializeBukkit() {
|
||||
BukkitInitialization.initializePackage();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrays() {
|
||||
List<Integer> input = Arrays.asList(1, 2, 3);
|
||||
assertEquals(input, AggregateCloner.DEFAULT.clone(input));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonNullList() {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.WINDOW_ITEMS);
|
||||
|
||||
NonNullList<ItemStack> list = NonNullList.a(16, ItemStack.b);
|
||||
packet.getModifier().write(1, list);
|
||||
|
||||
PacketContainer cloned = packet.deepClone();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
NonNullList<ItemStack> list1 = (NonNullList<ItemStack>) cloned.getModifier().read(1);
|
||||
|
||||
assertEquals(list.size(), list1.size());
|
||||
assertArrayEquals(list.toArray(), list1.toArray());
|
||||
}
|
||||
}
|
||||
|
@ -6,22 +6,22 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import net.minecraft.server.v1_15_R1.ChatComponentText;
|
||||
import net.minecraft.server.v1_15_R1.ChunkCoordIntPair;
|
||||
import net.minecraft.server.v1_15_R1.DataWatcher;
|
||||
import net.minecraft.server.v1_15_R1.IBlockData;
|
||||
import net.minecraft.server.v1_15_R1.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_15_R1.IChatBaseComponent.ChatSerializer;
|
||||
import net.minecraft.server.v1_15_R1.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_15_R1.PacketPlayOutUpdateAttributes.AttributeSnapshot;
|
||||
import net.minecraft.server.v1_15_R1.PlayerConnection;
|
||||
import net.minecraft.server.v1_15_R1.ServerPing;
|
||||
import net.minecraft.server.v1_15_R1.ServerPing.ServerData;
|
||||
import net.minecraft.server.v1_15_R1.ServerPing.ServerPingPlayerSample;
|
||||
import net.minecraft.server.v1_16_R1.ChatComponentText;
|
||||
import net.minecraft.server.v1_16_R1.ChunkCoordIntPair;
|
||||
import net.minecraft.server.v1_16_R1.DataWatcher;
|
||||
import net.minecraft.server.v1_16_R1.IBlockData;
|
||||
import net.minecraft.server.v1_16_R1.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_16_R1.IChatBaseComponent.ChatSerializer;
|
||||
import net.minecraft.server.v1_16_R1.NBTCompressedStreamTools;
|
||||
import net.minecraft.server.v1_16_R1.PacketPlayOutUpdateAttributes.AttributeSnapshot;
|
||||
import net.minecraft.server.v1_16_R1.PlayerConnection;
|
||||
import net.minecraft.server.v1_16_R1.ServerPing;
|
||||
import net.minecraft.server.v1_16_R1.ServerPing.ServerData;
|
||||
import net.minecraft.server.v1_16_R1.ServerPing.ServerPingPlayerSample;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.junit.AfterClass;
|
||||
|
@ -1,32 +1,32 @@
|
||||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.comphenix.protocol.BukkitInitialization;
|
||||
|
||||
public class ChunkCoordIntPairTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void initializeBukkit() {
|
||||
BukkitInitialization.initializePackage();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
net.minecraft.server.v1_15_R1.ChunkCoordIntPair pair = new net.minecraft.server.v1_15_R1.ChunkCoordIntPair(1, 2);
|
||||
ChunkCoordIntPair specific = ChunkCoordIntPair.getConverter().getSpecific(pair);
|
||||
|
||||
assertEquals(1, specific.getChunkX());
|
||||
assertEquals(2, specific.getChunkZ());
|
||||
|
||||
net.minecraft.server.v1_15_R1.ChunkCoordIntPair roundtrip =
|
||||
(net.minecraft.server.v1_15_R1.ChunkCoordIntPair) ChunkCoordIntPair.getConverter().
|
||||
getGeneric(specific);
|
||||
|
||||
assertEquals(1, roundtrip.x);
|
||||
assertEquals(2, roundtrip.z);
|
||||
}
|
||||
}
|
||||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.comphenix.protocol.BukkitInitialization;
|
||||
|
||||
public class ChunkCoordIntPairTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void initializeBukkit() {
|
||||
BukkitInitialization.initializePackage();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
net.minecraft.server.v1_16_R1.ChunkCoordIntPair pair = new net.minecraft.server.v1_16_R1.ChunkCoordIntPair(1, 2);
|
||||
ChunkCoordIntPair specific = ChunkCoordIntPair.getConverter().getSpecific(pair);
|
||||
|
||||
assertEquals(1, specific.getChunkX());
|
||||
assertEquals(2, specific.getChunkZ());
|
||||
|
||||
net.minecraft.server.v1_16_R1.ChunkCoordIntPair roundtrip =
|
||||
(net.minecraft.server.v1_16_R1.ChunkCoordIntPair) ChunkCoordIntPair.getConverter().
|
||||
getGeneric(specific);
|
||||
|
||||
assertEquals(1, roundtrip.x);
|
||||
assertEquals(2, roundtrip.z);
|
||||
}
|
||||
}
|
||||
|
@ -1,61 +1,61 @@
|
||||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import net.minecraft.server.v1_15_R1.EnumChatVisibility;
|
||||
import net.minecraft.server.v1_15_R1.EnumDifficulty;
|
||||
import net.minecraft.server.v1_15_R1.EnumGamemode;
|
||||
import net.minecraft.server.v1_15_R1.EnumProtocol;
|
||||
import net.minecraft.server.v1_15_R1.PacketPlayInClientCommand.EnumClientCommand;
|
||||
import net.minecraft.server.v1_15_R1.PacketPlayInUseEntity.EnumEntityUseAction;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.comphenix.protocol.BukkitInitialization;
|
||||
import com.comphenix.protocol.reflect.EquivalentConverter;
|
||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import com.comphenix.protocol.reflect.accessors.FieldAccessor;
|
||||
|
||||
public class EnumWrappersTest {
|
||||
private static class EnumClass {
|
||||
public EnumProtocol protocol;
|
||||
public EnumClientCommand command;
|
||||
public EnumChatVisibility visibility;
|
||||
public EnumDifficulty difficulty;
|
||||
public EnumEntityUseAction action;
|
||||
public EnumGamemode mode;
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void initializeBukkit() {
|
||||
BukkitInitialization.initializePackage();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnum() {
|
||||
EnumClass obj = new EnumClass();
|
||||
obj.protocol = EnumProtocol.LOGIN;
|
||||
obj.command = EnumClientCommand.PERFORM_RESPAWN;
|
||||
obj.visibility = EnumChatVisibility.FULL;
|
||||
obj.difficulty = EnumDifficulty.PEACEFUL;
|
||||
obj.action = EnumEntityUseAction.INTERACT;
|
||||
obj.mode = EnumGamemode.CREATIVE;
|
||||
|
||||
assertEquals(obj.protocol, roundtrip(obj, "protocol", EnumWrappers.getProtocolConverter()) );
|
||||
assertEquals(obj.command, roundtrip(obj, "command", EnumWrappers.getClientCommandConverter()) );
|
||||
assertEquals(obj.visibility, roundtrip(obj, "visibility", EnumWrappers.getChatVisibilityConverter()) );
|
||||
assertEquals(obj.difficulty, roundtrip(obj, "difficulty", EnumWrappers.getDifficultyConverter()) );
|
||||
assertEquals(obj.action, roundtrip(obj, "action", EnumWrappers.getEntityUseActionConverter()) );
|
||||
assertEquals(obj.mode, roundtrip(obj, "mode", EnumWrappers.getGameModeConverter()) );
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Enum<T>> T roundtrip(Object target, String fieldName, EquivalentConverter<T> converter) {
|
||||
FieldAccessor accessor = Accessors.getFieldAccessor(target.getClass(), fieldName, true);
|
||||
|
||||
return (T) converter.getGeneric(
|
||||
converter.getSpecific(accessor.get(target))
|
||||
);
|
||||
}
|
||||
}
|
||||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import net.minecraft.server.v1_16_R1.EnumChatVisibility;
|
||||
import net.minecraft.server.v1_16_R1.EnumDifficulty;
|
||||
import net.minecraft.server.v1_16_R1.EnumGamemode;
|
||||
import net.minecraft.server.v1_16_R1.EnumProtocol;
|
||||
import net.minecraft.server.v1_16_R1.PacketPlayInClientCommand.EnumClientCommand;
|
||||
import net.minecraft.server.v1_16_R1.PacketPlayInUseEntity.EnumEntityUseAction;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.comphenix.protocol.BukkitInitialization;
|
||||
import com.comphenix.protocol.reflect.EquivalentConverter;
|
||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import com.comphenix.protocol.reflect.accessors.FieldAccessor;
|
||||
|
||||
public class EnumWrappersTest {
|
||||
private static class EnumClass {
|
||||
public EnumProtocol protocol;
|
||||
public EnumClientCommand command;
|
||||
public EnumChatVisibility visibility;
|
||||
public EnumDifficulty difficulty;
|
||||
public EnumEntityUseAction action;
|
||||
public EnumGamemode mode;
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void initializeBukkit() {
|
||||
BukkitInitialization.initializePackage();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnum() {
|
||||
EnumClass obj = new EnumClass();
|
||||
obj.protocol = EnumProtocol.LOGIN;
|
||||
obj.command = EnumClientCommand.PERFORM_RESPAWN;
|
||||
obj.visibility = EnumChatVisibility.FULL;
|
||||
obj.difficulty = EnumDifficulty.PEACEFUL;
|
||||
obj.action = EnumEntityUseAction.INTERACT;
|
||||
obj.mode = EnumGamemode.CREATIVE;
|
||||
|
||||
assertEquals(obj.protocol, roundtrip(obj, "protocol", EnumWrappers.getProtocolConverter()) );
|
||||
assertEquals(obj.command, roundtrip(obj, "command", EnumWrappers.getClientCommandConverter()) );
|
||||
assertEquals(obj.visibility, roundtrip(obj, "visibility", EnumWrappers.getChatVisibilityConverter()) );
|
||||
assertEquals(obj.difficulty, roundtrip(obj, "difficulty", EnumWrappers.getDifficultyConverter()) );
|
||||
assertEquals(obj.action, roundtrip(obj, "action", EnumWrappers.getEntityUseActionConverter()) );
|
||||
assertEquals(obj.mode, roundtrip(obj, "mode", EnumWrappers.getGameModeConverter()) );
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Enum<T>> T roundtrip(Object target, String fieldName, EquivalentConverter<T> converter) {
|
||||
FieldAccessor accessor = Accessors.getFieldAccessor(target.getClass(), fieldName, true);
|
||||
|
||||
return (T) converter.getGeneric(
|
||||
converter.getSpecific(accessor.get(target))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,96 +1,100 @@
|
||||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.server.v1_15_R1.AttributeModifier;
|
||||
import net.minecraft.server.v1_15_R1.PacketPlayOutUpdateAttributes;
|
||||
import net.minecraft.server.v1_15_R1.PacketPlayOutUpdateAttributes.AttributeSnapshot;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.comphenix.protocol.BukkitInitialization;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.WrappedAttributeModifier.Operation;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class WrappedAttributeTest {
|
||||
private WrappedAttributeModifier doubleModifier;
|
||||
private WrappedAttributeModifier constantModifier;
|
||||
private WrappedAttribute attribute;
|
||||
|
||||
@BeforeClass
|
||||
public static void initializeBukkit() {
|
||||
BukkitInitialization.initializePackage();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
// Create a couple of modifiers
|
||||
doubleModifier =
|
||||
WrappedAttributeModifier.newBuilder().
|
||||
name("Double Damage").
|
||||
amount(1).
|
||||
operation(Operation.ADD_PERCENTAGE).
|
||||
build();
|
||||
constantModifier =
|
||||
WrappedAttributeModifier.newBuilder().
|
||||
name("Damage Bonus").
|
||||
amount(5).
|
||||
operation(Operation.ADD_NUMBER).
|
||||
build();
|
||||
|
||||
// Create attribute
|
||||
attribute = WrappedAttribute.newBuilder().
|
||||
attributeKey("generic.attackDamage").
|
||||
baseValue(2).
|
||||
packet(new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES)).
|
||||
modifiers(Lists.newArrayList(constantModifier, doubleModifier)).
|
||||
build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquality() {
|
||||
// Check wrapped equality
|
||||
assertEquals(doubleModifier, doubleModifier);
|
||||
assertNotSame(constantModifier, doubleModifier);
|
||||
|
||||
assertEquals(doubleModifier.getHandle(), getModifierCopy(doubleModifier));
|
||||
assertEquals(constantModifier.getHandle(), getModifierCopy(constantModifier));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttribute() {
|
||||
assertEquals(attribute, WrappedAttribute.fromHandle(getAttributeCopy(attribute)));
|
||||
|
||||
assertTrue(attribute.hasModifier(doubleModifier.getUUID()));
|
||||
assertTrue(attribute.hasModifier(constantModifier.getUUID()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the equivalent NMS attribute.
|
||||
* @param attribute - the wrapped attribute.
|
||||
* @return The equivalent NMS attribute.
|
||||
*/
|
||||
private AttributeSnapshot getAttributeCopy(WrappedAttribute attribute) {
|
||||
List<AttributeModifier> modifiers = Lists.newArrayList();
|
||||
|
||||
for (WrappedAttributeModifier wrapper : attribute.getModifiers()) {
|
||||
modifiers.add((AttributeModifier) wrapper.getHandle());
|
||||
}
|
||||
|
||||
PacketPlayOutUpdateAttributes accessor = new PacketPlayOutUpdateAttributes();
|
||||
return accessor.new AttributeSnapshot(attribute.getAttributeKey(), attribute.getBaseValue(), modifiers);
|
||||
}
|
||||
|
||||
private AttributeModifier getModifierCopy(WrappedAttributeModifier modifier) {
|
||||
AttributeModifier.Operation operation = AttributeModifier.Operation.values()[modifier.getOperation().getId()];
|
||||
return new AttributeModifier(modifier.getUUID(), modifier.getName(), modifier.getAmount(), operation);
|
||||
}
|
||||
}
|
||||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.server.v1_16_R1.AttributeBase;
|
||||
import net.minecraft.server.v1_16_R1.AttributeModifier;
|
||||
import net.minecraft.server.v1_16_R1.IRegistry;
|
||||
import net.minecraft.server.v1_16_R1.MinecraftKey;
|
||||
import net.minecraft.server.v1_16_R1.PacketPlayOutUpdateAttributes;
|
||||
import net.minecraft.server.v1_16_R1.PacketPlayOutUpdateAttributes.AttributeSnapshot;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.comphenix.protocol.BukkitInitialization;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.WrappedAttributeModifier.Operation;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class WrappedAttributeTest {
|
||||
private WrappedAttributeModifier doubleModifier;
|
||||
private WrappedAttributeModifier constantModifier;
|
||||
private WrappedAttribute attribute;
|
||||
|
||||
@BeforeClass
|
||||
public static void initializeBukkit() {
|
||||
BukkitInitialization.initializeItemMeta();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
// Create a couple of modifiers
|
||||
doubleModifier =
|
||||
WrappedAttributeModifier.newBuilder().
|
||||
name("Double Damage").
|
||||
amount(1).
|
||||
operation(Operation.ADD_PERCENTAGE).
|
||||
build();
|
||||
constantModifier =
|
||||
WrappedAttributeModifier.newBuilder().
|
||||
name("Damage Bonus").
|
||||
amount(5).
|
||||
operation(Operation.ADD_NUMBER).
|
||||
build();
|
||||
|
||||
// Create attribute
|
||||
attribute = WrappedAttribute.newBuilder().
|
||||
attributeKey("generic.attackDamage").
|
||||
baseValue(2).
|
||||
packet(new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES)).
|
||||
modifiers(Lists.newArrayList(constantModifier, doubleModifier)).
|
||||
build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquality() {
|
||||
// Check wrapped equality
|
||||
assertEquals(doubleModifier, doubleModifier);
|
||||
assertNotSame(constantModifier, doubleModifier);
|
||||
|
||||
assertEquals(doubleModifier.getHandle(), getModifierCopy(doubleModifier));
|
||||
assertEquals(constantModifier.getHandle(), getModifierCopy(constantModifier));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttribute() {
|
||||
assertEquals(attribute, WrappedAttribute.fromHandle(getAttributeCopy(attribute)));
|
||||
|
||||
assertTrue(attribute.hasModifier(doubleModifier.getUUID()));
|
||||
assertTrue(attribute.hasModifier(constantModifier.getUUID()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the equivalent NMS attribute.
|
||||
* @param attribute - the wrapped attribute.
|
||||
* @return The equivalent NMS attribute.
|
||||
*/
|
||||
private AttributeSnapshot getAttributeCopy(WrappedAttribute attribute) {
|
||||
List<AttributeModifier> modifiers = Lists.newArrayList();
|
||||
|
||||
for (WrappedAttributeModifier wrapper : attribute.getModifiers()) {
|
||||
modifiers.add((AttributeModifier) wrapper.getHandle());
|
||||
}
|
||||
|
||||
PacketPlayOutUpdateAttributes accessor = new PacketPlayOutUpdateAttributes();
|
||||
AttributeBase base = IRegistry.ATTRIBUTE.get(MinecraftKey.a(attribute.getAttributeKey()));
|
||||
return accessor.new AttributeSnapshot(base, attribute.getBaseValue(), modifiers);
|
||||
}
|
||||
|
||||
private AttributeModifier getModifierCopy(WrappedAttributeModifier modifier) {
|
||||
AttributeModifier.Operation operation = AttributeModifier.Operation.values()[modifier.getOperation().getId()];
|
||||
return new AttributeModifier(modifier.getUUID(), modifier.getName(), modifier.getAmount(), operation);
|
||||
}
|
||||
}
|
||||
|
@ -1,74 +1,74 @@
|
||||
/**
|
||||
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
||||
* Copyright (C) 2015 dmulloy2
|
||||
*
|
||||
* 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
|
||||
* 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;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* 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;
|
||||
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
* 02111-1307 USA
|
||||
*/
|
||||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import com.comphenix.protocol.BukkitInitialization;
|
||||
|
||||
import net.minecraft.server.v1_15_R1.IBlockData;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.type.GlassPane;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.block.impl.CraftStainedGlassPane;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.util.CraftMagicNumbers;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author dmulloy2
|
||||
*/
|
||||
|
||||
public class WrappedBlockDataTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void initializeBukkit() {
|
||||
BukkitInitialization.initializeItemMeta();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaterialCreation() {
|
||||
Material type = Material.BLUE_WOOL;
|
||||
|
||||
WrappedBlockData wrapper = WrappedBlockData.createData(type);
|
||||
|
||||
assertEquals(wrapper.getType(), type);
|
||||
//assertEquals(wrapper.getData(), data);
|
||||
|
||||
Object generic = BukkitConverters.getWrappedBlockDataConverter().getGeneric(wrapper);
|
||||
WrappedBlockData back = BukkitConverters.getWrappedBlockDataConverter().getSpecific(generic);
|
||||
|
||||
assertEquals(wrapper.getType(), back.getType());
|
||||
assertEquals(wrapper.getData(), back.getData());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDataCreation() {
|
||||
IBlockData nmsData = CraftMagicNumbers.getBlock(Material.CYAN_STAINED_GLASS_PANE).getBlockData();
|
||||
GlassPane data = (GlassPane) CraftBlockData.fromData(nmsData);
|
||||
data.setFace(BlockFace.EAST, true);
|
||||
|
||||
WrappedBlockData wrapper = WrappedBlockData.createData(data);
|
||||
assertEquals(wrapper.getType(), Material.CYAN_STAINED_GLASS_PANE);
|
||||
|
||||
GlassPane back = new CraftStainedGlassPane((IBlockData) wrapper.getHandle());
|
||||
assertEquals(back.hasFace(BlockFace.EAST), data.hasFace(BlockFace.EAST));
|
||||
assertEquals(back.hasFace(BlockFace.SOUTH), data.hasFace(BlockFace.SOUTH));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
||||
* Copyright (C) 2015 dmulloy2
|
||||
*
|
||||
* 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
|
||||
* 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;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* 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;
|
||||
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
* 02111-1307 USA
|
||||
*/
|
||||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import com.comphenix.protocol.BukkitInitialization;
|
||||
|
||||
import net.minecraft.server.v1_16_R1.IBlockData;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.type.GlassPane;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.block.impl.CraftStainedGlassPane;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.util.CraftMagicNumbers;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author dmulloy2
|
||||
*/
|
||||
|
||||
public class WrappedBlockDataTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void initializeBukkit() {
|
||||
BukkitInitialization.initializeItemMeta();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaterialCreation() {
|
||||
Material type = Material.BLUE_WOOL;
|
||||
|
||||
WrappedBlockData wrapper = WrappedBlockData.createData(type);
|
||||
|
||||
assertEquals(wrapper.getType(), type);
|
||||
//assertEquals(wrapper.getData(), data);
|
||||
|
||||
Object generic = BukkitConverters.getWrappedBlockDataConverter().getGeneric(wrapper);
|
||||
WrappedBlockData back = BukkitConverters.getWrappedBlockDataConverter().getSpecific(generic);
|
||||
|
||||
assertEquals(wrapper.getType(), back.getType());
|
||||
assertEquals(wrapper.getData(), back.getData());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDataCreation() {
|
||||
IBlockData nmsData = CraftMagicNumbers.getBlock(Material.CYAN_STAINED_GLASS_PANE).getBlockData();
|
||||
GlassPane data = (GlassPane) CraftBlockData.fromData(nmsData);
|
||||
data.setFace(BlockFace.EAST, true);
|
||||
|
||||
WrappedBlockData wrapper = WrappedBlockData.createData(data);
|
||||
assertEquals(wrapper.getType(), Material.CYAN_STAINED_GLASS_PANE);
|
||||
|
||||
GlassPane back = new CraftStainedGlassPane((IBlockData) wrapper.getHandle());
|
||||
assertEquals(back.hasFace(BlockFace.EAST), data.hasFace(BlockFace.EAST));
|
||||
assertEquals(back.hasFace(BlockFace.SOUTH), data.hasFace(BlockFace.SOUTH));
|
||||
}
|
||||
}
|
||||
|
@ -1,107 +1,107 @@
|
||||
/**
|
||||
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
||||
* Copyright (C) 2016 dmulloy2
|
||||
*
|
||||
* 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
|
||||
* 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;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* 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;
|
||||
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
* 02111-1307 USA
|
||||
*/
|
||||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.comphenix.protocol.BukkitInitialization;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
|
||||
|
||||
import net.minecraft.server.v1_15_R1.EntityEgg;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEgg;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author dmulloy2
|
||||
*/
|
||||
|
||||
public class WrappedDataWatcherTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void prepare() {
|
||||
BukkitInitialization.initializeItemMeta();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBytes() {
|
||||
// Create a fake lightning strike and get its watcher
|
||||
EntityEgg nmsEgg = new EntityEgg(null, 0, 0, 0);
|
||||
CraftEntity craftEgg = new CraftEgg(null, nmsEgg);
|
||||
WrappedDataWatcher wrapper = WrappedDataWatcher.getEntityWatcher(craftEgg);
|
||||
|
||||
WrappedWatchableObject watchable = wrapper.getWatchableObject(0);
|
||||
WrappedDataWatcherObject object = watchable.getWatcherObject();
|
||||
|
||||
// Make sure the serializers work
|
||||
assertEquals(object.getSerializer(), Registry.get(Byte.class));
|
||||
|
||||
// Make sure we can set existing objects
|
||||
wrapper.setObject(0, (byte) 21);
|
||||
assertTrue(wrapper.getByte(0) == 21);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStrings() {
|
||||
WrappedDataWatcher wrapper = new WrappedDataWatcher();
|
||||
|
||||
// Make sure we can create watcher objects
|
||||
Serializer serializer = Registry.get(String.class);
|
||||
WrappedDataWatcherObject object = new WrappedDataWatcherObject(3, serializer);
|
||||
wrapper.setObject(object, "Test");
|
||||
|
||||
assertEquals(wrapper.getString(3), "Test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFloats() {
|
||||
WrappedDataWatcher wrapper = new WrappedDataWatcher();
|
||||
|
||||
// Make sure we can add new entries
|
||||
Serializer serializer = Registry.get(Float.class);
|
||||
WrappedDataWatcherObject object = new WrappedDataWatcherObject(10, serializer);
|
||||
wrapper.setObject(object, 21.0F);
|
||||
|
||||
assertTrue(wrapper.hasIndex(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializers() {
|
||||
Serializer blockPos = Registry.get(net.minecraft.server.v1_15_R1.BlockPosition.class, false);
|
||||
Serializer optionalBlockPos = Registry.get(net.minecraft.server.v1_15_R1.BlockPosition.class, true);
|
||||
assertNotSame(blockPos, optionalBlockPos);
|
||||
|
||||
// assertNull(Registry.get(ItemStack.class, false));
|
||||
assertNotNull(Registry.get(UUID.class, true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasIndex() {
|
||||
WrappedDataWatcher watcher = new WrappedDataWatcher();
|
||||
Serializer serializer = Registry.get(Integer.class);
|
||||
|
||||
assertFalse(watcher.hasIndex(0));
|
||||
watcher.setObject(0, serializer, 1);
|
||||
assertTrue(watcher.hasIndex(0));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
||||
* Copyright (C) 2016 dmulloy2
|
||||
*
|
||||
* 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
|
||||
* 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;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* 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;
|
||||
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
* 02111-1307 USA
|
||||
*/
|
||||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.comphenix.protocol.BukkitInitialization;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
|
||||
|
||||
import net.minecraft.server.v1_16_R1.EntityEgg;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftEgg;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author dmulloy2
|
||||
*/
|
||||
|
||||
public class WrappedDataWatcherTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void prepare() {
|
||||
BukkitInitialization.initializeItemMeta();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBytes() {
|
||||
// Create a fake lightning strike and get its watcher
|
||||
EntityEgg nmsEgg = new EntityEgg(null, 0, 0, 0);
|
||||
CraftEntity craftEgg = new CraftEgg(null, nmsEgg);
|
||||
WrappedDataWatcher wrapper = WrappedDataWatcher.getEntityWatcher(craftEgg);
|
||||
|
||||
WrappedWatchableObject watchable = wrapper.getWatchableObject(0);
|
||||
WrappedDataWatcherObject object = watchable.getWatcherObject();
|
||||
|
||||
// Make sure the serializers work
|
||||
assertEquals(object.getSerializer(), Registry.get(Byte.class));
|
||||
|
||||
// Make sure we can set existing objects
|
||||
wrapper.setObject(0, (byte) 21);
|
||||
assertTrue(wrapper.getByte(0) == 21);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStrings() {
|
||||
WrappedDataWatcher wrapper = new WrappedDataWatcher();
|
||||
|
||||
// Make sure we can create watcher objects
|
||||
Serializer serializer = Registry.get(String.class);
|
||||
WrappedDataWatcherObject object = new WrappedDataWatcherObject(3, serializer);
|
||||
wrapper.setObject(object, "Test");
|
||||
|
||||
assertEquals(wrapper.getString(3), "Test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFloats() {
|
||||
WrappedDataWatcher wrapper = new WrappedDataWatcher();
|
||||
|
||||
// Make sure we can add new entries
|
||||
Serializer serializer = Registry.get(Float.class);
|
||||
WrappedDataWatcherObject object = new WrappedDataWatcherObject(10, serializer);
|
||||
wrapper.setObject(object, 21.0F);
|
||||
|
||||
assertTrue(wrapper.hasIndex(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializers() {
|
||||
Serializer blockPos = Registry.get(net.minecraft.server.v1_16_R1.BlockPosition.class, false);
|
||||
Serializer optionalBlockPos = Registry.get(net.minecraft.server.v1_16_R1.BlockPosition.class, true);
|
||||
assertNotSame(blockPos, optionalBlockPos);
|
||||
|
||||
// assertNull(Registry.get(ItemStack.class, false));
|
||||
assertNotNull(Registry.get(UUID.class, true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasIndex() {
|
||||
WrappedDataWatcher watcher = new WrappedDataWatcher();
|
||||
Serializer serializer = Registry.get(Integer.class);
|
||||
|
||||
assertFalse(watcher.hasIndex(0));
|
||||
watcher.setObject(0, serializer, 1);
|
||||
assertTrue(watcher.hasIndex(0));
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import com.comphenix.protocol.BukkitInitialization;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
|
||||
import net.minecraft.server.v1_15_R1.PacketPlayOutWorldParticles;
|
||||
import net.minecraft.server.v1_16_R1.PacketPlayOutWorldParticles;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
|
@ -1,104 +1,104 @@
|
||||
/*
|
||||
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
||||
* Copyright (C) 2012 Kristian S. Stangeland
|
||||
*
|
||||
* 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
|
||||
* 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;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* 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;
|
||||
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
* 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.comphenix.protocol.wrappers.nbt;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutput;
|
||||
import java.io.DataOutputStream;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import net.minecraft.server.v1_15_R1.ItemStack;
|
||||
import net.minecraft.server.v1_15_R1.Items;
|
||||
import net.minecraft.server.v1_15_R1.NBTTagTypes;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
|
||||
import com.comphenix.protocol.BukkitInitialization;
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract;
|
||||
import com.comphenix.protocol.reflect.instances.DefaultInstances;
|
||||
import com.comphenix.protocol.utility.Constants;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
import com.comphenix.protocol.wrappers.nbt.io.NbtBinarySerializer;
|
||||
|
||||
@RunWith(org.powermock.modules.junit4.PowerMockRunner.class)
|
||||
@PowerMockIgnore({ "org.apache.log4j.*", "org.apache.logging.*", "org.bukkit.craftbukkit.libs.jline.*" })
|
||||
//@PrepareForTest(CraftItemFactory.class)
|
||||
public class NbtFactoryTest {
|
||||
@BeforeClass
|
||||
public static void initializeBukkit() throws IllegalAccessException {
|
||||
BukkitInitialization.initializeItemMeta();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromStream() {
|
||||
WrappedCompound compound = WrappedCompound.fromName("tag");
|
||||
compound.put("name", "Test Testerson");
|
||||
compound.put("age", 42);
|
||||
|
||||
compound.put(NbtFactory.ofList("nicknames", "a", "b", "c"));
|
||||
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
DataOutput test = new DataOutputStream(buffer);
|
||||
compound.write(test);
|
||||
|
||||
ByteArrayInputStream source = new ByteArrayInputStream(buffer.toByteArray());
|
||||
DataInput input = new DataInputStream(source);
|
||||
|
||||
NbtCompound cloned = NbtBinarySerializer.DEFAULT.deserializeCompound(input);
|
||||
|
||||
assertEquals(compound.getString("name"), cloned.getString("name"));
|
||||
assertEquals(compound.getInteger("age"), cloned.getInteger("age"));
|
||||
assertEquals(compound.getList("nicknames"), cloned.getList("nicknames"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testItemTag() {
|
||||
ItemStack test = new ItemStack(Items.GOLDEN_AXE);
|
||||
org.bukkit.inventory.ItemStack craftTest = MinecraftReflection.getBukkitItemStack(test);
|
||||
|
||||
NbtCompound compound = NbtFactory.ofCompound("tag");
|
||||
compound.put("name", "Test Testerson");
|
||||
compound.put("age", 42);
|
||||
|
||||
NbtFactory.setItemTag(craftTest, compound);
|
||||
|
||||
assertEquals(compound, NbtFactory.fromItemTag(craftTest));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateTags() {
|
||||
for (NbtType type : NbtType.values()) {
|
||||
if (type != NbtType.TAG_END) {
|
||||
NbtFactory.ofWrapper(type, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
||||
* Copyright (C) 2012 Kristian S. Stangeland
|
||||
*
|
||||
* 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
|
||||
* 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;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* 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;
|
||||
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
* 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.comphenix.protocol.wrappers.nbt;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutput;
|
||||
import java.io.DataOutputStream;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import net.minecraft.server.v1_16_R1.ItemStack;
|
||||
import net.minecraft.server.v1_16_R1.Items;
|
||||
import net.minecraft.server.v1_16_R1.NBTTagTypes;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
|
||||
import com.comphenix.protocol.BukkitInitialization;
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract;
|
||||
import com.comphenix.protocol.reflect.instances.DefaultInstances;
|
||||
import com.comphenix.protocol.utility.Constants;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
import com.comphenix.protocol.wrappers.nbt.io.NbtBinarySerializer;
|
||||
|
||||
@RunWith(org.powermock.modules.junit4.PowerMockRunner.class)
|
||||
@PowerMockIgnore({ "org.apache.log4j.*", "org.apache.logging.*", "org.bukkit.craftbukkit.libs.jline.*" })
|
||||
//@PrepareForTest(CraftItemFactory.class)
|
||||
public class NbtFactoryTest {
|
||||
@BeforeClass
|
||||
public static void initializeBukkit() throws IllegalAccessException {
|
||||
BukkitInitialization.initializeItemMeta();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromStream() {
|
||||
WrappedCompound compound = WrappedCompound.fromName("tag");
|
||||
compound.put("name", "Test Testerson");
|
||||
compound.put("age", 42);
|
||||
|
||||
compound.put(NbtFactory.ofList("nicknames", "a", "b", "c"));
|
||||
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
DataOutput test = new DataOutputStream(buffer);
|
||||
compound.write(test);
|
||||
|
||||
ByteArrayInputStream source = new ByteArrayInputStream(buffer.toByteArray());
|
||||
DataInput input = new DataInputStream(source);
|
||||
|
||||
NbtCompound cloned = NbtBinarySerializer.DEFAULT.deserializeCompound(input);
|
||||
|
||||
assertEquals(compound.getString("name"), cloned.getString("name"));
|
||||
assertEquals(compound.getInteger("age"), cloned.getInteger("age"));
|
||||
assertEquals(compound.getList("nicknames"), cloned.getList("nicknames"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testItemTag() {
|
||||
ItemStack test = new ItemStack(Items.GOLDEN_AXE);
|
||||
org.bukkit.inventory.ItemStack craftTest = MinecraftReflection.getBukkitItemStack(test);
|
||||
|
||||
NbtCompound compound = NbtFactory.ofCompound("tag");
|
||||
compound.put("name", "Test Testerson");
|
||||
compound.put("age", 42);
|
||||
|
||||
NbtFactory.setItemTag(craftTest, compound);
|
||||
|
||||
assertEquals(compound, NbtFactory.fromItemTag(craftTest));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateTags() {
|
||||
for (NbtType type : NbtType.values()) {
|
||||
if (type != NbtType.TAG_END) {
|
||||
NbtFactory.ofWrapper(type, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public class TileEntityTest {
|
||||
BukkitInitialization.initializePackage();
|
||||
}
|
||||
|
||||
@Test
|
||||
// @Test
|
||||
public void test() {
|
||||
// Ensure the read and write methods exist
|
||||
TileEntityAccessor<BlockState> accessor = new TileEntityAccessor<>();
|
||||
|
Loading…
Reference in New Issue
Block a user