Hi, I need help with my plugin. It shoulds work but additions and subtractions in integers not works correctly. Here is my code, thanks Code: @EventHandler public void alClickearElInventario(InventoryClickEvent e) { File f1 = new File("plugins/LutorRPG/jugadores/" + e.getWhoClicked().getName() + ".yml"); FileConfiguration f2 = YamlConfiguration.loadConfiguration(f1); int pt = f2.getInt("Puntos_Disponibles"); int nv = f2.getInt("Nivel"); int f = f2.getInt("Fuerza"); int d = f2.getInt("Defensa"); int a = f2.getInt("Agilidad"); int i = f2.getInt("Inteligencia"); int dz = f2.getInt("Destreza"); Player p = (Player)e.getWhoClicked(); if (e.getInventory().getName().equals(inv1.getName())) { e.setCancelled(true); if (e.getCurrentItem() == null) return; if (!e.getCurrentItem().hasItemMeta()) return; if ((e.getCurrentItem().getItemMeta().getDisplayName().contains("Fuerza"))) { e.setCancelled(true); if (pt > 0) { f2.set("Puntos_Disponibles", pt-1); f2.set("Fuerza", f+1); p.playSound(p.getLocation(), Sound.LEVEL_UP, 1, 1); p.closeInventory(); try { f2.save(f1); } catch (IOException ex) { } } } } }
You're defining a new File and FileConfiguration every time someone clicks an inventory! You should be defining and creating these files in the main class passing values through a hierarchy. Also, you're assuming there are values and when it comes to programming assuming is bad.
No. No one here will spoonfeed you code (or give "Example code" which is exactly the same). Look at this to pass objects through a constructor: http://docs.oracle.com/javase/tutorial/java/javaOO/classes.html
All of the values you have defined put them outside of your method in the same class for starters. Secondly I suggest when loading the configuration if these values are not defined then disable the plugin and say the configuration isn't configured correctly then save that old configuration as old_config.yml and make a new one called config.yml (would be better if you also showed the server-owner where they made their mistake or what they didn't define). I am not going to spoon-feed code as you should be learning from primary data in general when it comes to programming.