當前位置: 首頁>>代碼示例>>Java>>正文


Java Creature類代碼示例

本文整理匯總了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);
	}
}
 
開發者ID:nfell2009,項目名稱:Skript,代碼行數:17,代碼來源:ExprTarget.java

示例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;
}
 
開發者ID:nfell2009,項目名稱:Skript,代碼行數:32,代碼來源:Utils.java

示例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);

}
 
開發者ID:xdev-pl,項目名稱:LeagueOfLegends,代碼行數:21,代碼來源:EntityUtils.java

示例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);
                }
            }
        }
    }
}
 
開發者ID:Samistine,項目名稱:BloodMoon,代碼行數:24,代碼來源:SpawnOnKillListener.java

示例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);
}
 
開發者ID:stefvanschie,項目名稱:buildinggame,代碼行數:19,代碼來源:ProfessionMenu.java

示例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);
        });
}
 
開發者ID:stefvanschie,項目名稱:buildinggame,代碼行數:23,代碼來源:ColorSelectionMenu.java

示例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);
   }
}
 
開發者ID:PaulBGD,項目名稱:MiniMiniGames,代碼行數:25,代碼來源:MMPlayer.java

示例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);
    }
}
 
開發者ID:rlf,項目名稱:uSkyBlock,代碼行數:27,代碼來源:GriefEvents.java

示例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());
            }
        }
    }
}
 
開發者ID:WaywardRealms,項目名稱:Wayward,代碼行數:18,代碼來源:EntityDamageByEntityListener.java

示例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");
}
 
開發者ID:DevCybran,項目名稱:Controllable-Mobs-API,代碼行數:19,代碼來源:ControllableMobHelper.java

示例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();
	}
}
 
開發者ID:timvisee,項目名稱:simple-survival-games,代碼行數:29,代碼來源:Arena.java

示例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;
}
 
開發者ID:mcardy,項目名稱:Zephyrus,代碼行數:17,代碼來源:LifeSteal.java

示例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;

}
 
開發者ID:mcardy,項目名稱:Zephyrus,代碼行數:17,代碼來源:LifeSteal.java

示例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);
		}
	}
}
 
開發者ID:DamoclesProject,項目名稱:Damocles,代碼行數:10,代碼來源:EventCanceller.java

示例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;
}
 
開發者ID:DamoclesProject,項目名稱:Damocles,代碼行數:14,代碼來源:EventCanceller.java


注:本文中的org.bukkit.entity.Creature類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。