Solved data.yml resetting after command is run.

Discussion in 'Plugin Development' started by dragonzuke, Sep 3, 2015.

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

    dragonzuke

    Hello Bukkit Community!

    I am trying to make a custom punishment system. But the problem is, when I run the info command to check to see if the player has been kicked or not, the file Int's reset. The booleans will stay the same (I know this because the StaffChat is set to true).

    Here is my code:

    Info Command Class: http://pastebin.com/d4p9bMWb
    Settings Class: http://pastebin.com/39jhY23f
    Main Class: http://pastebin.com/wZHUCGuS

    There are no errors in console.

    Thanks for helping!

    _Azor
     
    Last edited: Sep 3, 2015
  2. Can you tell me why the sender must be a player in onCommand? Why shouldn't the console or a commandblock use it?? At least you didn't blindly cast to Player but it's still not perfect :p

    Could you please explain your problem more detailed?
     
  3. Offline

    stormneo7

    Please show your Main.class I also don't see why you need to hide it xD
     
  4. Offline

    dragonzuke

    @FisheyLP I usally only make it a player, because that is what I am used to :p

    But basically when ever I use the /info command, the data.yml file's int's get reset. So for example, when I kick myself, it gives the kicks section a int of 1. But then when I log back into the game and do /info, it reset's to 0.

    Before the Kick: http://prntscr.com/8caph3
    After the Kick: http://prntscr.com/8capsf
    After the Info Command: http://prntscr.com/8caqe9

    EDIT: @stormneo7 I added it.
     
  5. Show the Kick command class
     
  6. Offline

    Oxyorum

    @dragonzuke We need to see the code that gets executed after someone gets kicked from the server.

    @FisheyLP +1 :)
     
  7. Offline

    dragonzuke

  8. Offline

    Oxyorum

    @dragonzuke It doesn't look like there's anything in your code that is actually resetting the int values, at least from what you've shown. I see some other issues with your code, though.

    1) You aren't reloading your configuration after saving to it. As far as I know, saving the configuration only writes the changes you have made to disk (if any), but will do nothing to the copy of your config that is already in memory (the one that is being used to obtain the values for settings.getData().getInt(path), etc). If someone were to run ./info after you were kicked, they would not see the new information. To ensure that the changes you have made are visible in-game after the save, reloadData() method you wrote in your Settings class after you make the save. Someone is free to call me out if the above is incorrect.

    2) You aren't explicitly ensuring that the ./info <player> part of your code runs when only one argument is supplied. The command would still technically work the way your code is written, but having it that way just looks "off" to me. :)

    Also, are you sure that the copy of data.yml you were looking at in the last picture is the latest one? Notepad++ tends to not immediately update files you are looking at after they are changed, and gives you a prompt asking if you want the new information to be shown. This is probably not an issue, but I want to make sure, because I've had things like this happen to me before with Notepad++.
     
  9. Offline

    dragonzuke

    @Oxyorum

    I will try #1 now. I did update the file when it asked me to.

    I have fixed the issue. All I had to do was to reload the data before the messages were sent.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
Thread Status:
Not open for further replies.

Share This Page