Always Daylight

Discussion in 'Plugin Development' started by mgbeenieboy, Sep 2, 2014.

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

    mgbeenieboy

    How do I check the time of a specific world and set it?
     
  2. Offline

    SuperOmegaCow

  3. Offline

    Syd

    mgbeenieboy
    World#getTime(), World#setTime(long), World#getFullTime() and World.setFullTime(long)
    You just have to retrieve the World object from somewhere.
    In most cases you already have it where you need it, otherwise you can get it by it's name with Bukkit.getWorld(String).
     
  4. Offline

    mgbeenieboy

    Thank you :)

    Code:java
    1. package me.craftwood.mckreativ;
    2.  
    3. import org.bukkit.World;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.player.PlayerMoveEvent;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7.  
    8. public class McKreativ extends JavaPlugin {
    9.  
    10. public void onEnable() {
    11. System.out.println("[" + this.getDescription().getName() + "] " + this.getDescription().getName() + " v" + this.getDescription().getVersion() + " by " + this.getDescription().getAuthors() + " enabled");
    12. }
    13. public void onDisable() {
    14. System.out.println("[" + this.getDescription().getName() + "] " + this.getDescription().getName() + " v" + this.getDescription().getVersion() + " by " + this.getDescription().getAuthors() + " disabled");
    15. }
    16.  
    17. @EventHandler
    18. public void onPlayerMove(PlayerMoveEvent e) {
    19. World w = e.getPlayer().getWorld();
    20. if(w.getTime() > 12000) {
    21. w.setTime(0);
    22. }
    23. }
    24. }
    25.  


    Why does this not work? :(
     
  5. Offline

    izarooni

  6. Offline

    mgbeenieboy

    Code:java
    1. package me.craftwood.mckreativ;
    2.  
    3. import org.bukkit.plugin.java.JavaPlugin;
    4.  
    5. public class McKreativ extends JavaPlugin {
    6.  
    7. public void onEnable() {
    8. System.out.println("[" + this.getDescription().getName() + "] " + this.getDescription().getName() + " v" + this.getDescription().getVersion() + " by " + this.getDescription().getAuthors() + " enabled");
    9. getServer().getPluginManager().registerEvents(new PlayerMoveListener(), this);
    10. }
    11. public void onDisable() {
    12. System.out.println("[" + this.getDescription().getName() + "] " + this.getDescription().getName() + " v" + this.getDescription().getVersion() + " by " + this.getDescription().getAuthors() + " disabled");
    13. }
    14. }
    15.  


    Code:java
    1. package me.craftwood.mckreativ;
    2.  
    3. import org.bukkit.World;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.player.PlayerMoveEvent;
    7.  
    8. public class PlayerMoveListener implements Listener {
    9.  
    10. @EventHandler
    11. public void onPlayerMove(PlayerMoveEvent e) {
    12. World w = e.getPlayer().getWorld();
    13. if(w.getTime() > 12000) {
    14. w.setTime(0);
    15. }
    16. }
    17.  
    18. }
    19.  


    I tried it with a second class file :S but it doesn't work.

    Aaaaah... Ok it works now :3

    Code:java
    1. package me.craftwood.mckreativ;
    2.  
    3. import org.bukkit.World;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.player.PlayerMoveEvent;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class McKreativ extends JavaPlugin implements Listener {
    10.  
    11. @Override
    12. public void onEnable() {
    13. System.out.println("[" + this.getDescription().getName() + "] " + this.getDescription().getName() + " v" + this.getDescription().getVersion() + " by " + this.getDescription().getAuthors() + " enabled");
    14. getServer().getPluginManager().registerEvents(this, this);
    15. }
    16.  
    17. @Override
    18. public void onDisable() {
    19. System.out.println("[" + this.getDescription().getName() + "] " + this.getDescription().getName() + " v" + this.getDescription().getVersion() + " by " + this.getDescription().getAuthors() + " disabled");
    20. }
    21.  
    22. @EventHandler
    23. public void onPlayerMove(PlayerMoveEvent e) {
    24. World w = e.getPlayer().getWorld();
    25. if(w.getTime() > 12000) {
    26. w.setTime(0);
    27. }
    28. }
    29. }
    30.  


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  7. Offline

    indyetoile

    mgbeenieboy
    What an inefficient way to do this. Each time a player moves this event will be fired.
    You should use a repeating task which checks the time every x ticks.
     
Thread Status:
Not open for further replies.

Share This Page