Solved [1.8.8] Cant add potion effects

Discussion in 'Spigot Plugin Development' started by Lockett18, Jun 1, 2017.

Thread Status:
Not open for further replies.
  1. I have been looking, and I haven't found anything that would point me to the fact I'm doing something wrong, but I clearly am so any help would be appreciated.
    Code (Text):
    package com.lockett.deathcooldowns;

    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    public class RespawnListner implements Listener {
       
        private Main main;
        public RespawnListner(Main main) {
            this.main = main;
        }
       
        @EventHandler
        public void PlayerRespawnEvent(org.bukkit.event.player.PlayerRespawnEvent e) {
            Player player = e.getPlayer();
           
            if (main.cooldown.containsKey(player) && main.cooldown.get(player) > System.currentTimeMillis()) {
                long longRemaining = main.cooldown.get(player) - System.currentTimeMillis();
                int intRemain = (int) (longRemaining / 1000);
                int ticks = (int) (intRemain * 20);
               
                player.addPotionEffect((new PotionEffect(PotionEffectType.INVISIBILITY, ticks, 1, false, false)));
                player.sendMessage("Respawn Event detected!");
           
            }
           
        }

    }
    The message is being sent.
     
  2. Does it not add the effect or does the event not work all together? And why are you using 'org.bukkit.event.player.PlayerRespawnEvent' and not just PlayerRespawnEvent?
     
  3. The event works, as like I said it sends the message. And believe me when I tried to do PlayerRespawnEvent it just would not work. So it wanted to change it to that so... The effect just doesn't add at all.
     
  4. Tell me if I'm missing somethjng here, but is that how you use PotionEffects? I use them like this, and they always work:

    Code (Text):
    player.addPotionEffect(new PotionEffect(PotionEffectType, duration (in ticks), amplifier));
     
  5. Read the spigot docs my dude. The 2 extra booleans that I have at the end are for ambient and particles.
     
  6. "PotionEffectType.INVISIBILITY, ticks, 1, false"

    ...where you say "ticks", what's that for?
     
  7. long longRemaining = main.cooldown.get(player) - System.currentTimeMillis();
    int intRemain = (int) (longRemaining / 1000);
    int ticks = (int) (intRemain * 20);

    Please actually read the code before asking questions.
     
    • Like Like x 1
  8. Oh, sorry! Somehow I skipped right over that bit.
     
  9. Someone told me to make it a runnable so I will try that tomorrow.
     
  10. Problem solved. Fix: Make it a Runnable and have it run one or two ticks later.
     
Thread Status:
Not open for further replies.