org.bukkit.block.BlockFace Java Examples
The following examples show how to use
org.bukkit.block.BlockFace.
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: FallingBlocksMatchModule.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockChange(BlockTransformEvent event) { BlockState newState = event.getNewState(); Block block = newState.getBlock(); long pos = encodePos(block); // Only breaks are credited. Making a bridge fall by updating a block // does not credit you with breaking the bridge. ParticipantState breaker = event.isBreak() ? ParticipantBlockTransformEvent.getPlayerState(event) : null; if (!(event.getCause() instanceof BlockFallEvent)) { this.disturb(pos, newState, breaker); } for (BlockFace face : NEIGHBORS) { this.disturb(neighborPos(pos, face), block.getRelative(face).getState(), breaker); } }
Example #2
Source File: Observer.java From Kettle with GNU General Public License v3.0 | 6 votes |
@Override public BlockFace getFacing() { int data = getData() & 0x7; switch (data) { case 0x0: return BlockFace.DOWN; case 0x1: return BlockFace.UP; case 0x2: return BlockFace.SOUTH; case 0x3: return BlockFace.NORTH; case 0x4: return BlockFace.EAST; case 0x5: return BlockFace.WEST; default: throw new IllegalArgumentException("Illegal facing direction " + data); } }
Example #3
Source File: SignsFeature.java From AreaShop with GNU General Public License v3.0 | 6 votes |
/** * Add a sign to this region. * @param location The location of the sign * @param signType The type of the sign (WALL_SIGN or SIGN_POST) * @param facing The orientation of the sign * @param profile The profile to use with this sign (null for default) */ public void addSign(Location location, Material signType, BlockFace facing, String profile) { int i = 0; while(getRegion().getConfig().isSet("general.signs." + i)) { i++; } String signPath = "general.signs." + i + "."; getRegion().setSetting(signPath + "location", Utils.locationToConfig(location)); getRegion().setSetting(signPath + "facing", facing != null ? facing.name() : null); getRegion().setSetting(signPath + "signType", signType != null ? signType.name() : null); if(profile != null && !profile.isEmpty()) { getRegion().setSetting(signPath + "profile", profile); } // Add to the map RegionSign sign = new RegionSign(this, i + ""); signs.put(sign.getStringLocation(), sign); allSigns.put(sign.getStringLocation(), sign); signsByChunk.computeIfAbsent(sign.getStringChunk(), key -> new ArrayList<>()) .add(sign); }
Example #4
Source File: EntitySpawnHandler.java From EntityAPI with GNU Lesser General Public License v3.0 | 6 votes |
@Override public <T extends ControllableEntityHandle<? extends LivingEntity>> T createEntityHandle(ControllableEntity entity, Location location) { SafeConstructor<ControllableEntityHandle> entityConstructor = getConstructorFor(entity.getEntityType()); EntityRegistrationEntry oldEntry = GameRegistry.get(IEntityRegistry.class).getDefaultEntryFor(entity.getEntityType()); GameRegistry.get(IEntityRegistry.class).register(new EntityRegistrationEntry( entity.getEntityType().getName(), entity.getEntityType().getId(), entity.getEntityType().getHandleClass() )); WorldServer worldServer = ((CraftWorld) location.getWorld()).getHandle(); T handle = (T) entityConstructor.getAccessor().invoke(worldServer, entity); handle.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); worldServer.addEntity((net.minecraft.server.v1_8_R1.Entity) handle, CreatureSpawnEvent.SpawnReason.CUSTOM); GameRegistry.get(IEntityRegistry.class).register(oldEntry); Material beneath = location.getBlock().getRelative(BlockFace.DOWN).getType(); if (beneath.isBlock()) { // What lies beneath ((Entity) handle).onGround = true; } return handle; }
Example #5
Source File: FisherAndroid.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
@Override protected void fish(Block b, BlockMenu menu) { Block water = b.getRelative(BlockFace.DOWN); if (water.getType() == Material.WATER) { water.getWorld().playSound(water.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 0.3F, 0.7F); if (ThreadLocalRandom.current().nextInt(100) < 10 * getTier()) { ItemStack drop = fishingLoot.getRandom(); if (menu.fits(drop, getOutputSlots())) { menu.pushItem(drop, getOutputSlots()); } } } }
Example #6
Source File: Door.java From Kettle with GNU General Public License v3.0 | 6 votes |
/** * Get the direction that this door is facing. * <p> * Undefined if <code>isTopHalf()</code> is true. * * @return the direction */ public BlockFace getFacing() { byte data = (byte) (getData() & 0x3); switch (data) { case 0: return BlockFace.WEST; case 1: return BlockFace.NORTH; case 2: return BlockFace.EAST; case 3: return BlockFace.SOUTH; default: throw new IllegalStateException("Unknown door facing (data: " + data + ")"); } }
Example #7
Source File: FlowerPowerListener.java From UhcCore with GNU General Public License v3.0 | 6 votes |
@EventHandler (priority = EventPriority.HIGH, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent e){ Block block = e.getBlock(); // For tall flowers start with the bottom block. Block below = block.getRelative(BlockFace.DOWN); if (isFlower(below)){ block = below; } if (isFlower(block)){ Location blockLoc = block.getLocation().add(.5,.5,.5); block.setType(Material.AIR); UhcItems.spawnExtraXp(blockLoc, expPerFlower); int random = RandomUtils.randomInteger(0, flowerDrops.size()-1); ItemStack drop = flowerDrops.get(random); blockLoc.getWorld().dropItem(blockLoc, drop); } }
Example #8
Source File: SlimefunBootsListener.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
private void stomp(EntityDamageEvent e) { Player p = (Player) e.getEntity(); p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR, 1F, 2F); p.setVelocity(new Vector(0.0, 0.7, 0.0)); for (Entity n : p.getNearbyEntities(4, 4, 4)) { if (n instanceof LivingEntity && !n.getUniqueId().equals(p.getUniqueId())) { Vector velocity = n.getLocation().toVector().subtract(p.getLocation().toVector()).normalize().multiply(1.4); n.setVelocity(velocity); if (!(n instanceof Player) || (p.getWorld().getPVP() && SlimefunPlugin.getProtectionManager().hasPermission(p, n.getLocation(), ProtectableAction.PVP))) { EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(p, n, DamageCause.ENTITY_ATTACK, e.getDamage() / 2); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) ((LivingEntity) n).damage(e.getDamage() / 2); } } } for (BlockFace face : BlockFace.values()) { Block b = p.getLocation().getBlock().getRelative(BlockFace.DOWN).getRelative(face); p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType()); } }
Example #9
Source File: LWC.java From Modern-LWC with MIT License | 6 votes |
/** * Find a block that is adjacent to another block on any of the block's 6 sides * given a Material * * @param block * @param material * @param ignore * @return */ public Block findAdjacentBlockOnAllSides(Block block, Material material, Block... ignore) { BlockFace[] faces = new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN}; List<Block> ignoreList = Arrays.asList(ignore); for (BlockFace face : faces) { Block adjacentBlock = block.getRelative(face); if (adjacentBlock.getType() == material && !ignoreList.contains(adjacentBlock)) { return adjacentBlock; } } return null; }
Example #10
Source File: EntitySpawnHandler.java From EntityAPI with GNU Lesser General Public License v3.0 | 6 votes |
@Override public ControllablePlayerHandle createPlayerHandle(ControllablePlayer player, Location location, String name, UUID uuid) { WorldServer worldServer = ((CraftWorld) location.getWorld()).getHandle(); if (name.length() > 16) name = name.substring(0, 16); GameProfile profile = new GameProfile(uuid.toString().replaceAll("-", ""), name); ControllablePlayerEntity handle = new ControllablePlayerEntity(worldServer.getMinecraftServer(), worldServer, profile, new PlayerInteractManager(worldServer), player); handle.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); worldServer.addEntity(handle); handle.world.players.remove(handle); if (location.getBlock().getRelative(BlockFace.DOWN).getType().isBlock()) handle.onGround = true; return handle; }
Example #11
Source File: QuadCrateSession.java From Crazy-Crates with MIT License | 6 votes |
private void rotateChest(Block chest, Integer direction) { BlockFace blockFace; switch (direction) { case 0://East blockFace = BlockFace.WEST; break; case 1://South blockFace = BlockFace.NORTH; break; case 2://West blockFace = BlockFace.EAST; break; case 3://North blockFace = BlockFace.SOUTH; break; default: blockFace = BlockFace.DOWN; break; } BlockState state = chest.getState(); state.setData(new Chest(blockFace)); state.update(); }
Example #12
Source File: CraftEventFactory.java From Kettle with GNU General Public License v3.0 | 6 votes |
private static PlayerEvent getPlayerBucketEvent(boolean isFilling, EntityPlayer who, int clickedX, int clickedY, int clickedZ, EnumFacing clickedFace, ItemStack itemstack, net.minecraft.item.Item item) { Player player = (who == null) ? null : (Player) who.getBukkitEntity(); CraftItemStack itemInHand = CraftItemStack.asNewCraftStack(item); Material bucket = CraftMagicNumbers.getMaterial(itemstack.getItem()); CraftWorld craftWorld = (CraftWorld) player.getWorld(); CraftServer craftServer = (CraftServer) player.getServer(); Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ); BlockFace blockFace = CraftBlock.notchToBlockFace(clickedFace); PlayerEvent event = null; if (isFilling) { event = new PlayerBucketFillEvent(player, blockClicked, blockFace, bucket, itemInHand); ((PlayerBucketFillEvent) event).setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ)); } else { event = new PlayerBucketEmptyEvent(player, blockClicked, blockFace, bucket, itemInHand); ((PlayerBucketEmptyEvent) event).setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ)); } craftServer.getPluginManager().callEvent(event); return event; }
Example #13
Source File: WorldProblemListener.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
@SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void repairChunk(ChunkLoadEvent event) { if (this.repairedChunks.put(event.getWorld(), event.getChunk())) { // Replace formerly invisible half-iron-door blocks with barriers for (Block ironDoor : event.getChunk().getBlocks(Material.IRON_DOOR_BLOCK)) { BlockFace half = (ironDoor.getData() & 8) == 0 ? BlockFace.DOWN : BlockFace.UP; if (ironDoor.getRelative(half.getOppositeFace()).getType() != Material.IRON_DOOR_BLOCK) { ironDoor.setType(Material.BARRIER, false); } } // Remove all block 36 and remember the ones at y=0 so VoidFilter can check them for (Block block36 : event.getChunk().getBlocks(Material.PISTON_MOVING_PIECE)) { if (block36.getY() == 0) { block36Locations .get(event.getWorld()) .add(block36.getX(), block36.getY(), block36.getZ()); } block36.setType(Material.AIR, false); } } }
Example #14
Source File: BukkitHandler1_13.java From AreaShop with GNU General Public License v3.0 | 6 votes |
@Override public boolean setSignFacing(Block block, BlockFace facing) { if (block == null || facing == null) { return false; } BlockState blockState = block.getState(); if (blockState == null) { return false; } BlockData blockData = blockState.getBlockData(); if (blockData == null) { return false; } if(blockData instanceof WallSign) { ((WallSign) blockData).setFacing(facing); } else if(blockData instanceof Sign) { ((Sign) blockData).setRotation(facing); } else { return false; } block.setBlockData(blockData); return true; }
Example #15
Source File: DisplayProtectionListener.java From QuickShop-Reremake with GNU General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void block(BlockFromToEvent event) { if (!useEnhanceProtection) { return; } if (DisplayItem.getNowUsing() != DisplayType.REALITEM) { return; } final Block targetBlock = event.getToBlock(); final Block shopBlock = targetBlock.getRelative(BlockFace.DOWN); final Shop shop = getShopNature(shopBlock.getLocation(),true); if (shop == null) { return; } event.setCancelled(true); if (shop.getDisplay() != null) { shop.getDisplay().remove(); } sendAlert( "[DisplayGuard] Liuqid " + targetBlock.getLocation() + " trying flow to top of shop, QuickShop already cancel it."); }
Example #16
Source File: Uncarried.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
public Uncarried(Flag flag, Post post, @Nullable Location location) { super(flag, post); if(location == null) location = flag.getReturnPoint(post); this.location = new Location(location.getWorld(), location.getBlockX() + 0.5, location.getBlockY(), location.getBlockZ() + 0.5, location.getYaw(), location.getPitch()); if(!flag.getMatch().getWorld().equals(this.location.getWorld())) { throw new IllegalStateException("Tried to place flag in the wrong world"); } Block block = this.location.getBlock(); if(block.getType() == Material.STANDING_BANNER) { // Banner may already be here at match start this.oldBlock = BlockStateUtils.cloneWithMaterial(block, Material.AIR); } else { this.oldBlock = block.getState(); } this.oldBase = block.getRelative(BlockFace.DOWN).getState(); }
Example #17
Source File: EnhancedCraftingTable.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
@Override public void onInteract(Player p, Block b) { Block dispenser = b.getRelative(BlockFace.DOWN); Dispenser disp = (Dispenser) dispenser.getState(); Inventory inv = disp.getInventory(); List<ItemStack[]> inputs = RecipeType.getRecipeInputList(this); for (int i = 0; i < inputs.size(); i++) { if (isCraftable(inv, inputs.get(i))) { ItemStack output = RecipeType.getRecipeOutputList(this, inputs.get(i)).clone(); if (Slimefun.hasUnlocked(p, output, true)) { craft(inv, dispenser, p, b, output); } return; } } SlimefunPlugin.getLocalization().sendMessage(p, "machines.pattern-not-found", true); }
Example #18
Source File: ProtectedChests.java From Shopkeepers with GNU General Public License v3.0 | 6 votes |
public List<PlayerShopkeeper> getShopkeeperOwnersOfChest(String worldName, int x, int y, int z) { List<PlayerShopkeeper> result = new ArrayList<PlayerShopkeeper>(); // checking this exact block: List<PlayerShopkeeper> shopkeepers = this.getShopkeepers(worldName, x, y, z); if (shopkeepers != null) { result.addAll(shopkeepers); } // including the directly adjacent blocks as well: for (BlockFace face : CHEST_PROTECTED_FACES) { shopkeepers = this.getShopkeepers(worldName, x + face.getModX(), y + face.getModY(), z + face.getModZ()); if (shopkeepers != null) { result.addAll(shopkeepers); } } return result; }
Example #19
Source File: MonstersIncListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@EventHandler (ignoreCancelled = true) public void onBlockClick(PlayerInteractEvent e) { Block block = e.getClickedBlock(); Player player = e.getPlayer(); Location goToLoc; if (e.getAction() != Action.RIGHT_CLICK_BLOCK){ return; } if (block == null){ return; } if(isDoor(block)) { Block below = block.getRelative(BlockFace.DOWN, 1); if (isDoor(below)) { block = below; } if (doorLocs.size() > 1) { do { goToLoc = doorLocs.get((int) (Math.random() * doorLocs.size())); // Door loc is no longer valid. if (!isValidDoorLocation(goToLoc)){ doorLocs.remove(goToLoc); goToLoc = null; } } while ((goToLoc == null || goToLoc.equals(block.getLocation())) && doorLocs.size() > 1); if (goToLoc != null) { player.teleport(goToLoc.clone().add(0.5, 0, 0.5)); } } } }
Example #20
Source File: BlockAdapterBlockData.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
@Override public BlockFace getFacing(Block block) { if (block.getBlockData() instanceof Directional) { return ((Directional) block.getBlockData()).getFacing(); } else if (block.getBlockData() instanceof Rotatable) { return ((Rotatable) block.getBlockData()).getRotation(); } else { throw new IllegalArgumentException("Block is not Directional or Rotatable"); } }
Example #21
Source File: ProtectedChests.java From Shopkeepers with GNU General Public License v3.0 | 5 votes |
private boolean isChestDirectlyProtected(String worldName, int x, int y, int z, Player player) { // checking if this exact block is protected: if (this.isThisChestProtected(worldName, x, y, z, player)) return true; // the adjacent blocks are always protected as well: for (BlockFace face : CHEST_PROTECTED_FACES) { if (this.isThisChestProtected(worldName, x + face.getModX(), y + face.getModY(), z + face.getModZ(), player)) { return true; } } return false; }
Example #22
Source File: BlockUtils.java From AACAdditionPro with GNU General Public License v3.0 | 5 votes |
/** * This gets the {@link Block}s around the given block if they are not air/empty. * * @param block the block that faces should be checked for other {@link Block}s * @param onlyHorizontal whether only the {@link Block}s should be counted that are horizontal around the block or all {@link Block}s (horizontal + vertical) * * @return a {@link List} of all {@link Block}s which were found. */ public static List<Block> getBlocksAround(final Block block, final boolean onlyHorizontal) { final List<Block> blocks = new ArrayList<>(onlyHorizontal ? 4 : 6); for (final BlockFace face : onlyHorizontal ? HORIZONTAL_FACES : ALL_FACES) { final Block relative = block.getRelative(face); if (!relative.isEmpty()) { blocks.add(relative); } } return blocks; }
Example #23
Source File: GlobalProtectionListener.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
private boolean isPortalInNearBy(Block block1) { Block block2 = block1.getRelative(BlockFace.WEST); Block block3 = block1.getRelative(BlockFace.NORTH); Block block4 = block1.getRelative(BlockFace.EAST); Block block5 = block1.getRelative(BlockFace.SOUTH); Block block6 = block2.getRelative(BlockFace.NORTH); Block block7 = block2.getRelative(BlockFace.SOUTH); Block block8 = block4.getRelative(BlockFace.NORTH); Block block9 = block4.getRelative(BlockFace.SOUTH); return (DPortal.getByBlock(plugin, block1) != null || DPortal.getByBlock(plugin, block2) != null || DPortal.getByBlock(plugin, block3) != null || DPortal.getByBlock(plugin, block4) != null || DPortal.getByBlock(plugin, block5) != null || DPortal.getByBlock(plugin, block6) != null || DPortal.getByBlock(plugin, block7) != null || DPortal.getByBlock(plugin, block8) != null || DPortal.getByBlock(plugin, block9) != null); }
Example #24
Source File: MultiBlockMachine.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
public MultiBlockMachine(Category category, SlimefunItemStack item, ItemStack[] recipe, ItemStack[] machineRecipes, BlockFace trigger) { super(category, item, RecipeType.MULTIBLOCK, recipe); this.recipes = new ArrayList<>(); this.displayRecipes = new ArrayList<>(); this.displayRecipes.addAll(Arrays.asList(machineRecipes)); this.multiblock = new MultiBlock(this, convertItemStacksToMaterial(recipe), trigger); }
Example #25
Source File: WorldProblemMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
private void checkChunk(ChunkPosition pos, @Nullable Chunk chunk) { if(repairedChunks.add(pos)) { if(chunk == null) { chunk = pos.getChunk(match.getWorld()); } for(BlockState state : chunk.getTileEntities()) { if(state instanceof Skull) { if(!NMSHacks.isSkullCached((Skull) state)) { Location loc = state.getLocation(); broadcastDeveloperWarning("Uncached skull \"" + ((Skull) state).getOwner() + "\" at " + loc.getBlockX() + ", " + loc.getBlockY() + ", " + loc.getBlockZ()); } } } // Replace formerly invisible half-iron-door blocks with barriers for(Block ironDoor : chunk.getBlocks(Material.IRON_DOOR_BLOCK)) { BlockFace half = (ironDoor.getData() & 8) == 0 ? BlockFace.DOWN : BlockFace.UP; if(ironDoor.getRelative(half.getOppositeFace()).getType() != Material.IRON_DOOR_BLOCK) { ironDoor.setType(Material.BARRIER, false); } } // Remove all block 36 and remember the ones at y=0 so VoidFilter can check them for(Block block36 : chunk.getBlocks(Material.PISTON_MOVING_PIECE)) { if(block36.getY() == 0) { block36Locations.add(block36.getX(), block36.getY(), block36.getZ()); } block36.setType(Material.AIR, false); } } }
Example #26
Source File: ItemArmorStand.java From Carbon with GNU Lesser General Public License v3.0 | 5 votes |
@Override public boolean interactWith(ItemStack itemStack, EntityHuman human, World world, int x, int y, int z, int blockFace, float paramFloat1, float paramFloat2, float paramFloat3) { if (blockFace == CraftBlock.blockFaceToNotch(BlockFace.DOWN)) { return false; } if (!world.getType(x, y, z).getMaterial().isReplaceable()) { y++; } List<?> entities = world.getEntities(null, AxisAlignedBB.a(x, y, z, x + 1.0D, y + 2.0D, z + 1.0D)); if (entities.size() > 0) { return false; } else { if (!world.isStatic) { EntityArmorStand armorStand = new EntityArmorStand(world, x + 0.5D, y, z + 0.5D); float yaw = (float) MathHelper.floor((clampYaw(human.yaw - 180.0F) + 22.5F) / 45.0F) * 45.0F; armorStand.setPositionRotation(x + 0.5D, y, z + 0.5D, yaw, 0.0F); this.setRandomBodyPose(armorStand, world.random); NBTTagCompound itemStackTag = itemStack.getTag(); if (itemStackTag != null && itemStackTag.hasKeyOfType("EntityTag", 10)) { //NBTTagCompound tag = new NBTTagCompound(); //armorStand.writeIfNoPassenger(tag); //tag.copyFrom(itemStackTag.getCompound("EntityTag")); //armorStand.load(tag); } world.addEntity(armorStand); } --itemStack.count; return true; } }
Example #27
Source File: ExprFacing.java From Skript with GNU General Public License v3.0 | 5 votes |
private static BlockFace toBlockFace(final Vector dir) { // dir.normalize(); BlockFace r = null; double d = Double.MAX_VALUE; for (final BlockFace f : BlockFace.values()) { final double a = Math.pow(f.getModX() - dir.getX(), 2) + Math.pow(f.getModY() - dir.getY(), 2) + Math.pow(f.getModZ() - dir.getZ(), 2); if (a < d) { d = a; r = f; } } assert r != null; return r; }
Example #28
Source File: GuildUtils.java From FunnyGuilds with Apache License 2.0 | 5 votes |
public static void spawnHeart(Guild guild) { PluginConfiguration config = FunnyGuilds.getInstance().getPluginConfiguration(); if (config.createMaterial != null && config.createMaterial.getLeft() != Material.AIR) { Block heart = guild.getRegion().getCenter().getBlock().getRelative(BlockFace.DOWN); heart.setType(config.createMaterial.getLeft()); BlockDataChanger.applyChanges(heart, config.createMaterial.getRight()); } else if (config.createEntityType != null) { GuildEntityHelper.spawnGuildHeart(guild); } }
Example #29
Source File: TNTSheepListener.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler public void onTNTSheepUsed(PlayerInteractEvent event) { Player player = event.getPlayer(); if (!Main.isPlayerInGame(player)) { return; } GamePlayer gamePlayer = Main.getPlayerGameProfile(player); Game game = gamePlayer.getGame(); if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (game.getStatus() == GameStatus.RUNNING && !gamePlayer.isSpectator && event.getItem() != null) { ItemStack stack = event.getItem(); String unhidden = APIUtils.unhashFromInvisibleStringStartsWith(stack, TNT_SHEEP_PREFIX); if (unhidden != null) { event.setCancelled(true); double speed = Double.parseDouble(unhidden.split(":")[2]); double follow = Double.parseDouble(unhidden.split(":")[3]); double maxTargetDistance = Double.parseDouble(unhidden.split(":")[4]); int explosionTime = Integer.parseInt(unhidden.split(":")[5]); Location startLocation; if (event.getClickedBlock() == null) { startLocation = player.getLocation(); } else { startLocation = event.getClickedBlock().getRelative(BlockFace.UP).getLocation(); } TNTSheep sheep = new TNTSheep(game, player, game.getTeamOfPlayer(player), startLocation, stack, speed, follow, maxTargetDistance, explosionTime); sheep.spawn(); } } } }
Example #30
Source File: BlockPistonEvent.java From Kettle with GNU General Public License v3.0 | 5 votes |
/** * Return the direction in which the piston will operate. * * @return direction of the piston */ public BlockFace getDirection() { // Both are meh! // return ((PistonBaseMaterial) block.getType().getNewData(block.getData())).getFacing(); // return ((PistonBaseMaterial) block.getState().getData()).getFacing(); return direction; }