- Баллы
- 96
- Имя в Minecraft
- sqdFendy
Доброе утро кодеры. У меня возник такой вопрос, как же мне обновить GUI при нажатии на Entity? У меня есть такой код, но он не работает, помогите пожалуйста.
Класс QuestManager
Класс CustomItemStack
Класс PlayerInteractEntity
Обсирания в комментариях не приветствуются!!!
Класс 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);
}
}
Код:
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);
}
}
Код:
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);
}
}
}
}