From e154cd25cf58a3ba385d54b4691f7b096f3079fb Mon Sep 17 00:00:00 2001 From: Charles Date: Sat, 29 Dec 2018 04:23:50 +0800 Subject: [PATCH] 1.0.0-SNAPSHOT-U147 + Completed the SprayEditorPanel's --- TODO | 1 - plugin-modules/Core/resources-yml/editor.yml | 1 - .../spray/SprayRewardMainEditorPanel.java | 50 +++++++++++++++++-- .../com/songoda/epicbosses/utils/Message.java | 1 + pom.xml | 2 +- 5 files changed, 48 insertions(+), 7 deletions(-) diff --git a/TODO b/TODO index 222a2d6..1386bee 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,3 @@ -01:00 -> Spray - Has a button for Rewards List (with chances), button for RandomSpray, button for MaxDistance, button for MaxDrops (1hr) 01:00 -> Drop - Has a button for Rewards List (with chances), button for RandomDrops, button for MaxDrops (1hr) 01:00 -> Give - Is a list panel with the positions and a button for adding a new position (1hr) 00:30 -> Is a list panel of reward sections, button to add a new section diff --git a/plugin-modules/Core/resources-yml/editor.yml b/plugin-modules/Core/resources-yml/editor.yml index a8afd34..b42c544 100644 --- a/plugin-modules/Core/resources-yml/editor.yml +++ b/plugin-modules/Core/resources-yml/editor.yml @@ -2212,7 +2212,6 @@ SprayRewardMainEditMenu: - '&bCurrently: &f{itemStack}' - '&7This is the selected itemStack for this' - '&7reward section.' - Button: Selected '4': type: EMERALD name: '&e&lChance' diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/panel/droptables/types/spray/SprayRewardMainEditorPanel.java b/plugin-modules/Core/src/com/songoda/epicbosses/panel/droptables/types/spray/SprayRewardMainEditorPanel.java index a54f26a..a3c2f97 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/panel/droptables/types/spray/SprayRewardMainEditorPanel.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/panel/droptables/types/spray/SprayRewardMainEditorPanel.java @@ -6,6 +6,7 @@ import com.songoda.epicbosses.droptable.DropTable; import com.songoda.epicbosses.droptable.elements.SprayTableElement; import com.songoda.epicbosses.managers.BossPanelManager; import com.songoda.epicbosses.managers.files.DropTableFileManager; +import com.songoda.epicbosses.skills.Skill; import com.songoda.epicbosses.utils.Message; import com.songoda.epicbosses.utils.NumberUtils; import com.songoda.epicbosses.utils.panel.Panel; @@ -14,6 +15,7 @@ import com.songoda.epicbosses.utils.panel.base.handlers.SubSubVariablePanelHandl 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; @@ -49,8 +51,7 @@ public class SprayRewardMainEditorPanel extends SubSubVariablePanelHandler {}); - panelBuilderCounter.getSlotsWith("Chance").forEach(slot -> {}); + panelBuilderCounter.getSlotsWith("Chance").forEach(slot -> panel.setOnClick(slot, getChanceAction(dropTable, sprayTableElement, string))); panelBuilderCounter.getSlotsWith("Remove").forEach(slot -> panel.setOnClick(slot, getRemoveAction(dropTable, sprayTableElement, string))); panel.openFor(player); @@ -61,17 +62,58 @@ public class SprayRewardMainEditorPanel extends SubSubVariablePanelHandler { + ClickType clickType = event.getClick(); + double amountToModifyBy; + + if(clickType == ClickType.SHIFT_LEFT) { + amountToModifyBy = 0.1; + } else if(clickType == ClickType.RIGHT) { + amountToModifyBy = -1.0; + } else if(clickType == ClickType.SHIFT_RIGHT) { + amountToModifyBy = -0.1; + } else { + amountToModifyBy = 1.0; + } + + String modifyValue = amountToModifyBy > 0? "increased" : "decreased"; + Map rewards = sprayTableElement.getSprayRewards(); + double currentValue = rewards.getOrDefault(name, 50.0); + double newValue = currentValue + amountToModifyBy; + + if(newValue < 0) { + newValue = 0; + } + + if(newValue > 100) { + newValue = 100; + } + + rewards.put(name, newValue); + sprayTableElement.setSprayRewards(rewards); + save(dropTable, sprayTableElement); + openFor((Player) event.getWhoClicked(), dropTable, sprayTableElement, name); + + Message.Boss_DropTable_SprayRewardChance.msg(event.getWhoClicked(), modifyValue, BossAPI.getDropTableName(dropTable), NumberUtils.get().formatDouble(newValue)); + }; + } + private ClickAction getRemoveAction(DropTable dropTable, SprayTableElement sprayTableElement, String name) { return event -> { Map current = sprayTableElement.getSprayRewards(); current.remove(name); sprayTableElement.setSprayRewards(current); - dropTable.setRewards(BossAPI.convertObjectToJsonObject(sprayTableElement)); - this.dropTableFileManager.save(); + save(dropTable, sprayTableElement); Message.Boss_DropTable_SprayRewardRemoved.msg(event.getWhoClicked()); this.bossPanelManager.getSprayRewardListEditMenu().openFor((Player) event.getWhoClicked(), dropTable, sprayTableElement); }; } + + private void save(DropTable dropTable, SprayTableElement sprayTableElement) { + dropTable.setRewards(BossAPI.convertObjectToJsonObject(sprayTableElement)); + this.dropTableFileManager.save(); + } } 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 cf94965..ce6852d 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/utils/Message.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/utils/Message.java @@ -40,6 +40,7 @@ public enum Message { Boss_DropTable_SetRandomDrops("&b&lEpicBosses &8» &7You have set the random drops mode for the drop table to &f{0}&7."), Boss_DropTable_SprayAddedNewReward("&b&lEpicBosses &8» &7You have added a new reward to the drop table &f{0}&7. Now opening the editing panel for the new reward."), Boss_DropTable_SprayRewardRemoved("&b&lEpicBosses &8» &7You have removed the reward section from the spray drop table."), + Boss_DropTable_SprayRewardChance("&b&lEpicBosses &8» &7You have {0} the chance for the reward section for &f{1}&7 to &f{2}%&7."), Boss_Edit_NoPermission("&c&l(!) &cYou do not have access to this command."), Boss_Edit_ItemStackHolderNull("&c&l(!) &cThe itemstack name that is provided for the spawn item doesn't exist or wasn't found."), diff --git a/pom.xml b/pom.xml index 78ee8e5..6f3bd6c 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ - 1.0.0-U146 + 1.0.0-U147 EpicBosses com.songoda.epicbosses.CustomBosses AMinecraftDev