getConfig().set Error

Discussion in 'Plugin Development' started by Ross Gosling, Jan 5, 2014.

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

    Ross Gosling

    I have a class that is called to setup a cooldown period and set it as InCooldown within the config, when the method calls 'main.getConfig().set(point + ".InCooldown", "true");' the server gets the following error and it doesn't work.

    If the line is commented out the function works without errors, its simply when I try to set the config value that it has issues. Can anyone explain what I'm doing wrong?

    Cooldown Class:
    Code:
    package me.x3DGosling.CustomGoslingPlugin;
     
    import org.bukkit.Bukkit;
     
    public class PointCooldownSystem {
       
        public static Main main = new Main();
        public PointCooldownSystem(Main instance) {
            main = instance;
        }
           
        public void startCooldown(String point, int cooldownValue) {
               
            final String cooldownLocation = point;
           
            //Marks point as in cooldown and sets duration in config
            main.getConfig().set(point + ".InCooldown", "true");
            setCooldown(cooldownLocation, cooldownValue);
           
            while(cooldownValue < 0) {
           
                //Creates a thread to perform systems every minute (1200 ticks)
                Bukkit.getServer().getScheduler().runTaskLater(main, new Runnable() {
                   
                    public void run() {
                       
                        setCooldown(cooldownLocation, getCooldown(cooldownLocation) - 1);
                       
                    }
                   
                }, 1200);
           
            }
           
        }
       
        public int getCooldown(String point) {
           
            int integer = (main.getConfig().getInt(point + ".Cooldown"));
           
            return integer;
           
        }
       
        public void setCooldown(String point, int cooldownValue) {
           
            main.getConfig().set(point + ".Cooldown", cooldownValue);
           
        }
       
    }
    
    Error within the console:
     
  2. Offline

    Pew446

    Did you make sure to saveDefaultConfig(); first? I think that error is caused by the config file not existing.
     
  3. Offline

    Ross Gosling

    Does that onEnable and it has created the config file with all correct details :/
     
  4. Offline

    Bionicrm

    Post your Main class. What's shown should work.

    Edit: A suggestion: why not do:
    Code:java
    1. private static Main plugin;
    2. public PointCooldownSystem(Main plugin) {
    3. this.plugin = plugin;
    4. }

    (I mean the naming can be whatever, and this assumes some other things too, but good luck.)
     
    mbaxter likes this.
  5. Offline

    Ross Gosling

    Bare in mind this is in the midst of being re-written so it meets etiquette and it's stupidly inefficient so I have cut out the irrelevant stuff like 45-ish imports, irrelevant event handlers etc*

    Main Class
    Code:
    //==================================================================================================================================
     
    package me.x3DGosling.CustomGoslingPlugin;
     
    <Tons of imports not shown>
     
    public class Main extends JavaPlugin implements Listener {
     
        public final Logger logger = Logger.getLogger("Minecraft");
        public static Main plugin;
         
        private final CraftingRecipes craftingRecipes = new CraftingRecipes(this);
     
        private final CaptureSystem captureSystem = new CaptureSystem(this);
        private final TabMenuSystem tabMenuSystem = new TabMenuSystem(this);
        private final JoinFactionSystem joinFactionSystem = new JoinFactionSystem(this);
        private final ResetSystem resetSystem = new ResetSystem(this);
        private final MiscSystem miscSystem = new MiscSystem(this);
        private final ShopSystem shopSystem = new ShopSystem(this);
        private final SpawnProtectionSystem spawnProtectionSystem = new SpawnProtectionSystem(this);
        private final MakeItemStack makeItemStack = new MakeItemStack(this);
        private final RewardSystem rewardSystem = new RewardSystem(this);
     
        private final Command_Outlaw command_Outlaw = new Command_Outlaw(this);
        private final Command_Claim command_Claim = new Command_Claim(this);
        private final Command_Leave command_Leave = new Command_Leave(this);
        private final Command_Chat command_Chat = new Command_Chat(this);
        private final Command_Captain command_Captain = new Command_Captain(this);
        private final Command_Gamemode command_Gamemode = new Command_Gamemode(this);
        private final Command_NameItem command_NameItem = new Command_NameItem(this);
        private final Command_Info command_Info = new Command_Info(this);
        private final Command_Teleport command_Teleport = new Command_Teleport(this);
        private final Command_Weather command_Weather = new Command_Weather(this);
        private final Command_Tester command_Tester = new Command_Tester(this);
        private final Command_Villager command_Villager = new Command_Villager(this);
     
        <Loads of public integers not shown>
         
    //==================================================================================================================================
     
        //OnEnable Event
     
    //==================================================================================================================================
     
        public void onEnable() {
         
            Bukkit.getPluginManager().registerEvents((Listener) this, this);
         
            //Creates a config
            this.saveDefaultConfig();
         
            this.logger.info("The CustomGoslingPlugin has been enabled.");
         
            //SetupCraftingRecipesClass
            craftingRecipes.createRecipes(getServer());
         
            //Creates a thread to perform systems every second (20 ticks)
            getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
             
                public void run() {
                 
                    captureSystem.capturePoint_Town(getServer(), "Ross", "Emberstone", "A");
                    captureSystem.capturePoint_Town(getServer(), "Ross", "Emberstone", "B");
                    captureSystem.capturePoint_Throne(getServer(), "Ross", "Emberstone");
                 
                    captureSystem.capturePoint_Town(getServer(), "Lewis", "Mykonos", "A");
                    captureSystem.capturePoint_Town(getServer(), "Lewis", "Mykonos", "B");
                    captureSystem.capturePoint_Throne(getServer(), "Lewis", "Mykonos");
                 
                    captureSystem.capturePoint_Town(getServer(), "Alex", "Summerhold", "A");
                    captureSystem.capturePoint_Town(getServer(), "Alex", "Summerhold", "B");
                    captureSystem.capturePoint_Throne(getServer(), "Alex", "Summerhold");
                 
                    captureSystem.capturePoint_Town(getServer(), "Curtis", "Icarus", "A");
                    captureSystem.capturePoint_Town(getServer(), "Curtis", "Icarus", "B");
                    captureSystem.capturePoint_Throne(getServer(), "Curtis", "Icarus");
                 
                    captureSystem.capturePoint_Fort(getServer(), "EasternFortress", "East");
                    captureSystem.capturePoint_Fort(getServer(), "WesternFortress", "West");
                 
                    rewardSystem.PersistentEffects(getServer(), "Emberstone", "Ross");
                    rewardSystem.PersistentEffects(getServer(), "Mykonos", "Lewis");
                    rewardSystem.PersistentEffects(getServer(), "Summerhold", "Alex");
                    rewardSystem.PersistentEffects(getServer(), "Icarus", "Curtis");
                 
                }
             
            }, 0, 20);
         
            //Creates a thread to perform systems every tick
            getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
             
                public void run() {
                 
                    spawnProtectionSystem.ProtectSpawnCheck("Emberstone", "Ross");
                    spawnProtectionSystem.ProtectSpawnCheck("Mykonos", "Lewis");
                    spawnProtectionSystem.ProtectSpawnCheck("Summerhold", "Alex");
                    spawnProtectionSystem.ProtectSpawnCheck("Icarus", "Curtis");
                 
                }
             
            }, 0, 1);
         
            //Resets all capture point rings
            resetSystem.resetCapturePoints("Startup", getServer());
                      
        }
     
    //==================================================================================================================================
     
        //OnDisable Event
     
    //==================================================================================================================================
     
        public void onDisable() {
         
            this.logger.info("The CustomGoslingPlugin has been disabled.");
         
            //Resets all capture point rings
            resetSystem.resetCapturePoints("Shutdown", getServer());
         
            getServer().clearRecipes();
         
        }
         
    //==================================================================================================================================
    Loads of event handlers after this point, need to split them into separate classes.
    
     
  6. Offline

    Bionicrm

    I don't see where PointCooldownsSystem is being created in the main class.
     
  7. Offline

    Ross Gosling

    I've realised I don't actually need to get this information from the config so I don't need any help anymore :/
    No one else seems to have had this problem so meh, oh well.
     
Thread Status:
Not open for further replies.

Share This Page