My Config is deleting strings/paths? Help?

Discussion in 'Plugin Development' started by OhYes, Mar 2, 2016.

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

    OhYes

    Hi, so i've posted quite a lot in the past with errors I'm getting. And today's error is with my config. I'm trying to make sort of like a anti-xray plugin where you can only mine so much, then have to wait for a cooldown before mining again. Only thing is, when I was testing this, and mining diamond ore, the /ml check Oh_Yes command was still coming up as 0. When I further investigated. I noticed that my config file, was not saving the same as the one in the plugin.

    Code:
    package me.OhYes.minelimit;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener{
       
       
        @Override
        public void onEnable(){
            Bukkit.getPluginManager().registerEvents(this, this);
            saveConfig();
            this.getConfig().options().copyDefaults();
        }
        @Override
        public void onDisable(){
            saveConfig();
        }
    
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            if(!(sender instanceof Player)){
                sender.sendMessage("You can't do that.");
            }else{
                Player p = (Player) sender;
                if(commandLabel.equalsIgnoreCase("ml")){
                    if(p.hasPermission("ml.commands")){
                    if(args.length == 0 || args.length == 1){
                        p.sendMessage(ChatColor.LIGHT_PURPLE + "- OFFICIAL TAKASA -");
                        p.sendMessage(ChatColor.AQUA + "/ml check <player> (Checks a player's Mine Score)");
                        p.sendMessage(ChatColor.AQUA + "/ml set <player> <amount> (Sets a player's Mine Score to an amount)");
                    }else if(args.length == 2){
                        if(args[0].equalsIgnoreCase("check")){
                            try{
                                @SuppressWarnings("deprecation")
                                Player t = Bukkit.getServer().getPlayer(args[1]);
                                p.sendMessage(ChatColor.AQUA + t.getName() + ": " + ChatColor.LIGHT_PURPLE + getConfig().getInt("Players." + t.getName()));
                            }catch(Exception e){
                                p.sendMessage(ChatColor.RED + "An unknown error occured.");
                                return false;
                            }
                        }
                    }else if(args.length == 3){
                        if(args[0].equalsIgnoreCase("set")){
                            try{
                                @SuppressWarnings("deprecation")
                                Player t = Bukkit.getServer().getPlayer(args[1]);
                                int amount = Integer.parseInt(args[2]);
                               
                                getConfig().set("Players." + t.getName(), amount);
                                p.sendMessage(ChatColor.GREEN + "MineScore updated.");
                            }catch(Exception e){
                                p.sendMessage(ChatColor.RED + "An unknown error occured.");
                                return false;
                            }
                        }
                    }else{
                        p.sendMessage(ChatColor.LIGHT_PURPLE + "- OFFICIAL TAKASA -");
                        p.sendMessage(ChatColor.AQUA + "/ml check <player> (Checks a player's Mine Score)");
                        p.sendMessage(ChatColor.AQUA + "/ml set <player> <amount> (Sets a player's Mine Score to an amount)");
                        return false;
                    }
                }else{
                    p.sendMessage(ChatColor.RED + "Only users with the permission can use commands for MineLimit.");
                }
            }
           
           
        }
            return false;
      }
       
        @EventHandler
        public void onBlockBreak(BlockBreakEvent e) {
            Player p = e.getPlayer();
            Block bl = e.getBlock();
            if (!(bl.getType().equals(Material.DIAMOND_ORE) && !(bl.getType().equals(Material.GOLD_ORE)
                    && !(bl.getType().equals(Material.REDSTONE_ORE) && !(bl.getType().equals(Material.IRON_ORE))))))
                return;
           
            if(getConfig().getInt("Players." + p.getName())>=getConfig().getInt("Limit")){
                p.sendMessage(ChatColor.RED + "You are at your Mine-Limit. Please wait before mining valubles again.");
                e.setCancelled(true);
                for(Player ops : Bukkit.getServer().getOnlinePlayers()){
                    if(ops.isOp()){
                        ops.sendMessage(ChatColor.DARK_RED + p.getName() + ChatColor.RED + " just tried to bypass the MineLimit. Could be suspicious.");
                    }else{
                        return;
                    }
                }
            }else{
                if(bl.getType().equals(Material.DIAMOND_ORE)){
                    getConfig().set("Players." + p.getName(), getConfig().getInt("Players." + p.getName() + 250));
                    if(getConfig().getInt("Players." + p.getName()) > getConfig().getInt("Limit")){
                        getConfig().set("Players." + p.getName(), getConfig().getInt("Limit"));
                    }
                }else if(bl.getType().equals(Material.GOLD_ORE)){
                    getConfig().set("Players." + p.getName(), getConfig().getInt("Players." + p.getName() + 200));
                    if(getConfig().getInt("Players." + p.getName()) > getConfig().getInt("Limit")){
                        getConfig().set("Players." + p.getName(), getConfig().getInt("Limit"));
                    }
                }else if(bl.getType().equals(Material.REDSTONE_ORE)){
                    getConfig().set("Players." + p.getName(), getConfig().getInt("Players." + p.getName() + 100));
                    if(getConfig().getInt("Players." + p.getName()) > getConfig().getInt("Limit")){
                        getConfig().set("Players." + p.getName(), getConfig().getInt("Limit"));
                    }
                }else if(bl.getType().equals(Material.IRON_ORE)){
                    getConfig().set("Players." + p.getName(), getConfig().getInt("Players." + p.getName() + 50));
                    if(getConfig().getInt("Players." + p.getName()) > getConfig().getInt("Limit")){
                        getConfig().set("Players." + p.getName(), getConfig().getInt("Limit"));
                    }
                }
            }
        }
       
    }
    
    Original Config:
    Code:
    # --- MineLimit Config ---
    # Here you can check a player's "mine score" it will increase whenever they mine valubles.
    # If it gets to a certain limit, they will not be able to mine valubles until it lowers.
    Default: 0
    #
    Limit: 1500
    #
    Players:
      Oh_Yes: 0
    What's showing up in my plugins folder:
    Code:
    # --- MineLimit Config ---
    # Here you can check a player's "mine score" it will increase whenever they mine valubles.
    # If it gets to a certain limit, they will not be able to mine valubles until it lowers.
    Players:
      Oh_Yes: 0
    P.S. I'm wondering if it would be easier to: rather than setting the player's mine score to the limit. To let it bypass the limit, until it cools down over time. Like -1 minescore every 5s or something.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Mar 2, 2016
  2. Offline

    wesley27

    @OhYes Swap lines 21 and 22. The reason your full config isn't loading in your server is because you're saving the config file before you load its default values.

    The only reason Player.oh_no shows up in the file is because your onBlockBreak method creates it if it doesn't exist. If your onBlockBreak didn't set that value, your config would be completely empty because you saved it before loading the default values.
     
  3. Offline

    OhYes

    Idk, I did what you said and added a OnJoin method to add them to the config, but still doesn't work.
    Code:
    # --- MineLimit Config ---
    # Here you can check a player's "mine score" it will increase whenever they mine valubles.
    # If it gets to a certain limit, they will not be able to mine valubles until it lowers.
    Players:
      Oh_Yes: 0
      Mattw0x: 0
    
    Still getting just the names and no Limit: or Default: ??
     
  4. Offline

    wesley27

    @OhYes Try saveDefaultConfig() in your onEnable instead of saveConfig()
     
  5. Offline

    OhYes

    Code:
    package me.OhYes.minelimit;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener {
    
        @Override
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents(this, this);
            saveDefaultConfig();
        }
    
        @Override
        public void onDisable() {
        }
    
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if (!(sender instanceof Player)) {
                sender.sendMessage("You can't do that.");
            } else {
                Player p = (Player) sender;
                if (commandLabel.equalsIgnoreCase("ml")) {
                    if (p.hasPermission("ml.commands")) {
                        if (args.length == 0 || args.length == 1) {
                            p.sendMessage(ChatColor.LIGHT_PURPLE + "- OFFICIAL TAKASA -");
                            p.sendMessage(ChatColor.AQUA + "/ml check <player> (Checks a player's Mine Score)");
                            p.sendMessage(
                                    ChatColor.AQUA + "/ml set <player> <amount> (Sets a player's Mine Score to an amount)");
                        } else if (args.length == 2) {
                            if (args[0].equalsIgnoreCase("check")) {
                                try {
                                    @SuppressWarnings("deprecation")
                                    Player t = Bukkit.getServer().getPlayer(args[1]);
                                    p.sendMessage(ChatColor.AQUA + t.getName() + ": " + ChatColor.LIGHT_PURPLE
                                            + getConfig().getInt("Players." + t.getName()));
                                } catch (Exception e) {
                                    p.sendMessage(ChatColor.RED + "An unknown error occured.");
                                    return false;
                                }
                            }
                        } else if (args.length == 3) {
                            if (args[0].equalsIgnoreCase("set")) {
                                try {
                                    @SuppressWarnings("deprecation")
                                    Player t = Bukkit.getServer().getPlayer(args[1]);
                                    int amount = Integer.parseInt(args[2]);
    
                                    getConfig().set("Players." + t.getName(), amount);
                                    p.sendMessage(ChatColor.GREEN + "MineScore updated.");
                                } catch (Exception e) {
                                    p.sendMessage(ChatColor.RED + "An unknown error occured.");
                                    return false;
                                }
                            }
                        } else {
                            p.sendMessage(ChatColor.LIGHT_PURPLE + "- OFFICIAL TAKASA -");
                            p.sendMessage(ChatColor.AQUA + "/ml check <player> (Checks a player's Mine Score)");
                            p.sendMessage(
                                    ChatColor.AQUA + "/ml set <player> <amount> (Sets a player's Mine Score to an amount)");
                            return false;
                        }
                    } else {
                        p.sendMessage(ChatColor.RED + "Only users with the permission can use commands for MineLimit.");
                    }
                }
    
            }
            return false;
        }
    
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            if (!(getConfig().contains("Players." + p.getName()))) {
                getConfig().createSection("Players." + p.getName()).set("Players." + p.getName(),
                        getConfig().getInt("Default"));
                ;
            } else {
                return;
            }
        }
    
        @EventHandler
        public void onBlockBreak(BlockBreakEvent e) {
            Player p = e.getPlayer();
            Block bl = e.getBlock();
            if (!(bl.getType().equals(Material.DIAMOND_ORE) && !(bl.getType().equals(Material.GOLD_ORE)
                    && !(bl.getType().equals(Material.REDSTONE_ORE) && !(bl.getType().equals(Material.IRON_ORE))
                            && !(bl.getType().equals(Material.LAPIS_ORE)) && !(bl.getType().equals(Material.EMERALD_ORE))
                            && !(bl.getType().equals(Material.QUARTZ_ORE)) && !(bl.getType().equals(Material.COAL_ORE))))))
                return;
    
            if (getConfig().getInt("Players." + p.getName()) >= getConfig().getInt("Limit")) {
    
                if (getConfig().getBoolean("Warning") == true) {
                    p.sendMessage(ChatColor.RED + "You are at your Mine-Limit. Please wait before mining valubles again.");
                    }
                e.setCancelled(true);
                for (Player ops : Bukkit.getServer().getOnlinePlayers()) {
                    if (ops.isOp()) {
                        ops.sendMessage(ChatColor.DARK_RED + p.getName() + ChatColor.RED
                                + " just tried to bypass the MineLimit. Could be suspicious.");
                    } else {
                        return;
                    }
                   
                }
               
                } else {
                    if (bl.getType().equals(Material.DIAMOND_ORE) && getConfig().getBoolean("Ores.Diamond") == true) {
                        getConfig().set("Players." + p.getName(),
                                getConfig().getInt("Players." + p.getName() + getConfig().getInt("Ores.Diamond.add")));
                        if (getConfig().getInt("Players." + p.getName()) > getConfig().getInt("Limit")) {
                            getConfig().set("Players." + p.getName(), getConfig().getInt("Limit"));
                        }
                    } else if (bl.getType().equals(Material.GOLD_ORE) && getConfig().getBoolean("Ores.Gold") == true) {
                        getConfig().set("Players." + p.getName(),
                                getConfig().getInt("Players." + p.getName() + getConfig().getInt("Ores.Gold.add")));
                        if (getConfig().getInt("Players." + p.getName()) > getConfig().getInt("Limit")) {
                            getConfig().set("Players." + p.getName(), getConfig().getInt("Limit"));
                        }
                    } else if (bl.getType().equals(Material.REDSTONE_ORE)
                            && getConfig().getBoolean("Ores.Redstone") == true) {
                        getConfig().set("Players." + p.getName(),
                                getConfig().getInt("Players." + p.getName() + getConfig().getInt("Ores.Redstone.add")));
                        if (getConfig().getInt("Players." + p.getName()) > getConfig().getInt("Limit")) {
                            getConfig().set("Players." + p.getName(), getConfig().getInt("Limit"));
                        }
                    } else if (bl.getType().equals(Material.IRON_ORE) && getConfig().getBoolean("Ores.Iron") == true) {
                        getConfig().set("Players." + p.getName(),
                                getConfig().getInt("Players." + p.getName() + getConfig().getInt("Ores.Iron.add")));
                        if (getConfig().getInt("Players." + p.getName()) > getConfig().getInt("Limit")) {
                            getConfig().set("Players." + p.getName(), getConfig().getInt("Limit"));
                        }
                    } else if (bl.getType().equals(Material.COAL_ORE) && getConfig().getBoolean("Ores.Coal") == true) {
                        getConfig().set("Players." + p.getName(),
                                getConfig().getInt("Players." + p.getName() + getConfig().getInt("Ores.Coal.add")));
                        if (getConfig().getInt("Players." + p.getName()) > getConfig().getInt("Limit")) {
                            getConfig().set("Players." + p.getName(), getConfig().getInt("Limit"));
                        }
                    } else if (bl.getType().equals(Material.EMERALD_ORE)
                            && getConfig().getBoolean("Ores.Emerald") == true) {
                        getConfig().set("Players." + p.getName(),
                                getConfig().getInt("Players." + p.getName() + getConfig().getInt("Ores.Emerald.add")));
                        if (getConfig().getInt("Players." + p.getName()) > getConfig().getInt("Limit")) {
                            getConfig().set("Players." + p.getName(), getConfig().getInt("Limit"));
                        }
                    } else if (bl.getType().equals(Material.LAPIS_ORE) && getConfig().getBoolean("Ores.Lapis") == true) {
                        getConfig().set("Players." + p.getName(),
                                getConfig().getInt("Players." + p.getName() + getConfig().getInt("Ores.Lapis.add")));
                        if (getConfig().getInt("Players." + p.getName()) > getConfig().getInt("Limit")) {
                            getConfig().set("Players." + p.getName(), getConfig().getInt("Limit"));
                        }
                    } else if (bl.getType().equals(Material.QUARTZ_ORE) && getConfig().getBoolean("Ores.Quartz") == true) {
                        getConfig().set("Players." + p.getName(),
                                getConfig().getInt("Players." + p.getName() + getConfig().getInt("Ores.Quartz.add")));
                        if (getConfig().getInt("Players." + p.getName()) > getConfig().getInt("Limit")) {
                            getConfig().set("Players." + p.getName(), getConfig().getInt("Limit"));
                        }
                    }
                }
            }
        }
    
    
    Urrm ok hold on. Hm, so it fixed the config loading. But it's still not adding MineScore when I mine ores.
    Here's the code now:
    Do I need to saveConfig() after every time I mine ores?

    EDIT: Ugh.. I did a bunch of tinkering, whenever I reload all of the scores reset, so saveDefaultConfig() won't work :/ Also, now even if my score is 0, I still can't mine diamond. And ONLY diamond, I can't mine... This is very strange...
    Code:
    Code:
    package me.OhYes.minelimit;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener {
    
        @Override
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents(this, this);
            saveDefaultConfig();
        }
    
        @Override
        public void onDisable() {
        }
    
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if (!(sender instanceof Player)) {
                sender.sendMessage("You can't do that.");
            } else {
                Player p = (Player) sender;
                if (commandLabel.equalsIgnoreCase("ml")) {
                    if (p.hasPermission("ml.commands")) {
                        if (args.length == 0 || args.length == 1) {
                            p.sendMessage(ChatColor.LIGHT_PURPLE + "- OFFICIAL TAKASA -");
                            p.sendMessage(ChatColor.AQUA + "/ml check <player> (Checks a player's Mine Score)");
                            p.sendMessage(
                                    ChatColor.AQUA + "/ml set <player> <amount> (Sets a player's Mine Score to an amount)");
                        } else if (args.length == 2) {
                            if (args[0].equalsIgnoreCase("check")) {
                                try {
                                    @SuppressWarnings("deprecation")
                                    Player t = Bukkit.getServer().getPlayer(args[1]);
                                    p.sendMessage(ChatColor.AQUA + t.getName() + ": " + ChatColor.LIGHT_PURPLE
                                            + getConfig().getInt("Players." + t.getName()));
                                } catch (Exception e) {
                                    p.sendMessage(ChatColor.RED + "An unknown error occured.");
                                    return false;
                                }
                            }
                        } else if (args.length == 3) {
                            if (args[0].equalsIgnoreCase("set")) {
                                try {
                                    @SuppressWarnings("deprecation")
                                    Player t = Bukkit.getServer().getPlayer(args[1]);
                                    int amount = Integer.parseInt(args[2]);
    
                                    getConfig().set("Players." + t.getName(), amount);
                                    p.sendMessage(ChatColor.GREEN + "MineScore updated.");
                                } catch (Exception e) {
                                    p.sendMessage(ChatColor.RED + "An unknown error occured.");
                                    return false;
                                }
                            }
                        } else {
                            p.sendMessage(ChatColor.LIGHT_PURPLE + "- OFFICIAL TAKASA -");
                            p.sendMessage(ChatColor.AQUA + "/ml check <player> (Checks a player's Mine Score)");
                            p.sendMessage(
                                    ChatColor.AQUA + "/ml set <player> <amount> (Sets a player's Mine Score to an amount)");
                            return false;
                        }
                    } else {
                        p.sendMessage(ChatColor.RED + "Only users with the permission can use commands for MineLimit.");
                    }
                }
    
            }
            return false;
        }
    
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            if (!(getConfig().contains("Players." + p.getName()))) {
                getConfig().createSection("Players." + p.getName()).set("Players." + p.getName(),
                        getConfig().getInt("Default"));
                ;
            } else {
                return;
            }
        }
    
        @EventHandler
        public void onBlockBreak(BlockBreakEvent e) {
            Player p = e.getPlayer();
            Block bl = e.getBlock();
            if (!(bl.getType().equals(Material.DIAMOND_ORE) && !(bl.getType().equals(Material.GOLD_ORE)
                    && !(bl.getType().equals(Material.REDSTONE_ORE) && !(bl.getType().equals(Material.IRON_ORE))
                            && !(bl.getType().equals(Material.LAPIS_ORE)) && !(bl.getType().equals(Material.EMERALD_ORE))
                            && !(bl.getType().equals(Material.QUARTZ_ORE)) && !(bl.getType().equals(Material.COAL_ORE))))))
                return;
    
            if (getConfig().getInt("Players." + p.getName()) >= getConfig().getInt("Limit")) {
    
                if (getConfig().getBoolean("Warning") == true) {
                    p.sendMessage(ChatColor.RED + "You are at your Mine-Limit. Please wait before mining valubles again.");
                    }
                e.setCancelled(true);
                for (Player ops : Bukkit.getServer().getOnlinePlayers()) {
                    if (ops.isOp()) {
                        ops.sendMessage(ChatColor.DARK_RED + p.getName() + ChatColor.RED
                                + " just tried to bypass the MineLimit. Could be suspicious.");
                    } else {
                        return;
                    }
                   
                }
               
                } else {
                    if (bl.getType().equals(Material.DIAMOND_ORE) && getConfig().getBoolean("Ores.Diamond") == true) {
                        getConfig().set("Players." + p.getName(),
                                getConfig().getInt("Players." + p.getName() + getConfig().getInt("Ores.Diamond.add")));
                        if (getConfig().getInt("Players." + p.getName()) > getConfig().getInt("Limit")) {
                            getConfig().set("Players." + p.getName(), getConfig().getInt("Limit"));
                        }
                    } else if (bl.getType().equals(Material.GOLD_ORE) && getConfig().getBoolean("Ores.Gold") == true) {
                        getConfig().set("Players." + p.getName(),
                                getConfig().getInt("Players." + p.getName() + getConfig().getInt("Ores.Gold.add")));
                        if (getConfig().getInt("Players." + p.getName()) > getConfig().getInt("Limit")) {
                            getConfig().set("Players." + p.getName(), getConfig().getInt("Limit"));
                        }
                    } else if (bl.getType().equals(Material.REDSTONE_ORE)
                            && getConfig().getBoolean("Ores.Redstone") == true) {
                        getConfig().set("Players." + p.getName(),
                                getConfig().getInt("Players." + p.getName() + getConfig().getInt("Ores.Redstone.add")));
                        if (getConfig().getInt("Players." + p.getName()) > getConfig().getInt("Limit")) {
                            getConfig().set("Players." + p.getName(), getConfig().getInt("Limit"));
                        }
                    } else if (bl.getType().equals(Material.IRON_ORE) && getConfig().getBoolean("Ores.Iron") == true) {
                        getConfig().set("Players." + p.getName(),
                                getConfig().getInt("Players." + p.getName() + getConfig().getInt("Ores.Iron.add")));
                        if (getConfig().getInt("Players." + p.getName()) > getConfig().getInt("Limit")) {
                            getConfig().set("Players." + p.getName(), getConfig().getInt("Limit"));
                        }
                    } else if (bl.getType().equals(Material.COAL_ORE) && getConfig().getBoolean("Ores.Coal") == true) {
                        getConfig().set("Players." + p.getName(),
                                getConfig().getInt("Players." + p.getName() + getConfig().getInt("Ores.Coal.add")));
                        if (getConfig().getInt("Players." + p.getName()) > getConfig().getInt("Limit")) {
                            getConfig().set("Players." + p.getName(), getConfig().getInt("Limit"));
                        }
                    } else if (bl.getType().equals(Material.EMERALD_ORE)
                            && getConfig().getBoolean("Ores.Emerald") == true) {
                        getConfig().set("Players." + p.getName(),
                                getConfig().getInt("Players." + p.getName() + getConfig().getInt("Ores.Emerald.add")));
                        if (getConfig().getInt("Players." + p.getName()) > getConfig().getInt("Limit")) {
                            getConfig().set("Players." + p.getName(), getConfig().getInt("Limit"));
                        }
                    } else if (bl.getType().equals(Material.LAPIS_ORE) && getConfig().getBoolean("Ores.Lapis") == true) {
                        getConfig().set("Players." + p.getName(),
                                getConfig().getInt("Players." + p.getName() + getConfig().getInt("Ores.Lapis.add")));
                        if (getConfig().getInt("Players." + p.getName()) > getConfig().getInt("Limit")) {
                            getConfig().set("Players." + p.getName(), getConfig().getInt("Limit"));
                        }
                    } else if (bl.getType().equals(Material.QUARTZ_ORE) && getConfig().getBoolean("Ores.Quartz") == true) {
                        getConfig().set("Players." + p.getName(),
                                getConfig().getInt("Players." + p.getName() + getConfig().getInt("Ores.Quartz.add")));
                        if (getConfig().getInt("Players." + p.getName()) > getConfig().getInt("Limit")) {
                            getConfig().set("Players." + p.getName(), getConfig().getInt("Limit"));
                        }
                    }
                }
            }
        }
    
    
    And the config (which I'm proud of btw :3):
    Code:
    # --- MineLimit Config ---
    # !!WARNING!! Do not change any words behind colons (":") !!
    #
    # Here you can check a player's "mine score" it will increase whenever they mine valuables.
    # If it gets to a certain limit, they will not be able to mine valuables until it lowers.
    #
    # This is the default score players will start off with. It is also the lowest their score
    # can decrease to.
    Default: 0
    #
    # This is the Limit, or the "trigger" amount of score before players must wait to mine ores
    # again.
    Limit: 1500
    #
    # If this is set to true, players will receive a warning message whenever they reach their
    # Limit. Set to false to disable.
    Warning: false
    #
    # Set any of the below to true to allow score addition when mining, and inability to mine that
    # ore when at the limit. Set to false to disable them from adding score, and making players
    # inable to mine them at their limit.
    # Also, the integer of "add:" is how much score will be added to the player's score when they
    # mine that ore.
    Ores:
      Diamond: true
        add: 250
      Gold: true
        add: 200
      Iron: true
        add: 100
      Coal: true
        add: 25
      Redstone: true
        add: 25
      Emerald: true
        add: 300
      Lapis: true
        add: 75
      Quartz: true
        add: 75
    #
    # Below are all of the registered players, and their current score. Can be edited.
    Players:
      Oh_Yes: 0
     
    Last edited: Mar 5, 2016
  6. Offline

    wesley27

    @OhYes saveDefaultConfig() should only be in your onEnable(). You should have the getConfig().options().copyDefaults(true) before it, like you originally did. This simply loads the configuration when you're enabling the plugin. To save data to the config elsewhere in your plugin, you need the saveConfig() method.

    The saveConfig() method saves the current configuration, which is why it doesn't load your defaults in the onEnable(). It simply saves whatever plugin.getConfig() is, and if you haven't saved the default values yet, plugin.getConfig() doesn't have anything in it. Hence, why you need saveDefaultConfig() in your onEnable(). Then, when you modify the configuration anywhere else in your plugin, you need to saveConfig().

    EDIT: About you not being able to mine diamond, check your code where you check for the adding of limits, around line 123, for example. I was initially confused at all this so I could be wrong, but it appears as though you might be missing parenthesis in this line? But then again, you don't have parenthesis in any of the similar lines for the other ores. I'm not sure?
    getConfig().getInt("Players."+ p.getName()+ getConfig().getInt("Ores.Diamond.add"))
    Isn't that trying to get an integer out of the config from a path that doesn't exist? If I'm correct in how that works, when it runs, that call is basically the same thing as:
    getConfig().getInt("Players.Oh_Yes250")
    I could be wrong, of course, can anyone confirm my slightly confused logic here? :p
     
    Last edited: Mar 6, 2016
  7. Offline

    OhYes

    Arggghh this is annoying me now. I don't know why it's doing this. Ok this is extremely derp. Do you have a Skype or anything I can contact you on? This is really hard to explain. I can now mine diamond when I set my score to -1 or below. anything above 0 and I cant mine ONLY diamond. I did what you said with the config, and it seems to work fine. Also, the warning will never be sent to the player even when the boolean in the config is true. Halp! D:
     
  8. Offline

    wesley27

    @OhYes Sure, I'll pm you my skype. So, the original issue, the config is now solved? That's good to hear, you can send me a pm on skype about the diamond issue.

    Also, why don't you start by creating a global final variable for the limit that pulls the limit out of the config. This way, you can just reference this variable in all of your conditional statements, rather than calling config.getInt() over and over again. It's more efficient and easier to read, work with, and debug.

    Also, please tag me everytime you post something to me otherwise there's a high chance I'll miss it.
     
Thread Status:
Not open for further replies.

Share This Page