I've been having a problem with a plugin that I have been trying to right for myself. The yml file gets created correctly, but for some reason I cannot get the plugin to scan the yml for the line of text that I'm looking for. This is the code that I'm using to determine the item name and the corresponding price. Code:java public int getGold(String name, int amount) { if(this.getCustomConfig().contains(name)) { int price1 = this.getCustomConfig().getInt(name); int pay = price1*amount; Bukkit.broadcastMessage("The item display is: "+name); Bukkit.broadcastMessage("The price of which it was sold at: "+pay); return pay; } else { int pay= 0; Bukkit.broadcastMessage("The item display is: "+name); Bukkit.broadcastMessage("The price of which it was sold at: "+pay); return pay; } } My CustomConfig yml file looks like this: Code: #### In here add ITEMNAME: PRICE And yes I understand that normal minecraft items don't have a Display Name, and that it will always return null if I try it. But I am doing this using items that have had their display name changed. So when I run this plugin, I just get a message telling me the correct display name but the price is returning as 0, telling me that the if statement return false. How would I get it to work if I had a yml file similar to: Code: Wooden Sword: 10 Wooden Axe: 5 Light Feather: 1 And so on. How do I get it to read the string "Wooden Sword" and compare to the item that triggered the event, and then later read the integer number after the colon as the price?
Lotsov Try using this: Code: public FileConfiguration getConfig(String configName, String path, JavaPlugin plugin) { if(!configName.contains(".yml")) { configName.replace(configName, configName+".yml"); } File f = new File(plugin.getDataFolder()+File.pathSeparator+path, configName); if(!f.exists()) { return null; }else{ return YamlConfiguration.loadConfiguration(f); } }
I have read it, but my problem is that what if I keep on adding onto the yml file, I would like my plugin to be able to get the Display name of the item and compare it to one of the many keys and then return the value as a price. But from what I understand, which I most likely am wrong, the method shown on the wiki is for when you know what each key name is, that way you only have to fetch the value.
If you could be more clear on what you mean by that, it would be fantastic. EDIT: So instead of doing (this.getCustomConfig().contains(name)) I would use (YamlConfiguration.loadConfiguration(customConfigFile).get(name) != null)? I think I found my problem, I am trying to pass a variable into getint() instead of giving it the path, because of that it kept returning 0 because what it was looking for was not found. The problem is how do I pass in my variable, which is a string, into getint()? EDIT by Moderator: merged posts, please use the edit button instead of double posting.