org.bukkit.craftbukkit.v1_8_R3.CraftWorld#org.bukkit.entity.Creature源码实例Demo

下面列出了org.bukkit.craftbukkit.v1_8_R3.CraftWorld#org.bukkit.entity.Creature 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: MineTinker   文件: ShadowDive.java
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);
		}
	}
}
 
源代码2 项目: Skript   文件: ExprTarget.java
@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);
	}
}
 
源代码3 项目: Skript   文件: Utils.java
/**
 * 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;
}
 
源代码4 项目: SonarPet   文件: EchoPetAPI.java
/**
 * 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);
    }
}
 
源代码5 项目: BedwarsRel   文件: TNTSheep.java
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);
}
 
源代码6 项目: BedwarsRel   文件: TNTSheep.java
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);
}
 
源代码7 项目: BedwarsRel   文件: TNTSheep.java
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);
}
 
源代码8 项目: BedwarsRel   文件: TNTSheep.java
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);
}
 
源代码9 项目: BedwarsRel   文件: TNTSheep.java
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);
}
 
源代码10 项目: BedwarsRel   文件: TNTSheep.java
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);
}
 
源代码11 项目: BedwarsRel   文件: TNTSheep.java
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);
}
 
源代码12 项目: BedwarsRel   文件: TNTSheep.java
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);
}
 
源代码13 项目: uSkyBlock   文件: GriefEvents.java
@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);
    }
}
 
源代码14 项目: CardinalPGM   文件: CauseFilter.java
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;
}
 
源代码15 项目: EchoPet   文件: Pet.java
@Override
public Creature getCraftPet() {
    return this.getEntityPet().getBukkitEntity();
}
 
源代码16 项目: SonarPet   文件: EchoPetAPI.java
/**
 * 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();
}
 
源代码17 项目: EchoPet   文件: IEntityPet.java
public Creature getBukkitEntity(); 
源代码18 项目: EchoPet   文件: IPet.java
public Creature getCraftPet();