Nerfing God Apples

Discussion in 'Archived: Plugin Requests' started by Nerdfuryz, Jul 24, 2014.

  1. Offline

    Nerdfuryz

    I want a plugin that decreases the amount of time gold apples last from 30 seconds to 20 seconds.
     
  2. Offline

    dsouzamatt

    Nerdfuryz I'll make this

    Nerdfuryz Here you go.

    The only way to get the absorption to run for 20 seconds was to increase it to level II, so I hope that's alright with you.

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

    au2001

    dsouzamatt Please give your code, maybe someone will find out how to make it level I ;)
     
  4. Offline

    timtower Administrator Administrator Moderator

    dsouzamatt Why not remove the effect and set a new one that is shorter?
     
  5. Offline

    dsouzamatt

    au2001 This is the line in question:
    Code:java
    1. PotionEffect absorb = new PotionEffect(PotionEffectType.ABSORPTION, 400, 1);

    It gives Absorption II for 20 seconds. When I change the amplifier to 0 it gives Absorption I, however it lasts for 2 minutes even though the duration remains at 400 ticks.
     
  6. Offline

    au2001

  7. Offline

    timtower Administrator Administrator Moderator

    dsouzamatt Java starts with counting at 0, same for the amplifier value
     
  8. Offline

    dsouzamatt

    timtower That's what I thought; 0 does give the Absorption I effect, however it lasts for 2 minutes even though I've specified 20 seconds.

    In the line that I posted above the player gets Absorption II and it lasts for 20 seconds.
     
  9. Offline

    timtower Administrator Administrator Moderator

    dsouzamatt Did you use the same code besides the amplifier? Did you also made sure that you removed the old effect?
     
  10. Offline

    dsouzamatt

    Yes. Here, I'll past the whole class:
    Code:java
    1. package me.dsouzamatt.NerfApples;
    2.  
    3. import org.bukkit.Material;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.player.PlayerItemConsumeEvent;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9. import org.bukkit.potion.PotionEffect;
    10. import org.bukkit.potion.PotionEffectType;
    11.  
    12. public class Main extends JavaPlugin implements Listener
    13. {
    14. public void onEnable()
    15. {
    16. getServer().getPluginManager().registerEvents(this, this);
    17. }
    18.  
    19. @EventHandler
    20. public void onEat(PlayerItemConsumeEvent event)
    21. {
    22. if(event.getItem().getType() == Material.GOLDEN_APPLE)
    23. {
    24. Player player = event.getPlayer();
    25.  
    26. player.removePotionEffect(PotionEffectType.ABSORPTION);
    27. player.removePotionEffect(PotionEffectType.REGENERATION);
    28.  
    29. PotionEffect absorb = new PotionEffect(PotionEffectType.ABSORPTION, 400, 0);
    30. PotionEffect regen = new PotionEffect(PotionEffectType.REGENERATION, 400, 1);
    31.  
    32. player.addPotionEffect(absorb);
    33. player.addPotionEffect(regen);
    34. }
    35. }
    36. }

    The player is left with Absorption I for 2 minutes. When the amplifier is changed to 1 they get Absorption II for 20 seconds.
     
  11. Offline

    au2001

    dsouzamatt Isn't there a regen.setDuration(400) or something? You could test that
     
  12. Offline

    dsouzamatt

    No, I don't think there is.
     
  13. I did test it, and did remove player.addPotionEffect(absorb);
    And the plugin did not remove the old potion effect.
     
  14. Offline

    JuicyDev

    Just as a test if you tried:
    Code:java
    1. PotionEffect absorb = new PotionEffect(PotionEffectType.ABSORPTION, 400 / 6, 0);

    It might, or might not work. Worth a try though?
     
  15. It does not remove the old apple potion effect.
    The event is called when the player eats and not when he finished the apple.

    This code will work
    But you only have to remove the apple and i am not sure how to do that in this event.
    Code:java
    1. package me.dsouzamatt.NerfApples;
    2.  
    3. import org.bukkit.Material;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.player.PlayerItemConsumeEvent;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9. import org.bukkit.potion.PotionEffect;
    10. import org.bukkit.potion.PotionEffectType;
    11.  
    12. public class Main extends JavaPlugin implements Listener
    13. {
    14. public void onEnable()
    15. {
    16. getServer().getPluginManager().registerEvents(this, this);
    17. }
    18.  
    19. @EventHandler
    20. public void onEat(PlayerItemConsumeEvent e)
    21. {
    22. if(e.getItem().getType() == Material.GOLDEN_APPLE){
    23. Player p = e.getPlayer();
    24. e.setCancelled(true);
    25. //Get players inventory and remove 1 goldenapple
    26.  
    27. PotionEffect a = new PotionEffect(PotionEffectType.ABSORPTION, 400, 0);
    28. PotionEffect r = new PotionEffect(PotionEffectType.REGENERATION, 400, 1);
    29.  
    30. p.addPotionEffect(a);
    31. p.addPotionEffect(r);
    32. }else{
    33. return;
    34. }
    35. }
    36. }
     
  16. Offline

    timtower Administrator Administrator Moderator

    TheLegendOffPabu Why not let the event run, make a runnable that runs a tick later ( so the player will have the effect already and the apple is gone ) and then remove the existing effect and set a new one.
     
  17. Offline

    JuicyDev

    Quick question is this for golden apples or god/notch/enchanted apples? Because you would need to discriminate between them.
     
  18. timtower Yes that would work, if somebody will make it okey. but not 4 me. I hate runnable, i always ahve trouble whit it.

    @dsouzamatt @Nerdfuryz
    This code will remove the old and add the new, it will take 1 apple
    It works for enchanted golden apples and normal golden apples.
    And it will give you the right apple back.
    I did put the code to split the 2 kinds of apples if you want to do that.
    Code:java
    1. package me.dsouzamatt.NerfApples;
    2.  
    3. import org.bukkit.Material;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.player.PlayerItemConsumeEvent;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9. import org.bukkit.potion.PotionEffect;
    10. import org.bukkit.potion.PotionEffectType;
    11.  
    12. public class Main extends JavaPlugin implements Listener
    13. {
    14. public void onEnable()
    15. {
    16. getServer().getPluginManager().registerEvents(this, this);
    17. }
    18.  
    19. @SuppressWarnings("deprecation")
    20. @EventHandler
    21. public void onEat(PlayerItemConsumeEvent e)
    22. {
    23.  
    24. if(e.getItem().getType() == Material.GOLDEN_APPLE)/*&& e.getItem().getDurability() == 1 (Enchanted Golden apples || && e.getItem().getDurability() == 0 (Normal golden apple */{
    25. Player p = e.getPlayer();
    26. e.setCancelled(true);
    27. p.updateInventory();
    28. int as = e.getItem().getAmount() - 1;
    29. ItemStack apple = new ItemStack(Material.GOLDEN_APPLE, as);
    30. int dura = e.getItem().getDurability(); /* To see if it is an Enchanted golden apple or not */
    31. apple.setDurability((short) dura);
    32. p.getInventory().setItemInHand(apple);
    33. p.updateInventory();
    34. PotionEffect a = new PotionEffect(PotionEffectType.ABSORPTION, 400, 0);
    35. PotionEffect r = new PotionEffect(PotionEffectType.REGENERATION, 400, 1);
    36.  
    37. p.addPotionEffect(a);
    38. p.addPotionEffect(r);
    39. }else{
    40. return;
    41. }
    42. }
    43. }


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

    Nerdfuryz

    Can I have a download? Don't have a compiler on this computer.
     
  20. Offline

    dsouzamatt

  21. dsouzamatt Im sorry bro if i did take your work. (I didnt do so much ;) )
     
  22. Offline

    dsouzamatt

  23. Offline

    Nerdfuryz

    Yeah thanks guys.

    Ok one problem, you made the god apple exactly the same as the normal golden apple. If you could make it slightly better that would be cool. I think the regen 2 thing is what made it the same.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  24. Yes, i can make it better.
    And what effect do i have to add to enchanted golden apples?
     
  25. Offline

    dsouzamatt

  26. Yes, but what effect do you want it to have?
    Normal : abs 1 and regen 2 for 20 sec
    God apple:
     

Share This Page