Java Code Examples for org.bukkit.Material#PISTON_MOVING_PIECE
The following examples show how to use
org.bukkit.Material#PISTON_MOVING_PIECE .
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: PGMListener.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) public void protect36(final PlayerInteractEvent event) { if (event.getClickedBlock() != null) { if (event.getClickedBlock().getType() == Material.PISTON_MOVING_PIECE) { event.setCancelled(true); } } }
Example 2
Source File: PGMListener.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) public void protect36(final PlayerInteractEvent event) { if(event.getClickedBlock() != null) { if(event.getClickedBlock().getType() == Material.PISTON_MOVING_PIECE) { event.setCancelled(true); } } }
Example 3
Source File: Phase.java From Hawk with GNU General Public License v3.0 | 4 votes |
@Override protected void check(MoveEvent event) { Location locTo = event.getTo(); Location locFrom = event.getFrom(); Player p = event.getPlayer(); HawkPlayer pp = event.getHawkPlayer(); if(!locFrom.getWorld().equals(locTo.getWorld())) return; //this stops an NPE double distanceSquared = locFrom.distanceSquared(locTo); if (distanceSquared == 0) return; double horizDistanceSquared = Math.pow(locTo.getX() - locFrom.getX(), 2) + Math.pow(locTo.getZ() - locFrom.getZ(), 2); double vertDistance = Math.abs(locTo.getY() - locFrom.getY()); Vector moveDirection = new Vector(locTo.getX() - locFrom.getX(), locTo.getY() - locFrom.getY(), locTo.getZ() - locFrom.getZ()); AABB playerFrom = WrappedEntity.getWrappedEntity(p).getCollisionBox(locFrom.toVector()); playerFrom.shrink(SIDE_EPSILON, 0, SIDE_EPSILON); playerFrom.getMin().setY(playerFrom.getMin().getY() + BOTTOM_EPSILON); playerFrom.getMax().setY(playerFrom.getMax().getY() - TOP_EPSILON); AABB playerTo = playerFrom.clone(); playerTo.translate(moveDirection); Vector minBigBox = new Vector(Math.min(playerFrom.getMin().getX(), playerTo.getMin().getX()), Math.min(playerFrom.getMin().getY(), playerTo.getMin().getY()), Math.min(playerFrom.getMin().getZ(), playerTo.getMin().getZ())); Vector maxBigBox = new Vector(Math.max(playerFrom.getMax().getX(), playerTo.getMax().getX()), Math.max(playerFrom.getMax().getY(), playerTo.getMax().getY()), Math.max(playerFrom.getMax().getZ(), playerTo.getMax().getZ())); AABB bigBox = new AABB(minBigBox, maxBigBox); AABB selection = bigBox.clone(); selection.getMin().setY(selection.getMin().getY() - 0.6); //we need to grab blocks below us too, such as fences Set<Location> ignored = pp.getIgnoredBlockCollisions(); GameMode gm = p.getGameMode(); if(gm == GameMode.SURVIVAL || gm == GameMode.ADVENTURE || gm == GameMode.CREATIVE) { for (int x = selection.getMin().getBlockX(); x <= selection.getMax().getBlockX(); x++) { for (int y = selection.getMin().getBlockY(); y <= selection.getMax().getBlockY(); y++) { for (int z = selection.getMin().getBlockZ(); z <= selection.getMax().getBlockZ(); z++) { Location blockLoc = new Location(locTo.getWorld(), x, y, z); //Skip block if it updated within player AABB (only if they move slowly) if(ignored.contains(blockLoc) && horizDistanceSquared <= HORIZONTAL_DISTANCE_THRESHOLD && vertDistance <= VERTICAL_DISTANCE_THRESHOLD) continue; Block bukkitBlock = ServerUtils.getBlockAsync(blockLoc); if (bukkitBlock == null) continue; WrappedBlock block = WrappedBlock.getWrappedBlock(bukkitBlock, pp.getClientVersion()); if (!block.isSolid()) continue; if(bukkitBlock.getType() == Material.PISTON_MOVING_PIECE) { continue; } if (bukkitBlock.getState().getData() instanceof Openable && horizDistanceSquared <= HORIZONTAL_DISTANCE_THRESHOLD && vertDistance <= VERTICAL_DISTANCE_THRESHOLD) { continue; } for (AABB test : block.getCollisionBoxes()) { //check if "test" box is even in "bigBox" if (!test.isColliding(bigBox)) continue; boolean xCollide = collides2d(test.getMin().getZ(), test.getMax().getZ(), test.getMin().getY(), test.getMax().getY(), playerFrom.getMin().getZ(), playerFrom.getMax().getZ(), playerFrom.getMin().getY(), playerFrom.getMax().getY(), moveDirection.getZ(), moveDirection.getY()); boolean yCollide = collides2d(test.getMin().getX(), test.getMax().getX(), test.getMin().getZ(), test.getMax().getZ(), playerFrom.getMin().getX(), playerFrom.getMax().getX(), playerFrom.getMin().getZ(), playerFrom.getMax().getZ(), moveDirection.getX(), moveDirection.getZ()); boolean zCollide = collides2d(test.getMin().getX(), test.getMax().getX(), test.getMin().getY(), test.getMax().getY(), playerFrom.getMin().getX(), playerFrom.getMax().getX(), playerFrom.getMin().getY(), playerFrom.getMax().getY(), moveDirection.getX(), moveDirection.getY()); if (xCollide && yCollide && zCollide) { punish(pp, false, event, new Placeholder("block", bukkitBlock.getType())); tryRubberband(event); return; } } } } } } reward(pp); }
Example 4
Source File: BlockPistonEvent.java From Kettle with GNU General Public License v3.0 | 2 votes |
/** * Returns true if the Piston in the event is sticky. * * @return stickiness of the piston */ public boolean isSticky() { return block.getType() == Material.PISTON_STICKY_BASE || block.getType() == Material.PISTON_MOVING_PIECE; }