BarAPI not working properly

Discussion in 'Plugin Development' started by MayoDwarf, May 4, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    MayoDwarf

    Code:java
    1. @EventHandler
    2. public void onEntityDamage(EntityDamageByEntityEvent evt) { //BUG where when player is hit with snowball they are not damaged by 2 hearts
    3. Entity hit = evt.getEntity();
    4. Entity damager = evt.getDamager();
    5. if(hit instanceof Player && damager instanceof Snowball) {
    6. Snowball sb = (Snowball) damager;
    7. if(sb.getShooter() instanceof Player) {
    8. Player shooter = (Player) sb.getShooter();
    9. if(DisguiseAPI.isDisguised(hit) && hasGolem.contains(((Player) hit).getDisplayName())) {
    10. if(DisguiseAPI.getDisguise(hit).getType() == DisguiseType.IRON_GOLEM) {
    11. evt.setCancelled(true);
    12. ((Player) hit).damage(2, shooter);
    13. ((Player) hit).setHealth(20);
    14. ((Player) hit).setFoodLevel(6);
    15. if(health.containsKey(((Player) hit).getDisplayName())) {
    16. health.put(ChatColor.stripColor(((Player) hit).getDisplayName()), health.get(ChatColor.stripColor(((Player) hit).getDisplayName()))-1);
    17. int healthScale = 100/60*health.get(ChatColor.stripColor(((Player) hit).getDisplayName()));
    18. Float h = Float.intBitsToFloat(health.get(((Player) hit).getDisplayName()));
    19. BarAPI.setMessage((Player) hit, "Golem Health");
    20. BarAPI.setHealth((Player) hit, h);
    21. if(health.get(((Player) hit).getDisplayName()) <= 0) {
    22. Player players = (Player) hit;
    23. ((Player) hit).damage(2, shooter);
    24. //BarAPI Possibly
    25. BarAPI.removeBar((Player) hit);
    26. DisguiseAPI.undisguiseToAll(hit);
    27. ((Player) hit).getInventory().clear();
    28. ((Player) hit).setFoodLevel(20);
    29. players.setVelocity(players.getVelocity().setY(2.0));
    30. hit.getWorld().createExplosion(hit.getLocation(), 0);
    31. players.getWorld().createExplosion(players.getLocation(), 0);
    32. players.getWorld().createExplosion(players.getLocation(), 0);
    33. shooter.sendMessage(ChatColor.AQUA+""+ChatColor.BOLD+"<<GolemFall>>"+" "+ChatColor.DARK_RED+"Successfully destroyed enemy Golem!");
    34. shooter.playSound(shooter.getLocation(), Sound.SUCCESSFUL_HIT, 1, 1);
    35. shooter.playSound(shooter.getLocation(), Sound.SUCCESSFUL_HIT, 1, 1);
    36. shooter.playSound(shooter.getLocation(), Sound.SUCCESSFUL_HIT, 1, 1);
    37. health.remove(players.getDisplayName());
    38. hasGolem.remove(players.getDisplayName());
    39. golem.remove(players.getDisplayName());
    40. } else {
    41. shooter.playSound(shooter.getLocation(), Sound.SUCCESSFUL_HIT, 1, 1);
    42. //BarAPI Possibly
    43. BarAPI.setMessage((Player) hit, "Golem Health", h);
    44. }
    45. } else {
    46. health.put(ChatColor.stripColor(((Player) hit).getDisplayName()), 60-1);
    47. shooter.playSound(shooter.getLocation(), Sound.SUCCESSFUL_HIT, 1, 1);
    48. Float h = Float.intBitsToFloat(health.get(((Player) hit).getDisplayName()));
    49. BarAPI.setMessage((Player) hit, "Golem Health", h);
    50. }
    51. }
    52. } else {
    53. ((Player) hit).damage(4.0, shooter);
    54. }
    55. }
    56. } else
    57. if(hit instanceof Player && damager instanceof SmallFireball) {
    58. SmallFireball sb = (SmallFireball) damager;
    59. if(sb.getShooter() instanceof Player) {
    60. Player shooter = (Player) sb.getShooter();
    61. if(DisguiseAPI.isDisguised(hit) && hasGolem.contains(((Player) hit).getDisplayName())) {
    62. if(DisguiseAPI.getDisguise(hit).getType() == DisguiseType.IRON_GOLEM) {
    63. evt.setCancelled(true);
    64. ((Player) hit).damage(2, shooter);
    65. ((Player) hit).setHealth(20);
    66. ((Player) hit).setFoodLevel(6);
    67. if(health.containsKey(((Player) hit).getDisplayName())) {
    68. health.put(ChatColor.stripColor(((Player) hit).getDisplayName()), health.get(ChatColor.stripColor(((Player) hit).getDisplayName()))-10);
    69. int healthScale = 100/60*health.get(ChatColor.stripColor(((Player) hit).getDisplayName()));
    70. Float h = Float.intBitsToFloat(health.get(((Player) hit).getDisplayName()));
    71. BarAPI.setMessage((Player) hit, "Golem Health", h);
    72. if(health.get(((Player) hit).getDisplayName()) <= 0) {
    73. Player players = (Player) hit;
    74. ((Player) hit).damage(2, shooter);
    75. //BarAPI Possibly
    76. BarAPI.removeBar((Player) hit);
    77. DisguiseAPI.undisguiseToAll(hit);
    78. ((Player) hit).getInventory().clear();
    79. ((Player) hit).setFoodLevel(20);
    80. players.setVelocity(players.getVelocity().setY(2.0));
    81. hit.getWorld().createExplosion(hit.getLocation(), 0);
    82. players.getWorld().createExplosion(players.getLocation(), 0);
    83. players.getWorld().createExplosion(players.getLocation(), 0);
    84. shooter.sendMessage(ChatColor.AQUA+""+ChatColor.BOLD+"<<GolemFall>>"+" "+ChatColor.DARK_RED+"Successfully destroyed enemy Golem!");
    85. shooter.playSound(shooter.getLocation(), Sound.SUCCESSFUL_HIT, 1, 1);
    86. shooter.playSound(shooter.getLocation(), Sound.SUCCESSFUL_HIT, 1, 1);
    87. shooter.playSound(shooter.getLocation(), Sound.SUCCESSFUL_HIT, 1, 1);
    88. health.remove(players.getDisplayName());
    89. hasGolem.remove(players.getDisplayName());
    90. golem.remove(players.getDisplayName());
    91. } else {
    92. shooter.playSound(shooter.getLocation(), Sound.SUCCESSFUL_HIT, 1, 1);
    93. //BarAPI Possibly
    94. BarAPI.setMessage((Player) hit, "Golem Health", h);
    95. }
    96. } else {
    97. health.put(ChatColor.stripColor(((Player) hit).getDisplayName()), 60-10);
    98. shooter.playSound(shooter.getLocation(), Sound.SUCCESSFUL_HIT, 1, 1);
    99. //BarAPI Possibly
    100. Float h = Float.intBitsToFloat(health.get(((Player) hit).getDisplayName()));
    101. BarAPI.setMessage((Player) hit, "Golem Health", h);
    102. }
    103. }
    104. } else {
    105. ((Player) hit).damage(2.0, shooter);
    106. ((Player) hit).setHealth(0);
    107. }
    108. }
    109. } else {
    110. evt.setCancelled(true);
    111. }
    112. }

    The health is not updating at all. I need the health to update. It's not setting the health right though... :( Please help. Thanks - Jared (MayoDwarf)
    Konkz

    Oh also btw what I mean is the health stays at 100% and never changes when it is set to change...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  2. Offline

    Niknea

    MayoDwarf Try something like this
    PHP:
       public void onBarChange(final Player p){
       
    BarAPI.removeBar(p);
     
          new 
    BukkitRunnable() {
     
     
     
                @
    Override
                
    public void run() {
     
                    
    // Code
     
     
                    
    }
            }.
    runTaskTimer(plugin0l20 7);
        }
     
     
    Then trigger the onBarChange in the onEnable for it to check the health every so often.
     
Thread Status:
Not open for further replies.

Share This Page