Need help with Respawn event

Discussion in 'Plugin Development' started by galbatoo, Jun 19, 2012.

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

    galbatoo

    Hey guys, i want that if a player respawns he will get a potion effect.
    How could i do that?

    First Code:
    Code:
    public void onPlayerRespawn(PlayerRespawnEvent event)
        {
            Player p = (Player) event.getEntity();
    This doesnt work :(
    I just want to make it like here
    Code:
                    Player p = (Player) event.getEntity();
                   
                    p.sendMessage("Du bist gestorben und hast einen Untoten mit einem Blitz beschworen! ");
                 
                  p.getWorld().spawnCreature(p.getLocation(), EntityType.ZOMBIE);
                  p.getWorld().strikeLightningEffect(p.getLocation());
    But it shows me an error with the first code
     
  2. Offline

    nisovin

    PlayerRespawnEvent is a Player event, just use getPlayer() on it, not getEntity().
     
    galbatoo likes this.
  3. Offline

    galbatoo

    Omg thanks! I am so stupid -.-

    Code:
    public void onPlayerRespawn(PlayerRespawnEvent event)
        {
           
            Player p = (Player) event.getPlayer();       
            p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 200, 1));
            p.sendMessage(ChatColor.RED + "Durch die Schmerzen bist du Verwirrt!");
        }
    Ok so far so good but if i respawn i dont get the effect or message. Btw i want to add a random Picker for the Respawn effects. Any tipps?

    Ok added a @EventHandler but i only get the message

    push

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

    CXdur

    This would work I think:
    Code:
        public void onPlayerRespawn(PlayerRespawnEvent event)    {
            Player p = event.getPlayer();     
            p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 200, 1));
            p.sendMessage(ChatColor.RED + "Durch die Schmerzen bist du Verwirrt!");
        }
    
     
  5. Offline

    galbatoo

    Still dont get the Potion Effect!

    push

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

    EnvisionRed

    In the main plugin class have you set it to register events from that listener? In the onEnable method, what I do is:

    Code:
    getServer().getPluginManager().registerEvents(new NameOfYourEventsClassHere(), this);
     
  7. Offline

    fromgate

    May you forget to define event handler declaration?

    Code:
    @EventHandler(priority=EventPriority.NORMAL, ignoreCancelled = true)
    public void onPlayerRespawn(PlayerRespawnEvent event)    {
    //...........
    }
     
  8. Offline

    galbatoo

    1. Dont works :(
    Code:
    @EventHandler(priority=EventPriority.NORMAL, ignoreCancelled = true)
          public void onPlayerRespawn(PlayerRespawnEvent event)    {
            Player p = event.getPlayer();   
            p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 200, 1));
            p.sendMessage(ChatColor.RED + "Durch die Schmerzen bist du Verwirrt!");
            p.setHealth(5);
        }
    2. The class loads because i get the message.
     
  9. Offline

    EnvisionRed

    I see.
    Perhaps it is because of the amplifier being 1? Try setting that to something such as 10, or higher. Maybe play with the duration for a bit (it's in ticks) to see what happens.


    Also, can you post your onEnable method here? I want to see how you are registering the listener.
     
  10. Offline

    galbatoo

    Code:
    @Override
        public void onEnable()
        {
            registerEvent();
            loadConfig();
            System.out.println("Minewow gestartet!");
         
         
            }
    Code:
    private void registerEvent(){
            pd = new op(this);
        }
        private op pd;
    op is the class
    The weird is that i dont get the Damage too

    push

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

    desht

    galbatoo likes this.
  12. Offline

    galbatoo

    Yay thanks youre my hero ;D

    Errr... still dont works :( What do i do wrong?
    Code:
    @EventHandler
        public void onPlayerRespawn(final PlayerRespawnEvent event) {
         
            event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 200, 10));
            event.getPlayer().sendMessage(ChatColor.RED + "Durch die Schmerzen bist du Verwirrt!");
           
        }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  13. Offline

    dxwarlock

    there is no delayedtask in there, you are still trying to do it from the re-spawn instant..
    try like the other thread he linked and delay it a tick or 2.
     
  14. Offline

    galbatoo

    Oops i failed ^^. Now it works

    Guys? How can i make a Random Picker for the potion effects that activates if you respawn?

    push

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

Share This Page