Solved Import config from main

Discussion in 'Plugin Development' started by Capby, Aug 3, 2016.

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


    So I have main class and a rankup class, how would I import the config so I can use getConfig(); and stuff?

    package commands;
    import java.util.logging.Logger;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.PluginDescriptionFile;
    import net.minebloxmc.main.Main;
    public class rankup implements CommandExecutor {
        FileConfiguration config = getConfig();
    public void onEnable() {
            PluginDescriptionFile pdfFile = getDescription();
            Logger logger = Logger.getLogger("Minecraft");
   + " has loaded (V." + pdfFile.getVersion() + ")");
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if (!(sender instanceof Player)) {
                sender.sendMessage("You must be a player");
                return false;
            Player player = (Player) sender;
                if (player.getLocation().getWorld().getName().equals("Prison")) {
                    player.sendMessage(ChatColor.BLUE + "Correct World!");
                } else {
                    player.sendMessage(ChatColor.RED + "Incorrect World!");
            return true;
  2. Offline


    Pass the instance of the main class through a constructor, or use a singleton.
  3. @Capby Why are you using Java's logger? Bukkit#getLogger, just use saveDefaultConfig rather than copyDefaults and save, and you don't need to log onEnable. To answer the question: Pass the instance
  4. Offline


Thread Status:
Not open for further replies.

Share This Page