Java Code Examples for org.bukkit.World#spawnEntity()

The following examples show how to use org.bukkit.World#spawnEntity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WitherEvent.java    From SkyWarsReloaded with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void doEvent() {
	if (gMap.getMatchState() == MatchState.PLAYING) {
		this.fired = true;
		sendTitle();
		CoordLoc loc = gMap.getSpectateSpawn();
		World world = gMap.getCurrentWorld();
		Location location = new Location(world, loc.getX(), loc.getY(), loc.getZ());
		entity = world.spawnEntity(location, EntityType.WITHER);
		if (length != -1) {
			br = new BukkitRunnable() {
				@Override
				public void run() {
					endEvent(false);
				}
			}.runTaskLater(SkyWarsReloaded.get(), length * 20L);
		}
	}
}
 
Example 2
Source File: SpawnEntityCustomNbtInjectorTest.java    From Item-NBT-API with MIT License 6 votes vote down vote up
@Override
public void test() throws Exception {
	if (!NBTInjector.isInjected())
		return;
	if (!Bukkit.getWorlds().isEmpty()) {
		World world = Bukkit.getWorlds().get(0);
		try {
			Entity entity = world.spawnEntity(new Location(world, 0, 0, 0), EntityType.ARMOR_STAND);
			entity = NBTInjector.patchEntity(entity);
			NBTCompound comp = NBTInjector.getNbtData(entity);
			comp.setString("Hello", "World");
			NBTEntity nbtent = new NBTEntity(entity);
			if (!nbtent.toString().contains("__extraData:{Hello:\"World\"}")) {
				throw new NbtApiException("Custom Data did not save to the Entity!");
			}
			comp.removeKey("Hello");
			entity.remove();

		} catch (Exception ex) {
			throw new NbtApiException("Wasn't able to use NBTEntities!", ex);
		}
	}
}
 
Example 3
Source File: FlagBowspleef.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private void dropBlock(Block block) {
	Plugin plugin = getHeavySpleef().getPlugin();
	Location location = block.getLocation();
	World world = location.getWorld();
	
	if (block.getType() == Material.TNT) {
		TNTPrimed tntEntity = (TNTPrimed) world.spawnEntity(location.add(0.5, 0, 0.5), EntityType.PRIMED_TNT);
		tntEntity.setMetadata(BOWSPLEEF_METADATA_KEY, new FixedMetadataValue(plugin, true));
		tntEntity.setVelocity(new Vector());
	} else {
		FallingBlock fallingBlock = block.getWorld().spawnFallingBlock(location, block.getType(), block.getData());
		fallingBlock.setMetadata(BOWSPLEEF_METADATA_KEY, new FixedMetadataValue(plugin, true));
	}
	
	block.setType(Material.AIR);
}
 
Example 4
Source File: SchematicUtil.java    From PlotMe-Core with GNU General Public License v3.0 5 votes vote down vote up
private org.bukkit.entity.Entity getLeash(IWorld world1, Leash leash, com.worldcretornica.plotme_core.api.Vector loc, int originX, int originY,
        int originZ) {
    org.bukkit.entity.Entity ent = null;
    World world = ((BukkitWorld) world1).getWorld();

    int x = leash.getX() - originX;
    int y = leash.getY() - originY;
    int z = leash.getZ() - originZ;

    org.bukkit.Location etloc = new org.bukkit.Location(world, x + loc.getBlockX(), y + loc.getBlockY(), z + loc.getBlockZ());

    Block block = world.getBlockAt(etloc);

    if (block.getType() == Material.FENCE || block.getType() == Material.NETHER_FENCE) {
        etloc.setX(Math.floor(etloc.getX()));
        etloc.setY(Math.floor(etloc.getY()));
        etloc.setZ(Math.floor(etloc.getZ()));

        ent = world.spawnEntity(etloc, EntityType.LEASH_HITCH);

        List<org.bukkit.entity.Entity> nearbyentities = ent.getNearbyEntities(1, 1, 1);

        for (org.bukkit.entity.Entity nearby : nearbyentities) {
            if (nearby instanceof LeashHitch) {
                if (nearby.getLocation().distance(ent.getLocation()) == 0) {
                    ent.remove();
                    return nearby;
                }
            }
        }
    }

    return ent;
}
 
Example 5
Source File: BeastmastersBow.java    From ce with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
	public boolean effect(Event event, Player player) {
//		  List<String> lore = e.getBow().getItemMeta().getLore();
//		  if(!lore.contains(placeHolder)) {
//			  for(int i = descriptionSize; i != 0; i--)
//				  lore.remove(i);
//			  e.getProjectile().setMetadata("ce." + this.getOriginalName(), new FixedMetadataValue(main, writeType(lore)));
//			  player.setMetadata("ce.CanUnleashBeasts", null);
//		  } else
//			  e.getProjectile().setMetadata("ce." + this.getOriginalName(), null);
		  if(event instanceof EntityDamageByEntityEvent) {
		  EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
		  if(e.getDamager() != player)
			  return false;
		  Entity ent = e.getEntity();
		  Location loc = ent.getLocation();
		  World w = ent.getWorld();
			if(ent instanceof Silverfish || ent instanceof EnderDragon || ent instanceof Spider || ent instanceof Slime || ent instanceof Ghast || ent instanceof MagmaCube || ent instanceof CaveSpider || (ent instanceof Wolf && ((Wolf) ent).isAngry()) || ent instanceof PigZombie) {
					e.setDamage(e.getDamage()*DamageMultiplication);
					w.playEffect(loc, Effect.SMOKE, 50);
					w.playEffect(loc, Effect.MOBSPAWNER_FLAMES, 50);
					EffectManager.playSound(loc, "BLOCK_PISTON_RETRACT", 1.3f, 3f);
				return true;
			} else if (ent instanceof Player) {
				for(int i = 0; i < MaximumMobs; i++) {
					if(rand.nextInt(100) < MobAppearanceChance) {
						w.spawnEntity(loc, rand.nextInt(2) == 1 ? EntityType.SPIDER : EntityType.SLIME);
						w.playEffect(loc, Effect.MOBSPAWNER_FLAMES, 30);
						w.playEffect(loc, Effect.SMOKE, 30);
						EffectManager.playSound(loc, "BLOCK_ANVIL_BREAK", 0.3f, 0.1f);
					}
				}
			}
		}
		  return false;
	}
 
Example 6
Source File: DMobType.java    From DungeonsXL with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Entity toEntity(Location loc) {
    World world = loc.getWorld();
    GameWorld gameWorld = plugin.getGameWorld(world);
    if (gameWorld == null) {
        return null;
    }
    LivingEntity entity = (LivingEntity) world.spawnEntity(loc, type);

    /* Set the Items */
    entity.getEquipment().setItemInHand(itemHand);
    entity.getEquipment().setHelmet(itemHelmet);
    entity.getEquipment().setChestplate(itemChestplate);
    entity.getEquipment().setLeggings(itemLeggings);
    entity.getEquipment().setBoots(itemBoots);

    /* Check mob specified stuff */
    if (type == EntityType.SKELETON) {
        if (witherSkeleton) {
            ((Skeleton) entity).setSkeletonType(SkeletonType.WITHER);
        } else {
            ((Skeleton) entity).setSkeletonType(SkeletonType.NORMAL);
        }
    }

    if (type == EntityType.OCELOT) {
        Ocelot ocelot = (Ocelot) entity;
        if (EnumUtil.isValidEnum(Ocelot.Type.class, ocelotType.toUpperCase())) {
            ocelot.setCatType(Ocelot.Type.valueOf(ocelotType.toUpperCase()));
        }
    }

    /* Set Health */
    if (maxHealth > 0) {
        entity.setMaxHealth(maxHealth);
        entity.setHealth(maxHealth);
    }

    /* Disable Despawning */
    entity.setRemoveWhenFarAway(false);

    /* Spawn Mob */
    new DMob(entity, gameWorld, this);
    return entity;
}