use of com.gmail.stefvanschiedev.buildinggame.utils.Report 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;
}
Aggregations