getTime()

Discussion in 'Plugin Development' started by MillerTheBeast, Jan 14, 2011.

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

    MillerTheBeast

    I'm having a little trouble with getTime() and setTime(). Im getting the following error in Eclipse whenever I try to use those two methods.
    Code:
    The method setTime(int) is undefined for the type mPlayerListener
    Are the time hooks not implemented yet or am I going about this all wrong? This is the code I'm using for time get/set time function.

    Code:
    if (split[0].equalsIgnoreCase("/mtime")) {
                if (split.length == 1) {
                    player.sendMessage("Usage: /mtime [day,night,check]");
                } else if (split.length == 2){
                    if (split[1].equalsIgnoreCase("day")) {
                        setTime(12000);
                    } else if (split[1].equalsIgnoreCase("night")){
                        setTime(24000);
                    } else if (split[1].equalsIgnoreCase("check")){
                        long  time = getTime();
                        time = time / 1000;
                        player.sendMessage("The time is " + time + " hours");
                    }
                }
                event.setCancelled(true);
                }
     
  2. Offline

    Ben S

    As long as you have the server instance
    You should be able to do instance.getTime()/instance.setTime()
     
  3. Offline

    MillerTheBeast

    Now I'm getting
    Code:
    instance cannot be resolved
    with
    Code:
    instance.getTime();
    and I've got Server instance put in right.
    Code:
    public MillersPlugin(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File plugin, ClassLoader cLoader)
     
  4. Offline

    Ben S

    To me it sounds like you haven't told eclipse to include the external Bukkit.jar correctly.
     
  5. Offline

    MillerTheBeast

  6. Offline

    feverdream

    Since I have a few plugins that use this (And I use eclipse) , I saw the thread and thought I would stop by..

    If the bukkit.jar file is referenced in your project (NOT CraftBukkit!) the following code should let you get the current minecraft server time in RAW format. There is no way to directly get it in AM/PM or in seconds, you have to take the RAW time and calculate it yourself..

    Call getServer() from your own onEnable() function. Store that and use the object later, or then call getTime() directly.

    Code:
    	public void onEnable() {
    		Server server = getServer();
                    long time = server.getTime();
                    long time2 = getServer().getTime();
    	}
    
     
  7. Offline

    FlameHead269

    actually idt my msg has anything to do with this but almost everyone epic fails in Eclipse... =/ but try NetBeans IDE(Way Better)
     
  8. Offline

    xpansive

    I think the problem is that instance is a local variable, so you cant access it from wherever you try to access it. You need to do this:
    Code:
    Server server;
    public thePluginName(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File plugin, ClassLoader cLoader) {
        server = instance;
    }
     
  9. Offline

    MillerTheBeast

    Fixed it, looked at some source code in feverdreams github! Thanks for the help guys!

    For anyone else with the problem, this is the code I used:
    Code:
     Server server = plugin.getServer();
            long time = server.getTime();
     
  10. Offline

    feverdream

    May I ask what code you used? I sort of forked a lot of code the other day so it would not get lost after hey0 died.. intention is to port things if they do not get ported by the authors.
     
  11. Offline

    MillerTheBeast

    I used some code from either noon, or extendday.
     
  12. Offline

    brbtus

    MillerTheBeast
    feverdream
    xpansive
    Code:java
    1. scheduler.scheduleSyncDelayedTask(this, new Runnable() {
    2. @Override
    3. public void run() {
    4. Server server = plugin.getServer();
    5. long time = server.getTime();
    6. }
    7. }, 2);

    And it doesnt work at the plugin.getServer(); plugin is underlined
     
  13. Offline

    AoH_Ruthless

    brbtus
    Holy crap, this is the biggest necro I've ever seen. Nearly 3 and a half years have gone by since this thread's last post.
     
    brbtus, TheBigSuperCraft and zack6849 like this.
Thread Status:
Not open for further replies.

Share This Page