Solved GetConfig () Error in other package/class

Discussion in 'Plugin Development' started by Max604, Jan 21, 2014.

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

    Max604

    Hey guys ive got an bug in my code please give me the line of code to fix it btw im learning java.

    Main Class:
    Code:java
    1. package me.max604.duty;
    2.  
    3.  
    4. import me.max604.duty.command.DutyCommand;
    5.  
    6. // import org.bukkit.ChatColor;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class Main extends JavaPlugin
    10. {
    11. //String dc = ChatColor.GREEN + "[" + ChatColor.GOLD + "Duty" + ChatColor.GREEN + "]" + ChatColor.WHITE;
    12. @Override
    13. public void onEnable()
    14. {
    15. getLogger().info("Duty Plugin has been Enabled!)");
    16. this.getCommand("duty").setExecutor(new DutyCommand(this));
    17. getConfig().options().copyDefaults(true);
    18. saveConfig();
    19.  
    20. }
    21. @Override
    22. public void onDisable()
    23. {
    24. getLogger().info("Duty Plugin has been Disabled!");
    25. saveConfig();
    26. }
    27. }
    28.  
    29.  
    30.  
    31.  
    32.  
    33.  


    Plugin.yml
    Code:
    name: Duty
    author: Max604
    version: 1
    description: Duty Plugin
    main: me.max604.duty.Main
    commands:
      duty:
        description: Duty
    Config.yml
    Code:java
    1. # Duty Configuration File
    2. Prefix: Duty

    DutyCommand (This is where the error is at the getConfig() on line 35)
    Code:java
    1. package me.max604.duty.command;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.HashMap;
    5.  
    6. import me.max604.duty.Main;
    7.  
    8. import org.bukkit.Bukkit;
    9. import org.bukkit.ChatColor;
    10. import org.bukkit.block.Block;
    11. import org.bukkit.command.Command;
    12. import org.bukkit.command.CommandExecutor;
    13. import org.bukkit.command.CommandSender;
    14. import org.bukkit.entity.Player;
    15.  
    16. public class DutyCommand implements CommandExecutor
    17. {
    18. String bc = ChatColor.DARK_GREEN + ">" + ChatColor.GREEN + ">";
    19. public final HashMap<Player, ArrayList<Block>> hashmap = new HashMap<Player, ArrayList<Block>>();
    20.  
    21. Main plugin;
    22. public DutyCommand(Main passedPlugin)
    23. {
    24. this.plugin = passedPlugin;
    25. }
    26. @Override
    27. public boolean onCommand(CommandSender sender, Command cmd, String label,String[] args)
    28. {
    29. Player player = (Player) sender;
    30. if(label.equalsIgnoreCase("duty"))
    31. {
    32. if(hashmap.containsKey(player))
    33. {
    34. hashmap.remove(player);
    35. Bukkit.broadcastMessage(getConfig().getString("Prefix") + ChatColor.AQUA + " Staff Member " + ChatColor.BLUE.toString() + ChatColor.BOLD + player.getName() + ChatColor.RED + " is now OFF duty");
    36.  
    37. }else
    38. {
    39. hashmap.put(player, null);
    40. Bukkit.broadcastMessage(this.bc + ChatColor.AQUA + " Staff Member " + ChatColor.BLUE.toString() + ChatColor.BOLD + player.getName() + ChatColor.GREEN + " is now ON duty");
    41. }
    42. }
    43. return false;
    44. }
    45.  
    46. }
    47.  
     
  2. Offline

    Warreo

    Max604 You need to call the getConfig() from your main class, so you would need to call like so:
    Code:java
    1. plugin.getConfig()
    Since you passed your Main class and assigned it to the var plugin.
     
  3. Offline

    Max604

    Thanks for the help it now works
     
  4. Offline

    Warreo

    Max604 Please change the title to solved then. :)
     
Thread Status:
Not open for further replies.

Share This Page