use of com.github.stefvanschie.inventoryframework.gui.GuiItem in project buildinggame by stefvanschie.
the class ArenaSelection method show.
/**
* {@inheritDoc}
*
* @since 5.6.0
*/
@Override
public void show(@NotNull HumanEntity humanEntity) {
var outlinePane = new OutlinePane(0, 0, 9, 6);
for (Arena arena : ArenaManager.getInstance().getArenas()) {
if (arena.canJoin()) {
continue;
}
var item = new ItemStack(Material.LIME_WOOL);
ItemMeta itemMeta = item.getItemMeta();
itemMeta.setDisplayName(ChatColor.GREEN + arena.getName());
item.setItemMeta(itemMeta);
outlinePane.addItem(new GuiItem(item, event -> {
arena.join((Player) humanEntity);
event.setCancelled(true);
}));
}
addPane(outlinePane);
super.show(humanEntity);
}
use of com.github.stefvanschie.inventoryframework.gui.GuiItem in project buildinggame by stefvanschie.
the class SubjectMenu method initializePages.
/**
* Initializes the pages for this gui
*
* @param gui the gui for which to initialize pages
* @param paginatedPane the paginated pane
* @since 5.6.0
*/
private void initializePages(@NotNull ChestGui gui, @NotNull PaginatedPane paginatedPane) {
paginatedPane.clear();
for (var page = 0; page < Math.ceil((float) subjects.size() / (paginatedPane.getHeight() * paginatedPane.getLength())); page++) {
var pane = new OutlinePane(0, 0, paginatedPane.getLength(), paginatedPane.getHeight());
pane.setOrientation(Orientable.Orientation.valueOf(CONFIG.getString("subject-gui.vote-items.orientation").toUpperCase(Locale.getDefault())));
for (var index = 0; index < paginatedPane.getLength() * paginatedPane.getHeight(); index++) {
if (subjects.size() - 1 < index + (page * paginatedPane.getLength() * paginatedPane.getHeight()))
break;
final String subject = ChatColor.stripColor(subjects.get(index + (page * paginatedPane.getLength() * paginatedPane.getHeight())));
if (getSubjectVote(subject) == null)
votes.add(new SubjectVote(subject, 0));
Material material = SettingsManager.getInstance().getMaterial("subject-gui.vote-items.item.id", Material.BARRIER);
var item = new ItemStack(material);
var meta = item.getItemMeta();
meta.setDisplayName(MessageManager.translate(MESSAGES.getString("subject-gui.subject.name").replace("%subject%", subject)));
var lores = new ArrayList<String>();
MESSAGES.getStringList("subject-gui.subject.lores").forEach(lore -> lores.add(MessageManager.translate(lore.replace("%votes%", getSubjectVote(subject).getVotes() + ""))));
meta.setLore(lores);
item.setItemMeta(meta);
pane.addItem(new GuiItem(item, event -> {
addVote((Player) event.getWhoClicked(), subject);
new BukkitRunnable() {
@Override
public void run() {
initializePages(gui, paginatedPane);
update();
}
}.runTaskLater(Main.getInstance(), 1L);
event.setCancelled(true);
}));
if (CONFIG.getBoolean("subject-gui.percentage-bars.enable")) {
int x;
int y;
if (pane.getOrientation() == Orientable.Orientation.HORIZONTAL) {
x = index % pane.getLength();
y = (int) Math.floor((double) index / pane.getLength());
} else if (pane.getOrientation() == Orientable.Orientation.VERTICAL) {
x = (int) Math.floor((double) index / pane.getHeight());
y = index % pane.getHeight();
} else {
throw new UnsupportedOperationException("Unknown orientation found");
}
int xOffset = CONFIG.getInt("subject-gui.percentage-bars.offset.x");
int yOffset = CONFIG.getInt("subject-gui.percentage-bars.offset.y");
int totalVotes = votes.stream().mapToInt(SubjectVote::getVotes).sum();
int userVotes = getSubjectVote(subject).getVotes();
var percentageBar = new PercentageBar(x + xOffset, y + yOffset, 7, 1);
percentageBar.setPercentage(totalVotes == 0 ? 0 : (float) userVotes / totalVotes);
gui.addPane(percentageBar);
}
}
paginatedPane.addPane(page, pane);
}
}
use of com.github.stefvanschie.inventoryframework.gui.GuiItem in project buildinggame by stefvanschie.
the class TeamSelection method show.
/**
* {@inheritDoc}
*
* @since 5.6.0
*/
@Override
public void show(@NotNull HumanEntity humanEntity) {
YamlConfiguration config = SettingsManager.getInstance().getConfig();
int iteration = 0;
var outlinePane = new OutlinePane(0, 0, 9, (int) Math.max(Math.ceil(arena.getPlots().size() / 9.0), 6));
for (final var plot : arena.getPlots()) {
Material material = SettingsManager.getInstance().getMaterial("team-selection.team." + (iteration + 1) + ".id", Material.BARRIER);
var item = new ItemStack(material);
var itemMeta = item.getItemMeta();
itemMeta.setDisplayName(MessageManager.translate(MESSAGES.getString("team-gui.team.name").replace("%plot%", plot.getId() + "").replace("%plot_players%", plot.getPlayers() + "").replace("%plot_max_players%", plot.getMaxPlayers() + ""), (Player) humanEntity));
List<String> lores = config.getBoolean("team-selection.show-names-as-lore") ? plot.getGamePlayers().stream().map(gamePlayer -> gamePlayer.getPlayer().getName()).collect(Collectors.toList()) : MESSAGES.getStringList("team-gui.team.lores").stream().map(lore -> MessageManager.translate(lore, (Player) humanEntity)).collect(Collectors.toList());
itemMeta.setLore(lores);
item.setItemMeta(itemMeta);
outlinePane.addItem(new GuiItem(item, event -> {
Player p = (Player) event.getWhoClicked();
var previousPlot = arena.getPlot(p);
var gamePlayer = previousPlot.getGamePlayer(p);
if (plot.join(gamePlayer))
previousPlot.leave(gamePlayer);
p.closeInventory();
update();
event.setCancelled(true);
}));
iteration++;
}
addPane(outlinePane);
super.show(humanEntity);
}
use of com.github.stefvanschie.inventoryframework.gui.GuiItem in project EmployMe by DavidTheExplorer.
the class ItemPaletteGUI method createEnglishSearchItem.
private GuiItem createEnglishSearchItem() {
return new GuiItem(new ItemBuilder(Material.NAME_TAG).named(this.messageService.getMessage(INVENTORY_ITEM_PALETTE_ENGLISH_SEARCH_ITEM_NAME).first()).glowing().createCopy(), event -> {
Player player = (Player) event.getWhoClicked();
this.showGoalCustomizationGUIOnClose = false;
player.closeInventory();
Conversation conversation = this.typeConversationFactory.buildConversation(player);
conversation.getContext().setSessionData("goal inventory", this);
conversation.begin();
});
}
use of com.github.stefvanschie.inventoryframework.gui.GuiItem in project EmployMe by DavidTheExplorer.
the class ItemPaletteGUI method createItemsPane.
private Pane createItemsPane() {
Deque<GuiItem> remainingItems = ALL_ITEMS.stream().map(this::toRedirectItem).collect(toCollection(LinkedList::new));
PaginatedPane pane = new PaginatedPane(0, 0, 9, 6, Priority.LOWEST);
for (int i = 0; i < PAGES_AMOUNT; i++) pane.addPane(i, createPage(remainingItems));
pane.setPage(0);
this.itemsPane = pane;
return pane;
}
Aggregations