From 039783663e15690523fd6164e8cefeccbef95f51 Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 7 Jan 2019 19:57:37 +0800 Subject: [PATCH] 1.0.0-SNAPSHOT-U183 + Connected and completed the AutoSpawnCustomSettings Panel + Set up ExtraInformation in to AutoSpawnCustomSettings Display ItemStack --- .../epicbosses/managers/BossPanelManager.java | 5 ++ .../AutoSpawnCustomSettingsEditorPanel.java | 79 +++++++++++++++++-- pom.xml | 2 +- 3 files changed, 80 insertions(+), 6 deletions(-) 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 564df97..e685730 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossPanelManager.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossPanelManager.java @@ -10,6 +10,7 @@ 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 com.songoda.epicbosses.panel.autospawns.AutoSpawnCustomSettingsEditorPanel; import com.songoda.epicbosses.panel.autospawns.AutoSpawnEntitiesEditorPanel; import com.songoda.epicbosses.panel.autospawns.MainAutoSpawnEditorPanel; import com.songoda.epicbosses.panel.bosses.*; @@ -247,18 +248,22 @@ public class BossPanelManager implements ILoadable, IReloadable { FileConfiguration editor = this.customBosses.getEditor(); PanelBuilder panelBuilder = new PanelBuilder(editor.getConfigurationSection("MainAutoSpawnEditMenu")); PanelBuilder panelBuilder1 = new PanelBuilder(editor.getConfigurationSection("AutoSpawnEntitiesEditMenu")); + PanelBuilder panelBuilder2 = new PanelBuilder(editor.getConfigurationSection("AutoSpawnCustomSettingsEditMenu")); this.mainAutoSpawnEditPanel = new MainAutoSpawnEditorPanel(this, panelBuilder, this.customBosses); this.autoSpawnEntitiesEditPanel = new AutoSpawnEntitiesEditorPanel(this, panelBuilder1, this.customBosses); + this.autoSpawnSpecialSettingsEditorPanel = new AutoSpawnCustomSettingsEditorPanel(this, panelBuilder2, this.customBosses); } private void reloadAutoSpawnEditMenus() { FileConfiguration editor = this.customBosses.getEditor(); PanelBuilder panelBuilder = new PanelBuilder(editor.getConfigurationSection("MainAutoSpawnEditMenu")); PanelBuilder panelBuilder1 = new PanelBuilder(editor.getConfigurationSection("AutoSpawnEntitiesEditMenu")); + PanelBuilder panelBuilder2 = new PanelBuilder(editor.getConfigurationSection("AutoSpawnCustomSettingsEditMenu")); this.mainAutoSpawnEditPanel.initializePanel(panelBuilder); this.autoSpawnEntitiesEditPanel.initializePanel(panelBuilder1); + this.autoSpawnSpecialSettingsEditorPanel.initializePanel(panelBuilder2); } //--------------------------------------------- diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/panel/autospawns/AutoSpawnCustomSettingsEditorPanel.java b/plugin-modules/Core/src/com/songoda/epicbosses/panel/autospawns/AutoSpawnCustomSettingsEditorPanel.java index 5b2d42f..07e18fa 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/panel/autospawns/AutoSpawnCustomSettingsEditorPanel.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/panel/autospawns/AutoSpawnCustomSettingsEditorPanel.java @@ -5,38 +5,55 @@ import com.songoda.epicbosses.api.BossAPI; import com.songoda.epicbosses.autospawns.AutoSpawn; import com.songoda.epicbosses.managers.AutoSpawnManager; import com.songoda.epicbosses.managers.BossPanelManager; +import com.songoda.epicbosses.skills.interfaces.ICustomSettingAction; import com.songoda.epicbosses.utils.ObjectUtils; +import com.songoda.epicbosses.utils.itemstack.ItemStackUtils; import com.songoda.epicbosses.utils.panel.Panel; +import com.songoda.epicbosses.utils.panel.base.ClickAction; import com.songoda.epicbosses.utils.panel.base.handlers.VariablePanelHandler; import com.songoda.epicbosses.utils.panel.builder.PanelBuilder; +import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; /** * @author Charles Cullen * @version 1.0.0 * @since 07-Jan-19 - * - * TODO Handle Extra Information */ public class AutoSpawnCustomSettingsEditorPanel extends VariablePanelHandler { - private AutoSpawnManager autoSpawnManager; private CustomBosses plugin; public AutoSpawnCustomSettingsEditorPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) { super(bossPanelManager, panelBuilder); this.plugin = plugin; - this.autoSpawnManager = plugin.getAutoSpawnManager(); } @Override public void fillPanel(Panel panel, AutoSpawn autoSpawn) { - String currentType = ObjectUtils.getValue(autoSpawn.getType(), ""); + List customButtons = autoSpawn.getIntervalSpawnData().getCustomSettingActions(autoSpawn); + if(customButtons == null || customButtons.isEmpty()) return; + + int maxPage = panel.getMaxPage(customButtons); + + panel.setOnPageChange(((player, currentPage, requestedPage) -> { + if(requestedPage < 0 || requestedPage > maxPage) return false; + + loadPage(panel, requestedPage, customButtons); + return true; + })); + + + loadPage(panel, 0, customButtons); } @Override @@ -58,4 +75,56 @@ public class AutoSpawnCustomSettingsEditorPanel extends VariablePanelHandler clickActions) { + panel.loadPage(page, ((slot, realisticSlot) -> { + if(slot >= clickActions.size()) { + panel.setItem(realisticSlot, new ItemStack(Material.AIR), e -> {}); + } else { + ICustomSettingAction customSettingAction = clickActions.get(slot); + ClickAction clickAction = customSettingAction.getAction(); + String name = customSettingAction.getSettingName(); + ItemStack displayStack = customSettingAction.getDisplayItemStack().clone(); + String currently = customSettingAction.getCurrent(); + List extraInfo = customSettingAction.getExtraInformation(); + + Map replaceMap = new HashMap<>(); + + replaceMap.put("{setting}", name); + replaceMap.put("{currently}", currently); + + if(displayStack == null || displayStack.getType() == Material.AIR) return; + + ItemStackUtils.applyDisplayName(displayStack, this.plugin.getConfig().getString("Display.AutoSpawns.CustomSettings.name"), replaceMap); + + ItemMeta itemMeta = displayStack.getItemMeta(); + List lore = this.plugin.getConfig().getStringList("Display.AutoSpawns.CustomSettings.lore"); + List newLore = new ArrayList<>(); + + for(String s : lore) { + if(s.contains("{extraInformation}")) { + if(extraInfo == null || extraInfo.isEmpty()) continue; + + newLore.add("&7"); + newLore.addAll(extraInfo); + } else { + for(String replaceKey : replaceMap.keySet()) { + if(s.contains(replaceKey)) { + s = s.replace(replaceKey, replaceMap.get(replaceKey)); + } + } + + newLore.add(s); + } + } + + newLore.replaceAll(s -> s.replace('&', 'ยง')); + itemMeta.setLore(newLore); + displayStack.setItemMeta(itemMeta); + + panel.setItem(realisticSlot, displayStack, clickAction); + } + })); + } + } diff --git a/pom.xml b/pom.xml index a5e9015..b1a9514 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ - 1.0.0-U182 + 1.0.0-U183 EpicBosses com.songoda.epicbosses.CustomBosses AMinecraftDev