Solved Import config from main

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

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

    Capby

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


    Code:
    package commands;
    
    import java.io.File;
    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");
           
            config.options().copyDefaults(true);
            saveConfig();
    
            logger.info(pdfFile.getName() + " 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

    MarinD99

    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

    Capby

Thread Status:
Not open for further replies.

Share This Page