/** * Gets the first serializer associated with a given class and optional state. * * <p><b>Note</b>: If the serializer is optional, values <i>must<i> be * wrapped in an {@link Optional} * * @param clazz Class to find serializer for * @param optional Optional state * @return The serializer, or null if none exists */ public static Serializer get(Class<?> clazz, boolean optional) { Validate.notNull(clazz, "Class cannot be null!"); initialize(); Validate.notEmpty(REGISTRY, "Registry has no elements!"); for (Serializer serializer : REGISTRY) { if (serializer.getType().equals(clazz) && serializer.isOptional() == optional) { return serializer; } } throw new IllegalArgumentException("No serializer found for " + (optional ? "Optional<" + clazz + ">" : clazz)); }
WrappedDataWatcher.Registry.get(Byte.class)), (byte) 32);
itemSerializer = Registry.get(MinecraftReflection.getItemStackClass()); intSerializer = Registry.get(Integer.class); byteSerializer = Registry.get(Byte.class); stringSerializer = Registry.get(String.class); booleanSerializer = Registry.get(Boolean.class); chatComponentSerializer = Registry.get(MinecraftReflection.getIChatBaseComponentClass(), true);
/** * Gets this watcher object's serializer. Will return null if the * serializer was never specified. * * @return The serializer, or null */ public Serializer getSerializer() { if (getSerializer == null) { getSerializer = Accessors.getMethodAccessor(FuzzyReflection.fromClass(HANDLE_TYPE, true) .getMethodByParameters("getSerializer", MinecraftReflection.getDataWatcherSerializerClass(), new Class[0])); } Object serializer = getSerializer.invoke(handle); if (serializer != null) { Serializer wrapper = Registry.fromHandle(serializer); if (wrapper != null) { return wrapper; } else { return new Serializer(null, serializer, false); } } else { return null; } }
/** * Gets the first serializer associated with a given class. * * <p><b>Note</b>: If {@link Serializer#isOptional() the serializer is optional}, * values <i>must</i> be wrapped in an {@link Optional}.</p> * * <p>If there are multiple serializers for a given class (i.e. BlockPosition), * you should use {@link #get(Class, boolean)} for more precision.</p> * * @param clazz Class to find serializer for * @return The serializer, or null if none exists */ public static Serializer get(Class<?> clazz) { Validate.notNull(clazz,"Class cannot be null!"); initialize(); for (Serializer serializer : REGISTRY) { if (serializer.getType().equals(clazz)) { return serializer; } } throw new IllegalArgumentException("No serializer found for " + clazz); }
/** * Gets the serializer associated with a given NMS handle. * @param handle The handle * @return The serializer, or null if none exists */ public static Serializer fromHandle(Object handle) { Validate.notNull(handle, "handle cannot be null!"); initialize(); for (Serializer serializer : REGISTRY) { if (serializer.getHandle().equals(handle)) { return serializer; } } return null; }
/** * Gets the serializer for UUIDs * @param optional If true, objects <b>must</b> be wrapped in an {@link Optional} * @return The serializer */ public static Serializer getUUIDSerializer(boolean optional) { return get(UUID.class, optional); }
/** * Gets the serializer for Directions * @return The serializer */ public static Serializer getDirectionSerializer() { return get(EnumWrappers.getDirectionClass()); }
/** * Gets the serializer for Vector3Fs * @return The serializer */ public static Serializer getVectorSerializer() { return get(Vector3F.getMinecraftClass()); }
/** * Gets the serializer for IChatBaseComponents * @param optional If true, objects <b>must</b> be wrapped in an {@link Optional} * @return The serializer */ public static Serializer getChatComponentSerializer(boolean optional) { return get(MinecraftReflection.getIChatBaseComponentClass(), optional); }
/** * Gets the serializer for NBT Compound tags * @return The serializer */ public static Serializer getNBTCompoundSerializer() { return get(MinecraftReflection.getNBTCompoundClass(), false); } }
/** * Gets the serializer for BlockData * @param optional If true, objects <b>must</b> be wrapped in an {@link Optional} * @return The serializer */ public static Serializer getBlockDataSerializer(boolean optional) { return get(MinecraftReflection.getIBlockDataClass(), optional); }
/** * Gets the serializer for ItemStacks * @param optional If true, objects <b>must</b> be wrapped in an {@link Optional} * @return The serializer */ public static Serializer getItemStackSerializer(boolean optional) { return get(MinecraftReflection.getItemStackClass(), optional); }
/** * Gets the serializer for IChatBaseComponents * @return The serializer */ public static Serializer getChatComponentSerializer() { return getChatComponentSerializer(false); }
/** * Gets the serializer for BlockPositions * @param optional If true, objects <b>must</b> be wrapped in an {@link Optional} * @return The serializer */ public static Serializer getBlockPositionSerializer(boolean optional) { return get(MinecraftReflection.getBlockPositionClass(), optional); }