Помогите метод создания голов в инвентаре

  • Автор темы Автор темы Chupaaa
  • Дата начала Дата начала

Chupaaa

Новичок
Пользователь
Баллы
21
Имя в Minecraft
xChupa
Всем привет!
Есть у меня файл, там записано так:
Код:
players:
  Chupaaa:
    points: 2
    lvl: 5
  xChupa:
    points: 33
    lvl: 9
Я "написал" метод, который возвращает голову только Chupaaa.
А мне нужно чтобы он возвращал, и Chupaaa, и xChupa.
Код:
    public ItemStack Top(FileConfiguration file) {
        ConfigurationSection typeSection = file.getConfigurationSection("players");
        if(typeSection == null) return null;
        for (String type : typeSection.getKeys(false)) {
            String owner = typeSection.getString(type);
            ItemStack head = new ItemStack(Material.SKULL_ITEM,1, (short) 3);
            SkullMeta meta = (SkullMeta) head.getItemMeta();
            meta.setOwner(owner);
            head.setItemMeta(meta);
            return head;
    }
        return null;
}
Потом я прописываю в event: inv.addItem(Top(file))
И у меня добавляется в инв только первая голова.
Прошу вашей помощи.
 
Ну правильно, ты заходишь в фор, а возвращаешь только первую голову.
Сделай List<ItemStack> и добавляй туда головы с фора, потом возвращай этот список и со списка уже ставь в инвентарь.
 
Ну правильно, ты заходишь в фор, а возвращаешь только первую голову.
Сделай List<ItemStack> и добавляй туда головы с фора, потом возвращай этот список и со списка уже ставь в инвентарь.
Понял, принял. Спасибо 🙂
 
Код:
   public List<ItemStack> Top(FileConfiguration file) {
       ConfigurationSection typeSection = file.getConfigurationSection("players");
       if(typeSection == null) return null;
       for (String type : typeSection.getKeys(false)) {
           String owner = typeSection.getString(type);
           ItemStack head = new ItemStack(Material.SKULL_ITEM,1, (short) 3);
           SkullMeta meta = (SkullMeta) head.getItemMeta();
           meta.setOwner(owner);
           head.setItemMeta(meta);
            List<ItemStack> trt = new ArrayList<>();
            trt.add(head);
            return trt;
   }
       return null;
}

for(ItemStack heads : Top(file))
inv.addItem(heads);
не помогло, явно я делаю что-то не так.
 
Код:
   public List<ItemStack> Top(FileConfiguration file) {
       ConfigurationSection typeSection = file.getConfigurationSection("players");
       if(typeSection == null) return null;
       for (String type : typeSection.getKeys(false)) {
           String owner = typeSection.getString(type);
           ItemStack head = new ItemStack(Material.SKULL_ITEM,1, (short) 3);
           SkullMeta meta = (SkullMeta) head.getItemMeta();
           meta.setOwner(owner);
           head.setItemMeta(meta);
            List<ItemStack> trt = new ArrayList<>();
            trt.add(head);
            return trt;
   }
       return null;
}

for(ItemStack heads : Top(file))
inv.addItem(heads);
не помогло, явно я делаю что-то не так.
Да, ты делаешь что-то не так. Опять возвращаешь список с одним элементом
 
Код:
   public List<ItemStack> Top(FileConfiguration file) {
       ConfigurationSection typeSection = file.getConfigurationSection("players");
       if(typeSection == null) return null;
       for (String type : typeSection.getKeys(false)) {
           String owner = typeSection.getString(type);
           ItemStack head = new ItemStack(Material.SKULL_ITEM,1, (short) 3);
           SkullMeta meta = (SkullMeta) head.getItemMeta();
           meta.setOwner(owner);
           head.setItemMeta(meta);
            List<ItemStack> trt = new ArrayList<>();
            trt.add(head);
            return trt;
   }
       return null;
}

for(ItemStack heads : Top(file))
inv.addItem(heads);
не помогло, явно я делаю что-то не так.
Включи логику и поймешь что не так.
Создание и возвращение списка должно быть за пределами цикла.
 
Назад
Верх