/** * Get the Leash Hitch to which entities should be attached at the block. Useful if multiple * Leash Hitches could exist. * * @param block the Block to get the relevant Leash Hitch for * @return either an already existing Leash Hitch, or a newly spawned one */ public static LeashHitch getLeashHitchAt(Block block) { // Use the oldest leash entity as leash holder // If none found, create a new leash hitch Stream<LeashHitch> sorted = GlowLeashHitch.getExistingLeashHitches(block).sorted( comparingInt(Entity::getTicksLived) .reversed() ); Optional<LeashHitch> first = sorted.findFirst(); return first.orElseGet( () -> first.orElse(block.getWorld().spawn(block.getLocation(), LeashHitch.class))); }
@Override public boolean onRightClick(ItemUseEvent e, Player p, ItemStack item) { if (SlimefunManager.isItemSimiliar(item, SlimefunItems.GRAPPLING_HOOK, true)) { if (e.getClickedBlock() == null && !Variables.jump.containsKey(p.getUniqueId())) { e.setCancelled(true); if (p.getInventory().getItemInOffHand().getType().equals(Material.BOW)) { // Cancel, to fix dupe #740 return false; } Variables.jump.put(p.getUniqueId(), p.getInventory().getItemInMainHand().getType() != Material.SHEARS); if (p.getInventory().getItemInMainHand().getType() == Material.LEAD) PlayerInventory.consumeItemInHand(p); Vector direction = p.getEyeLocation().getDirection().multiply(2.0); Projectile projectile = p.getWorld().spawn(p.getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), Arrow.class); projectile.setShooter(p); projectile.setVelocity(direction); Arrow arrow = (Arrow) projectile; Bat b = (Bat) p.getWorld().spawnEntity(p.getLocation(), EntityType.BAT); b.setCanPickupItems(false); b.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 100000, 100000)); b.setLeashHolder(arrow); Variables.damage.put(p.getUniqueId(), true); Variables.remove.put(p.getUniqueId(), new Entity[] {b, arrow}); } return true; } else return false; } });
private void placeBoat(GlowPlayer player, ItemStack holding) { Block targetBlock = player.getTargetBlock((Set<Material>) null, 5); if (targetBlock != null && !targetBlock.isEmpty() && targetBlock.getRelative(BlockFace.UP).isEmpty()) { Location location = targetBlock.getRelative(BlockFace.UP).getLocation(); // center boat on cursor location location.add(0.6875f, 0, 0.6875f); location.setYaw(player.getLocation().getYaw()); Boat boat = targetBlock.getWorld().spawn(location, Boat.class); boat.setWoodType(woodType); if (player.getGameMode() != GameMode.CREATIVE) { player.getInventory().removeItem(holding); } } }
@SuppressWarnings("unchecked") private <T extends Entity> Entity spawn(Location location, Class<T> clazz, Consumer<? extends Entity> consumer) { return w.spawn(location, clazz, (Consumer<T>) consumer); }
@Override public MCEntity spawn(MCLocation l, Class mobType) { return BukkitConvertor.BukkitGetCorrectEntity(w.spawn(((BukkitMCLocation) l).l, mobType)); }
public TempArmorStand(final Location loc) { this.stand = loc.getWorld().spawn(loc, ArmorStand.class); this.stand.setMetadata("temparmorstand", new FixedMetadataValue(ProjectKorra.plugin, 0)); }
@Override public void run() { for (Block tntBlock : affected) { TNTPrimed tnt = tntBlock.getWorld().spawn(tntBlock.getLocation(), TNTPrimed.class); tnt.setFuseTicks(5); tntBlock.setType(Material.AIR); } } }.runTaskLater(plugin, 30L);
loc.getWorld().spawn(loc, ArmorStand.class, as -> { int eid = getEntityId(as); holoEntity.setId(eid);
ArmorStand as = loc.getWorld().spawn(loc, ArmorStand.class); as.setSmall(true); as.setMarker(true);
ArmorStand as = loc.getWorld().spawn(loc, ArmorStand.class); as.setSmall(true); as.setMarker(true);
@SuppressWarnings("deprecation") @Override public void run() { if (arrow.isDead() || !arrow.isValid()) { cancel(); return; } if (arrow.isInBlock() || arrow.isOnGround()) { translocatorPlayerMap.invalidate(arrow.getUniqueId()); playerTranslocatorMap.invalidate(player.getUniqueId()); Location location = arrow.getLocation(); arrow.remove(); ArmorStand armorStand = location.getWorld().spawn(location, ArmorStand.class); armorStand.setCanPickupItems(false); armorStand.setSmall(true); armorStand.setMarker(false); armorStand.setPersistent(false); armorStand.setCustomName(I18n.format("message.translocator", player.getName())); armorStand.setCustomNameVisible(true); playerTranslocatorMap.put(player.getUniqueId(), armorStand.getUniqueId()); translocatorPlayerMap.put(armorStand.getUniqueId(), player.getUniqueId()); cancel(); } } }.runTaskTimer(plugin, 0L, 5L);
try { Entity entity = event.getLocation().getWorld().spawn( event.getLocation(), EntityType.fromName(distribution.getAlternate()).getEntityClass());
/** * Detonate TNT for Blast Mining */ public void remoteDetonation() { Player player = getPlayer(); Block targetBlock = player.getTargetBlock(BlockUtils.getTransparentBlocks(), BlastMining.MAXIMUM_REMOTE_DETONATION_DISTANCE); //Blast mining cooldown check needs to be first so the player can be messaged if (!blastMiningCooldownOver() || targetBlock.getType() != Material.TNT || !EventUtils.simulateBlockBreak(targetBlock, player, true)) { return; } TNTPrimed tnt = player.getWorld().spawn(targetBlock.getLocation(), TNTPrimed.class); //SkillUtils.sendSkillMessage(player, SuperAbilityType.BLAST_MINING.getAbilityPlayer(player)); NotificationManager.sendPlayerInformation(player, NotificationType.SUPER_ABILITY, "Mining.Blast.Boom"); //player.sendMessage(LocaleLoader.getString("Mining.Blast.Boom")); tnt.setMetadata(mcMMO.tntMetadataKey, mcMMOPlayer.getPlayerMetadata()); tnt.setFuseTicks(0); targetBlock.setType(Material.AIR); mcMMOPlayer.setAbilityDATS(SuperAbilityType.BLAST_MINING, System.currentTimeMillis()); mcMMOPlayer.setAbilityInformed(SuperAbilityType.BLAST_MINING, false); new AbilityCooldownTask(mcMMOPlayer, SuperAbilityType.BLAST_MINING).runTaskLaterAsynchronously(mcMMO.p, SuperAbilityType.BLAST_MINING.getCooldown() * Misc.TICK_CONVERSION_FACTOR); }
@Override public PowerResult<Void> rightClick(Player player, ItemStack stack, PlayerInteractEvent event) { if (!checkCooldown(this, player, cooldown, true, true)) return PowerResult.cd(); if (!getItem().consumeDurability(stack, cost)) return PowerResult.cost(); player.playSound(player.getLocation(), Sound.ENTITY_ARROW_SHOOT, 1.0f, 1.0f); TNTPrimed tnt = player.getWorld().spawn(player.getLocation().add(0, 1.8, 0), TNTPrimed.class); tnt.setVelocity(player.getLocation().getDirection().multiply(2d)); return PowerResult.ok(); }
this.explosion = this.player.getWorld().spawn(this.location, TNTPrimed.class); this.explosion.setFuseTicks(0); double yield = this.explosionRadius;
/** * Send a projectile from an entity's eye level. * * @param loc * @param dir * @param speed */ public static <T extends Projectile> T sendProjectileFromLocation(Location loc, Vector dir, float speed, Class<T> clazz) { loc = loc.clone(); Vector actualDir = dir.clone().normalize(); Vector finalVecLoc = loc.toVector().add(actualDir.multiply(2)); loc.setX(finalVecLoc.getX()); loc.setY(finalVecLoc.getY()); loc.setZ(finalVecLoc.getZ()); T projectile = loc.getWorld().spawn(loc, clazz); if (projectile instanceof Fireball) { ((Fireball) projectile).setDirection(dir.multiply(speed)); } else { projectile.setVelocity(dir.multiply(speed)); } return projectile; }
TNTPrimed tnt = b.getWorld().spawn(b.getRelative(BlockFace.UP).getLocation(), TNTPrimed.class); setPlanter(tnt, event.getPlayer()); return;
if (planter != null) { b.setType(Material.AIR); TNTPrimed tnt = b.getWorld().spawn(b.getLocation(), TNTPrimed.class); setPlanter(tnt, planter);
Firework firework = player.getWorld().spawn(location, Firework.class); FireworkMeta fireworkMeta = firework.getFireworkMeta(); FireworkEffect fireworkEffect = FireworkEffect.builder()