Solved Having Problems With Configs

Discussion in 'Plugin Development' started by niels1k, Dec 4, 2012.

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

    niels1k

    Hello, i am having problems with configuration files. This is my main class called Main.java:
    Code:
    package com.niels1k.plugin;
     
    import java.util.logging.Logger;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin{
        public static Main plugin;
        Logger logger = Logger.getLogger("Minecraft");
        public final Niels1kPlayerListener pl = new Niels1kPlayerListener();
       
        @Override
        public void onEnable() {
            getLogger().info("Niels1K Plugin Has Been Enabled!");
            PluginManager pm = getServer().getPluginManager();
            getCommand("niels1k").setExecutor(new Niels1kCommandExecutor(this));
            getCommand("niels1k heal").setExecutor(new Niels1kCommandExecutor(this));
            getCommand("niels1k info").setExecutor(new Niels1kCommandExecutor(this));
            getCommand("niels1k truth").setExecutor(new Niels1kCommandExecutor(this));
            this.getConfig().options().copyDefaults(true);
            this.saveDefaultConfig();
            this.saveConfig();
            pm.registerEvents(pl, this);
        }
       
        @Override
        public void onDisable() {
            getLogger().info("Niels1K Plugin Has Been Disabled!");
        }
    }
    
    '
    Then here is my Player listener class called Niels1kPlayerListener.java:
    Code:
    package com.niels1k.plugin;
     
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
     
    @SuppressWarnings("deprecation")
    public class Niels1kPlayerListener implements Listener{
     
        public static Main plugin;
       
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event){
            Player player = event.getPlayer();
            event.setJoinMessage(plugin.getConfig().getString("onjoin").replace("&player&", player.getName()).replaceAll("&1", ChatColor.DARK_BLUE+"").replaceAll("&0", ChatColor.BLACK+"").replaceAll("&2", ChatColor.DARK_GREEN+"").replaceAll("&3", ChatColor.DARK_AQUA+"").replaceAll("&4", ChatColor.DARK_RED+"").replaceAll("&5", ChatColor.DARK_PURPLE+"").replaceAll("&6", ChatColor.GOLD+"").replaceAll("&7", ChatColor.GRAY+"").replaceAll("&8", ChatColor.DARK_GRAY+"").replaceAll("&9", ChatColor.LIGHT_PURPLE+"").replaceAll("&a", ChatColor.GREEN+"").replaceAll("&b", ChatColor.AQUA+"").replaceAll("&c", ChatColor.RED+"").replaceAll("&e", ChatColor.YELLOW+"").replaceAll("&f", ChatColor.WHITE+"").replaceAll("&m", ChatColor.STRIKETHROUGH+"").replaceAll("&n", ChatColor.UNDERLINE+"").replaceAll("&l", ChatColor.BOLD+"").replaceAll("&k", ChatColor.MAGIC+"").replaceAll("&o", ChatColor.ITALIC+""));
        }
    }
    
    When i load up my server it doesnt generate a config file. If you look at my code, you see that i am trying to make the join message configurable. It might be someting with the Player listener, but it doesnt even gen a config. However, i do get an error in the console. If it doesnt have to do with this problem, ignore it.
    Code:
    16:15:12 [INFO] [Niels1K] Enabling Niels1K v0.1
    16:15:12 [INFO] [Niels1K] Niels1K Plugin Has Been Enabled!
    16:15:12 [SEVERE] Error occurred while enabling Niels1K v0.1 (Is it up to date?)
     
    java.lang.NullPointerException
            at com.niels1k.plugin.Main.onEnable(Main.java:17)
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
    .java:374)
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
    r.java:381)
            at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:270)
            at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:252
    )
            at net.minecraft.server.MinecraftServer.j(MinecraftServer.java:320)
            at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:299)
            at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:258)
            at net.minecraft.server.DedicatedServer.init(DedicatedServer.java:147)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:398)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:856)
    16:15:12 [INFO] Server permissions file permissions.yml is empty, ignoring it
    16:15:12 [INFO] Done (3,247s)! For help, type "help" or "?"
     
  2. Offline

    gomeow

    To generate a config file easily, the best way to do it is write a sample config, (what you want your users to see) then place it inside the src/ folder of your project. To make it so that it copies over into the data folder like you see other plugins do, all you need to do is add this to your onEnable():
    Code:
    saveDefaultConfig();
     
  3. Offline

    niels1k

    Forgot to say, i actually have a sample config. Here it is:
    Code:
    ##########################
    # Default Niels1K Config #
    ##########################
    # www.niels1k.comoj.com  #
    ##########################
     
    #Set the player join message
    #onjoin: <message>
    #Color Codes can be use. Notice that the color pink (&d) doesn't work
    onjoin: &bHello &player&! Welcome to a Niels1K server!
    I also have saveDefaultConfig();
    :(
     
  4. Offline

    gomeow

    You are copying defaults, saving the default one, and saving it at the same place. Delete the other two
     
  5. Offline

    niels1k

    Well, people tell me alot that i'm stupid. And you just prove it. Haha it actually worked. Thanks buddy.
     
  6. Offline

    gomeow

    No problem :)

    Every programmer starts stupid. I remember when I started, I tried to use a player like this:
    Code:
    "gomeow".someMethod();
     
Thread Status:
Not open for further replies.

Share This Page