Solved Creating of config file not working :(

Discussion in 'Bukkit Help' started by unrealdesign, Mar 20, 2013.

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

    unrealdesign

    So it's been 2 days now and I've finally given up on how to create a config file. It's really bothering me and it is crucial for further plugin development. If you could help, that would be AMAZING!

    Code:
    Code:
    this.plugin.addPlayerBounty(args[1], args[2]);
     
    /*
    *  What I use to set to the config after a player types something for args[1] and args[2]
    */
    Main class:
    Code:
    private HashMap<String, String> playerBounty;
     
        public void addPlayerBounty(final String newBounty, final String newPrice){
            this.playerBounty.put(newBounty, newPrice);
            this.getConfig().set("bounties."+newBounty, newPrice);
            this.saveConfig();
        }

    I have no idea what my problem is and I've created main test plugins just to fix this, but I can't seem to get around it. I've thought through logically how it would work, and it works in my head? Where am I going wrong, and all advice/ideas are welcome! :D

    Thanks!
     
  2. Offline

    LandonTheGeek

    What you need to do is create a .yml file (like plugin.yml) and then in your code type,
    Code:
        getConfig().options().copyDefaults(true);
        saveConfig();
    There you go!
     
  3. Offline

    unrealdesign

    xXTh3B3astXxify

    I did that and it didn't work earlier, and I just did it now and it didn't work:/

    I put it in the onLoad(), should I put it somewhere else?
     
  4. Offline

    LandonTheGeek

  5. Offline

    unrealdesign

    xXTh3B3astXxify

    I know something is obviously wrong, but I can't find it either. Here is everything that should be involved with this besides the implementation the vault crap.

    Please note: Everything works 100% fine without me putting in the creation of the config.

    Main Class:
    Code:
        private HashMap<String, String> playerBounty;
     
        public void addPlayerBounty(final String newBounty, final String newPrice){
            this.playerBounty.put(newBounty, newPrice);
            this.getConfig().set("bounties."+newBounty, newPrice);
            //this.getConfig().set("bounties.djoutbased", "10");
            this.saveConfig();
        }
     
     
        public void onLoad() {
            //this.saveDefaultConfig();
            this.getConfig().options().copyDefaults(true);
            this.saveConfig();
        }
     
        public void onEnable() {
            getLogger().info("has been enabled.");
            CommandController.registerCommands(this, new Bounty(this));
            if (!setupEconomy() ) {
                log.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
                getServer().getPluginManager().disablePlugin(this);
                return;
            }
            setupPermissions();
            setupChat();
       
            getServer().getPluginManager().registerEvents(this, this);
            if (!new File(getDataFolder(), "config.yml").exists()) {
                saveDefaultConfig();
          }
        }
        
    CommandClass:
    Code:
       
    private final FZBounty plugin;
     
    public Bounty(final FZBounty plugin) {
            this.plugin = plugin;
        }
     
    @SubCommandHandler(parent = "bounty", name = "set")
        public void bountySetCommand(Player player, String[] args){
            Player[] OnlinePlayers = Bukkit.getOnlinePlayers();
            double money = Double.valueOf(args[2]).doubleValue();
            Player target = player.getServer().getPlayer(args[1]);
            if(args.length == 3) {
                EconomyResponse r = econ.bankWithdraw(player.getName(), money);
                if(r.transactionSuccess()) {
                    player.sendMessage(String.format(ChatColor.GOLD+"[Bounty] "+ChatColor.WHITE+"%s "+ChatColor.YELLOW+"has been taken from your account and now have"+ChatColor.WHITE+" %s"+ChatColor.YELLOW+".", econ.format(r.amount), econ.format(r.balance)));
                    for( Player player1 : OnlinePlayers ){
                        player1.sendMessage(ChatColor.GOLD+"[Bounty] "+ChatColor.YELLOW+"A bounty has been set on "+ChatColor.WHITE+target.getDisplayName()+ChatColor.YELLOW+" for "+ChatColor.WHITE+"$"+money+ChatColor.YELLOW+".");
                    }
                    this.plugin.addPlayerBounty(args[1], args[2]);
                    //this.plugin.addPlayerBounty(args[1], args[2]);
                }
            } else if(args.length != 3){
                player.sendMessage(ChatColor.GOLD+"/bounty set <player> <amount>");
            }
        }
    I'll also add, it's caused by a NullPointerException. I enter a String value, then a double value. I use the Double.valueOf() to change the args[2] to a double, and then use it for economy. I've tried using HashMap with String and Double values, but that doesn't work either

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

Share This Page