Solved Potion Effects help?

Discussion in 'Plugin Development' started by Liutenantpickle, Nov 10, 2012.

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

    Liutenantpickle

    Sup bukkit. Can you check what error did I make in this event? It doesnt work for me though :(

    Code:
        @EventHandler
        public void onRespawn(PlayerDeathEvent e) {
            Player killed = e.getEntity();
            if (killed instanceof Player) {
               
                PotionEffect speed = PotionEffectType.SPEED.createEffect(10, 0);
     
                killed.addPotionEffect(speed, true);
            }
        }
    }
    Help maybe? Thanks.
     
  2. Offline

    CeramicTitan

    hey

    Code:
    @EventHandler
        public void onRespawn(PlayerDeathEvent e) {
            Player killed = e.getEntity();
            if (killed instanceof Player) {
            killed.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, *DURATION*, 1));
            }
        }
    *DURATION* = time the effect should last. IN TICKS(20 TICKS = 1 SECOND)
     
    Liutenantpickle likes this.
  3. Offline

    Liutenantpickle

    Doesnt work :( I forgot to state that the potioneffect will be applied on respawn of player.
    but can I do "public void onRespawn(PlayerRespawnEvent e) {" ?
     
  4. Offline

    CeramicTitan

    Liutenantpickle

    I think there is another event. Ill find out soon enough


    EDIT: replace ' Player killed = e.getEntity();' with Player killed = e.getPlayer();

    And that should work.

    Use "public void onRespawn(PlayerRespawnEvent e) {" if you didn't realise.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  5. Offline

    Liutenantpickle

    Still doesnt work though :l
    Code:

    Code:
    package me.Rad.perks;
     
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerRespawnEvent;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
     
    public class Boost implements Listener {
     
        @EventHandler
        public void onRespawn(PlayerRespawnEvent e) {
            Player player = e.getPlayer();
            if (player instanceof Player) {
                player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,
                        500, 1));
            }
        }
    }
     
  6. Offline

    CeramicTitan

    Schedule a task. Ill code it for you one sec

    Code:
     @EventHandler
            public void onRespawn(PlayerRespawnEvent e) {
                final Player player = e.getPlayer();
                if (player instanceof Player) {
                    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
                    @Override
                    public void run() {
                    player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,
                            500, 1));
                    }
                    }, 10L);
                }
            }
        }
    then you need to reference you plugin otherwise it will return null and you will have an error

    Code:
    public *class name*(*Main class name* plugin){
            this.plugin = plugin;
        }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  7. Offline

    Liutenantpickle

    Where do I add this? In my class? or MAIN class?
     
  8. Offline

    CeramicTitan

    your Listener class

    above "public void onRespawn(PlayerRespawnEvent e) {"
     
  9. Offline

    Liutenantpickle

    I'm getting errors here, on "this.plugin = plugin;"
    Code:
        public Boost(Perks plugin) {
            this.plugin = plugin;
    and here on "plugin"
    Code:
                Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    What will I do? D: (Sorry, I'm a noob at java :( )
     
  10. Offline

    CeramicTitan

    above this public Boost(Perks plugin) {
    this.plugin = plugin;
    Type 'public *your class name* plugin;'
     
    Liutenantpickle likes this.
  11. Offline

    Liutenantpickle

    Alright! Thanks Ceramic! :)
     
  12. Offline

    CeramicTitan

    Let me know if it works :)
     
Thread Status:
Not open for further replies.

Share This Page