Get config file from another class.

Discussion in 'Plugin Development' started by Dreeass, Apr 10, 2012.

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

    Dreeass

    Heey, I'm trying to access my config file from another file then where the onEnable is. Whatever I do it doesn't work.. I know that it's trying to get something that doesn't exist because it isn't public but I tried several things and looked it up on here and they don't work.

    Error when typing /motd:
    Code:
    16:49:22 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'motd
    ' in plugin VanillaPlus v0.3
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:16
    6)
            at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:4
    73)
            at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.
    java:821)
            at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:781)
     
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:764)
            at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:34)
            at net.minecraft.server.NetworkManager.b(NetworkManager.java:229)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:113)
            at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:7
    8)
            at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:551)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:449)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.NullPointerException
            at me.Dreeass.VanillaPlus.CommandMotd.onCommand(CommandMotd.java:15)
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
            ... 12 more
    Main:
    Code:
    package me.Dreeass.VanillaPlus;
     
    import java.util.ArrayList;
    import java.util.logging.Logger;
     
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Main extends JavaPlugin {
        public static ArrayList<String> godPlayers = new ArrayList<String>();
        public final Logger logger = Logger.getLogger("Minecraft");
        public static Main plugin;
        public final BlockListener bl = new BlockListener();
        public final PlayerListener pl = new PlayerListener();
        public static ArrayList<String> afkPlayers = new ArrayList<String>();
       
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " has been disabled.");
        }
       
        @Override
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " has been enabled.");
           
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(this.bl, this);
            pm.registerEvents(this.pl, this);
           
            final FileConfiguration config = this.getConfig();
            config.addDefault("Motd", "Hello welcome to the server!");
            config.options().copyDefaults(true);
            saveConfig();
           
            getCommand("motd").setExecutor(new CommandMotd());
            getCommand("afk").setExecutor(new CommandAfk());
            getCommand("tp").setExecutor(new CommandTp());
            getCommand("tphere").setExecutor(new CommandTphere());
            getCommand("god").setExecutor(new CommandGod());
            getCommand("spawn").setExecutor(new CommandSpawn());
            getCommand("setspawn").setExecutor(new CommandSetspawn());
            getCommand("give").setExecutor(new CommandGive());
            getCommand("broadcast").setExecutor(new CommandBroadcast());
            getCommand("heal").setExecutor(new CommandHeal());
            getCommand("time").setExecutor(new CommandTime());
            getCommand("list").setExecutor(new CommandList());
            getCommand("gm").setExecutor(new CommandGM());
        }
       
    }
    
    Motd class:
    Code:
    package me.Dreeass.VanillaPlus;
     
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
     
    public class CommandMotd implements CommandExecutor {
        public static Main plugin;
     
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            Player playerSender = (Player) sender;
     
            playerSender.sendMessage(plugin.getConfig().getString("Motd"));
           
            return false;
        }
     
    }
    
     
  2. Offline

    theguynextdoor

  3. Offline

    Dreeass

    Thanks! ;)
     
Thread Status:
Not open for further replies.

Share This Page