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

The following examples show how to use org.bukkit.entity.Player#getLevel() . 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: KnowledgeFlask.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ItemUseHandler getItemHandler() {
    return e -> {
        Player p = e.getPlayer();

        if (p.getLevel() >= 1 && (!e.getClickedBlock().isPresent() || !(e.getClickedBlock().get().getType().isInteractable()))) {
            p.setLevel(p.getLevel() - 1);
            p.getInventory().addItem(SlimefunItems.FILLED_FLASK_OF_KNOWLEDGE.clone());

            p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1F, 0.5F);

            ItemUtils.consumeItem(e.getItem(), false);
            e.cancel();
        }
    };
}
 
Example 2
Source File: Util.java    From SkyWarsReloaded with GNU General Public License v3.0 6 votes vote down vote up
public int getPlayerLevel(Player player) {
    if (SkyWarsReloaded.getCfg().displayPlayerExeperience()) {
    	return player.getLevel();
    } else {
    	PlayerStat ps = PlayerStat.getPlayerStats(player);
    	if (ps != null) {
    		int amount = ps.getXp();
    		if (amount <= 352) {
    			return (int) Math.floor(quadraticEquationRoot(1, 6, 0-amount));
    		} else if (amount <= 1507) {
    			return (int) Math.floor(quadraticEquationRoot(2.5, -40.5, 360-amount));
    		} else {
    			return (int) Math.floor(quadraticEquationRoot(4.5, -162.5, 2220-amount));
    		}
    	} else {
        	return 0;
    	}
    }
}
 
Example 3
Source File: Util.java    From SkyWarsReloaded with GNU General Public License v3.0 6 votes vote down vote up
public int getPlayerLevel(Player player) {
    if (SkyWarsReloaded.getCfg().displayPlayerExeperience()) {
    	return player.getLevel();
    } else {
    	PlayerStat ps = PlayerStat.getPlayerStats(player);
    	if (ps != null) {
    		int amount = ps.getXp();
    		if (amount <= 352) {
    			return (int) Math.floor(quadraticEquationRoot(1, 6, 0-amount));
    		} else if (amount <= 1507) {
    			return (int) Math.floor(quadraticEquationRoot(2.5, -40.5, 360-amount));
    		} else {
    			return (int) Math.floor(quadraticEquationRoot(4.5, -162.5, 2220-amount));
    		}
    	} else {
        	return 0;
    	}
    }
}
 
Example 4
Source File: ClearXPAction.java    From UHC with MIT License 5 votes vote down vote up
@Override
protected void run(Player player) {
    exp = player.getExp();
    level = player.getLevel();
    total = player.getTotalExperience();

    player.setExp(0F);
    player.setLevel(0);
    player.setTotalExperience(0);
}
 
Example 5
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 6
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 7
Source File: Research.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks if the {@link Player} can unlock this {@link Research}.
 * 
 * @param p
 *            The {@link Player} to check
 * @return Whether that {@link Player} can unlock this {@link Research}
 */
public boolean canUnlock(Player p) {
    if (!isEnabled()) {
        return true;
    }

    boolean creativeResearch = p.getGameMode() == GameMode.CREATIVE && SlimefunPlugin.getRegistry().isFreeCreativeResearchingEnabled();
    return creativeResearch || p.getLevel() >= cost;
}
 
Example 8
Source File: SetExpFix.java    From PlayerSQL with GNU General Public License v2.0 5 votes vote down vote up
public static int getTotalExperience(final Player player) {
    int exp = (int) Math.round(getExpAtLevel(player) * player.getExp());
    int currentLevel = player.getLevel();

    while (currentLevel > 0) {
        currentLevel--;
        exp += getExpAtLevel(currentLevel);
    }
    if (exp < 0) {
        exp = Integer.MAX_VALUE;
    }
    return exp;
}
 
Example 9
Source File: Utils.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
public static int getTotalExperience(final Player player) {
    int exp = Math.round(getExpAtLevel(player.getLevel()) * player.getExp());
    int currentLevel = player.getLevel();

    while (currentLevel > 0) {
        currentLevel--;
        exp += getExpAtLevel(currentLevel);
    }
    if (exp < 0) {
        exp = Integer.MAX_VALUE;
    }
    return exp;
}
 
Example 10
Source File: FeeLevelRequirement.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
private int getRelevantLevel(Player player) {
    if (isKeepInventory(player)) {
        return player.getLevel();
    }

    DGlobalPlayer dPlayer = (DGlobalPlayer) api.getPlayerCache().get(player);
    return dPlayer.getData().getOldLevel();
}
 
Example 11
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 12
Source File: ExprLevel.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Integer[] get(final Event e, final Player[] source) {
	return super.get(source, new Converter<Player, Integer>() {
		@SuppressWarnings("null")
		@Override
		public Integer convert(final Player p) {
			if (e instanceof PlayerLevelChangeEvent && ((PlayerLevelChangeEvent) e).getPlayer() == p && !Delay.isDelayed(e)) {
				return getTime() < 0 ? ((PlayerLevelChangeEvent) e).getOldLevel() : ((PlayerLevelChangeEvent) e).getNewLevel();
			}
			return p.getLevel();
		}
	});
}
 
Example 13
Source File: CronusUtils.java    From TabooLib with MIT License 5 votes vote down vote up
public static int getTotalExperience(Player player) {
    int exp = Math.round(getExpAtLevel(player) * player.getExp());
    int currentLevel = player.getLevel();

    while (currentLevel > 0) {
        currentLevel--;
        exp += getExpAtLevel(currentLevel);
    }
    if (exp < 0) {
        exp = Integer.MAX_VALUE;
    }
    return exp;
}
 
Example 14
Source File: PlayerInfo.java    From MineTinker with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param player The player
 * @return the players current total exp amount
 */
public static int getPlayerExp(@NotNull Player player) {
	int exp = 0;
	int level = player.getLevel();

	// Get the amount of XP in past levels
	exp += getExpAtLevel(level);

	// Get amount of XP towards next level
	exp += Math.round(getExpToLevelUp(level) * player.getExp());

	return exp;
}
 
Example 15
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 16
Source File: SetExpFix.java    From PlayerSQL with GNU General Public License v2.0 4 votes vote down vote up
public static int getExpUntilNextLevel(final Player player) {
    int exp = (int) Math.round(getExpAtLevel(player) * player.getExp());
    int nextLevel = player.getLevel();
    return getExpAtLevel(nextLevel) - exp;
}
 
Example 17
Source File: CronusUtils.java    From TabooLib with MIT License 4 votes vote down vote up
public static int getExpUntilNextLevel(Player player) {
    int exp = Math.round(getExpAtLevel(player) * player.getExp());
    int nextLevel = player.getLevel();
    return getExpAtLevel(nextLevel) - exp;
}
 
Example 18
Source File: Modifier.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
public void enchantItem(Player player) {
	if (!player.hasPermission("minetinker.modifiers." + getKey().replace("-", "").toLowerCase() + ".craft")) {
		return;
	}

	if (getConfig().getBoolean("Recipe.Enabled")) {
		return;
	}

	Location location = player.getLocation();
	World world = location.getWorld();
	PlayerInventory inventory = player.getInventory();

	if (world == null) {
		return;
	}

	if (player.getGameMode() == GameMode.CREATIVE) {
		if (inventory.addItem(getModItem()).size() != 0) { //adds items to (full) inventory
			world.dropItem(location, getModItem());
		} // no else as it gets added in if

		if (MineTinker.getPlugin().getConfig().getBoolean("Sound.OnEnchanting")) {
			player.playSound(location, Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1.0F, 0.5F);
		}

		ChatWriter.log(false, player.getDisplayName() + " created a " + getName() + "-Modifiers in Creative!");
	} else if (player.getLevel() >= getEnchantCost()) {
		int amount = inventory.getItemInMainHand().getAmount();
		int newLevel = player.getLevel() - getEnchantCost();

		player.setLevel(newLevel);
		inventory.getItemInMainHand().setAmount(amount - 1);

		if (inventory.addItem(getModItem()).size() != 0) { //adds items to (full) inventory
			world.dropItem(location, getModItem());
		} // no else as it gets added in if

		if (MineTinker.getPlugin().getConfig().getBoolean("Sound.OnEnchanting")) {
			player.playSound(location, Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1.0F, 0.5F);
		}

		ChatWriter.log(false, player.getDisplayName() + " created a " + getName() + "-Modifiers!");
	} else {
		ChatWriter.sendActionBar(player, ChatColor.RED
				+ LanguageManager.getString("Modifier.Enchantable.LevelsRequired", player)
				.replace("%amount", String.valueOf(getEnchantCost())));
		ChatWriter.log(false, player.getDisplayName() + " tried to create a "
				+ getName() + "-Modifiers but had not enough levels!");
	}
}