use of org.bukkit.event.player.PlayerLevelChangeEvent in project Glowstone by GlowstoneMC.
the class GlowPlayer method setLevel.
@Override
public void setLevel(int level) {
int newLevel = Math.max(level, 0);
if (newLevel != this.level) {
EventFactory.getInstance().callEvent(new PlayerLevelChangeEvent(this, this.level, newLevel));
this.level = newLevel;
sendExperience();
}
}
use of org.bukkit.event.player.PlayerLevelChangeEvent 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