Solved Potion Effect Not Working

Discussion in 'Plugin Development' started by spankynutbean, Jun 4, 2013.

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

    spankynutbean

    My code is supposed to make the player invisible when they sneak, but it isn't working!
    Code:
    @EventHandler
            public void onSneak(PlayerToggleSneakEvent e){
                Player p = e.getPlayer();
                if(ninja.contains(p.getName())){
                    p.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 1, 1));
                }
            }
     
  2. Offline

    WolfClash

    Noob question but, whats the "ninja" for?
     
  3. It's a variable standing for something I guess, or could be the class name.
     
  4. Offline

    WolfClash

    If you're still having troubles try this:
    Code:
    @EventHandler
            public void onSneak(PlayerToggleSneakEvent e){
                Player p = e.getPlayer();
                if(e.isSneaking());
                    p.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 1, 1));
     
    InspectorFacepalm likes this.
  5. Offline

    ZeusAllMighty11

    Well it gives them the effect for 1/20th of a second...
     
  6. Offline

    WolfClash

    I don't think that should matter since the potion is given as long as the player is shifting.
     
  7. Offline

    ZeusAllMighty11

    It only checks when they toggle it. It doesn't check WHILE they are sneaking, so even by inserting a while loop it is useless
     
  8. The player has to repeatedly click shift to give them the 1 sec potion effect I think.
    EDIT: Ninja'd by TheGreenGamer
     
  9. Offline

    WolfClash

    Oh then in that case
    Code:
    @EventHandler
            public void onSneak(PlayerToggleSneakEvent e){
                Player p = e.getPlayer();
                if(e.isSneaking());
                    p.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999999, 1));
    If that doesn't work, then I have no idea.
     
  10. Offline

    ZeusAllMighty11

    It would be better if you stored the player's name somewhere, when they first sneak. After that, run a task for all sneaked players every second to see if they were sneaking. If so, apply effect.
     
  11. Offline

    spankynutbean

    How do you run a task for all players every second to see if they were sneaking TheGreenGamerHD?

    *bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  12. Offline

    ZeusAllMighty11

    It's pathetic that you bumped after an hour. Go use google or something
     
  13. Offline

    Retherz_

    @EventHandler
    public void onSneak(PlayerToggleSneakEvent e){
    Player p = e.getPlayer();
    if(ninja.contains(p.getName())){
    p.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 1, 1));
    }
    }

    Will give them invsibility for 1 tick (1/20 of a second) when they start to sneak, you could add them to a list and keep checking if they are sneaking then add the potion effect else you remove them from the list and they get added when they toggle sneak
     
  14. Offline

    FlaminYogurt

    Code:
    @EventHandler
        public void onToggleSneak(PlayerToggleSneakEvent e) {
            Player p = e.getPlayer();
            if (e.isSneaking()) {
                p.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 999999999, 1));
            } else {
                p.removePotionEffect(PotionEffectType.INVISIBILITY);
            }
        }
    What about this?
     
  15. Offline

    thecrystalflame

    WolfClash
    ninja is refering to a list

    spankynutbean
    The method is only being called for 1 tick
    What you need to do is give the player infinite invisibility when sneak is toggled and then remove the effect once they stop
     
  16. Offline

    spankynutbean

    Ok got it guys thanks!
     
Thread Status:
Not open for further replies.

Share This Page