Some help please

Discussion in 'Plugin Development' started by Simme_15, Mar 16, 2016.

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

    Simme_15

    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) { }
                    }
                }
            }
      }
     
  2. Offline

    Zombie_Striker

    @Simme_15
    What do you mean "not works correctly"? Can you explain? Where are you adding/subtracting?
     
  3. Offline

    MajorSkillage

    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.
     
  4. Offline

    Simme_15

    @MajorSkillage
    Thanks for your answer, but, can you give an example? I would appreciate :)
     
  5. Offline

    Zombie_Striker

  6. Offline

    MajorSkillage

    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.
     
    Zombie_Striker likes this.
Thread Status:
Not open for further replies.

Share This Page