Kit plugin doesn't work

Discussion in 'Plugin Development' started by CredibleLotus12, Oct 25, 2016.

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

    CredibleLotus12

    Hi guys, i'm making a kit plugin.
    This is the command "kit" in my commands class that implements CommandExecutor:

    Code:
    if (cmd.getName().equalsIgnoreCase("kit")) {
              
                if (!p.isOp()) {
                    p.sendMessage(ChatColor.RED.toString() + ChatColor.BOLD + "AxelKits > " + ChatColor.GRAY + "Non hai ol permesso di usare questo comando!");
                    return true;
                }
              
                if (!p.hasPermission("kits.kit")) {
                    p.sendMessage(ChatColor.RED.toString() + ChatColor.BOLD + "AxelKits > " + ChatColor.GRAY + "Non hai ol permesso di usare questo comando!");
                    return true;
                }
              
                if (args.length == 0) {
                    p.sendMessage(ChatColor.RED.toString() + ChatColor.BOLD + "AxelKits > " + ChatColor.GRAY + "Devi specificare il nome del kit che vuoi ricevere");
                } else {
                  
                    if (KitDataBase.getDataBase().getConfigurationSection("kits." + args[0]) == null) {
                        p.sendMessage(ChatColor.RED.toString() + ChatColor.BOLD + "AxelKits > " + ChatColor.GRAY + "Il kit " + ChatColor.GREEN + args[0] + ChatColor.GRAY + " non esiste!");
                        return true;
                    }
        
                  
                    for (String item : KitDataBase.getDataBase().getStringList("kits." + args[0] + ".components")) {
                      
                        if (KitDataBase.getDataBase().get("kits." + args[0] + "." + item + ".amount") != null) {
                            p.getInventory().addItem(new ItemStack(Material.getMaterial(item.toUpperCase()), KitDataBase.getDataBase().getInt("kits." + args[0] + "." + item + ".amount")));
                            p.sendMessage("item");
                        } else {
                            p.getInventory().addItem(new ItemStack(Material.getMaterial(item.toUpperCase()), 1));
                            p.sendMessage("item");
                        }
                      
                    }
                  
                    DataBaseManager.getDataBase().set("player." + p.getName() + ".kit." + args[0] + ".delay", true);
                    data.saveDataBase();
                    data.reloadDataBase();
                  
                    p.sendMessage(ChatColor.BLUE.toString() + ChatColor.BOLD + "AxelKits > " + ChatColor.GRAY + "Hai ricevuto il kit " + ChatColor.GREEN + args[0] + ChatColor.GRAY + "!");
                  
                    Bukkit.getScheduler().scheduleAsyncDelayedTask(Main.getPlugin(Main.class), new Runnable() {
                        public void run() {
                            DataBaseManager.getDataBase().set("player." + pName + ".kit." + args[0] + ".delay", false);
                            data.saveDataBase();
                            data.reloadDataBase();
                        }
                    }, KitDataBase.getDataBase().getInt("kits." + args[0] + ".delay") * 20);
                  
                    return true;
                }
                
    At the beginning the plugin checks for player permissions and if the player has the right permission and if he has specified a name for the kit that he wants to receive. If a kit has the same name as the one specified the pl iterates trough all the items of a list of string took from a .yml file and then add them to the player inventory. The problem is that the foreach loop "doesn't works" and i tried to figure out what's the problem here a lot of times. I googled too before posting... but it doesn't seem to work.
    please help me.
     
    Last edited: Oct 30, 2016
  2. Offline

    timtower Administrator Administrator Moderator

    @CredibleLotus12 You have a semicolon in your loop, probably stops it from working.
     
  3. Offline

    xelatercero

    If that solved your problem , please mark this thread as Solved, thanks.
     
  4. Offline

    CredibleLotus12

    @timtower Can you please explain better?
     
  5. Offline

    timtower Administrator Administrator Moderator

    @CredibleLotus12
    for (String item : KitDataBase.getDataBase().getStringList("kits." + args[0] + ".components");)
    Look at the last 2 characters
     
  6. Offline

    CredibleLotus12

    @timtower I understood, just asked because i made a bad translation of semicolon. I read semicolumn.
    Thank you i'll try and i'll let you know ;)

    Tried now and it doesn't work... please help me, i really can't figure out why it's not working
     
  7. Offline

    Zombie_Striker

    @CredibleLotus12
    Post your updated code.

    Also, we can't help you unless you tell us what is not working. Is the code not running? Is it not doing something correctly?
     
    danichef likes this.
  8. Offline

    RenditionsRule

    @CredibleLotus12
    At the start, you check if the player is Op. If they aren't op, you return, which stops the code there. May wanna rethink how you've done this...
     
  9. Offline

    CredibleLotus12

    @RenditionsRule Thanks for telling me about the op check, but that's not the matter.
    However @Zombie_Striker i didn't update the code, that's the same, except for the semicolon that @timtower reported to me.
    If you read in my first post i wrote that the foreach loop doesn't work. For doesn't work i mean the the items on the list are not added to my inventory. Thanks for all the support guys.
     
  10. Offline

    Zombie_Striker

    Please test the following bit of code.
    If you place this somewhere in your code (outside of the for loop), this should print the amount of objects in the list. Because of what you are reporting (that it does not loop), that most likely means that there is nothing in the list , so this should print out "0". If that is the case, you have to make sure the list exists and that the list actually contains some values.
     
  11. Offline

    CredibleLotus12

    @Zombie_Striker 0 comes out, but i don't understand why. In the command i write "base" as args[0] and in the yml file the list of the kit base exists!
    Here is the yml file containing the kits:


    Code:
    kits:
      base:
        golden_apple:
          amount: 2
        bread:
          amount: 64
        apple:
          amount: 64
        components:
        - - wood_sword
          - wood_pickaxe
          - wood_axe
          - wood_spade
          - wood_hoe
          - golden_apple
          - bread
          - apple
          - leather_boots
          - leather_leggings
          - leather_chestplate
          - leather_helmet
        delay: 20
        price: 20
     
  12. Offline

    Zombie_Striker

    @CredibleLotus12
    Did you put in all these values? If so, try letting the plugin create the array first and then try re-adding the values.
    [edit]I just noticed this line has two dashes. Is this intentional? This may be why it is not getting the list.
     
Thread Status:
Not open for further replies.

Share This Page