Won't Change Time

Discussion in 'Plugin Development' started by Yummy Juice, Sep 11, 2012.

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

    Yummy Juice

    My code doesn't change time when it's supposed to or at all for that matter.

    package me.yummyjuice.daym;
    import org.bukkit.World;
    import org.bukkit.plugin.java.JavaPlugin;
    public class DayM extends JavaPlugin {
        public void onEnable(){
            System.out.print("[DayM] Enabling DayM.");
            getServer().getScheduler().scheduleSyncRepeatingTask(this, new DayMTime(), 0L, 5L);
    public void onDisable(){
            System.out.print("[DayM] Disabling DayM.");
    class DayMTime implements Runnable {
        private World world;
        public void run() {
            System.out.print("The Plugin is working!");
            long time = world.getTime();
            if(time == 15000) {
            if(time == 2500) {
  2. Offline


    Have you tried bukkits dispatch command function?
  3. Offline


    world isn't ever initialized and you defined a class within your main class.
  4. Offline

    Yummy Juice

    So how does one go about fixing this?
  5. Offline


    Also you havent defined world correctly it doesent know what world it should set the time in
    Edit: refresh'd page. Allready said
  6. Offline

    Yummy Juice

    Woops. Tried defining world like this but I get a syntax error on world on the first line.
    world = plugin.getServer().getWorld(worldName);
        private World world;
  7. Last you tell the scheduler to run every 5 ticks, which isn't goof as use use == with the worlds time. Think about it that way: You check if the tick is 15000.
    First run: 14997
    Next run: 15002
    Both runs will get a false with your ==, so it won't change the time.
    So either change it to something like this:
    1. if(time > 15000) { //BTW: This will cause 2000 ticks day instead of 24000 ticks day and your next else will never be called. Sure you want it like that? o.O
    2. world.setTime(13000);
    3. }
    4. else if(time > 2500 && time < 5000) {
    5. world.setTime(5000);
    6. }

    Or tell the scheduler to run every tick (change 5L to 1L).
Thread Status:
Not open for further replies.

Share This Page