/** * Retrieve every NMS to/from Bukkit converter as unwrappers. * @return Every unwrapper. */ public static List<Unwrapper> getUnwrappers() { if (unwrappers == null) { ImmutableList.Builder<Unwrapper> builder = ImmutableList.builder(); for (Map.Entry<Class<?>, EquivalentConverter<Object>> entry : getConvertersForGeneric().entrySet()) { builder.add(asUnwrapper(entry.getKey(), entry.getValue())); } unwrappers = builder.build(); } return unwrappers; }
/** * Retrieves a read/write structure for entity objects. * <p> * Note that entities are transmitted by integer ID, and the type may not be enough * to distinguish between entities and other values. Thus, this structure modifier * MAY return null or invalid entities for certain fields. Using the correct index * is essential. * * @param world - the world each entity is currently occupying. * @return A modifier entity types. */ public StructureModifier<Entity> getEntityModifier(@Nonnull World world) { Preconditions.checkNotNull(world, "world cannot be NULL."); // Convert to and from the Bukkit wrapper return structureModifier.withType( int.class, BukkitConverters.getEntityConverter(world)); }
/** * Retrieves a read/write structure for lists of ItemStacks. * <p> * This modifier will automatically marshal between the Bukkit ItemStack and the * internal Minecraft ItemStack. * @return A modifier for ItemStack list fields. */ public StructureModifier<List<ItemStack>> getItemListModifier() { // Convert to and from the Bukkit wrapper return structureModifier.withType( List.class, BukkitConverters.getListConverter(BukkitConverters.getItemStackConverter()) ); }
/** * Retrieves a read/write structure for lists of NBT classes. * @return A modifier for lists of NBT classes. */ public StructureModifier<List<NbtBase<?>>> getListNbtModifier() { // Convert to and from the ProtocolLib wrapper return structureModifier.withType( Collection.class, BukkitConverters.getListConverter(BukkitConverters.getNbtConverter()) ); }
/** * Retrieves a read/write structure for collections of watchable objects. * <p> * This modifier will automatically marshal between the visible WrappedWatchableObject and the * internal Minecraft WatchableObject. * @return A modifier for watchable object list fields. */ public StructureModifier<List<WrappedWatchableObject>> getWatchableCollectionModifier() { // Convert to and from the ProtocolLib wrapper return structureModifier.withType( Collection.class, BukkitConverters.getListConverter(BukkitConverters.getWatchableObjectConverter())); }
put(MinecraftReflection.getDataWatcherClass(), (EquivalentConverter) getDataWatcherConverter()). put(MinecraftReflection.getItemStackClass(), (EquivalentConverter) getItemStackConverter()). put(MinecraftReflection.getNBTBaseClass(), (EquivalentConverter) getNbtConverter()). put(MinecraftReflection.getNBTCompoundClass(), (EquivalentConverter) getNbtConverter()). put(MinecraftReflection.getDataWatcherItemClass(), (EquivalentConverter) getWatchableObjectConverter()). put(MinecraftReflection.getMobEffectClass(), (EquivalentConverter) getPotionEffectConverter()). put(MinecraftReflection.getNmsWorldClass(), (EquivalentConverter) getWorldConverter()); builder.put(MinecraftReflection.getWorldTypeClass(), (EquivalentConverter) getWorldTypeConverter()); if (hasAttributeSnapshot) builder.put(MinecraftReflection.getAttributeSnapshotClass(), (EquivalentConverter) getWrappedAttributeConverter()); builder.put(MinecraftReflection.getBlockClass(), (EquivalentConverter) getBlockConverter()); builder.put(MinecraftReflection.getGameProfileClass(), (EquivalentConverter) getWrappedGameProfileConverter()); builder.put(MinecraftReflection.getIChatBaseComponentClass(), (EquivalentConverter) getWrappedChatComponentConverter()); builder.put(MinecraftReflection.getServerPingClass(), (EquivalentConverter) getWrappedServerPingConverter()); builder.put(MinecraftReflection.getStatisticClass(), (EquivalentConverter) getWrappedStatisticConverter());
return ((WrappedChatComponent) wrapped).getHandle(); } else if (wrapped instanceof ItemStack) { return BukkitConverters.getItemStackConverter().getGeneric((ItemStack) wrapped); } else if (wrapped instanceof WrappedBlockData) { return BukkitConverters.getWrappedBlockDataConverter().getGeneric((WrappedBlockData) wrapped); } else if (wrapped instanceof Vector3F) { return Vector3F.getConverter().getGeneric((Vector3F) wrapped);
/** * Retrieves a read/write structure for collections of attribute snapshots. * <p> * This modifier will automatically marshal between the visible ProtocolLib WrappedAttribute and the * internal Minecraft AttributeSnapshot. * @return A modifier for AttributeSnapshot collection fields. */ public StructureModifier<List<WrappedAttribute>> getAttributeCollectionModifier() { // Convert to and from the ProtocolLib wrapper return structureModifier.withType( Collection.class, BukkitConverters.getListConverter(BukkitConverters.getWrappedAttributeConverter()) ); }
/** * Retrieve the closest equivalent converter to a specific class. * @param clazz - the class. * @return The closest converter, or NULL if not found, */ private EquivalentConverter<Object> findConverter(Class<?> clazz) { Map<Class<?>, EquivalentConverter<Object>> converters = BukkitConverters.getConvertersForGeneric(); while (clazz != null) { EquivalentConverter<Object> result = converters.get(clazz); if (result != null) return result; else clazz = clazz.getSuperclass(); } return null; }
/** * Retrieve a read/write structure for the List class. * @param converter Converter for elements * @param <E> Element param * @return A modifier for List fields */ public <E> StructureModifier<List<E>> getLists(EquivalentConverter<E> converter) { return structureModifier.withType( List.class, BukkitConverters.getListConverter(converter)); }
/** * Retrieves a read/write structure for block fields. * <p> * This modifier will automatically marshal between Material and the * internal Minecraft Block. * @return A modifier for GameProfile fields. */ public StructureModifier<Material> getBlocks() { // Convert to and from the Bukkit wrapper return structureModifier.withType( MinecraftReflection.getBlockClass(), BukkitConverters.getBlockConverter()); }
/** * Retrieves a read/write structure for ItemStack. * <p> * This modifier will automatically marshal between the Bukkit ItemStack and the * internal Minecraft ItemStack. * @return A modifier for ItemStack fields. */ public StructureModifier<ItemStack> getItemModifier() { // Convert to and from the Bukkit wrapper return structureModifier.withType( MinecraftReflection.getItemStackClass(), BukkitConverters.getItemStackConverter()); }
/** * Retrieve a read/write structure for the Map class. * @param keyConverter Converter for map keys * @param valConverter Converter for map values * @param <K> Key param * @param <V> Value param * @return A modifier for Map fields. * * @see BukkitConverters * @see EquivalentConverter */ public <K, V> StructureModifier<Map<K, V>> getMaps(EquivalentConverter<K> keyConverter, EquivalentConverter<V> valConverter) { return structureModifier.withType( Map.class, BukkitConverters.getMapConverter(keyConverter, valConverter)); }
/** * Retrive a read/write structure for dimension IDs in 1.13.1+ * @return A modifier for dimension IDs */ public StructureModifier<Integer> getDimensions() { return structureModifier.withType( MinecraftReflection.getMinecraftClass("DimensionManager"), BukkitConverters.getDimensionIDConverter() ); }
/** * Retrieves a read/write structure for data watchers. * @return A modifier for data watchers. */ public StructureModifier<WrappedDataWatcher> getDataWatcherModifier() { // Convert to and from the Bukkit wrapper return structureModifier.withType( MinecraftReflection.getDataWatcherClass(), BukkitConverters.getDataWatcherConverter()); }
/** * Retrieve a read/write structure for the MobEffectList class in 1.9. * @return A modifier for MobEffectList fields. */ public StructureModifier<PotionEffectType> getEffectTypes() { // Convert to and from Bukkit return structureModifier.withType( MinecraftReflection.getMobEffectListClass(), BukkitConverters.getEffectTypeConverter()); }
return WrappedChatComponent.fromHandle(value); } else if (is(MinecraftReflection.getItemStackClass(), value)) { return BukkitConverters.getItemStackConverter().getSpecific(value); } else if (is(MinecraftReflection.getIBlockDataClass(), value)) { return BukkitConverters.getWrappedBlockDataConverter().getSpecific(value); } else if (is (Vector3F.getMinecraftClass(), value)) { return Vector3F.getConverter().getSpecific(value);
/** * Retrieve a read/write structure for the PlayerInfoData list fields in the following packet: <br> * <ul> * <li>{@link PacketType.Play.Server#PLAYER_INFO} * </ul> * @return A modifier for PlayerInfoData list fields. */ public StructureModifier<List<PlayerInfoData>> getPlayerInfoDataLists() { // Convert to and from the ProtocolLib wrapper return structureModifier.withType( Collection.class, BukkitConverters.getListConverter(PlayerInfoData.getConverter())); }
@Override public Material getType() { Object block = GET_BLOCK.invoke(handle); return BukkitConverters.getBlockConverter().getSpecific(block); }
private static Object getItem(Object handle) { return new StructureModifier<>(handle.getClass()) .withTarget(handle) .withType(MinecraftReflection.getItemStackClass(), BukkitConverters.getItemStackConverter()) .read(0); }