Java Code Examples for org.bukkit.entity.Player#isSleeping()

The following examples show how to use org.bukkit.entity.Player#isSleeping() . 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: FlyOld.java    From Hawk with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void check(MoveEvent event) {
    Player p = event.getPlayer();
    HawkPlayer pp = event.getHawkPlayer();
    double deltaY = event.getTo().getY() - event.getFrom().getY();
    if (pp.hasFlyPending() && p.getAllowFlight())
        return;
    if (!event.isOnGroundReally() && !pp.isFlying() && !p.isInsideVehicle() && !pp.isSwimming() && !p.isSleeping() &&
            !isInClimbable(event.getTo()) && !isOnBoat(p, event.getTo())) {

        if (!inAir.contains(p.getUniqueId()) && deltaY > 0)
            lastDeltaY.put(p.getUniqueId(), 0.42 + getJumpBoostLvl(p) * 0.1);

        //handle any pending knockbacks
        if(event.hasAcceptedKnockback())
            lastDeltaY.put(p.getUniqueId(), deltaY);

        if(event.isSlimeBlockBounce())
            lastDeltaY.put(p.getUniqueId(), deltaY);

        double expectedDeltaY = lastDeltaY.getOrDefault(p.getUniqueId(), 0D);
        double epsilon = 0.03;

        //lastDeltaY.put(p.getUniqueId(), (lastDeltaY.getOrDefault(p.getUniqueId(), 0D) - 0.025) * 0.8); //water function
        if (WrappedEntity.getWrappedEntity(p).getCollisionBox(event.getFrom().toVector()).getMaterials(p.getWorld()).contains(Material.WEB)) {
            lastDeltaY.put(p.getUniqueId(), -0.007);
            epsilon = 0.000001;
            if (AdjacentBlocks.onGroundReally(event.getTo().clone().add(0, -0.03, 0), -1, false, 0.02, pp))
                return;
        } else if(!pp.isInWater() && event.isInWater()) {
            //entering liquid
            lastDeltaY.put(p.getUniqueId(), (lastDeltaY.getOrDefault(p.getUniqueId(), 0D) * 0.98) - 0.038399);
        } else {
            //in air
            lastDeltaY.put(p.getUniqueId(), (lastDeltaY.getOrDefault(p.getUniqueId(), 0D) - 0.08) * 0.98);
        }


        //handle teleport
        if (event.hasTeleported()) {
            lastDeltaY.put(p.getUniqueId(), 0D);
            expectedDeltaY = 0;
            legitLoc.put(p.getUniqueId(), event.getTo());
        }

        if (deltaY - expectedDeltaY > epsilon && event.hasDeltaPos()) { //oopsie daisy. client made a goof up

            //wait one little second: minecraft is being a pain in the ass and it wants to play tricks when you parkour on the very edge of blocks
            //we need to check this first...
            if (deltaY < 0) {
                Location checkLoc = event.getFrom().clone();
                checkLoc.setY(event.getTo().getY());
                if (AdjacentBlocks.onGroundReally(checkLoc, deltaY, false, 0.02, pp)) {
                    onGroundStuff(p);
                    return;
                }
                //extrapolate move BEFORE getFrom, then check
                checkLoc.setY(event.getFrom().getY());
                checkLoc.setX(checkLoc.getX() - (event.getTo().getX() - event.getFrom().getX()));
                checkLoc.setZ(checkLoc.getZ() - (event.getTo().getZ() - event.getFrom().getZ()));
                if (AdjacentBlocks.onGroundReally(checkLoc, deltaY, false, 0.02, pp)) {
                    onGroundStuff(p);
                    return;
                }
            }

            if(event.isOnClientBlock() != null) {
                onGroundStuff(p);
                return;
            }

            //scold the child
            punish(pp, false, event);
            tryRubberband(event);
            lastDeltaY.put(p.getUniqueId(), canCancel() ? 0 : deltaY);
            failedSoDontUpdateRubberband.add(p.getUniqueId());
            return;
        }

        reward(pp);

        //the player is in air now, since they have a positive Y velocity and they're not on the ground
        if (inAir.contains(p.getUniqueId()))
            //upwards now
            stupidMoves.put(p.getUniqueId(), 0);

        //handle stupid moves, because the client tends to want to jump a little late if you jump off the edge of a block
        if (stupidMoves.getOrDefault(p.getUniqueId(), 0) >= STUPID_MOVES || (deltaY > 0 && AdjacentBlocks.onGroundReally(event.getFrom(), -1, true, 0.02, pp)))
            //falling now
            inAir.add(p.getUniqueId());
        stupidMoves.put(p.getUniqueId(), stupidMoves.getOrDefault(p.getUniqueId(), 0) + 1);
    } else {
        onGroundStuff(p);
    }

    if (!failedSoDontUpdateRubberband.contains(p.getUniqueId()) || event.isOnGroundReally()) {
        legitLoc.put(p.getUniqueId(), p.getLocation());
        failedSoDontUpdateRubberband.remove(p.getUniqueId());
    }

}
 
Example 2
Source File: CondIsSleeping.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean check(final Player p) {
	return p.isSleeping();
}
 
Example 3
Source File: VaultOperations.java    From PlayerVaults with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Open a player's own vault.
 *
 * @param player The player to open to.
 * @param arg    The vault number to open.
 * @return Whether or not the player was allowed to open it.
 */
public static boolean openOwnVault(Player player, String arg) {
    if (isLocked()) {
        return false;
    }
    if (player.isSleeping() || player.isDead() || !player.isOnline()) {
        return false;
    }
    int number;
    try {
        number = Integer.parseInt(arg);
        if (number < 1) {
            return false;
        }
    } catch (NumberFormatException nfe) {
        player.sendMessage(Lang.TITLE.toString() + Lang.MUST_BE_NUMBER.toString());
        return false;
    }

    if (checkPerms(player, number)) {
        if (EconomyOperations.payToOpen(player, number)) {
            Inventory inv = VaultManager.getInstance().loadOwnVault(player, number, getMaxVaultSize(player));
            if (inv == null) {
                PlayerVaults.debug(String.format("Failed to open null vault %d for %s. This is weird.", number, player.getName()));
                return false;
            }

            player.openInventory(inv);

            // Check if the inventory was actually opened
            if (player.getOpenInventory().getTopInventory() instanceof CraftingInventory || player.getOpenInventory().getTopInventory() == null) {
                PlayerVaults.debug(String.format("Cancelled opening vault %s for %s from an outside source.", arg, player.getName()));
                return false; // inventory open event was cancelled.
            }

            VaultViewInfo info = new VaultViewInfo(player.getUniqueId().toString(), number);
            PlayerVaults.getInstance().getOpenInventories().put(info.toString(), inv);

            player.sendMessage(Lang.TITLE.toString() + Lang.OPEN_VAULT.toString().replace("%v", arg));
            return true;
        } else {
            player.sendMessage(Lang.TITLE.toString() + Lang.INSUFFICIENT_FUNDS);
            return false;
        }
    } else {
        player.sendMessage(Lang.TITLE.toString() + Lang.NO_PERMS);
    }
    return false;
}
 
Example 4
Source File: VaultOperations.java    From PlayerVaults with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Open another player's vault.
 *
 * @param player     The player to open to.
 * @param vaultOwner The name of the vault owner.
 * @param arg        The vault number to open.
 * @return Whether or not the player was allowed to open it.
 */
public static boolean openOtherVault(Player player, String vaultOwner, String arg) {
    if (isLocked()) {
        return false;
    }

    if (player.isSleeping() || player.isDead() || !player.isOnline()) {
        return false;
    }

    long time = System.currentTimeMillis();

    int number = 0;
    try {
        number = Integer.parseInt(arg);
        if (number < 1) {
            player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
            return false;
        }
    } catch (NumberFormatException nfe) {
        player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
    }

    Inventory inv = VaultManager.getInstance().loadOtherVault(vaultOwner, number, getMaxVaultSize(vaultOwner));
    String name = vaultOwner;
    try {
        OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString(vaultOwner));
        name = offlinePlayer.getName();
    } catch (Exception e) {
        // not a player
    }

    if (inv == null) {
        player.sendMessage(Lang.TITLE.toString() + Lang.VAULT_DOES_NOT_EXIST.toString());
    } else {
        player.openInventory(inv);

        // Check if the inventory was actually opened
        if (player.getOpenInventory().getTopInventory() instanceof CraftingInventory || player.getOpenInventory().getTopInventory() == null) {
            PlayerVaults.debug(String.format("Cancelled opening vault %s for %s from an outside source.", arg, player.getName()));
            return false; // inventory open event was cancelled.
        }
        player.sendMessage(Lang.TITLE.toString() + Lang.OPEN_OTHER_VAULT.toString().replace("%v", arg).replace("%p", name));
        PlayerVaults.debug("opening other vault", time);

        // Need to set ViewInfo for a third party vault for the opening player.
        VaultViewInfo info = new VaultViewInfo(vaultOwner, number);
        PlayerVaults.getInstance().getInVault().put(player.getUniqueId().toString(), info);
        PlayerVaults.getInstance().getOpenInventories().put(player.getUniqueId().toString(), inv);
        return true;
    }

    PlayerVaults.debug("opening other vault returning false", time);
    return false;
}