Java Code Examples for com.captainbern.reflection.Reflection

The following examples show how to use com.captainbern.reflection.Reflection. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public <T extends ControllableEntityHandle<? extends LivingEntity>> T createHandle(ControllableEntity entity, Location location) {
    SafeConstructor<ControllableEntityHandle> entityConstructor = new Reflection().reflect(entity.getEntityType().getHandleClass()).getSafeConstructor(World.class, entity.getEntityType().getControllableInterface());

    EntityRegistrationEntry oldEntry = GameRegistry.get(IEntityRegistry.class).getDefaultEntryFor(entity.getEntityType());
    GameRegistry.get(IEntityRegistry.class).register(new EntityRegistrationEntry(
            entity.getEntityType().getName(),
            entity.getEntityType().getId(),
            entity.getEntityType().getHandleClass()
    ));

    WorldServer worldServer = ((CraftWorld) location.getWorld()).getHandle();
    T handle = (T) entityConstructor.getAccessor().invoke(worldServer, entity);

    handle.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    worldServer.addEntity((net.minecraft.server.v1_7_R1.Entity) handle, CreatureSpawnEvent.SpawnReason.CUSTOM);

    GameRegistry.get(IEntityRegistry.class).register(oldEntry);

    Material beneath = location.getBlock().getRelative(BlockFace.DOWN).getType();
    if (beneath.isBlock()) { // What lies beneath
        ((Entity) handle).onGround = true;
    }

    return handle;
}
 
Example 2
@Override
public <T extends ControllableEntityHandle<? extends LivingEntity>> T createHandle(ControllableEntity entity, Location location) {
    SafeConstructor<ControllableEntityHandle> entityConstructor = new Reflection().reflect(entity.getEntityType().getHandleClass()).getSafeConstructor(World.class, entity.getEntityType().getControllableInterface());

    EntityRegistrationEntry oldEntry = GameRegistry.get(IEntityRegistry.class).getDefaultEntryFor(entity.getEntityType());
    GameRegistry.get(IEntityRegistry.class).register(new EntityRegistrationEntry(
            entity.getEntityType().getName(),
            entity.getEntityType().getId(),
            entity.getEntityType().getHandleClass()
    ));

    WorldServer worldServer = ((CraftWorld) location.getWorld()).getHandle();
    T handle = (T) entityConstructor.getAccessor().invoke(worldServer, entity);

    handle.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    worldServer.addEntity((net.minecraft.server.v1_7_R1.Entity) handle, CreatureSpawnEvent.SpawnReason.CUSTOM);

    GameRegistry.get(IEntityRegistry.class).register(oldEntry);

    Material beneath = location.getBlock().getRelative(BlockFace.DOWN).getType();
    if (beneath.isBlock()) { // What lies beneath
        ((Entity) handle).onGround = true;
    }

    return handle;
}
 
Example 3
private void initializeGameComponents() {
    try {

        Class<? extends IEntityRegistry> entityRegistry = Class.forName(EntityAPI.INTERNAL_NMS_PATH + ".game.EntityRegistry").asSubclass(IEntityRegistry.class);
        GameRegistry.registerPermanently(IEntityRegistry.class, new Reflection().reflect(entityRegistry).getSafeConstructor().getAccessor().invoke());

        Class<? extends IEntitySpawnHandler> spawnHandler = Class.forName(EntityAPI.INTERNAL_NMS_PATH + ".game.EntitySpawnHandler").asSubclass(IEntitySpawnHandler.class);
        GameRegistry.register(IEntitySpawnHandler.class, new Reflection().reflect(spawnHandler).getSafeConstructor().getAccessor().invoke());

    } catch (Exception e) {
        ConsoleCommandSender console = this.getServer().getConsoleSender();
        console.sendMessage(ChatColor.RED + "-------------------------------");
        console.sendMessage(ChatColor.RED + "Failed to initialize the game components!");
        console.sendMessage(ChatColor.RED + "-------------------------------");
    }
}
 
Example 4
private void cQ() {
    // Possibly just call the method instead...But that won't work with Cauldron :\
    if (!this.world.isStatic) {
        // int bE
        SafeField<Integer> field_bE = (SafeField<Integer>) new Reflection().reflect(EntityHorse.class).getSafeFields(withExactType(Integer.class)).get(1);
        field_bE.getAccessor().set(this, 1);

        // Open the horse's mouth (animation 128)
        this.horseVisual(128, true);
    }
}
 
Example 5
private void cS() {
    if (!this.world.isStatic) {
        // int bF
        SafeField<Integer> field_bF = (SafeField<Integer>) new Reflection().reflect(EntityHorse.class).getSafeFields(withExactType(Integer.class)).get(2);
        field_bF.getAccessor().set(this, 1);

        // Stop looking down (animation 32)
        this.p(true);
    }
}
 
Example 6
@Override
public void onRide(float[] motion) {
    EntityLiving entity = (EntityLiving) this.getControllableEntity().getHandle();
    if (entity.passenger == null) {
        return;
    }

    if (!canControl((LivingEntity) entity.getBukkitEntity())) {
        return;
    }

    entity.X = 0.5F;

    entity.lastYaw = entity.yaw = entity.passenger.yaw;
    entity.pitch = entity.passenger.pitch * 0.5F;

    if (this.isVehicleMotionOverriden() || motion[0] == 0.0F) {
        motion[0] = ((EntityLiving) entity.passenger).be * 0.5F;
    }
    if (this.isVehicleMotionOverriden() || motion[2] == 0.0F) {
        motion[2] = ((EntityLiving) entity.passenger).bf;
    }

    // boolean bD
    boolean jumping = (Boolean) new Reflection().reflect(EntityHorse.class).getSafeFields(withExactType(Boolean.class)).get(2).getAccessor().get(entity);
    if (this.canFly()) {
        if (jumping) {
            motion[1] = 0.5F;
        } else if (entity.passenger.pitch >= 50) {
            motion[1] = -0.25F;
        }
    } else if (entity.onGround && this.isJumpingEnabled()) {
        if (jumping) {
            motion[1] = 0.5F;
        }
    }
}
 
Example 7
protected void swapFields() {
    if (CHANNEL_FIELD == null) {
        CHANNEL_FIELD = new Reflection().reflect(NetworkManager.class).getSafeFieldByType(Channel.class).getAccessor();
    }

    if (ADDRESS_FIELD == null) {
        ADDRESS_FIELD = new Reflection().reflect(NetworkManager.class).getSafeFieldByType(InetSocketAddress.class).getAccessor();
    }

    CHANNEL_FIELD.set(this, new NullChannel(null));
    ADDRESS_FIELD.set(this, null);
}
 
Example 8
private void cQ() {
    // Possibly just call the method instead...But that won't work with Cauldron :\
    if (!this.world.isStatic) {
        // int bE
        SafeField<Integer> field_bE = (SafeField<Integer>) new Reflection().reflect(EntityHorse.class).getSafeFields(withExactType(Integer.class)).get(1);
        field_bE.getAccessor().set(this, 1);

        // Open the horse's mouth (animation 128)
        this.horseVisual(128, true);
    }
}
 
Example 9
private void cS() {
    if (!this.world.isStatic) {
        // int bF
        SafeField<Integer> field_bF = (SafeField<Integer>) new Reflection().reflect(EntityHorse.class).getSafeFields(withExactType(Integer.class)).get(2);
        field_bF.getAccessor().set(this, 1);

        // Stop looking down (animation 32)
        this.p(true);
    }
}
 
Example 10
@Override
public void onRide(float[] motion) {
    EntityLiving entity = (EntityLiving) this.getControllableEntity().getHandle();
    if (entity.passenger == null) {
        return;
    }

    if (!canControl((LivingEntity) entity.getBukkitEntity())) {
        return;
    }

    entity.X = 0.5F;

    entity.lastYaw = entity.yaw = entity.passenger.yaw;
    entity.pitch = entity.passenger.pitch * 0.5F;

    if (this.isVehicleMotionOverriden() || motion[0] == 0.0F) {
        motion[0] = ((EntityLiving) entity.passenger).be * 0.5F;
    }
    if (this.isVehicleMotionOverriden() || motion[2] == 0.0F) {
        motion[2] = ((EntityLiving) entity.passenger).bf;
    }

    // boolean bD
    boolean jumping = (Boolean) new Reflection().reflect(EntityHorse.class).getSafeFields(withExactType(Boolean.class)).get(2).getAccessor().get(entity);
    if (this.canFly()) {
        if (jumping) {
            motion[1] = 0.5F;
        } else if (entity.passenger.pitch >= 50) {
            motion[1] = -0.25F;
        }
    } else if (entity.onGround && this.isJumpingEnabled()) {
        if (jumping) {
            motion[1] = 0.5F;
        }
    }
}
 
Example 11
protected void swapFields() {
    if (CHANNEL_FIELD == null) {
        CHANNEL_FIELD = new Reflection().reflect(NetworkManager.class).getSafeFieldByType(Channel.class).getAccessor();
    }

    if (ADDRESS_FIELD == null) {
        ADDRESS_FIELD = new Reflection().reflect(NetworkManager.class).getSafeFieldByType(InetSocketAddress.class).getAccessor();
    }

    CHANNEL_FIELD.set(this, new NullChannel(null));
    ADDRESS_FIELD.set(this, null);
}
 
Example 12
private SafeConstructor<ControllableEntityHandle> getConstructorFor(ControllableEntityType type) {
    SafeConstructor<ControllableEntityHandle> entityTypeSafeConstructor = typeToConstructor.get(type);

    if (entityTypeSafeConstructor == null) {
        entityTypeSafeConstructor = (SafeConstructor<ControllableEntityHandle>) new Reflection().reflect(type.getHandleClass()).getSafeConstructor(World.class, type.getControllableInterface());
        typeToConstructor.put(type, entityTypeSafeConstructor);
    }

    return entityTypeSafeConstructor;
}
 
Example 13
private void cQ() {
    // Possibly just call the method instead...But that won't work with Cauldron :\
    if (!this.world.isStatic) {
        // int bE
        SafeField<Integer> field_bE = (SafeField<Integer>) new Reflection().reflect(EntityHorse.class).getSafeFields(withExactType(Integer.class)).get(1);
        field_bE.getAccessor().set(this, 1);

        // Open the horse's mouth (animation 128)
        this.horseVisual(128, true);
    }
}
 
Example 14
private void cS() {
    if (!this.world.isStatic) {
        // int bF
        SafeField<Integer> field_bF = (SafeField<Integer>) new Reflection().reflect(EntityHorse.class).getSafeFields(withExactType(Integer.class)).get(2);
        field_bF.getAccessor().set(this, 1);

        // Stop looking down (animation 32)
        this.p(true);
    }
}
 
Example 15
@Override
public void onRide(float[] motion) {
    EntityLiving entity = (EntityLiving) this.getControllableEntity().getHandle();
    if (entity.passenger == null) {
        return;
    }

    if (!canControl((LivingEntity) entity.getBukkitEntity())) {
        return;
    }

    entity.X = 0.5F;

    entity.lastYaw = entity.yaw = entity.passenger.yaw;
    entity.pitch = entity.passenger.pitch * 0.5F;

    if (this.isVehicleMotionOverriden() || motion[0] == 0.0F) {
        motion[0] = ((EntityLiving) entity.passenger).be * 0.5F;
    }
    if (this.isVehicleMotionOverriden() || motion[2] == 0.0F) {
        motion[2] = ((EntityLiving) entity.passenger).bf;
    }

    // boolean bD
    boolean jumping = (Boolean) new Reflection().reflect(EntityHorse.class).getSafeFields(withExactType(Boolean.class)).get(2).getAccessor().get(entity);
    if (this.canFly()) {
        if (jumping) {
            motion[1] = 0.5F;
        } else if (entity.passenger.pitch >= 50) {
            motion[1] = -0.25F;
        }
    } else if (entity.onGround && this.isJumpingEnabled()) {
        if (jumping) {
            motion[1] = 0.5F;
        }
    }
}
 
Example 16
protected void swapFields() {
    if (CHANNEL_FIELD == null) {
        CHANNEL_FIELD = new Reflection().reflect(NetworkManager.class).getSafeFieldByType(Channel.class).getAccessor();
    }

    if (ADDRESS_FIELD == null) {
        ADDRESS_FIELD = new Reflection().reflect(NetworkManager.class).getSafeFieldByType(SocketAddress.class).getAccessor();
    }

    CHANNEL_FIELD.set(this, new NullChannel(null));
    ADDRESS_FIELD.set(this, new SocketAddress() {});
}
 
Example 17
Source Project: EntityAPI   Source File: Behaviour.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
protected Behaviour(Object... args) {
    Class<?>[] classes = new Class[args.length];
    if (args.length > 0) {
        for (int i = 0; i < args.length; i++) {
            classes[i] = args[i].getClass();
        }
    }
    this.behaviourGoal = (BehaviourGoal) new Reflection().reflect(EntityAPI.INTERNAL_NMS_PATH + ".entity.mind.behaviour.goals.BehaviourGoal" + this.getKey()).getSafeConstructor(classes).getAccessor().invoke(args);
}
 
Example 18
public ControllableBaseEntity(int id, ControllableEntityType entityType, EntityManager manager) {
    this.accessor = (NMSAccessor<T, S>) new Reflection().reflect(EntityAPI.INTERNAL_NMS_PATH + ".NMSAccessorImpl").getSafeConstructor(ControllableEntity.class).getAccessor().invoke(this);
    this.manager = manager;
    this.ID = id;
    this.mind = new Mind();
    this.mind.setControllableEntity(this);
    this.entityType = entityType;
    this.initSounds();
}
 
Example 19
Source Project: EntityAPI   Source File: EntityUtil.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
protected static void initializeFields() {
    try {

        ClassTemplate goalTemplate = new Reflection().reflect(MinecraftReflection.getMinecraftClass("PathfinderGoalSelector"));

        List<SafeMethod<Void>> methodCandidates = goalTemplate.getSafeMethods(withArguments(int.class, MinecraftReflection.getMinecraftClass("PathfinderGoal")));
        if (methodCandidates.size() > 0) {
            ADD_GOAL = methodCandidates.get(0).getAccessor();
        } else {
            throw new RuntimeException("Failed to get the addGoal method!");
        }

        List<SafeField<List>> fieldCandidates = goalTemplate.getSafeFields(withType(List.class));
        if (fieldCandidates.size() > 1) {
            GOALS = fieldCandidates.get(0).getAccessor();
            ACTIVE_GOALS = fieldCandidates.get(0).getAccessor();
        } else {
            throw new RuntimeException("Failed to initialize the goal-lists!");
        }

        // The GoalSelector
        ClassTemplate entityTemplate = new Reflection().reflect(MinecraftReflection.getMinecraftClass("EntityInsentient"));
        List<SafeField<Object>> candidates = entityTemplate.getSafeFields(withType(goalTemplate.getReflectedClass()));

        if (candidates.size() > 0) {
            GOAL_SELECTOR = candidates.get(0).getAccessor(); // the normal selector is the first one
        } else {
            throw new RuntimeException("Failed to initialize the GoalSelector field for the entities");
        }

    } catch (Exception ಠ_ಠ) {
        throw new RuntimeException("Failed to initialize the goal-related fields!", ಠ_ಠ);
    }
}
 
Example 20
private SafeConstructor<ControllableEntityHandle> getConstructorFor(ControllableEntityType type) {
    SafeConstructor<ControllableEntityHandle> entityTypeSafeConstructor = typeToConstructor.get(type);

    if (entityTypeSafeConstructor == null) {
        entityTypeSafeConstructor = (SafeConstructor<ControllableEntityHandle>) new Reflection().reflect(type.getHandleClass()).getSafeConstructor(World.class, type.getControllableInterface());
        typeToConstructor.put(type, entityTypeSafeConstructor);
    }

    return entityTypeSafeConstructor;
}
 
Example 21
private void cQ() {
    // Possibly just call the method instead...But that won't work with Cauldron :\
    if (!this.world.isStatic) {
        // int bE
        SafeField<Integer> field_bE = (SafeField<Integer>) new Reflection().reflect(EntityHorse.class).getSafeFields(withExactType(Integer.class)).get(1);
        field_bE.getAccessor().set(this, 1);

        // Open the horse's mouth (animation 128)
        this.horseVisual(128, true);
    }
}
 
Example 22
private void cS() {
    if (!this.world.isStatic) {
        // int bF
        SafeField<Integer> field_bF = (SafeField<Integer>) new Reflection().reflect(EntityHorse.class).getSafeFields(withExactType(Integer.class)).get(2);
        field_bF.getAccessor().set(this, 1);

        // Stop looking down (animation 32)
        this.p(true);
    }
}
 
Example 23
@Override
public void onRide(float[] motion) {
    EntityLiving entity = (EntityLiving) this.getControllableEntity().getHandle();
    if (entity.passenger == null) {
        return;
    }

    if (!canControl((LivingEntity) entity.getBukkitEntity())) {
        return;
    }

    entity.X = 0.5F;

    entity.lastYaw = entity.yaw = entity.passenger.yaw;
    entity.pitch = entity.passenger.pitch * 0.5F;

    if (this.isVehicleMotionOverriden() || motion[0] == 0.0F) {
        motion[0] = ((EntityLiving) entity.passenger).be * 0.5F;
    }
    if (this.isVehicleMotionOverriden() || motion[2] == 0.0F) {
        motion[2] = ((EntityLiving) entity.passenger).bf;
    }

    // boolean bD
    boolean jumping = (Boolean) new Reflection().reflect(EntityHorse.class).getSafeFields(withExactType(Boolean.class)).get(2).getAccessor().get(entity);
    if (this.canFly()) {
        if (jumping) {
            motion[1] = 0.5F;
        } else if (entity.passenger.pitch >= 50) {
            motion[1] = -0.25F;
        }
    } else if (entity.onGround && this.isJumpingEnabled()) {
        if (jumping) {
            motion[1] = 0.5F;
        }
    }
}
 
Example 24
protected void swapFields() {
    if (CHANNEL_FIELD == null) {
        CHANNEL_FIELD = new Reflection().reflect(NetworkManager.class).getSafeFieldByType(Channel.class).getAccessor();
    }

    if (ADDRESS_FIELD == null) {
        ADDRESS_FIELD = new Reflection().reflect(NetworkManager.class).getSafeFieldByType(SocketAddress.class).getAccessor();
    }

    CHANNEL_FIELD.set(this, new NullChannel(null));
    ADDRESS_FIELD.set(this, new SocketAddress() {});
}
 
Example 25
Source Project: EchoPet   Source File: NMSEntityUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected static void initializeFields() {
    try {

        ClassTemplate goalTemplate = new Reflection().reflect(MinecraftReflection.getMinecraftClass("PathfinderGoalSelector"));

        List<SafeMethod<Void>> methodCandidates = goalTemplate.getSafeMethods(withArguments(int.class, MinecraftReflection.getMinecraftClass("PathfinderGoal")));
        if (methodCandidates.size() > 0) {
            ADD_GOAL = methodCandidates.get(0).getAccessor();
        } else {
            throw new RuntimeException("Failed to get the addGoal method!");
        }

        List<SafeField<List>> fieldCandidates = goalTemplate.getSafeFields(withType(List.class));
        if (fieldCandidates.size() > 1) {
            GOALS = fieldCandidates.get(0).getAccessor();
            ACTIVE_GOALS = fieldCandidates.get(0).getAccessor();
        } else {
            throw new RuntimeException("Failed to initialize the goal-lists!");
        }

        // The GoalSelector
        ClassTemplate entityTemplate = new Reflection().reflect(MinecraftReflection.getMinecraftClass("EntityInsentient"));
        List<SafeField<Object>> candidates = entityTemplate.getSafeFields(withType(goalTemplate.getReflectedClass()));

        if (candidates.size() > 0) {
            GOAL_SELECTOR = candidates.get(0).getAccessor(); // the normal selector is the first one
        } else {
            throw new RuntimeException("Failed to initialize the GoalSelector field for the entities");
        }

    } catch (Exception ಠ_ಠ) {
        throw new RuntimeException("Failed to initialize the goal-related fields!", ಠ_ಠ);
    }
}
 
Example 26
Source Project: EchoPet   Source File: NMSEntityUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected static void initializeFields() {
    try {

        ClassTemplate goalTemplate = new Reflection().reflect(MinecraftReflection.getMinecraftClass("PathfinderGoalSelector"));

        List<SafeMethod<Void>> methodCandidates = goalTemplate.getSafeMethods(withArguments(int.class, MinecraftReflection.getMinecraftClass("PathfinderGoal")));
        if (methodCandidates.size() > 0) {
            ADD_GOAL = methodCandidates.get(0).getAccessor();
        } else {
            throw new RuntimeException("Failed to get the addGoal method!");
        }

        List<SafeField<List>> fieldCandidates = goalTemplate.getSafeFields(withType(List.class));
        if (fieldCandidates.size() > 1) {
            GOALS = fieldCandidates.get(0).getAccessor();
            ACTIVE_GOALS = fieldCandidates.get(0).getAccessor();
        } else {
            throw new RuntimeException("Failed to initialize the goal-lists!");
        }

        // The GoalSelector
        ClassTemplate entityTemplate = new Reflection().reflect(MinecraftReflection.getMinecraftClass("EntityInsentient"));
        List<SafeField<Object>> candidates = entityTemplate.getSafeFields(withType(goalTemplate.getReflectedClass()));

        if (candidates.size() > 0) {
            GOAL_SELECTOR = candidates.get(0).getAccessor(); // the normal selector is the first one
        } else {
            throw new RuntimeException("Failed to initialize the GoalSelector field for the entities");
        }

    } catch (Exception ಠ_ಠ) {
        throw new RuntimeException("Failed to initialize the goal-related fields!", ಠ_ಠ);
    }
}
 
Example 27
Source Project: EntityAPI   Source File: Attribute.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
protected T getNewEvent(final Object... args) {
    Type paramType = this.getClass().getGenericSuperclass();
    Class<?> paramClass = (Class<?>) paramType;

    Type paramEventType = paramClass.getGenericSuperclass();
    Class<T> event = (Class<T>) ((ParameterizedType) paramEventType).getActualTypeArguments()[0];

    ClassTemplate<T> template = new Reflection().reflect(event);

    try {

        List<SafeConstructor<T>> candidates = template.getSafeConstructors(new AbstractMatcher<Constructor>() {
            @Override
            public boolean matches(Constructor constructor) {
                if (constructor.getParameterTypes().length != args.length)
                    return false;

                Class<?>[] argTypes = constructor.getParameterTypes();
                for (int i = 0; i < argTypes.length; i++) {
                    if (!argTypes[i].isAssignableFrom(args[i].getClass()))
                        return false;
                }
                return true;
            }
        });

        if (candidates.size() > 0) {
            return candidates.get(0).getAccessor().invoke(args);
        } else {
            throw new IllegalStateException(); // Will throw a "proper" exception
        }

    } catch (Exception e) { // TODO: Should we be throwing exceptions?
        if (args.length > 0) {
            String argBuilder = args[0].getClass().getCanonicalName();
            for (int i = 1; i < args.length; i++) {
                argBuilder += ", " + args[i].getClass().getCanonicalName();
            }

            throw new RuntimeException("Failed to get the right constructor! (Event class: " + event.getCanonicalName() +
                    "\nArguments: " + argBuilder);
        } else {
            throw new RuntimeException("Failed to get the right constructor! (Event class: " + event.getCanonicalName() + ")");
        }
    }
}
 
Example 28
public ControllableEntity create() {
    if (this.type == null)
        throw new NullPointerException("ControllableEntity Type cannot be null.");

    if (this.location == null)
        throw new NullPointerException("Location cannot be null.");

    if (this.type.isNameRequired() && this.name.isEmpty())
        throw new IllegalStateException("Entity: " + this.type.toString() + " requires a name!");

    int id = this.entityManager.getNextID();
    ControllableEntity entity;

    if (this.type.isNameRequired()) {

        // Fix the name, in case it's too long
        if (this.name.length() > 16)
            this.name = name.substring(0, 16);

        entity = new Reflection().reflect(this.type.getControllableClass()).getSafeConstructor(int.class, String.class, EntityManager.class).getAccessor().invoke(id, this.name, this.entityManager);
    } else {
         entity = new Reflection().reflect(this.type.getControllableClass()).getSafeConstructor(int.class, EntityManager.class).getAccessor().invoke(id, this.entityManager);
    }

    if (entity != null) {
        if (this.prepare || this.mind == null) {
            this.mind = new Mind();
        }
        this.mind.setControllableEntity(entity);
        if (this.prepare) {
            entity.setDefaultBehaviours();
        } else {
            for (Map.Entry<Behaviour, Integer> entry : this.behaviours.entrySet()) {
                entity.getMind().getMovementBehaviourSelector().addBehaviour(entry.getKey(), entry.getValue());
            }
        }
        if (this.name != null) {
            entity.setName(this.name);
        }

        if (forceSpawn) {
            if (!this.location.getChunk().isLoaded()) {
                this.location.getChunk().load();
            }
        }
        entityManager.getChunkManager().queueSpawn(entity, this.location);
        return entity;
    }

    return null;
}
 
Example 29
Source Project: EntityAPI   Source File: EntityUtil.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
protected static Class<?> getNmsFromField(Class<?> type) {
    final FieldAccessor<Object> accessor = new Reflection().reflect(type).getSafeFieldByName("handle").getAccessor();
    return accessor.getField().member().getType();
}
 
Example 30
Source Project: EntityAPI   Source File: EntityUtil.java    License: GNU Lesser General Public License v3.0 4 votes vote down vote up
protected static Class<?> getNmsFromMethod(Class<?> type) {
    final MethodAccessor<Object> accessor = new Reflection().reflect(type).getSafeMethod("getHandle").getAccessor();
    return accessor.getMethod().member().getReturnType();
}