Solved Soup plugin trouble

Discussion in 'Plugin Development' started by WasabiLover, Aug 27, 2013.

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

    WasabiLover

    Hello, I've been trying to make a soup plugin like mcPvP's but I haven't been successful. Whenever I use the soup it doesn't disappear. Please help.
     
  2. Offline

    SuperOmegaCow

    @WasabiLove does the potion effect fire?
     
  3. Offline

    WasabiLover

    SuperOmegaCow
    what do you mean by fire? If you mean work than yes it does.
     
  4. Offline

    monkeymanboy

    I think you need to do setItemInHand(Material.AIR)
     
  5. Offline

    WasabiLover

  6. Offline

    Regagames

    Try this;
    Code:java
    1. player.getInventory().getItemInHand().setAmount(player.getInventory().getItemInHand().getAmount()-1);


    Btw, I suggest adding health to the player instead of giving them the "Heal" potion effect.
     
  7. Offline

    WasabiLover

    Still doesn't work and I was never able to add health it always says getHealth() was ambiguous for entity type Player
     
  8. Offline

    Regagames

    I don't know, sorry :( But to fix the getHealth() was ambigiuous.... etc Import Bukkit.jar as well as CraftBukkit.jar (Make sure to make Bukkit.jar a priority)
    http://dl.bukkit.org/downloads/bukkit/
     
  9. Offline

    AstramG

    Try:
    Code:java
    1. player.getInventory().removeItem(player.getItemInHand());


    To fix the health issue cast the entity into a Damageable:
    Code:java
    1. Damageable damageable = player;
    2. damageable.setHealth(damageable.getHealth() + 3.0D);


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

    WasabiLover

    AstramG Great the soup works now thank you for that AstramG, but the soup still doesn't disappear

    AstramG Wait I just noticed an error once the player eats enough soup to get up to say 19 health the server says the health has to be between 0 and 20

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

    AstramG

    Do a check to see if their health is allowed to go that high and if it's over 17 in your case then just set their health to their max health.
     
  12. Offline

    WasabiLover

    AstramG So like this:
    Code:java
    1. if(damageable.getHealth() == 18){
    2. damageable.setMaxHealth();
    3. }
    4.  


    AstramG Also what should I do about them still not disappearing

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

    AstramG

    I don't know what to do about disappearing but this is what you should do for health:
    Code:java
    1. if (damageable.getHealth() + 3.0D > damageable.getMaxHealth()) {
    2. damageable.setHealth(damageable.getMaxHealth());
    3. } else {
    4. damageable.setHealth(damageable.getHealth() + 3.0D);
    5. }
     
  14. Offline

    WasabiLover

    AstramG
    I still get this error:
    Code:
    22:44:10 [SEVERE] Could not pass event PlayerInteractEvent to TheThreeKingdoms v6.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
        at org.bukkit.craftbukkit.v1_6_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:190)
        at net.minecraft.server.v1_6_R2.PlayerInteractManager.interact(PlayerInteractManager.java:373)
        at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java:628)
        at net.minecraft.server.v1_6_R2.Packet15Place.handle(SourceFile:58)
        at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:296)
        at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java:116)
        at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
        at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:590)
        at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
        at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
        at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
        at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    Caused by: java.lang.IllegalArgumentException: Health must be between 0 and 20.0
        at org.bukkit.craftbukkit.v1_6_R2.entity.CraftLivingEntity.setHealth(CraftLivingEntity.java:75)
        at me.WasabiLover.TheThreeKingdoms.Soups.onPlayerInteractEvent(Soups.java:29)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
        ... 16 more
    AstramG I get this error if I click the soup when I have full health

    AstramG Never mind I fixed it, but it would be a real help if you could help me fix the soups disappear. But if you don't want to it's fine. Cause you've been a real help.

    AstramG
    Wait sorry about this but I didn't notice it before, but the code you gave me doesn't exactly work here is my code:
    Code:java
    1. @EventHandler
    2. public void onPlayerInteractEvent(PlayerInteractEvent event){
    3.  
    4. Player player = event.getPlayer();
    5.  
    6. if(player.getItemInHand().getTypeId() == Material.MUSHROOM_SOUP.getId()){
    7.  
    8. Damageable damageable = player;
    9.  
    10. if(!(damageable.getHealth() == 20)){
    11.  
    12. damageable.setHealth(damageable.getHealth() + 3.0D);
    13.  
    14. if (damageable.getHealth() + 3.0D > damageable.getMaxHealth()) {
    15. damageable.setHealth(damageable.getMaxHealth());
    16. } else {
    17. damageable.setHealth(damageable.getHealth() + 3.0D);
    18. }
    19.  
    20. if(player.getInventory().getItemInHand().getTypeId() == Material.MUSHROOM_SOUP.getId()){
    21. player.getItemInHand().setAmount(0);
    22. }
    23. }
    24. }
    25. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
Thread Status:
Not open for further replies.

Share This Page