Archiviert
13
0

Add modifiers for UUIDs and Directions

Dieser Commit ist enthalten in:
Dan Mulloy 2016-07-06 15:46:42 -04:00
Ursprung 12e9c08a1a
Commit c13b8d4fc6
2 geänderte Dateien mit 55 neuen und 15 gelöschten Zeilen

Datei anzeigen

@ -33,6 +33,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -77,6 +78,7 @@ import com.comphenix.protocol.wrappers.EnumWrappers.ChatVisibility;
import com.comphenix.protocol.wrappers.EnumWrappers.ClientCommand; import com.comphenix.protocol.wrappers.EnumWrappers.ClientCommand;
import com.comphenix.protocol.wrappers.EnumWrappers.CombatEventType; import com.comphenix.protocol.wrappers.EnumWrappers.CombatEventType;
import com.comphenix.protocol.wrappers.EnumWrappers.Difficulty; import com.comphenix.protocol.wrappers.EnumWrappers.Difficulty;
import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
import com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction; import com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction;
import com.comphenix.protocol.wrappers.EnumWrappers.EnumConverter; import com.comphenix.protocol.wrappers.EnumWrappers.EnumConverter;
import com.comphenix.protocol.wrappers.EnumWrappers.Hand; import com.comphenix.protocol.wrappers.EnumWrappers.Hand;
@ -333,6 +335,14 @@ public class PacketContainer implements Serializable {
return structureModifier.withType(String.class); return structureModifier.withType(String.class);
} }
/**
* Retrieves a read/write structure for every UUID field.
* @return A modifier for every UUID field.
*/
public StructureModifier<UUID> getUUIDs() {
return structureModifier.withType(UUID.class);
}
/** /**
* Retrieves a read/write structure for every String array field. * Retrieves a read/write structure for every String array field.
* @return A modifier for every String array field. * @return A modifier for every String array field.
@ -368,7 +378,7 @@ public class PacketContainer implements Serializable {
/** /**
* Retrieves a read/write structure for ItemStack. * Retrieves a read/write structure for ItemStack.
* <p> * <p>
* This modifier will automatically marshall between the Bukkit ItemStack and the * This modifier will automatically marshal between the Bukkit ItemStack and the
* internal Minecraft ItemStack. * internal Minecraft ItemStack.
* @return A modifier for ItemStack fields. * @return A modifier for ItemStack fields.
*/ */
@ -381,7 +391,7 @@ public class PacketContainer implements Serializable {
/** /**
* Retrieves a read/write structure for arrays of ItemStacks. * Retrieves a read/write structure for arrays of ItemStacks.
* <p> * <p>
* This modifier will automatically marshall between the Bukkit ItemStack and the * This modifier will automatically marshal between the Bukkit ItemStack and the
* internal Minecraft ItemStack. * internal Minecraft ItemStack.
* @return A modifier for ItemStack array fields. * @return A modifier for ItemStack array fields.
*/ */
@ -410,7 +420,7 @@ public class PacketContainer implements Serializable {
/** /**
* Retrieves a read/write structure for the world type enum. * Retrieves a read/write structure for the world type enum.
* <p> * <p>
* This modifier will automatically marshall between the Bukkit world type and the * This modifier will automatically marshal between the Bukkit world type and the
* internal Minecraft world type. * internal Minecraft world type.
* @return A modifier for world type fields. * @return A modifier for world type fields.
*/ */
@ -524,7 +534,7 @@ public class PacketContainer implements Serializable {
/** /**
* Retrieves a read/write structure for collections of attribute snapshots. * Retrieves a read/write structure for collections of attribute snapshots.
* <p> * <p>
* This modifier will automatically marshall between the visible ProtocolLib WrappedAttribute and the * This modifier will automatically marshal between the visible ProtocolLib WrappedAttribute and the
* internal Minecraft AttributeSnapshot. * internal Minecraft AttributeSnapshot.
* @return A modifier for AttributeSnapshot collection fields. * @return A modifier for AttributeSnapshot collection fields.
*/ */
@ -541,7 +551,7 @@ public class PacketContainer implements Serializable {
/** /**
* Retrieves a read/write structure for collections of chunk positions. * Retrieves a read/write structure for collections of chunk positions.
* <p> * <p>
* This modifier will automatically marshall between the visible ProtocolLib ChunkPosition and the * This modifier will automatically marshal between the visible ProtocolLib ChunkPosition and the
* internal Minecraft ChunkPosition. * internal Minecraft ChunkPosition.
* *
* @return A modifier for ChunkPosition list fields. * @return A modifier for ChunkPosition list fields.
@ -559,7 +569,7 @@ public class PacketContainer implements Serializable {
/** /**
* Retrieves a read/write structure for collections of chunk positions. * Retrieves a read/write structure for collections of chunk positions.
* <p> * <p>
* This modifier will automatically marshall between the visible ProtocolLib BlockPosition and the * This modifier will automatically marshal between the visible ProtocolLib BlockPosition and the
* internal Minecraft BlockPosition. * internal Minecraft BlockPosition.
* *
* @return A modifier for ChunkPosition list fields. * @return A modifier for ChunkPosition list fields.
@ -577,7 +587,7 @@ public class PacketContainer implements Serializable {
/** /**
* Retrieves a read/write structure for collections of watchable objects. * Retrieves a read/write structure for collections of watchable objects.
* <p> * <p>
* This modifier will automatically marshall between the visible WrappedWatchableObject and the * This modifier will automatically marshal between the visible WrappedWatchableObject and the
* internal Minecraft WatchableObject. * internal Minecraft WatchableObject.
* @return A modifier for watchable object list fields. * @return A modifier for watchable object list fields.
*/ */
@ -594,7 +604,7 @@ public class PacketContainer implements Serializable {
/** /**
* Retrieves a read/write structure for block fields. * Retrieves a read/write structure for block fields.
* <p> * <p>
* This modifier will automatically marshall between Material and the * This modifier will automatically marshal between Material and the
* internal Minecraft Block. * internal Minecraft Block.
* @return A modifier for GameProfile fields. * @return A modifier for GameProfile fields.
*/ */
@ -607,7 +617,7 @@ public class PacketContainer implements Serializable {
/** /**
* Retrieves a read/write structure for game profiles in Minecraft 1.7.2. * Retrieves a read/write structure for game profiles in Minecraft 1.7.2.
* <p> * <p>
* This modifier will automatically marshall between WrappedGameProfile and the * This modifier will automatically marshal between WrappedGameProfile and the
* internal Minecraft GameProfile. * internal Minecraft GameProfile.
* @return A modifier for GameProfile fields. * @return A modifier for GameProfile fields.
*/ */
@ -620,7 +630,7 @@ public class PacketContainer implements Serializable {
/** /**
* Retrieves a read/write structure for BlockData in Minecraft 1.8. * Retrieves a read/write structure for BlockData in Minecraft 1.8.
* <p> * <p>
* This modifier will automatically marshall between WrappedBlockData and the * This modifier will automatically marshal between WrappedBlockData and the
* internal Minecraft IBlockData. * internal Minecraft IBlockData.
* @return A modifier for BlockData fields. * @return A modifier for BlockData fields.
*/ */
@ -633,7 +643,7 @@ public class PacketContainer implements Serializable {
/** /**
* Retrieves a read/write structure for MultiBlockChangeInfo arrays in Minecraft 1.8. * Retrieves a read/write structure for MultiBlockChangeInfo arrays in Minecraft 1.8.
* <p> * <p>
* This modifier will automatically marshall between MultiBlockChangeInfo and the * This modifier will automatically marshal between MultiBlockChangeInfo and the
* internal Minecraft MultiBlockChangeInfo. * internal Minecraft MultiBlockChangeInfo.
* @return A modifier for BlockData fields. * @return A modifier for BlockData fields.
*/ */
@ -648,7 +658,7 @@ public class PacketContainer implements Serializable {
/** /**
* Retrieves a read/write structure for chat components in Minecraft 1.7.2. * Retrieves a read/write structure for chat components in Minecraft 1.7.2.
* <p> * <p>
* This modifier will automatically marshall between WrappedChatComponent and the * This modifier will automatically marshal between WrappedChatComponent and the
* internal Minecraft IChatBaseComponent. * internal Minecraft IChatBaseComponent.
* @return A modifier for ChatComponent fields. * @return A modifier for ChatComponent fields.
*/ */
@ -887,7 +897,7 @@ public class PacketContainer implements Serializable {
} }
/** /**
* Retrive a read/write structure for the ItemSlot enum in 1.9. * Retrieve a read/write structure for the ItemSlot enum in 1.9.
* @return A modifier for ItemSlot enum fields. * @return A modifier for ItemSlot enum fields.
*/ */
public StructureModifier<ItemSlot> getItemSlots() { public StructureModifier<ItemSlot> getItemSlots() {
@ -896,7 +906,7 @@ public class PacketContainer implements Serializable {
} }
/** /**
* Retrive a read/write structure for the Hand enum in 1.9. * Retrieve a read/write structure for the Hand enum in 1.9.
* @return A modifier for Hand enum fields. * @return A modifier for Hand enum fields.
*/ */
public StructureModifier<Hand> getHands() { public StructureModifier<Hand> getHands() {
@ -904,6 +914,15 @@ public class PacketContainer implements Serializable {
EnumWrappers.getHandClass(), EnumWrappers.getHandConverter()); EnumWrappers.getHandClass(), EnumWrappers.getHandConverter());
} }
/**
* Retrieve a read/write structure for the Direction enum in 1.10.
* @return A modifier for Direction enum fields.
*/
public StructureModifier<Direction> getDirections() {
return structureModifier.<Direction>withType(
EnumWrappers.getDirectionClass(), EnumWrappers.getDirectionConverter());
}
/** /**
* Retrieve a read/write structure for an enum. This allows for the use of * Retrieve a read/write structure for an enum. This allows for the use of
* user-created enums that may not exist in ProtocolLib. The specific (user * user-created enums that may not exist in ProtocolLib. The specific (user

Datei anzeigen

@ -320,6 +320,15 @@ public abstract class EnumWrappers {
OFF_HAND; OFF_HAND;
} }
public enum Direction {
DOWN(),
UP(),
NORTH(),
SOUTH(),
WEST(),
EAST();
}
private static Class<?> PROTOCOL_CLASS = null; private static Class<?> PROTOCOL_CLASS = null;
private static Class<?> CLIENT_COMMAND_CLASS = null; private static Class<?> CLIENT_COMMAND_CLASS = null;
private static Class<?> CHAT_VISIBILITY_CLASS = null; private static Class<?> CHAT_VISIBILITY_CLASS = null;
@ -338,6 +347,7 @@ public abstract class EnumWrappers {
private static Class<?> SOUND_CATEGORY_CLASS = null; private static Class<?> SOUND_CATEGORY_CLASS = null;
private static Class<?> ITEM_SLOT_CLASS = null; private static Class<?> ITEM_SLOT_CLASS = null;
private static Class<?> HAND_CLASS = null; private static Class<?> HAND_CLASS = null;
private static Class<?> DIRECTION_CLASS = null;
private static boolean INITIALIZED = false; private static boolean INITIALIZED = false;
private static Map<Class<?>, EquivalentConverter<?>> FROM_NATIVE = Maps.newHashMap(); private static Map<Class<?>, EquivalentConverter<?>> FROM_NATIVE = Maps.newHashMap();
@ -373,6 +383,7 @@ public abstract class EnumWrappers {
SOUND_CATEGORY_CLASS = getEnum(PacketType.Play.Server.CUSTOM_SOUND_EFFECT.getPacketClass(), 0); SOUND_CATEGORY_CLASS = getEnum(PacketType.Play.Server.CUSTOM_SOUND_EFFECT.getPacketClass(), 0);
ITEM_SLOT_CLASS = getEnum(PacketType.Play.Server.ENTITY_EQUIPMENT.getPacketClass(), 0); ITEM_SLOT_CLASS = getEnum(PacketType.Play.Server.ENTITY_EQUIPMENT.getPacketClass(), 0);
HAND_CLASS = getEnum(PacketType.Play.Client.USE_ENTITY.getPacketClass(), 1); HAND_CLASS = getEnum(PacketType.Play.Client.USE_ENTITY.getPacketClass(), 1);
DIRECTION_CLASS = getEnum(PacketType.Play.Client.USE_ITEM.getPacketClass(), 0);
associate(PROTOCOL_CLASS, Protocol.class, getClientCommandConverter()); associate(PROTOCOL_CLASS, Protocol.class, getClientCommandConverter());
associate(CLIENT_COMMAND_CLASS, ClientCommand.class, getClientCommandConverter()); associate(CLIENT_COMMAND_CLASS, ClientCommand.class, getClientCommandConverter());
@ -392,6 +403,7 @@ public abstract class EnumWrappers {
associate(SOUND_CATEGORY_CLASS, SoundCategory.class, getSoundCategoryConverter()); associate(SOUND_CATEGORY_CLASS, SoundCategory.class, getSoundCategoryConverter());
associate(ITEM_SLOT_CLASS, ItemSlot.class, getItemSlotConverter()); associate(ITEM_SLOT_CLASS, ItemSlot.class, getItemSlotConverter());
associate(HAND_CLASS, Hand.class, getHandConverter()); associate(HAND_CLASS, Hand.class, getHandConverter());
associate(DIRECTION_CLASS, Direction.class, getDirectionConverter());
INITIALIZED = true; INITIALIZED = true;
} }
@ -515,6 +527,11 @@ public abstract class EnumWrappers {
return HAND_CLASS; return HAND_CLASS;
} }
public static Class<?> getDirectionClass() {
initialize();
return DIRECTION_CLASS;
}
// Get the converters // Get the converters
public static EquivalentConverter<Protocol> getProtocolConverter() { public static EquivalentConverter<Protocol> getProtocolConverter() {
return new EnumConverter<Protocol>(Protocol.class); return new EnumConverter<Protocol>(Protocol.class);
@ -588,6 +605,10 @@ public abstract class EnumWrappers {
return new EnumConverter<Hand>(Hand.class); return new EnumConverter<Hand>(Hand.class);
} }
public static EquivalentConverter<Direction> getDirectionConverter() {
return new EnumConverter<Direction>(Direction.class);
}
/** /**
* Retrieve a generic enum converter for use with StructureModifiers. * Retrieve a generic enum converter for use with StructureModifiers.
* @param enumClass - Enum class * @param enumClass - Enum class