/** * 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))); }
/** * Get all LeashHitch Entities in the specified block. * * @param block the Block to search LeashHitch Entities in * @return a Stream of all found LeashHitch Entities */ private static Stream<LeashHitch> getExistingLeashHitches(Block block) { Location location = block.getLocation().add(0.5, 0.5, 0.5); Collection<Entity> nearbyEntities = block.getWorld() .getNearbyEntities(location, 0.49, 0.49, 0.49); return nearbyEntities.stream() .filter(e -> e instanceof LeashHitch) .map(e -> (LeashHitch) e); }
private World getGameWorld(CommandSender sender) { if (sender instanceof HumanEntity) { World world = ((HumanEntity) sender).getWorld(); if (world != null) { return world; } } else if (sender instanceof BlockCommandSender) { return ((BlockCommandSender) sender).getBlock().getWorld(); } return Bukkit.getWorlds().get(0); }
@Override protected String disambiguate(Block subject, String metadataKey) { return subject.getWorld() + "," + subject.getX() + "," + subject.getY() + "," + subject .getZ() + ":" + metadataKey; } }
/** * Returns the world that the given command sender is referring to when not specifying one. * * @param sender a command sender * @return the command sender's world if the sender is a block or entity, or the default world * otherwise */ public static GlowWorld getWorld(CommandSender sender) { if (sender instanceof ConsoleCommandSender) { return getDefaultWorld(); } else if (sender instanceof Entity) { return (GlowWorld) ((Entity) sender).getWorld(); } else if (sender instanceof BlockCommandSender) { return (GlowWorld) ((BlockCommandSender) sender).getBlock().getWorld(); } return getDefaultWorld(); }
private void setType(Block block, int type, int data) { World world = block.getWorld(); int x = block.getX(); int y = block.getY(); int z = block.getZ(); GlowChunk chunk = (GlowChunk) world.getChunkAt(block); chunk.setType(x & 0xf, z & 0xf, y, type); chunk.setMetaData(x & 0xf, z & 0xf, y, data); } }
/** * Convert a TNT block into a primed TNT entity with the player who ignited the TNT. * * @param tntBlock The block to ignite. * @param ignitedByExplosion True if another explosion caused this ignition. * @param player The player who ignited the TNT. */ public static void igniteBlock( Block tntBlock, boolean ignitedByExplosion, GlowPlayer player) { tntBlock.setType(Material.AIR); World world = tntBlock.getWorld(); GlowTntPrimed tnt = (GlowTntPrimed) world .spawnEntity(tntBlock.getLocation().add(0.5, 0, 0.5), EntityType.PRIMED_TNT); tnt.setSource(player); tnt.setIgnitedByExplosion(ignitedByExplosion); world.playSound(tntBlock.getLocation(), Sound.ENTITY_TNT_PRIMED, 1, 1); }
BlockCommandSender blockCommandSender = (BlockCommandSender) source; if (blockCommandSender.getBlock().getWorld().getGameRuleValue("commandBlockOutput").equalsIgnoreCase("false")) { Bukkit.getConsoleSender().sendMessage(result); return;
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); } } }
public static int getBlockPlaceHash(final Block block, final Material mat) { int hash = getCoordHash(block); if (mat != null) { hash |= mat.name().hashCode(); } hash |= block.getWorld().getName().hashCode(); return hash; }
@Override public synchronized void setTrue(Block block) { if (block == null) { return; } setTrue(block.getX(), block.getY(), block.getZ(), block.getWorld()); }
@Override public synchronized boolean isTrue(Block block) { if (block == null) { return false; } return isTrue(block.getX(), block.getY(), block.getZ(), block.getWorld()); }
@Override public synchronized void setFalse(Block block) { if (block == null) { return; } setFalse(block.getX(), block.getY(), block.getZ(), block.getWorld()); }
private boolean isItemAppliedToBlock(ItemStack item, Block clicked) { return Materials.isItemAppliedToBlock(item.getType(), clicked.getType()) && !hasInteractBypass(clicked) && !hasInteractBypass(clicked.getWorld(), item); }
@EventHandler(ignoreCancelled = true) public void onBlockMultiPlace(BlockMultiPlaceEvent event) { List<Block> blocks = new ArrayList<>(); for (BlockState bs : event.getReplacedBlockStates()) { blocks.add(bs.getBlock()); } Events.fireToCancel(event, new PlaceBlockEvent(event, create(event.getPlayer()), event.getBlock().getWorld(), blocks, event.getBlock().getType())); }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockGrow(BlockGrowEvent event) { /* WORLD BLACKLIST CHECK */ if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld())) return; BlockState blockState = event.getBlock().getState(); if (!BlockUtils.shouldBeWatched(blockState)) { return; } mcMMO.getPlaceStore().setFalse(blockState); }
public static ArmorStand getArmorStand(Block hopper) { Location l = new Location(hopper.getWorld(), hopper.getX() + 0.5, hopper.getY() + offset, hopper.getZ() + 0.5); for (Entity n: l.getChunk().getEntities()) { if (n instanceof ArmorStand) { if (n.getCustomName() == null && l.distanceSquared(n.getLocation()) < 0.4D) return (ArmorStand) n; } } ArmorStand hologram = ArmorStandFactory.createHidden(l); hologram.setCustomNameVisible(false); hologram.setCustomName(null); return hologram; }
@EventHandler public void blockFormEvent(BlockFormEvent event) { if (event.getNewState().getType() == Material.SNOW) { WorldClimateEngine climateEngine = ClimateEngine.getInstance().getClimateEngine(event.getBlock().getWorld().getUID()); if (climateEngine != null && climateEngine.isEffectEnabled(ClimateEffectType.SNOW_FORMATION)) { double temperature = climateEngine.getTemperature(); if (event.getBlock().getY() < heightMap.getValue(temperature)) { event.setCancelled(true); } } } }
@EventHandler public void blockFormEvent(BlockFormEvent event) { if (event.getNewState().getType() == Material.ICE) { WorldClimateEngine climateEngine = ClimateEngine.getInstance().getClimateEngine(event.getBlock().getWorld().getUID()); if (climateEngine != null && climateEngine.isEffectEnabled(ClimateEffectType.ICE_FORMATION)) { if (event.getBlock().getY() < heightMap.getValue(climateEngine.getTemperature())) { event.setCancelled(true); } } } }
@EventHandler(ignoreCancelled = true) public void onBlockDispense(BlockDispenseEvent event) { ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager(); WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(event.getBlock().getWorld())); if (wcfg.getBlacklist() != null) { if (!wcfg.getBlacklist().check(new BlockDispenseBlacklistEvent(null, BukkitAdapter.asBlockVector(event.getBlock().getLocation()), createTarget(event.getItem())), false, false)) { event.setCancelled(true); } } }