Ejemplo n.º 1
0
 /**
  * Retrieves a read/write structure for collections of chunk positions.
  *
  * <p>This modifier will automatically marshall between the visible ProtocolLib ChunkPosition and
  * the internal Minecraft ChunkPosition.
  *
  * @return A modifier for ChunkPosition list fields.
  */
 public StructureModifier<List<ChunkPosition>> getPositionCollectionModifier() {
   // Convert to and from the ProtocolLib wrapper
   return structureModifier.withType(
       Collection.class,
       BukkitConverters.getListConverter(
           MinecraftReflection.getChunkPositionClass(), ChunkPosition.getConverter()));
 }
Ejemplo n.º 2
0
 /**
  * Retrieves a read/write structure for collections of watchable objects.
  *
  * <p>This modifier will automatically marshall 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(
           MinecraftReflection.getWatchableObjectClass(),
           BukkitConverters.getWatchableObjectConverter()));
 }
Ejemplo n.º 3
0
  /**
   * Retrieves a read/write structure for arrays of ItemStacks.
   *
   * <p>This modifier will automatically marshall between the Bukkit ItemStack and the internal
   * Minecraft ItemStack.
   *
   * @return A modifier for ItemStack array fields.
   */
  public StructureModifier<ItemStack[]> getItemArrayModifier() {

    final EquivalentConverter<ItemStack> stackConverter = BukkitConverters.getItemStackConverter();

    // Convert to and from the Bukkit wrapper
    return structureModifier.<ItemStack[]>withType(
        MinecraftReflection.getItemStackArrayClass(),
        BukkitConverters.getIgnoreNull(
            new EquivalentConverter<ItemStack[]>() {

              public Object getGeneric(Class<?> genericType, ItemStack[] specific) {
                Class<?> nmsStack = MinecraftReflection.getItemStackClass();
                Object[] result = (Object[]) Array.newInstance(nmsStack, specific.length);

                // Unwrap every item
                for (int i = 0; i < result.length; i++) {
                  result[i] = stackConverter.getGeneric(nmsStack, specific[i]);
                }
                return result;
              }

              @Override
              public ItemStack[] getSpecific(Object generic) {
                Object[] input = (Object[]) generic;
                ItemStack[] result = new ItemStack[input.length];

                // Add the wrapper
                for (int i = 0; i < result.length; i++) {
                  result[i] = stackConverter.getSpecific(input[i]);
                }
                return result;
              }

              @Override
              public Class<ItemStack[]> getSpecificType() {
                return ItemStack[].class;
              }
            }));
  }
Ejemplo n.º 4
0
 /**
  * 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.
  *
  * @return A modifier entity types.
  */
 public StructureModifier<Entity> getEntityModifier(World world) {
   // Convert to and from the Bukkit wrapper
   return structureModifier.<Entity>withType(
       int.class, BukkitConverters.getEntityConverter(world));
 }
Ejemplo n.º 5
0
 /**
  * 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.<WrappedDataWatcher>withType(
       MinecraftReflection.getDataWatcherClass(), BukkitConverters.getDataWatcherConverter());
 }
Ejemplo n.º 6
0
 /**
  * Retrieves a read/write structure for the world type enum.
  *
  * <p>This modifier will automatically marshall between the Bukkit world type and the internal
  * Minecraft world type.
  *
  * @return A modifier for world type fields.
  */
 public StructureModifier<WorldType> getWorldTypeModifier() {
   // Convert to and from the Bukkit wrapper
   return structureModifier.<WorldType>withType(
       MinecraftReflection.getWorldTypeClass(), BukkitConverters.getWorldTypeConverter());
 }
Ejemplo n.º 7
0
 /**
  * Retrieves a read/write structure for ItemStack.
  *
  * <p>This modifier will automatically marshall 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.<ItemStack>withType(
       MinecraftReflection.getItemStackClass(), BukkitConverters.getItemStackConverter());
 }
Ejemplo n.º 8
0
 /**
  * Retrieves a read/write structure for every byte field.
  *
  * @return A modifier for every byte field.
  */
 public StructureModifier<Byte> getBytes() {
   return structureModifier.withType(byte.class);
 }
Ejemplo n.º 9
0
 /**
  * Retrieves a read/write structure for every String array field.
  *
  * @return A modifier for every String array field.
  */
 public StructureModifier<String[]> getStringArrays() {
   return structureModifier.withType(String[].class);
 }
Ejemplo n.º 10
0
 /**
  * Retrieves a read/write structure for every String field.
  *
  * @return A modifier for every String field.
  */
 public StructureModifier<String> getStrings() {
   return structureModifier.withType(String.class);
 }
Ejemplo n.º 11
0
 /**
  * Retrieves a read/write structure for every double field.
  *
  * @return A modifier for every double field.
  */
 public StructureModifier<Double> getDoubles() {
   return structureModifier.withType(double.class);
 }
Ejemplo n.º 12
0
 /**
  * Retrieves a read/write structure for every float field.
  *
  * @return A modifier for every float field.
  */
 public StructureModifier<Float> getFloat() {
   return structureModifier.withType(float.class);
 }
Ejemplo n.º 13
0
 /**
  * Retrieves a read/write structure for every long field.
  *
  * @return A modifier for every long field.
  */
 public StructureModifier<Long> getLongs() {
   return structureModifier.withType(long.class);
 }
Ejemplo n.º 14
0
 /**
  * Retrieves a read/write structure for every integer field.
  *
  * @return A modifier for every integer field.
  */
 public StructureModifier<Integer> getIntegers() {
   return structureModifier.withType(int.class);
 }
Ejemplo n.º 15
0
 /**
  * Retrieves a read/write structure for every short field.
  *
  * @return A modifier for every short field.
  */
 public StructureModifier<Short> getShorts() {
   return structureModifier.withType(short.class);
 }
Ejemplo n.º 16
0
 /**
  * Retrieves a read/write structure for chunk positions.
  *
  * @return A modifier for a ChunkPosition.
  */
 public StructureModifier<ChunkPosition> getPositionModifier() {
   // Convert to and from the Bukkit wrapper
   return structureModifier.withType(
       MinecraftReflection.getChunkPositionClass(), ChunkPosition.getConverter());
 }
Ejemplo n.º 17
0
 /**
  * Retrieves a read/write structure for NBT classes.
  *
  * @return A modifier for NBT classes.
  */
 public StructureModifier<NbtBase<?>> getNbtModifier() {
   // Allow access to the NBT class in packet 130
   return structureModifier.withType(
       MinecraftReflection.getNBTBaseClass(), BukkitConverters.getNbtConverter());
 }
Ejemplo n.º 18
0
 /**
  * Retrieves a read/write structure for every byte array field.
  *
  * @return A modifier for every byte array field.
  */
 public StructureModifier<byte[]> getByteArrays() {
   return structureModifier.withType(byte[].class);
 }
Ejemplo n.º 19
0
 /**
  * Retrieves a read/write structure for every int array field.
  *
  * @return A modifier for every int array field.
  */
 public StructureModifier<int[]> getIntegerArrays() {
   return structureModifier.withType(int[].class);
 }
Ejemplo n.º 20
0
 /**
  * Retrieves a read/write structure for every field with the given type.
  *
  * @param primitiveType - the type to find.
  * @return A modifier for this specific type.
  */
 public <T> StructureModifier<T> getSpecificModifier(Class<T> primitiveType) {
   return structureModifier.withType(primitiveType);
 }