diff --git a/plugin-modules/Core/resources-yml/config.yml b/plugin-modules/Core/resources-yml/config.yml index c40af32..4ca3431 100644 --- a/plugin-modules/Core/resources-yml/config.yml +++ b/plugin-modules/Core/resources-yml/config.yml @@ -34,6 +34,13 @@ Hooks: - 'blocked_region2' Display: Boss: + Text: + menuName: '&b&l{name} Editor' + selectedName: '&bMessage: &f{name} &a&l** Selected **' + name: '&bMessage: &f{name}' + lore: + - '&fStrings within this section:' + - '{message}' Commands: menuName: '&b&l{name} Editor' selectedName: '&bCommand: &f{name} &a&l** Selected **' diff --git a/plugin-modules/Core/resources-yml/editor.yml b/plugin-modules/Core/resources-yml/editor.yml index c94b11c..0d8b352 100644 --- a/plugin-modules/Core/resources-yml/editor.yml +++ b/plugin-modules/Core/resources-yml/editor.yml @@ -289,9 +289,6 @@ DropsMainEditorPanel: name: '&e&lGo Back' lore: - '&7Click here to go back.' - - - DropsEditorPanel: name: '&b&l{name} Editor' slots: 54 @@ -1095,7 +1092,7 @@ TextEditorMainPanel: Items: '1': type: BOOK - name: '&c&lCommands Guide' + name: '&c&lText Guide' lore: - '&7Here you can configure which command set' - '&7the boss has for specific events.' @@ -1112,6 +1109,7 @@ TextEditorMainPanel: lore: - '&7Here you can adjust the settings for' - '&7the taunts of the boss.' + Button: Taunts '6': type: REDSTONE name: '&e&lOn Death' @@ -1124,4 +1122,50 @@ TextEditorMainPanel: name: '&e&lGo Back' lore: - '&7Click here to go back.' - +TextEditorSubPanel: + name: '&b&l{name} Editor' + slots: 9 + Settings: + backButton: true + emptySpaceFiller: true + EmptySpaceFiller: + type: WHITE_STAINED_GLASS_PANE + name: '&7' + Buttons: + backButton: 5 + Items: + '3': + type: TALL_GRASS + name: '&e&lSelect Message' + lore: + - '&7Here you can change the message that is' + - '&7currently selected.' + - '&7' + - '&bCurrent: &f{selected}' + Button: Select + '5': + type: PAPER + name: '&e&lGo Back' + lore: + - '&7Click here to go back.' + '7': + type: REDSTONE + name: '&e&lRadius' + lore: + - '&7Here you can change the radius for' + - '&7this message. It is currently: &f{radius}' + - '&7blocks. Set it to &f-1&7 if you want it' + - '&7to be a server-wide broadcast.' + - '&7' + - '&bLeft Click »' + - '&7Increase the radius by &f1&7.' + - '&7' + - '&bShift Left-Click »' + - '&7Increase the radius by &f10&7.' + - '&7' + - '&bRight Click »' + - '&7Decrease the radius by &f1&7.' + - '&7' + - '&bShift Right-Click »' + - '&7Decrease the radius by &f10&7.' + Button: Radius 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 2ceb2ac..f3c3171 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossPanelManager.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossPanelManager.java @@ -14,6 +14,10 @@ import com.songoda.epicbosses.panel.bosses.equipment.HelmetEditorPanel; import com.songoda.epicbosses.panel.bosses.equipment.LeggingsEditorPanel; import com.songoda.epicbosses.panel.bosses.list.BossListStatisticEditorPanel; import com.songoda.epicbosses.panel.bosses.list.BossListWeaponEditorPanel; +import com.songoda.epicbosses.panel.bosses.text.OnDeathTextEditor; +import com.songoda.epicbosses.panel.bosses.text.OnDeathTextSubEditor; +import com.songoda.epicbosses.panel.bosses.text.OnSpawnTextEditor; +import com.songoda.epicbosses.panel.bosses.text.OnSpawnTextSubEditor; import com.songoda.epicbosses.panel.bosses.weapons.MainHandEditorPanel; import com.songoda.epicbosses.panel.bosses.weapons.OffHandEditorPanel; import com.songoda.epicbosses.utils.panel.base.ISubVariablePanelHandler; @@ -47,7 +51,7 @@ public class BossPanelManager implements ILoadable, IReloadable { @Getter private ISubVariablePanelHandler weaponEditMenu, offHandEditorMenu, mainHandEditorMenu; @Getter private ISubVariablePanelHandler statisticMainEditMenu, entityTypeEditMenu; @Getter private IVariablePanelHandler mainBossEditMenu, dropsEditMenu, targetingEditMenu, skillsBossEditMenu, skillListBossEditMenu, commandsMainEditMenu, onSpawnCommandEditMenu, onDeathCommandEditMenu; - @Getter private IVariablePanelHandler mainDropsEditMenu; + @Getter private IVariablePanelHandler mainDropsEditMenu, mainTextEditMenu, mainTauntEditMenu, onSpawnTextEditMenu, onSpawnSubTextEditMenu, onDeathTextEditMenu, onDeathSubTextEditMenu; @Getter private BossListEditorPanel equipmentListEditMenu, weaponListEditMenu, statisticListEditMenu; private final CustomBosses customBosses; @@ -75,6 +79,7 @@ public class BossPanelManager implements ILoadable, IReloadable { loadSkillsEditMenu(); loadStatEditMenu(); loadCommandEditMenus(); + loadTextEditMenus(); loadEquipmentEditMenu(); loadWeaponEditMenu(); @@ -101,6 +106,7 @@ public class BossPanelManager implements ILoadable, IReloadable { reloadSkillsEditMenu(); reloadStatEditMenu(); reloadCommandEditMenus(); + reloadTextEditMenus(); reloadEquipmentEditMenu(); reloadWeaponEditMenu(); @@ -133,6 +139,34 @@ public class BossPanelManager implements ILoadable, IReloadable { return timesUsed; } + //--------------------------------------------- + // + // T E X T E D I T P A N E L S + // + //--------------------------------------------- + + private void loadTextEditMenus() { + PanelBuilder panelBuilder = new PanelBuilder(this.customBosses.getEditor().getConfigurationSection("TextEditorMainPanel")); + PanelBuilder panelBuilder1 = new PanelBuilder(this.customBosses.getEditor().getConfigurationSection("TextEditorSubPanel")); + + this.mainTextEditMenu = new TextMainEditorPanel(this, panelBuilder); + this.onSpawnSubTextEditMenu = new OnSpawnTextSubEditor(this, panelBuilder1.cloneBuilder(), this.customBosses); + this.onDeathSubTextEditMenu = new OnDeathTextSubEditor(this, panelBuilder1.cloneBuilder(), this.customBosses); + this.onSpawnTextEditMenu = new OnSpawnTextEditor(this, getListMenu("Boss.Text"), this.customBosses); + this.onDeathTextEditMenu = new OnDeathTextEditor(this, getListMenu("Boss.Text"), this.customBosses); + } + + private void reloadTextEditMenus() { + PanelBuilder panelBuilder = new PanelBuilder(this.customBosses.getEditor().getConfigurationSection("TextEditorMainPanel")); + PanelBuilder panelBuilder1 = new PanelBuilder(this.customBosses.getEditor().getConfigurationSection("TextEditorSubPanel")); + + this.mainTextEditMenu.initializePanel(panelBuilder); + this.onSpawnSubTextEditMenu.initializePanel(panelBuilder1.cloneBuilder()); + this.onDeathSubTextEditMenu.initializePanel(panelBuilder1.cloneBuilder()); + this.onSpawnTextEditMenu.initializePanel(getListMenu("Boss.Text")); + this.onDeathTextEditMenu.initializePanel(getListMenu("Boss.Text")); + } + //--------------------------------------------- // // C O M M A N D S E D I T P A N E L S diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/MainBossEditPanel.java b/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/MainBossEditPanel.java index 1a0fed9..8d01e57 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/MainBossEditPanel.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/MainBossEditPanel.java @@ -83,6 +83,7 @@ public class MainBossEditPanel extends VariablePanelHandler { counter.getSlotsWith("Skill").forEach(slot -> panel.setOnClick(slot, e -> this.bossPanelManager.getSkillsBossEditMenu().openFor((Player) e.getWhoClicked(), bossEntity))); counter.getSlotsWith("Stats").forEach(slot -> panel.setOnClick(slot, e -> this.bossPanelManager.getStatisticListEditMenu().openFor((Player) e.getWhoClicked(), bossEntity))); counter.getSlotsWith("Command").forEach(slot -> panel.setOnClick(slot, e -> this.bossPanelManager.getCommandsMainEditMenu().openFor((Player) e.getWhoClicked(), bossEntity))); + counter.getSlotsWith("Text").forEach(slot -> panel.setOnClick(slot, e -> this.bossPanelManager.getMainTextEditMenu().openFor((Player) e.getWhoClicked(), bossEntity))); panel.openFor(player); } diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/TextMainEditorPanel.java b/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/TextMainEditorPanel.java index 06ff13f..bfeb942 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/TextMainEditorPanel.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/TextMainEditorPanel.java @@ -1,9 +1,62 @@ package com.songoda.epicbosses.panel.bosses; +import com.songoda.epicbosses.api.BossAPI; +import com.songoda.epicbosses.entity.BossEntity; +import com.songoda.epicbosses.managers.BossPanelManager; +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 org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.Map; + /** * @author Charles Cullen * @version 1.0.0 * @since 28-Nov-18 */ -public class TextMainEditorPanel { +public class TextMainEditorPanel extends VariablePanelHandler { + + public TextMainEditorPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder) { + super(bossPanelManager, panelBuilder); + } + + @Override + public void fillPanel(Panel panel, BossEntity bossEntity) { + + } + + @Override + public void openFor(Player player, BossEntity bossEntity) { + Map replaceMap = new HashMap<>(); + PanelBuilder panelBuilder = getPanelBuilder().cloneBuilder(); + + replaceMap.put("{name}", BossAPI.getBossEntityName(bossEntity)); + panelBuilder.addReplaceData(replaceMap); + + Panel panel = panelBuilder.getPanel() + .setDestroyWhenDone(true) + .setCancelClick(true) + .setCancelLowerClick(true) + .setParentPanelHandler(this.bossPanelManager.getMainBossEditMenu(), bossEntity); + PanelBuilderCounter counter = panel.getPanelBuilderCounter(); + + counter.getSlotsWith("OnSpawn").forEach(slot -> panel.setOnClick(slot, event -> this.bossPanelManager.getOnSpawnSubTextEditMenu().openFor((Player) event.getWhoClicked(), bossEntity))); + counter.getSlotsWith("OnDeath").forEach(slot -> panel.setOnClick(slot, event -> this.bossPanelManager.getOnDeathSubTextEditMenu().openFor((Player) event.getWhoClicked(), bossEntity))); + counter.getSlotsWith("Taunts").forEach(slot -> panel.setOnClick(slot, event -> this.bossPanelManager.getMainTauntEditMenu().openFor((Player) event.getWhoClicked(), bossEntity))); + + panel.openFor(player); + } + + @Override + public void initializePanel(PanelBuilder panelBuilder) { + PanelBuilderCounter panelBuilderCounter = panelBuilder.getPanelBuilderCounter(); + + panelBuilderCounter + .addSlotCounter("OnSpawn") + .addSlotCounter("OnDeath") + .addSlotCounter("Taunts"); + } } diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/commands/OnSpawnCommandEditor.java b/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/commands/OnSpawnCommandEditor.java index 3c35a75..a5fdf21 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/commands/OnSpawnCommandEditor.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/commands/OnSpawnCommandEditor.java @@ -5,8 +5,6 @@ import com.songoda.epicbosses.api.BossAPI; import com.songoda.epicbosses.entity.BossEntity; import com.songoda.epicbosses.managers.BossPanelManager; import com.songoda.epicbosses.managers.files.CommandsFileManager; -import com.songoda.epicbosses.skills.Skill; -import com.songoda.epicbosses.utils.NumberUtils; import com.songoda.epicbosses.utils.StringUtils; import com.songoda.epicbosses.utils.itemstack.ItemStackConverter; import com.songoda.epicbosses.utils.itemstack.ItemStackUtils; @@ -14,7 +12,6 @@ import com.songoda.epicbosses.utils.itemstack.holder.ItemStackHolder; 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 javafx.scene.layout.Pane; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/text/OnDeathTextEditor.java b/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/text/OnDeathTextEditor.java new file mode 100644 index 0000000..1d83aed --- /dev/null +++ b/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/text/OnDeathTextEditor.java @@ -0,0 +1,131 @@ +package com.songoda.epicbosses.panel.bosses.text; + +import com.songoda.epicbosses.CustomBosses; +import com.songoda.epicbosses.api.BossAPI; +import com.songoda.epicbosses.entity.BossEntity; +import com.songoda.epicbosses.managers.BossPanelManager; +import com.songoda.epicbosses.managers.files.MessagesFileManager; +import com.songoda.epicbosses.utils.StringUtils; +import com.songoda.epicbosses.utils.itemstack.ItemStackConverter; +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.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 29-Nov-18 + */ +public class OnDeathTextEditor extends VariablePanelHandler { + + private MessagesFileManager messagesFileManager; + private ItemStackConverter itemStackConverter; + private CustomBosses plugin; + + public OnDeathTextEditor(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) { + super(bossPanelManager, panelBuilder); + + this.plugin = plugin; + this.itemStackConverter = new ItemStackConverter(); + this.messagesFileManager = plugin.getBossMessagesFileManager(); + } + + @Override + public void fillPanel(Panel panel, BossEntity bossEntity) { + Map> currentTexts = this.messagesFileManager.getMessagesMap(); + List entryList = new ArrayList<>(currentTexts.keySet()); + int maxPage = panel.getMaxPage(entryList); + + panel.setOnPageChange(((player, currentPage, requestedPage) -> { + if(requestedPage < 0 || requestedPage > maxPage) return false; + + loadPage(panel, requestedPage, currentTexts, entryList, bossEntity); + return true; + })); + + loadPage(panel, 0, currentTexts, entryList, bossEntity); + } + + @Override + public void openFor(Player player, BossEntity bossEntity) { + Map replaceMap = new HashMap<>(); + PanelBuilder panelBuilder = getPanelBuilder().cloneBuilder(); + + replaceMap.put("{name}", BossAPI.getBossEntityName(bossEntity)); + panelBuilder.addReplaceData(replaceMap); + + Panel panel = panelBuilder.getPanel() + .setDestroyWhenDone(true) + .setCancelClick(true) + .setCancelLowerClick(true) + .setParentPanelHandler(this.bossPanelManager.getOnDeathSubTextEditMenu(), bossEntity); + + fillPanel(panel, bossEntity); + + panel.openFor(player); + } + + @Override + public void initializePanel(PanelBuilder panelBuilder) { + + } + + private void loadPage(Panel panel, int page, Map> currentMessages, List entryList, BossEntity bossEntity) { + String current = bossEntity.getMessages().getOnDeath().getMessage(); + + panel.loadPage(page, (slot, realisticSlot) -> { + if(slot >= entryList.size()) { + panel.setItem(realisticSlot, new ItemStack(Material.AIR), e -> {}); + } else { + String name = entryList.get(slot); + List messages = currentMessages.get(name); + ItemStackHolder itemStackHolder = BossAPI.getStoredItemStack("DefaultTextMenuItem"); + ItemStack itemStack = this.itemStackConverter.from(itemStackHolder); + + Map replaceMap = new HashMap<>(); + + replaceMap.put("{name}", name); + + if(current.equalsIgnoreCase(name)) { + ItemStackUtils.applyDisplayName(itemStack, this.plugin.getConfig().getString("Display.Boss.Text.selectedName"), replaceMap); + } else { + ItemStackUtils.applyDisplayName(itemStack, this.plugin.getConfig().getString("Display.Boss.Text.name"), replaceMap); + } + + ItemMeta itemMeta = itemStack.getItemMeta(); + List presetLore = this.plugin.getConfig().getStringList("Display.Boss.Text.lore"); + List newLore = new ArrayList<>(); + + for(String s : presetLore) { + if(s.contains("{message}")) { + for(String message : messages) { + newLore.add(StringUtils.get().translateColor("&7" + message)); + } + } else { + newLore.add(StringUtils.get().translateColor(s)); + } + } + + itemMeta.setLore(newLore); + itemStack.setItemMeta(itemMeta); + + panel.setItem(realisticSlot, itemStack, e -> { + bossEntity.getMessages().getOnDeath().setMessage(name); + this.plugin.getBossesFileManager().save(); + loadPage(panel, page, currentMessages, entryList, bossEntity); + }); + } + }); + } +} diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/text/OnDeathTextSubEditor.java b/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/text/OnDeathTextSubEditor.java new file mode 100644 index 0000000..1a54a05 --- /dev/null +++ b/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/text/OnDeathTextSubEditor.java @@ -0,0 +1,110 @@ +package com.songoda.epicbosses.panel.bosses.text; + +import com.songoda.epicbosses.CustomBosses; +import com.songoda.epicbosses.api.BossAPI; +import com.songoda.epicbosses.entity.BossEntity; +import com.songoda.epicbosses.managers.BossPanelManager; +import com.songoda.epicbosses.managers.files.BossesFileManager; +import com.songoda.epicbosses.utils.Message; +import com.songoda.epicbosses.utils.NumberUtils; +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 com.songoda.epicbosses.utils.panel.builder.PanelBuilderCounter; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author Charles Cullen + * @version 1.0.0 + * @since 29-Nov-18 + */ +public class OnDeathTextSubEditor extends VariablePanelHandler { + + private BossesFileManager bossesFileManager; + + public OnDeathTextSubEditor(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) { + super(bossPanelManager, panelBuilder); + + this.bossesFileManager = plugin.getBossesFileManager(); + } + + @Override + public void fillPanel(Panel panel, BossEntity bossEntity) { + + } + + @Override + public void openFor(Player player, BossEntity bossEntity) { + Map replaceMap = new HashMap<>(); + Integer radius = bossEntity.getMessages().getOnDeath().getRadius(); + String message = bossEntity.getMessages().getOnDeath().getMessage(); + PanelBuilder panelBuilder = getPanelBuilder().cloneBuilder(); + + if(radius == null) radius = 0; + if(message == null) message = "N/A"; + + replaceMap.put("{name}", BossAPI.getBossEntityName(bossEntity)); + replaceMap.put("{radius}", NumberUtils.get().formatDouble(radius)); + replaceMap.put("{selected}", message); + panelBuilder.addReplaceData(replaceMap); + + Panel panel = panelBuilder.getPanel() + .setDestroyWhenDone(true) + .setCancelClick(true) + .setCancelLowerClick(true) + .setParentPanelHandler(this.bossPanelManager.getMainTextEditMenu(), bossEntity); + PanelBuilderCounter counter = panel.getPanelBuilderCounter(); + + counter.getSlotsWith("Select").forEach(slot -> panel.setOnClick(slot, event -> this.bossPanelManager.getOnDeathTextEditMenu().openFor((Player) event.getWhoClicked(), bossEntity))); + counter.getSlotsWith("Radius").forEach(slot -> panel.setOnClick(slot, getRadiusAction(bossEntity))); + + panel.openFor(player); + } + + @Override + public void initializePanel(PanelBuilder panelBuilder) { + PanelBuilderCounter panelBuilderCounter = panelBuilder.getPanelBuilderCounter(); + + panelBuilderCounter + .addSlotCounter("Select") + .addSlotCounter("Radius"); + } + + private ClickAction getRadiusAction(BossEntity bossEntity) { + return event -> { + ClickType clickType = event.getClick(); + int radiusToModifyBy = 0; + + if(clickType == ClickType.LEFT) { + radiusToModifyBy = 1; + } else if(clickType == ClickType.SHIFT_LEFT) { + radiusToModifyBy = 10; + } else if(clickType == ClickType.RIGHT) { + radiusToModifyBy = -1; + } else if(clickType == ClickType.SHIFT_RIGHT) { + radiusToModifyBy = -10; + } + + String modifyValue = radiusToModifyBy > 0? "increased" : "decreased"; + Integer currentRadius = bossEntity.getMessages().getOnDeath().getRadius(); + + if(currentRadius == null) currentRadius = 0; + + int newRadius = currentRadius + radiusToModifyBy; + + if(newRadius < -1) { + newRadius = -1; + } + + bossEntity.getMessages().getOnDeath().setRadius(newRadius); + this.bossesFileManager.save(); + Message.Boss_Messages_SetRadiusOnDeath.msg(event.getWhoClicked(), modifyValue, NumberUtils.get().formatDouble(newRadius)); + openFor((Player) event.getWhoClicked(), bossEntity); + }; + } +} diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/text/OnSpawnTextEditor.java b/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/text/OnSpawnTextEditor.java new file mode 100644 index 0000000..c54aabf --- /dev/null +++ b/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/text/OnSpawnTextEditor.java @@ -0,0 +1,131 @@ +package com.songoda.epicbosses.panel.bosses.text; + +import com.songoda.epicbosses.CustomBosses; +import com.songoda.epicbosses.api.BossAPI; +import com.songoda.epicbosses.entity.BossEntity; +import com.songoda.epicbosses.managers.BossPanelManager; +import com.songoda.epicbosses.managers.files.MessagesFileManager; +import com.songoda.epicbosses.utils.StringUtils; +import com.songoda.epicbosses.utils.itemstack.ItemStackConverter; +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.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 29-Nov-18 + */ +public class OnSpawnTextEditor extends VariablePanelHandler { + + private MessagesFileManager messagesFileManager; + private ItemStackConverter itemStackConverter; + private CustomBosses plugin; + + public OnSpawnTextEditor(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) { + super(bossPanelManager, panelBuilder); + + this.plugin = plugin; + this.itemStackConverter = new ItemStackConverter(); + this.messagesFileManager = plugin.getBossMessagesFileManager(); + } + + @Override + public void fillPanel(Panel panel, BossEntity bossEntity) { + Map> currentTexts = this.messagesFileManager.getMessagesMap(); + List entryList = new ArrayList<>(currentTexts.keySet()); + int maxPage = panel.getMaxPage(entryList); + + panel.setOnPageChange(((player, currentPage, requestedPage) -> { + if(requestedPage < 0 || requestedPage > maxPage) return false; + + loadPage(panel, requestedPage, currentTexts, entryList, bossEntity); + return true; + })); + + loadPage(panel, 0, currentTexts, entryList, bossEntity); + } + + @Override + public void openFor(Player player, BossEntity bossEntity) { + Map replaceMap = new HashMap<>(); + PanelBuilder panelBuilder = getPanelBuilder().cloneBuilder(); + + replaceMap.put("{name}", BossAPI.getBossEntityName(bossEntity)); + panelBuilder.addReplaceData(replaceMap); + + Panel panel = panelBuilder.getPanel() + .setDestroyWhenDone(true) + .setCancelClick(true) + .setCancelLowerClick(true) + .setParentPanelHandler(this.bossPanelManager.getOnSpawnSubTextEditMenu(), bossEntity); + + fillPanel(panel, bossEntity); + + panel.openFor(player); + } + + @Override + public void initializePanel(PanelBuilder panelBuilder) { + + } + + private void loadPage(Panel panel, int page, Map> currentMessages, List entryList, BossEntity bossEntity) { + String current = bossEntity.getMessages().getOnSpawn().getMessage(); + + panel.loadPage(page, (slot, realisticSlot) -> { + if(slot >= entryList.size()) { + panel.setItem(realisticSlot, new ItemStack(Material.AIR), e -> {}); + } else { + String name = entryList.get(slot); + List messages = currentMessages.get(name); + ItemStackHolder itemStackHolder = BossAPI.getStoredItemStack("DefaultTextMenuItem"); + ItemStack itemStack = this.itemStackConverter.from(itemStackHolder); + + Map replaceMap = new HashMap<>(); + + replaceMap.put("{name}", name); + + if(current.equalsIgnoreCase(name)) { + ItemStackUtils.applyDisplayName(itemStack, this.plugin.getConfig().getString("Display.Boss.Text.selectedName"), replaceMap); + } else { + ItemStackUtils.applyDisplayName(itemStack, this.plugin.getConfig().getString("Display.Boss.Text.name"), replaceMap); + } + + ItemMeta itemMeta = itemStack.getItemMeta(); + List presetLore = this.plugin.getConfig().getStringList("Display.Boss.Text.lore"); + List newLore = new ArrayList<>(); + + for(String s : presetLore) { + if(s.contains("{message}")) { + for(String message : messages) { + newLore.add(StringUtils.get().translateColor("&7" + message)); + } + } else { + newLore.add(StringUtils.get().translateColor(s)); + } + } + + itemMeta.setLore(newLore); + itemStack.setItemMeta(itemMeta); + + panel.setItem(realisticSlot, itemStack, e -> { + bossEntity.getMessages().getOnSpawn().setMessage(name); + this.plugin.getBossesFileManager().save(); + loadPage(panel, page, currentMessages, entryList, bossEntity); + }); + } + }); + } +} diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/text/OnSpawnTextSubEditor.java b/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/text/OnSpawnTextSubEditor.java new file mode 100644 index 0000000..782d368 --- /dev/null +++ b/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/text/OnSpawnTextSubEditor.java @@ -0,0 +1,110 @@ +package com.songoda.epicbosses.panel.bosses.text; + +import com.songoda.epicbosses.CustomBosses; +import com.songoda.epicbosses.api.BossAPI; +import com.songoda.epicbosses.entity.BossEntity; +import com.songoda.epicbosses.managers.BossPanelManager; +import com.songoda.epicbosses.managers.files.BossesFileManager; +import com.songoda.epicbosses.utils.Message; +import com.songoda.epicbosses.utils.NumberUtils; +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 com.songoda.epicbosses.utils.panel.builder.PanelBuilderCounter; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author Charles Cullen + * @version 1.0.0 + * @since 29-Nov-18 + */ +public class OnSpawnTextSubEditor extends VariablePanelHandler { + + private BossesFileManager bossesFileManager; + + public OnSpawnTextSubEditor(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) { + super(bossPanelManager, panelBuilder); + + this.bossesFileManager = plugin.getBossesFileManager(); + } + + @Override + public void fillPanel(Panel panel, BossEntity bossEntity) { + + } + + @Override + public void openFor(Player player, BossEntity bossEntity) { + Map replaceMap = new HashMap<>(); + Integer radius = bossEntity.getMessages().getOnSpawn().getRadius(); + String message = bossEntity.getMessages().getOnDeath().getMessage(); + PanelBuilder panelBuilder = getPanelBuilder().cloneBuilder(); + + if(radius == null) radius = 0; + if(message == null) message = "N/A"; + + replaceMap.put("{name}", BossAPI.getBossEntityName(bossEntity)); + replaceMap.put("{radius}", NumberUtils.get().formatDouble(radius)); + replaceMap.put("{selected}", message); + panelBuilder.addReplaceData(replaceMap); + + Panel panel = panelBuilder.getPanel() + .setDestroyWhenDone(true) + .setCancelClick(true) + .setCancelLowerClick(true) + .setParentPanelHandler(this.bossPanelManager.getMainTextEditMenu(), bossEntity); + PanelBuilderCounter counter = panel.getPanelBuilderCounter(); + + counter.getSlotsWith("Select").forEach(slot -> panel.setOnClick(slot, event -> this.bossPanelManager.getOnSpawnTextEditMenu().openFor((Player) event.getWhoClicked(), bossEntity))); + counter.getSlotsWith("Radius").forEach(slot -> panel.setOnClick(slot, getRadiusAction(bossEntity))); + + panel.openFor(player); + } + + @Override + public void initializePanel(PanelBuilder panelBuilder) { + PanelBuilderCounter panelBuilderCounter = panelBuilder.getPanelBuilderCounter(); + + panelBuilderCounter + .addSlotCounter("Select") + .addSlotCounter("Radius"); + } + + private ClickAction getRadiusAction(BossEntity bossEntity) { + return event -> { + ClickType clickType = event.getClick(); + int radiusToModifyBy = 0; + + if(clickType == ClickType.LEFT) { + radiusToModifyBy = 1; + } else if(clickType == ClickType.SHIFT_LEFT) { + radiusToModifyBy = 10; + } else if(clickType == ClickType.RIGHT) { + radiusToModifyBy = -1; + } else if(clickType == ClickType.SHIFT_RIGHT) { + radiusToModifyBy = -10; + } + + String modifyValue = radiusToModifyBy > 0? "increased" : "decreased"; + Integer currentRadius = bossEntity.getMessages().getOnSpawn().getRadius(); + + if(currentRadius == null) currentRadius = 0; + + int newRadius = currentRadius + radiusToModifyBy; + + if(newRadius < -1) { + newRadius = -1; + } + + bossEntity.getMessages().getOnSpawn().setRadius(newRadius); + this.bossesFileManager.save(); + Message.Boss_Messages_SetRadiusOnSpawn.msg(event.getWhoClicked(), modifyValue, NumberUtils.get().formatDouble(newRadius)); + openFor((Player) event.getWhoClicked(), bossEntity); + }; + } +} 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 b9e5f1d..2da5327 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/utils/Message.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/utils/Message.java @@ -106,6 +106,9 @@ public enum Message { Boss_Menu_NoPermission("&c&l(!) &cYou do not have access to this command."), + Boss_Messages_SetRadiusOnSpawn("&b&lEpicBosses &8» &7You have just {0} the radius for the onSpawn message to &f{1}&7."), + Boss_Messages_SetRadiusOnDeath("&b&lEpicBosses &8» &7You have just {0} the radius for the onDeath message to &f{1}&7."), + Boss_Nearby_NoPermission("&c&l(!) &cYou do not have access to this command."), Boss_Nearby_MaxRadius("&c&l(!) &cYou cannot check for bosses any further then &f{0}&c away from your position."), Boss_Nearby_NoneNearby("&b&lEpicBosses &8» &7There is currently no nearby bosses."), diff --git a/pom.xml b/pom.xml index 33a28af..37c273d 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ - maven-version-number-SNAPSHOT-U89 + maven-version-number-SNAPSHOT-U90 EpicBosses com.songoda.epicbosses.CustomBosses AMinecraftDev