Getting the time in the world

Discussion in 'Plugin Development' started by UHoplite, May 6, 2014.

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

    UHoplite

    Hi, so I'm working on a plugin, just for fun, but I have a problem.
    In a specific part of the code, I want to get the time in the world (Not the server!), add 3000 ticks to it and broadcast a message. In order to do that, I wrote these lines of code-

    [​IMG]

    Iv'e tried debugging, and I figured out that the code stops at the first line in the image above (The rest of the code works just fine).

    So what am I doing wrong? How do I get the world and the time in it, and how do I change the time?

    And what's the difference between 'setTime' and 'setFullTime' ?

    Thanks ahead!
     
  2. UHoplite
    Hi and welcome.

    First of all, the getWorlds() method returns a List<World>. With this line of code
    Code:
    ( (World) Bukkit.getServer().getWorlds() ).setTime(time);
    you're giving the compiler the right to assume that the World object is either a List<World> or a subclass of it. Hence the (World) right at the beginning. clicky.

    If you take a look at your server console after running that code, you should see a ClassCastException in it.

    If you want to set the time of a specific world which's name you already know, use getWorld("name here"). If not, then please elaborate what you want to do.
     
    UHoplite and xTigerRebornx like this.
  3. Offline

    UHoplite

    Assist

    Hi again!

    I managed to deal with this problem, I wanted to choose the overworld so I actually needed to write-
    Code:java
    1. Bukkit.getServer().getWorlds().get(0).setTime(time);

    Thanks anyways!
     
Thread Status:
Not open for further replies.

Share This Page