Sorry if this is something stupid, but when attempting to get something from a config file and send it to the player, it just send the word "false" to the player. here is my code if it helps: Spoiler (Move your mouse to the spoiler area to reveal the content) Show Spoiler Hide Spoiler Code:java public class EventListener implements Listener { public EasyAnswers plugin; public EventListener(EasyAnswers plugin) { this.plugin = plugin; } @EventHandler public void onChat(AsyncPlayerChatEvent event) { if (plugin.getConfig().contains( event.getMessage().toLowerCase().replaceAll(" ", "_"))) { event.setCancelled(true); event.getPlayer().sendMessage( plugin.getConfig().getString(event.getMessage().toLowerCase() .replaceAll(" ", "_")+".answer")); } } }
mattrick16 Maybe have an else statement to allow a chat message to be sent if it doesn't contain "_" ?
That's not the problem. It allows the event anyway, but when the criteria is met, the message sent is "false".
mattrick16 That seems really strange... Do you mind posting the config? I'm not even sure what you are trying to do.
AoH_Ruthless Code: can_i_be_op: answer: No The Gaming Grunts 1Rogue Nope it exists.....printed out variables, they were correct. It just sends "false" to the player which makes no sense as I never even added a possibility for that to happen :/
mattrick16 Well, idk if this has anything to do with the problem, but you don't need to have an underscore in the config ("_" <--this thing). You can just put normal spaces. So in your code, you don't have to try to replace anything. You can simply do getConfig().getString("some string") and what-not.
Try putting No in quotes. Its looking for a string, and it being in quotes says "Hey! this is a string!". I'm not sure if YML likes the double quotes " or single quotes '. Code: can_i_be_op: answer: "No"
When .getString() attempts to get a value of "No", it will return false. Looking into the reason now. (Tested externally and confirmed) Edit: Putting the word in quotes works. This isn't a bukkit issue, yaml considers "no" as a false value. Either quote is fine. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Good to know for future reference. Double quote and single quotes essentially do the same thing. I don't believe there is a difference. EDIT: I got ninja'ed
There's way better ways to do what you're trying to do, but... Without quotes, Bukkit will interpret that field as a boolean and default to returning "false" when getString is called. Surrounding the answer with quotes will solidify it as a String and return "no" like you expect.
Just a follow up question, I am also trying to replace question mark characters, but using just a "?" throws an error, and using a double backslash question mark ("\\?") also doesn't work. Any ideas? AoH_Ruthless 1Rogue
Not quite, YAML itself returns a b0olean value. This is independant of bukkit Again, in YAML, single or double quotes make no difference. Put it in quotes or use a "\" in double quotes. Alternately use the unicode value of the character.
Technically, yes... However, the object returned by Bukkit's MemorySection.getString does not get casted to String, but instead calls toString() from the object. This is kind of a stretch, as you would expect a method called getString would either return null or log a ClassCastException in the event that a requested field isn't a String. I'm not really sure why it doesn't do this, but it's probably so that plugin makers can conveniently readout configurations to administrators without having to write too many statements.
What? This makes perfect sense. (Primative) booleans can have two values: true or false. When you cast a boolean to a string it can only be two things, so it returns "false" when you get the string value.