Solved Potion effects arent given its never triggered?

Discussion in 'Spigot Plugin Development' started by mmuziek, May 29, 2016.

  1. hi there.
    im working out how to use potion effects but it seems the timer is not running or doing its job can someone see what im doing wrong.
    its in my main class :

    in the ON enable i have added effectstimer();
    Code (Text):



    public void effectstimer() {

            boolean slow = getConfig().getBoolean("Slowness");
            boolean jump = getConfig().getBoolean("Jumpboost");
            World w = getServer().getWorld(getConfig().getString("space"));
            for (Player p : Bukkit.getOnlinePlayers()) {
                if (p.getWorld() == w) {
                    getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {

                        @Override
                        public void run() {
                            if (slow == true) {
                                p.sendMessage("Slow Applied");
                                p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 800, 2));

                            }
                            if (jump == true) {
                                p.sendMessage("Jump Applied");
                                p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 800, 2));

                            }

                        }
                    }, 0L, 80L);

                }
            }

        }
    Config:
    Code (Text):
    Slowness: true
    Jumpboost: true
     
  2. You posted two posts within 2min of eachother.
     
  3. Where is this being called? Check if slow or jump is false.
     
  4. You check if the player is in a certain world, yet you never define the world in the config
     
  5. Replease:
    Code (Text):
    p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 800, 2));
    for this
    Code (Text):
     p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 800, 2), true);
     
  6. Or, it's because you're calling the method in the onEnable, when no players are online.

    Also, doing:
    Code (Text):
    if (bool == true)
    Is unnecessary and can replaced with the more logical:
    Code (Text):
    if (bool)
     
  7. Indeed but you can do that if you are creating your boolean like this
    Code (Java):
    public boolean bool() {
       if(getConfig().getBoolean("Path")) {
             return true;
        }
        return false;
    }
     
  8. Or...
    Code (Text):
    public boolean getBoolean() {
        return getConfig().getBoolean();
        // That method can return null, but the logic is the important part
    }
    Boolean logic. You failed to understand my point completely.
     
  9. well :p you don't get what I mean either I mean op's way

    if(bool == true) and if (bool == false)
     
    #9 MadMaxCookie, May 30, 2016
    Last edited: May 30, 2016
  10. any current error ? @OP "?
     
  11. ok i tested all suggestions out. moved the auto runner to before the player check so it does the player check every 4 seconds
    and added the TRUE at the end of the potion effect code
    and fixed the boolean if
    still no luck
    here is my current code:
    Code (Text):
    public void effectstimer() {

            boolean slow = getConfig().getBoolean("Slowness");
            boolean jump = getConfig().getBoolean("Jumpboost");
            World w = getServer().getWorld(getConfig().getString("space"));
            getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {

                @Override
                public void run() {
            for (Player p : Bukkit.getOnlinePlayers()) {
                if (p.getWorld() == w) {
                   
                            if (slow) {
                                p.sendMessage("Slow Applied");
                                 p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 800, 2), true);

                            }
                            if (jump) {
                                p.sendMessage("Jump Applied");
                                 p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 800, 2), true);

                            }

                        }
                   

                }
               
            }
            }, 0L, 80L);
        }
    my config contains :
    Code (Text):
    space: space
    Jumpboost: true
    Slowness: true
     
  12. error ?
     
  13. Nope no errors in console
     
  14. inside the run use BukkitRunnable.

    it should be like this

    Code (Java):
    Bukkit.getScheduler().scheduleAsyncRepeatingTask(Core.plugin, new Runnable(){
               publicvoid run(){
                   // some code

                   new BukkitRunnable(){
                       publicvoid run(){
                           // sendPluginMessage here
                       }
                   }.runTask(Core.plugin);

               }
    }, 0, 80);
     
    • Optimistic Optimistic x 1
  15. will try that when i get home again thanks for the help :)
     
  16. no problem
     
  17. i currently have this code im debugging it more but until now i cannot seems to find the solution
    Code (Text):
    public void effectstimer() {

            boolean slow = getConfig().getBoolean("Slowness");
            boolean jump = getConfig().getBoolean("Jumpboost");
            World w = getServer().getWorld(getConfig().getString("space"));
             BukkitScheduler scheduler = getServer().getScheduler();
                scheduler.scheduleSyncRepeatingTask(this, new Runnable() {

                @Override
                public void run() {
            for (Player p : Bukkit.getOnlinePlayers()) {
                if (p.getWorld().equals(w)) {
                   
                            if (slow) {
                                p.sendMessage("Slow Applied");
                                 p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 800, 2), true);

                            }
                            if (jump) {
                                p.sendMessage("Jump Applied");
                                 p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 800, 2), true);

                            }

                        }
                   

                }
               
            }
            }, 0L, 80L);
        }
     
  18. After a long trial and error period i found the solution.

    i was getting the values from the config BEFORE the timer that goes every .... seconds after the first run it loses the value W and the JUMP and SLOW values.
    i moved those all inside the timer and now it works!

    thanks for the help tho!
    good luck!