本文整理匯總了Java中org.bukkit.entity.EntityType類的典型用法代碼示例。如果您正苦於以下問題:Java EntityType類的具體用法?Java EntityType怎麽用?Java EntityType使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
EntityType類屬於org.bukkit.entity包,在下文中一共展示了EntityType類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: spawnVillager
import org.bukkit.entity.EntityType; //導入依賴的package包/類
/**
* Spawns a Villager of the given VillagerType at the provided Location
*
* @param type - the Type of the Villager you wish to Spawn
* @param location - the Location at which you want the Villager to be
* @return Villager - the Villager that you had set at the provided Location if you wish to use it
*/
public Villager spawnVillager(VillagerType type, Location location) {
if (!location.getChunk().isLoaded()) {
location.getChunk().load();
}
Villager villager = (Villager) location.getWorld().spawnEntity(location, EntityType.VILLAGER);
villager.setAdult();
villager.setAgeLock(true);
villager.setProfession(Profession.FARMER);
villager.setRemoveWhenFarAway(false);
villager.setCustomName(type.getColor() + type.getName());
villager.setCustomNameVisible(true);
villager.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, -6, true), true);
villager.teleport(location, TeleportCause.PLUGIN);
villager.setHealth(20.0D);
return villager;
}
示例2: onPlayerInteract
import org.bukkit.entity.EntityType; //導入依賴的package包/類
/**
* Handle interaction with armor stands V1.8
* Note - some armor stand protection is done in IslandGuard.java, e.g. against projectiles.
*
* @param e
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onPlayerInteract(final PlayerInteractAtEntityEvent e) {
if (DEBUG) {
plugin.getLogger().info("1.8 " + e.getEventName());
}
if (!Util.inWorld(e.getPlayer())) {
return;
}
if (e.getRightClicked() != null && e.getRightClicked().getType().equals(EntityType.ARMOR_STAND)) {
if (actionAllowed(e.getPlayer(), e.getRightClicked().getLocation(), SettingsFlag.ARMOR_STAND)) {
return;
}
e.setCancelled(true);
Util.sendMessage(e.getPlayer(), plugin.getLocale(e.getPlayer().getUniqueId()).get("island.protected"));
}
}
示例3: play
import org.bukkit.entity.EntityType; //導入依賴的package包/類
@Override
public void play(PAUser u) {
if (isInCooldown(u, getName())) return;
final ArmorStand as = (ArmorStand) spawnEntity(u.getLoc(), EntityType.ARMOR_STAND);
as.setGravity(false);
as.setSmall(true);
as.setVisible(false);
as.setHelmet(new ItemStack(Material.SEA_LANTERN));
as.setPassenger(u.getPlayer());
as.teleport(as.getLocation().add(0, 5, 0));
bt = plugin.getServer().getScheduler().runTaskTimer(plugin, ()-> {
as.teleport(as.getLocation().add(0, 0.2, 0));
if (count <= 0) {
remove(u, as);
bt.cancel();
return;
}
count--;
}, 0, 20);
}
示例4: onMobDeath
import org.bukkit.entity.EntityType; //導入依賴的package包/類
@EventHandler
public void onMobDeath(EntityDeathEvent event) {
if(event.getEntity() instanceof Entity){
Entity e = (Entity) event.getEntity();
if(e.hasMetadata("challenge")){
event.getDrops().clear();
String[] meta = e.getMetadata("challenge").get(0).asString().split(", ");
final String player = meta[1];
plugin.getChallenges().addKill(Bukkit.getPlayer(player));
Bukkit.getPlayer(player).setLevel(plugin.getChallenges().getKillsLeft(Bukkit.getPlayer(player)));
if(e.getType().equals(EntityType.MAGMA_CUBE) || e.getType().equals(EntityType.SLIME)) {
e.remove();
}
if(plugin.getChallenges().getKillsLeft(Bukkit.getPlayer(player)) == 0){
plugin.getChallenges().finishChallenge(Bukkit.getPlayer(player), false);
}
}
}
}
示例5: spawnCompanion
import org.bukkit.entity.EntityType; //導入依賴的package包/類
/**
* Spawns a random companion for the player with a random name at the location given
* @param player
* @param location
*/
protected void spawnCompanion(Player player, Location location) {
// Older versions of the server require custom names to only apply to Living Entities
//Bukkit.getLogger().info("DEBUG: spawning compantion at " + location);
if (!islandCompanion.isEmpty() && location != null) {
Random rand = new Random();
int randomNum = rand.nextInt(islandCompanion.size());
EntityType type = islandCompanion.get(randomNum);
if (type != null) {
LivingEntity companion = (LivingEntity) location.getWorld().spawnEntity(location, type);
if (!companionNames.isEmpty()) {
randomNum = rand.nextInt(companionNames.size());
String name = companionNames.get(randomNum).replace("[player]", player.getName());
//plugin.getLogger().info("DEBUG: name is " + name);
companion.setCustomName(name);
companion.setCustomNameVisible(true);
}
}
}
}
示例6: onProjectileLaunch
import org.bukkit.entity.EntityType; //導入依賴的package包/類
/**
* Launch 2 more arrows when one is launched
*
* @param event Event
*/
@EventHandler
public void onProjectileLaunch(ProjectileLaunchEvent event)
{
if (event.getEntity().getType() != EntityType.ARROW || !(event.getEntity().getShooter() instanceof Player) || event.getEntity().hasMetadata("TAM"))
return;
final Vector velocity = event.getEntity().getVelocity();
for(int i = 0; i < 2; i++)
{
this.plugin.getServer().getScheduler().runTaskLater(this.plugin, () ->
{
EntityArrow entityArrow = new EntityArrow(((CraftWorld)event.getEntity().getWorld()).getHandle(), ((CraftLivingEntity)event.getEntity().getShooter()).getHandle(), 1F);
entityArrow.shoot(((CraftLivingEntity)event.getEntity().getShooter()).getHandle().pitch, ((CraftLivingEntity)event.getEntity().getShooter()).getHandle().yaw, 0.0F, 3.0F, 1.0F);
entityArrow.getBukkitEntity().setMetadata("TAM", new FixedMetadataValue(this.plugin, true));
entityArrow.getBukkitEntity().setVelocity(velocity);
((CraftWorld)event.getEntity().getWorld()).getHandle().addEntity(entityArrow);
}, 5L * (i + 1));
}
}
示例7: onPlayerInteractEntity
import org.bukkit.entity.EntityType; //導入依賴的package包/類
@EventHandler
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
Player player = event.getPlayer();
Entity entity = event.getRightClicked();
try {
int balance = ScrapsUtil.getScraps(player);
if (entity.getType().equals(EntityType.VILLAGER)) {
event.setCancelled(true);
String npc = entity.getName();
if (MerchantManager.getAllNPCs().contains(npc)) {
ItemStack selling = MerchantManager.getItem(npc);
int price = MerchantManager.getPrice(npc);
if (balance >= price) {
player.getInventory().addItem(selling);
player.sendMessage(MerchantManager.getSuccessMessage(npc));
ScrapsUtil.removeScraps(player, price);
} else {
player.sendMessage(MerchantManager.getDenialMessage(npc));
}
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
示例8: leave
import org.bukkit.entity.EntityType; //導入依賴的package包/類
@EventHandler
public void leave(final PlayerQuitEvent event) {
if(GameState.current() != GameState.LOBBY && event.getPlayer().getGameMode() != GameMode.SPECTATOR){
event.setQuitMessage(colour("&6" + event.getPlayer().getName() + " has quit! " +
"They have " + UHC.getInstance().getMainConfig().getDisconnectGracePeriodSeconds() + "s to reconnect."));
bukkitRunnable(() -> disqualified(event.getPlayer().getUniqueId(), event.getPlayer().getName(),
event.getPlayer().getLocation(), event.getPlayer().getInventory())).runTaskLater(UHC.getInstance(),
TimeUnit.MILLISECONDS.convert(UHC.getInstance().getMainConfig().getDisconnectGracePeriodSeconds(), TimeUnit.SECONDS));
//Zombie Spawning
Zombie zombie = (Zombie) event.getPlayer().getWorld().spawnEntity(event.getPlayer().getLocation(), EntityType.ZOMBIE);
zombie.setCustomName(event.getPlayer().getName());
zombie.setCustomNameVisible(true);
//TODO Make no AI and invulnerable cough cough Proxi cough cough
deadRepresentatives.put(event.getPlayer().getUniqueId(), zombie);
}
}
示例9: load
import org.bukkit.entity.EntityType; //導入依賴的package包/類
/**
* Load the plugin's settings.
*
* @author HomieDion
* @since 1.1.0
*/
public void load() {
// Variables
final Sunscreen plugin = Sunscreen.getInstance();
final CustomConfig config = new CustomConfig("config.yml", plugin);
final Logger log = plugin.getLogger();
// Add the disabled worlds
for (final String world : config.getStringList("disabled_worlds")) {
worlds.add(world);
log.info(String.format("%s will not use this plugin.", world));
}
// Loop all entities
for (final EntityType type : EntityType.values()) {
// Loop all values of the list
for (final String line : config.getStringList("mobs")) {
// If the names match
if (type.name().equalsIgnoreCase(line)) {
mobs.add(type);
log.info(String.format("%s will not burn in the sun.", type.name()));
break;
}
}
}
}
示例10: onProjectileHit
import org.bukkit.entity.EntityType; //導入依賴的package包/類
@EventHandler
public void onProjectileHit(ProjectileHitEvent event)
{
if (event.getEntity().getType() != EntityType.SNOWBALL || !event.getEntity().hasMetadata("paintball-ball") || !event.getEntity().getMetadata("paintball-ball").get(0).asString().equals(this.uuid.toString()))
return;
for (Block block : getNearbyBlocks(event.getEntity().getLocation(), 2))
{
if (block.getType() == Material.AIR || block.getType() == Material.SIGN || block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN)
continue;
if (this.isBlockGloballyUsed(block.getLocation()))
continue;
SimpleBlock simpleBlock = new SimpleBlock(Material.STAINED_CLAY, DyeColor.values()[new Random().nextInt(DyeColor.values().length)].getWoolData());
this.addBlockToUse(block.getLocation(), simpleBlock);
block.setType(simpleBlock.getType());
block.setData(simpleBlock.getData());
}
event.getEntity().remove();
}
示例11: getSpawnEgg
import org.bukkit.entity.EntityType; //導入依賴的package包/類
@SuppressWarnings("deprecation")
@Override
// This is kind of a dumb way to do this.. But I'm too lazy to fix my reflection
public org.bukkit.inventory.ItemStack getSpawnEgg(org.bukkit.inventory.ItemStack i, String entityTag){
EntityType type = null;
try{
type = EntityType.valueOf(entityTag.toUpperCase());
}catch(Exception ex){
switch (entityTag){
case "mooshroom":
type = EntityType.MUSHROOM_COW;
break;
case "zombie_pigman":
type = EntityType.PIG_ZOMBIE;
break;
default:
type = EntityType.BAT;
System.out.println("Bad tag: " + entityTag);
break;
}
}
return new ItemStack(i.getType(), i.getAmount(), type.getTypeId());
}
示例12: ClickCheckItem
import org.bukkit.entity.EntityType; //導入依賴的package包/類
@EventHandler
public void ClickCheckItem(InventoryClickEvent evt){
if(ConfigPatch.AntiLongStringCrashenable == true){
if(evt.getWhoClicked().getType() != EntityType.PLAYER){
return;
}
Player player = (Player) evt.getWhoClicked();
ItemStack item = evt.getCursor();
if(item != null){
if(item.hasItemMeta() && item.getItemMeta().getDisplayName() != null){
if(item.getItemMeta().getDisplayName().length() >= 127){
evt.setCancelled(true);
evt.setCurrentItem(null);
AzureAPI.log(player, ConfigPatch.AntiLongStringCrashWarnMessage);
}
}
}
}
}
示例13: getNearbyPlayers
import org.bukkit.entity.EntityType; //導入依賴的package包/類
public static List<Player> getNearbyPlayers(Location location, double distance) {
List<Player> nearbyPlayers = new ArrayList<>();
for (LivingEntity entity : location.getWorld().getLivingEntities()) {
if (entity.getType() == EntityType.PLAYER && entity.getLocation().distance(location) <= distance) {
nearbyPlayers.add((Player) entity);
}
}
return nearbyPlayers;
}
示例14: getRandomFirework
import org.bukkit.entity.EntityType; //導入依賴的package包/類
public static Firework getRandomFirework(Location loc) {
FireworkMeta fireworkMeta = (FireworkMeta) (new ItemStack(Material.FIREWORK)).getItemMeta();
Firework firework = (Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK);
fireworkMeta.setPower(GizmoConfig.FIREWORK_POWER);
fireworkMeta.addEffect(FireworkEffect.builder()
.with(RocketUtils.randomFireworkType())
.withColor(RocketUtils.randomColor())
.trail(GizmoConfig.FIREWORK_TRAIL)
.build());
firework.setFireworkMeta(fireworkMeta);
return firework;
}
示例15: worldEntities
import org.bukkit.entity.EntityType; //導入依賴的package包/類
private List<Entity> worldEntities(World w, EntityType entityType) {
List<Entity> entities = new ArrayList<>();
w.getEntities().forEach(e -> {
if (e.getType() == entityType) {
entities.add(e);
}
});
return entities;
}