diff --git a/plugin-modules/Core/resources-yml/editor.yml b/plugin-modules/Core/resources-yml/editor.yml index b42c544..669dd61 100644 --- a/plugin-modules/Core/resources-yml/editor.yml +++ b/plugin-modules/Core/resources-yml/editor.yml @@ -2234,6 +2234,62 @@ SprayRewardMainEditMenu: - '&7You can always re-create this section if' - '&7was a mistake.' Button: Remove + '9': + type: REDSTONE + name: '&e&lGo Back' + lore: + - '&7Click here to go back.' +DropDropTableMainEditMenu: + name: '&b&l{name} Editor' + slots: 9 + Settings: + backButton: true + emptySpaceFiller: true + EmptySpaceFiller: + type: WHITE_STAINED_GLASS_PANE + name: '&7' + Buttons: + backButton: 9 + Items: + '3': + type: DIAMOND + name: '&e&lRewards' + lore: + - '&7Click here to modify the rewards and their' + - '&7assigned drop chances. You can add more by' + - '&7clicking the emerald block at the middle' + - '&7bottom of the rewards menu.' + Button: Rewards + '4': + type: GUNPOWDER + name: '&e&lRandom Drops' + lore: + - '&bCurrently: &f{randomDrops}' + - '&7Click here to toggle the random drop mode.' + - '&7If this is set to &ftrue&7 then when the' + - '&7drop table is called it will shuffle the' + - '&7list contents so it''s not in the same order.' + - '&7If this is set to &ffalse&7 then when the' + - '&7drop table is called it will go from top to' + - '&7bottom through the list.' + Button: RandomDrops + '5': + type: EMERALD + name: '&e&lMax Drops' + lore: + - '&bCurrently: &f{maxDrops}' + - '&7Click here to modify the maximum amount of' + - '&7drops this drop table can have. Keep in mind' + - '&7that when getting drops the drop table will' + - '&7only cycle through the list once. Not until' + - '&7this amount of drops has been met.' + - '&7' + - '&bLeft Click &8» &f+1' + - '&bShift Left-Click &8» &f+10' + - '&7' + - '&bRight Click &8» &f-1' + - '&bShift Right-Click &8» &f-10' + Button: MaxDrops '9': type: REDSTONE name: '&e&lGo Back' 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 a25b320..e03dc17 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossPanelManager.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossPanelManager.java @@ -25,6 +25,9 @@ import com.songoda.epicbosses.panel.bosses.weapons.OffHandEditorPanel; import com.songoda.epicbosses.panel.droptables.DropTableTypeEditorPanel; import com.songoda.epicbosses.panel.droptables.MainDropTableEditorPanel; import com.songoda.epicbosses.panel.droptables.types.drop.DropDropTableMainEditorPanel; +import com.songoda.epicbosses.panel.droptables.types.drop.DropNewRewardEditorPanel; +import com.songoda.epicbosses.panel.droptables.types.drop.DropRewardMainEditorPanel; +import com.songoda.epicbosses.panel.droptables.types.drop.DropRewardsListEditorPanel; import com.songoda.epicbosses.panel.droptables.types.give.GiveDropTableMainEditorPanel; import com.songoda.epicbosses.panel.droptables.types.spray.SprayDropTableMainEditorPanel; import com.songoda.epicbosses.panel.droptables.types.spray.SprayNewRewardEditorPanel; @@ -98,7 +101,8 @@ public class BossPanelManager implements ILoadable, IReloadable { @Getter private ISubVariablePanelHandler sprayDropTableMainEditMenu, sprayRewardListEditMenu, sprayNewRewardEditMenu; @Getter private ISubSubVariablePanelHandler sprayRewardMainEditMenu; @Getter private ISubVariablePanelHandler giveDropTableMainEditMenu; - @Getter private ISubVariablePanelHandler dropDropTableMainEditMenu; + @Getter private ISubVariablePanelHandler dropDropTableMainEditMenu, dropRewardListEditMenu, dropNewRewardEditMenu; + @Getter private ISubSubVariablePanelHandler dropRewardMainEditMenu; private final CustomBosses customBosses; @@ -215,15 +219,26 @@ public class BossPanelManager implements ILoadable, IReloadable { PanelBuilder panelBuilder1 = new PanelBuilder(editor.getConfigurationSection("DropTableTypeEditorPanel")); PanelBuilder panelBuilder2 = new PanelBuilder(editor.getConfigurationSection("SprayDropTableMainEditMenu")); PanelBuilder panelBuilder3 = new PanelBuilder(editor.getConfigurationSection("SprayRewardsListEditMenu")); - PanelBuilder panelBuilder4 = new PanelBuilder(editor.getConfigurationSection("SprayDropTableMainEditMenu")); //TODO + PanelBuilder panelBuilder4 = new PanelBuilder(editor.getConfigurationSection("SprayDropTableMainEditMenu")); PanelBuilder panelBuilder5 = new PanelBuilder(editor.getConfigurationSection("SprayNewRewardEditMenu")); + PanelBuilder panelBuilder6 = new PanelBuilder(editor.getConfigurationSection("DropDropTableMainEditMenu")); + PanelBuilder panelBuilder7 = new PanelBuilder(editor.getConfigurationSection("DropRewardsListEditMenu")); + PanelBuilder panelBuilder8 = new PanelBuilder(editor.getConfigurationSection("DropDropTableMainEditMenu")); + PanelBuilder panelBuilder9 = new PanelBuilder(editor.getConfigurationSection("DropNewRewardEditMenu")); + this.mainDropTableEditMenu = new MainDropTableEditorPanel(this, panelBuilder); this.dropTableTypeEditMenu = new DropTableTypeEditorPanel(this, panelBuilder1, this.customBosses); + this.sprayDropTableMainEditMenu = new SprayDropTableMainEditorPanel(this, panelBuilder2, this.customBosses); this.sprayRewardListEditMenu = new SprayRewardsListEditorPanel(this, panelBuilder3, this.customBosses); this.sprayRewardMainEditMenu = new SprayRewardMainEditorPanel(this, panelBuilder4, this.customBosses); this.sprayNewRewardEditMenu = new SprayNewRewardEditorPanel(this, panelBuilder5, this.customBosses); + + this.dropDropTableMainEditMenu = new DropDropTableMainEditorPanel(this, panelBuilder6, this.customBosses); + this.dropRewardListEditMenu = new DropRewardsListEditorPanel(this, panelBuilder7, this.customBosses); + this.dropRewardMainEditMenu = new DropRewardMainEditorPanel(this, panelBuilder8, this.customBosses); + this.dropNewRewardEditMenu = new DropNewRewardEditorPanel(this, panelBuilder9, this.customBosses); } private void reloadDropTableEditMenus() { @@ -232,15 +247,26 @@ public class BossPanelManager implements ILoadable, IReloadable { PanelBuilder panelBuilder1 = new PanelBuilder(editor.getConfigurationSection("DropTableTypeEditorPanel")); PanelBuilder panelBuilder2 = new PanelBuilder(editor.getConfigurationSection("SprayDropTableMainEditMenu")); PanelBuilder panelBuilder3 = new PanelBuilder(editor.getConfigurationSection("SprayRewardsListEditMenu")); - PanelBuilder panelBuilder4 = new PanelBuilder(editor.getConfigurationSection("SprayDropTableMainEditMenu")); //TODO + PanelBuilder panelBuilder4 = new PanelBuilder(editor.getConfigurationSection("SprayDropTableMainEditMenu")); PanelBuilder panelBuilder5 = new PanelBuilder(editor.getConfigurationSection("SprayNewRewardEditMenu")); + PanelBuilder panelBuilder6 = new PanelBuilder(editor.getConfigurationSection("DropDropTableMainEditMenu")); + PanelBuilder panelBuilder7 = new PanelBuilder(editor.getConfigurationSection("DropRewardsListEditMenu")); + PanelBuilder panelBuilder8 = new PanelBuilder(editor.getConfigurationSection("DropDropTableMainEditMenu")); + PanelBuilder panelBuilder9 = new PanelBuilder(editor.getConfigurationSection("DropNewRewardEditMenu")); + this.mainDropTableEditMenu.initializePanel(panelBuilder); this.dropTableTypeEditMenu.initializePanel(panelBuilder1); + this.sprayDropTableMainEditMenu.initializePanel(panelBuilder2); this.sprayRewardListEditMenu.initializePanel(panelBuilder3); this.sprayRewardMainEditMenu.initializePanel(panelBuilder4); this.sprayNewRewardEditMenu.initializePanel(panelBuilder5); + + this.dropDropTableMainEditMenu.initializePanel(panelBuilder6); + this.dropRewardListEditMenu.initializePanel(panelBuilder7); + this.dropRewardMainEditMenu.initializePanel(panelBuilder8); + this.dropNewRewardEditMenu.initializePanel(panelBuilder9); } //--------------------------------------------- diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/panel/droptables/types/drop/DropDropTableMainEditorPanel.java b/plugin-modules/Core/src/com/songoda/epicbosses/panel/droptables/types/drop/DropDropTableMainEditorPanel.java index 4c7b418..e539c61 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/panel/droptables/types/drop/DropDropTableMainEditorPanel.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/panel/droptables/types/drop/DropDropTableMainEditorPanel.java @@ -1,17 +1,22 @@ package com.songoda.epicbosses.panel.droptables.types.drop; +import com.google.gson.JsonObject; import com.songoda.epicbosses.CustomBosses; import com.songoda.epicbosses.api.BossAPI; import com.songoda.epicbosses.droptable.DropTable; import com.songoda.epicbosses.droptable.elements.DropTableElement; +import com.songoda.epicbosses.droptable.elements.SprayTableElement; import com.songoda.epicbosses.managers.BossPanelManager; +import com.songoda.epicbosses.utils.Message; import com.songoda.epicbosses.utils.NumberUtils; import com.songoda.epicbosses.utils.StringUtils; import com.songoda.epicbosses.utils.panel.Panel; +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.Player; +import org.bukkit.event.inventory.ClickType; import java.util.HashMap; import java.util.Map; @@ -23,8 +28,12 @@ import java.util.Map; */ public class DropDropTableMainEditorPanel extends SubVariablePanelHandler { + private CustomBosses plugin; + public DropDropTableMainEditorPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) { super(bossPanelManager, panelBuilder); + + this.plugin = plugin; } @Override @@ -36,17 +45,24 @@ public class DropDropTableMainEditorPanel extends SubVariablePanelHandler replaceMap = new HashMap<>(); + Boolean randomDrops = dropTableElement.getRandomDrops(); + Integer maxDrops = dropTableElement.getDropMaxDrops(); + + if(randomDrops == null) randomDrops = false; + if(maxDrops == null) maxDrops = -1; replaceMap.put("{name}", BossAPI.getDropTableName(dropTable)); - replaceMap.put("{randomDrops}", StringUtils.get().formatString(""+dropTableElement.getRandomDrops())); - replaceMap.put("{maxDrops}", NumberUtils.get().formatDouble(dropTableElement.getDropMaxDrops())); + replaceMap.put("{randomDrops}", StringUtils.get().formatString(""+randomDrops)); + replaceMap.put("{maxDrops}", NumberUtils.get().formatDouble(maxDrops)); panelBuilder.addReplaceData(replaceMap); PanelBuilderCounter panelBuilderCounter = panelBuilder.getPanelBuilderCounter(); Panel panel = panelBuilder.getPanel() - .setParentPanelHandler(this.bossPanelManager.getDropTables()); + .setParentPanelHandler(this.bossPanelManager.getMainDropTableEditMenu(), dropTable); - //handle buttons + panelBuilderCounter.getSlotsWith("Rewards").forEach(slot -> panel.setOnClick(slot, event -> this.bossPanelManager.getDropRewardListEditMenu().openFor((Player) event.getWhoClicked(), dropTable, dropTableElement))); + panelBuilderCounter.getSlotsWith("RandomDrops").forEach(slot -> panel.setOnClick(slot, getRandomDropsAction(dropTable, dropTableElement))); + panelBuilderCounter.getSlotsWith("MaxDrops").forEach(slot -> panel.setOnClick(slot, getMaxDropsAction(dropTable, dropTableElement))); panel.openFor(player); } @@ -55,4 +71,58 @@ public class DropDropTableMainEditorPanel extends SubVariablePanelHandler { + Boolean currentValue = dropTableElement.getRandomDrops(); + + if(currentValue == null) currentValue = false; + + boolean newValue = !currentValue; + + dropTableElement.setRandomDrops(newValue); + saveDropTable(dropTable, (Player) event.getWhoClicked(), dropTableElement, BossAPI.convertObjectToJsonObject(dropTableElement)); + + Message.Boss_DropTable_SetRandomDrops.msg(event.getWhoClicked(), newValue); + }; + } + + private ClickAction getMaxDropsAction(DropTable dropTable, DropTableElement dropTableElement) { + return event -> { + ClickType clickType = event.getClick(); + int amountToModifyBy; + + if(clickType == ClickType.SHIFT_LEFT) { + amountToModifyBy = 10; + } else if(clickType == ClickType.RIGHT) { + amountToModifyBy = -1; + } else if(clickType == ClickType.SHIFT_RIGHT) { + amountToModifyBy = -10; + } else { + amountToModifyBy = 1; + } + + String modifyValue = amountToModifyBy > 0? "increased" : "decreased"; + Integer currentAmount = dropTableElement.getDropMaxDrops(); + + if(currentAmount == null) currentAmount = -1; + + int newAmount = currentAmount + amountToModifyBy; + + if(newAmount < -1) { + newAmount = -1; + } + + dropTableElement.setDropMaxDrops(newAmount); + saveDropTable(dropTable, (Player) event.getWhoClicked(), dropTableElement, BossAPI.convertObjectToJsonObject(dropTableElement)); + + Message.Boss_DropTable_SetMaxDrops.msg(event.getWhoClicked(), modifyValue, NumberUtils.get().formatDouble(newAmount)); + }; + } + + private void saveDropTable(DropTable dropTable, Player player, DropTableElement dropTableElement, JsonObject jsonObject) { + dropTable.setRewards(jsonObject); + this.plugin.getDropTableFileManager().save(); + openFor(player, dropTable, dropTableElement); + } } diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/panel/droptables/types/drop/DropNewRewardEditorPanel.java b/plugin-modules/Core/src/com/songoda/epicbosses/panel/droptables/types/drop/DropNewRewardEditorPanel.java new file mode 100644 index 0000000..72a7232 --- /dev/null +++ b/plugin-modules/Core/src/com/songoda/epicbosses/panel/droptables/types/drop/DropNewRewardEditorPanel.java @@ -0,0 +1,37 @@ +package com.songoda.epicbosses.panel.droptables.types.drop; + +import com.songoda.epicbosses.CustomBosses; +import com.songoda.epicbosses.droptable.DropTable; +import com.songoda.epicbosses.droptable.elements.DropTableElement; +import com.songoda.epicbosses.managers.BossPanelManager; +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.entity.Player; + +/** + * @author Charles Cullen + * @version 1.0.0 + * @since 29-Dec-18 + */ +public class DropNewRewardEditorPanel extends SubVariablePanelHandler { + + public DropNewRewardEditorPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) { + super(bossPanelManager, panelBuilder); + } + + @Override + public void fillPanel(Panel panel, DropTable dropTable, DropTableElement dropTableElement) { + + } + + @Override + public void openFor(Player player, DropTable dropTable, DropTableElement dropTableElement) { + + } + + @Override + public void initializePanel(PanelBuilder panelBuilder) { + + } +} diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/panel/droptables/types/drop/DropRewardMainEditorPanel.java b/plugin-modules/Core/src/com/songoda/epicbosses/panel/droptables/types/drop/DropRewardMainEditorPanel.java new file mode 100644 index 0000000..5383189 --- /dev/null +++ b/plugin-modules/Core/src/com/songoda/epicbosses/panel/droptables/types/drop/DropRewardMainEditorPanel.java @@ -0,0 +1,31 @@ +package com.songoda.epicbosses.panel.droptables.types.drop; + +import com.songoda.epicbosses.CustomBosses; +import com.songoda.epicbosses.droptable.DropTable; +import com.songoda.epicbosses.droptable.elements.DropTableElement; +import com.songoda.epicbosses.managers.BossPanelManager; +import com.songoda.epicbosses.utils.panel.base.handlers.SubSubVariablePanelHandler; +import com.songoda.epicbosses.utils.panel.builder.PanelBuilder; +import org.bukkit.entity.Player; + +/** + * @author Charles Cullen + * @version 1.0.0 + * @since 29-Dec-18 + */ +public class DropRewardMainEditorPanel extends SubSubVariablePanelHandler { + + public DropRewardMainEditorPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) { + super(bossPanelManager, panelBuilder); + } + + @Override + public void openFor(Player player, DropTable dropTable, DropTableElement dropTableElement, String s) { + + } + + @Override + public void initializePanel(PanelBuilder panelBuilder) { + + } +} diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/panel/droptables/types/drop/DropRewardsListEditorPanel.java b/plugin-modules/Core/src/com/songoda/epicbosses/panel/droptables/types/drop/DropRewardsListEditorPanel.java new file mode 100644 index 0000000..b33fe0c --- /dev/null +++ b/plugin-modules/Core/src/com/songoda/epicbosses/panel/droptables/types/drop/DropRewardsListEditorPanel.java @@ -0,0 +1,104 @@ +package com.songoda.epicbosses.panel.droptables.types.drop; + +import com.songoda.epicbosses.CustomBosses; +import com.songoda.epicbosses.api.BossAPI; +import com.songoda.epicbosses.droptable.DropTable; +import com.songoda.epicbosses.droptable.elements.DropTableElement; +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.NumberUtils; +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 com.songoda.epicbosses.utils.panel.builder.PanelBuilderCounter; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +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-Dec-18 + */ +public class DropRewardsListEditorPanel extends SubVariablePanelHandler { + + private ItemsFileManager itemsFileManager; + private CustomBosses plugin; + + public DropRewardsListEditorPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) { + super(bossPanelManager, panelBuilder); + + this.plugin = plugin; + this.itemsFileManager = plugin.getItemStackManager(); + } + + @Override + public void fillPanel(Panel panel, DropTable dropTable, DropTableElement dropTableElement) { + Map rewardMap = dropTableElement.getDropRewards(); + List keyList = new ArrayList<>(rewardMap.keySet()); + int maxPage = panel.getMaxPage(keyList); + + panel.setOnPageChange(((player, currentPage, requestedPage) -> { + if(requestedPage < 0 || requestedPage > maxPage) return false; + + loadPage(panel, requestedPage, dropTable, dropTableElement, rewardMap, keyList); + return true; + })); + + loadPage(panel, 0, dropTable, dropTableElement, rewardMap, keyList); + } + + @Override + public void openFor(Player player, DropTable dropTable, DropTableElement dropTableElement) { + PanelBuilder panelBuilder = getPanelBuilder().cloneBuilder(); + Map replaceMap = new HashMap<>(); + + replaceMap.put("{name}", BossAPI.getDropTableName(dropTable)); + panelBuilder.addReplaceData(replaceMap); + + PanelBuilderCounter panelBuilderCounter = panelBuilder.getPanelBuilderCounter(); + Panel panel = panelBuilder.getPanel() + .setParentPanelHandler(this.bossPanelManager.getDropDropTableMainEditMenu(), dropTable, dropTableElement); + + panelBuilderCounter.getSlotsWith("NewReward").forEach(slot -> panel.setOnClick(slot, event -> this.bossPanelManager.getDropNewRewardEditMenu().openFor((Player) event.getWhoClicked(), dropTable, dropTableElement))); + fillPanel(panel, dropTable, dropTableElement); + + panel.openFor(player); + } + + @Override + public void initializePanel(PanelBuilder panelBuilder) { + + } + + private void loadPage(Panel panel, int page, DropTable dropTable, DropTableElement dropTableElement, Map rewardMap, List keyList) { + panel.loadPage(page, (slot, realisticSlot) -> { + if(slot >= keyList.size()) { + panel.setItem(realisticSlot, new ItemStack(Material.AIR), e -> {}); + } else { + String name = keyList.get(slot); + Double chance = rewardMap.get(name); + Map replaceMap = new HashMap<>(); + + if(chance == null) chance = 100.0; + + replaceMap.put("{itemName}", name); + replaceMap.put("{chance}", NumberUtils.get().formatDouble(chance)); + + ItemStack itemStack = this.itemsFileManager.getItemStackConverter().from(this.itemsFileManager.getItemStackHolder(name)); + + ItemStackUtils.applyDisplayName(itemStack, this.plugin.getConfig().getString("Display.DropTable.RewardList.name"), replaceMap); + ItemStackUtils.applyDisplayLore(itemStack, this.plugin.getConfig().getStringList("Display.DropTable.RewardList.lore"), replaceMap); + + panel.setItem(realisticSlot, itemStack, event -> this.bossPanelManager.getDropRewardMainEditMenu().openFor((Player) event.getWhoClicked(), dropTable, dropTableElement, name)); + } + }); + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 6f3bd6c..4faf43c 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ - 1.0.0-U147 + 1.0.0-U148 EpicBosses com.songoda.epicbosses.CustomBosses AMinecraftDev