Java Code Examples for org.bukkit.block.Block#isLiquid()
The following examples show how to use
org.bukkit.block.Block#isLiquid() .
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: BlockTransformListener.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
@EventWrapper public void onDispenserDispense(final BlockDispenseEvent event) { if (Materials.isBucket(event.getItem())) { // Yes, the location the dispenser is facing is stored in "velocity" for some ungodly reason Block targetBlock = event.getVelocity().toLocation(event.getBlock().getWorld()).getBlock(); Material contents = Materials.materialInBucket(event.getItem()); if (Materials.isLiquid(contents) || (contents == Material.AIR && targetBlock.isLiquid())) { callEvent( event, targetBlock.getState(), BlockStates.cloneWithMaterial(targetBlock, contents), Trackers.getOwner(event.getBlock())); } } }
Example 2
Source File: AABB.java From Hawk with GNU General Public License v3.0 | 6 votes |
public boolean isLiquidPresent(World world) { for (int x = (int)Math.floor(min.getX()); x < (int)Math.ceil(max.getX()); x++) { for (int y = (int)Math.floor(min.getY()); y < (int)Math.ceil(max.getY()); y++) { for (int z = (int)Math.floor(min.getZ()); z < (int)Math.ceil(max.getZ()); z++) { Block block = ServerUtils.getBlockAsync(new Location(world, x, y, z)); if(block == null) continue; if(block.isLiquid()) return true; } } } return false; }
Example 3
Source File: AdjacentBlocks.java From Hawk with GNU General Public License v3.0 | 6 votes |
public static boolean blockAdjacentIsLiquid(Location loc) { Location check = loc.clone(); Set<Block> sample = new HashSet<>(); sample.add(ServerUtils.getBlockAsync(check.add(0, 0, 0.3))); sample.add(ServerUtils.getBlockAsync(check.add(0.3, 0, 0))); sample.add(ServerUtils.getBlockAsync(check.add(0, 0, -0.3))); sample.add(ServerUtils.getBlockAsync(check.add(0, 0, -0.3))); sample.add(ServerUtils.getBlockAsync(check.add(-0.3, 0, 0))); sample.add(ServerUtils.getBlockAsync(check.add(-0.3, 0, 0))); sample.add(ServerUtils.getBlockAsync(check.add(0, 0, 0.3))); sample.add(ServerUtils.getBlockAsync(check.add(0, 0, 0.3))); for (Block b : sample) { if (b != null && b.isLiquid()) return true; } return false; }
Example 4
Source File: BlockEventHandler.java From GriefDefender with MIT License | 5 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onBlockFromTo(BlockFromToEvent event) { final Block fromBlock = event.getBlock(); final Block toBlock = event.getToBlock(); final World world = fromBlock.getWorld(); if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) { return; } final GDPermissionUser user = CauseContextHelper.getEventUser(fromBlock.getLocation(), PlayerTracker.Type.NOTIFIER); if (user == null) { return; } Location location = toBlock.getLocation(); GDClaim targetClaim = this.storage.getClaimAt(location); if (targetClaim.isWilderness()) { return; } if (fromBlock.isLiquid()) { final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.LIQUID_FLOW, fromBlock, toBlock, user, TrustTypes.BUILDER, true); if (result == Tristate.FALSE) { event.setCancelled(true); return; } } else if (handleBlockBreak(event, location, targetClaim, event.getBlock(), event.getToBlock(), user, false)) { event.setCancelled(true); } }
Example 5
Source File: InvalidPlacement.java From Hawk with GNU General Public License v3.0 | 5 votes |
@Override protected void check(InteractWorldEvent e) { HawkPlayer pp = e.getHawkPlayer(); Block targetedBlock = ServerUtils.getBlockAsync(e.getTargetedBlockLocation()); if(targetedBlock == null) return; Material mat = targetedBlock.getType(); if(targetedBlock.isLiquid() || mat == Material.AIR) { punishAndTryCancelAndBlockRespawn(pp, 1, e); } }
Example 6
Source File: BlockInteractOcclusion.java From Hawk with GNU General Public License v3.0 | 5 votes |
@Override protected void check(InteractWorldEvent e) { HawkPlayer pp = e.getHawkPlayer(); Vector eyePos = pp.getPosition().clone().add(new Vector(0, pp.isSneaking() ? 1.54 : 1.62, 0)); Vector direction = MathPlus.getDirection(pp.getYaw(), pp.getPitch()); Location bLoc = e.getTargetedBlockLocation(); Block b = bLoc.getBlock(); WrappedBlock bNMS = WrappedBlock.getWrappedBlock(b, pp.getClientVersion()); AABB targetAABB = new AABB(bNMS.getHitBox().getMin(), bNMS.getHitBox().getMax()); double distance = targetAABB.distanceToPosition(eyePos); BlockIterator iter = new BlockIterator(pp.getWorld(), eyePos, direction, 0, (int) distance + 2); while (iter.hasNext()) { Block bukkitBlock = iter.next(); if (bukkitBlock.getType() == Material.AIR || bukkitBlock.isLiquid()) continue; if (bukkitBlock.getLocation().equals(bLoc)) break; WrappedBlock iterBNMS = WrappedBlock.getWrappedBlock(bukkitBlock, pp.getClientVersion()); AABB checkIntersection = new AABB(iterBNMS.getHitBox().getMin(), iterBNMS.getHitBox().getMax()); Vector occludeIntersection = checkIntersection.intersectsRay(new Ray(eyePos, direction), 0, Float.MAX_VALUE); if (occludeIntersection != null) { if (occludeIntersection.distance(eyePos) < distance) { Placeholder ph = new Placeholder("type", iterBNMS.getBukkitBlock().getType()); punishAndTryCancelAndBlockRespawn(pp, 1, e, ph); return; } } } }
Example 7
Source File: AdjacentBlocks.java From Hawk with GNU General Public License v3.0 | 5 votes |
/** * Checks if the location is on ground. Good replacement for Entity#isOnGround() * since that flag can be spoofed by the client. Hawk's definition of being on * ground: yVelocity must not exceed 0.6, player's feet must not be inside * a solid block's AABB, and there must be at least 1 solid block AABB collision * with the AABB defining the thin area below the location (represents below the * player's feet). * * @param loc Test location * @param yVelocity Y-velocity * @param ignoreInGround return false if location is inside something * @param feetDepth Don't set this too low. The client doesn't like to send moves unless they are significant enough. * @param pp * @return boolean */ //if not sure what your velocity is, just put -1 for velocity //if you just want to check for location, just put -1 for velocity public static boolean onGroundReally(Location loc, double yVelocity, boolean ignoreInGround, double feetDepth, HawkPlayer pp) { if (yVelocity > 0.6) //allows stepping up short blocks, but not full blocks return false; Location check = loc.clone(); Set<Block> blocks = new HashSet<>(); blocks.addAll(AdjacentBlocks.getBlocksInLocation(check)); blocks.addAll(AdjacentBlocks.getBlocksInLocation(check.add(0, -1, 0))); AABB underFeet = new AABB(loc.toVector().add(new Vector(-0.3, -feetDepth, -0.3)), loc.toVector().add(new Vector(0.3, 0, 0.3))); for (Block block : blocks) { WrappedBlock bNMS = WrappedBlock.getWrappedBlock(block, pp.getClientVersion()); if (block.isLiquid() || (!bNMS.isSolid() && Hawk.getServerVersion() == 8)) continue; if (bNMS.isColliding(underFeet)) { //almost done. gotta do one more check... Check if their foot ain't in a block. (stops checkerclimb) if (ignoreInGround) { AABB topFeet = underFeet.clone(); topFeet.translate(new Vector(0, feetDepth + 0.00001, 0)); for (Block block1 : AdjacentBlocks.getBlocksInLocation(loc)) { WrappedBlock bNMS1 = WrappedBlock.getWrappedBlock(block1, pp.getClientVersion()); if (block1.isLiquid() || (!bNMS1.isSolid() && Hawk.getServerVersion() == 8) || block1.getState().getData() instanceof Openable || pp.getIgnoredBlockCollisions().contains(block1.getLocation())) continue; if (bNMS1.isColliding(topFeet)) return false; } } return true; } } return false; }
Example 8
Source File: BlockTransformListener.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventWrapper public void onDispenserDispense(final BlockDispenseEvent event) { if(Materials.isBucket(event.getItem())) { // Yes, the location the dispenser is facing is stored in "velocity" for some ungodly reason Block targetBlock = event.getVelocity().toLocation(event.getBlock().getWorld()).getBlock(); Material contents = Materials.materialInBucket(event.getItem()); if(Materials.isLiquid(contents) || (contents == Material.AIR && targetBlock.isLiquid())) { callEvent(event, targetBlock.getState(), BlockStateUtils.cloneWithMaterial(targetBlock, contents), blockResolver.getOwner(event.getBlock())); } } }
Example 9
Source File: ExplosiveTool.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
protected void breakBlock(Player p, ItemStack item, Block b, int fortune, List<ItemStack> drops) { if (b.getType() != Material.AIR && !b.isLiquid() && !MaterialCollections.getAllUnbreakableBlocks().contains(b.getType()) && SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.BREAK_BLOCK)) { SlimefunPlugin.getProtectionManager().logAction(p, b, ProtectableAction.BREAK_BLOCK); b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType()); SlimefunItem sfItem = BlockStorage.check(b); if (sfItem != null && !sfItem.useVanillaBlockBreaking()) { SlimefunBlockHandler handler = SlimefunPlugin.getRegistry().getBlockHandlers().get(sfItem.getID()); if (handler != null && !handler.onBreak(p, b, sfItem, UnregisterReason.PLAYER_BREAK)) { drops.add(BlockStorage.retrieve(b)); } } else if (b.getType() == Material.PLAYER_HEAD || b.getType().name().endsWith("_SHULKER_BOX")) { b.breakNaturally(); } else { boolean applyFortune = b.getType().name().endsWith("_ORE") && b.getType() != Material.IRON_ORE && b.getType() != Material.GOLD_ORE; for (ItemStack drop : b.getDrops(getItem())) { // For some reason this check is necessary with Paper if (drop != null && drop.getType() != Material.AIR) { b.getWorld().dropItemNaturally(b.getLocation(), applyFortune ? new CustomItem(drop, fortune) : drop); } } b.setType(Material.AIR); } damageItem(p, item); } }
Example 10
Source File: GlobalListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) public void onFlow(BlockFromToEvent e) { RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Is BlockFromToEvent event"); Block b = e.getToBlock(); Block bfrom = e.getBlock(); RedProtect.get().logger.debug(LogLevel.DEFAULT, "GlobalListener - Is BlockFromToEvent event is to " + b.getType().name() + " from " + bfrom.getType().name()); Region r = RedProtect.get().rm.getTopRegion(b.getLocation()); if (r != null) { return; } if (bfrom.isLiquid() && !RedProtect.get().config.globalFlagsRoot().worlds.get(b.getWorld().getName()).allow_changes_of.liquid_flow) { e.setCancelled(true); return; } if ((bfrom.getType().equals(Material.WATER) || (bfrom.getType().name().contains("WATER") && (bfrom.getType().name().contains("STATIONARY") || bfrom.getType().name().contains("FLOWING")))) && !RedProtect.get().config.globalFlagsRoot().worlds.get(b.getWorld().getName()).allow_changes_of.water_flow) { e.setCancelled(true); return; } if ((bfrom.getType().equals(Material.LAVA) || (bfrom.getType().name().contains("LAVA") && (bfrom.getType().name().contains("STATIONARY") || bfrom.getType().name().contains("FLOWING")))) && !RedProtect.get().config.globalFlagsRoot().worlds.get(b.getWorld().getName()).allow_changes_of.lava_flow) { e.setCancelled(true); return; } if (!b.isEmpty() && !RedProtect.get().config.globalFlagsRoot().worlds.get(b.getWorld().getName()).allow_changes_of.flow_damage) { e.setCancelled(true); } }
Example 11
Source File: BlockListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) public void onFlow(BlockFromToEvent e) { RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is BlockFromToEvent event"); Block bto = e.getToBlock(); Block bfrom = e.getBlock(); RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is BlockFromToEvent event is to " + bto.getType().name() + " from " + bfrom.getType().name()); Region rto = RedProtect.get().rm.getTopRegion(bto.getLocation()); Region rfrom = RedProtect.get().rm.getTopRegion(bfrom.getLocation()); boolean isLiquid = bfrom.isLiquid() || bfrom.getType().name().contains("BUBBLE_COLUMN") || bfrom.getType().name().contains("KELP"); if (rto != null && isLiquid && !rto.canFlow()) { e.setCancelled(true); return; } if (rfrom != null && isLiquid && !rfrom.canFlow()) { e.setCancelled(true); return; } if (rto != null && !bto.isEmpty() && !rto.canFlowDamage()) { e.setCancelled(true); return; } //deny blocks spread in/out regions if (rfrom != null && rto != null && rfrom != rto && !rfrom.sameLeaders(rto)) { e.setCancelled(true); return; } if (rfrom == null && rto != null) { e.setCancelled(true); } }
Example 12
Source File: FlagFireworks.java From HeavySpleef with GNU General Public License v3.0 | 4 votes |
@Subscribe public void onPlayerWinGame(PlayerWinGameEvent event) { for (Location location : getValue()) { int amount = random.nextInt(3) + 3; for (int i = 0; i < amount; i++) { Location spawn; int trys = 0; do { int x = random.nextInt(8) - 4; int y = random.nextInt(8) - 4; int z = random.nextInt(8) - 4; spawn = location.clone().add(x, y, z); Block block = spawn.getBlock(); if (!block.isLiquid() && block.getType() != Material.AIR) { //Do another search spawn = null; } } while (spawn == null && ++trys < MAX_TRYS); if (spawn == null) { continue; } Firework firework = (Firework) spawn.getWorld().spawnEntity(spawn, EntityType.FIREWORK); FireworkMeta meta = firework.getFireworkMeta(); Type type = typeValues.get(random.nextInt(typeValues.size())); Color c1 = colorValues.get(random.nextInt(colorValues.size())); Color c2 = colorValues.get(random.nextInt(colorValues.size())); FireworkEffect effect = FireworkEffect.builder() .flicker(random.nextBoolean()) .withColor(c1) .withFade(c2) .with(type) .trail(random.nextBoolean()) .build(); meta.addEffect(effect); int rp = random.nextInt(3); meta.setPower(rp); firework.setFireworkMeta(meta); } } }
Example 13
Source File: GridManager.java From askyblock with GNU General Public License v2.0 | 4 votes |
/** * Checks if this location is safe for a player to teleport to. Used by * warps and boat exits Unsafe is any liquid or air and also if there's no * space * * @param l * - Location to be checked * @return true if safe, otherwise false */ public static boolean isSafeLocation(final Location l) { if (l == null) { return false; } // TODO: improve the safe location finding. //Bukkit.getLogger().info("DEBUG: " + l.toString()); final Block ground = l.getBlock().getRelative(BlockFace.DOWN); final Block space1 = l.getBlock(); final Block space2 = l.getBlock().getRelative(BlockFace.UP); //Bukkit.getLogger().info("DEBUG: ground = " + ground.getType()); //Bukkit.getLogger().info("DEBUG: space 1 = " + space1.getType()); //Bukkit.getLogger().info("DEBUG: space 2 = " + space2.getType()); // Portals are not "safe" if (space1.getType() == Material.PORTAL || ground.getType() == Material.PORTAL || space2.getType() == Material.PORTAL || space1.getType() == Material.ENDER_PORTAL || ground.getType() == Material.ENDER_PORTAL || space2.getType() == Material.ENDER_PORTAL) { return false; } // If ground is AIR, then this is either not good, or they are on slab, // stair, etc. if (ground.getType() == Material.AIR) { // Bukkit.getLogger().info("DEBUG: air"); return false; } // In ASkyBlock, liquid may be unsafe if (ground.isLiquid() || space1.isLiquid() || space2.isLiquid()) { if (Settings.acidDamage > 0D || ground.getType().equals(Material.STATIONARY_LAVA) || ground.getType().equals(Material.LAVA) || space1.getType().equals(Material.STATIONARY_LAVA) || space1.getType().equals(Material.LAVA) || space2.getType().equals(Material.STATIONARY_LAVA) || space2.getType().equals(Material.LAVA)) { return false; } } MaterialData md = ground.getState().getData(); if (md instanceof SimpleAttachableMaterialData) { //Bukkit.getLogger().info("DEBUG: trapdoor/button/tripwire hook etc."); if (md instanceof TrapDoor) { TrapDoor trapDoor = (TrapDoor)md; if (trapDoor.isOpen()) { //Bukkit.getLogger().info("DEBUG: trapdoor open"); return false; } } else { return false; } //Bukkit.getLogger().info("DEBUG: trapdoor closed"); } if (ground.getType().equals(Material.CACTUS) || ground.getType().equals(Material.BOAT) || ground.getType().equals(Material.FENCE) || ground.getType().equals(Material.NETHER_FENCE) || ground.getType().equals(Material.SIGN_POST) || ground.getType().equals(Material.WALL_SIGN)) { // Bukkit.getLogger().info("DEBUG: cactus"); return false; } // Check that the space is not solid // The isSolid function is not fully accurate (yet) so we have to // check // a few other items // isSolid thinks that PLATEs and SIGNS are solid, but they are not if (space1.getType().isSolid() && !space1.getType().equals(Material.SIGN_POST) && !space1.getType().equals(Material.WALL_SIGN)) { return false; } return !space2.getType().isSolid() || space2.getType().equals(Material.SIGN_POST) || space2 .getType().equals(Material.WALL_SIGN); }
Example 14
Source File: TeleportFeature.java From AreaShop with GNU General Public License v3.0 | 4 votes |
/** * Checks if a certain location is safe to teleport to. * @param location The location to check * @return true if it is safe, otherwise false */ private boolean isSafe(Location location) { Block feet = location.getBlock(); Block head = feet.getRelative(BlockFace.UP); Block below = feet.getRelative(BlockFace.DOWN); Block above = head.getRelative(BlockFace.UP); // Check the block at the feet and head of the player if((feet.getType().isSolid() && !canSpawnIn(feet.getType())) || feet.isLiquid()) { return false; } else if((head.getType().isSolid() && !canSpawnIn(head.getType())) || head.isLiquid()) { return false; } else if(!below.getType().isSolid() || cannotSpawnOn(below.getType()) || below.isLiquid()) { return false; } else if(above.isLiquid() || cannotSpawnBeside(above.getType())) { return false; } // Get all blocks around the player (below foot level, foot level, head level and above head level) Set<Material> around = new HashSet<>(); for(int y = 0; y <= 3; y++) { for(int x = -1; x <= 1; x++) { for(int z = -1; z <= 1; z++) { // Skip blocks in the column of the player if(x == 0 && z == 0) { continue; } around.add(below.getRelative(x, y, z).getType()); } } } // Check the blocks around the player for(Material material : around) { if(cannotSpawnBeside(material)) { return false; } } return true; }
Example 15
Source File: RedProtectUtil.java From RedProtect with GNU General Public License v3.0 | 4 votes |
private boolean isSecure(Location loc) { Block b = loc.add(0, -1, 0).getBlock(); return (!b.isLiquid() && !b.isEmpty()) || b.getType().name().contains("LAVA"); }
Example 16
Source File: CommandHandler.java From NyaaUtils with MIT License | 4 votes |
@SubCommand(value = "tpall", permission = "nu.tpall") public void tpall(CommandSender sender, Arguments args) { Player p = asPlayer(sender); int r = args.nextInt(); Block center = p.getLocation().getBlock(); int minX = center.getX() - r; int minZ = center.getZ() - r; int maxX = center.getX() + r; int maxZ = center.getZ() + r; int maxY = center.getY() + 1; List<Location> locations = new ArrayList<>(); int playerCount = Bukkit.getOnlinePlayers().size() - 1; for (int x = minX; x <= maxX; x++) { for (int z = minZ; z <= maxZ; z++) { for (int i = 0; i <= 16; i++) { Block b = p.getWorld().getBlockAt(x, maxY - i, z); if (b.getType().isSolid()) { Block b2 = b.getRelative(BlockFace.UP, 1); Block b3 = b.getRelative(BlockFace.UP, 2); if ((b2.isEmpty() || b2.isPassable()) && (b3.isEmpty() || b3.isPassable()) && !b2.isLiquid() && !b3.isLiquid()) { Location loc = b.getBoundingBox().getCenter().toLocation(b.getWorld()); loc.setY(b.getBoundingBox().getMaxY()); locations.add(loc.clone()); break; } } } } } if (locations.size() < playerCount) { msg(sender, "user.tpall.error"); return; } Collections.shuffle(locations); int success = 0; for (Player player : Bukkit.getOnlinePlayers()) { if (!player.isDead() && player.getUniqueId() != p.getUniqueId()) { if (player.getWorld() == p.getWorld() && player.getLocation().distance(p.getLocation()) + 3 <= r) { continue; } Location old = player.getLocation().clone(); if (player.teleport(locations.get(success))) { success++; plugin.ess.getUser(player).setLastLocation(old); } } } msg(sender, "user.tpall.success", success); }
Example 17
Source File: SitListener.java From NyaaUtils with MIT License | 4 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onClickBlock(PlayerInteractEvent event) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.hasBlock() && !event.hasItem()) { Block block = event.getClickedBlock(); BlockFace face = event.getBlockFace(); if (face == BlockFace.DOWN || block.isLiquid() || !plugin.cfg.sit_blocks.contains(block.getType())) { return; } Block relative = block.getRelative(0, 1, 0); Player player = event.getPlayer(); if (messageCooldown.getIfPresent(player.getUniqueId()) != null) { return; } messageCooldown.put(player.getUniqueId(), true); if (!player.hasPermission("nu.sit") || !enabledPlayers.contains(player.getUniqueId()) || player.isInsideVehicle() || !player.getPassengers().isEmpty() || player.getGameMode() == GameMode.SPECTATOR || !player.isOnGround()) { return; } if (relative.isLiquid() || !(relative.isEmpty() || relative.isPassable())) { player.sendMessage(I18n.format("user.sit.invalid_location")); return; } Vector vector = block.getBoundingBox().getCenter().clone(); Location loc = vector.setY(block.getBoundingBox().getMaxY()).toLocation(player.getWorld()).clone(); for (SitLocation sl : plugin.cfg.sit_locations.values()) { if (sl.blocks != null && sl.x != null && sl.y != null && sl.z != null && sl.blocks.contains(block.getType().name())) { loc.add(sl.x, sl.y, sl.z); } } if (block.getBlockData() instanceof Directional) { face = ((Directional) block.getBlockData()).getFacing(); if (face == BlockFace.EAST) { loc.setYaw(90); } else if (face == BlockFace.WEST) { loc.setYaw(-90); } else if (face == BlockFace.NORTH) { loc.setYaw(0); } else if (face == BlockFace.SOUTH) { loc.setYaw(-180); } } else { if (face == BlockFace.WEST) { loc.setYaw(90); } else if (face == BlockFace.EAST) { loc.setYaw(-90); } else if (face == BlockFace.SOUTH) { loc.setYaw(0); } else if (face == BlockFace.NORTH) { loc.setYaw(-180); } else { loc.setYaw(player.getEyeLocation().getYaw()); } } for (Entity e : loc.getWorld().getNearbyEntities(loc, 0.5, 0.7, 0.5)) { if (e instanceof LivingEntity) { if (e.hasMetadata(metadata_key) || (e instanceof Player && e.isInsideVehicle() && e.getVehicle().hasMetadata(metadata_key))) { player.sendMessage(I18n.format("user.sit.invalid_location")); return; } } } Location safeLoc = player.getLocation().clone(); ArmorStand armorStand = loc.getWorld().spawn(loc, ArmorStand.class, (e) -> { e.setVisible(false); e.setPersistent(false); e.setCanPickupItems(false); e.setBasePlate(false); e.setArms(false); e.setMarker(true); e.setInvulnerable(true); e.setGravity(false); }); if (armorStand != null) { armorStand.setMetadata(metadata_key, new FixedMetadataValue(plugin, true)); if (armorStand.addPassenger(player)) { safeLocations.put(player.getUniqueId(), safeLoc); } else { armorStand.remove(); } } } }
Example 18
Source File: FightHitbox.java From Hawk with GNU General Public License v3.0 | 4 votes |
private void processDirection(InteractEntityEvent e, float yaw, float pitch) { Entity entity = e.getEntity(); if (!(entity instanceof Player) && !CHECK_OTHER_ENTITIES) return; Player attacker = e.getPlayer(); int ping = ServerUtils.getPing(attacker); if (ping > PING_LIMIT && PING_LIMIT != -1) return; HawkPlayer att = e.getHawkPlayer(); Location attackerEyeLocation = att.getPosition().clone().add(new Vector(0, 1.62, 0)).toLocation(att.getWorld()); Vector attackerDirection = MathPlus.getDirection(yaw, pitch); double maxReach = MAX_REACH; if (attacker.getGameMode() == GameMode.CREATIVE) maxReach += 1.9; Vector victimLocation; if (LAG_COMPENSATION) //No need to add 50ms; the move and attack are already chronologically so close together victimLocation = hawk.getLagCompensator().getHistoryLocation(ping, e.getEntity()).toVector(); else victimLocation = e.getEntity().getLocation().toVector(); Vector eyePos = new Vector(attackerEyeLocation.getX(), attacker.isSneaking() ? attackerEyeLocation.getY() - 0.08 : attackerEyeLocation.getY(), attackerEyeLocation.getZ()); Vector direction = new Vector(attackerDirection.getX(), attackerDirection.getY(), attackerDirection.getZ()); Ray attackerRay = new Ray(eyePos, direction); AABB victimAABB; victimAABB = WrappedEntity.getWrappedEntity(entity).getHitbox(victimLocation); victimAABB.expand(BOX_EPSILON, BOX_EPSILON, BOX_EPSILON); Vector intersectVec3d = victimAABB.intersectsRay(attackerRay, 0, Float.MAX_VALUE); if (DEBUG_HITBOX) { victimAABB.highlight(hawk, attacker.getWorld(), 0.29); } if (DEBUG_RAY) { attackerRay.highlight(hawk, attacker.getWorld(), maxReach, 0.1); } if (intersectVec3d != null) { Location intersect = new Location(attacker.getWorld(), intersectVec3d.getX(), intersectVec3d.getY(), intersectVec3d.getZ()); double interDistance = intersect.distance(attackerEyeLocation); if (interDistance > maxReach) { punish(att, 1, true, e, new Placeholder("type", "Reach: " + MathPlus.round(interDistance, 2) + "m")); return; } if (CHECK_OCCLUSION && interDistance > 1D) { BlockIterator iter = new BlockIterator(attacker.getWorld(), eyePos, attackerDirection, 0, (int) interDistance + 1); while (iter.hasNext()) { Block bukkitBlock = iter.next(); if (bukkitBlock.getType() == Material.AIR || bukkitBlock.isLiquid()) continue; WrappedBlock b = WrappedBlock.getWrappedBlock(bukkitBlock, att.getClientVersion()); Vector intersection = b.getHitBox().intersectsRay(new Ray(attackerEyeLocation.toVector(), attackerDirection), 0, Float.MAX_VALUE); if (intersection != null) { if (intersection.distance(eyePos) < interDistance) { punish(att, 1, true, e, new Placeholder("type", "Interacted through " + b.getBukkitBlock().getType())); return; } } } } } else if (CHECK_BOX_INTERSECTION) { punish(att, 1, true, e, new Placeholder("type", "Did not hit hitbox.")); return; } reward(att); //reward player }