本文整理汇总了Java中org.bukkit.entity.Player.giveExp方法的典型用法代码示例。如果您正苦于以下问题:Java Player.giveExp方法的具体用法?Java Player.giveExp怎么用?Java Player.giveExp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.entity.Player
的用法示例。
在下文中一共展示了Player.giveExp方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onHit
import org.bukkit.entity.Player; //导入方法依赖的package包/类
@EventHandler(priority=EventPriority.HIGHEST)
public void onHit(EntityDamageByEntityEvent e) {
if(e.isCancelled())return;
if (e.getEntity() instanceof Player && e.getDamager() instanceof Player) {
// Player to = (Player) e.getEntity();
Player by = (Player) e.getDamager();
if (!e.isCancelled()) {
by.giveExp(5);
}
}
}
示例2: subtractExpPoints
import org.bukkit.entity.Player; //导入方法依赖的package包/类
public static void subtractExpPoints(Player p, int points) {
if (points < 0) throw new IllegalArgumentException();
if (points == 0) return;
int total = getExpPoints(p);
if (total < points) throw new IllegalArgumentException("Negative Exp Left");
int newLevel = getLevelForExp(total - points);
int remPoint = total - points - getExpForLevel(newLevel);
p.setLevel(newLevel);
p.setExp(0);
p.giveExp(remPoint);
}
示例3: addPlayerExperience
import org.bukkit.entity.Player; //导入方法依赖的package包/类
/**
* Change the player's experience (not experience level)
* Related events may be triggered.
*
* @param p the target player
* @param exp amount of xp to be added to the player,
* if negative, then subtract from the player.
* @throws IllegalArgumentException if the player ended with negative xp
*/
public static void addPlayerExperience(Player p, int exp) {
if (exp > 0) {
p.giveExp(exp);
} else if (exp < 0) {
subtractExpPoints(p, -exp);
}
}