Plugin not reading from config

Discussion in 'Plugin Development' started by SteppingHat, Jun 22, 2012.

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

    SteppingHat

    I have a value in my config that is an integer that I am trying to assign to an integer variable in the actual plugin itself.

    However, the plugin is returning a 0 instead of the 60 that is specified in the config.

    Code:
    public class TempTeleport extends JavaPlugin {
     
        public static TempTeleport plugin;
        public final Logger logger = Logger.getLogger("Minecraft");
        Logger log = Logger.getLogger("Minecraft");
     
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " has been disabled!");
        }
     
        public static int CONF_time;
     
        @Override
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            log.info("--------TEMPTELEPORT by SteppingHat--------");
            this.logger.info(pdfFile.getName() + " v" + pdfFile.getVersion() + " has been enabled!");
            log.info("-------------------------------------------");
            this.getConfig().options().copyDefaults(true);
            this.saveConfig();
            CONF_time = getConfig().getInt("time");
        }
    It's probably a small silly mistake that I fail to somehow find. But I would greatly appreciate it if someone could help me find out what it is.

    Thanks in advance!
     
  2. Offline

    Taco

    I don't see where the variable "time" is ever written to the config. Either way, assuming it's there, have you tried moving CONF_time = getConfig().getInt("time"); to before you save the config?
     
  3. Offline

    Sagacious_Zed Bukkit Docs

    Taco
    The value could be written ahead of time, and does not need to be generated in code.

    SteppingHat
    can you provide us with your yaml file.
     
  4. Offline

    r0306

    SteppingHat
    Make sure the time in your config does not have " " or ' ' surrounding the number.

    Code:
    #Should be
     
    time: 60
     
    #Not
     
    time: "60"
     
    #Or
     
    time: '60'
     
  5. Offline

    SteppingHat

    Here is the Config YAML file.

    Code:
    # #################### #
    # Temp Teleport Config #
    # #################### #
     
    # It is strongly recommended that you use an editor such as Notepad++ to
    # edit Bukkit config files. Windows Notepad doesn't like reading yml files.
     
    # The time that it takes before the user is teleported back (in seconds)
    time: 60
     
  6. Offline

    chaseoes

    Seeing as you're using "this." for everything else, why isn't it before getConfig()?
    Code:java
    1. CONF_time = this.getConfig().getInt("time");
     
  7. Offline

    SteppingHat

    I've done that but it doesn't seem to work. The plugin still reads a 0.
     
  8. Offline

    EnvisionRed

Thread Status:
Not open for further replies.

Share This Page