Solved Large Cooldowns

Discussion in 'Plugin Development' started by MordorKing78, May 31, 2015.

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

    MordorKing78

    @teej107 Yes, It ain't showing up

    @AdamQpzm Yesyes I know about the milliseconds. How exactly do I convert it into milliseconds times 1000 ?

    <Edited by bwfcwalshy: Merged posts, please use the edit button rather than double posting.>
     
    Last edited by a moderator: Jun 3, 2015
  2. Offline

    Zombie_Striker

    @MordorKing78
    1000 milliseconds is one second (hence the Milli), so you would multiply seconds times 1000 to get milliseconds or you would divide milliseconds by 1000 to get the seconds.
     
  3. Offline

    MordorKing78

    @Zombie_Striker I understand it but I used ticks and I did 20 seconds so 20*20 = 400 Ticks
    Thats 0.4 from a second but then it should still work right? the code..

    Updated Code, So ive added test messages it does not get further then testmessage1

    Code:
                          ConfigurationSection players = player.getConfigurationSection("Players"); //Get all players who are in the file
                        
                          if(players.contains(p.getUniqueId().toString())){ //Checks if the players uuid is in the file
                              Bukkit.broadcastMessage("test1"); //test message
    
                              long groupActivation = player.getLong(players + p.getUniqueId().toString() + ".Time"); //The time the player has joined the group                        
                            
                              String group = player.getString(players + p.getUniqueId().toString() + ".Group"); //Gets the group the player is in
    
                              ConfigurationSection playerGroup = config.getConfigurationSection("Groups." + group); //Gets the group the player is in                        
                              long groupDuration = playerGroup.getLong("Seconds")*1000;
                            
                              Bukkit.broadcastMessage("test2"); //test message
    
                              if(System.currentTimeMillis() - groupActivation >= groupDuration){ //Current Time minus when the player joined the group and check if its more then the given ticks
                              
                                  Bukkit.broadcastMessage("test, You should be able.."); //test message
                                
                              }else{
                                  Bukkit.broadcastMessage("Not yet..!"); //test message
                              }
                          }else{
                              return;
                          }
    This line gives me an error,

    Code:
                              long groupDuration = playerGroup.getLong("Seconds")*1000;
    
    <Edited by bwfcwalshy: Merged posts, please use the edit button rather than double posting.>
     
    Last edited by a moderator: Jun 3, 2015
  4. Offline

    teej107

    A tick is 1/20th of a second. 1/20th of a second is 50ms.
    Errors are actually helpful but just saying there is an error and nothing else gives us no information.
     
    AdamQpzm likes this.
  5. Errors aren't helpful unless we know what they are ;)

    Edit: Sniped :(
     
  6. Offline

    Zombie_Striker

    @MordorKing78
    Is seconds an double or a String instead of a Long? Does the config contain "Seconds"? Is playerGroup null?
     
  7. Offline

    MordorKing78

    @Zombie_Striker This is basicly the group format,
    Code:
    Groups:
      Epic:
        Seconds: 10


    @AdamQpzm @teej107 Eymm,
    Code:
    java.lang.NullPointerException
            at org.m.Plugin.Main.Main$1.run(Main.java:46) ~[?:?]
    ?
     
  8. Offline

    teej107

  9. Offline

    MordorKing78

    @teej107 Well I've found out that this line is the first that returns null, But I can not figure out why..
    Code:
                          String group = player.getString(players + p.getUniqueId().toString() + ".Group"); //Gets the group the player is in
    
     
  10. Offline

    Zombie_Striker

    @MordorKing78
    Is player null? Is the String null?

    BTW, you are getting this from the config:
    CONFIGDATA,NOT A STRING - PLAYERSUUID:
    Groups :
    The String
     
  11. @MordorKing78 player or p being null is the issue that you're having with that line.
     
  12. Offline

    MordorKing78

    @Zombie_Striker @AdamQpzm Well, Yeah. I updated my code again but now the timer doesnt work the message just show up.

    Code:
    ConfigurationSection players = player.getConfigurationSection("Players");
                                              
                          String group = players.getString(p.getUniqueId().toString() + ".Group");
                                              
                          ConfigurationSection playerGroup = config.getConfigurationSection("Groups");                     
    
                          if(players.contains(p.getUniqueId().toString())){
    
                              long groupActivation = players.getLong(p.getUniqueId().toString() + ".Time");                     
                            
                              long groupDuration = playerGroup.getLong(group + ".Seconds")*1000;
                            
                              long a = groupActivation-groupDuration;
    
                            
                              if(groupActivation - groupDuration <= System.currentTimeMillis()){
                                Bukkit.broadcastMessage("test");
                                
                              }else{
    
                            
                              }
                          }
     
  13. Offline

    Zombie_Striker

    @MordorKing78
    Writing code, whether it is for a plugin or any other program, requires a lot of debugging. Try debugging every line like so:
    • System.out.println(group) to see what group is,
    • System.out.println((groupActivation-GroupDuration)) to see the time.
    • System.out.printnln("If Statement 1/2 is working") after each if statement means that it is true.)
     
  14. Offline

    MordorKing78

    Thanks everyone for the help! I figured it out!
     
Thread Status:
Not open for further replies.

Share This Page