use of org.bukkit.event.player.PlayerExpChangeEvent in project Glowstone by GlowstoneMC.
the class GlowPlayer method giveExp.
@Override
public void giveExp(int xp) {
PlayerExpChangeEvent event = EventFactory.getInstance().callEvent(new PlayerExpChangeEvent(this, xp));
xp = event.getAmount();
totalExperience += xp;
// gradually award levels based on xp points
float value = 1.0f / getExpToLevel();
for (int i = 0; i < xp; ++i) {
exp += value;
if (exp >= 1) {
exp -= 1;
setLevel(level + 1);
value = 1.0f / getExpToLevel(level);
}
}
sendExperience();
}
use of org.bukkit.event.player.PlayerExpChangeEvent in project Glowstone by GlowstoneMC.
the class GlowPlayerTest method testGiveExp.
@Test
public void testGiveExp() {
entity.giveExp(20);
verify(eventFactory, times(2)).callEvent(argThat(input -> {
if (input instanceof PlayerExpChangeEvent) {
PlayerExpChangeEvent event = (PlayerExpChangeEvent) input;
assertEquals(20, event.getAmount());
return true;
} else if (input instanceof PlayerLevelChangeEvent) {
PlayerLevelChangeEvent event = (PlayerLevelChangeEvent) input;
assertSame(entity, event.getPlayer());
assertEquals(2, event.getNewLevel());
assertEquals(1, event.getOldLevel());
return true;
}
return false;
}));
assertEquals(2, entity.getLevel());
assertEquals(0.17, entity.getExp(), 0.1);
assertEquals(20, entity.getTotalExperience());
}
Aggregations