PlayerRespawnEvent [Need Help]

Discussion in 'Plugin Development' started by Josh014, Aug 25, 2013.

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

    Josh014

    Hey,
    I got a problem with the PlayerRespawnEvent. I use this code
    Code:java
    1. @EventHandler
    2. public void onPlayerRespawn(PlayerRespawnEvent event) {
    3. if(Guard1.contains(event.getPlayer().getName())){
    4. event.getPlayer().getInventory().setContents(inventory);
    5. event.getPlayer().getInventory().setHelmet(helm);
    6. event.getPlayer().getInventory().setChestplate(chestPlate);
    7. event.getPlayer().getInventory().setLeggings(leggins);
    8. event.getPlayer().getInventory().setBoots(boots);
    9. event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 500, 1));
    10. event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 999999999, 1));
    11. event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 999999999, 1));
    12. event.getPlayer().playEffect(event.getPlayer().getLocation(), Effect.SMOKE, 200);
    13. event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 40, 1));
    14. }
    15. }
    16. }

    But it wont give the player his potion effect. What is the problem with this code?

    Thank you,
     
  2. Offline

    Chinwe

    Have you registered the listener in onEnable()?
     
  3. Offline

    bennie3211

    Chinwe I think he did, becuase he didnt say the inventory didnt come back :p Cant u add a scheduler to delay that 1 tick? Maybe that will work?
     
  4. Offline

    Chinwe

    Truetrue, couldn't see any other problems with it though :oops:
    Delaying it by a few ticks like bennie3211 said might do it :)
     
  5. Offline

    Josh014

  6. Offline

    bennie3211

    by using a scheduler :) this is a video for a Repeating task, but you can choose the delay task, it only uses 1 less argue :)
     
  7. Offline

    Josh014

    bennie3211
    I don't really get it that much...
    Where do I need to put the Scheduler
     
  8. Offline

    OracleTarget

    Josh014

    Try this


    Code:
    @EventHandler
        public void onPlayerRespawn(final PlayerRespawnEvent event) {
            if(Guard1.contains(event.getPlayer().getName())){   
            event.getPlayer().getInventory().setContents(inventory);
            event.getPlayer().getInventory().setHelmet(helm);
            event.getPlayer().getInventory().setChestplate(chestPlate);
            event.getPlayer().getInventory().setLeggings(leggins);
            event.getPlayer().getInventory().setBoots(boots);
            event.getPlayer().playEffect(event.getPlayer().getLocation(), Effect.SMOKE, 200);
     
            Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
                         
            @Override
            public void run(){
            event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 500, 1));
            event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 999999999, 1));
            event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 999999999, 1));
            event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 40, 1));
                    }
                },1L);
            }
        }

    DO you see the 1L on the bottom?

    This is the amount of ticks it's waiting!

    You can change it to 20 for exaple to wait 1 sec
     
  9. Offline

    MrlolDestructo

    Also, just as a tip that's sorta unrelated to the problem, instead of doing 999999999 as your time, use Integer.MAX_VALUE. Then it won't deplete. :)
     
Thread Status:
Not open for further replies.

Share This Page