Java 类org.bukkit.entity.Creature 实例源码

项目: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);
    }
}
项目: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;
}
项目:LeagueOfLegends    文件:EntityUtils.java   
public void creatureMove(Entity ent, Location target, float speed) {
    if (!(ent instanceof Creature))
        return;

    if (MathUtils.offset(ent.getLocation(), target) < 0.1)
        return;

    EntityCreature ec = ((CraftCreature) ent).getHandle();
    NavigationAbstract nav = ec.getNavigation();

    if (MathUtils.offset(ent.getLocation(), target) > 16) {
        Location newTarget = ent.getLocation();

        newTarget.add(VectorUtils.getTrajectory(ent.getLocation(), target).multiply(16));

        nav.a(newTarget.getX(), newTarget.getY(), newTarget.getZ(), speed);
    } else
        nav.a(target.getX(), target.getY(), target.getZ(), speed);

}
项目:BloodMoon    文件:SpawnOnKillListener.java   
@EventHandler(priority = EventPriority.MONITOR)
public void onEntityDeath(EntityDeathEvent event) {
    Entity entity = event.getEntity();
    World world = entity.getWorld();
    PluginConfig worldConfig = plugin.getConfig(world);

    if (entity instanceof Creature && plugin.isActive(world) && plugin.isFeatureEnabled(world, Feature.SPAWN_ON_KILL)) {
        Creature creature = (Creature) entity;
        EntityDamageEvent lastDamage = entity.getLastDamageCause();

        if (lastDamage != null && creature.getTarget() instanceof Player && playerCauses.contains(lastDamage.getCause()) && worldConfig.getStringList(Config.FEATURE_SPAWN_ON_KILL_MOBS).contains(creature.getType().name().toUpperCase())) {
            if (this.random.nextInt(100) < worldConfig.getInt(Config.FEATURE_SPAWN_ON_KILL_CHANCE)) {
                String mobName = ListUtils.getRandom(worldConfig.getStringList(Config.FEATURE_SPAWN_ON_KILL_SPAWN));
                EntityType creatureType = EntityType.fromName(mobName.toUpperCase());

                if (creatureType != null) {
                    world.spawnEntity(creature.getLocation(), creatureType);
                    //world.spawn(creature.getLocation(), creatureType.getEntityClass(), SpawnReason.NATURAL);
                }
            }
        }
    }
}
项目:buildinggame    文件:ProfessionMenu.java   
/**
 * {@inheritDoc}
 */
public ProfessionMenu(Plot plot, Creature creature) {
    super(plot, creature);

    //profession
    ItemStack profession = new ItemStack(Material.EMERALD);
    ItemMeta professionMeta = profession.getItemMeta();
    professionMeta.setDisplayName(ChatColor.GREEN + "Change the profession");
    profession.setItemMeta(professionMeta);

    insertItem(profession, event -> {
        new ProfessionSelectionMenu(creature).open((Player) event.getWhoClicked());

        event.setCancelled(true);
    }, 0);
}
项目:buildinggame    文件:ColorSelectionMenu.java   
/**
 * Constructs a new Gui
 *
 * @param entity the entity to change the color of
 */
public ColorSelectionMenu(Creature entity) {
    super(null, 18, ChatColor.GREEN + "Select a color", 1);

    for (DyeColor dyeColor : DyeColor.values())
        addItem(new Wool(dyeColor).toItemStack(1), event -> {
            if (entity instanceof Colorable)
                ((Colorable) entity).setColor(dyeColor);
            else if (entity instanceof Wolf) {
                Wolf wolf = (Wolf) entity;

                wolf.setTamed(true);
                wolf.setCollarColor(dyeColor);
            }

            event.setCancelled(true);
        });
}
项目:MiniMiniGames    文件:MMPlayer.java   
public void setSpectating(boolean spectating) {
   this.spectating = spectating;
   if (spectating) {
      for (Player player : Bukkit.getOnlinePlayers()) {
         if (player == this.player) {
            continue;
         }
         player.hidePlayer(this.player);
      }
      this.player.setAllowFlight(true);
      for (LivingEntity entity : this.player.getWorld().getLivingEntities()) {
         if (!(entity instanceof Creature)) {
            continue;
         }
         EntityCreature creature = (EntityCreature) ((CraftLivingEntity) entity).getHandle();
         if (creature.target == ((CraftPlayer) this.player).getHandle()) {
            creature.target = null;
         }
      }
      MMEventHandler.onStartSpectating(this);
   } else {
      this.player.setAllowFlight(false);
   }
}
项目:uSkyBlock    文件:GriefEvents.java   
@EventHandler
public void onEntityDamage(EntityDamageByEntityEvent event) {
    if ((!killAnimalsEnabled && !killMonstersEnabled) || !plugin.isSkyAssociatedWorld(event.getDamager().getWorld())) {
        return;
    }
    if (!(event.getEntity() instanceof Creature)) {
        return;
    }
    if (event.getDamager() instanceof Player
            && !plugin.playerIsOnIsland((Player)event.getDamager())) {
        if (hasPermission(event.getDamager(), "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 (hasPermission(player, "usb.mod.bypassprotection") || plugin.playerIsOnIsland(player)) {
            return;
        }
        cancelMobDamage(event);
    }
}
项目:Wayward    文件:EntityDamageByEntityListener.java   
@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    if (event.getDamager() instanceof Player) {
        Player player = (Player) event.getDamager();
        if (plugin.isUnconscious(player)) {
            event.setCancelled(true);
        }
    }
    if (event.getDamager() instanceof Projectile) {
        Projectile projectile = (Projectile) event.getDamager();
        if (projectile.getShooter() instanceof Player) {
            if (event.getEntity() instanceof Creature) {
                ((Creature) event.getEntity()).setTarget((Player) projectile.getShooter());
            }
        }
    }
}
项目:Controllable-Mobs-API    文件:ControllableMobHelper.java   
@SuppressWarnings("deprecation")
public static Class<? extends net.minecraft.server.v1_7_R1.Entity> getNmsEntityClass(final Class<? extends LivingEntity> entityClass) throws IllegalArgumentException {
    if(entityClass==null) throw new IllegalArgumentException("entityClass must not be null");
    if(entityClass==HumanEntity.class || entityClass==Player.class) return net.minecraft.server.v1_7_R1.EntityHuman.class;
    if(entityClass==Monster.class) return net.minecraft.server.v1_7_R1.EntityMonster.class;
    if(entityClass==Creature.class) return net.minecraft.server.v1_7_R1.EntityCreature.class;
    if(entityClass==Animals.class) return net.minecraft.server.v1_7_R1.EntityAnimal.class;
    if(entityClass==LivingEntity.class) return net.minecraft.server.v1_7_R1.EntityLiving.class;

    for(EntityType entityType: EntityType.values()) {
        if(entityType.getEntityClass()==null || entityType.getTypeId()==-1) continue;
        if(entityClass.equals(entityType.getEntityClass())) {
            return getNmsEntityClass(entityType);
        }
    }

    throw new IllegalArgumentException("Class "+entityClass.getSimpleName()+" is not resolvable to an EntityType");
}
项目:simple-survival-games    文件:Arena.java   
/**
 * Remove entities from the arena
 * @param items remove items
 * @param creatures remove mobs
 * @param projectiles remove projectiles
 */
public void removeEntitiesFromArena(boolean items, boolean creatures, boolean projectiles) {
    // The arena cuboid has to be set
    if(!isArenaCuboidSet())
        return;

    // Loop through all the entities, if they are inside the arena, remove them
    World w = getArenaCuboid().getWorld();
    ArenaCuboid cuboid = getArenaCuboid();
    for(Entity e : w.getEntities()) {
        if(items && e instanceof Item)
            if(cuboid.isInsideCuboid(e.getLocation()))
                e.remove();

        if(creatures && e instanceof Creature)
            if(cuboid.isInsideCuboid(e.getLocation()))
                e.remove();

        if(projectiles && e instanceof Projectile)
            if(cuboid.isInsideCuboid(e.getLocation()))
                e.remove();
    }
}
项目:Zephyrus    文件:LifeSteal.java   
@Override
public boolean run(Player player, String[] args, int power) {
    Entity e = getTarget(player);
    if (e == null || !(e instanceof Creature)) {
        Lang.errMsg("spells.lifesteal.fail", player);
        return false;
    }
    Creature en = (Creature) getTarget(player);
    en.damage(2*power);
    try {
        player.setHealth(player.getMaxHealth() + 2*power);
    } catch (Exception ex) {
        player.setHealth(player.getMaxHealth());
    }
    return true;
}
项目:Zephyrus    文件:LifeSteal.java   
@Override
public boolean sideEffect(Player player, String[] args) {
    Random rand = new Random();
    if (rand.nextInt(2) == 0) {
        Creature en = (Creature) getTarget(player);
        try {
            en.setHealth(en.getHealth() + 2);
        } catch (Exception e) {
            en.setHealth(en.getMaxHealth());
        }
        player.damage(2, en);
        return true;
    }
    return false;

}
项目:Damocles    文件:EventCanceller.java   
@EventHandler
public void onMobSpawnEgg(CreatureSpawnEvent event){
    if(event.getSpawnReason() == SpawnReason.SPAWNER_EGG){
        if(event.getEntity() instanceof Creature){
            Creature creature = (Creature) event.getEntity();
            creature.setAI(false);
        }
    }
}
项目:Damocles    文件:EventCanceller.java   
@EventHandler
public void deathEvent(EntityDeathEvent event){
    if(ThreadLocalRandom.current().nextInt(100) <= 10){
        event.getEntity().getWorld().spawnEntity(event.getEntity().getLocation(), EntityType.ENDER_CRYSTAL);
    }
    event.setDroppedExp(0);
    if(event.getEntity() instanceof Creature){
        event.getDrops().add(createMoney(ThreadLocalRandom.current().nextInt(12)));
        return;
    }

    return;
}
项目:Damocles    文件:TornadoSpell.java   
public void cast(Player source) {
    Account account = new Account(source);
    Character character = account.getLoadedCharacter();
    if(character.getMana() < getCost()){
        return;
    }
    character.setMana(character.getMana() - getCost());
    new ParticleUtil().playTornadoEffect(overSeconds(), character.getTargetBlock(100).getLocation());
    new BukkitRunnable(){
        List<Entity> affected = new ArrayList<Entity>();
        int count = 0;
        int time = overSeconds();

        public void run(){

            Entity stand = getLocation().getWorld().spawnEntity(getLocation(), EntityType.ARMOR_STAND);
            affected = stand.getNearbyEntities(getRange()*2, getRange()*2, getRange()*2);
            stand.remove();
            affected = Extra.getNearbyEntitiesFromLocation(location, getRange());

            for(Entity entity : affected){
                if(entity instanceof Creature){
                    new Damage().playerDamageCreature((Creature)entity, source, source.getInventory().getItemInMainHand(), (getDamage()/overSeconds()), DamageType.MAGICAL);
                }
                if(entity instanceof Player){
                    new Damage().playerDamagePlayer((Player)entity, source, source.getInventory().getItemInMainHand(), (getDamage()/overSeconds()), DamageType.MAGICAL);
                }
            }

            count++;

            if(count == time)
                this.cancel();

        }
    }.runTaskTimer(Cardinal.getPlugin(), 0, 20);
}
项目:LeagueOfLegends    文件:EntityUtils.java   
public boolean creatureMoveFast(Entity ent, Location target, float speed, boolean slow) {
    if (!(ent instanceof Creature))
        return false;

    if (MathUtils.offset(ent.getLocation(), target) < 0.1)
        return false;

    if (MathUtils.offset(ent.getLocation(), target) < 2)
        speed = Math.min(speed, 1f);

    EntityCreature ec = ((CraftCreature) ent).getHandle();
    ec.getControllerMove().a(target.getX(), target.getY(), target.getZ(), speed);

    return true;
}
项目: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);
    }
}
项目:BloodMoon    文件:MoreExpListener.java   
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEntityDeath(EntityDeathEvent event) {
    LivingEntity entity = event.getEntity();
    World world = entity.getWorld();
    PluginConfig worldConfig = plugin.getConfig(world);

    if (entity instanceof Creature && plugin.isActive(world) && plugin.isFeatureEnabled(world, Feature.MORE_EXP)) {
        if (!worldConfig.getBoolean(Config.FEATURE_MORE_EXP_IGNORE_SPAWNERS) || plugin.getSpawnReason(entity) != SpawnReason.SPAWNER) {
            event.setDroppedExp(event.getDroppedExp() * Math.max(worldConfig.getInt(Config.FEATURE_MORE_EXP_MULTIPLIER), 0));
        }
    }
}
项目:BloodMoon    文件:MoreDropsListener.java   
@EventHandler(priority = EventPriority.NORMAL)
public void onEntityDeath(EntityDeathEvent event) {
    LivingEntity entity = event.getEntity();
    World world = entity.getWorld();
    PluginConfig worldConfig = plugin.getConfig(world);

    if (entity instanceof Creature && plugin.isActive(world) && plugin.isFeatureEnabled(world, Feature.MORE_DROPS)) {
        if (!worldConfig.getBoolean(Config.FEATURE_MORE_DROPS_IGNORE_SPAWNERS) || plugin.getSpawnReason(entity) != SpawnReason.SPAWNER) {
            for (ItemStack drop : event.getDrops()) {
                drop.setAmount(drop.getAmount() * Math.max(worldConfig.getInt(Config.FEATURE_MORE_DROPS_MULTIPLIER), 0));
            }
        }
    }
}
项目:BloodMoon    文件:SwordDamageListener.java   
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEntityDamage(EntityDamageEvent event) {
    Entity entity = event.getEntity();
    World world = entity.getWorld();
    PluginConfig worldConfig = plugin.getConfig(world);

    if (event.getCause() == DamageCause.ENTITY_ATTACK && plugin.isActive(world) && plugin.isFeatureEnabled(world, Feature.SWORD_DAMAGE)) {
        if (entity instanceof Creature) {
            Creature creature = (Creature) entity;
            String creatureName = creature.getType().name().toUpperCase();
            LivingEntity target = creature.getTarget();

            if (target instanceof Player) {
                Player player = (Player) target;
                ItemStack item = player.getItemInHand();
                String itemName = item.getType().name().toUpperCase();

                if (worldConfig.getStringList(Config.FEATURE_SWORD_DAMAGE_MOBS).contains(creatureName) && itemName.endsWith("_SWORD") && this.random.nextInt(100) <= worldConfig.getInt(Config.FEATURE_SWORD_DAMAGE_CHANCE)) {
                    short damage = item.getDurability();
                    short remove = (short) (item.getType().getMaxDurability() / 50);

                    item.setDurability((short) ((damage > remove) ? damage - remove : 1));
                }
            }
        }
    }
}
项目: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);
}
项目: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);
}
项目: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);
}
项目: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);
}
项目: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);
}
项目: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);
}
项目: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);
}
项目: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);
}
项目:war-sponge    文件:PlayerListener.java   
@EventHandler
public void onPlayerDamage(EntityDamageEvent event) {
    if (!(event.getEntity() instanceof Player)) {
        return;
    }
    WarPlayer defender = plugin.getWarPlayer((Player) event.getEntity());
    double damage = event.getFinalDamage();
    WarDamageCause cause;
    if (event instanceof EntityDamageByEntityEvent) {
        EntityDamageByEntityEvent edee = (EntityDamageByEntityEvent) event;
        if (edee.getDamager() instanceof TNTPrimed) {
            cause = new WarDamageCause.Explosion(defender);
        } else if (edee.getDamager() instanceof Creature) {
            cause = new WarDamageCause.Creature(defender);
        } else if (edee.getDamager() instanceof Player) {
            WarPlayer attacker = plugin.getWarPlayer((Player) edee.getDamager());
            cause = new WarDamageCause.Combat(defender, attacker);
        } else {
            cause = new WarDamageCause(defender);
        }
    } else if (event.getCause() == EntityDamageEvent.DamageCause.FIRE || event.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK
            || event.getCause() == EntityDamageEvent.DamageCause.LAVA || event.getCause() == EntityDamageEvent.DamageCause.LIGHTNING) {
        cause = new WarDamageCause.Combustion(defender);
    } else if (event.getCause() == EntityDamageEvent.DamageCause.DROWNING) {
        cause = new WarDamageCause.Drowning(defender);
    } else if (event.getCause() == EntityDamageEvent.DamageCause.FALL) {
        cause = new WarDamageCause.Falling(defender);
    } else {
        cause = new WarDamageCause(defender);
    }
    boolean b = plugin.getListener().handleDamage(defender, damage, cause);
    event.setCancelled(b);
}
项目:MobSweeper    文件:Region.java   
public void setMobs(List<String> mobs)
    throws MobSweeperException
{
    EntityType type;
    Class      klass;

    this.mobs.clear();

    for (String m : mobs) {
        m = m.toUpperCase().trim().replaceAll("\\s", "_");

        try {
            type = EntityType.valueOf(m);
        } catch (IllegalArgumentException e) {
            throw new MobSweeperException("Unknown mob: %s", m);
        }

        klass = type.getEntityClass();

        if ((klass == null) || !Creature.class.isAssignableFrom(klass))
            throw new MobSweeperException("Unsupported mob: %s", m);

        this.mobs.add(type);
    }

    if (this.mobs.size() > 0)
        return;

    for (EntityType t : EntityType.values()) {
        klass = t.getEntityClass();

        if ((klass != null) && Creature.class.isAssignableFrom(klass))
            this.mobs.add(t);
    }
}
项目:UnexpectedFishing    文件:UnexpectedFishingListener.java   
/** Throws a mob into the player. */
private Creature throwMob(World world, Player player, Location hookLoc, EntityType mobType) {
    Creature mob = (Creature) world.spawn(hookLoc, mobType.getEntityClass());
    mob.setVelocity(getFishItemVelocity(player.getLocation(), hookLoc).multiply(1.5));
    mob.setTarget(player);
    mob.setCanPickupItems(false);

    return mob;
}
项目:UnexpectedFishing    文件:UnexpectedFishingListener.java   
private Creature throwMob(World world, Player player, Location hookLoc, EntityType mobType, double velocityMultiplier) {
    Creature mob = (Creature) world.spawn(hookLoc, mobType.getEntityClass());
    mob.setVelocity(getFishItemVelocity(player.getLocation(), hookLoc).multiply(velocityMultiplier));
    mob.setTarget(player);
    mob.setCanPickupItems(false);

    return mob;
}
项目:MobSweeper    文件:Region.java   
public void setMobs(List<String> mobs)
    throws MobSweeperException
{
    EntityType type;
    Class      klass;

    this.mobs.clear();

    for (String m : mobs) {
        m = m.toUpperCase().trim().replaceAll("\\s", "_");

        try {
            type = EntityType.valueOf(m);
        } catch (IllegalArgumentException e) {
            throw new MobSweeperException("Unknown mob: %s", m);
        }

        klass = type.getEntityClass();

        if ((klass == null) || !Creature.class.isAssignableFrom(klass))
            throw new MobSweeperException("Unsupported mob: %s", m);

        this.mobs.add(type);
    }

    if (this.mobs.size() > 0)
        return;

    for (EntityType t : EntityType.values()) {
        klass = t.getEntityClass();

        if ((klass != null) && Creature.class.isAssignableFrom(klass))
            this.mobs.add(t);
    }
}
项目:Zephyrus    文件:FlameStepEffect.java   
@EventHandler
public void onMove(PlayerMoveEvent e) {
    if (EffectHandler.hasEffect(e.getPlayer(), EffectType.FLAMESTEP)) {
        for (Entity en : e.getPlayer().getNearbyEntities(RADIUS, RADIUS, RADIUS)) {
            if (en instanceof Creature) {
                Creature cr = (Creature) en;
                cr.setFireTicks(20);
            }
        }
        int radius = this.RADIUS;
        final Block block = e.getPlayer().getLocation().getBlock();
        for (int x = -(radius); x <= radius; x++) {
            for (int y = -(radius); y <= radius; y++) {
                for (int z = -(radius); z <= radius; z++) {
                    Block b = block.getRelative(x, y, z);
                    if (b.getType() == Material.SAND || b.getType() == Material.COBBLESTONE) {
                        BlockBreakEvent event = new BlockBreakEvent(b, e.getPlayer());
                        Bukkit.getPluginManager().callEvent(event);
                        if (event.isCancelled()) {
                            continue;
                        }
                        if (b.getType() == Material.SAND) {
                            b.setType(Material.GLASS);
                        }
                        if (b.getType() == Material.COBBLESTONE) {
                            b.setType(Material.STONE);
                        }
                    }
                }
            }
        }
    }
}
项目:EchoPet    文件:Pet.java   
@Override
public Creature getCraftPet(){
    return this.getEntityPet().getBukkitEntity();
}
项目:Cardinal    文件:CreatureFilter.java   
@Override
public Boolean evaluate(Entity entity) {
  return entity instanceof Creature || entity.getType().equals(EntityType.SLIME); // Slimes extend Living entity
}
项目:Cardinal    文件:CauseFilter.java   
@Override
public Boolean evaluate(Event event) {
  if (!(event instanceof EntityDamageEvent)) {
    switch (cause) {
      /* Actor Type */
      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;
      /* Block action */
      case PUNCH:
        return event instanceof BlockDamageEvent;
      case TRAMPLE:
        return event instanceof PlayerMoveEvent;
      case MINE:
        return event instanceof BlockBreakEvent;

      case EXPLOSION:
        return event instanceof EntityExplodeEvent;

      default:
        return null;
    }
  } else {
    /* Damage Type */
    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);

      default:
        return null;
    }
  }
}
项目:McMMOPlus    文件:KrakenAttackTask.java   
public KrakenAttackTask(Creature kraken, Player player) {
    this.kraken = kraken;
    this.player = player;
}
项目:McMMOPlus    文件:KrakenAttackTask.java   
public KrakenAttackTask(Creature kraken, Player player, Location location) {
    this.kraken = kraken;
    this.player = player;
    this.location = location;
}