org.bukkit.material.Openable Java Examples

The following examples show how to use org.bukkit.material.Openable. 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: DoorEvent.java    From BetonQuest with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Void execute(String playerID) throws QuestRuntimeException {
    Block block = loc.getLocation(playerID).getBlock();
    BlockState state = block.getState();
    MaterialData data = state.getData();
    if (data instanceof Openable) {
        Openable openable = (Openable) data;
        switch (type) {
            case ON:
                openable.setOpen(true);
                break;
            case OFF:
                openable.setOpen(false);
                break;
            case TOGGLE:
                openable.setOpen(!openable.isOpen());
                break;
        }
        state.setData((MaterialData) openable);
        state.update();
    }
    return null;
}
 
Example #2
Source File: AdjacentBlocks.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 #3
Source File: Phase.java    From Hawk with GNU General Public License v3.0 4 votes vote down vote up
@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: VersionHelper18.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public boolean isOpenable(Block b) {
    return b.getState().getData() instanceof Openable;
}
 
Example #5
Source File: VersionHelper112.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public boolean isOpenable(Block b) {
    return b.getState().getData() instanceof Openable;
}
 
Example #6
Source File: VersionHelper113.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public boolean isOpenable(Block b) {
    return b.getState().getData() instanceof Openable;
}