Help with getConfig() to send a message

Discussion in 'Plugin Development' started by AguilaAudaz, Sep 18, 2013.

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

    AguilaAudaz

    Well i have a problem with my code, i dont know if i have to link something with another thing, i have 2 classes, the main and another for commands

    MAIN

    Code:java
    1. public void onDisable()
    2. {
    3. PluginDescriptionFile pdfFile = getDescription();
    4. logger.info(pdfFile.getName() + " has been disabled!");
    5. }
    6.  
    7. public void onEnable()
    8. {
    9. getConfig().options().copyDefaults(true);
    10. saveConfig();
    11. this.getCommand("textures").setExecutor(new Commandsinfo());
    12. PluginDescriptionFile pdfFile = getDescription();
    13. logger.info(pdfFile.getName() + " has been enabled!");
    14. }
    15. public final Logger logger = Logger.getLogger("Minecraft");
    16. public static Warpixelcommands plugin;
    17.  
    18. }


    The other class

    Code:
    package me.christopher.warpixelcommands;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
     
    public class Commandsinfo implements CommandExecutor
    {
        public boolean onCommand(CommandSender sender, Command cmd, String label, String args[]) {
                Player player = (Player) sender;
                if(cmd.getName().equalsIgnoreCase("textures")){
                player.sendMessage(getConfig().getString("textures-info"));
                }
                return false;
        }
    }
     
  2. Offline

    iiHeroo


    I don't think you need the {} in the

    Code:java
    1. if(cmd.getName().equalsIgnoreCase("textures")){
    2. player.sendMessage(getConfig().getString("textures-info"));
    3. }


    Here's my code,
    Code:java
    1. if(commandLabel.equalsIgnoreCase("owner"))
    2. if(player.hasPermission("serverinfoplus.owner"))
    3. player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("powner")) + ChatColor.translateAlternateColorCodes('&', config.getString("owner")));


    the ChatColor.iinfdnld stuff allows color code responses, and config = getConfig();
     
  3. Offline

    AguilaAudaz

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String args[]) {
    2. Player player = (Player) sender;
    3. config = getConfig(); //This keeps giving me the error
    4. if(cmd.getName().equalsIgnoreCase("textures"))
    5. player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("textures-info")));


    Like this?
     
  4. Offline

    metalhedd

    you don't NEED the {}'s but you should use them. it makes your code difficult to read if you don't, and they definitely aren't causing any problems.


    That's exactly what he has already...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  5. Offline

    AguilaAudaz

    I update it but i still having the error in config = getConfig();

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    2. Player player = (Player) sender;
    3. config = getConfig();
    4. if(cmd.getName().equalsIgnoreCase("owner")){
    5. player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getString("textures-info")));
     
  6. Offline

    metalhedd


    The CommandExecutor classs doesn't HAVE a getConfig() method. you need to access your main class for that, you should pass in a reference to the main class into the constructor of this CommandExecutor class and call plugin.getConfig() instead


    Would you care to prove that with a code sample where they behave differently? They're exactly the same thing as far as I'm aware.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
Thread Status:
Not open for further replies.

Share This Page