Solved Tempbanning Players...

Discussion in 'Plugin Development' started by Astrophylite, Dec 22, 2015.

Thread Status:
Not open for further replies.
  1. Hello everyone!

    I am having a problem with tempbanning players. I have got the command working that converts 1h into milliseconds (example) and adding it all to the database. However, on the onPlayerLogon Event, I have something that unbans the banned player if the time is up. For some reason, it unbans my alt account even though I have set the ban time to 1 year...

    EVENTPlayerLogon: http://pastebin.com/qFXn37kk

    Any help will be appreciated,
    _zircon_.
     
  2. @_zircon_ you should rubbberduck debug the code :)
    You're adding time to current and calling it endOfBan.
    Then you check if endOfBan is bigger than current. Which it will always be, since you added the always positive "time" to it.

    You should probably save the timestamp for when the ban is over in the database. And then compare that to current. For displaying how much time is left, you use current subtracted from time.

    Makes sense?
     
  3. Yes, it does. For how much time is left, I want it to display in # days, # hours, # minutes, # seconds.

    Thanks,
    _zircon_.

    EDIT: Nevermind, I just realised you said "save the timestamp".
     
  4. Did you make the change? If you did and still have issues, post your code and tahg me
     
  5. @BreezerFly
    Could you provide some sample code as to how I would check if the ban is up?

    Thanks,
    _zircon_.

    EDIT: I have added a colum to the database called "endOfBan" which contains the time in milliseconds until the ban is up but even comparing that with the current time (in milliseconds) it removes the entry and lets the player join..
     
    Last edited: Dec 22, 2015
  6. @_zircon_ You have to modify your code that adds the user to the database to save System.currentTimeMillis() + banLengthInMs (or you can convert to seconds, since you don't need ms precision and it's a smaller number). Then you can use that to check against the current system time when the user logs in.

    You have to add currentTime to the one in the database. When you save it. So that you get the timestamp for when the ban is up.
     
    Last edited: Dec 22, 2015
  7. Hmm... I'm trying to convert milliseconds to seconds by multiplying MILLISECONDS by 60000 and it still returns the millisecond value?

    Thanks,
    _zircon_.
     
  8. You have to divide milliseconds by 1000 to get seconds
     
  9. @BreezerFly I thought as much xD

    Okay, I'm still having problems with this. I have updated the code, but I only now realise that SimpleDateFormat only allows dates in the past and today's date and not future dates. Is there any other way I can parse the "endOfBan"?

    Thanks,
    _zircon_.

    (@BreezerFly)

    EDIT: Here is the code: http://pastebin.com/Yr970UgX
    I have set the expiration date to 1 week.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.

    EDIT2: I keep getting this error "java.sql.SQLException: Operation not allowed after ResultSet closed". When I use MySQLHandler.getStatement(), I close the statement then create a new one so I don't know why this is happening...
    CMDTempBan: http://pastebin.com/1Dyv92UW
    EVENTPlayerLogon: http://pastebin.com/5LASKwMG
     
    Last edited: Dec 24, 2015
  10. Offline

    Zombie_Striker

    If it's saying that the thing is closed, most likely you are getting/using the wrong instance. Are you sure you modified the new operation?
     
  11. @Zombie_Striker Don't worry - I kept creating a new connection to the database in every class that used it. I changed it to connect in the onEnable() and close the connection & statement in the onDisable().

    Thanks,
    _zircon_.
     
Thread Status:
Not open for further replies.

Share This Page