Solved int questions

Discussion in 'Plugin Development' started by kamakarzy, May 7, 2013.

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

    kamakarzy

    for some reason my code is returning 0
    Code:
    if (count >= getConfig().getInt("Time")){

    the config says
    but
    Code:
    Time: 108000
    i have a feeling its something to do with .getInt but im not quite sure
     
  2. Offline

    Craftiii4

    Is the path correct?
    Just to make sure, at the moment your using if (count (is greater than or equal to) time) {
     
  3. Offline

    kamakarzy

    Craftiii4 the path is correct but everytime i load up server i get

    Code:
    2013-05-07 22:42:43 [INFO] BasicVersion1.0Has Been Enabled
    2013-05-07 22:42:43 [INFO] [Main] Enabling Main v1.0
    2013-05-07 22:42:43 [INFO] [Main] By nomad856 aka kamakarzy with thanks to bukkit fourms team
    2013-05-07 22:42:43 [INFO] MainHas Been Enabled
    2013-05-07 22:42:43 [INFO] [ImportVault] Enabling ImportVault v1.0
    2013-05-07 22:42:43 [INFO] [PermissionsEx] Enabling PermissionsEx v1.19.5
    2013-05-07 22:42:43 [INFO] [PermissionsEx] Superperms support enabled.
    2013-05-07 22:42:43 [INFO] [PermissionsEx] v1.19.5 enabled
    2013-05-07 22:42:43 [INFO] [Vault][Chat] PermissionsEx_Chat hooked.
    2013-05-07 22:42:43 [INFO] [ShopTeleport] Enabling ShopTeleport v2.0
    2013-05-07 22:42:43 [INFO] [ShopTeleport] By nomad856 aka kamakarzy with thanks to bukkit fourms team
    2013-05-07 22:42:43 [INFO] ShopTeleportHas Been Disabled
    2013-05-07 22:42:43 [INFO] [Huggs] Enabling Huggs v1.1
    2013-05-07 22:42:43 [INFO] [Huggs] By nomad856 aka kamakarzy with thanks to bukkit fourms team
    2013-05-07 22:42:43 [INFO] HuggsHas Been Enabled
    2013-05-07 22:42:43 [INFO] Server permissions file permissions.yml is empty, ignoring it
    2013-05-07 22:42:43 [INFO] Done (2.312s)! For help, type "help" or "?"
    2013-05-07 22:42:43 [INFO] Now Saving...
    2013-05-07 22:42:43 [INFO] Saving Players...
    2013-05-07 22:42:43 [INFO] Saving Players...
    2013-05-07 22:42:43 [INFO] Saved Players
    2013-05-07 22:42:43 [INFO] Saving world: null
    2013-05-07 22:42:43 [INFO] Saving world: world
    2013-05-07 22:42:43 [INFO] Saving world: world_nether
    2013-05-07 22:42:43 [INFO] Saving world: world_the_end
    2013-05-07 22:42:43 [INFO] Saved nullWorlds
    2013-05-07 22:42:43 [INFO] Now Saving...
    2013-05-07 22:42:43 [INFO] Saving Players...
    2013-05-07 22:42:43 [INFO] Saving Players...
    2013-05-07 22:42:43 [INFO] Saved Players
    2013-05-07 22:42:43 [INFO] Saving world: null
    2013-05-07 22:42:43 [INFO] Saving world: world
    2013-05-07 22:42:43 [INFO] Saving world: world_nether
    2013-05-07 22:42:43 [INFO] Saving world: world_the_end
    2013-05-07 22:42:43 [INFO] Saved nullWorlds
    but my code is
    Code:java
    1. @Override
    2. public void run() {
    3. if (count == getConfig().getInt("Time")){
    4. Bukkit.broadcastMessage("Now Saving...");
    5. Bukkit.broadcastMessage("Saving Players...");
    6. savePlayers();
    7. Bukkit.broadcastMessage("Saved Players");
    8. Bukkit.broadcastMessage("Saving world: " + Bukkit.getWorld(getName()));
    9. saveWorlds();
    10. Bukkit.broadcastMessage(String.format("Saved "
    11. + Bukkit.getWorld(getName()) + "Worlds"));
    12. count = 0;
    13. return;
    14. }
    15. count++;
    16.  
    17. }
    18.  
    19. };
    20. run.runTaskTimer(this, 0L, 20L);
    21. return;


    config

    Code:
    # This is the Default config for Easysave
     
    Time: 108000
    
     
  4. Offline

    Minnymin3

    When is count first initialized?
     
  5. Offline

    kamakarzy

  6. Offline

    Craftiii4

    Have you tried printing out Time to check its value in that sub?
     
  7. Offline

    kamakarzy

    Craftiii4 yes i have it says that Time is giving me 0 but as you can se the config is 108000 im just wondering does int hold that many numbers

    Minnymin3 the int says 0

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

    Craftiii4

    How did you add time to the config file?
     
  9. Offline

    kamakarzy

    Craftiii4 its in the file as soon as it generates
     
  10. Offline

    Craftiii4

    What code?
     
  11. Offline

    kamakarzy

    the config.yml in the project folder

    Code:
    # This is the Default config for Easysave
     
    #Time in seconds default is 108000 seconds
    Time: 108000
     
  12. Offline

    Craftiii4

    hm?

    use getConfig().addDefault("Time",108000);

    nearly forgot: then end with

    getConfig().options().copyDefaults(true);
    saveConfig();

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

    kamakarzy

    Craftiii4 that worked its not spawmming but its not counting either
     
  14. Offline

    Craftiii4

    Print out count when you check every time to see if it's working.
     
  15. Offline

    kamakarzy

    its not
    Code:
    2013-05-07 23:59:14 [INFO] 108000
    2013-05-07 23:59:14 [INFO] 108000
    2013-05-07 23:59:14 [INFO] 108000
    2013-05-07 23:59:15 [INFO] 108000
    2013-05-07 23:59:15 [INFO] 108000
    2013-05-07 23:59:15 [INFO] 108000
    2013-05-07 23:59:16 [INFO] 108000
    2013-05-07 23:59:16 [INFO] 108000
    2013-05-07 23:59:16 [INFO] 108000
    2013-05-07 23:59:17 [INFO] 108000
    2013-05-07 23:59:17 [INFO] 108000
    2013-05-07 23:59:17 [INFO] 108000
    2013-05-07 23:59:18 [INFO] 108000
    2013-05-07 23:59:18 [INFO] 108000
    2013-05-07 23:59:18 [INFO] 108000
    2013-05-07 23:59:19 [INFO] 108000
    2013-05-07 23:59:19 [INFO] 108000
    2013-05-07 23:59:19 [INFO] 108000
    2013-05-07 23:59:20 [INFO] 108000
    2013-05-07 23:59:20 [INFO] 108000
    2013-05-07 23:59:20 [INFO] 108000
    2013-05-07 23:59:21 [INFO] 108000
    2013-05-07 23:59:21 [INFO] 108000
    2013-05-07 23:59:21 [INFO] 108000
    2013-05-07 23:59:22 [INFO] 108000
    2013-05-07 23:59:22 [INFO] 108000
    2013-05-07 23:59:22 [INFO] 108000
     
  16. Offline

    Craftiii4

    If you are trying to make a delay, create a delayed scheduled task? I can't help you more really unless I can see the entire code related to this.

    What purpose is that? Replace the 20L with the ticks you get from time and remove the counter value with the checks as well.

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

    kamakarzy

    Craftiii4 the point of the whole thing is to save the server every 30 mins without any commands or fuss just saves all worlds easy :)
     
  18. Offline

    Craftiii4

    Okay, do the maths :p

    1*60*30*20 = ?
    Replace the 0L, 20L, with ?, ?
    Remove counter and timer (or keep timer to let them choose time)

    Sorry on phone.
     
  19. Offline

    kamakarzy

    Craftiii4 ok so if i wanted to do
    Code:
    int time =    getConfig().getInt("Time");
        int ticks = time*20;
        }
    how would i do this correctly

    Code:
    run.runTaskTimer(this, 0L, long ticks1 = ticks);
    Craftiii4 never mind thanks it was
    Code:
    run.runTaskTimer(this, 0L, Long.valueOf(ticks));
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
Thread Status:
Not open for further replies.

Share This Page