✈️ migrate admin guis to new gui template/format

Took 22 minutes
This commit is contained in:
Kiran Hart 2024-04-15 15:41:32 -04:00
parent 285a118367
commit f50012a2f4
No known key found for this signature in database
GPG Key ID: 5F36C7BC79D3EBC3
3 changed files with 108 additions and 132 deletions

View File

@ -20,69 +20,48 @@ package ca.tweetzy.auctionhouse.guis.admin;
import ca.tweetzy.auctionhouse.AuctionHouse; import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.auction.AuctionedItem; import ca.tweetzy.auctionhouse.auction.AuctionedItem;
import ca.tweetzy.auctionhouse.guis.AbstractPlaceholderGui; import ca.tweetzy.auctionhouse.guis.abstraction.AuctionPagedGUI;
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
import ca.tweetzy.auctionhouse.settings.Settings; import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.utils.TextUtils; import ca.tweetzy.core.gui.events.GuiClickEvent;
import org.bukkit.Bukkit; import ca.tweetzy.flight.utils.QuickItem;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public final class GUIAdminExpired extends AbstractPlaceholderGui { public final class GUIAdminExpired extends AuctionPagedGUI<AuctionedItem> {
final OfflinePlayer targetUser; final OfflinePlayer targetUser;
List<AuctionedItem> items;
public GUIAdminExpired(Player viewer, OfflinePlayer targetUser) { public GUIAdminExpired(Player viewer, OfflinePlayer targetUser) {
super(viewer); super(null, viewer, Settings.GUI_EXPIRED_ITEMS_ADMIN_TITLE.getString(), 6, new ArrayList<>(AuctionHouse.getInstance().getAuctionItemManager().getItems().values().stream().filter(item -> item.isExpired() && item.getOwner().equals(targetUser.getUniqueId()) && !AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().containsKey(item.getId())).collect(Collectors.toList())));
this.targetUser = targetUser; this.targetUser = targetUser;
this.items = AuctionHouse.getInstance().getAuctionItemManager().getItems().values().stream().filter(item -> item.isExpired() && item.getOwner().equals(targetUser.getUniqueId())).collect(Collectors.toList());
setTitle(Settings.GUI_EXPIRED_ITEMS_ADMIN_TITLE.getString());
setRows(6);
setAcceptsItems(false); setAcceptsItems(false);
draw(); draw();
} }
private void draw() { @Override
reset(); protected void drawFixed() {
applyBackExit();
}
setButton(5, 4, ConfigurationItemHelper.createConfigurationItem(this.player, Settings.GUI_CLOSE_BTN_ITEM.getString(), Settings.GUI_CLOSE_BTN_NAME.getString(), Settings.GUI_CLOSE_BTN_LORE.getStringList(), null), e -> e.gui.close()); @Override
protected void prePopulate() {
this.items.sort(Comparator.comparing(AuctionedItem::getExpiresAt).reversed());
}
AuctionHouse.newChain().asyncFirst(() -> this.items.stream().sorted(Comparator.comparingLong(AuctionedItem::getExpiresAt).reversed()).skip((page - 1) * 45L).limit(45).collect(Collectors.toList())).asyncLast(data -> { @Override
pages = (int) Math.max(1, Math.ceil(this.items.size() / (double) 45)); protected ItemStack makeDisplayItem(AuctionedItem auctionedItem) {
setPrevPage(5, 3, getPreviousPageItem()); final ItemStack item = auctionedItem.getItem().clone();
setNextPage(5, 5, getNextPageItem()); return QuickItem.of(item).lore(Settings.GUI_EXPIRED_ITEMS_ADMIN_ITEMS_LORE.getStringList()).make();
}
setOnPage(e -> { @Override
draw(); protected void onClick(AuctionedItem item, GuiClickEvent event) {
}); AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(item);
event.manager.showGUI(event.player, new GUIAdminExpired(event.player, this.targetUser));
int slot = 0;
for (AuctionedItem auctionItem : data) {
ItemStack item = auctionItem.getItem().clone();
ItemMeta meta = item.hasItemMeta() ? item.getItemMeta() : Bukkit.getItemFactory().getItemMeta(item.getType());
List<String> lore = (meta.hasLore()) ? meta.getLore() : new ArrayList<>();
lore.addAll(TextUtils.formatText(Settings.GUI_EXPIRED_ITEMS_ADMIN_ITEMS_LORE.getStringList()));
meta.setLore(lore);
item.setItemMeta(meta);
setButton(slot++, item, ClickType.LEFT, e -> {
AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(auctionItem);
e.manager.showGUI(e.player, new GUIAdminExpired(e.player, this.targetUser));
});
}
}).execute();
} }
} }

View File

@ -27,13 +27,12 @@ import ca.tweetzy.auctionhouse.auction.AuctionedItem;
import ca.tweetzy.auctionhouse.auction.enums.AdminAction; import ca.tweetzy.auctionhouse.auction.enums.AdminAction;
import ca.tweetzy.auctionhouse.auction.enums.PaymentReason; import ca.tweetzy.auctionhouse.auction.enums.PaymentReason;
import ca.tweetzy.auctionhouse.events.AuctionAdminEvent; import ca.tweetzy.auctionhouse.events.AuctionAdminEvent;
import ca.tweetzy.auctionhouse.guis.AbstractPlaceholderGui;
import ca.tweetzy.auctionhouse.guis.GUIAuctionHouse; import ca.tweetzy.auctionhouse.guis.GUIAuctionHouse;
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper; import ca.tweetzy.auctionhouse.guis.abstraction.AuctionBaseGUI;
import ca.tweetzy.auctionhouse.settings.Settings; import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.hooks.EconomyManager; import ca.tweetzy.core.hooks.EconomyManager;
import ca.tweetzy.core.utils.PlayerUtils; import ca.tweetzy.core.utils.PlayerUtils;
import ca.tweetzy.core.utils.TextUtils; import ca.tweetzy.flight.utils.QuickItem;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
@ -45,32 +44,39 @@ import org.bukkit.entity.Player;
* Time Created: 3:04 p.m. * Time Created: 3:04 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise * Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/ */
public class GUIAdminItem extends AbstractPlaceholderGui { public class GUIAdminItem extends AuctionBaseGUI {
private final AuctionPlayer auctionPlayer; private final AuctionPlayer auctionPlayer;
private final AuctionedItem auctionItem; private final AuctionedItem auctionItem;
public GUIAdminItem(AuctionPlayer auctionPlayer, AuctionedItem auctionItem) { public GUIAdminItem(AuctionPlayer auctionPlayer, AuctionedItem auctionItem) {
super(auctionPlayer); super(new GUIAuctionHouse(auctionPlayer), auctionPlayer.getPlayer(), Settings.GUI_ITEM_ADMIN_TITLE.getString(), 3);
this.auctionPlayer = auctionPlayer; this.auctionPlayer = auctionPlayer;
this.auctionItem = auctionItem; this.auctionItem = auctionItem;
setTitle(TextUtils.formatText(Settings.GUI_ITEM_ADMIN_TITLE.getString()));
setDefaultItem(ConfigurationItemHelper.createConfigurationItem(this.player, Settings.GUI_ITEM_ADMIN_BG_ITEM.getString()));
setRows(3);
setAcceptsItems(false); setAcceptsItems(false);
setUseLockedCells(true); setUseLockedCells(true);
setOnClose(close -> close.manager.showGUI(close.player, new GUIAuctionHouse(this.auctionPlayer))); setOnClose(close -> close.manager.showGUI(close.player, new GUIAuctionHouse(this.auctionPlayer)));
draw(); draw();
} }
private void draw() { @Override
protected void draw() {
applyBackExit();
drawReturnButton();
drawClaimButton();
drawDeleteButton();
drawCopyButton();
}
private void drawReturnButton() {
if (Settings.ADMIN_OPTION_SHOW_RETURN_ITEM.getBoolean()) if (Settings.ADMIN_OPTION_SHOW_RETURN_ITEM.getBoolean())
setButton(1, 1, ConfigurationItemHelper.createConfigurationItem(this.player, Settings.GUI_ITEM_ADMIN_ITEMS_RETURN_ITEM.getString(), Settings.GUI_ITEM_ADMIN_ITEMS_RETURN_NAME.getString(), Settings.GUI_ITEM_ADMIN_ITEMS_RETURN_LORE.getStringList(), null), e -> { setButton(1, 1, QuickItem.of(Settings.GUI_ITEM_ADMIN_ITEMS_RETURN_ITEM.getString()).name(Settings.GUI_ITEM_ADMIN_ITEMS_RETURN_NAME.getString()).lore(Settings.GUI_ITEM_ADMIN_ITEMS_RETURN_LORE.getStringList()).make(), click -> {
if (!e.player.hasPermission("auctionhouse.admin.returnitem")) return;
AuctionAdminEvent event = new AuctionAdminEvent(createLog(e.player, AdminAction.RETURN_ITEM)); if (!click.player.hasPermission("auctionhouse.admin.returnitem")) return;
AuctionAdminEvent event = new AuctionAdminEvent(createLog(click.player, AdminAction.RETURN_ITEM));
Bukkit.getServer().getPluginManager().callEvent(event); Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return; if (event.isCancelled()) return;
@ -83,47 +89,36 @@ public class GUIAdminItem extends AbstractPlaceholderGui {
final OfflinePlayer oldBidder = Bukkit.getOfflinePlayer(this.auctionItem.getHighestBidder()); final OfflinePlayer oldBidder = Bukkit.getOfflinePlayer(this.auctionItem.getHighestBidder());
if (Settings.STORE_PAYMENTS_FOR_MANUAL_COLLECTION.getBoolean()) if (Settings.STORE_PAYMENTS_FOR_MANUAL_COLLECTION.getBoolean())
AuctionHouse.getInstance().getDataManager().insertAuctionPayment(new AuctionPayment( AuctionHouse.getInstance().getDataManager().insertAuctionPayment(new AuctionPayment(oldBidder.getUniqueId(), auctionItem.getCurrentPrice(), auctionItem.getItem(), click.player.getName(), PaymentReason.ADMIN_REMOVED), null);
oldBidder.getUniqueId(), else EconomyManager.deposit(oldBidder, auctionItem.getCurrentPrice());
auctionItem.getCurrentPrice(),
auctionItem.getItem(),
e.player.getName(),
PaymentReason.ADMIN_REMOVED
), null);
else
EconomyManager.deposit(oldBidder, auctionItem.getCurrentPrice());
if (oldBidder.isOnline()) if (oldBidder.isOnline())
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyadd").processPlaceholder("player_balance", AuctionAPI.getInstance().formatNumber(EconomyManager.getBalance(oldBidder))).processPlaceholder("price", AuctionAPI.getInstance().formatNumber(this.auctionItem.getCurrentPrice())).sendPrefixedMessage(oldBidder.getPlayer()); AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyadd").processPlaceholder("player_balance", AuctionAPI.getInstance().formatNumber(EconomyManager.getBalance(oldBidder))).processPlaceholder("price", AuctionAPI.getInstance().formatNumber(this.auctionItem.getCurrentPrice())).sendPrefixedMessage(oldBidder.getPlayer());
} }
// AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(this.auctionItem); click.gui.close();
e.gui.close();
}); });
}
private void drawClaimButton() {
if (Settings.ADMIN_OPTION_SHOW_CLAIM_ITEM.getBoolean()) if (Settings.ADMIN_OPTION_SHOW_CLAIM_ITEM.getBoolean())
setButton(1, 3, ConfigurationItemHelper.createConfigurationItem(this.player, Settings.GUI_ITEM_ADMIN_ITEMS_CLAIM_ITEM.getString(), Settings.GUI_ITEM_ADMIN_ITEMS_CLAIM_NAME.getString(), Settings.GUI_ITEM_ADMIN_ITEMS_CLAIM_LORE.getStringList(), null), e -> { setButton(1, 3, QuickItem.of(Settings.GUI_ITEM_ADMIN_ITEMS_CLAIM_ITEM.getString()).name(Settings.GUI_ITEM_ADMIN_ITEMS_CLAIM_NAME.getString()).lore(Settings.GUI_ITEM_ADMIN_ITEMS_CLAIM_LORE.getStringList()).make(), click -> {
if (!e.player.hasPermission("auctionhouse.admin.claimitem")) return;
AuctionAdminEvent event = new AuctionAdminEvent(createLog(e.player, AdminAction.CLAIM_ITEM)); if (!click.player.hasPermission("auctionhouse.admin.claimitem")) return;
AuctionAdminEvent event = new AuctionAdminEvent(createLog(click.player, AdminAction.CLAIM_ITEM));
Bukkit.getServer().getPluginManager().callEvent(event); Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return; if (event.isCancelled()) return;
PlayerUtils.giveItem(e.player, this.auctionItem.getItem()); PlayerUtils.giveItem(click.player, this.auctionItem.getItem());
if (Settings.BIDDING_TAKES_MONEY.getBoolean() && !this.auctionItem.getHighestBidder().equals(this.auctionItem.getOwner())) { if (Settings.BIDDING_TAKES_MONEY.getBoolean() && !this.auctionItem.getHighestBidder().equals(this.auctionItem.getOwner())) {
final OfflinePlayer oldBidder = Bukkit.getOfflinePlayer(this.auctionItem.getHighestBidder()); final OfflinePlayer oldBidder = Bukkit.getOfflinePlayer(this.auctionItem.getHighestBidder());
if (Settings.STORE_PAYMENTS_FOR_MANUAL_COLLECTION.getBoolean()) if (Settings.STORE_PAYMENTS_FOR_MANUAL_COLLECTION.getBoolean())
AuctionHouse.getInstance().getDataManager().insertAuctionPayment(new AuctionPayment( AuctionHouse.getInstance().getDataManager().insertAuctionPayment(new AuctionPayment(oldBidder.getUniqueId(), auctionItem.getCurrentPrice(), auctionItem.getItem(), click.player.getName(), PaymentReason.ADMIN_REMOVED), null);
oldBidder.getUniqueId(), else EconomyManager.deposit(oldBidder, auctionItem.getCurrentPrice());
auctionItem.getCurrentPrice(),
auctionItem.getItem(),
e.player.getName(),
PaymentReason.ADMIN_REMOVED
), null);
else
EconomyManager.deposit(oldBidder, auctionItem.getCurrentPrice());
if (oldBidder.isOnline()) if (oldBidder.isOnline())
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyadd").processPlaceholder("player_balance", AuctionAPI.getInstance().formatNumber(EconomyManager.getBalance(oldBidder))).processPlaceholder("price", AuctionAPI.getInstance().formatNumber(this.auctionItem.getCurrentPrice())).sendPrefixedMessage(oldBidder.getPlayer()); AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyadd").processPlaceholder("player_balance", AuctionAPI.getInstance().formatNumber(EconomyManager.getBalance(oldBidder))).processPlaceholder("price", AuctionAPI.getInstance().formatNumber(this.auctionItem.getCurrentPrice())).sendPrefixedMessage(oldBidder.getPlayer());
@ -131,13 +126,16 @@ public class GUIAdminItem extends AbstractPlaceholderGui {
} }
AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(this.auctionItem); AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(this.auctionItem);
e.gui.close(); click.gui.close();
}); });
}
private void drawDeleteButton() {
if (Settings.ADMIN_OPTION_SHOW_DELETE_ITEM.getBoolean()) if (Settings.ADMIN_OPTION_SHOW_DELETE_ITEM.getBoolean())
setButton(1, 5, ConfigurationItemHelper.createConfigurationItem(this.player, Settings.GUI_ITEM_ADMIN_ITEMS_DELETE_ITEM.getString(), Settings.GUI_ITEM_ADMIN_ITEMS_DELETE_NAME.getString(), Settings.GUI_ITEM_ADMIN_ITEMS_DELETE_LORE.getStringList(), null), e -> { setButton(1, 5, QuickItem.of(Settings.GUI_ITEM_ADMIN_ITEMS_DELETE_ITEM.getString()).name(Settings.GUI_ITEM_ADMIN_ITEMS_DELETE_NAME.getString()).lore(Settings.GUI_ITEM_ADMIN_ITEMS_DELETE_LORE.getStringList()).make(), click -> {
if (!e.player.hasPermission("auctionhouse.admin.deleteitem")) return;
AuctionAdminEvent event = new AuctionAdminEvent(createLog(e.player, AdminAction.DELETE_ITEM)); if (!click.player.hasPermission("auctionhouse.admin.deleteitem")) return;
AuctionAdminEvent event = new AuctionAdminEvent(createLog(click.player, AdminAction.DELETE_ITEM));
Bukkit.getServer().getPluginManager().callEvent(event); Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return; if (event.isCancelled()) return;
@ -149,7 +147,7 @@ public class GUIAdminItem extends AbstractPlaceholderGui {
oldBidder.getUniqueId(), oldBidder.getUniqueId(),
auctionItem.getCurrentPrice(), auctionItem.getCurrentPrice(),
auctionItem.getItem(), auctionItem.getItem(),
e.player.getName(), click.player.getName(),
PaymentReason.ADMIN_REMOVED PaymentReason.ADMIN_REMOVED
), null); ), null);
else else
@ -161,36 +159,31 @@ public class GUIAdminItem extends AbstractPlaceholderGui {
} }
AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(this.auctionItem); AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(this.auctionItem);
e.gui.close(); click.gui.close();
}); });
}
private void drawCopyButton() {
if (Settings.ADMIN_OPTION_SHOW_COPY_ITEM.getBoolean()) if (Settings.ADMIN_OPTION_SHOW_COPY_ITEM.getBoolean())
setButton(1, 7, ConfigurationItemHelper.createConfigurationItem(this.player, Settings.GUI_ITEM_ADMIN_ITEMS_COPY_ITEM.getString(), Settings.GUI_ITEM_ADMIN_ITEMS_COPY_NAME.getString(), Settings.GUI_ITEM_ADMIN_ITEMS_COPY_LORE.getStringList(), null), e -> { setButton(1, 7, QuickItem.of(Settings.GUI_ITEM_ADMIN_ITEMS_COPY_ITEM.getString()).name(Settings.GUI_ITEM_ADMIN_ITEMS_COPY_NAME.getString()).lore(Settings.GUI_ITEM_ADMIN_ITEMS_COPY_LORE.getStringList()).make(), click -> {
if (!e.player.hasPermission("auctionhouse.admin.copyitem")) return;
if (Settings.ITEM_COPY_REQUIRES_GMC.getBoolean() && e.player.getGameMode() != GameMode.CREATIVE) { if (!click.player.hasPermission("auctionhouse.admin.copyitem")) return;
AuctionHouse.getInstance().getLocale().getMessage("general.requires creative").sendPrefixedMessage(e.player); if (Settings.ITEM_COPY_REQUIRES_GMC.getBoolean() && click.player.getGameMode() != GameMode.CREATIVE) {
AuctionHouse.getInstance().getLocale().getMessage("general.requires creative").sendPrefixedMessage(click.player);
return; return;
} }
AuctionAdminEvent event = new AuctionAdminEvent(createLog(e.player, AdminAction.COPY_ITEM)); AuctionAdminEvent event = new AuctionAdminEvent(createLog(click.player, AdminAction.COPY_ITEM));
Bukkit.getServer().getPluginManager().callEvent(event); Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return; if (event.isCancelled()) return;
PlayerUtils.giveItem(e.player, this.auctionItem.getItem()); PlayerUtils.giveItem(click.player, this.auctionItem.getItem());
e.gui.close(); click.gui.close();
}); });
} }
private AuctionAdminLog createLog(final Player player, AdminAction adminAction) { private AuctionAdminLog createLog(final Player player, AdminAction adminAction) {
return new AuctionAdminLog( return new AuctionAdminLog(player.getUniqueId(), player.getName(), auctionItem.getOwner(), auctionItem.getOwnerName(), auctionItem.getItem(), auctionItem.getId(), adminAction, System.currentTimeMillis());
player.getUniqueId(),
player.getName(),
auctionItem.getOwner(),
auctionItem.getOwnerName(),
auctionItem.getItem(),
auctionItem.getId(),
adminAction,
System.currentTimeMillis()
);
} }
} }

View File

@ -20,16 +20,19 @@ package ca.tweetzy.auctionhouse.guis.admin;
import ca.tweetzy.auctionhouse.api.AuctionAPI; import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionAdminLog; import ca.tweetzy.auctionhouse.auction.AuctionAdminLog;
import ca.tweetzy.auctionhouse.guis.AbstractPlaceholderGui; import ca.tweetzy.auctionhouse.guis.abstraction.AuctionPagedGUI;
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper; import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
import ca.tweetzy.auctionhouse.settings.Settings; import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.gui.events.GuiClickEvent;
import ca.tweetzy.core.utils.TextUtils; import ca.tweetzy.core.utils.TextUtils;
import ca.tweetzy.flight.utils.QuickItem;
import ca.tweetzy.flight.utils.Replacer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* The current file has been created by Kiran Hart * The current file has been created by Kiran Hart
@ -37,41 +40,42 @@ import java.util.stream.Collectors;
* Time Created: 2:11 p.m. * Time Created: 2:11 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise * Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/ */
public final class GUIAdminLogs extends AbstractPlaceholderGui { public final class GUIAdminLogs extends AuctionPagedGUI<AuctionAdminLog> {
final List<AuctionAdminLog> logs;
public GUIAdminLogs(Player player, List<AuctionAdminLog> logs) { public GUIAdminLogs(Player player, List<AuctionAdminLog> logs) {
super(player); super(null, player, Settings.GUI_LOGS_TITLE.getString(), 6, logs);
this.logs = logs;
setTitle(TextUtils.formatText(Settings.GUI_LOGS_TITLE.getString()));
setRows(6);
setAcceptsItems(false); setAcceptsItems(false);
draw(); draw();
} }
private void draw() { @Override
reset(); protected void drawFixed() {
applyBackExit();
}
pages = (int) Math.max(1, Math.ceil(this.logs.size() / (double) 45)); @Override
setPrevPage(5, 3, getPreviousPageItem()); protected void prePopulate() {
setNextPage(5, 5, getNextPageItem()); this.items.sort(Comparator.comparingLong(AuctionAdminLog::getTime).reversed());
setOnPage(e -> draw()); }
int slot = 0; @Override
List<AuctionAdminLog> data = this.logs.stream().sorted(Comparator.comparingLong(AuctionAdminLog::getTime).reversed()).skip((page - 1) * 45L).limit(45).collect(Collectors.toList()); protected ItemStack makeDisplayItem(AuctionAdminLog log) {
return QuickItem
.of(log.getItem())
.name(AuctionAPI.getInstance().getItemName(log.getItem()))
.lore(Replacer.replaceVariables(Settings.GUI_LOGS_LORE.getStringList(),
"admin", log.getAdminName(),
"target", log.getTargetName(),
"admin_uuid", log.getAdmin(),
"target_uuid", log.getTarget(),
"item_id", log.getItemId(),
"admin_action", log.getAdminAction().getTranslation(),
"admin_log_date", AuctionAPI.getInstance().convertMillisToDate(log.getTime())
)).make();
}
@Override
protected void onClick(AuctionAdminLog object, GuiClickEvent clickEvent) {
for (AuctionAdminLog log : data) {
setItem(slot++, ConfigurationItemHelper.createConfigurationItem(this.player, log.getItem(), AuctionAPI.getInstance().getItemName(log.getItem()), Settings.GUI_LOGS_LORE.getStringList(), new HashMap<String, Object>() {{
put("%admin%", log.getAdminName());
put("%target%", log.getTargetName());
put("%admin_uuid%", log.getAdmin());
put("%target_uuid%", log.getTarget());
put("%item_id%", log.getItemId());
put("%admin_action%", log.getAdminAction().getTranslation());
put("%admin_log_date%", AuctionAPI.getInstance().convertMillisToDate(log.getTime()));
}}));
}
} }
} }