示例#1
0
  /**
   * Updates the player's max health and mana using class data.
   *
   * @param player player to update the health and mana for
   */
  public void updateHealthAndMana(Player player) {
    if (player == null) {
      return;
    }

    // Update maxes
    double health = bonusHealth;
    maxMana = bonusMana;
    for (PlayerClass c : classes.values()) {
      health += c.getHealth();
      maxMana += c.getMana();
    }
    if (health == bonusHealth) {
      health += SkillAPI.getSettings().getDefaultHealth();
    }
    if (health == 0) {
      health = 20;
    }
    if (SkillAPI.getSettings().isModifyHealth()) VersionManager.setMaxHealth(player, health);
    mana = Math.min(mana, maxMana);

    // Health scaling is available starting with 1.6.2
    if (SkillAPI.getSettings().isModifyHealth()
        && VersionManager.isVersionAtLeast(VersionManager.V1_6_2)) {
      if (SkillAPI.getSettings().isOldHealth()) {
        player.setHealthScaled(true);
        player.setHealthScale(20);
      } else {
        player.setHealthScaled(false);
      }
    }
  }
示例#2
0
 /**
  * Cancels left clicks on disabled items
  *
  * @param event event details
  */
 @EventHandler(priority = EventPriority.LOWEST)
 public void onAttack(EntityDamageByEntityEvent event) {
   if (event.getDamager() instanceof Player) {
     Player player = (Player) event.getDamager();
     if (InventoryTask.cannotUse(SkillAPI.getPlayerData(player), player.getItemInHand())) {
       SkillAPI.getLanguage().sendMessage(ErrorNodes.CANNOT_USE, player, FilterType.COLOR);
       event.setCancelled(true);
     }
   }
   if (event.getEntity() instanceof Player
       && VersionManager.isVersionAtLeast(VersionManager.V1_9_0)) {
     Player player = (Player) event.getEntity();
     if (event.getDamage(EntityDamageEvent.DamageModifier.BLOCKING) < 0
         && InventoryTask.cannotUse(
             SkillAPI.getPlayerData(player), player.getInventory().getItemInMainHand())) {
       SkillAPI.getLanguage()
           .sendMessage(ErrorNodes.CANNOT_USE, event.getEntity(), FilterType.COLOR);
       event.setDamage(EntityDamageEvent.DamageModifier.BLOCKING, 0);
     }
   }
 }