From d6b94e658a4267747423fcdb174df2e95babbf2d Mon Sep 17 00:00:00 2001 From: Zeruska Date: Wed, 3 Dec 2014 21:56:23 +0100 Subject: [PATCH] Add more EnumWrappers (PlayerDiggingAction, EntityAction, UpdateScoreAction) --- .../protocol/events/PacketContainer.java | 33 ++++++++++ .../protocol/wrappers/EnumWrappers.java | 60 +++++++++++++++++++ 2 files changed, 93 insertions(+) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java b/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java index 16c5750a..c6394b16 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java @@ -75,11 +75,14 @@ import com.comphenix.protocol.wrappers.EnumWrappers.ChatVisibility; import com.comphenix.protocol.wrappers.EnumWrappers.ClientCommand; import com.comphenix.protocol.wrappers.EnumWrappers.CombatEventType; import com.comphenix.protocol.wrappers.EnumWrappers.Difficulty; +import com.comphenix.protocol.wrappers.EnumWrappers.EntityAction; import com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction; import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode; +import com.comphenix.protocol.wrappers.EnumWrappers.PlayerDiggingAction; import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction; import com.comphenix.protocol.wrappers.EnumWrappers.ResourcePackStatus; import com.comphenix.protocol.wrappers.EnumWrappers.TitleAction; +import com.comphenix.protocol.wrappers.EnumWrappers.UpdateScoreAction; import com.comphenix.protocol.wrappers.EnumWrappers.WorldBorderAction; import com.comphenix.protocol.wrappers.WrappedAttribute; import com.comphenix.protocol.wrappers.WrappedChatComponent; @@ -744,6 +747,36 @@ public class PacketContainer implements Serializable { return structureModifier.withType( EnumWrappers.getCombatEventTypeClass(), EnumWrappers.getCombatEventTypeConverter()); } + + /** + * Retrieve a read/write structure for the PlayerDiggingAction enum in 1.8. + * @return A modifier for PlayerDiggingAction enum fields. + */ + public StructureModifier getPlayerDiggingActions() { + // Convert to and from the wrapper + return structureModifier.withType( + EnumWrappers.getPlayerDiggingActionClass(), EnumWrappers.getPlayerDiggingActionConverter()); + } + + /** + * Retrieve a read/write structure for the EntityAction enum in 1.8. + * @return A modifier for EntityAction enum fields. + */ + public StructureModifier getEntityActions() { + // Convert to and from the wrapper + return structureModifier.withType( + EnumWrappers.getEntityActionClass(), EnumWrappers.getEntityActionConverter()); + } + + /** + * Retrieve a read/write structure for the UpdateScoreAction enum in 1.8. + * @return A modifier for UpdateScoreAction enum fields. + */ + public StructureModifier getUpdateScoreActions() { + // Convert to and from the wrapper + return structureModifier.withType( + EnumWrappers.getUpdateScoreActionClass(), EnumWrappers.getUpdateScoreActionConverter()); + } /** * Retrieves the ID of this packet. diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java index 78992559..0f5614ba 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java @@ -98,6 +98,30 @@ public abstract class EnumWrappers { ENTITY_DIED; } + public enum PlayerDiggingAction { + START_DESTROY_BLOCK, + ABORT_DESTROY_BLOCK, + STOP_DESTROY_BLOCK, + DROP_ALL_ITEMS, + DROP_ITEM, + RELEASE_USE_ITEM; + } + + public enum EntityAction { + START_SNEAKING, + STOP_SNEAKING, + STOP_SLEEPING, + START_SPRINTING, + STOP_SPRINTING, + RIDING_JUMP, + OPEN_INVENTORY; + } + + public enum UpdateScoreAction { + CHANGE, + REMOVE; + } + private static Class PROTOCOL_CLASS = null; private static Class CLIENT_COMMAND_CLASS = null; private static Class CHAT_VISIBILITY_CLASS = null; @@ -109,6 +133,9 @@ public abstract class EnumWrappers { private static Class TITLE_ACTION_CLASS = null; private static Class WORLD_BORDER_ACTION_CLASS = null; private static Class COMBAT_EVENT_TYPE_CLASS = null; + private static Class PLAYER_DIGGING_ACTION_CLASS = null; + private static Class ENTITY_ACTION_CLASS = null; + private static Class UPDATE_SCORE_ACTION_CLASS = null; private static boolean INITIALIZED = false; private static Map, EquivalentConverter> FROM_NATIVE = Maps.newHashMap(); @@ -135,6 +162,9 @@ public abstract class EnumWrappers { TITLE_ACTION_CLASS = getEnum(PacketType.Play.Server.TITLE.getPacketClass(), 0); WORLD_BORDER_ACTION_CLASS = getEnum(PacketType.Play.Server.WORLD_BORDER.getPacketClass(), 0); COMBAT_EVENT_TYPE_CLASS = getEnum(PacketType.Play.Server.COMBAT_EVENT.getPacketClass(), 0); + PLAYER_DIGGING_ACTION_CLASS = getEnum(PacketType.Play.Client.BLOCK_DIG.getPacketClass(), 0); + ENTITY_ACTION_CLASS = getEnum(PacketType.Play.Client.ENTITY_ACTION.getPacketClass(), 0); + UPDATE_SCORE_ACTION_CLASS = getEnum(PacketType.Play.Server.SCOREBOARD_SCORE.getPacketClass(), 0); associate(PROTOCOL_CLASS, Protocol.class, getClientCommandConverter()); associate(CLIENT_COMMAND_CLASS, ClientCommand.class, getClientCommandConverter()); @@ -147,6 +177,9 @@ public abstract class EnumWrappers { associate(TITLE_ACTION_CLASS, TitleAction.class, getTitleActionConverter()); associate(WORLD_BORDER_ACTION_CLASS, WorldBorderAction.class, getWorldBorderActionConverter()); associate(COMBAT_EVENT_TYPE_CLASS, CombatEventType.class, getCombatEventTypeConverter()); + associate(PLAYER_DIGGING_ACTION_CLASS, PlayerDiggingAction.class, getPlayerDiggingActionConverter()); + associate(ENTITY_ACTION_CLASS, EntityAction.class, getEntityActionConverter()); + associate(UPDATE_SCORE_ACTION_CLASS, UpdateScoreAction.class, getUpdateScoreActionConverter()); INITIALIZED = true; } @@ -229,6 +262,21 @@ public abstract class EnumWrappers { return COMBAT_EVENT_TYPE_CLASS; } + public static Class getPlayerDiggingActionClass() { + initialize(); + return PLAYER_DIGGING_ACTION_CLASS; + } + + public static Class getEntityActionClass() { + initialize(); + return ENTITY_ACTION_CLASS; + } + + public static Class getUpdateScoreActionClass() { + initialize(); + return UPDATE_SCORE_ACTION_CLASS; + } + // Get the converters public static EquivalentConverter getProtocolConverter() { return new EnumConverter(Protocol.class); @@ -274,6 +322,18 @@ public abstract class EnumWrappers { return new EnumConverter(CombatEventType.class); } + public static EquivalentConverter getPlayerDiggingActionConverter() { + return new EnumConverter(PlayerDiggingAction.class); + } + + public static EquivalentConverter getEntityActionConverter() { + return new EnumConverter(EntityAction.class); + } + + public static EquivalentConverter getUpdateScoreActionConverter() { + return new EnumConverter(UpdateScoreAction.class); + } + // The common enum converter @SuppressWarnings({ "rawtypes", "unchecked" }) private static class EnumConverter> implements EquivalentConverter {