Solved "Health must be between 0 and 16.0" - What The Hell?

Discussion in 'Plugin Development' started by oriamrm, Apr 2, 2017.

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

    oriamrm

    Hi Everyone,
    I'm using the setHealth() method for quite a while, and every time I inputted a value greater than 20, the console said:

    Caused by: java.lang.IllegalArgumentException: Health must be between 0 and 20.0

    Wich is totally logical, but recently whenever I try inputting a value greater than 16 (8 Hearts) I get this error message:

    Caused by: java.lang.IllegalArgumentException: Health must be between 0 and 16.0

    What the hell? Last time I checked, the player doesn't have 8 hearts in Minecraft...

    Anyway, here's my code:
    Code:
    public void heal(Player player){
            Location loc = player.getLocation().subtract(0, 0.5, 0);
            List<Entity> entities = player.getNearbyEntities(10, 10, 10);
           
            for(Entity entity : entities){
                LivingEntity le = (LivingEntity) entity;
                if(le.getHealth() <= 19){
                    Location l = entity.getLocation().add(0, 1, 0);
                   
                    double density = loc.distance(l)*2;
                    double x = (loc.getX()-l.getX())/density;
                    double y = (loc.getY()-l.getY())/density;
                    double z = (loc.getZ()-l.getZ())/density;
                    Location pLoc = new Location(loc.getWorld(), loc.getX()-x, loc.getY()-y, loc.getZ()-z);
                    l.getWorld().spawnParticle(Particle.TOTEM, pLoc, 1, 0, 0, 0, 0);
                   
                    for(int count = 2; count <= density; count++){       
                        pLoc = new Location(loc.getWorld(), pLoc.getX()-x, pLoc.getY()-y, pLoc.getZ()-z);
                        l.getWorld().spawnParticle(Particle.TOTEM, pLoc, 1, 0, 0, 0, 0);
                    }                               
    
                    int heal = (int) Math.ceil(le.getHealth()*1.8);
                    if(heal <= 20){
                        le.setHealth(heal); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Line 490
                    } else {
                        le.setHealth(20);
                    }
                }
            }
           
            recharge(player, 8, ChatColor.LIGHT_PURPLE + "Heal", Material.YELLOW_FLOWER, Material.RED_ROSE, Items.getHelper().get(0));
        }
    And here's the error log:
    Code:
    [00:44:11 ERROR]: Could not pass event PlayerInteractEvent to TheImmuneSystem v0.1.5
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.11.2.jar:git-Spigot-7d78b81-f709362]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.11.2.jar:git-Spigot-7d78b81-f709362]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.11.2.jar:git-Spigot-7d78b81-f709362]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.11.2.jar:git-Spigot-7d78b81-f709362]
            at org.bukkit.craftbukkit.v1_11_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:232) [spigot-1.11.2.jar:git-Spigot-7d78b81-f709362]
            at org.bukkit.craftbukkit.v1_11_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:199) [spigot-1.11.2.jar:git-Spigot-7d78b81-f709362]
            at org.bukkit.craftbukkit.v1_11_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:195) [spigot-1.11.2.jar:git-Spigot-7d78b81-f709362]
            at net.minecraft.server.v1_11_R1.PlayerConnection.a(PlayerConnection.java:942) [spigot-1.11.2.jar:git-Spigot-7d78b81-f709362]
            at net.minecraft.server.v1_11_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:26) [spigot-1.11.2.jar:git-Spigot-7d78b81-f709362]
            at net.minecraft.server.v1_11_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:1) [spigot-1.11.2.jar:git-Spigot-7d78b81-f709362]
            at net.minecraft.server.v1_11_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.11.2.jar:git-Spigot-7d78b81-f709362]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_111]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_111]
            at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:46) [spigot-1.11.2.jar:git-Spigot-7d78b81-f709362]
            at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:739) [spigot-1.11.2.jar:git-Spigot-7d78b81-f709362]
            at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:399) [spigot-1.11.2.jar:git-Spigot-7d78b81-f709362]
            at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:675) [spigot-1.11.2.jar:git-Spigot-7d78b81-f709362]
            at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:574) [spigot-1.11.2.jar:git-Spigot-7d78b81-f709362]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_111]
    Caused by: java.lang.IllegalArgumentException: Health must be between 0 and 16.0
            at org.bukkit.craftbukkit.v1_11_R1.entity.CraftLivingEntity.setHealth(CraftLivingEntity.java:95) ~[spigot-1.11.2.jar:git-Spigot-7d78b81-f709362]
            at oriamrm.tis.Weapons.heal(Weapons.java:490) ~[?:?]
            at oriamrm.tis.events.InteractSorter.sort(InteractSorter.java:84) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_111]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_111]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_111]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_111]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot-1.11.2.jar:git-Spigot-7d78b81-f709362]
            ... 18 more

    Anyone knows why?
    Thanks in advance!

    (And sorry for my bad English:))
     
  2. Offline

    Zombie_Striker

    @oriamrm
    Health can only be between 0 and the maximum health, and different entities have different maximum values. Instead of just assuming that all entities have 10 hearts, set the heal equal to the entities max health.
     
  3. Offline

    oriamrm

    Oops!
    I was sure I added this line...
    Thanks!
     
Thread Status:
Not open for further replies.

Share This Page