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

The following examples show how to use org.bukkit.entity.Player#getAllowFlight() . 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: ModeCoordinator.java    From StaffPlus with GNU General Public License v3.0 6 votes vote down vote up
public void addMode(Player player)
{
	UUID uuid = player.getUniqueId();
	User user = userManager.get(uuid);
	ModeDataVault modeData = new ModeDataVault(uuid, player.getInventory().getContents(), player.getInventory().getArmorContents(), player.getLocation(), player.getAllowFlight(), player.getGameMode(), user.getVanishType());
	
	if(isInMode(player.getUniqueId()))
	{
		return;
	}
	
	JavaUtils.clearInventory(player);
	modeUsers.put(uuid, modeData);
	setPassive(player, user);
	message.send(player, messages.modeStatus.replace("%status%", "enabled"), messages.prefixGeneral);
}
 
Example 2
Source File: FlyFlagHandler.java    From WorldGuardExtraFlagsPlugin with MIT License 6 votes vote down vote up
private void handleValue(Player player, State state)
{
	if (state != null)
	{
		boolean value = (state == State.ALLOW ? true : false);
		
		if (player.getAllowFlight() != value)
		{
			if (this.originalFly == null)
			{
				this.originalFly = player.getAllowFlight();
			}
			
			player.setAllowFlight(value);
		}
	}
	else
	{
		if (this.originalFly != null)
		{
			player.setAllowFlight(this.originalFly);
			
			this.originalFly = null;
		}
	}
}
 
Example 3
Source File: TutorialPlayer.java    From ServerTutorial with MIT License 5 votes vote down vote up
public TutorialPlayer(Player player) {
    this.startLoc = player.getLocation();
    this.inventory = player.getInventory().getContents();
    this.flight = player.isFlying();
    this.allowFlight = player.getAllowFlight();
    this.exp = player.getExp();
    this.level = player.getLevel();
    this.hunger = player.getFoodLevel();
    this.health = player.getHealth();
    this.gameMode = player.getGameMode();
}
 
Example 4
Source File: PWIPlayer.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
PWIPlayer(Player player, Group group, double bankBalance, double balance, boolean useAttributes) {
    this.uuid = player.getUniqueId();
    this.name = player.getName();
    this.location = player.getLocation();

    this.group = group;
    this.saved = false;

    this.armor = player.getInventory().getArmorContents();
    this.enderChest = player.getEnderChest().getContents();
    this.inventory = player.getInventory().getContents();

    this.canFly = player.getAllowFlight();
    this.displayName = player.getDisplayName();
    this.exhaustion = player.getExhaustion();
    this.experience = player.getExp();
    this.isFlying = player.isFlying();
    this.foodLevel = player.getFoodLevel();
    if (useAttributes) {
        this.maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue();
    } else {
        this.maxHealth = player.getMaxHealth();
    }
    this.health = player.getHealth();
    this.gamemode = player.getGameMode();
    this.level = player.getLevel();
    this.saturationLevel = player.getSaturation();
    this.potionEffects = player.getActivePotionEffects();
    this.fallDistance = player.getFallDistance();
    this.fireTicks = player.getFireTicks();
    this.maxAir = player.getMaximumAir();
    this.remainingAir = player.getRemainingAir();

    this.bankBalance = bankBalance;
    this.balance = balance;
}
 
Example 5
Source File: SilentOpenChest.java    From SuperVanish with Mozilla Public License 2.0 5 votes vote down vote up
static StateInfo extract(Player p) {
    return new StateInfo(
            p.getAllowFlight(),
            p.isFlying(),
            p.getGameMode()
    );
}
 
Example 6
Source File: LimboServiceHelper.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a LimboPlayer with the given player's details.
 *
 * @param player the player to process
 * @param isRegistered whether the player is registered
 * @param location the player location
 * @return limbo player with the player's data
 */
LimboPlayer createLimboPlayer(Player player, boolean isRegistered, Location location) {
    // For safety reasons an unregistered player should not have OP status after registration
    boolean isOperator = isRegistered && player.isOp();
    boolean flyEnabled = player.getAllowFlight();
    float walkSpeed = player.getWalkSpeed();
    float flySpeed = player.getFlySpeed();
    Collection<String> playerGroups = permissionsManager.hasGroupSupport()
        ? permissionsManager.getGroups(player) : Collections.emptyList();
    logger.debug("Player `{0}` has groups `{1}`", player.getName(), String.join(", ", playerGroups));

    return new LimboPlayer(location, isOperator, playerGroups, flyEnabled, walkSpeed, flySpeed);
}
 
Example 7
Source File: PWIPlayer.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
PWIPlayer(Player player, Group group, double bankBalance, double balance, boolean useAttributes) {
    this.uuid = player.getUniqueId();
    this.name = player.getName();
    this.location = player.getLocation();

    this.group = group;
    this.saved = false;

    this.armor = player.getInventory().getArmorContents();
    this.enderChest = player.getEnderChest().getContents();
    this.inventory = player.getInventory().getContents();

    this.canFly = player.getAllowFlight();
    this.displayName = player.getDisplayName();
    this.exhaustion = player.getExhaustion();
    this.experience = player.getExp();
    this.isFlying = player.isFlying();
    this.foodLevel = player.getFoodLevel();
    if (useAttributes) {
        this.maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue();
    } else {
        this.maxHealth = player.getMaxHealth();
    }
    this.health = player.getHealth();
    this.gamemode = player.getGameMode();
    this.level = player.getLevel();
    this.saturationLevel = player.getSaturation();
    this.potionEffects = player.getActivePotionEffects();
    this.fallDistance = player.getFallDistance();
    this.fireTicks = player.getFireTicks();
    this.maxAir = player.getMaximumAir();
    this.remainingAir = player.getRemainingAir();

    this.bankBalance = bankBalance;
    this.balance = balance;
}
 
Example 8
Source File: Acrobat.java    From AnnihilationPro with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
	public void AcrobatJumpMonitor(PlayerMoveEvent event) 
	{ 
		Player player = event.getPlayer();
		if(player.getGameMode() != GameMode.CREATIVE)
		{
			if(player.isFlying())
			{
				player.setAllowFlight(false);
				player.setFlying(false);
				return;
			}
			
			if(Game.isGameRunning())
			{
				if(!player.getAllowFlight())
				{
					AnniPlayer p = AnniPlayer.getPlayer(player.getUniqueId());
					if(p != null && p.getKit().equals(this))
					{
						if(player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() != Material.AIR && !Delays.getInstance().hasActiveDelay(player, this.getInternalName()))
						{
							//Bukkit.getLogger().info("Thing 2");
							player.setAllowFlight(true);
							return;
						}
					}
				}
			}
//			else
//			{
//				player.setAllowFlight(false);
//				player.setFlying(false);
//			}
		}
			
			
//		if(player.getGameMode() != GameMode.CREATIVE && player.isFlying())
//		{
//			player.setAllowFlight(false);
//			player.setFlying(false);
//		}
//		
//		if(Game.isGameRunning() && player.getGameMode() != GameMode.CREATIVE && !player.getAllowFlight())
//		{
//			AnniPlayer p = AnniPlayer.getPlayer(player.getUniqueId());
//			if(p != null && p.getKit().equals(this))
//			{
//				//This is possibly also where we would make them able to permanently sprint
//				if(player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() != Material.AIR && !Delays.getInstance().hasActiveDelay(player, this.getInternalName()))
//				{
//					//Bukkit.getLogger().info("Thing 2");
//					player.setAllowFlight(true);
//					return;
//				}
//			}
//			player.setAllowFlight(false);
//			player.setFlying(false);
//		}
	}
 
Example 9
Source File: StatSerializer.java    From PerWorldInventory with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Apply stats to a player.
 *
 * @param player The Player to apply the stats to.
 * @param stats  The stats to apply.
 * @param dataFormat See {@link PlayerSerializer#serialize(PWIPlayer)}.
 */
public void deserialize(Player player,JsonObject stats, int dataFormat) {
    if (settings.getProperty(PwiProperties.LOAD_CAN_FLY) && stats.has("can-fly"))
        player.setAllowFlight(stats.get("can-fly").getAsBoolean());
    if (settings.getProperty(PwiProperties.LOAD_DISPLAY_NAME) && stats.has("display-name"))
        player.setDisplayName(stats.get("display-name").getAsString());
    if (settings.getProperty(PwiProperties.LOAD_EXHAUSTION) && stats.has("exhaustion"))
        player.setExhaustion((float) stats.get("exhaustion").getAsDouble());
    if (settings.getProperty(PwiProperties.LOAD_EXP) && stats.has("exp"))
        player.setExp((float) stats.get("exp").getAsDouble());
    if (settings.getProperty(PwiProperties.LOAD_FLYING) && stats.has("flying") && player.getAllowFlight())
        player.setFlying(stats.get("flying").getAsBoolean());
    if (settings.getProperty(PwiProperties.LOAD_HUNGER) && stats.has("food"))
        player.setFoodLevel(stats.get("food").getAsInt());
    if (settings.getProperty(PwiProperties.LOAD_HEALTH) &&
            stats.has("max-health") &&
            stats.has("health")) {
        double maxHealth = stats.get("max-health").getAsDouble();
        if (bukkitService.shouldUseAttributes()) {
            player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(maxHealth);
        } else {
            player.setMaxHealth(maxHealth);
        }

        double health = stats.get("health").getAsDouble();
        if (health > 0 && health <= maxHealth) {
            player.setHealth(health);
        } else {
            player.setHealth(maxHealth);
        }
    }
    if (settings.getProperty(PwiProperties.LOAD_GAMEMODE) && (!settings.getProperty(PwiProperties.SEPARATE_GAMEMODE_INVENTORIES)) && stats.has("gamemode")) {
        if (stats.get("gamemode").getAsString().length() > 1) {
            player.setGameMode(GameMode.valueOf(stats.get("gamemode").getAsString()));
        } else {
            int gm = stats.get("gamemode").getAsInt();
            switch (gm) {
                case 0:
                    player.setGameMode(GameMode.CREATIVE);
                    break;
                case 1:
                    player.setGameMode(GameMode.SURVIVAL);
                    break;
                case 2:
                    player.setGameMode(GameMode.ADVENTURE);
                    break;
                case 3:
                    player.setGameMode(GameMode.SPECTATOR);
                    break;
            }
        }
    }
    if (settings.getProperty(PwiProperties.LOAD_LEVEL) && stats.has("level"))
        player.setLevel(stats.get("level").getAsInt());
    if (settings.getProperty(PwiProperties.LOAD_POTION_EFFECTS) && stats.has("potion-effects")) {
        if (dataFormat < 2) {
            PotionEffectSerializer.setPotionEffects(stats.get("potion-effects").getAsString(), player);
        } else {
            PotionEffectSerializer.setPotionEffects(stats.getAsJsonArray("potion-effects"), player);
        }
    }
    if (settings.getProperty(PwiProperties.LOAD_SATURATION) && stats.has("saturation"))
        player.setSaturation((float) stats.get("saturation").getAsDouble());
    if (settings.getProperty(PwiProperties.LOAD_FALL_DISTANCE) && stats.has("fallDistance"))
        player.setFallDistance(stats.get("fallDistance").getAsFloat());
    if (settings.getProperty(PwiProperties.LOAD_FIRE_TICKS) && stats.has("fireTicks"))
        player.setFireTicks(stats.get("fireTicks").getAsInt());
    if (settings.getProperty(PwiProperties.LOAD_MAX_AIR) && stats.has("maxAir"))
        player.setMaximumAir(stats.get("maxAir").getAsInt());
    if (settings.getProperty(PwiProperties.LOAD_REMAINING_AIR) && stats.has("remainingAir"))
        player.setRemainingAir(stats.get("remainingAir").getAsInt());
}
 
Example 10
Source File: PWIPlayerManager.java    From PerWorldInventory with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Get a player from the cache, and apply the cached inventories and stats
 * to the actual player. If no matching player is found in the cache, nothing
 * happens and this method simply returns.
 *
 * @param group The {@link Group} the cached player was in.
 * @param gamemode The GameMode the cached player was in.
 * @param player The current actual player to apply the data to.
 * @param cause What triggered the inventory switch; passed on for post-processing.
 */
private void getDataFromCache(Group group, GameMode gamemode, Player player, DeserializeCause cause) {
    PWIPlayer cachedPlayer = getCachedPlayer(group, gamemode, player.getUniqueId());
    if (cachedPlayer == null) {
        ConsoleLogger.debug("No data for player '" + player.getName() + "' found in cache");

        return;
    }

    ConsoleLogger.debug("Player '" + player.getName() + "' found in cache! Setting their data");

    if (settings.getProperty(PwiProperties.LOAD_ENDER_CHESTS))
        player.getEnderChest().setContents(cachedPlayer.getEnderChest());
    if (settings.getProperty(PwiProperties.LOAD_INVENTORY)) {
        player.getInventory().setContents(cachedPlayer.getInventory());
        player.getInventory().setArmorContents(cachedPlayer.getArmor());
    }
    if (settings.getProperty(PwiProperties.LOAD_CAN_FLY))
        player.setAllowFlight(cachedPlayer.getCanFly());
    if (settings.getProperty(PwiProperties.LOAD_DISPLAY_NAME))
        player.setDisplayName(cachedPlayer.getDisplayName());
    if (settings.getProperty(PwiProperties.LOAD_EXHAUSTION))
        player.setExhaustion(cachedPlayer.getExhaustion());
    if (settings.getProperty(PwiProperties.LOAD_EXP))
        player.setExp(cachedPlayer.getExperience());
    if (settings.getProperty(PwiProperties.LOAD_FLYING) && player.getAllowFlight())
        player.setFlying(cachedPlayer.isFlying());
    if (settings.getProperty(PwiProperties.LOAD_HUNGER))
        player.setFoodLevel(cachedPlayer.getFoodLevel());
    if (settings.getProperty(PwiProperties.LOAD_HEALTH)) {
        if (bukkitService.shouldUseAttributes()) {
            player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(cachedPlayer.getMaxHealth());
        } else {
            player.setMaxHealth(cachedPlayer.getMaxHealth());
        }
        if (cachedPlayer.getHealth() > 0 && cachedPlayer.getHealth() <= cachedPlayer.getMaxHealth()) {
            player.setHealth(cachedPlayer.getHealth());
        } else {
            player.setHealth(cachedPlayer.getMaxHealth());
        }
    }
    if (settings.getProperty(PwiProperties.LOAD_GAMEMODE) && (!settings.getProperty(PwiProperties.SEPARATE_GAMEMODE_INVENTORIES)))
        player.setGameMode(cachedPlayer.getGamemode());
    if (settings.getProperty(PwiProperties.LOAD_LEVEL))
        player.setLevel(cachedPlayer.getLevel());
    if (settings.getProperty(PwiProperties.LOAD_POTION_EFFECTS)) {
        for (PotionEffect effect : player.getActivePotionEffects()) {
            player.removePotionEffect(effect.getType());
        }
        player.addPotionEffects(cachedPlayer.getPotionEffects());
    }
    if (settings.getProperty(PwiProperties.LOAD_SATURATION))
        player.setSaturation(cachedPlayer.getSaturationLevel());
    if (settings.getProperty(PwiProperties.LOAD_FALL_DISTANCE))
        player.setFallDistance(cachedPlayer.getFallDistance());
    if (settings.getProperty(PwiProperties.LOAD_FIRE_TICKS))
        player.setFireTicks(cachedPlayer.getFireTicks());
    if (settings.getProperty(PwiProperties.LOAD_MAX_AIR))
        player.setMaximumAir(cachedPlayer.getMaxAir());
    if (settings.getProperty(PwiProperties.LOAD_REMAINING_AIR))
        player.setRemainingAir(cachedPlayer.getRemainingAir());
    if (settings.getProperty(PwiProperties.USE_ECONOMY)) {
        Economy econ = plugin.getEconomy();
        if (econ == null) {
            ConsoleLogger.warning("Economy saving is turned on, but no economy found!");
            return;
        }

        EconomyResponse er = econ.withdrawPlayer(player, econ.getBalance(player));
        if (er.transactionSuccess()) {
            econ.depositPlayer(player, cachedPlayer.getBalance());
        } else {
            ConsoleLogger.warning("[ECON] Unable to withdraw currency from '" + player.getName() + "': " + er.errorMessage);
        }

        EconomyResponse bankER = econ.bankWithdraw(player.getName(), econ.bankBalance(player.getName()).amount);
        if (bankER.transactionSuccess()) {
            econ.bankDeposit(player.getName(), cachedPlayer.getBankBalance());
        } else {
            ConsoleLogger.warning("[ECON] Unable to withdraw currency from bank of '" + player.getName() + "': " + er.errorMessage);
        }
    }

    InventoryLoadCompleteEvent event = new InventoryLoadCompleteEvent(player, cause);
    Bukkit.getPluginManager().callEvent(event);
}
 
Example 11
Source File: DPlayerData.java    From DungeonsXL with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Saves the player's data to the file.
 *
 * @param player the Player to save
 */
public void savePlayerState(Player player) {
    oldGameMode = player.getGameMode();
    oldFireTicks = player.getFireTicks();
    oldFoodLevel = player.getFoodLevel();
    if (is1_9) {
        oldMaxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue();
    }
    oldHealth = player.getHealth();
    oldExp = player.getExp();
    oldLvl = player.getLevel();
    oldArmor = new ArrayList<>(Arrays.asList(player.getInventory().getArmorContents()));
    oldInventory = new ArrayList<>(Arrays.asList(player.getInventory().getContents()));
    if (is1_9) {
        oldOffHand = player.getInventory().getItemInOffHand();
    }
    oldLocation = player.getLocation();
    oldPotionEffects = player.getActivePotionEffects();
    if (is1_9) {
        oldCollidabilityState = player.isCollidable();
        oldInvulnerabilityState = player.isInvulnerable();
    }
    oldFlyingState = player.getAllowFlight();

    config.set(PREFIX_STATE_PERSISTENCE + "oldGameMode", oldGameMode.toString());
    config.set(PREFIX_STATE_PERSISTENCE + "oldFireTicks", oldFireTicks);
    config.set(PREFIX_STATE_PERSISTENCE + "oldFoodLevel", oldFoodLevel);
    config.set(PREFIX_STATE_PERSISTENCE + "oldMaxHealth", oldMaxHealth);
    config.set(PREFIX_STATE_PERSISTENCE + "oldHealth", oldHealth);
    config.set(PREFIX_STATE_PERSISTENCE + "oldExp", oldExp);
    config.set(PREFIX_STATE_PERSISTENCE + "oldLvl", oldLvl);
    config.set(PREFIX_STATE_PERSISTENCE + "oldArmor", oldArmor);
    config.set(PREFIX_STATE_PERSISTENCE + "oldInventory", oldInventory);
    config.set(PREFIX_STATE_PERSISTENCE + "oldOffHand", oldOffHand);
    config.set(PREFIX_STATE_PERSISTENCE + "oldLocation", oldLocation);
    config.set(PREFIX_STATE_PERSISTENCE + "oldPotionEffects", oldPotionEffects);
    config.set(PREFIX_STATE_PERSISTENCE + "oldCollidabilityState", oldCollidabilityState);
    config.set(PREFIX_STATE_PERSISTENCE + "oldFlyingState", oldFlyingState);
    config.set(PREFIX_STATE_PERSISTENCE + "oldInvulnerabilityState", oldInvulnerabilityState);

    save();
}
 
Example 12
Source File: LimboServiceTest.java    From AuthMeReloaded with GNU General Public License v3.0 4 votes vote down vote up
private static LimboPlayer convertToLimboPlayer(Player player, Location location, Collection<String> groups) {
    return new LimboPlayer(location, player.isOp(), groups, player.getAllowFlight(),
        player.getWalkSpeed(), player.getFlySpeed());
}
 
Example 13
Source File: PWIPlayerManager.java    From PerWorldInventory with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Get a player from the cache, and apply the cached inventories and stats
 * to the actual player. If no matching player is found in the cache, nothing
 * happens and this method simply returns.
 *
 * @param group The {@link Group} the cached player was in.
 * @param gamemode The GameMode the cached player was in.
 * @param player The current actual player to apply the data to.
 * @param cause What triggered the inventory switch; passed on for post-processing.
 */
private void getDataFromCache(Group group, GameMode gamemode, Player player, DeserializeCause cause) {
    PWIPlayer cachedPlayer = getCachedPlayer(group, gamemode, player.getUniqueId());
    if (cachedPlayer == null) {
        ConsoleLogger.debug("No data for player '" + player.getName() + "' found in cache");

        return;
    }

    ConsoleLogger.debug("Player '" + player.getName() + "' found in cache! Setting their data");

    if (settings.getProperty(PwiProperties.LOAD_ENDER_CHESTS))
        player.getEnderChest().setContents(cachedPlayer.getEnderChest());
    if (settings.getProperty(PwiProperties.LOAD_INVENTORY)) {
        player.getInventory().setContents(cachedPlayer.getInventory());
        player.getInventory().setArmorContents(cachedPlayer.getArmor());
    }
    if (settings.getProperty(PwiProperties.LOAD_CAN_FLY))
        player.setAllowFlight(cachedPlayer.getCanFly());
    if (settings.getProperty(PwiProperties.LOAD_DISPLAY_NAME))
        player.setDisplayName(cachedPlayer.getDisplayName());
    if (settings.getProperty(PwiProperties.LOAD_EXHAUSTION))
        player.setExhaustion(cachedPlayer.getExhaustion());
    if (settings.getProperty(PwiProperties.LOAD_EXP))
        player.setExp(cachedPlayer.getExperience());
    if (settings.getProperty(PwiProperties.LOAD_FLYING) && player.getAllowFlight())
        player.setFlying(cachedPlayer.isFlying());
    if (settings.getProperty(PwiProperties.LOAD_HUNGER))
        player.setFoodLevel(cachedPlayer.getFoodLevel());
    if (settings.getProperty(PwiProperties.LOAD_HEALTH)) {
        if (bukkitService.shouldUseAttributes()) {
            player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(cachedPlayer.getMaxHealth());
        } else {
            player.setMaxHealth(cachedPlayer.getMaxHealth());
        }
        if (cachedPlayer.getHealth() > 0 && cachedPlayer.getHealth() <= cachedPlayer.getMaxHealth()) {
            player.setHealth(cachedPlayer.getHealth());
        } else {
            player.setHealth(cachedPlayer.getMaxHealth());
        }
    }
    if (settings.getProperty(PwiProperties.LOAD_GAMEMODE) && (!settings.getProperty(PwiProperties.SEPARATE_GAMEMODE_INVENTORIES)))
        player.setGameMode(cachedPlayer.getGamemode());
    if (settings.getProperty(PwiProperties.LOAD_LEVEL))
        player.setLevel(cachedPlayer.getLevel());
    if (settings.getProperty(PwiProperties.LOAD_POTION_EFFECTS)) {
        for (PotionEffect effect : player.getActivePotionEffects()) {
            player.removePotionEffect(effect.getType());
        }
        player.addPotionEffects(cachedPlayer.getPotionEffects());
    }
    if (settings.getProperty(PwiProperties.LOAD_SATURATION))
        player.setSaturation(cachedPlayer.getSaturationLevel());
    if (settings.getProperty(PwiProperties.LOAD_FALL_DISTANCE))
        player.setFallDistance(cachedPlayer.getFallDistance());
    if (settings.getProperty(PwiProperties.LOAD_FIRE_TICKS))
        player.setFireTicks(cachedPlayer.getFireTicks());
    if (settings.getProperty(PwiProperties.LOAD_MAX_AIR))
        player.setMaximumAir(cachedPlayer.getMaxAir());
    if (settings.getProperty(PwiProperties.LOAD_REMAINING_AIR))
        player.setRemainingAir(cachedPlayer.getRemainingAir());
    if (settings.getProperty(PwiProperties.USE_ECONOMY)) {
        Economy econ = plugin.getEconomy();
        if (econ == null) {
            ConsoleLogger.warning("Economy saving is turned on, but no economy found!");
            return;
        }

        EconomyResponse er = econ.withdrawPlayer(player, econ.getBalance(player));
        if (er.transactionSuccess()) {
            econ.depositPlayer(player, cachedPlayer.getBalance());
        } else {
            ConsoleLogger.warning("[ECON] Unable to withdraw currency from '" + player.getName() + "': " + er.errorMessage);
        }

        EconomyResponse bankER = econ.bankWithdraw(player.getName(), econ.bankBalance(player.getName()).amount);
        if (bankER.transactionSuccess()) {
            econ.bankDeposit(player.getName(), cachedPlayer.getBankBalance());
        } else {
            ConsoleLogger.warning("[ECON] Unable to withdraw currency from bank of '" + player.getName() + "': " + er.errorMessage);
        }
    }

    InventoryLoadCompleteEvent event = new InventoryLoadCompleteEvent(player, cause);
    Bukkit.getPluginManager().callEvent(event);
}
 
Example 14
Source File: ExprFlightMode.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Boolean convert(final Player player) {
	return player.getAllowFlight();
}
 
Example 15
Source File: CondCanFly.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean check(Player player) {
	return player.getAllowFlight();
}
 
Example 16
Source File: CombatLogTracker.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Get the cause of the player's imminent death, or null if they are not about to die
 * NOTE: not idempotent, has the side effect of clearing the recentDamage cache
 */
public @Nullable ImminentDeath getImminentDeath(Player player) {
    // If the player is already dead or in creative mode, we don't care
    if(player.isDead() || player.getGameMode() == GameMode.CREATIVE) return null;

    // If the player was on the ground, or is flying, or is able to fly, they are fine
    if(!(player.isOnGround() || player.isFlying() || player.getAllowFlight())) {
        // If the player is falling, detect an imminent falling death
        double fallDistance = player.getFallDistance();
        Block landingBlock = null;
        int waterDepth = 0;
        Location location = player.getLocation();

        if(location.getY() > 256) {
            // If player is above Y 256, assume they fell at least to there
            fallDistance += location.getY() - 256;
            location.setY(256);
        }

        // Search the blocks directly beneath the player until we find what they would have landed on
        Block block = null;
        for(; location.getY() >= 0; location.add(0, -1, 0)) {
            block = location.getBlock();
            if(block != null) {
                landingBlock = block;

                if(Materials.isWater(landingBlock.getType())) {
                    // If the player falls through water, reset fall distance and inc the water depth
                    fallDistance = -1;
                    waterDepth += 1;

                    // Break if they have fallen through enough water to stop falling
                    if(waterDepth >= BREAK_FALL_WATER_DEPTH) break;
                } else {
                    // If the block is not water, reset the water depth
                    waterDepth = 0;

                    if(Materials.isColliding(landingBlock.getType()) || Materials.isLava(landingBlock.getType())) {
                        // Break if the player hits a solid block or lava
                        break;
                    } else if(landingBlock.getType() == Material.WEB) {
                        // If they hit web, reset their fall distance, but assume they keep falling
                        fallDistance = -1;
                    }
                }
            }

            fallDistance += 1;
        }

        double resistanceFactor = getResistanceFactor(player);
        boolean fireResistance = hasFireResistance(player);

        // Now decide if the landing would have killed them
        if(location.getBlockY() < 0) {
            // The player would have fallen into the void
            return new ImminentDeath(EntityDamageEvent.DamageCause.VOID, location, null, false);
        } else if(landingBlock != null) {
            if(Materials.isColliding(landingBlock.getType()) && player.getHealth() <= resistanceFactor * (fallDistance - SAFE_FALL_DISTANCE)) {
                // The player would have landed on a solid block and taken enough fall damage to kill them
                return new ImminentDeath(EntityDamageEvent.DamageCause.FALL, landingBlock.getLocation().add(0, 0.5, 0), null, false);
            } else if (Materials.isLava(landingBlock.getType()) && resistanceFactor > 0 && !fireResistance) {
                // The player would have landed in lava, and we give the lava the benefit of the doubt
                return new ImminentDeath(EntityDamageEvent.DamageCause.LAVA, landingBlock.getLocation(), landingBlock, false);
            }
        }
    }

    // If we didn't predict a falling death, detect combat log due to recent damage
    Damage damage = this.recentDamage.remove(player);
    if(damage != null && damage.time.plus(RECENT_DAMAGE_THRESHOLD).isAfter(Instant.now())) {
        // Player logged out too soon after taking damage
        return new ImminentDeath(damage.event.getCause(), player.getLocation(), null, true);
    }

    return null;
}
 
Example 17
Source File: PacketConverter7.java    From Hawk with GNU General Public License v3.0 4 votes vote down vote up
private static AbilitiesEvent packetToAbilitiesEvent(PacketPlayInAbilities packet, Player p, HawkPlayer pp) {
    return new AbilitiesEvent(p, pp, packet.isFlying() && p.getAllowFlight(), new WrappedPacket7(packet, WrappedPacket.PacketType.ABILITIES));
}
 
Example 18
Source File: PacketConverter8.java    From Hawk with GNU General Public License v3.0 4 votes vote down vote up
private static AbilitiesEvent packetToAbilitiesEvent(PacketPlayInAbilities packet, Player p, HawkPlayer pp) {
    return new AbilitiesEvent(p, pp, packet.isFlying() && p.getAllowFlight(), new WrappedPacket8(packet, WrappedPacket.PacketType.ABILITIES));
}
 
Example 19
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 20
Source File: CombatLogTracker.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Get the cause of the player's imminent death, or null if they are not about to die NOTE: not
 * idempotent, has the side effect of clearing the recentDamage cache
 */
public @Nullable ImminentDeath getImminentDeath(Player player) {
  // If the player is already dead or in creative mode, we don't care
  if (player.isDead() || player.getGameMode() == GameMode.CREATIVE) return null;

  // If the player was on the ground, or is flying, or is able to fly, they are fine
  if (!(player.isOnGround() || player.isFlying() || player.getAllowFlight())) {
    // If the player is falling, detect an imminent falling death
    double fallDistance = player.getFallDistance();
    Block landingBlock = null;
    int waterDepth = 0;
    Location location = player.getLocation();

    if (location.getY() > 256) {
      // If player is above Y 256, assume they fell at least to there
      fallDistance += location.getY() - 256;
      location.setY(256);
    }

    // Search the blocks directly beneath the player until we find what they would have landed on
    Block block = null;
    for (; location.getY() >= 0; location.add(0, -1, 0)) {
      block = location.getBlock();
      if (block != null) {
        landingBlock = block;

        if (Materials.isWater(landingBlock.getType())) {
          // If the player falls through water, reset fall distance and inc the water depth
          fallDistance = -1;
          waterDepth += 1;

          // Break if they have fallen through enough water to stop falling
          if (waterDepth >= BREAK_FALL_WATER_DEPTH) break;
        } else {
          // If the block is not water, reset the water depth
          waterDepth = 0;

          if (Materials.isSolid(landingBlock.getType())
              || Materials.isLava(landingBlock.getType())) {
            // Break if the player hits a solid block or lava
            break;
          } else if (landingBlock.getType() == Material.WEB) {
            // If they hit web, reset their fall distance, but assume they keep falling
            fallDistance = -1;
          }
        }
      }

      fallDistance += 1;
    }

    double resistanceFactor = getResistanceFactor(player);
    boolean fireResistance = hasFireResistance(player);

    // Now decide if the landing would have killed them
    if (location.getBlockY() < 0) {
      // The player would have fallen into the void
      return new ImminentDeath(EntityDamageEvent.DamageCause.VOID, location, null, false);
    } else if (landingBlock != null) {
      if (Materials.isSolid(landingBlock.getType())
          && player.getHealth() <= resistanceFactor * (fallDistance - SAFE_FALL_DISTANCE)) {
        // The player would have landed on a solid block and taken enough fall damage to kill them
        return new ImminentDeath(
            EntityDamageEvent.DamageCause.FALL,
            landingBlock.getLocation().add(0, 0.5, 0),
            null,
            false);
      } else if (Materials.isLava(landingBlock.getType())
          && resistanceFactor > 0
          && !fireResistance) {
        // The player would have landed in lava, and we give the lava the benefit of the doubt
        return new ImminentDeath(
            EntityDamageEvent.DamageCause.LAVA, landingBlock.getLocation(), landingBlock, false);
      }
    }
  }

  // If we didn't predict a falling death, detect combat log due to recent damage
  Damage damage = this.recentDamage.remove(player);
  if (damage != null && damage.time.plus(RECENT_DAMAGE_THRESHOLD).isAfter(Instant.now())) {
    // Player logged out too soon after taking damage
    return new ImminentDeath(damage.event.getCause(), player.getLocation(), null, true);
  }

  return null;
}