From 5bb87ab6b9924ba09ff475bbc951261a4ef19d99 Mon Sep 17 00:00:00 2001 From: Charles Date: Sun, 2 Dec 2018 18:42:10 +0800 Subject: [PATCH] 1.0.0-SNAPSHOT-U103 + Started implementing CustomData menus + Added PotionSkillEditorPanel to editor.yml --- plugin-modules/Core/resources-yml/editor.yml | 57 +++++++++ .../epicbosses/managers/BossPanelManager.java | 9 +- .../custom/CreatePotionEffectEditorPanel.java | 9 ++ .../skills/custom/PotionSkillEditorPanel.java | 115 ++++++++++++++++++ pom.xml | 2 +- 5 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 plugin-modules/Core/src/com/songoda/epicbosses/panel/skills/custom/CreatePotionEffectEditorPanel.java create mode 100644 plugin-modules/Core/src/com/songoda/epicbosses/panel/skills/custom/PotionSkillEditorPanel.java diff --git a/plugin-modules/Core/resources-yml/editor.yml b/plugin-modules/Core/resources-yml/editor.yml index 1254d04..74869f5 100644 --- a/plugin-modules/Core/resources-yml/editor.yml +++ b/plugin-modules/Core/resources-yml/editor.yml @@ -1429,3 +1429,60 @@ SkillTypeEditorPanel: - '&7This will remove any previous' - '&7custom skill data.' Button: Group +PotionSkillEditorPanel: + name: '&b&l{name} Skill Editor' + slots: 54 + Settings: + backButton: true + Buttons: + backButton: 54 + Items: + '46': + type: BOOK + name: '&e&lPotion Guide' + lore: + - '&7Here you can adjust the potion effects' + - '&7that are applied when the skill is' + - '&7called. If you want to remove a potion' + - '&7effect simply click on the potion and' + - '&7it will removed from the skill. If you' + - '&7want to add a new potion effect click' + - '&7on the green emerald block.' + '47': + type: GLASS_PANE + name: '&7' + '48': + type: GLASS_PANE + name: '&7' + '49': + type: ARROW + name: '&e&l&m<-&e&l Previous Page' + lore: + - '&7Click here to go to the previous' + - '&7page of custom drops.' + PreviousPage: true + '50': + type: EMERALD_BLOCK + name: '&e&lCreate a new Potion Effect' + lore: + - '&7Click here to create a new potion' + - '&7effect.' + Button: PotionEffect + '51': + type: ARROW + name: '&e&lNext Page &e&l&m->' + lore: + - '&7Click here to go to the next' + - '&7page of custom drops.' + NextPage: true + '52': + type: GLASS_PANE + name: '&7' + '53': + type: GLASS_PANE + name: '&7' + '54': + type: PAPER + name: '&e&lGo Back' + lore: + - '&7Click here to go back.' \ No newline at end of file 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 84361f3..d3bf73f 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossPanelManager.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossPanelManager.java @@ -21,7 +21,9 @@ import com.songoda.epicbosses.panel.bosses.weapons.OffHandEditorPanel; import com.songoda.epicbosses.panel.handlers.*; import com.songoda.epicbosses.panel.skills.MainSkillEditorPanel; import com.songoda.epicbosses.panel.skills.SkillTypeEditorPanel; +import com.songoda.epicbosses.panel.skills.custom.PotionSkillEditorPanel; import com.songoda.epicbosses.skills.Skill; +import com.songoda.epicbosses.skills.types.PotionSkillElement; import com.songoda.epicbosses.utils.panel.base.ISubVariablePanelHandler; import com.songoda.epicbosses.utils.panel.base.IVariablePanelHandler; import lombok.Getter; @@ -61,7 +63,8 @@ public class BossPanelManager implements ILoadable, IReloadable { onTauntTextEditMenu; @Getter private BossListEditorPanel equipmentListEditMenu, weaponListEditMenu, statisticListEditMenu; - @Getter private IVariablePanelHandler mainSkillEditMenu, customMessageEditMenu, skillTypeEditMenu; + @Getter private IVariablePanelHandler mainSkillEditMenu, customMessageEditMenu, skillTypeEditMenu, potionSkillEditorPanel; + @Getter private ISubVariablePanelHandler createPotionEffectMenu; private final CustomBosses customBosses; @@ -159,6 +162,7 @@ public class BossPanelManager implements ILoadable, IReloadable { FileConfiguration editor = this.customBosses.getEditor(); PanelBuilder panelBuilder = new PanelBuilder(editor.getConfigurationSection("SkillEditorPanel")); PanelBuilder panelBuilder1 = new PanelBuilder(editor.getConfigurationSection("SkillTypeEditorPanel")); + PanelBuilder panelBuilder2 = new PanelBuilder(editor.getConfigurationSection("PotionSkillEditorPanel")); this.mainSkillEditMenu = new MainSkillEditorPanel(this, panelBuilder, this.customBosses); this.customMessageEditMenu = new SingleMessageListEditor(this, getListMenu("Skills.MainEdit"), this.customBosses) { @@ -185,16 +189,19 @@ public class BossPanelManager implements ILoadable, IReloadable { } }; this.skillTypeEditMenu = new SkillTypeEditorPanel(this, panelBuilder1, this.customBosses); + this.potionSkillEditorPanel = new PotionSkillEditorPanel(this, panelBuilder2, this.customBosses); } private void reloadSkillEditMenus() { FileConfiguration editor = this.customBosses.getEditor(); PanelBuilder panelBuilder = new PanelBuilder(editor.getConfigurationSection("SkillEditorPanel")); PanelBuilder panelBuilder1 = new PanelBuilder(editor.getConfigurationSection("SkillTypeEditorPanel")); + PanelBuilder panelBuilder2 = new PanelBuilder(editor.getConfigurationSection("PotionSkillEditorPanel")); this.mainSkillEditMenu.initializePanel(panelBuilder); this.customMessageEditMenu.initializePanel(getListMenu("Skills.MainEdit")); this.skillTypeEditMenu.initializePanel(panelBuilder1); + this.potionSkillEditorPanel.initializePanel(panelBuilder2); } //--------------------------------------------- diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/panel/skills/custom/CreatePotionEffectEditorPanel.java b/plugin-modules/Core/src/com/songoda/epicbosses/panel/skills/custom/CreatePotionEffectEditorPanel.java new file mode 100644 index 0000000..b9dc86c --- /dev/null +++ b/plugin-modules/Core/src/com/songoda/epicbosses/panel/skills/custom/CreatePotionEffectEditorPanel.java @@ -0,0 +1,9 @@ +package com.songoda.epicbosses.panel.skills.custom; + +/** + * @author Charles Cullen + * @version 1.0.0 + * @since 02-Dec-18 + */ +public class CreatePotionEffectEditorPanel { +} diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/panel/skills/custom/PotionSkillEditorPanel.java b/plugin-modules/Core/src/com/songoda/epicbosses/panel/skills/custom/PotionSkillEditorPanel.java new file mode 100644 index 0000000..f4560a7 --- /dev/null +++ b/plugin-modules/Core/src/com/songoda/epicbosses/panel/skills/custom/PotionSkillEditorPanel.java @@ -0,0 +1,115 @@ +package com.songoda.epicbosses.panel.skills.custom; + +import com.songoda.epicbosses.CustomBosses; +import com.songoda.epicbosses.api.BossAPI; +import com.songoda.epicbosses.managers.BossPanelManager; +import com.songoda.epicbosses.managers.BossSkillManager; +import com.songoda.epicbosses.managers.files.SkillsFileManager; +import com.songoda.epicbosses.skills.Skill; +import com.songoda.epicbosses.skills.types.PotionSkillElement; +import com.songoda.epicbosses.utils.panel.Panel; +import com.songoda.epicbosses.utils.panel.base.handlers.VariablePanelHandler; +import com.songoda.epicbosses.utils.panel.builder.PanelBuilder; +import com.songoda.epicbosses.utils.panel.builder.PanelBuilderCounter; +import com.songoda.epicbosses.utils.potion.PotionEffectConverter; +import com.songoda.epicbosses.utils.potion.holder.PotionEffectHolder; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.PotionMeta; +import org.bukkit.potion.PotionEffect; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author Charles Cullen + * @version 1.0.0 + * @since 02-Dec-18 + */ +public class PotionSkillEditorPanel extends VariablePanelHandler { + + private PotionEffectConverter potionEffectConverter; + private SkillsFileManager skillsFileManager; + private BossSkillManager bossSkillManager; + + public PotionSkillEditorPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) { + super(bossPanelManager, panelBuilder); + + this.bossSkillManager = plugin.getBossSkillManager(); + this.skillsFileManager = plugin.getSkillsFileManager(); + this.potionEffectConverter = new PotionEffectConverter(); + } + + @Override + public void fillPanel(Panel panel, Skill skill) { + PotionSkillElement potionSkillElement = this.bossSkillManager.getPotionSkillElement(skill); + List potionEffectHolders = potionSkillElement.getPotions(); + int maxPage = panel.getMaxPage(potionEffectHolders); + + panel.setOnPageChange(((player, currentPage, requestedPage) -> { + if(requestedPage < 0 || requestedPage > maxPage) return false; + + loadPage(panel, requestedPage, potionEffectHolders, potionSkillElement); + return true; + })); + + loadPage(panel, 0, potionEffectHolders, potionSkillElement); + } + + @Override + public void openFor(Player player, Skill skill) { + Map replaceMap = new HashMap<>(); + PanelBuilder panelBuilder = getPanelBuilder().cloneBuilder(); + + replaceMap.put("{name}", BossAPI.getSkillName(skill)); + panelBuilder.addReplaceData(replaceMap); + + PanelBuilderCounter counter = panelBuilder.getPanelBuilderCounter(); + PotionSkillElement potionSkillElement = this.bossSkillManager.getPotionSkillElement(skill); + Panel panel = panelBuilder.getPanel() + .setDestroyWhenDone(true) + .setCancelClick(true) + .setCancelLowerClick(true) + .setParentPanelHandler(this.bossPanelManager.getMainSkillEditMenu(), skill); + + fillPanel(panel, skill); + counter.getSlotsWith("PotionEffect").forEach(slot -> panel.setOnClick(slot, event -> this.bossPanelManager.getCreatePotionEffectMenu().openFor((Player) event.getWhoClicked(), skill, potionSkillElement))); + + panel.openFor(player); + } + + @Override + public void initializePanel(PanelBuilder panelBuilder) { + PanelBuilderCounter panelBuilderCounter = panelBuilder.getPanelBuilderCounter(); + + panelBuilderCounter + .addSlotCounter("PotionEffect"); + } + + private void loadPage(Panel panel, int page, List potionEffectHolders, PotionSkillElement potionSkillElement) { + panel.loadPage(page, (slot, realisticSlot) -> { + if(slot >= potionEffectHolders.size()) { + panel.setItem(realisticSlot, new ItemStack(Material.AIR), e -> {}); + } else { + PotionEffectHolder potionEffectHolder = potionEffectHolders.get(slot); + PotionEffect potionEffect = this.potionEffectConverter.from(potionEffectHolder); + + ItemStack itemStack = new ItemStack(Material.POTION); + PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta(); + + potionMeta.addCustomEffect(potionEffect, true); + itemStack.setItemMeta(potionMeta); + + panel.setItem(realisticSlot, itemStack, e -> { + potionEffectHolders.remove(potionEffectHolder); + potionSkillElement.setPotions(potionEffectHolders); + this.skillsFileManager.save(); + + loadPage(panel, page, potionEffectHolders, potionSkillElement); + }); + } + }); + } +} diff --git a/pom.xml b/pom.xml index 9a71daf..edf5779 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ - 1.0.0-U102 + 1.0.0-U103 EpicBosses com.songoda.epicbosses.CustomBosses AMinecraftDev