Development Assistance Odd Listener Behaviour

Discussion in 'Plugin Help/Development/Requests' started by Comt, Mar 5, 2016.

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

    Comt

    Here is the Listener, KnightArmor, ArcherArmor, and SupportArmor are all classes. Knight Armor functions perfectly well but support and archer fail. No errors are thrown in console, and there are no warnings or errors in Eclipse.

    The class should check to see if a player has full custom armor equipped on login (hidden in the lore are §k, §a, and §s. For example: a knight set is just diamond armor with a different recipe, display name, and lore which contains "§k"), then apply all the effects listed as strings in an arraylist stored in each armor class.

    Each armor class has the getBuffEffects method; a static method that returns its buffEffects arraylist.
    Each armor class also has addBuffEffects, which take a string from a config (after ensuring it is non null) and add it to the buffEffects array.

    Potions.potions is a hashmap full of strings and their related PotionEffectType, such as
    potions.put("WITHER", PotionEffectType.WITHER);
    Code:
    public class EffectsLoader implements Listener {
    
        // checks to see if Custom Armor is already equipped
        @EventHandler
        public void onPlayerLogin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
            ItemStack[] armorList = player.getInventory().getArmorContents();
            if (allTheSame(armorList)) {
                if (armorList[0].getItemMeta().getLore().contains("§k")) {
                    for (int i = 0; i < KnightArmor.getBuffEffects().size(); i++) {
                        ArrayList<String> effects = KnightArmor.getBuffEffects();
                        if (effects.get(i).equals("HEALTH_BOOST")) {
                            player.addPotionEffect(
                                    new PotionEffect((Potions.potions.get(effects.get(i))), Integer.MAX_VALUE, 3));
                        } else {
                            player.addPotionEffect(
                                    new PotionEffect((Potions.potions.get(effects.get(i))), Integer.MAX_VALUE, 0));
                        }
                    }
                }
                if (armorList[0].getItemMeta().getLore().contains("§a")) {
                    for (int i = 0; i < ArcherArmor.getBuffEffects().size(); i++) {
                        ArrayList<String> effects = ArcherArmor.getBuffEffects();
                        {
                            player.addPotionEffect(
                                    new PotionEffect((Potions.potions.get(effects.get(i))), Integer.MAX_VALUE, 0));
                        }
                    }
                }
                if (armorList[0].getItemMeta().getLore().contains("§s")) {
                    player.sendMessage("support armor");
                    for (int i = 0; i < SupportArmor.getBuffEffects().size(); i++) {
                        ArrayList<String> effects = SupportArmor.getBuffEffects();
                        player.addPotionEffect(
                                new PotionEffect((Potions.potions.get(effects.get(i))), Integer.MAX_VALUE, 0));
                    }
                }
            }
        }
    
        // if i = 2, all items must have same lore
        private boolean allTheSame(ItemStack[] armorList) {
            int i = 0;
            for (int x = 0; x < armorList.length; x++) {
                if (armorList[x] == null || armorList[x].getType() == Material.AIR) {
                    return false;
                }
            }
            for (int c = 0; c < armorList.length - 1; c++) {
                System.out.println(i);
                if ((armorList[c].getItemMeta().getLore().equals(armorList[c + 1].getItemMeta().getLore()))) {
                    i++;
                }
            }
            if (i == 2) {
                return true;
            }
            return false;
        }
    }
     
  2. Offline

    mine-care

    And that means....?
    I hope you have done the following checks: is armorList[0] null? Does it have itemMeta? Does it have a lore?
    Dont abuse static...
     
Thread Status:
Not open for further replies.

Share This Page