/** * Construct an attribute modifier wrapper around a NMS instance. * @param handle - the NMS instance. * @param uuid - the UUID. * @param name - the human readable name. * @param amount - the amount. * @param operation - the operation. */ protected WrappedAttributeModifier(@Nonnull Object handle, UUID uuid, String name, double amount, Operation operation) { this(uuid, name, amount, operation); // Initialize handle and modifier setHandle(handle); initializeModifier(handle); }
/** * Construct an attribute modifier wrapper around a given NMS instance. * @param handle - the NMS instance. */ @SuppressWarnings("unchecked") protected WrappedAttributeModifier(@Nonnull Object handle) { // Update handle and modifier super(MinecraftReflection.getAttributeModifierClass()); setHandle(handle); initializeModifier(handle); // Load final values, caching them this.uuid = (UUID) modifier.withType(UUID.class).read(0); StructureModifier<String> stringMod = modifier.withType(String.class); if (stringMod.size() == 0) { Supplier<String> supplier = (Supplier<String>) modifier.withType(Supplier.class).read(0); this.name = supplier; } else { this.name = () -> stringMod.read(0); } this.amount = (Double) modifier.withType(double.class).read(0); this.operation = Operation.fromId((Integer) modifier.withType(int.class).read(0)); }