Solved It does not give items when it joins... Why?

Discussion in 'Plugin Development' started by ToldiIII, Mar 24, 2018.

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

    ToldiIII

    So, as it is in the title, why not give items when I join the server?
    There is NO error in the console or elsewhere.
    Code:
    Code:
    public class Test extends JavaPlugin implements Listener {
        @Override
        public void onEnable() {
               pm.registerEvents(this, this);
            }
    @EventHandler(priority = EventPriority.HIGH)
        public void onPlJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
    if (getConfig().getBoolean("advanced-join-items.enable")) {
                    Material itype = Material.valueOf(getConfig().getString("advanced-join-items.items.type"));
                        String str1 = getConfig().getString("advanced-join-items.items.type." + itype);
                        if (str1 != null) {
                            Material localMaterial = Material.valueOf(str1);
                            ItemStack localItemStack = new ItemStack(localMaterial);
                            localItemStack.setAmount(getConfig().getInt("advanced-join-items.items.type." + itype + ".amount"));
                            localItemStack.setDurability((short) getConfig().getDouble("advanced-join-items.items.type." + itype + ".durability"));
                            if (getConfig().getBoolean("advanced-join-items.items.type." + itype + ".meta")) {
                                ItemMeta localItemMeta = localItemStack.getItemMeta();
                                String str2 = getConfig().getString("advanced-join-items.items.type." + itype + ".name");
                                if (str2 != null) {
                                    localItemMeta.setDisplayName(str2);
                                }
                                List<String> localList1 = getConfig().getStringList("advanced-join-items.items.type." + itype + ".lore");
                                if ((localList1 != null) && (localList1.size() > 0)) {
                                    localItemMeta.setLore(localList1);
                                }
                                String str3 = getConfig().getString("advanced-join-items.items.type." + itype + ".color");
                                if (str3 != null) {
                                    if ((localItemMeta instanceof LeatherArmorMeta)) {
                                        ((LeatherArmorMeta)localItemMeta).setColor(getColorFromString(str3));
                                    }
                                }
                                localItemStack.setItemMeta(localItemMeta);
                                List<String> localList2 = getConfig().getStringList("advanced-join-items.items.type." + itype + ".enchants");
                                if ((localList2 != null) && (localList2.size() > 0)) {
                                    for (String str4 : localList2) {
                                        String[] arrayOfString = str4.split(":");
                                        if ((localItemStack.getItemMeta() instanceof EnchantmentStorageMeta)) {
                                            EnchantmentStorageMeta localEnchantmentStorageMeta = (EnchantmentStorageMeta)localItemStack.getItemMeta();
                                            localEnchantmentStorageMeta.addStoredEnchant(Enchantment.getByName(arrayOfString[0]), Integer.parseInt(arrayOfString[1]), true);
                                            localItemStack.setItemMeta(localEnchantmentStorageMeta);
                                        } else {
                                            localItemStack.addUnsafeEnchantment(Enchantment.getByName(arrayOfString[0]), Integer.parseInt(arrayOfString[1]));
                                        }
                                    }
                                }
                            }
    p.getInventory().addItem(new ItemStack[] { localItemStack });
    }
    }
    
        private static Color getColorFromString(String paramString) {
            String[] arrayOfString = paramString.split(",");
            return Color.fromRGB(Integer.parseInt(arrayOfString[0]), Integer.parseInt(arrayOfString[1]), Integer.parseInt(arrayOfString[2]));
        }
    }
    Config:
    Code:
    advanced-join-items:
      enable: true
      items:
        type:
          STONE:
            amount: 1
            durability: 0
    As you can, seeing all the elements is not required.
     
    Last edited: Mar 26, 2018
  2. Offline

    JanTuck

    Add some debug lines. The config looks unformatted from tapatalk. So i don’t know if that is the issue.


    Sent from my iPhone using Tapatalk
     
  3. Offline

    KarimAKL

    Is it on purpose that you have "rue" instead of "true" in the config at enable?
     
  4. Offline

    ToldiIII

    @KarimAKL
    I've fixed it, but nothing.
     
  5. Offline

    KarimAKL

    Sorry but i'm new to this and can't help you, i just thought i'd let you know that you wrote rue instead of true. :/
     
    ToldiIII likes this.
  6. Offline

    timtower Administrator Administrator Moderator

    @ToldiIII Did you add print statements to see where it is stopping?
     
  7. Offline

    ToldiIII

    @JanTuck
    I tried that but did not succeed:
    Open! (open)
    try{
    //code
    } catch (Exception ex) {
    ex.printStackTrace();
    }


    Just now...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Mar 26, 2018
  8. Offline

    timtower Administrator Administrator Moderator

    @ToldiIII A try catch is not a print statement, print statements are being used to print something every ... lines to see where it is running.
    After each if statement is the most logical place.
     
    JanTuck likes this.
  9. Offline

    JanTuck

    What did you do? And what was the output?


    Sent from my iPhone using Tapatalk
     
Thread Status:
Not open for further replies.

Share This Page