From 28d036cf9754bb80364b539927d96557e8b1d893 Mon Sep 17 00:00:00 2001 From: Charles Date: Sat, 29 Dec 2018 01:36:21 +0800 Subject: [PATCH] 1.0.0-SNAPSHOT-U145 + Fully implemented the new Reward section for the Spray DropTable. --- plugin-modules/Core/resources-yml/editor.yml | 2 +- .../epicbosses/managers/BossPanelManager.java | 4 +- .../spray/SprayNewRewardEditorPanel.java | 67 +++++++++++++++++++ .../com/songoda/epicbosses/utils/Message.java | 1 + pom.xml | 2 +- 5 files changed, 72 insertions(+), 4 deletions(-) diff --git a/plugin-modules/Core/resources-yml/editor.yml b/plugin-modules/Core/resources-yml/editor.yml index 20ddc6a..78f417c 100644 --- a/plugin-modules/Core/resources-yml/editor.yml +++ b/plugin-modules/Core/resources-yml/editor.yml @@ -2142,7 +2142,7 @@ SprayNewRewardEditMenu: type: BOOK name: '&c&lNew Spray Reward Guide' lore: - - '&7Once u click an item within this' + - '&7Once you click an item within this' - '&7menu it will create a new reward' - '&7section with that selected item' - '&7to the drop table you were working' 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 f178a24..a25b320 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossPanelManager.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossPanelManager.java @@ -216,7 +216,7 @@ public class BossPanelManager implements ILoadable, IReloadable { PanelBuilder panelBuilder2 = new PanelBuilder(editor.getConfigurationSection("SprayDropTableMainEditMenu")); PanelBuilder panelBuilder3 = new PanelBuilder(editor.getConfigurationSection("SprayRewardsListEditMenu")); PanelBuilder panelBuilder4 = new PanelBuilder(editor.getConfigurationSection("SprayDropTableMainEditMenu")); //TODO - PanelBuilder panelBuilder5 = new PanelBuilder(editor.getConfigurationSection("SprayDropTableMainEditMenu")); //TODO + PanelBuilder panelBuilder5 = new PanelBuilder(editor.getConfigurationSection("SprayNewRewardEditMenu")); this.mainDropTableEditMenu = new MainDropTableEditorPanel(this, panelBuilder); this.dropTableTypeEditMenu = new DropTableTypeEditorPanel(this, panelBuilder1, this.customBosses); @@ -233,7 +233,7 @@ public class BossPanelManager implements ILoadable, IReloadable { PanelBuilder panelBuilder2 = new PanelBuilder(editor.getConfigurationSection("SprayDropTableMainEditMenu")); PanelBuilder panelBuilder3 = new PanelBuilder(editor.getConfigurationSection("SprayRewardsListEditMenu")); PanelBuilder panelBuilder4 = new PanelBuilder(editor.getConfigurationSection("SprayDropTableMainEditMenu")); //TODO - PanelBuilder panelBuilder5 = new PanelBuilder(editor.getConfigurationSection("SprayDropTableMainEditMenu")); //TODO + PanelBuilder panelBuilder5 = new PanelBuilder(editor.getConfigurationSection("SprayNewRewardEditMenu")); this.mainDropTableEditMenu.initializePanel(panelBuilder); this.dropTableTypeEditMenu.initializePanel(panelBuilder1); diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/panel/droptables/types/spray/SprayNewRewardEditorPanel.java b/plugin-modules/Core/src/com/songoda/epicbosses/panel/droptables/types/spray/SprayNewRewardEditorPanel.java index 961ffec..f103122 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/panel/droptables/types/spray/SprayNewRewardEditorPanel.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/panel/droptables/types/spray/SprayNewRewardEditorPanel.java @@ -1,13 +1,23 @@ package com.songoda.epicbosses.panel.droptables.types.spray; import com.songoda.epicbosses.CustomBosses; +import com.songoda.epicbosses.api.BossAPI; import com.songoda.epicbosses.droptable.DropTable; import com.songoda.epicbosses.droptable.elements.SprayTableElement; import com.songoda.epicbosses.managers.BossPanelManager; +import com.songoda.epicbosses.managers.files.ItemsFileManager; +import com.songoda.epicbosses.utils.Message; +import com.songoda.epicbosses.utils.itemstack.holder.ItemStackHolder; import com.songoda.epicbosses.utils.panel.Panel; import com.songoda.epicbosses.utils.panel.base.handlers.SubVariablePanelHandler; import com.songoda.epicbosses.utils.panel.builder.PanelBuilder; +import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; /** * @author Charles Cullen @@ -16,22 +26,79 @@ import org.bukkit.entity.Player; */ public class SprayNewRewardEditorPanel extends SubVariablePanelHandler { + private ItemsFileManager itemsFileManager; + private CustomBosses plugin; + public SprayNewRewardEditorPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) { super(bossPanelManager, panelBuilder); + + this.itemsFileManager = plugin.getItemStackManager(); + this.plugin = plugin; } @Override public void fillPanel(Panel panel, DropTable dropTable, SprayTableElement sprayTableElement) { + Map itemStacks = this.itemsFileManager.getItemStackHolders(); + List currentKeys = new ArrayList<>(sprayTableElement.getSprayRewards().keySet()); + List filteredKeys = getFilteredKeys(itemStacks, currentKeys); + int maxPage = panel.getMaxPage(filteredKeys); + panel.setOnPageChange(((player, currentPage, requestedPage) -> { + if(requestedPage < 0 || requestedPage > maxPage) return false; + + loadPage(panel, requestedPage, dropTable, sprayTableElement, filteredKeys, itemStacks); + return true; + })); + + loadPage(panel, 0, dropTable, sprayTableElement, filteredKeys, itemStacks); } @Override public void openFor(Player player, DropTable dropTable, SprayTableElement sprayTableElement) { + Panel panel = getPanelBuilder().getPanel() + .setParentPanelHandler(this.bossPanelManager.getSprayRewardListEditMenu(), dropTable, sprayTableElement); + fillPanel(panel, dropTable, sprayTableElement); + panel.openFor(player); } @Override public void initializePanel(PanelBuilder panelBuilder) { } + + private void loadPage(Panel panel, int page, DropTable dropTable, SprayTableElement sprayTableElement, List filteredKeys, Map itemStacks) { + panel.loadPage(page, (slot, realisticSlot) -> { + if(slot >= filteredKeys.size()) { + panel.setItem(realisticSlot, new ItemStack(Material.AIR), e->{}); + } else { + String name = filteredKeys.get(slot); + ItemStackHolder itemStackHolder = itemStacks.get(name); + ItemStack itemStack = this.itemsFileManager.getItemStackConverter().from(itemStackHolder); + + panel.setItem(realisticSlot, itemStack, event -> { + Map currentRewards = sprayTableElement.getSprayRewards(); + + currentRewards.put(name, 50.0); + dropTable.setRewards(BossAPI.convertObjectToJsonObject(sprayTableElement)); + this.plugin.getDropTableFileManager().save(); + + this.bossPanelManager.getSprayRewardMainEditMenu().openFor((Player) event.getWhoClicked(), dropTable, sprayTableElement, name); + Message.Boss_DropTable_SprayAddedNewReward.msg(event.getWhoClicked(), BossAPI.getDropTableName(dropTable)); + }); + } + }); + } + + private List getFilteredKeys(Map itemStacks, List currentKeys) { + List filteredList = new ArrayList<>(); + + itemStacks.keySet().forEach(string -> { + if(currentKeys.contains(string)) return; + + filteredList.add(string); + }); + + return filteredList; + } } 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 fa86ca6..5256ac1 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/utils/Message.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/utils/Message.java @@ -38,6 +38,7 @@ public enum Message { Boss_DropTable_SetMaxDrops("&b&lEpicBosses &8» &7You have {0} the max drops for the drop table to &f{1}&7."), Boss_DropTable_SetMaxDistance("&b&lEpicBosses &8» &7You have {0} the max distance for the drop table to &f{1}&7."), Boss_DropTable_SetRandomDrops("&b&lEpicBosses &8» &7You have set the random drops mode for the drop table to &f{0}&7."), + Boss_DropTable_SprayAddedNewReward("&b&lEpicBosses &8» &7You have added a new reward to the drop table &f{0}&7. Now opening the editing panel for the new reward."), Boss_Edit_NoPermission("&c&l(!) &cYou do not have access to this command."), Boss_Edit_ItemStackHolderNull("&c&l(!) &cThe itemstack name that is provided for the spawn item doesn't exist or wasn't found."), diff --git a/pom.xml b/pom.xml index 07064d7..b560bc1 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ - 1.0.0-U144 + 1.0.0-U145 EpicBosses com.songoda.epicbosses.CustomBosses AMinecraftDev