Issues with Schedulers in my plugin

Discussion in 'Plugin Development' started by bobacadodl, Oct 29, 2012.

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

    bobacadodl

    Code:
        @Override
        public void run() {
            getServer().broadcastMessage("WORKING");
            if(getConfig().getBoolean("enabled")==true){
                timeleft=timeleft-1;
                if(timeleft==getConfig().getInt("time-on-warning")) getServer().broadcastMessage("§6§lExpParty starting in "+Double.toString(timeleft)+" minutes!");
                if(timeleft<=0){
                    getServer().broadcastMessage("§6§lExpParty Starting!");
                    final int runningtime=getServer().getOnlinePlayers().length*getConfig().getInt("seconds-per-player-online");
                    String[] point1 = getConfig().getString("point1").split(",");
                    String[] point2 = getConfig().getString("point2").split(",");
                    final World w = getServer().getWorld(getConfig().getString("world"));
                    final Location loc1 = new Location(w,Integer.parseInt(point1[0]),Integer.parseInt(point1[1]),Integer.parseInt(point1[2]));
                    final Location loc2 = new Location(w,Integer.parseInt(point2[0]),Integer.parseInt(point2[1]),Integer.parseInt(point2[2]));
                    final int bps = getConfig().getInt("bottles-per-second");
                 
                    getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                        public void run() {
                            if(timeupparty>runningtime){
                                getServer().getScheduler().cancelTasks(expparty);
                                getServer().getScheduler().scheduleSyncDelayedTask(expparty, expparty);
                                getServer().broadcastMessage("§6§lThe ExpParty is now over!");
                            }
                            getServer().broadcastMessage("TIME LEFT:"+Double.toString(timeupparty));
                            timeupparty = timeupparty+(1/getConfig().getInt("bottles-per-second"));
                            int locx = (int) (loc1.getX() + (int)(Math.random()*loc2.getX()));
                            int locz = (int) (loc1.getZ() + (int)(Math.random()*loc2.getZ()));
                            Bukkit.getServer().broadcastMessage(Integer.toString(locx));
                            Bukkit.getServer().broadcastMessage(Integer.toString(locz));
                            Location spawnedloc = new Location(w,locx,loc2.getY(),locz);
                            w.spawnEntity(spawnedloc, EntityType.THROWN_EXP_BOTTLE);
                        }
                    }, (20/bps)*1L);
                    timeleft=getConfig().getInt("interval-in-minutes");
                }
            }
        }
    I have been working with this code for HOURS trying to figure out what is wrong. Debugging, testing, you know. I'm tired today, and I need to get this done D: but I can't figure out what is wrong. There are still 2 problems with the code. The runnable inside the runnable only executes once, and the expbottles aren't spawning correctly. I really need help.
     
  2. Offline

    the_merciless

    Shouldnt you be using a repeating task, or am i completely mis-understanding it all?
     
    bobacadodl likes this.
  3. Offline

    bobacadodl

    HOLY CRAP THANK YOU SO MUCH!!!

    My code always fails because of tiny mistakes like this I never find T_T
     
  4. Offline

    the_merciless

    LOL, we have all made silly mistakes like that, and believe me when i say i have done it more than most :p
     
    bobacadodl likes this.
  5. Offline

    bobacadodl

    Anyways thank you so much. I got the plugin working perfectly now
     
Thread Status:
Not open for further replies.

Share This Page