use of com.github.stefvanschie.inventoryframework.gui.GuiItem in project PixliesCoreV2 by PixliesEarth.
the class MarketPane method loadPage.
public void loadPage(MarketCommand.Selection page, UUID uuid) {
fillWith(new ItemStack(Material.AIR));
if (!page.hasSeventhRow()) {
for (int y = 0; y < 6; y++) addItem(new GuiItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE)), 6, y);
}
for (OrderItem item : OrderItem.getItemsOfPage(page.ordinal())) {
OrderBook book = item.getBook();
assert book != null;
ItemBuilder builder = new ItemBuilder(item.getMaterial()).setDisplayName(page.getColor() + item.getName()).addLoreLine("§7Lowest buy offer: §6" + book.getLowestBuyPrice(uuid) + " coins").addLoreLine("§7Highest sell offer: §6" + book.getHighestSellPrice(uuid) + " coins").addLoreLine(" ").addLoreLine("§eClick to buy or sell!");
GuiItem guiItem = new GuiItem(builder.build());
guiItem.setAction(event -> {
User user = User.get(uuid);
OrderProfile profile = (OrderProfile) user.getExtras().get("orderProfile");
profile.openItemPage(item);
});
addItem(guiItem, item.getPosX(), item.getPosY());
}
}
use of com.github.stefvanschie.inventoryframework.gui.GuiItem in project EzMediaCore by MinecraftMediaLibrary.
the class ScreenBuilderGui method handleMaterial.
private void handleMaterial(@NotNull final InventoryClickEvent event) {
final ItemStack stack = event.getCursor();
if (stack == null || stack.getType() == Material.AIR) {
return;
}
this.material = stack.getType();
final Component name = join(noSeparators(), text("Material - ", GOLD), text(this.material.toString(), AQUA));
final GuiItem newStack = ItemBuilder.from(this.material).name(name).build();
this.pane.addItem(newStack, 7, 2);
this.gui.update();
}
use of com.github.stefvanschie.inventoryframework.gui.GuiItem in project oraxen by oraxen.
the class RecipesView method create.
public ChestGui create(final int page, final List<CustomRecipe> filteredRecipes) {
final ChestGui gui = new ChestGui(6, menuTexture);
final CustomRecipe currentRecipe = filteredRecipes.get(page);
// Check if last page
final boolean lastPage = filteredRecipes.size() - 1 == page;
final StaticPane pane = new StaticPane(9, 6);
pane.addItem(new GuiItem(new ItemBuilder(currentRecipe.getResult()).build()), 4, 0);
for (int i = 0; i < currentRecipe.getIngredients().size(); i++) {
final ItemStack itemStack = currentRecipe.getIngredients().get(i);
if (itemStack != null && itemStack.getType() != Material.AIR)
pane.addItem(new GuiItem(itemStack), 3 + i % 3, 2 + i / 3);
}
// Close RecipeShowcase inventory button
pane.addItem(new GuiItem((OraxenItems.getItemById("exit_icon") == null ? new ItemBuilder(Material.BARRIER) : OraxenItems.getItemById("exit_icon")).setDisplayName(Message.EXIT_MENU.toSerializedString()).build(), (event -> event.getWhoClicked().closeInventory())), 4, 5);
// Previous Page button
if (page > 0)
pane.addItem(new GuiItem((OraxenItems.getItemById("arrow_previous_icon") == null ? new ItemBuilder(Material.ARROW) : OraxenItems.getItemById("arrow_previous_icon")).setAmount(page).setDisplayName(ChatColor.YELLOW + "Open page " + page).build(), event -> create(page - 1, filteredRecipes).show(event.getWhoClicked())), 1, 3);
// Next page button
if (!lastPage)
pane.addItem(new GuiItem((OraxenItems.getItemById("arrow_next_icon") == null ? new ItemBuilder(Material.ARROW) : OraxenItems.getItemById("arrow_next_icon")).setAmount(page + 2).setDisplayName(ChatColor.YELLOW + "Open page " + (page + 2)).build(), event -> create(page + 1, filteredRecipes).show(event.getWhoClicked())), 7, 3);
gui.addPane(pane);
gui.setOnGlobalClick(event -> event.setCancelled(true));
return gui;
}
use of com.github.stefvanschie.inventoryframework.gui.GuiItem in project buildinggame by stefvanschie.
the class ReportMenu method playerReportsGui.
/**
* Creates a reports gui where the reports are for the specified player.
*
* @param player the reportee of the reports gui
* @return the gui created
* @since 6.5.0
*/
@NotNull
@Contract(pure = true)
private ChestGui playerReportsGui(@NotNull OfflinePlayer player) {
ChestGui gui = new ChestGui(6, ChatColor.GREEN + player.getName() + "'s reports");
var paginatedPane = new PaginatedPane(0, 0, 9, 5);
int paginatedPaneArea = paginatedPane.getLength() * paginatedPane.getHeight();
for (int page = 0; page < Math.min(1, Math.ceil((double) Report.getReports(player).size() / paginatedPaneArea)); page++) {
var outlinePane = new OutlinePane(0, 0, 9, 5);
for (int i = 0; i < paginatedPaneArea; i++) {
var index = i + (page * paginatedPaneArea);
if (index >= Report.getReports(player).size()) {
break;
}
var report = Report.getReports(player).get(index);
var reportItem = new ItemStack(Material.PAPER);
var reportMeta = reportItem.getItemMeta();
reportMeta.setDisplayName(ChatColor.GOLD + "Report #" + (index + 1));
reportMeta.setLore(Arrays.asList(ChatColor.AQUA + "By: " + report.getReporter().getName(), ChatColor.AQUA + "At: " + report.getDate().format(DateTimeFormatter.RFC_1123_DATE_TIME)));
reportItem.setItemMeta(reportMeta);
outlinePane.addItem(new GuiItem(reportItem, event -> {
HumanEntity clicker = event.getWhoClicked();
if (event.isLeftClick()) {
new BukkitRunnable() {
@Override
public void run() {
try {
var clipboard = report.loadSchematic();
new BukkitRunnable() {
@Override
public void run() {
WorldEditPlugin plugin = WorldEditPlugin.getPlugin(WorldEditPlugin.class);
LocalSession session = plugin.getSession((Player) clicker);
session.setClipboard(new ClipboardHolder(clipboard));
clicker.closeInventory();
MessageManager.getInstance().send(clicker, ChatColor.GREEN + "The schematic has been copied to your clipboard.");
}
}.runTask(Main.getInstance());
} catch (IOException exception) {
exception.printStackTrace();
}
}
}.runTaskAsynchronously(Main.getInstance());
} else if (event.isRightClick()) {
new ConfirmationMenu(ChatColor.GREEN + "Are you sure you want to delete this report?", click -> new BukkitRunnable() {
@Override
public void run() {
if (click == ConfirmationMenu.Response.ACCEPT) {
Report.delete(report);
playerReportsGui((OfflinePlayer) clicker).show(clicker);
} else if (click == ConfirmationMenu.Response.DENY) {
gui.show(clicker);
} else {
throw new IllegalStateException("Unknown confirmation click type");
}
}
}.runTaskLater(Main.getInstance(), 1L)).show(clicker);
}
event.setCancelled(true);
}));
}
paginatedPane.addPane(page, outlinePane);
}
gui.addPane(paginatedPane);
var backItemPane = new OutlinePane(4, 5, 1, 1);
var backItem = new ItemStack(Material.BOOK);
var backMeta = backItem.getItemMeta();
backMeta.setDisplayName(ChatColor.GREEN + "Go back");
backItem.setItemMeta(backMeta);
backItemPane.addItem(new GuiItem(backItem, event -> show(event.getWhoClicked())));
gui.addPane(backItemPane);
if (paginatedPane.getPages() > 1) {
var previousPageItemPane = new OutlinePane(2, 5, 1, 1);
var nextPageItemPane = new OutlinePane(6, 5, 1, 1);
var previousPageItem = new ItemStack(Material.SUGAR_CANE);
var previousPageMeta = previousPageItem.getItemMeta();
previousPageMeta.setDisplayName(ChatColor.GREEN + "Previous page");
previousPageItem.setItemMeta(previousPageMeta);
previousPageItemPane.addItem(new GuiItem(previousPageItem, event -> {
paginatedPane.setPage(paginatedPane.getPage() - 1);
if (paginatedPane.getPage() == 0) {
previousPageItemPane.setVisible(false);
}
nextPageItemPane.setVisible(true);
update();
event.setCancelled(true);
}));
var nextPageItem = new ItemStack(Material.SUGAR_CANE);
var nextPageMeta = nextPageItem.getItemMeta();
nextPageMeta.setDisplayName(ChatColor.GREEN + "Next page");
nextPageItem.setItemMeta(nextPageMeta);
nextPageItemPane.addItem(new GuiItem(nextPageItem, event -> {
paginatedPane.setPage(paginatedPane.getPage() + 1);
if (paginatedPane.getPage() == paginatedPane.getPages() - 1) {
nextPageItemPane.setVisible(false);
}
previousPageItemPane.setVisible(true);
update();
event.setCancelled(true);
}));
gui.addPane(previousPageItemPane);
gui.addPane(nextPageItemPane);
}
return gui;
}
use of com.github.stefvanschie.inventoryframework.gui.GuiItem in project buildinggame by stefvanschie.
the class SubjectMenu method show.
/**
* Opens this gui for the specified human entity
*
* @param humanEntity the human entity to open the gui for
* @since 9.0.3
*/
public void show(@NotNull HumanEntity humanEntity) {
ChestGui gui = new ChestGui(CONFIG.getInt("subject-gui.rows"), MessageManager.translate(MESSAGES.getString("subject-gui.title")));
int rows = gui.getRows();
var paginatedPane = new PaginatedPane(0, 0, 9, rows - 1);
initializePages(gui, paginatedPane);
if (paginatedPane.getPages() == 1 && !CONFIG.getBoolean("subject-gui.close-item.enable")) {
paginatedPane.setHeight(gui.getRows());
initializePages(gui, paginatedPane);
}
gui.addPane(paginatedPane);
if (paginatedPane.getPages() != 1) {
var previousPane = new OutlinePane(2, rows - 1, 1, 1);
var nextPane = new OutlinePane(6, rows - 1, 1, 1);
// previous page
var prevItem = new ItemStack(Material.SUGAR_CANE);
var prevMeta = prevItem.getItemMeta();
prevMeta.setDisplayName(MessageManager.translate(MESSAGES.getString("subject-gui.previous-page.name")));
prevMeta.setLore(MessageManager.translate(MESSAGES.getStringList("subject-gui.previous-page.lores")));
prevItem.setItemMeta(prevMeta);
previousPane.addItem(new GuiItem(prevItem, event -> {
paginatedPane.setPage(paginatedPane.getPage() - 1);
if (paginatedPane.getPage() == 0)
previousPane.setVisible(false);
nextPane.setVisible(true);
update();
event.setCancelled(true);
}));
previousPane.setVisible(false);
gui.addPane(previousPane);
// next page
var nextItem = new ItemStack(Material.SUGAR_CANE);
var nextMeta = nextItem.getItemMeta();
nextMeta.setDisplayName(MessageManager.translate(MESSAGES.getString("subject-gui.next-page.name")));
nextMeta.setLore(MessageManager.translate(MESSAGES.getStringList("subject-gui.next-page.lores")));
nextItem.setItemMeta(nextMeta);
nextPane.addItem(new GuiItem(nextItem, event -> {
paginatedPane.setPage(paginatedPane.getPage() + 1);
if (paginatedPane.getPage() == paginatedPane.getPages() - 1)
nextPane.setVisible(false);
previousPane.setVisible(true);
update();
event.setCancelled(true);
}));
gui.addPane(nextPane);
}
if (CONFIG.getBoolean("subject-gui.close-item.enable")) {
var closePane = new OutlinePane(4, rows - 1, 1, 1);
var closeItem = new ItemStack(Material.BOOK);
var closeMeta = closeItem.getItemMeta();
closeMeta.setDisplayName(MessageManager.translate(MESSAGES.getString("subject-gui.close-menu.name")));
closeMeta.setLore(MessageManager.translate(MESSAGES.getStringList("subject-gui.close-menu.lores")));
closeItem.setItemMeta(closeMeta);
closePane.addItem(new GuiItem(closeItem, event -> {
event.getWhoClicked().closeInventory();
event.setCancelled(true);
}));
gui.addPane(closePane);
}
// additional items
CONFIG.getConfigurationSection("subject-gui.additional-items").getKeys(false).forEach(section -> {
String baseNode = "subject-gui.additional-items." + section;
int x = CONFIG.getInt(baseNode + ".x") - 1;
int y = CONFIG.getInt(baseNode + ".y") - 1;
var pane = new OutlinePane(x, y, 1, 1);
Material material = SettingsManager.getInstance().getMaterial(baseNode + ".id", Material.BARRIER);
var item = new ItemStack(material);
var itemMeta = item.getItemMeta();
var name = MESSAGES.getString(baseNode + ".name");
if (name == null) {
var baseName = item.getType().name().substring(1).replace('_', ' ');
var lowerCaseName = baseName.toLowerCase(Locale.getDefault());
var prettyName = Character.toUpperCase(item.getType().name().charAt(0)) + lowerCaseName;
MESSAGES.set(baseNode + ".name", prettyName);
name = MESSAGES.getString(baseNode + ".name");
}
itemMeta.setDisplayName(MessageManager.translate(name));
var lore = MESSAGES.getStringList(baseNode + ".lore");
if (lore == null) {
MESSAGES.set(baseNode + ".name", new ArrayList<String>());
lore = new ArrayList<>();
}
itemMeta.setLore(MessageManager.translate(lore));
item.setItemMeta(itemMeta);
pane.addItem(new GuiItem(item, event -> event.setCancelled(true)));
gui.addPane(pane);
});
gui.setOnClose(event -> openGuis.remove(gui));
gui.show(humanEntity);
openGuis.put(gui, paginatedPane);
}
Aggregations