How to make toggle-able commands?

Discussion in 'Plugin Development' started by xMrPoi, Jul 17, 2013.

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

    xMrPoi

    How would I make it so that when a player does something like /status, it says on the first time, then it says off the next. And it remembers which one you are on even over a reload.
     
  2. Offline

    FozZeW

    One way of doing this is making a hashmap that stores String and a Boolean and when player does command it puts player into hashmap and set players value to true if he does command again it checks whats value for that player in hashmap and if true it changes it to false and disables some code or idk
     
  3. Offline

    savagesun

    The guy above me has it right, although you shouldn't store the player, just his/her name. Also if you want your hashmap to persist over a reload or restart you need to save the hashmap somehow, and then load the hashmap back into memory on startup. Try using GSON, it makes serializing data very easy! There is a lot of information on how to save data using GSON, so fire up google!
     
  4. This is half of the answer, and is how I would do it. The second question of how to record the data even after a reload would be to store the boolean values in a database. As you'll only be needing a tiny database, I'd recommend using a Persistence one. There's a tutorial here, and an example of usage by Dinnerbone here.
     
  5. Offline

    Henzz

    xMrPoi
    Use HashSet and store the players name.
    Check if hashset doesn't contain playersname, enable the command feature, if it does disable the command feature. All generic types won't hold the data once the server has restarted/reloaded
     
Thread Status:
Not open for further replies.

Share This Page