remove something from config??

Discussion in 'Plugin Help/Development/Requests' started by Bowser_Jr, Jan 29, 2015.

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

    Bowser_Jr

    Hello, I have a void for setting up and adding them to config, but I also need to remove them for a "/marry divorce" command.
    this is my void for SettingUpConfiguration

    Code:
    public void setConfiguration(Player sender, Player receiver) {
            marriageConfig.set("marriages." + sender.getUniqueId().toString() + ".Name", sender.getName());
            marriageConfig.set("marriages." + sender.getUniqueId().toString() + ".Married To", receiver.getName());
          
            marriageConfig.set("marriages." + receiver.getUniqueId().toString() + ".Name", receiver.getName());
            marriageConfig.set("marriages." + receiver.getUniqueId().toString() + ".Married To", sender.getName());
        }
    But how do I remove them from the config if they do /divorce ??????
     
  2. Offline

    Experminator

    @Bowser_Jr Easy: set the value to null. And it would be removed.

    @Bowser_Jr Bytheway: It's not Browser_Jr?
     
    Last edited by a moderator: Jan 29, 2015
  3. Offline

    Bowser_Jr

    @Experminator
    How do I set it to null and no, It's Bowser xD Browser is the search engine or whatever it's called.

    Read the MARIO FAQ XDDD
     
  4. Offline

    Konato_K

    @Bowser_Jr It's Koopa

    Code:
    // Erasing a value
    this.getConfig().set("path.to.value", null);
     
  5. Offline

    Bowser_Jr

    @Konato_K
    Like this?
    Code:
    marriageConfig.set(sender.getName(), null);
            marriageConfig.set(receiver.getName(), null);
     
  6. Offline

    Konato_K

    @Bowser_Jr I don't know the structure of your YAML file, but checking the above code it should be something like this
    Code:
     "marriages." + sender.getUniqueId().toString()
    But again, I don't know the structure of your YAML
     
  7. Offline

    Bowser_Jr

    @Konato_K
    This is my config voids
    Code:
    public void setConfiguration(Player sender, Player receiver) {
            marriageConfig.set("marriages." + sender.getUniqueId().toString() + ".Name", sender.getName());
            marriageConfig.set("marriages." + sender.getUniqueId().toString() + ".Married To", receiver.getName());
          
            marriageConfig.set("marriages." + receiver.getUniqueId().toString() + ".Name", receiver.getName());
            marriageConfig.set("marriages." + receiver.getUniqueId().toString() + ".Married To", sender.getName());
        }
       
        public void removeConfiguration(Player sender, Player receiver) {
            marriageConfig.set("marriages." + sender.getUniqueId().toString(), null);
            marriageConfig.set("marriages." + receiver.getUniqueId().toString(), null);
        }
    And this is my config:

    Code:
    ## MESSAGES ##
    # THis plugin is made for PrisonMine. Don't try to copy it!
    INVALID_SENDER: '&cInvalid sender. This command can only be performed by a player.'
    NO_PERMISSION: '&cYou do not have permission to execute this command.'
    NO_MARRIED_COUPLES: '&cThere are currently no married couples on the server.'
    REQUEST_CANCELLATION_FAILURE: '&cYou do not have any marriage request to cancel.'
    SUCCESSFUL_CANCELLATION: '&7You have successfully cancelled your marriage request.'
    ALREADY_MARRIED: '&cYou are already married to another player.'
    ALREADY_SENT_REQUEST: '&cYou must cancel your marriage request first before sending another: ./marry cancel.'
    PLAYER_OFFLINE: '&cThe specified player is currently offline.'
    PLAYER_ALREADY_MARRIED: '&cThis player is already married to another player.'
    NO_RECEIVED_REQUEST: '&cThis player has not sent you a marriage request.'
    SUCCESSFUL_REQUEST: '&7You have sent a marriage request to &c{receiver}&7.'
    RECEIVED_REQUEST: '&7You have received a marriage request from &c{sender}&7. Type in &c./marry <accept | deny> <name> &7to accept or deny this request.'
    SENDER_DENIED: '&c{receiver} &7has denied your marriage request.'
    RECEIVER_DENIED: '&7You have successfully denied the marriage request from &c{sender}&7.'
    SENDER_ACCEPT: '&c{receiver} &7has accepted your marriage request.'
    RECEIVER_ACCEPT: '&7You have successfully married &c{sender}&7.'
    command-list:
    
    - '&7/Marry {Name} &8: &7Requests player to marry them'
    - '&7/Marry accept {Name} &8: &7accepts marriage'
    - '&7/Marry deny {Name} &8: &7Deny marriage'
    - '&7/Marry list &8: &7Lists all married players'
    - '&7/Marry cancel &8: &7Cancel the current request'
    - '&7/Marry divorce &8: &7divorce'
    
    And this is my marriages.yml
    Code:
    marriages:
    @Konato_K
    Sorry for double posting, but is the code I just posted done correct?
     
    Last edited by a moderator: Jan 29, 2015
  8. Offline

    Skionz

    @Bowser_Jr They are called methods, not voids. Void is the return type.
    As for the issue, you never actually save the YAML file after modifying it.
     
  9. Offline

    bwfcwalshy Retired Staff

    @Bowser_Jr You can tap the magical edit button to add to your post ;)

    As Skionz said, you never save it in them methods. Set marriages. UniqueId.toString to null.
     
  10. Offline

    Bowser_Jr

    @bwfcwalshy @Skionz
    I do have a method to save the config:
    Code:
    public static void saveConfiguration() {
            try { Marriage.marriageConfig.save(Marriage.marriageFile); }
            catch (IOException e) {
                e.printStackTrace();
            }
        }
    So did I do it right or wrong? my english isn't the best. Sorry :(
     
  11. Offline

    Skionz

  12. Offline

    Bowser_Jr

    @Skionz
    Please someone I need this awnser very Fast :I
    I get this error in my consol:
    Code:
    [07:23:38 INFO]: BeastCraft3 issued server command: /marry divorce
    [07:23:38 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'marr
    y' in plugin PrisonMarriage v1.3
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[cra
    ftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
    1) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServe
    r.java:767) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand(PlayerCon
    nection.java:1043) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java
    :880) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java
    :28) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle(PacketPlayInChat
    .java:65) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:186
    ) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java
    :81) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:7
    34) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:2
    89) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:5
    84) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java
    :490) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:6
    28) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
    Caused by: java.lang.NullPointerException
            at me.DrBeast.PrisonMarriage.MarriageExecutor.Divorce(MarriageExecutor.j
    ava:179) ~[?:?]
            at me.DrBeast.PrisonMarriage.MarriageExecutor.onCommand(MarriageExecutor
    .java:75) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[cra
    ftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            ... 13 more
    Here is my divorce command:
    Code:
    if(args[0].equalsIgnoreCase("divorce")) {
                   
                    if(!marriageConfig.contains("marriages." + player.getUniqueId().toString())) {
                        player.sendMessage(color(plugin.getConfig().getString("YOUR_NOT_MARRIED")));
                        return true;
                    }
                   
                    Player user = Bukkit.getPlayer(args[0]);
                    if(user != null) {
                        player.sendMessage("PLAYER_OFFLINE");
                        return true;
                    }
                   
                    Divorce(player, user);
                    return true;
                }
    Here is my Divorce method:
    Code:
    public void Divorce(Player sender, Player receiver) {
            sender.sendMessage(color(plugin.getConfig().getString("SENDER_DIVORCE").replace("{receiver}", receiver.getName())));
            receiver.sendMessage(color(plugin.getConfig().getString("RECEIVER_DIVORCE").replace("{sender}", sender.getName())));
                   
           
            removeConfiguration(sender, receiver);
            saveConfiguration();
        }
    This is my removeConfiguration method:

    Code:
    public void removeConfiguration(Player sender, Player receiver) {
            marriageConfig.set("marriages." + sender.getUniqueId().toString(), null);
            marriageConfig.set("marriages." + receiver.getUniqueId().toString(), null);
        }

    PLease help me quick!
     
  13. Offline

    nverdier

    @Bowser_Jr
    Invoke means to call the method, if you needed clarification on it. Why are you saying "please help me quick" if Skionz possibly already delved this for you?
     
  14. Offline

    mrCookieSlime Retired Staff

    Moved to Alternatives Section.
     
  15. Offline

    Bowser_Jr

    @nverdier
    no I must have done something wrong in the code, since I get the international error message when I do /marry divorce
    and I honestly don't now whats wrong. And I really reallly neeed help with it quickly
     
  16. Offline

    nverdier

    @Bowser_Jr What is on line 179 in class 'MarriageExecutor'?
     
  17. Offline

    Bowser_Jr

    @nverdier
    sorry I've been on a short vecation.
    line 179 is nothing, It's a space betwen two methods.
     
  18. Offline

    nverdier

    @Bowser_Jr You sure about that? Please recompile and then post the error as of now.
     
  19. Offline

    Bowser_Jr

  20. Offline

    nverdier

    @Bowser_Jr You updated your code since the error was posted, yes? Recompile, and paste the new error.
     
  21. Offline

    Bowser_Jr

    @nverdier
    I get this error now when I type anything that was todo with /marry
    Code:
            at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlCo
    nfiguration.java:57) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:209) [
    craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:157) [cra
    ftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at me.DrBeast.PrisonMarriage.MarriageExecutor.onCommand(MarriageExecutor
    .java:69) [PrisonMarriage.jar:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) [craf
    tbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
    1) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServe
    r.java:767) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand(PlayerCon
    nection.java:1043) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java
    :880) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java
    :28) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle(PacketPlayInChat
    .java:65) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:186
    ) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java
    :81) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:7
    34) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:2
    89) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:5
    84) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java
    :490) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:6
    28) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
    Caused by: org.yaml.snakeyaml.scanner.ScannerException: while scanning a simple
    key; could not found expected ':';  in 'string', line 27, column 1:
        command-list:
        ^
            at org.yaml.snakeyaml.scanner.ScannerImpl.stalePossibleSimpleKeys(Scanne
    rImpl.java:465) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at org.yaml.snakeyaml.scanner.ScannerImpl.needMoreTokens(ScannerImpl.jav
    a:280) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:22
    5) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingKey.produce(Par
    serImpl.java:558) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158) ~
    [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:143)
    ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java
    :230) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:159) ~
    [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:12
    2) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:105)
    ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseCons
    tructor.java:120) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:481) ~[craftbukkit.j
    ar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at org.yaml.snakeyaml.Yaml.load(Yaml.java:400) ~[craftbukkit.jar:git-Spi
    got-1.7.9-R0.2-205-g48578ee]
            at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlCo
    nfiguration.java:55) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            ... 17 more
    >
     
  22. Offline

    nverdier

    @Bowser_Jr Well now it's a problem with YAML formatting. Run it though a parser and fix all of the problems.
     
  23. Offline

    Bowser_Jr

    @nverdier
    lol, I forgot to add the ":" after a string in my config.

    Now to the divorce situasion...
    No error comes up but their still married. this is my code that includes the divorce:
    Code:
    public void Divorce(Player sender, Player receiver) {
            sender.sendMessage(color(plugin.getConfig().getString("SENDER_DIVORCE").replace("{receiver}", receiver.getName())));
            receiver.sendMessage(color(plugin.getConfig().getString("RECEIVER_DIVORCE").replace("{sender}", sender.getName())));
                   
           
            removeConfiguration(sender, receiver);
            saveConfiguration();
        }

    Code:
    public void removeConfiguration(Player sender, Player receiver) {
            marriageConfig.set("marriages." + sender.getUniqueId().toString(), null);
            marriageConfig.set("marriages." + receiver.getUniqueId().toString(), null);
        }
    Code:
    if(args[0].equalsIgnoreCase("divorce")) {
                   
                    if(!marriageConfig.contains("marriages." + player.getUniqueId().toString())) {
                        player.sendMessage(color(plugin.getConfig().getString("YOUR_NOT_MARRIED")));
                        return true;
                    }
                   
                    Player user = Bukkit.getPlayer(args[0]);
                    if(user != null) {
                        player.sendMessage("PLAYER_OFFLINE");
                        return true;
                    }
                   
                    Divorce(player, user);
                    return true;
                }
     
  24. Offline

    nverdier

  25. Offline

    Bowser_Jr

    @nverdier
    as I said. No error. Just doesn't work
     
  26. Offline

    nverdier

    @Bowser_Jr Hmmm. Try debugging and making sure methods are called, etc.
     
  27. Offline

    Bowser_Jr

    @nverdier
    hmm I just tested it again with one debug message in the divorce command and now this error came up
    Code:
    [21:12:29 INFO]: BeastCraft3 issued server command: /marry divorce
    [21:12:29 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'marr
    y' in plugin PrisonMarriage v1.3
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[cra
    ftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
    1) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServe
    r.java:767) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand(PlayerCon
    nection.java:1043) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java
    :880) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java
    :28) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle(PacketPlayInChat
    .java:65) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:186
    ) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java
    :81) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:7
    34) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:2
    89) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:5
    84) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java
    :490) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:6
    28) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
    Caused by: java.lang.NullPointerException
            at me.DrBeast.PrisonMarriage.MarriageExecutor.Divorce(MarriageExecutor.j
    ava:189) ~[?:?]
            at me.DrBeast.PrisonMarriage.MarriageExecutor.onCommand(MarriageExecutor
    .java:80) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[cra
    ftbukkit.jar:git-Spigot-1.7.9-R0.2-205-g48578ee]
            ... 13 more
    >
     
  28. Offline

    nverdier

    @Bowser_Jr That's gold in my eyes.
    Now what's on line 189 of MarriageExecutor?
     
  29. Offline

    Bowser_Jr

    @nverdier
    Code:
    sender.sendMessage(color(plugin.getConfig().getString("SENDER_DIVORCE").replace("{receiver}", receiver.getName()))); 
    And this is line 80:
    Code:
    Divorce(player, user);
     
  30. Offline

    nverdier

    @Bowser_Jr Something in there has a null value. Debug, and test all of the values on that line. Once you find what's null, make it not-null!
     
Thread Status:
Not open for further replies.

Share This Page