/** @param event */ @EventHandler(priority = EventPriority.MONITOR) public void OnPlayerLogin(PlayerLoginEvent event) { final Player player = event.getPlayer(); final FundamentalPlayer funplayer = SurvivalPlus.Players.getPlayer(player); if (funplayer == null) { return; } PlayerSkillData data = (PlayerSkillData) funplayer.getPlayerData(this.getPlayerDataClass()); if (data == null) { return; } final int level = data.getLevel(); setPlayerHitpoints(player, level); }
/** Called after the module is loaded. */ @Override public void onPostEnable() { for (Player player : Bukkit.getOnlinePlayers()) { final FundamentalPlayer funplayer = SurvivalPlus.Players.getPlayer(player); if (funplayer == null) { return; } PlayerSkillData data = (PlayerSkillData) funplayer.getPlayerData(this.getPlayerDataClass()); if (data == null) { return; } final int level = data.getLevel(); setPlayerHitpoints(player, level); } }
/** @param event */ @EventHandler(priority = EventPriority.NORMAL) public void OnEntityDamanged(EntityDamageByEntityEvent event) { final Entity entity = event.getEntity(); final Entity damager = event.getDamager(); FundamentalPlayer player = null; if (entity instanceof Player) { // Defence player = SurvivalPlus.Players.getPlayer((Player) entity); } else if (damager instanceof Player) { // Attack player = SurvivalPlus.Players.getPlayer((Player) damager); } else if (damager instanceof Projectile) { // Archery final ProjectileSource source = ((Projectile) damager).getShooter(); if (source instanceof Player) { player = SurvivalPlus.Players.getPlayer((Player) source); } } if (player == null) { return; } PlayerSkillData data = (PlayerSkillData) player.getPlayerData(this.getPlayerDataClass()); if (data == null) { return; } final int oldlevel = data.getLevel(); data.addXP(1L); final int level = data.getLevel(); // Have we leveld up? give more health if (level != oldlevel) { setPlayerHitpoints(player.getPlayer(), level); } }