org.bukkit.entity.Creature Java Examples

The following examples show how to use org.bukkit.entity.Creature. 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: ExprTarget.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) {
	if (mode == ChangeMode.SET || mode == ChangeMode.DELETE) {
		final LivingEntity target = delta == null ? null : (LivingEntity) delta[0];
		for (final LivingEntity entity : getExpr().getArray(e)) {
			if (getTime() >= 0 && e instanceof EntityTargetEvent && entity.equals(((EntityTargetEvent) e).getEntity()) && !Delay.isDelayed(e)) {
				((EntityTargetEvent) e).setTarget(target);
			} else {
				if (entity instanceof Creature)
					((Creature) entity).setTarget(target);
			}
		}
	} else {
		super.change(e, delta, mode);
	}
}
 
Example #2
Source File: Utils.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets an entity's target.
 * 
 * @param entity The entity to get the target of
 * @param type Can be null for any entity
 * @return The entity's target
 */
@SuppressWarnings("unchecked")
@Nullable
public static <T extends Entity> T getTarget(final LivingEntity entity, @Nullable final EntityData<T> type) {
	if (entity instanceof Creature) {
		return ((Creature) entity).getTarget() == null || type != null && !type.isInstance(((Creature) entity).getTarget()) ? null : (T) ((Creature) entity).getTarget();
	}
	T target = null;
	double targetDistanceSquared = 0;
	final double radiusSquared = 1;
	final Vector l = entity.getEyeLocation().toVector(), n = entity.getLocation().getDirection().normalize();
	final double cos45 = Math.cos(Math.PI / 4);
	for (final T other : type == null ? (List<T>) entity.getWorld().getEntities() : entity.getWorld().getEntitiesByClass(type.getType())) {
		if (other == null || other == entity || type != null && !type.isInstance(other))
			continue;
		if (target == null || targetDistanceSquared > other.getLocation().distanceSquared(entity.getLocation())) {
			final Vector t = other.getLocation().add(0, 1, 0).toVector().subtract(l);
			if (n.clone().crossProduct(t).lengthSquared() < radiusSquared && t.normalize().dot(n) >= cos45) {
				target = other;
				targetDistanceSquared = target.getLocation().distanceSquared(entity.getLocation());
			}
		}
	}
	return target;
}
 
Example #3
Source File: ShadowDive.java    From MineTinker with GNU General Public License v3.0 6 votes vote down vote up
private void hidePlayer(Player p) {
	activePlayers.add(p);

	//Clear all mob targets
	Collection<Entity> nearbyEntities = p.getWorld().getNearbyEntities(p.getLocation(), 64, 64, 64);
	for (Entity ent : nearbyEntities) {
		if (ent instanceof Creature) {
			if (p.equals(((Creature) ent).getTarget())) {
				((Creature) ent).setTarget(null);
			}
		}
	}

	//Hide from all players
	for (Player player : Bukkit.getServer().getOnlinePlayers()) {
		if (!p.equals(player)) {
			if (!player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) player.hidePlayer(MineTinker.getPlugin(), p);
		}
	}
}
 
Example #4
Source File: TNTSheep.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
public TNTSheep(Location location, Player target) {
  super(((CraftWorld) location.getWorld()).getHandle());

  this.world = location.getWorld();

  this.locX = location.getX();
  this.locY = location.getY();
  this.locZ = location.getZ();

  try {
    Field b = this.goalSelector.getClass().getDeclaredField("b");
    b.setAccessible(true);

    Set<?> goals = (Set<?>) b.get(this.goalSelector);
    goals.clear(); // Clears the goals

    this.getAttributeInstance(GenericAttributes.FOLLOW_RANGE).setValue(128D);
    this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
        .setValue(
            BedwarsRel.getInstance().getConfig().getDouble("specials.tntsheep.speed", 0.4D));
  } catch (Exception e) {
    BedwarsRel.getInstance().getBugsnag().notify(e);
    e.printStackTrace();
  }

  this.goalSelector.a(0, new PathfinderGoalBedwarsPlayer(this, 1D, false)); // Add bedwars player
  // goal
  try {
    this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()),
        TargetReason.TARGET_ATTACKED_ENTITY, false);
  } catch (Exception ex) {
    // newer spigot builds
    if (ex instanceof NoSuchMethodException) {
      BedwarsRel.getInstance().getBugsnag().notify(ex);
      this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()));
    }
  }

  ((Creature) this.getBukkitEntity()).setTarget((LivingEntity) target);
}
 
Example #5
Source File: GriefEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onEntityDamage(EntityDamageByEntityEvent event) {
    if ((!killAnimalsEnabled && !killMonstersEnabled)
            || !plugin.getWorldManager().isSkyAssociatedWorld(event.getDamager().getWorld())) {
        return;
    }
    if (!(event.getEntity() instanceof Creature)) {
        return;
    }
    if (event.getDamager() instanceof Player
            && !plugin.playerIsOnIsland((Player)event.getDamager())) {
        if (event.getDamager().hasPermission("usb.mod.bypassprotection")) {
            return;
        }
        cancelMobDamage(event);
    } else if (event.getDamager() instanceof Projectile) {
        ProjectileSource shooter = ((Projectile) event.getDamager()).getShooter();
        if (!(shooter instanceof Player)) {
            return;
        }
        Player player = (Player) shooter;
        if (player.hasPermission("usb.mod.bypassprotection") || plugin.playerIsOnIsland(player)) {
            return;
        }
        cancelMobDamage(event);
    }
}
 
Example #6
Source File: TNTSheep.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
public TNTSheep(Location location, Player target) {
  super(((CraftWorld) location.getWorld()).getHandle());

  this.world = location.getWorld();

  this.locX = location.getX();
  this.locY = location.getY();
  this.locZ = location.getZ();

  try {
    Field b = this.goalSelector.getClass().getDeclaredField("b");
    b.setAccessible(true);

    Set<?> goals = (Set<?>) b.get(this.goalSelector);
    goals.clear(); // Clears the goals

    this.getAttributeInstance(GenericAttributes.FOLLOW_RANGE).setValue(128D);
    this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
        .setValue(
            BedwarsRel.getInstance().getConfig().getDouble("specials.tntsheep.speed", 0.4D));
  } catch (Exception e) {
    BedwarsRel.getInstance().getBugsnag().notify(e);
    e.printStackTrace();
  }

  this.goalSelector.a(0, new PathfinderGoalBedwarsPlayer(this, 1D, false)); // Add bedwars player
  // goal
  try {
    this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()),
        TargetReason.TARGET_ATTACKED_ENTITY, false);
  } catch (Exception ex) {
    // newer spigot builds
    if (ex instanceof NoSuchMethodException) {
      BedwarsRel.getInstance().getBugsnag().notify(ex);
      this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()));
    }
  }

  ((Creature) this.getBukkitEntity()).setTarget((LivingEntity) target);
}
 
Example #7
Source File: TNTSheep.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
public TNTSheep(Location location, Player target) {
  super(((CraftWorld) location.getWorld()).getHandle());

  this.world = location.getWorld();

  this.locX = location.getX();
  this.locY = location.getY();
  this.locZ = location.getZ();

  try {
    Field b = this.goalSelector.getClass().getDeclaredField("b");
    b.setAccessible(true);
    b.set(this.goalSelector, new ArrayList<>());
    this.getAttributeInstance(GenericAttributes.b).setValue(128D);
    this.getAttributeInstance(GenericAttributes.d)
        .setValue(
            BedwarsRel.getInstance().getConfig().getDouble("specials.tntsheep.speed", 0.4D));
  } catch (Exception e) {
    BedwarsRel.getInstance().getBugsnag().notify(e);
    e.printStackTrace();
  }

  this.goalSelector.a(0, new PathfinderGoalBedwarsPlayer(this, EntityHuman.class, 1D, false));
  this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()),
      EntityTargetEvent.TargetReason.OWNER_ATTACKED_TARGET, false);
  ((Creature) this.getBukkitEntity()).setTarget((LivingEntity) target);
}
 
Example #8
Source File: TNTSheep.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
public TNTSheep(Location location, Player target) {
  super(((CraftWorld) location.getWorld()).getHandle());

  this.world = location.getWorld();

  this.locX = location.getX();
  this.locY = location.getY();
  this.locZ = location.getZ();

  try {
    Field b = this.goalSelector.getClass().getDeclaredField("b");
    b.setAccessible(true);
    b.set(this.goalSelector, new ArrayList<>());
    this.getAttributeInstance(GenericAttributes.FOLLOW_RANGE).setValue(128D);
    this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
        .setValue(
            BedwarsRel.getInstance().getConfig().getDouble("specials.tntsheep.speed", 0.4D));
  } catch (Exception e) {
    BedwarsRel.getInstance().getBugsnag().notify(e);
    e.printStackTrace();
  }

  this.goalSelector.a(0, new PathfinderGoalBedwarsPlayer(this, EntityHuman.class, 1D, false));
  this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()),
      EntityTargetEvent.TargetReason.OWNER_ATTACKED_TARGET, false);
  ((Creature) this.getBukkitEntity()).setTarget((LivingEntity) target);
}
 
Example #9
Source File: TNTSheep.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
public TNTSheep(Location location, Player target) {
  super(((CraftWorld) location.getWorld()).getHandle());

  this.world = location.getWorld();

  this.locX = location.getX();
  this.locY = location.getY();
  this.locZ = location.getZ();

  try {
    Field b = this.goalSelector.getClass().getDeclaredField("b");
    b.setAccessible(true);

    Set<?> goals = (Set<?>) b.get(this.goalSelector);
    goals.clear(); // Clears the goals

    this.getAttributeInstance(GenericAttributes.FOLLOW_RANGE).setValue(128D);
    this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
        .setValue(
            BedwarsRel.getInstance().getConfig().getDouble("specials.tntsheep.speed", 0.4D));
  } catch (Exception e) {
    BedwarsRel.getInstance().getBugsnag().notify(e);
    e.printStackTrace();
  }

  this.goalSelector.a(0, new PathfinderGoalBedwarsPlayer(this, 1D, false)); // Add bedwars player
  // goal
  try {
    this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()),
        TargetReason.TARGET_ATTACKED_ENTITY, false);
  } catch (Exception ex) {
    // newer spigot builds
    if (ex instanceof NoSuchMethodException) {
      BedwarsRel.getInstance().getBugsnag().notify(ex);
      this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()));
    }
  }

  ((Creature) this.getBukkitEntity()).setTarget((LivingEntity) target);
}
 
Example #10
Source File: TNTSheep.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
public TNTSheep(Location location, Player target) {
  super(((CraftWorld) location.getWorld()).getHandle());

  this.world = location.getWorld();

  this.locX = location.getX();
  this.locY = location.getY();
  this.locZ = location.getZ();

  try {
    Field b = this.goalSelector.getClass().getDeclaredField("b");
    b.setAccessible(true);
    b.set(this.goalSelector, new ArrayList<>());
    this.getAttributeInstance(GenericAttributes.b).setValue(128D);
    this.getAttributeInstance(GenericAttributes.d)
        .setValue(
            BedwarsRel.getInstance().getConfig().getDouble("specials.tntsheep.speed", 0.4D));
  } catch (Exception e) {
    BedwarsRel.getInstance().getBugsnag().notify(e);
    e.printStackTrace();
  }

  this.goalSelector.a(0, new PathfinderGoalBedwarsPlayer(this, EntityHuman.class, 1D, false));
  this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()),
      EntityTargetEvent.TargetReason.OWNER_ATTACKED_TARGET, false);
  ((Creature) this.getBukkitEntity()).setTarget((LivingEntity) target);
}
 
Example #11
Source File: TNTSheep.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
public TNTSheep(Location location, Player target) {
  super(((CraftWorld) location.getWorld()).getHandle());

  this.world = location.getWorld();

  this.locX = location.getX();
  this.locY = location.getY();
  this.locZ = location.getZ();

  try {
    Field b = this.goalSelector.getClass().getDeclaredField("b");
    b.setAccessible(true);

    Set<?> goals = (Set<?>) b.get(this.goalSelector);
    goals.clear(); // Clears the goals

    this.getAttributeInstance(GenericAttributes.FOLLOW_RANGE).setValue(128D);
    this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
        .setValue(
            BedwarsRel.getInstance().getConfig().getDouble("specials.tntsheep.speed", 0.4D));
  } catch (Exception e) {
    BedwarsRel.getInstance().getBugsnag().notify(e);
    e.printStackTrace();
  }

  this.goalSelector.a(0, new PathfinderGoalBedwarsPlayer(this, 1D, false)); // Add bedwars player
  // goal
  try {
    this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()),
        TargetReason.TARGET_ATTACKED_ENTITY, false);
  } catch (Exception ex) {
    // newer spigot builds
    if (ex instanceof NoSuchMethodException) {
      BedwarsRel.getInstance().getBugsnag().notify(ex);
      this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()));
    }
  }

  ((Creature) this.getBukkitEntity()).setTarget((LivingEntity) target);
}
 
Example #12
Source File: TNTSheep.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
public TNTSheep(Location location, Player target) {
  super(((CraftWorld) location.getWorld()).getHandle());

  this.world = location.getWorld();

  this.locX = location.getX();
  this.locY = location.getY();
  this.locZ = location.getZ();

  try {
    Field b = this.goalSelector.getClass().getDeclaredField("b");
    b.setAccessible(true);

    Set<?> goals = (Set<?>) b.get(this.goalSelector);
    goals.clear(); // Clears the goals

    this.getAttributeInstance(GenericAttributes.FOLLOW_RANGE).setValue(128D);
    this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED)
        .setValue(
            BedwarsRel.getInstance().getConfig().getDouble("specials.tntsheep.speed", 0.4D));
  } catch (Exception e) {
    BedwarsRel.getInstance().getBugsnag().notify(e);
    e.printStackTrace();
  }

  this.goalSelector.a(0, new PathfinderGoalBedwarsPlayer(this, 1D, false)); // Add bedwars player
  // goal
  try {
    this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()),
        TargetReason.TARGET_ATTACKED_ENTITY, false);
  } catch (Exception ex) {
    // newer spigot builds
    if (ex instanceof NoSuchMethodException) {
      BedwarsRel.getInstance().getBugsnag().notify(ex);
      this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()));
    }
  }

  ((Creature) this.getBukkitEntity()).setTarget((LivingEntity) target);
}
 
Example #13
Source File: EchoPetAPI.java    From SonarPet with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set a target for the {@link com.dsh105.echopet.api.pet.Pet} to attack
 *
 * @param pet    the attacker
 * @param target the {@link org.bukkit.entity.LivingEntity} for the {@link com.dsh105.echopet.api.pet.Pet} to
 *               attack
 */
public void setAttackTarget(IPet pet, LivingEntity target) {
    Preconditions.checkNotNull(pet, "Null pet");
    Preconditions.checkNotNull(target, "Null target");
    Preconditions.checkArgument(pet.getCraftPet() instanceof Creature, "Pet is a %s, not a Creature", pet.getPetType());
    if (pet.getEntityPet().getPetGoalSelector().getGoal("Attack") != null) {
        ((Creature) pet.getCraftPet()).setTarget(target);
    }
}
 
Example #14
Source File: CauseFilter.java    From CardinalPGM with MIT License 4 votes vote down vote up
private Boolean evaluate(Event event) {
    if (!(event instanceof EntityDamageEvent)) {
        switch (cause) {
            case WORLD:
                return event instanceof WorldEvent;
            case LIVING:
                return event instanceof EntityEvent && ((EntityEvent) event).getEntity() instanceof LivingEntity;
            case MOB:
                return event instanceof EntityEvent && ((EntityEvent) event).getEntity() instanceof Creature;
            case PLAYER:
                return event instanceof PlayerEvent || event instanceof BlockPlaceEvent || event instanceof BlockBreakEvent;

            case PUNCH:
                return event instanceof PlayerInteractEvent
                        && ((PlayerInteractEvent) event).getAction().equals(Action.LEFT_CLICK_BLOCK);
            case TRAMPLE:
                return event instanceof PlayerMoveEvent;
            case MINE:
                return event instanceof BlockBreakEvent;

            case EXPLOSION:
                return event instanceof EntityExplodeEvent;
        }
    } else {
        EntityDamageEvent.DamageCause damageCause = ((EntityDamageEvent) event).getCause();
        switch (cause) {
            case MELEE:
                return damageCause.equals(EntityDamageEvent.DamageCause.ENTITY_ATTACK);
            case PROJECTILE:
                return damageCause.equals(EntityDamageEvent.DamageCause.PROJECTILE);
            case POTION:
                return damageCause.equals(EntityDamageEvent.DamageCause.MAGIC)
                        || damageCause.equals(EntityDamageEvent.DamageCause.POISON)
                        || damageCause.equals(EntityDamageEvent.DamageCause.WITHER)
                        || damageCause.equals(EntityDamageEvent.DamageCause.DRAGON_BREATH);
            case EXPLOSION:
                return damageCause.equals(EntityDamageEvent.DamageCause.BLOCK_EXPLOSION)
                        || damageCause.equals(EntityDamageEvent.DamageCause.ENTITY_EXPLOSION);
            case COMBUSTION:
                return damageCause.equals(EntityDamageEvent.DamageCause.FIRE)
                        || damageCause.equals(EntityDamageEvent.DamageCause.FIRE_TICK)
                        || damageCause.equals(EntityDamageEvent.DamageCause.MELTING)
                        || damageCause.equals(EntityDamageEvent.DamageCause.LAVA)
                        || damageCause.equals(EntityDamageEvent.DamageCause.HOT_FLOOR);
            case FALL:
                return damageCause.equals(EntityDamageEvent.DamageCause.FALL);
            case GRAVITY:
                return damageCause.equals(EntityDamageEvent.DamageCause.FALL)
                        || damageCause.equals(EntityDamageEvent.DamageCause.VOID);
            case VOID:
                return damageCause.equals(EntityDamageEvent.DamageCause.VOID);
            case SQUASH:
                return damageCause.equals(EntityDamageEvent.DamageCause.FALLING_BLOCK);
            case SUFFOCATION:
                return damageCause.equals(EntityDamageEvent.DamageCause.SUFFOCATION);
            case DROWNING:
                return damageCause.equals(EntityDamageEvent.DamageCause.DROWNING);
            case STARVATION:
                return damageCause.equals(EntityDamageEvent.DamageCause.STARVATION);
            case LIGHTNING:
                return damageCause.equals(EntityDamageEvent.DamageCause.LIGHTNING);
            case CACTUS:
                return damageCause.equals(EntityDamageEvent.DamageCause.CONTACT);
            case THORNS:
                return damageCause.equals(EntityDamageEvent.DamageCause.THORNS);
        }
    }
    return null;
}
 
Example #15
Source File: Pet.java    From EchoPet with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Creature getCraftPet() {
    return this.getEntityPet().getBukkitEntity();
}
 
Example #16
Source File: EchoPetAPI.java    From SonarPet with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Get the {@link org.bukkit.entity.LivingEntity} that a {@link com.dsh105.echopet.api.pet.Pet} is targeting
 *
 * @param pet the attacker
 * @return {@link org.bukkit.entity.LivingEntity} being attacked, null if none
 */
public LivingEntity getAttackTarget(IPet pet) {
    Preconditions.checkNotNull(pet, "Null pet");
    Preconditions.checkArgument(pet.getCraftPet() instanceof Creature, "Pet is a %s, not a Creature", pet.getPetType());
    return ((Creature) pet.getCraftPet()).getTarget();
}
 
Example #17
Source File: IEntityPet.java    From EchoPet with GNU General Public License v3.0 votes vote down vote up
public Creature getBukkitEntity(); 
Example #18
Source File: IPet.java    From EchoPet with GNU General Public License v3.0 votes vote down vote up
public Creature getCraftPet();