ConfigMessage -> variable

Discussion in 'Plugin Development' started by Mallow, Jul 7, 2012.

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

    Mallow

    English:
    Hello Bukkit Forum =). I'm quite new at developing plugins but I was able to create a config and give it out if a player types in the right command. What I want now is to look into the configMessage before sending to look if there is nothing in it or to look if there is something specific in it for what I don't want to send the message. This looked like this in my Code:
    String News = this.getConfig().getString("messages.news");
    ...
    if (cmd.getName().equalsIgnoreCase("news") && News != null) {
    p.sendMessage(this.getConfig.getString("messages.news")
    }
    Well, I tried some things but I didn't found a way to check what is in that ConfigFile. Hope that you are able to help me and understand this because I'm from Germany :oops:.
     
  2. you mean the basic java stuff "String message = this.getConfig.getString("messages.news");"?
     
  3. Offline

    Mallow

    Found it out myself, the clue is the position of "String News = ..." Because by writing it all above i recieve the message "illegal argument, File cannot be null".
     
  4. That means you tried to access the config before you loaded it.
    Good that you fixed it, but you wanted to check if the string is in he config. The way your doing it now is bad. Why do you execute this.getConfig().getString("messages.news") 2 times? Why at different states? What if you implement a reload command but forget to update News?

    Have a look at that two methods which both do the same:
    Code:java
    1. if (cmd.getName().equalsIgnoreCase("news")) {
    2. String news = this.getConfig().getString("messages.news");
    3. if(news != null)
    4. p.sendMessage(news);
    5. else
    6. p.sendMessage("Message not found!");
    7. }

    Code:java
    1. if (cmd.getName().equalsIgnoreCase("news")) {
    2. if(this.getConfig().contains("message.news"))
    3. p.sendMessage(this.getConfig().getString("messages.news"));
    4. else
    5. p.sendMessage("Message not found!");
    6. }
     
Thread Status:
Not open for further replies.

Share This Page