Java Code Examples for org.bukkit.entity.LivingEntity#setAI()

The following examples show how to use org.bukkit.entity.LivingEntity#setAI() . 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
Source File: EntityUtils.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void disableEntityAI(LivingEntity entity) {
	try {
		entity.setAI(false);
	} catch (Throwable t) {
		try {
			Object handler = getHandle(entity);
			Object tag = getMethod(handler, "getNBTTag").invoke(); // Can this really work? or it's always creating
																	// new
																	// one?
			if (tag == null) {
				tag = NBTTagCompound.getConstructor().newInstance();
			}
			getMethod(handler, "c,func_184198_c", NBTTagCompound).invoke(tag);
			getMethod(NBTTagCompound, "setInt,func_74768_a", String.class, int.class).invokeInstance(tag, "NoAI",
				1);
			getMethod(handler, "f,func_70020_e", NBTTagCompound).invoke(tag);
		} catch (Throwable ignored) {
		}
	}
}
 
Example 2
Source File: EntityUtils.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void disableEntityAI(LivingEntity entity) {
	try {
		entity.setAI(false);
	} catch (Throwable t) {
		try {
			Object handler = getHandle(entity);
			Object tag = getMethod(handler, "getNBTTag").invoke(); // Can this really work? or it's always creating
																	// new
																	// one?
			if (tag == null) {
				tag = NBTTagCompound.getConstructor().newInstance();
			}
			getMethod(handler, "c,func_184198_c", NBTTagCompound).invoke(tag);
			getMethod(NBTTagCompound, "setInt,func_74768_a", String.class, int.class).invokeInstance(tag, "NoAI",
				1);
			getMethod(handler, "f,func_70020_e", NBTTagCompound).invoke(tag);
		} catch (Throwable ignored) {
		}
	}
}
 
Example 3
Source File: ExprAI.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void change(Event event, @Nullable Object[] delta, Changer.ChangeMode mode) {
	if (delta == null || delta[0] == null) {
		return;
	}
	boolean value = (Boolean) delta[0];
	for (LivingEntity entity : getExpr().getArray(event)) {
		entity.setAI(value);
	}
}
 
Example 4
Source File: VersionUtils_1_13.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setEntityAI(LivingEntity entity, boolean b){
    entity.setAI(b);
}
 
Example 5
Source File: VersionUtils_1_12.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setEntityAI(LivingEntity entity, boolean b){
    entity.setAI(b);
}
 
Example 6
Source File: NMSHandler.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setNoAI(LivingEntity bukkitEntity) {
	bukkitEntity.setAI(false);
}
 
Example 7
Source File: NMSHandler.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setNoAI(LivingEntity bukkitEntity) {
	bukkitEntity.setAI(false);
}
 
Example 8
Source File: NMSHandler.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setNoAI(LivingEntity bukkitEntity) {
	bukkitEntity.setAI(false);
}
 
Example 9
Source File: NMSHandler.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setNoAI(LivingEntity bukkitEntity) {
	bukkitEntity.setAI(false);
}
 
Example 10
Source File: NMSHandler.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setNoAI(LivingEntity bukkitEntity) {
	bukkitEntity.setAI(false);
}
 
Example 11
Source File: SpiritWalk.java    From EliteMobs with GNU General Public License v3.0 3 votes vote down vote up
private void spiritWalkAnimation(LivingEntity bossMob, Location entityLocation, Location finalLocation) {

        bossMob.setAI(false);
        bossMob.setInvulnerable(true);
        bossMob.addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, 20 * 10, 1));
        Vector toDestination = finalLocation.clone().subtract(entityLocation.clone()).toVector().normalize().divide(new Vector(2, 2, 2));

        new BukkitRunnable() {

            int counter = 0;

            @Override
            public void run() {

                if (bossMob.getLocation().clone().distance(finalLocation) < 2 || counter > 20 * 10) {

                    bossMob.teleport(finalLocation);
                    bossMob.setAI(true);
                    bossMob.setInvulnerable(false);
                    bossMob.removePotionEffect(PotionEffectType.GLOWING);
                    cancel();

                }

                bossMob.teleport(bossMob.getLocation().clone().add(toDestination.clone()));

                counter++;

            }

        }.runTaskTimer(MetadataHandler.PLUGIN, 0, 1);

    }