本文整理汇总了Java中org.bukkit.entity.Creature类的典型用法代码示例。如果您正苦于以下问题:Java Creature类的具体用法?Java Creature怎么用?Java Creature使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Creature类属于org.bukkit.entity包,在下文中一共展示了Creature类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: change
import org.bukkit.entity.Creature; //导入依赖的package包/类
@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);
}
}
示例2: getTarget
import org.bukkit.entity.Creature; //导入依赖的package包/类
/**
* 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;
}
示例3: creatureMove
import org.bukkit.entity.Creature; //导入依赖的package包/类
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);
}
示例4: onEntityDeath
import org.bukkit.entity.Creature; //导入依赖的package包/类
@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);
}
}
}
}
}
示例5: ProfessionMenu
import org.bukkit.entity.Creature; //导入依赖的package包/类
/**
* {@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);
}
示例6: ColorSelectionMenu
import org.bukkit.entity.Creature; //导入依赖的package包/类
/**
* 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);
});
}
示例7: setSpectating
import org.bukkit.entity.Creature; //导入依赖的package包/类
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);
}
}
示例8: onEntityDamage
import org.bukkit.entity.Creature; //导入依赖的package包/类
@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);
}
}
示例9: onEntityDamageByEntity
import org.bukkit.entity.Creature; //导入依赖的package包/类
@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());
}
}
}
}
示例10: getNmsEntityClass
import org.bukkit.entity.Creature; //导入依赖的package包/类
@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");
}
示例11: removeEntitiesFromArena
import org.bukkit.entity.Creature; //导入依赖的package包/类
/**
* 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();
}
}
示例12: run
import org.bukkit.entity.Creature; //导入依赖的package包/类
@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;
}
示例13: sideEffect
import org.bukkit.entity.Creature; //导入依赖的package包/类
@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;
}
示例14: onMobSpawnEgg
import org.bukkit.entity.Creature; //导入依赖的package包/类
@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);
}
}
}
示例15: deathEvent
import org.bukkit.entity.Creature; //导入依赖的package包/类
@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;
}