Помогите Обновление GUI из конфига, при нажатии на Entity

HunterGaming

Активный участник
Пользователь
Баллы
96
Имя в Minecraft
sqdFendy
Доброе утро кодеры. У меня возник такой вопрос, как же мне обновить GUI при нажатии на Entity? У меня есть такой код, но он не работает, помогите пожалуйста.
Класс QuestManager
Код:
    public void updateQuests() {
        Set<CustomItemStack> customItemStacks = new HashSet<CustomItemStack>();
        List<String> lores = new ArrayList<String>();
        for (Quest quest : quests) {
            for (CustomItemStack customItemStack : quest.getQuestItems()) {
                customItemStack.getLores().forEach(lore -> lores.add(lore.replace("%bstat%", "30")));
                CustomItemStack itemStack = new CustomItemStack(customItemStack.getItemStack().getType(), customItemStack.getName(), lores);
                customItemStacks.add(itemStack);
            }
            quest.setQuestItems(customItemStacks);
        }
    }
Класс CustomItemStack
Код:
public class CustomItemStack {
   
    private ItemStack itemStack;
    private String name;
    private List<String> lores;
   
    public CustomItemStack(Material material, String name, List<String> lores) {
        this.name = name;
        this.lores = new ArrayList<String>();
       
        itemStack = new ItemStack(material);
        ItemMeta itemMeta = itemStack.getItemMeta();
        itemMeta.setDisplayName(formatColor(this.name));
        lores.forEach(lore -> this.lores.add(formatColor(lore)));
        itemMeta.setLore(this.lores);
        itemStack.setItemMeta(itemMeta);
    }
}
Класс PlayerInteractEntity
Код:
public class PlayerInteractEntity extends AListener {
   
    private QuestManager questManager;
   
    public PlayerInteractEntity(Main instance) {
        super(instance);
        questManager = instance.getQuestManager();
    }

    @EventHandler
    public void onPlayerInteractEntity(PlayerInteractEntityEvent e) {
        LivingEntity livingEntity = (LivingEntity) e.getRightClicked();
        Player p = e.getPlayer();
       
        for (Quest quest : getInstance().getQuestManager().getQuests()) {
            if (livingEntity.getName().equals(quest.getQuestName())) {
                p.updateInventory();
                questManager.updateQuests();
                p.openInventory(quest.getInventory());
                e.setCancelled(true);
            }
        }
    }
}
Обсирания в комментариях не приветствуются!!!
 
Доброе утро кодеры. У меня возник такой вопрос, как же мне обновить GUI при нажатии на Entity? У меня есть такой код, но он не работает, помогите пожалуйста.
Класс QuestManager
Код:
    public void updateQuests() {
        Set<CustomItemStack> customItemStacks = new HashSet<CustomItemStack>();
        List<String> lores = new ArrayList<String>();
        for (Quest quest : quests) {
            for (CustomItemStack customItemStack : quest.getQuestItems()) {
                customItemStack.getLores().forEach(lore -> lores.add(lore.replace("%bstat%", "30")));
                CustomItemStack itemStack = new CustomItemStack(customItemStack.getItemStack().getType(), customItemStack.getName(), lores);
                customItemStacks.add(itemStack);
            }
            quest.setQuestItems(customItemStacks);
        }
    }
Класс CustomItemStack
Код:
public class CustomItemStack {
  
    private ItemStack itemStack;
    private String name;
    private List<String> lores;
  
    public CustomItemStack(Material material, String name, List<String> lores) {
        this.name = name;
        this.lores = new ArrayList<String>();
      
        itemStack = new ItemStack(material);
        ItemMeta itemMeta = itemStack.getItemMeta();
        itemMeta.setDisplayName(formatColor(this.name));
        lores.forEach(lore -> this.lores.add(formatColor(lore)));
        itemMeta.setLore(this.lores);
        itemStack.setItemMeta(itemMeta);
    }
}
Класс PlayerInteractEntity
Код:
public class PlayerInteractEntity extends AListener {
  
    private QuestManager questManager;
  
    public PlayerInteractEntity(Main instance) {
        super(instance);
        questManager = instance.getQuestManager();
    }

    @EventHandler
    public void onPlayerInteractEntity(PlayerInteractEntityEvent e) {
        LivingEntity livingEntity = (LivingEntity) e.getRightClicked();
        Player p = e.getPlayer();
      
        for (Quest quest : getInstance().getQuestManager().getQuests()) {
            if (livingEntity.getName().equals(quest.getQuestName())) {
                p.updateInventory();
                questManager.updateQuests();
                p.openInventory(quest.getInventory());
                e.setCancelled(true);
            }
        }
    }
}
Обсирания в комментариях не приветствуются!!!
Для чего в яве был добавлен diamond operator?
 
Во-первых, хотелось бы увидить класс Quest.
Во-вторых, объясни подробнее, что должно быть в 'инвентаре'
Класс Quest
Код:
    private String questName;
    private int questSizeInv;
    private Set<CustomItemStack> questItems;
    private Inventory questInv;
   
    public Quest(Location questLoc, EntityType questType, String questName, int questSizeInv, Set<CustomItemStack> questItems) {
        this.questName = questName;
        this.questSizeInv = questSizeInv;
        this.questItems = questItems;
        questInv = Bukkit.createInventory(this, questSizeInv, questName);
        questItems.forEach(questItem -> questInv.addItem(questItem.getItemStack()));
       
        LivingEntity livingEntity = (LivingEntity) questLoc.getWorld().spawnEntity(questLoc, questType);
        livingEntity.setCustomName(questName);
    }
Геттеры/сеттеры, думаю тебе не нужны..
 
Класс Quest
Код:
    private String questName;
    private int questSizeInv;
    private Set<CustomItemStack> questItems;
    private Inventory questInv;
  
    public Quest(Location questLoc, EntityType questType, String questName, int questSizeInv, Set<CustomItemStack> questItems) {
        this.questName = questName;
        this.questSizeInv = questSizeInv;
        this.questItems = questItems;
        questInv = Bukkit.createInventory(this, questSizeInv, questName);
        questItems.forEach(questItem -> questInv.addItem(questItem.getItemStack()));
      
        LivingEntity livingEntity = (LivingEntity) questLoc.getWorld().spawnEntity(questLoc, questType);
        livingEntity.setCustomName(questName);
    }
Геттеры/сеттеры, думаю тебе не нужны..
Так че не работает то?
 
Назад
Верх