i can't get my commands use getConfig().getString() (fixed)

Discussion in 'Plugin Development' started by dark2222, Mar 29, 2012.

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

    dark2222

    please help i can't get my commands to load with the code getConfig().getSting("hbegin")
    it shull look out for a string they are carled hbegin in my config.yml but the command is in its own class so i get errors if i do this
    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            Player player = (Player) sender;
            if(commandLabel.equalsIgnoreCase("hbegin")){
                player.sendMessage(ChatColor.GOLD + getConfig().getSting("hbegin"));
    can any1 please help me
     
  2. Offline

    anerach

    Try this
    Code:java
    1. player.sendMessage(ChatColor.GOLD + getConfig().getSting("hbegin"));
     
  3. Offline

    dark2222

    that is what i type and i have try 1 more time but it say getConfig() and how i fix it is i make a method but if i do that will it say getString("hbegin") is wrong and i i fix that as the same way as getConfig() i say (ChatColor.GOLD + getConfig().getSting("hbegin")); is wrong

    (it is not my main class)
     
  4. Offline

    Theodossis

    I believe you have to do it from main class. I go the same problem too...
     
  5. Offline

    Superkabii

    ...basic Java. You want to pass your main class to your command executor class, making a variable for it. If you know basic Java you should be able to figure that out.
     
  6. Offline

    dark2222

    just so you now i just start with this for 2 days ago so i don't now so much but i is trying to fix it right now
     
  7. Offline

    Superkabii

    I can see that. I'm pointing out you should know Java before you delve into Bukkit plugin creation, not the other way around.
     
  8. Offline

    dillyg10

    lol... yeah what Superkabii said.. but I mean u can still learn stuff along the way for deving. I know I've learned a lot for deving with bukkit, some basic java things that I can't belive I didn't know!

    But anywho, you need to make an object for your main plugin, make a constructor for your commandexecuter class, and then do like plugin.getConfig() etc.. etc..

    If u have no idea what I just said, I'll give u an example.
     
  9. Offline

    Mr Washington

    dillyg10 is correct. I will revise yor command below:

    Code:
    player.sendMessage(ChatColor.GOLD + plugin.getConfig().getSting("hbegin"));
    Make sure you include an instance of plugin at the top! Here is an example:

    Code:
    private <MainClassName> plugin;
    
    public <ClassName> (<MainClassName> plugin) {
       this.plugin = plugin;
    }
    (Sorry for any errors, typing this on my iPad during class ;) )
     
  10. Offline

    Sagacious_Zed Bukkit Docs

    Alsto there is no getSting method. its getString
     
  11. Offline

    dark2222

    thanks for the help guys that help me so much i have think so much on this so i have not make my homework right now :( :)

    thanks for the help guys that help me so much i have think so much on this so i have not make my homework right now :( :)

    i only have one problem back now
    when i type the command nothing happen
    here is my command class
    Code:
    package commands;
     
    import me.dark2222.helpbot.helpbotmain;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
     
    public class commandhbegin{
        private helpbotmain plugin;
     
     
        public commandhbegin (helpbotmain plugin) {
            this.plugin = plugin;
        }
     
            public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
                Player player = (Player) sender;
                if(commandLabel.equalsIgnoreCase("hbegin"));
                  player.sendMessage(ChatColor.GOLD + plugin.getConfig().getString("hbegin"));
                return false;
     
     
         
    }
    }
    and here is my main class
    Code:
    package me.dark2222.helpbot;
     
    import java.util.logging.Logger;
     
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class helpbotmain extends JavaPlugin{
        public final Logger logger = Logger.getLogger("minecraft");
       
       
        @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!");
            getConfig().options().copyDefaults(true);
            saveConfig();
           
       
     
    }
    }
    a example sound great
    i you will i will get glad if you can help me and learn some stuff :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  12. Offline

    Mr Washington

    First of all, I gave you an example of his thing if you didn't notice :)

    Now to answer your above question. You need to set all commands in the plugin.yml like this:
    Code:
    commands:
      <command>
        description: <description
        usage: /<command>
    
    Please note that the tabs above are 2 spaces (Do not use tabs, it messes up the yml)
     
  13. Offline

    dark2222

    ups i don't have the usage
    i now that with tap :)

    i have now try that it just did so now it say /hbegin (the command) when i use it wtf?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  14. Offline

    ThatBox

    Ummm where are your { }
    And it seems you're using command Label instead of cmd.getName(). You should really learn some basic java :/
     
  15. Offline

    dark2222

    i start work with java for 3 day ago
    and i will try the cmd.getName()
     
  16. Offline

    Mr Washington

    In the onCommand thread, make sure that once you have done what you want in an if()statement. Make sure you return true ;)
     
  17. Offline

    anerach

    Try this
    Main class
    Code:java
    1. package me.dark2222.helpbot;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.plugin.PluginDescriptionFile;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7.  
    8. public class helpbotmain extends JavaPlugin {
    9. public final Logger logger = Logger.getLogger("minecraft");
    10.  
    11.  
    12. @Override
    13. public void onDisable() {
    14. PluginDescriptionFile pdfFile = this.getDescription();
    15. this.logger.info(pdfFile.getName() + " Has Been Disabled!");
    16. }
    17.  
    18. @Override
    19. public void onEnable() {
    20. getCommand("hbegin").setExecutor(new Commandhbegin(this));
    21. PluginDescriptionFile pdfFile = this.getDescription();
    22. this.logger.info(pdfFile.getName() + " Version" + pdfFile.getVersion() + " Has Been Enabled!");
    23. getConfig().options().copyDefaults(true);
    24. saveConfig();
    25. }
    26. }

    Command class
    Code:java
    1. package commands;
    2.  
    3. import me.dark2222.helpbot.helpbotmain;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandExecutor;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10.  
    11. public class commandhbegin implements CommandExecutor {
    12. private helpbotmain plugin;
    13.  
    14. public commandhbegin (helpbotmain plugin) {
    15. this.plugin = plugin;
    16. }
    17.  
    18. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    19. Player player = (Player) sender;
    20. if(cmd.getName().equalsIgnoreCase("hbegin"));
    21. player.sendMessage(ChatColor.GOLD + plugin.getConfig().getString("hbegin"));
    22.  
    23. return true;
    24. }
    25. }
     
  18. Offline

    dark2222

    thanks so much it works now! :D
     
  19. hello i hava a question i have a problem when i fill in a string in the config file and i want to reload the server everything i changed in the config file is back to normal how can i set that doesn't change
     
  20. Offline

    dark2222

    can i see your class?
     
  21. it is fixed
     
Thread Status:
Not open for further replies.

Share This Page