reduce so many item meta calls

Used a universal item meta variable
This commit is contained in:
Ryder Belserion 2024-10-11 10:06:37 -04:00
parent f0e6607bdc
commit 1b41e0c531
No known key found for this signature in database

View File

@ -593,19 +593,34 @@ public class GuiListener implements Listener {
Player player = (Player) e.getWhoClicked();
final Inventory inv = e.getClickedInventory();
if (inv != null) {
if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Categories")))) {
if (inv == null) return;
final ItemStack item = e.getCurrentItem();
if (item == null) return;
if (!item.hasItemMeta()) return;
final ItemMeta itemMeta = item.getItemMeta();
if (!itemMeta.hasDisplayName()) return;
final InventoryView view = e.getView();
final String title = view.getTitle();
final String displayName = itemMeta.getDisplayName();
if (title.contains(Methods.color(config.getString("Settings.Categories")))) {
e.setCancelled(true);
int slot = e.getRawSlot();
if (slot <= inv.getSize()) {
if (e.getCurrentItem() != null) {
ItemStack item = e.getCurrentItem();
if (slot > inv.getSize()) return;
if (item.hasItemMeta()) {
if (item.getItemMeta().hasDisplayName()) {
for (Category cat : Category.values()) {
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.Category-Settings." + cat.getName() + ".Name")))) {
if (displayName.equals(Methods.color(config.getString("Settings.GUISettings.Category-Settings." + cat.getName() + ".Name")))) {
openShop(player, HolderManager.getShopType(player), cat, 1);
playClick(player);
@ -613,7 +628,7 @@ public class GuiListener implements Listener {
return;
}
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))) {
if (displayName.equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))) {
openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), 1);
playClick(player);
@ -622,22 +637,14 @@ public class GuiListener implements Listener {
}
}
}
}
}
}
}
if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Bidding-On-Item")))) {
if (title.contains(Methods.color(config.getString("Settings.Bidding-On-Item")))) {
e.setCancelled(true);
int slot = e.getRawSlot();
if (slot <= inv.getSize()) {
if (e.getCurrentItem() != null) {
ItemStack item = e.getCurrentItem();
if (slot > inv.getSize()) return;
if (item.hasItemMeta()) {
if (item.getItemMeta().hasDisplayName()) {
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Bid.Name")))) {
if (displayName.equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Bid.Name")))) {
String ID = HolderManager.getBidId(player);
int bid = HolderManager.getBidding(player);
String topBidder = data.getString("Items." + ID + ".TopBidder");
@ -715,22 +722,14 @@ public class GuiListener implements Listener {
}
}
}
}
}
}
}
if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Buying-Item")))) {
if (title.contains(Methods.color(config.getString("Settings.Buying-Item")))) {
e.setCancelled(true);
int slot = e.getRawSlot();
if (slot <= inv.getSize()) {
if (e.getCurrentItem() != null) {
ItemStack item = e.getCurrentItem();
if (slot > inv.getSize()) return;
if (item.hasItemMeta()) {
if (item.getItemMeta().hasDisplayName()) {
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Confirm.Name")))) {
if (displayName.equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Confirm.Name")))) {
String ID = HolderManager.getId(player);
long cost = data.getLong("Items." + ID + ".Price");
String seller = data.getString("Items." + ID + ".Seller");
@ -805,7 +804,7 @@ public class GuiListener implements Listener {
return;
}
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Cancel.Name")))) {
if (displayName.equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Cancel.Name")))) {
openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), 1);
playClick(player);
@ -813,30 +812,21 @@ public class GuiListener implements Listener {
return;
}
}
}
}
}
}
if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Players-Current-Items")))) {
if (title.contains(Methods.color(config.getString("Settings.Players-Current-Items")))) {
e.setCancelled(true);
int slot = e.getRawSlot();
if (slot <= inv.getSize()) {
if (e.getCurrentItem() != null) {
ItemStack item = e.getCurrentItem();
if (slot > inv.getSize()) return;
if (item.hasItemMeta()) {
if (item.getItemMeta().hasDisplayName()) {
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))) {
if (displayName.equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))) {
openShop(player, HolderManager.getShopType(player), HolderManager.getShopCategory(player), 1);
playClick(player);
return;
}
}
if (HolderManager.containsPage(player)) {
final List<Integer> pages = HolderManager.getPages(player);
@ -886,22 +876,15 @@ public class GuiListener implements Listener {
}
}
}
}
}
}
if (e.getView().getTitle().contains(Methods.color(config.getString("Settings.Cancelled/Expired-Items")))) {
if (title.contains(Methods.color(config.getString("Settings.Cancelled/Expired-Items")))) {
e.setCancelled(true);
final int slot = e.getRawSlot();
if (slot <= inv.getSize()) {
if (e.getCurrentItem() != null) {
final ItemStack item = e.getCurrentItem();
if (slot > inv.getSize()) return;
if (item.hasItemMeta()) {
if (item.getItemMeta().hasDisplayName()) {
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))) {
if (displayName.equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Back.Name")))) {
Methods.updateAuction();
playClick(player);
@ -911,10 +894,10 @@ public class GuiListener implements Listener {
return;
}
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.PreviousPage.Name")))) {
if (displayName.equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.PreviousPage.Name")))) {
Methods.updateAuction();
int page = Integer.parseInt(e.getView().getTitle().split("#")[1]);
int page = Integer.parseInt(title.split("#")[1]);
if (page == 1) page++;
@ -925,10 +908,10 @@ public class GuiListener implements Listener {
return;
}
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Return.Name")))) {
if (displayName.equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.Return.Name")))) {
Methods.updateAuction();
int page = Integer.parseInt(e.getView().getTitle().split("#")[1]);
int page = Integer.parseInt(title.split("#")[1]);
if (data.contains("OutOfTime/Cancelled")) {
for (String i : data.getConfigurationSection("OutOfTime/Cancelled").getKeys(false)) {
@ -957,10 +940,10 @@ public class GuiListener implements Listener {
return;
}
if (item.getItemMeta().getDisplayName().equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.NextPage.Name")))) {
if (displayName.equals(Methods.color(config.getString("Settings.GUISettings.OtherSettings.NextPage.Name")))) {
Methods.updateAuction();
int page = Integer.parseInt(e.getView().getTitle().split("#")[1]);
int page = Integer.parseInt(title.split("#")[1]);
playClick(player);
@ -968,7 +951,6 @@ public class GuiListener implements Listener {
return;
}
}
if (HolderManager.containsPage(player)) {
final List<Integer> pages = HolderManager.getPages(player);
@ -1015,10 +997,6 @@ public class GuiListener implements Listener {
}
}
}
}
}
}
}
private static void playClick(Player player) {
FileConfiguration config = Files.config.getConfiguration();