From ea734965bce95dabf5d4e1ff66486c2ecafa99dd Mon Sep 17 00:00:00 2001 From: Flo // Sheigutn Date: Tue, 2 Dec 2014 19:29:10 +0100 Subject: [PATCH] Add PlayerInfoAction EnumWrapper --- .../protocol/events/PacketContainer.java | 12 ++++++++- .../protocol/wrappers/EnumWrappers.java | 27 ++++++++++++++++--- 2 files changed, 34 insertions(+), 5 deletions(-) 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 e89e4162..bd42957d 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java @@ -80,6 +80,7 @@ import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode; import com.comphenix.protocol.wrappers.EnumWrappers.ResourcePackStatus; import com.comphenix.protocol.wrappers.EnumWrappers.TitleAction; import com.comphenix.protocol.wrappers.EnumWrappers.WorldBorderAction; +import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction; import com.comphenix.protocol.wrappers.WrappedAttribute; import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedDataWatcher; @@ -683,7 +684,7 @@ public class PacketContainer implements Serializable { return structureModifier.withType( EnumWrappers.getEntityUseActionClass(), EnumWrappers.getEntityUseActionConverter()); } - + /** * Retrieve a read/write structure for the NativeGameMode enum in 1.7.2. * @return A modifier for NativeGameMode enum fields. @@ -704,6 +705,15 @@ public class PacketContainer implements Serializable { EnumWrappers.getResourcePackStatusClass(), EnumWrappers.getResourcePackStatusConverter()); } + /** + * Retrieve a read/write structure for the PlayerInfo enum in 1.8 + * @return A modifier for PlayerInfoAction enum fields. + */ + public StructureModifier getPlayerInfoAction() { + // Convert to and from the wrapper + return structureModifier.withType( + EnumWrappers.getPlayerInfoActionClass(), EnumWrappers.getPlayerInfoActionConverter()); + } /** * Retrieve a read/write structure for the TitleAction enum in 1.8. * @return A modifier for TitleAction enum fields. 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 34d70714..f6868536 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java @@ -1,15 +1,14 @@ package com.comphenix.protocol.wrappers; -import java.util.Map; - -import org.bukkit.GameMode; - import com.comphenix.protocol.PacketType; import com.comphenix.protocol.PacketType.Protocol; import com.comphenix.protocol.reflect.EquivalentConverter; import com.comphenix.protocol.reflect.FuzzyReflection; import com.comphenix.protocol.utility.MinecraftReflection; import com.google.common.collect.Maps; +import org.bukkit.GameMode; + +import java.util.Map; /** * Represents a generic enum converter. @@ -67,6 +66,14 @@ public abstract class EnumWrappers { ACCEPTED; } + public enum PlayerInfoAction { + ADD_PLAYER, + UPDATE_GAMEMODE, + UPDATE_LATENCY, + UPDATE_DISPLAY_NAME, + REMOVE_PLAYER; + } + public enum TitleAction { TITLE, SUBTITLE, @@ -97,6 +104,7 @@ public abstract class EnumWrappers { private static Class ENTITY_USE_ACTION_CLASS = null; private static Class GAMEMODE_CLASS = null; private static Class RESOURCE_PACK_STATUS_CLASS = null; + private static Class PLAYER_INFO_ACTION_CLASS = null; private static Class TITLE_ACTION_CLASS = null; private static Class WORLD_BORDER_ACTION_CLASS = null; private static Class COMBAT_EVENT_TYPE_CLASS = null; @@ -122,6 +130,7 @@ public abstract class EnumWrappers { ENTITY_USE_ACTION_CLASS = getEnum(PacketType.Play.Client.USE_ENTITY.getPacketClass(), 0); GAMEMODE_CLASS = getEnum(PacketType.Play.Server.LOGIN.getPacketClass(), 0); RESOURCE_PACK_STATUS_CLASS = getEnum(PacketType.Play.Client.RESOURCE_PACK_STATUS.getPacketClass(), 0); + PLAYER_INFO_ACTION_CLASS = getEnum(PacketType.Play.Server.PLAYER_INFO.getPacketClass(), 0); 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); @@ -133,6 +142,7 @@ public abstract class EnumWrappers { associate(ENTITY_USE_ACTION_CLASS, EntityUseAction.class, getEntityUseActionConverter()); associate(GAMEMODE_CLASS, NativeGameMode.class, getGameModeConverter()); associate(RESOURCE_PACK_STATUS_CLASS, ResourcePackStatus.class, getResourcePackStatusConverter()); + associate(PLAYER_INFO_ACTION_CLASS, PlayerInfoAction.class, getPlayerInfoActionConverter()); associate(TITLE_ACTION_CLASS, TitleAction.class, getTitleActionConverter()); associate(WORLD_BORDER_ACTION_CLASS, WorldBorderAction.class, getWorldBorderActionConverter()); associate(COMBAT_EVENT_TYPE_CLASS, CombatEventType.class, getCombatEventTypeConverter()); @@ -198,6 +208,11 @@ public abstract class EnumWrappers { return RESOURCE_PACK_STATUS_CLASS; } + public static Class getPlayerInfoActionClass() { + initialize(); + return PLAYER_INFO_ACTION_CLASS; + } + public static Class getTitleActionClass() { initialize(); return TITLE_ACTION_CLASS; @@ -242,6 +257,10 @@ public abstract class EnumWrappers { return new EnumConverter(ResourcePackStatus.class); } + public static EquivalentConverter getPlayerInfoActionConverter() { + return new EnumConverter(PlayerInfoAction.class); + } + public static EquivalentConverter getTitleActionConverter() { return new EnumConverter(TitleAction.class); }