コード例 #1
0
  @EventHandler(priority = EventPriority.NORMAL)
  public void onEDamaged(EntityDamageEvent event) {

    if (event.getEntity() instanceof Player) {
      DamageCause cause = event.getCause();
      if (cause != DamageCause.LAVA && cause != DamageCause.FIRE) {
        Player p = (Player) event.getEntity();
        // p.sendMessage("Au!");
        // formula daño equivalente
        int evdmg = event.getDamage();
        double resHP = event.getDamage();
        double tempop = 0;
        event.setDamage(0);
        double CH = plugin.PCH.get(p.getName().toLowerCase());
        double MH = plugin.PMH.get(p.getName().toLowerCase());
        CH = CH - evdmg;
        tempop = MH / 20;
        resHP = CH / tempop;
        p.setHealth((int) resHP);
        plugin.PCH.put(p.getName().toLowerCase(), CH);
        p.sendMessage(
            "HP: " + ChatColor.AQUA + CH + ChatColor.GRAY + "/" + ChatColor.DARK_AQUA + MH);

      } else {
        Player p = (Player) event.getEntity();
        double HP = p.getHealth();
        double CH = plugin.PCH.get(p.getName().toLowerCase());
        double MH = plugin.PMH.get(p.getName().toLowerCase());
        double tempop = 0;
        tempop = MH / 20;
        CH = HP * tempop;
        plugin.PCH.put(p.getName().toLowerCase(), CH);
      }
    }
  }
コード例 #2
0
  @EventHandler(priority = EventPriority.NORMAL)
  public void onRegainH(EntityRegainHealthEvent event) {
    Player p = (Player) event.getEntity();
    int regain = event.getAmount();
    // regen HP
    double CH = plugin.PCH.get(p.getName().toLowerCase());
    double MH = plugin.PMH.get(p.getName().toLowerCase());
    double tempop = 0;
    double resHP = 0;
    CH = CH + regain;
    tempop = MH / 20;
    resHP = CH / tempop;
    // event.setDamage((int) resdmg);
    p.setHealth((int) resHP);
    plugin.PCH.put(p.getName().toLowerCase(), CH);

    // Bukkit.broadcastMessage("regain "+ p);
    // event.
    // añadir sistema de max health nuevo
  }