Read out the maximum value of Monster Spawners in the inventory

Discussion in 'Spigot Plugin Help' started by Rysefoxx, Oct 12, 2019.

  1. My problem is at: " i = i+ Spawner.getAmount(); "

    Codes works perfectly but one thing is horrible:
    After clicking on my ams, I just want to see the maximum value from my inv.

    So for e.g in my inv I have 2 64x Monster Spawners:
    I add it to my AMS and get this message:
    Your AMS received 64x Spawner

    and after it the I get the max value -> Your AMS received 128x Spawner (64 * 2 = 128)

    [​IMG]

    Code (Text):
        if(e.getInventory().getName().equals(Main.AMSName)) {
            if(e.isLeftClick() && !e.isShiftClick()) {
                if(e.getCurrentItem().hasItemMeta() == true) {
                    if(Spawner.contains(p.getUniqueId()+".Spawner Amount")) {
                        Long AlteSpawner = Spawner.getLong(p.getUniqueId()+".Spawner Amount");
                        int i = 0;
                        for(ItemStack Spawner : p.getInventory().getContents()) {
                            if(!(Spawner == null)) {
                                if(Spawner.getType() == Material.MOB_SPAWNER) {
                                    i = i+ Spawner.getAmount();
                                    p.getInventory().remove(Spawner);
                                    Long NeueSpawner = (long) AlteSpawner+i;
                                    InventoryClick.Spawner.set(p.getUniqueId()+".Spawner Amount", NeueSpawner);
                                    InventoryClick.Spawner.save(file);
                                    //p.sendMessage("§e§lAMS-SYSTEM §7>> §7Insgesamt wurden §c"+i+" Spawner §7hinzugefügt"); (( GERMAN VERSION)
                                    p.sendMessage("§e§lAMS-SYSTEM §7>> §7Youre AMS earned §c"+i+" Spawner"); ((ENLISH VERSION))
                                 
                                    p.updateInventory();
                                }
                            }else {
                                return;
                            }
                        }
                    }
                }
            }else {
                p.sendMessage("§e§lAMS-SYSTEM §7>> §cBitte nur die linke Maustaste benutzen!");
                return;
                }
            }else {
                return;
            }
     
  2. You're sending the message in your for loop. Just move it outside of it and it will be fine.