public void openKitSelectorMenu(HumanEntity humanEntity) {
McKits.getInstance(GuiDatabase.class).getGuiInventoryTitle(name -> {
if (name != null) {
invName = name;
}
});
inventory = Bukkit.createInventory(null, 4*9, invName);
McKits.getInstance(GuiDatabase.class).getGuiInventoryItems(items -> {
if (!items.isEmpty()) {
LoadoutConverter.equipDecodedLoadout(inventory, items);
}
});
McKits.getInstance(KitDatabase.class).getKits(kits -> {
try {
for (Kit kit : kits) {
ItemStack itemStack = kit.getIcon();
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setDisplayName(kit.getName());
List<String> lore = new ArrayList<>();
lore.add(kit.getDescription());
lore.add(" ");
if (player.hasPermission("mckits.usekit." + kit.getName())) {
McKits.getInstance(UserDatabase.class).canUseKit(kit.getName(), player, kitCanUse -> {
if (kitCanUse) {
lore.add("Kliknij, aby odebrac!");
} else {
McKits.getInstance(UserDatabase.class).timeLeft(kit.getName(), player, kitTimeLeft -> {
lore.add("Odbierzesz za: " + CooldownFormatters.getRemainingTimeFormatted(kitTimeLeft));
});
}
});
} else {
lore.add("Nie masz permisji do tego zestawu.");
}
itemMeta.setLore(lore);
itemStack.setItemMeta(itemMeta);
inventory.setItem(kit.getSlot(), kit.getIcon());
}
} catch (Exception e) {
player.sendMessage("cos poszlo nie tak ");
}
});
KitSelectorMenuClickListener.addPlayer(player);
humanEntity.openInventory(inventory);
updateInventory(player);
}
private void updateInventory(final Player player) {
new BukkitRunnable() {
@Override
public void run() {
Inventory inventory = ((HumanEntity) player).getOpenInventory().getTopInventory();
if (!KitSelectorMenuClickListener.getList().contains(player.getUniqueId())) {
cancel();
return;
}
// if (!inventory.getType().name().equals(MyGuiDatabase.guiInventoryName)) {
// System.out.println(MyGuiDatabase.guiInventoryName);
// cancel();
// return;
// }
McKits.getInstance(KitDatabase.class).getKits(kits -> {
try {
for (Kit kit : kits) {
ItemStack itemStack = kit.getIcon();
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setDisplayName(kit.getName());
List<String> lore = new ArrayList<>();
lore.add(kit.getDescription());
lore.add(" ");
if (player.hasPermission("mckits.usekit." + kit.getName())) {
McKits.getInstance(UserDatabase.class).canUseKit(kit.getName(), player, kitCanUse -> {
if (kitCanUse) {
lore.add("Kliknij, aby odebrac!");
} else {
McKits.getInstance(UserDatabase.class).timeLeft(kit.getName(), player, kitTimeLeft -> {
lore.add("Odbierzesz za: " + CooldownFormatters.getRemainingTimeFormatted(kitTimeLeft));
});
}
});
} else {
lore.add("Nie masz permisji do tego zestawu.");
}
itemMeta.setLore(lore);
itemStack.setItemMeta(itemMeta);
inventory.setItem(kit.getSlot(), kit.getIcon());
}
} catch (Exception e) {
player.sendMessage("cos poszlo nie tak ");
}
});
}
}.runTaskTimer(McKits.getProvidingPlugin(McKits.class), 0L, 20L);
}