Solved Plugin Not Working - Possibly Need Help With Reading Config

Discussion in 'Plugin Development' started by Rocky_990, May 3, 2015.

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

    Rocky_990

    Hello,

    I have currently been making a plugin to give users a simple warning count which moderators can view as well as give and take warnings from a user.
    I have been attempted to store every user's quantity of warnings in 5he config.yml document - and I am wondering if this is why some commands of the plugin (/warn add, /warn remove, /warn view, /warn reload) don't work. If it is this, then how do I fix it? Do I need to check whether the user has had their warnings documented in the config and if not create that line with the warnings set to 0?

    This is the main class:
    http://pastebin.com/unGwpdqs
    and this is the plugin.yml:
    http://pastebin.com/bQE6GNfs

    Thank you and any help/advice is appreciated.
    ~Rocky_990
     
  2. For the add warnings:
    int warns = (getConfig().contains(playerName) ? getConfig.getInt(playerName) : 0) + 1;
    //Set the warns
    For the removing, the same but instead - 1

    And you need to check if the args length is 2 or a ArrayIndexOutOfBoundsException will be thrown
     
    Rocky_990 likes this.
  3. Offline

    Rocky_990

    @FisheyLP
    After just trying that, I'm finding that the second "getConfig cannot be resolved"...

    Thanks for the help so far :)
     
  4. Offline

    SuperOriginal

    Show your updated code
     
  5. Offline

    BrickBoy55

    Don't do "if (args[0] == "<string>) {}", use "if (args[0].equalsIgnoreCase("<string>")) {}".
     
    Rocky_990 likes this.
  6. Offline

    Rocky_990

    @SuperOriginal
    Code:
                if (args[0] == "add") {
                            String playerToAdd = null;
                            args[1] = playerToAdd;
                            String warnToAddStr = "1";
                            args[2] = warnToAddStr;
                            int warnToAdd = Integer.parseInt("warnToAddStr");
                           
                            int warnings = (getConfig().contains(playerToAdd) ? getConfig.getInt(playerToAdd) : 0) + 1;
                            //Set the warns
    
                            int final_warnings = warnings + warnToAdd;
                            this.getConfig().set(playerToAdd, final_warnings);
                            this.saveConfig();
                           
                            player.sendMessage(ChatColor.GRAY + "Added " + warnToAdd + " warnings to: " + playerToAdd + ". New warning count: " + final_warnings);
                           
                            return true;
    @BrickBoy55 will change that in a sec
     
  7. Offline

    meguy26

    @Rocky_990
    Code:
    String playerToAdd = null;
    args[1] = playerToAdd;
    String warnToAddStr = "1";
    args[2] = warnToAddStr;
    Code:
    String playerToRemove = null;
    args[1] = playerToRemove;
    String warnToRemoveStr = "1";
    args[2] = warnToRemoveStr;
    Code:
    String playerToView = null;
    args[1] = playerToView;
    I am not sure how the above could have been missed, none of the lines above will work. For whatever reason, you have inverted the = statements. In all the above examples you are setting args[1] or args[2] to something, rather than setting something to them.

    I think what you are trying to do is:
    Code:
    String playerToRemove = args[0];
    String warnToRemoveStr =  args[1];
    NOTE: Arrays start at 0, so the first argument is actually args[0]
     
Thread Status:
Not open for further replies.

Share This Page