Solved Adding potion effects on respawn

Discussion in 'Plugin Development' started by xlr20ice, Aug 30, 2015.

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

    xlr20ice

    Hello, world!

    The goal of this little snippet of code is to give the players potion effects based on their permission groups. Here it is:

    Code:
        @EventHandler
        public void saveEffect(PlayerRespawnEvent e)
        {
            Player player=e.getPlayer();
            player.setMaxHealth(10);
            if(Compass.perms.playerInGroup(player, Compass.adelgae))
            {
                player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE,Integer.MAX_VALUE,0,true,false));
                player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 0, true, false));
            }
            if(Compass.perms.playerInGroup(player, Compass.eshanti))
            {
                player.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, Integer.MAX_VALUE, 0, true, false));
            }
            if(Compass.perms.playerInGroup(player, Compass.negveh))
            {
                player.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE,Integer.MAX_VALUE,1,true,false));
            }
        }
    Yes I know static variables are the root of all evil but that is a problem for another time
    I tried the method where you save the potion effects on death in a HashMap and give them back on the player respawn, which didn't work.

    Thanks in advance!

    ~Xlr~
     
  2. Offline

    mine-care

    Static isnt evil, the way it is used is. By your code snippet and not knowing the background code, what those variables are and so on i cant really judge if it is used properly or not...

    Now back to your problem, i dont see anything related to this attempt:
    Anyway your current snippet should work, Have you debuged? does "Compass.perms.playerInGroup(..)" ever return true?
     
  3. Offline

    Concurrent

    @xlr20ice just add a few ticks of delay (i usually use 4) to the respawn event.
     
  4. Offline

    xlr20ice

Thread Status:
Not open for further replies.

Share This Page