From be18aba3746e7ae89fa62e49d5c41e7a5b02cde2 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 27 Nov 2018 22:33:14 +0800 Subject: [PATCH] 1.0.0-SNAPSHOT-U85 + Added EntityTypeEditor Panel + Finished StatisticsEditor Panels --- plugin-modules/Core/resources-yml/config.yml | 4 + .../handlers/BossDisplayNameHandler.java | 79 ++++++++++ .../epicbosses/managers/BossPanelManager.java | 4 +- .../mechanics/boss/EntityTypeMechanic.java | 2 - .../panel/EntityTypeEditorPanel.java | 140 ++++++++++++++++++ .../panel/bosses/MainBossEditPanel.java | 1 + .../bosses/StatisticMainEditorPanel.java | 35 ++++- .../songoda/epicbosses/utils/IHandler.java | 12 ++ .../com/songoda/epicbosses/utils/Message.java | 6 +- pom.xml | 2 +- 10 files changed, 272 insertions(+), 13 deletions(-) create mode 100644 plugin-modules/Core/src/com/songoda/epicbosses/handlers/BossDisplayNameHandler.java create mode 100644 plugin-modules/Core/src/com/songoda/epicbosses/panel/EntityTypeEditorPanel.java create mode 100644 plugin-modules/Core/src/com/songoda/epicbosses/utils/IHandler.java diff --git a/plugin-modules/Core/resources-yml/config.yml b/plugin-modules/Core/resources-yml/config.yml index e87bed1..87b2d18 100644 --- a/plugin-modules/Core/resources-yml/config.yml +++ b/plugin-modules/Core/resources-yml/config.yml @@ -33,6 +33,10 @@ Hooks: - 'blocked_region1' - 'blocked_region2' Display: + EntityTypeEditor: + menuName: '&b&l{name} Editor' + selectedName: '&f{name} Entity &a&l** Selected **' + name: '&f{name} Entity' BossListEditor: name: '&3{position} Entity' lore: diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/handlers/BossDisplayNameHandler.java b/plugin-modules/Core/src/com/songoda/epicbosses/handlers/BossDisplayNameHandler.java new file mode 100644 index 0000000..8c8bebe --- /dev/null +++ b/plugin-modules/Core/src/com/songoda/epicbosses/handlers/BossDisplayNameHandler.java @@ -0,0 +1,79 @@ +package com.songoda.epicbosses.handlers; + +import com.songoda.epicbosses.entity.BossEntity; +import com.songoda.epicbosses.entity.elements.EntityStatsElement; +import com.songoda.epicbosses.managers.files.BossesFileManager; +import com.songoda.epicbosses.utils.IHandler; +import com.songoda.epicbosses.utils.ServerUtils; +import com.songoda.epicbosses.utils.panel.base.ISubVariablePanelHandler; +import lombok.Getter; +import lombok.Setter; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; + +import java.util.UUID; + +/** + * @author Charles Cullen + * @version 1.0.0 + * @since 27-Nov-18 + */ +public class BossDisplayNameHandler implements IHandler { + + @Getter private final ISubVariablePanelHandler panelHandler; + + @Getter private final EntityStatsElement entityStatsElement; + @Getter private final BossesFileManager bossesFileManager; + @Getter private final BossEntity bossEntity; + @Getter private final Player player; + + @Getter @Setter private boolean handled = false; + private Listener listener; + + public BossDisplayNameHandler(Player player, BossEntity bossEntity, EntityStatsElement entityStatsElement, BossesFileManager bossesFileManager, ISubVariablePanelHandler panelHandler) { + this.entityStatsElement = entityStatsElement; + this.bossEntity = bossEntity; + this.player = player; + this.bossesFileManager = bossesFileManager; + this.panelHandler = panelHandler; + + this.listener = getListener(); + } + + @Override + public void handle() { + ServerUtils.get().registerListener(this.listener); + } + + private Listener getListener() { + return new Listener() { + @EventHandler + public void onChat(AsyncPlayerChatEvent event) { + Player player = event.getPlayer(); + UUID uuid = player.getUniqueId(); + + if(!uuid.equals(getPlayer().getUniqueId())) return; + if(isHandled()) return; + + String input = event.getMessage(); + + if(input.equalsIgnoreCase("-")) { + input = null; + } + + getEntityStatsElement().getMainStats().setDisplayName(input); + getBossesFileManager().save(); + setHandled(true); + + finish(); + } + }; + } + + private void finish() { + AsyncPlayerChatEvent.getHandlerList().unregister(this.listener); + getPanelHandler().openFor(getPlayer(), getBossEntity(), getEntityStatsElement()); + } +} 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 d872f66..a3e888a 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossPanelManager.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossPanelManager.java @@ -43,7 +43,7 @@ public class BossPanelManager implements ILoadable, IReloadable { @Getter private ISubVariablePanelHandler equipmentEditMenu, helmetEditorMenu, chestplateEditorMenu, leggingsEditorMenu, bootsEditorMenu; @Getter private ISubVariablePanelHandler weaponEditMenu, offHandEditorMenu, mainHandEditorMenu; - @Getter private ISubVariablePanelHandler statisticMainEditMenu; + @Getter private ISubVariablePanelHandler statisticMainEditMenu, entityTypeEditMenu; @Getter private IVariablePanelHandler mainBossEditMenu, dropsEditMenu, targetingEditMenu, skillsBossEditMenu, skillListBossEditMenu; @Getter private BossListEditorPanel equipmentListEditMenu, weaponListEditMenu, statisticListEditMenu; @@ -193,12 +193,14 @@ public class BossPanelManager implements ILoadable, IReloadable { PanelBuilder panelBuilder = new PanelBuilder(this.customBosses.getEditor().getConfigurationSection("StatisticsMainEditorPanel")); this.statisticMainEditMenu = new StatisticMainEditorPanel(this, panelBuilder, this.customBosses); + this.entityTypeEditMenu = new EntityTypeEditorPanel(this, getListMenu("EntityTypeEditor"), this.customBosses); } private void reloadStatEditMenu() { PanelBuilder panelBuilder = new PanelBuilder(this.customBosses.getEditor().getConfigurationSection("StatisticsMainEditorPanel")); this.statisticMainEditMenu.initializePanel(panelBuilder); + this.entityTypeEditMenu.initializePanel(getListMenu("EntityTypeEditor")); } //--------------------------------------------- diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/mechanics/boss/EntityTypeMechanic.java b/plugin-modules/Core/src/com/songoda/epicbosses/mechanics/boss/EntityTypeMechanic.java index daa0106..d47a47e 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/mechanics/boss/EntityTypeMechanic.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/mechanics/boss/EntityTypeMechanic.java @@ -30,8 +30,6 @@ public class EntityTypeMechanic implements IBossMechanic { if(position == null) position = 1; if(entityFinder == null) return false; - System.out.println("SPAWNING BOSS #" + position); - LivingEntity livingEntity = entityFinder.spawnNewLivingEntity(bossEntityType, activeBossHolder.getLocation()); if(livingEntity == null) return false; diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/panel/EntityTypeEditorPanel.java b/plugin-modules/Core/src/com/songoda/epicbosses/panel/EntityTypeEditorPanel.java new file mode 100644 index 0000000..d1bf28a --- /dev/null +++ b/plugin-modules/Core/src/com/songoda/epicbosses/panel/EntityTypeEditorPanel.java @@ -0,0 +1,140 @@ +package com.songoda.epicbosses.panel; + +import com.songoda.epicbosses.CustomBosses; +import com.songoda.epicbosses.api.BossAPI; +import com.songoda.epicbosses.entity.BossEntity; +import com.songoda.epicbosses.entity.elements.EntityStatsElement; +import com.songoda.epicbosses.managers.BossPanelManager; +import com.songoda.epicbosses.utils.*; +import com.songoda.epicbosses.utils.itemstack.ItemStackUtils; +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.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * @author Charles Cullen + * @version 1.0.0 + * @since 27-Nov-18 + */ +public class EntityTypeEditorPanel extends SubVariablePanelHandler { + + private CustomBosses plugin; + + public EntityTypeEditorPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) { + super(bossPanelManager, panelBuilder); + + this.plugin = plugin; + } + + @Override + public void fillPanel(Panel panel, BossEntity bossEntity, EntityStatsElement entityStatsElement) { + List list = Arrays.stream(EntityType.values()).filter(EntityType::isSpawnable).collect(Collectors.toList()); + Map filteredMap = getFilteredMap(list); + List filteredList = new ArrayList<>(filteredMap.keySet()); + int maxPage = panel.getMaxPage(filteredMap); + + panel.setOnPageChange(((player, currentPage, requestedPage) -> { + if(requestedPage < 0 || requestedPage > maxPage) return false; + + loadPage(panel, requestedPage, filteredMap, filteredList, bossEntity, entityStatsElement); + return true; + })); + + loadPage(panel, 0, filteredMap, filteredList, bossEntity, entityStatsElement); + } + + @Override + public void openFor(Player player, BossEntity bossEntity, EntityStatsElement entityStatsElement) { + 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.getStatisticMainEditMenu(), bossEntity, entityStatsElement); + + fillPanel(panel, bossEntity, entityStatsElement); + + panel.openFor(player); + } + + @Override + public void initializePanel(PanelBuilder panelBuilder) { + + } + + private Map getFilteredMap(List entityTypes) { + Map filteredMap = new HashMap<>(); + + entityTypes.forEach(entityType -> { + String materialName = entityType + "_SPAWN_EGG"; + Material material = Material.matchMaterial(materialName); + + if(material == null) return; + + filteredMap.put(entityType, material); + }); + + return filteredMap; + } + + private void loadPage(Panel panel, int requestedPage, Map filteredMap, List filteredList, BossEntity bossEntity, EntityStatsElement entityStatsElement) { + String entityTypeValue = entityStatsElement.getMainStats().getEntityType(); + + ServerUtils.get().runTaskAsync(() -> panel.loadPage(requestedPage, ((slot, realisticSlot) -> { + if(slot >= filteredMap.size()) { + panel.setItem(realisticSlot, new ItemStack(Material.AIR), e -> {}); + } else { + EntityType entityType = filteredList.get(slot); + Material material = filteredMap.get(entityType); + ItemStack itemStack = new ItemStack(material); + + Map replaceMap = new HashMap<>(); + boolean found = false; + + replaceMap.put("{name}", StringUtils.get().formatString(entityType.name())); + + if(entityTypeValue != null) { + EntityFinder entityFinder = EntityFinder.get(entityTypeValue); + + if (entityFinder != null) { + for (String s : entityFinder.getNames()) { + if (s.equalsIgnoreCase(entityType.name())) { + ItemStackUtils.applyDisplayName(itemStack, this.plugin.getConfig().getString("Display.EntityTypeEditor.selectedName"), replaceMap); + found = true; + break; + } + } + } + } + + if(!found) { + ItemStackUtils.applyDisplayName(itemStack, this.plugin.getConfig().getString("Display.EntityTypeEditor.name"), replaceMap); + } + + panel.setItem(realisticSlot, itemStack, e -> { + EntityFinder entityFinder = EntityFinder.get(entityType.name()); + + if(entityFinder != null) { + Message.Boss_Statistics_SetEntityFinder.msg(e.getWhoClicked(), entityFinder.getFancyName()); + entityStatsElement.getMainStats().setEntityType(entityFinder.getFancyName()); + this.plugin.getBossesFileManager().save(); + + loadPage(panel, requestedPage, filteredMap, filteredList, bossEntity, entityStatsElement); + } + }); + } + }))); + } +} 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 2e8e4ca..07d4909 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 @@ -80,6 +80,7 @@ public class MainBossEditPanel extends VariablePanelHandler { counter.getSlotsWith("Equipment").forEach(slot -> panel.setOnClick(slot, e -> this.bossPanelManager.getEquipmentListEditMenu().openFor((Player) e.getWhoClicked(), bossEntity))); counter.getSlotsWith("Weapon").forEach(slot -> panel.setOnClick(slot, e -> this.bossPanelManager.getWeaponListEditMenu().openFor((Player) e.getWhoClicked(), bossEntity))); 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))); panel.openFor(player); } diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/StatisticMainEditorPanel.java b/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/StatisticMainEditorPanel.java index e007214..65ff6fd 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/StatisticMainEditorPanel.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/panel/bosses/StatisticMainEditorPanel.java @@ -4,8 +4,10 @@ import com.songoda.epicbosses.CustomBosses; import com.songoda.epicbosses.api.BossAPI; import com.songoda.epicbosses.entity.BossEntity; import com.songoda.epicbosses.entity.elements.EntityStatsElement; +import com.songoda.epicbosses.handlers.BossDisplayNameHandler; import com.songoda.epicbosses.managers.BossPanelManager; import com.songoda.epicbosses.managers.files.BossesFileManager; +import com.songoda.epicbosses.utils.EntityFinder; import com.songoda.epicbosses.utils.Message; import com.songoda.epicbosses.utils.NumberUtils; import com.songoda.epicbosses.utils.panel.Panel; @@ -13,6 +15,7 @@ import com.songoda.epicbosses.utils.panel.base.ClickAction; import com.songoda.epicbosses.utils.panel.base.handlers.SubVariablePanelHandler; import com.songoda.epicbosses.utils.panel.builder.PanelBuilder; import com.songoda.epicbosses.utils.panel.builder.PanelBuilderCounter; +import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; @@ -45,6 +48,7 @@ public class StatisticMainEditorPanel extends SubVariablePanelHandler panel.setOnClick(slot, event -> {})); - counter.getSlotsWith("EntityType").forEach(slot -> panel.setOnClick(slot, event -> this.bossPanelManager.getSkillListBossEditMenu().openFor((Player) event.getWhoClicked(), bossEntity))); + counter.getSlotsWith("DisplayName").forEach(slot -> panel.setOnClick(slot, getDisplayNameAction(bossEntity, entityStatsElement))); + counter.getSlotsWith("EntityType").forEach(slot -> panel.setOnClick(slot, event -> this.bossPanelManager.getEntityTypeEditMenu().openFor((Player) event.getWhoClicked(), bossEntity, entityStatsElement))); counter.getSlotsWith("Health").forEach(slot -> panel.setOnClick(slot, getHealthAction(bossEntity, entityStatsElement))); panel.openFor(player); @@ -75,6 +83,17 @@ public class StatisticMainEditorPanel extends SubVariablePanelHandler { + Player humanEntity = (Player) event.getWhoClicked(); + BossDisplayNameHandler bossDisplayNameHandler = new BossDisplayNameHandler(humanEntity, bossEntity, entityStatsElement, this.bossesFileManager, this); + + Message.Boss_Statistics_SetDisplayName.msg(humanEntity); + bossDisplayNameHandler.handle(); + humanEntity.closeInventory(); + }; + } + private ClickAction getHealthAction(BossEntity bossEntity, EntityStatsElement entityStatsElement) { return event -> { ClickType clickType = event.getClick(); @@ -95,15 +114,15 @@ public class StatisticMainEditorPanel extends SubVariablePanelHandler - maven-version-number-SNAPSHOT-U84 + maven-version-number-SNAPSHOT-U85 EpicBosses com.songoda.epicbosses.CustomBosses AMinecraftDev