Adding Potion Effects

Discussion in 'Plugin Development' started by Sparta, Jan 2, 2013.

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

    Sparta

    So I've ran into a problem. Adding potion effects won't work. I have this in my player respawn listener.

    //Strength Potion Effect (20 ticks = 10 seconds)
    p.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 18000, 1));

    I want players to spawn with Strength I effect for 15 minutes, but it won't work.

    WHY WON'T THIS WORK?
     
  2. Offline

    Major_Derp

    Sparta
    That looks about right, it should work, What is the code for the listener?
     
  3. Offline

    Sparta

    It has nothing to do with the listener, if I showed you the code it would basically be public void listenerName(Event event) { addPotionEffect(blabhahjvkhadksa); }

    I still need help with this....

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

    fireblast709

  5. Offline

    Sparta

  6. Offline

    LaxWasHere

    Please don't bash other people for trying to help you.

    Did you "Register" the listener?
     
  7. Offline

    Sparta

    Yes, the listener is registered. I'm not bashing on him, I'm just stating something to him.
     
  8. Offline

    LaxWasHere

    Did you put an "@EventHandler" before the listner? How about giving us the code?
     
  9. Offline

    Sparta

    public class listenerName implements Listener {

    @EventHandler
    public void onPlayerRespawn(PlayerRespawnEvent event) {
    Player p = event.getPlayer();
    //Diamond Sword
    ItemStack diamondSword = new ItemStack(276, 1);

    //Iron Armor
    ItemStack ironHelmet = new ItemStack(Material.IRON_HELMET);
    ItemStack ironChestPlate = new ItemStack(Material.IRON_CHESTPLATE);
    ItemStack ironLeggings = new ItemStack(Material.IRON_LEGGINGS);
    ItemStack ironBoots = new ItemStack(Material.IRON_BOOTS);
    ItemStack mushroomSoup = new ItemStack(Material.MUSHROOM_SOUP);

    p.getInventory().setItem(0, diamondSword);
    p.getInventory().setHelmet(ironHelmet);
    p.getInventory().setChestplate(ironChestPlate);
    p.getInventory().setLeggings(ironLeggings);
    p.getInventory().setBoots(ironBoots);

    for(int i = 1; i <= 8; i++) {
    p.getInventory().setItem(i, mushroomSoup);
    }
    //Strength Potion Effect (20 ticks = 10 seconds)
    p.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 18000, 2));
    }
    }

    I still need help on this...

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

    LaxWasHere

    It's not registered.
    Where's your main class?
     
  11. Offline

    gomeow

    Also, in the OP, you said 20 ticks = 10 seconds. It is actually equal to 1 second, not 10
     
  12. Offline

    Sparta

    It is registered, and I'd know that because people spawn with armor and a diamond sword and mushroom soup already.

    Still need help with this....

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

    Major_Derp

    It doesnt work because it fires right away on respawn, so the potion effect can't be added, but you can create a delayed task like this:
    Code:java
    1.  
    2. final Player player = event.getPlayer();
    3. plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable() {
    4. public void run() {
    5. player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 18000, 2));
    6. }
    7. }, 20);
    8. [FONT=Consolas][/FONT]

    and the 20 at the end is the number of ticks to delay. Hopefully this works!
    Or you might have to use a "Sync" delayed task, im still new to the delayed task stuff, so im a little unsure.
     
  14. Offline

    Sparta

    Major_Derp, that didn't help at all or work. :(
     
  15. Offline

    brandonHD

    I just tested it with 1.5.2 and I used 40 instead of 20 and It worked fine!
     
Thread Status:
Not open for further replies.

Share This Page