Solved Config Issue

Discussion in 'Plugin Development' started by Jason Malouin, Jun 10, 2015.

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

    Jason Malouin

    Whenever I try to call the config method.... The plugin never reaches the variable and returns "null" in-game:
    Its kind of hard to explain
    This is inside of a timer loop. It works outsde the timer loop but not in... I tried removing "this" from getConfig().getString but It returned null in game even though I got no errors. Does anyone have an idea.. Thanks :)
  2. Offline

    I Al Istannen

  3. Offline

    Jason Malouin

    Yes !
  4. Offline

    I Al Istannen

    @Jason Malouin Is it in your main class? Otherwise you won't be able to call "getConfig()". Using "this" makes it even worse, as the "BukkitRunnable" or a "Runnable" don't have the method.
    If the path is correct it should work.

    EDIT: Just tried it. It does work. If it doesn't for you, but the path is right and it is in your Main class, post the code.
  5. Offline

    Jason Malouin

    Heres All Of The Code. The GetConfig Is At The Bottom Of This Area Of Code.

    package me.Tobysmith10.tour;
    import org.bukkit.scheduler.BukkitScheduler;
    import java.util.logging.Logger;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Server;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.MemorySection;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    public class Tour extends JavaPlugin {
        public static Tour plugin;
        public final Logger logger = Logger.getLogger("Minecraft");
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
   + " Has Been Disabled");
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
   + " Has Been Enabled");
            PluginManager pm = this.getServer().getPluginManager();
            pm.registerEvents(new PlayerListener(), this);
             File file = new File(getDataFolder() + File.separator + "config.yml");
               this.getLogger().info(pdfFile.getName() + " Generating Configuration File");
               this.getConfig().addDefault("NOTE","Don't Edit This. Still Under Construction");
               this.getConfig().addDefault("tour1", "TourMaster");
               this.getConfig().addDefault("tour2", "Version: BETA 1.0");
               this.getConfig().addDefault("tour3", "Created By Tobysmith10");
        int countint = 1;
        public boolean onCommand(final CommandSender sender, Command cmd, String commandLabel, String[] args){
            if (cmd.getName().equalsIgnoreCase("tour")) {
                if(args.length == 0){
            if(args.length == 1){
                sender.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GOLD + "Tours" + ChatColor.DARK_GRAY + "] " + ChatColor.AQUA + "Teleporting In 5 Seconds");
               if(countint== 1){
               BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
               scheduler.scheduleSyncDelayedTask(this, new Runnable() {
                    final Player player = (Player) sender;
                   public void run() {
                            double x1 = 19.5 + 1;
                               double y1 = 107 + 1;
                               double z1 = -247.5 + 1;
                           final Location teleportLocation1 = new Location(player.getWorld(), x1, y1, z1);
                            sender.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GOLD + "Tours" + ChatColor.DARK_GRAY + "] " + ChatColor.AQUA + "Teleporting To Our First Stop");
                            sender.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GOLD + "Tours" + ChatColor.DARK_GRAY + "] " + ChatColor.RED + getConfig().getString("tour1"));
               }, 100L);
    Note: This isnt all of the code. Just the error Portion
  6. Offline


    Is there any fix for this problem? I got it too.
  7. Offline

    Jason Malouin

    Sorry if its a bit cloudy with all the stuff
  8. Offline

    timtower Moderator Moderator

    @Jason Malouin Why not just load the config in onEnable and put the string in a variable?
  9. Offline

    Jason Malouin

    I thought that is loading the config in onEnable


    EDIT by Timtower: merged posts
    Last edited by a moderator: Jun 10, 2015
Thread Status:
Not open for further replies.

Share This Page