diff --git a/plugin-modules/Core/resources-json/items.json b/plugin-modules/Core/resources-json/items.json index 76536b5..e8e9e7e 100644 --- a/plugin-modules/Core/resources-json/items.json +++ b/plugin-modules/Core/resources-json/items.json @@ -1,6 +1,7 @@ { "DefaultBossMenuItem": { - "type": "BARRIER" + "type": "BARRIER", + "name": "&c&lDefault Boss Menu Item" }, "SKSpawnItem": { "type": "SKELETON_SPAWN_EGG", diff --git a/plugin-modules/Core/resources-yml/editor.yml b/plugin-modules/Core/resources-yml/editor.yml index 9eabf45..1a768d2 100644 --- a/plugin-modules/Core/resources-yml/editor.yml +++ b/plugin-modules/Core/resources-yml/editor.yml @@ -128,4 +128,32 @@ ListPanel: name: '&7' '54': type: GLASS_PANE - name: '&7' \ No newline at end of file + name: '&7' +AddItemsMenu: + name: '&b&lAdd Item Menu' + slots: 27 + Settings: + emptySpaceFiller: true + EmptySpaceFiller: + name: '&7' + type: LIGHT_BLUE_STAINED_GLASS_PANE + Items: + '11': + type: REDSTONE + name: '&c&lCancel' + lore: + - '&7Click here to cancel the transaction' + - '&7of adding the item to the EpicBosses' + - '&7database.' + Button: Cancel + '14': + type: AIR + Button: SelectedSlot + '17': + type: LIME_DYE + name: '&a&lAccept' + lore: + - '&7Click here to accept the transaction' + - '&7of adding the item to the EpicBosses' + - '&7database.' + Button: Accept diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossPanelManager.java b/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossPanelManager.java index 6618129..9cb34a8 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossPanelManager.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossPanelManager.java @@ -1,5 +1,10 @@ package com.songoda.epicbosses.managers; +import com.songoda.epicbosses.droptable.DropTable; +import com.songoda.epicbosses.entity.BossEntity; +import com.songoda.epicbosses.entity.elements.EntityStatsElement; +import com.songoda.epicbosses.entity.elements.EquipmentElement; +import com.songoda.epicbosses.entity.elements.HandsElement; import lombok.Getter; import com.songoda.epicbosses.CustomBosses; import com.songoda.epicbosses.panel.*; @@ -9,7 +14,9 @@ import com.songoda.epicbosses.utils.StringUtils; import com.songoda.epicbosses.utils.panel.base.IPanelHandler; import com.songoda.epicbosses.utils.panel.builder.PanelBuilder; +import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -20,6 +27,7 @@ import java.util.Map; public class BossPanelManager implements ILoadable, IReloadable { @Getter private IPanelHandler mainMenu, customItems, bosses, autoSpawns, dropTables, customSkills, shopPanel; + @Getter private IPanelHandler addItemsMenu; private final CustomBosses customBosses; @@ -38,6 +46,7 @@ public class BossPanelManager implements ILoadable, IReloadable { loadCustomSkillsMenu(); loadDropTableMenu(); + loadAddItemsMenu(); } @Override @@ -51,6 +60,50 @@ public class BossPanelManager implements ILoadable, IReloadable { reloadCustomSkills(); reloadDropTable(); + reloadAddItemsMenu(); + } + + public int isItemStackUsed(String name) { + Collection values = this.customBosses.getBossEntityContainer().getData().values(); + int timesUsed = 0; + + for(BossEntity bossEntity : values) { + if(bossEntity.getSpawnItem().equalsIgnoreCase(name)) timesUsed += 1; + + List entityStatsElements = bossEntity.getEntityStats(); + + for(EntityStatsElement entityStatsElement : entityStatsElements) { + EquipmentElement equipmentElement = entityStatsElement.getEquipment(); + HandsElement handsElement = entityStatsElement.getHands(); + + if(handsElement.getMainHand().equalsIgnoreCase(name)) timesUsed += 1; + if(handsElement.getOffHand().equalsIgnoreCase(name)) timesUsed += 1; + if(equipmentElement.getHelmet().equalsIgnoreCase(name)) timesUsed += 1; + if(equipmentElement.getChestplate().equalsIgnoreCase(name)) timesUsed += 1; + if(equipmentElement.getLeggings().equalsIgnoreCase(name)) timesUsed += 1; + if(equipmentElement.getBoots().equalsIgnoreCase(name)) timesUsed += 1; + } + } + + return timesUsed; + } + + //--------------------------------------------- + // + // A D D I T E M S P A N E L + // + //--------------------------------------------- + + private void loadAddItemsMenu() { + PanelBuilder panelBuilder = new PanelBuilder(this.customBosses.getEditor().getConfigurationSection("AddItemsMenu")); + + this.addItemsMenu = new AddItemsPanel(this, panelBuilder, this.customBosses); + } + + private void reloadAddItemsMenu() { + PanelBuilder panelBuilder = new PanelBuilder(this.customBosses.getEditor().getConfigurationSection("AddItemsMenu")); + + this.addItemsMenu.initializePanel(panelBuilder); } //--------------------------------------------- @@ -148,7 +201,7 @@ public class BossPanelManager implements ILoadable, IReloadable { //--------------------------------------------- private void loadCustomItemsMenu() { - this.customItems = new CustomItemsPanel(this, getListMenu("Items")); + this.customItems = new CustomItemsPanel(this, getListMenu("Items"), this.customBosses); } private void reloadCustomItems() { diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/managers/files/ItemsFileManager.java b/plugin-modules/Core/src/com/songoda/epicbosses/managers/files/ItemsFileManager.java index fda348f..aa29857 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/managers/files/ItemsFileManager.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/managers/files/ItemsFileManager.java @@ -7,6 +7,7 @@ import com.songoda.epicbosses.utils.ISavable; import com.songoda.epicbosses.utils.itemstack.ItemStackConverter; import com.songoda.epicbosses.file.ItemStackFileHandler; import com.songoda.epicbosses.utils.itemstack.holder.ItemStackHolder; +import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; import java.io.File; @@ -50,6 +51,16 @@ public class ItemsFileManager implements ILoadable, ISavable, IReloadable { return this.itemStackHolders.getOrDefault(name, null); } + public void addItemStack(String name, ItemStack itemStack) { + this.itemStackHolders.put(name, this.itemStackConverter.to(itemStack)); + save(); + } + + public void removeItemStack(String name) { + this.itemStackHolders.remove(name); + save(); + } + public Map getItemStackHolders() { return new HashMap<>(this.itemStackHolders); } diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/panel/AddItemsPanel.java b/plugin-modules/Core/src/com/songoda/epicbosses/panel/AddItemsPanel.java new file mode 100644 index 0000000..851e39e --- /dev/null +++ b/plugin-modules/Core/src/com/songoda/epicbosses/panel/AddItemsPanel.java @@ -0,0 +1,129 @@ +package com.songoda.epicbosses.panel; + +import com.songoda.epicbosses.CustomBosses; +import com.songoda.epicbosses.managers.BossPanelManager; +import com.songoda.epicbosses.managers.files.ItemsFileManager; +import com.songoda.epicbosses.utils.Message; +import com.songoda.epicbosses.utils.panel.Panel; +import com.songoda.epicbosses.utils.panel.base.ClickAction; +import com.songoda.epicbosses.utils.panel.base.PanelHandler; +import com.songoda.epicbosses.utils.panel.builder.PanelBuilder; +import com.songoda.epicbosses.utils.panel.builder.PanelBuilderCounter; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +/** + * @author Charles Cullen + * @version 1.0.0 + * @since 18-Nov-18 + */ +public class AddItemsPanel extends PanelHandler { + + private Map storedItemStacks = new HashMap<>(); + private ItemsFileManager itemsFileManager; + + public AddItemsPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) { + super(bossPanelManager, panelBuilder); + + this.itemsFileManager = plugin.getItemStackManager(); + } + + @Override + public void initializePanel(PanelBuilder panelBuilder) { + PanelBuilderCounter panelBuilderCounter = panelBuilder.getPanelBuilderCounter(); + + panelBuilderCounter + .addSlotCounter("Cancel", getCancelAction()) + .addSlotCounter("Accept", getAcceptAction()) + .addSlotCounter("SelectedSlot", getSelectedSlotAction(panelBuilderCounter)); + } + + @Override + public void fillPanel(Panel panel) { + + } + + @Override + public void openFor(Player player) { + Panel panel = getPanelBuilder().getPanel() + .setDestroyWhenDone(true) + .setCancelClick(true) + .setCancelLowerClick(false); + + panel.setOnClick(event -> { + Player playerWhoClicked = (Player) event.getWhoClicked(); + UUID uuid = playerWhoClicked.getUniqueId(); + int rawSlot = event.getRawSlot(); + int slot = event.getSlot(); + + if(panel.isLowerClick(rawSlot)) { + if(this.storedItemStacks.containsKey(uuid)) { + Message.Boss_Items_AlreadySet.msg(playerWhoClicked); + return; + } + + ItemStack itemStack = event.getClickedInventory().getItem(slot); + + this.storedItemStacks.put(uuid, itemStack.clone()); + panel.getPanelBuilderCounter().getSlotsWith("SelectedSlot").forEach(s -> event.getInventory().setItem(s, itemStack.clone())); + event.getClickedInventory().setItem(slot, new ItemStack(Material.AIR)); + } + }); + + panel.openFor(player); + } + + private ClickAction getSelectedSlotAction(PanelBuilderCounter panelBuilderCounter) { + return event -> { + System.out.println("CALLED 1"); + + Player player = (Player) event.getWhoClicked(); + UUID uuid = player.getUniqueId(); + + if(this.storedItemStacks.containsKey(uuid)) { + player.getInventory().addItem(this.storedItemStacks.get(uuid)); + this.storedItemStacks.remove(uuid); + + panelBuilderCounter.getSlotsWith("SelectedSlot").forEach(slot -> event.getInventory().setItem(slot, new ItemStack(Material.AIR))); + } + }; + } + + private ClickAction getAcceptAction() { + return event -> { + System.out.println("CALLED 2"); + + Player player = (Player) event.getWhoClicked(); + UUID uuid = player.getUniqueId(); + + if(this.storedItemStacks.containsKey(uuid)) { + this.itemsFileManager.addItemStack(UUID.randomUUID().toString(), this.storedItemStacks.get(uuid)); + Message.Boss_Items_Added.msg(player); + this.storedItemStacks.remove(uuid); + } + + this.bossPanelManager.getCustomItems().openFor(player); + }; + } + + private ClickAction getCancelAction() { + return event -> { + System.out.println("CALLED 3"); + + Player player = (Player) event.getWhoClicked(); + UUID uuid = player.getUniqueId(); + + if(this.storedItemStacks.containsKey(uuid)) { + player.getInventory().addItem(this.storedItemStacks.get(uuid)); + this.storedItemStacks.remove(uuid); + } + + this.bossPanelManager.getCustomItems().openFor(player); + }; + } +} diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/panel/CustomItemsPanel.java b/plugin-modules/Core/src/com/songoda/epicbosses/panel/CustomItemsPanel.java index d685468..c811991 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/panel/CustomItemsPanel.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/panel/CustomItemsPanel.java @@ -1,22 +1,39 @@ package com.songoda.epicbosses.panel; +import com.songoda.epicbosses.CustomBosses; +import com.songoda.epicbosses.entity.BossEntity; import com.songoda.epicbosses.managers.BossPanelManager; +import com.songoda.epicbosses.managers.files.ItemsFileManager; +import com.songoda.epicbosses.utils.Debug; +import com.songoda.epicbosses.utils.Message; +import com.songoda.epicbosses.utils.itemstack.ItemStackUtils; +import com.songoda.epicbosses.utils.itemstack.holder.ItemStackHolder; import com.songoda.epicbosses.utils.panel.Panel; import com.songoda.epicbosses.utils.panel.base.PanelHandler; import com.songoda.epicbosses.utils.panel.builder.PanelBuilder; +import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * @author Charles Cullen * @version 1.0.0 * @since 10-Oct-18 - * - * TODO */ public class CustomItemsPanel extends PanelHandler { - public CustomItemsPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder) { + private ItemsFileManager itemsFileManager; + + public CustomItemsPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) { super(bossPanelManager, panelBuilder); + + this.itemsFileManager = plugin.getItemStackManager(); } @Override @@ -26,11 +43,67 @@ public class CustomItemsPanel extends PanelHandler { @Override public void fillPanel(Panel panel) { + Map currentItemStacks = this.itemsFileManager.getItemStackHolders(); + List entryList = new ArrayList<>(currentItemStacks.keySet()); + int maxPage = panel.getMaxPage(entryList); + panel.setOnPageChange(((player, currentPage, requestedPage) -> { + if(requestedPage < 0 || requestedPage > maxPage) return false; + + loadPage(panel, requestedPage, currentItemStacks, entryList); + return true; + })); + + loadPage(panel, 0, currentItemStacks, entryList); } @Override public void openFor(Player player) { + Panel panel = getPanelBuilder().getPanel() + .setDestroyWhenDone(true) + .setCancelClick(true) + .setCancelLowerClick(true) + .setParentPanel(this.bossPanelManager.getMainMenu().getPanel()); + fillPanel(panel); + + panel.openFor(player); + } + + private void loadPage(Panel panel, int requestedPage, Map currentItemStacks, List entryList) { + panel.loadPage(requestedPage, (slot, realisticSlot) -> { + if(slot >= currentItemStacks.size()) { + panel.setItem(realisticSlot, new ItemStack(Material.AIR), e -> {}); + } else { + String name = entryList.get(slot); + ItemStackHolder itemStackHolder = currentItemStacks.get(name); + ItemStack itemStack = this.itemsFileManager.getItemStackConverter().from(itemStackHolder); + ItemStack cloneStack = itemStack.clone(); + + panel.setItem(realisticSlot, itemStack, e -> { + if(e.getClick() == ClickType.RIGHT || e.getClick() == ClickType.SHIFT_RIGHT) { + int timesUsed = this.bossPanelManager.isItemStackUsed(name); + + if(timesUsed > 0) { + Message.Boss_Items_CannotBeRemoved.msg(e.getWhoClicked(), timesUsed); + } else { + this.itemsFileManager.removeItemStack(name); + currentItemStacks.remove(name); + entryList.remove(name); + + loadPage(panel, requestedPage, currentItemStacks, entryList); + Message.Boss_Items_Removed.msg(e.getWhoClicked()); + } + } else if(e.getClick() == ClickType.LEFT || e.getClick() == ClickType.SHIFT_LEFT) { + if(cloneStack == null) { + Debug.FAILED_TO_GIVE_CUSTOM_ITEM.debug(e.getWhoClicked().getName()); + return; + } + + e.getWhoClicked().getInventory().addItem(cloneStack); + } + }); + } + }); } } diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/panel/MainMenuPanel.java b/plugin-modules/Core/src/com/songoda/epicbosses/panel/MainMenuPanel.java index 460f491..f946746 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/panel/MainMenuPanel.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/panel/MainMenuPanel.java @@ -7,6 +7,7 @@ import com.songoda.epicbosses.utils.panel.base.ClickAction; import com.songoda.epicbosses.utils.panel.base.PanelHandler; import com.songoda.epicbosses.utils.panel.builder.PanelBuilder; import com.songoda.epicbosses.utils.panel.builder.PanelBuilderCounter; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; @@ -68,8 +69,7 @@ public class MainMenuPanel extends PanelHandler { if(event.getClick() == ClickType.LEFT || event.getClick() == ClickType.SHIFT_LEFT) { this.bossPanelManager.getCustomItems().openFor(player); } else if(event.getClick() == ClickType.RIGHT || event.getClick() == ClickType.SHIFT_RIGHT) { - //TODO: Set up create item inventory - player.closeInventory(); + this.bossPanelManager.getAddItemsMenu().openFor(player); } }; } diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/utils/Debug.java b/plugin-modules/Core/src/com/songoda/epicbosses/utils/Debug.java index 4aefa41..2268707 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/utils/Debug.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/utils/Debug.java @@ -40,6 +40,7 @@ public enum Debug { FAILED_TO_GIVE_SPAWN_EGG("{0} tried to obtain a spawn egg for the boss {1} but it has not been set yet."), FAILED_TO_CONNECT_TO_VAULT("Something went wrong while trying to connect to Vault. Please make sure you have an Economy and Permission plugin connected to your Vault plugin such as Essentials and GroupManager."), FAILED_TO_OBTAIN_THE_SKILL_HANDLER("Something went wrong when trying to detect the skill handler for {0}."), + FAILED_TO_GIVE_CUSTOM_ITEM("{0} tried to obtain a custom item from the Custom Items list but failed due to the item not being set properly."), DROP_TABLE_FAILED_INVALID_NUMBER("The specified position ({0}) on the drop table is not a valid number."), DROP_TABLE_FAILED_TO_GET_ITEM("The drop table failed to get the specific item for the list."), diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/utils/Message.java b/plugin-modules/Core/src/com/songoda/epicbosses/utils/Message.java index 6df94fb..17bdf97 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/utils/Message.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/utils/Message.java @@ -89,6 +89,10 @@ public enum Message { "&bComplete enough to spawn: &f{3}"), Boss_Items_NoPermission("&c&l(!) &cYou do not have access to this command."), + Boss_Items_CannotBeRemoved("&c&l(!) &cThe selected item cannot be removed because it is still used in {0} different positions on the bosses."), + Boss_Items_Removed("&b&lEpicBosses &8» &7The selected item has been removed from the EpicBosses custom items database."), + Boss_Items_Added("&b&lEpicBosses &8» &7You have added an item to the EpicBosses custom items database."), + Boss_Items_AlreadySet("&c&l(!) &cYou must take out the item you have set to add before you can add another."), Boss_KillAll_WorldNotFound("&c&l(!) &cThe specified world was not found. If you'd like to kill every boss/minion just use &f/boss killall&c without any arguments."), Boss_KillAll_KilledAll("&b&lEpicBosses &8» &7You have killed {0} boss(es) and minions that were currently active on the server."), diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/utils/itemstack/ItemStackConverter.java b/plugin-modules/Core/src/com/songoda/epicbosses/utils/itemstack/ItemStackConverter.java index ae383b2..442f892 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/utils/itemstack/ItemStackConverter.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/utils/itemstack/ItemStackConverter.java @@ -53,14 +53,14 @@ public class ItemStackConverter implements IReplaceableConverter(); for(String string : itemMeta.getLore()) { - lore.add(StringUtils.get().stripColor(string)); + lore.add(string.replace('§', '&')); } } @@ -88,14 +88,14 @@ public class ItemStackConverter implements IReplaceableConverter lore = itemStackHolder.getLore(), enchants = itemStackHolder.getEnchants(); Boolean isGlowing = itemStackHolder.getIsGlowing(); if(durability != null) itemStack.setDurability(durability); - if(enchants != null) itemStack.addEnchantments(this.enchantConverter.from(enchants)); + if(enchants != null) itemStack.addUnsafeEnchantments(this.enchantConverter.from(enchants)); if(name != null || skullOwner != null || lore != null || spawnerId != null) { ItemMeta itemMeta = itemStack.getItemMeta(); @@ -176,6 +177,10 @@ public class ItemStackConverter implements IReplaceableConverter 1) { + itemStack.setAmount(amount); + } + return itemStack; } diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/utils/panel/Panel.java b/plugin-modules/Core/src/com/songoda/epicbosses/utils/panel/Panel.java index 3229e31..9ab195a 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/utils/panel/Panel.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/utils/panel/Panel.java @@ -2,6 +2,7 @@ package com.songoda.epicbosses.utils.panel; import com.songoda.epicbosses.utils.panel.base.IPageHandler; import com.songoda.epicbosses.utils.panel.builder.PanelBuilder; +import com.songoda.epicbosses.utils.panel.builder.PanelBuilderCounter; import lombok.Getter; import com.songoda.epicbosses.utils.ICloneable; import com.songoda.epicbosses.utils.StringUtils; @@ -55,11 +56,11 @@ public class Panel implements Listener, ICloneable { private final List allSlotActions = new ArrayList<>(); private final Map currentPageContainer = new HashMap<>(); - private final Map pageData = new HashMap<>(); private final List openedUsers = new ArrayList<>(); @Getter private boolean cancelClick = true, destroyWhenDone = true, cancelLowerClick = true; @Getter private PanelBuilderSettings panelBuilderSettings; + @Getter private PanelBuilderCounter panelBuilderCounter; @Getter private Sound clickSound = null; @Getter private Inventory inventory; @Getter private int viewers = 0; @@ -104,14 +105,13 @@ public class Panel implements Listener, ICloneable { * Creates a Panel with the specified arguments * * @param inventory - Panel inventory - * @param pageData - Panel page data */ - public Panel(Inventory inventory, Map pageData, PanelBuilderSettings panelBuilderSettings) { + public Panel(Inventory inventory, PanelBuilderSettings panelBuilderSettings, PanelBuilderCounter panelBuilderCounter) { Bukkit.getPluginManager().registerEvents(this, PLUGIN); this.inventory = inventory; - this.pageData.putAll(pageData); this.panelBuilderSettings = panelBuilderSettings; + this.panelBuilderCounter = panelBuilderCounter; fillEmptySpace(); @@ -132,7 +132,8 @@ public class Panel implements Listener, ICloneable { Player player = (Player) event.getWhoClicked(); - if((!isCancelClick()) && (event.getRawSlot() > inventory.getSize())) { + if(isCancelLowerClick() && isLowerClick(event.getRawSlot())) { + System.out.println("CANCELLED "); event.setCancelled(true); return; } @@ -165,10 +166,10 @@ public class Panel implements Listener, ICloneable { private void executeAction(int slot, InventoryClickEvent e) { Player clicker = (Player) e.getWhoClicked(); - if(this.pageData.containsKey(slot)) { + if(getPanelBuilderCounter().getPageData().containsKey(slot)) { int currentPage = this.currentPageContainer.getOrDefault(clicker.getUniqueId(), 0); - if(this.pageData.get(slot) > 0) { + if(getPanelBuilderCounter().getPageData().get(slot) > 0) { if(this.onPageChange.onPageAction(clicker, currentPage, currentPage+1)) { this.currentPageContainer.put(clicker.getUniqueId(), currentPage+1); } @@ -348,6 +349,9 @@ public class Panel implements Listener, ICloneable { return this; } + public boolean isLowerClick(int rawSlot) { + return rawSlot > inventory.getSize(); + } public void loadPage(int page, IPageHandler pageHandler) { int fillTo = getPanelBuilderSettings().getFillTo(); @@ -418,7 +422,6 @@ public class Panel implements Listener, ICloneable { this.currentPageContainer.clear(); this.targettedSlotActions.clear(); this.allSlotActions.clear(); - this.pageData.clear(); this.inventory = null; this.openedUsers.forEach(uuid -> { @@ -451,6 +454,8 @@ public class Panel implements Listener, ICloneable { for(int i = 0; i < getInventory().getSize(); i++) { ItemStack itemAtSlot = getInventory().getItem(i); + if(getPanelBuilderCounter().isButtonAtSlot(i)) continue; + if(itemAtSlot == null || itemAtSlot.getType() == Material.AIR) { getInventory().setItem(i, itemStack); } @@ -486,6 +491,7 @@ public class Panel implements Listener, ICloneable { panel.destroyWhenDone = this.destroyWhenDone; panel.cancelLowerClick = this.cancelLowerClick; panel.panelBuilderSettings = this.panelBuilderSettings; + panel.panelBuilderCounter = this.panelBuilderCounter; panel.clickSound = this.clickSound; panel.onPageChange = this.onPageChange; panel.panelClose = this.panelClose; diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/utils/panel/builder/PanelBuilder.java b/plugin-modules/Core/src/com/songoda/epicbosses/utils/panel/builder/PanelBuilder.java index 4fc2f9b..c7d7a68 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/utils/panel/builder/PanelBuilder.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/utils/panel/builder/PanelBuilder.java @@ -57,7 +57,7 @@ public class PanelBuilder { public Panel getPanel() { build(); - Panel panel = new Panel(this.inventory, this.panelBuilderCounter.getPageData(), this.panelBuilderSettings); + Panel panel = new Panel(this.inventory, this.panelBuilderSettings, this.panelBuilderCounter); Map itemStackMap = this.panelBuilderCounter.getItemStacks(); Map clickActionMap = this.panelBuilderCounter.getClickActions(); diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/utils/panel/builder/PanelBuilderCounter.java b/plugin-modules/Core/src/com/songoda/epicbosses/utils/panel/builder/PanelBuilderCounter.java index a013387..27bf0e5 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/utils/panel/builder/PanelBuilderCounter.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/utils/panel/builder/PanelBuilderCounter.java @@ -23,6 +23,18 @@ public class PanelBuilderCounter { @Getter private final Map itemStacks = new HashMap<>(); @Getter private final Map pageData = new HashMap<>(); + public boolean isButtonAtSlot(int slot) { + for (Set integers : this.slotsWithCounter.values()) { + if(integers.contains(slot)) return true; + } + + for(Map map : this.specialValuesCounter.values()) { + if(map.containsKey(slot)) return true; + } + + return false; + } + public PanelBuilderCounter addSpecialCounter(String identifier) { this.specialValuesCounter.put(identifier, new HashMap<>()); diff --git a/pom.xml b/pom.xml index 7b8d339..ce6472a 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ - 1.0.0-SNAPSHOT-U60 + 1.0.0-SNAPSHOT-U61 EpicBosses com.songoda.epicbosses.CustomBosses AMinecraftDev