mirror of
https://github.com/songoda/EpicBosses.git
synced 2025-01-11 01:37:40 +01:00
1.0.0-SNAPSHOT-U165
+ Completed GiveCommandNewRewardPanel + Completed GIveCommandRewardListPanel + Completed GiveCommandRewardMainEditPanel + Updated the TODO + Connected all new panels
This commit is contained in:
parent
5d26a6371a
commit
ec073be198
5
TODO
5
TODO
@ -1,6 +1,3 @@
|
||||
00:30 -> Panel with Items button, Commands button, maxDrops button, maxCommands button, randomDrops button, randomCommands button, requiredPercentage button
|
||||
01:00 -> Items panel is Rewards List (with chances)
|
||||
00:30 -> Commands panel is Rewards List (with chances)
|
||||
02:00 -> Add full AutoSpawns system
|
||||
02:00 -> Interval based spawn system, so bosses will spawn at location after certain time
|
||||
|
||||
@ -16,4 +13,4 @@
|
||||
01:00 -> Add a new branch for the plugin and add support for Legacy version
|
||||
|
||||
-----------
|
||||
17:45 hrs
|
||||
15:45 hrs
|
@ -114,6 +114,13 @@ Display:
|
||||
- '&3Chance: &f{chance}%'
|
||||
- '&7'
|
||||
- '&7Click to modify this reward.'
|
||||
CommandRewardList:
|
||||
name: '&bReward Section'
|
||||
lore:
|
||||
- '&3Selected Command: &f{commandName}'
|
||||
- '&3Chance: &f{chance}%'
|
||||
- '&7'
|
||||
- '&7Click to modify this reward.'
|
||||
GivePositionList:
|
||||
name: '&bReward Section'
|
||||
lore:
|
||||
|
@ -34,6 +34,9 @@ import com.songoda.epicbosses.panel.droptables.types.drop.DropDropTableMainEdito
|
||||
import com.songoda.epicbosses.panel.droptables.types.give.GiveRewardMainEditPanel;
|
||||
import com.songoda.epicbosses.panel.droptables.types.give.GiveRewardPositionListPanel;
|
||||
import com.songoda.epicbosses.panel.droptables.types.give.GiveRewardRewardsListPanel;
|
||||
import com.songoda.epicbosses.panel.droptables.types.give.commands.GiveCommandNewRewardPanel;
|
||||
import com.songoda.epicbosses.panel.droptables.types.give.commands.GiveCommandRewardListPanel;
|
||||
import com.songoda.epicbosses.panel.droptables.types.give.commands.GiveCommandRewardMainEditPanel;
|
||||
import com.songoda.epicbosses.panel.droptables.types.give.drops.GiveDropNewRewardPanel;
|
||||
import com.songoda.epicbosses.panel.droptables.types.give.drops.GiveDropRewardListPanel;
|
||||
import com.songoda.epicbosses.panel.droptables.types.give.drops.GiveDropRewardMainEditPanel;
|
||||
@ -111,9 +114,10 @@ public class BossPanelManager implements ILoadable, IReloadable {
|
||||
@Getter private DropTableNewRewardEditorPanel<SprayTableElement> sprayDropNewRewardEditPanel;
|
||||
@Getter private DropTableRewardsListEditorPanel<SprayTableElement> sprayDropRewardListPanel;
|
||||
|
||||
@Getter private ISubVariablePanelHandler<DropTable, GiveRewardEditHandler> giveRewardMainEditMenu, giveCommandRewardListPanel, giveCommandNewRewardPanel;
|
||||
@Getter private ISubSubVariablePanelHandler<DropTable, GiveRewardEditHandler, String> giveCommandRewardMainEditMenu;
|
||||
@Getter private ISubSubVariablePanelHandler<DropTable, GiveTableElement, String> giveRewardRewardsListMenu;
|
||||
@Getter private ISubVariablePanelHandler<DropTable, GiveTableElement> giveRewardPositionListMenu;
|
||||
@Getter private ISubVariablePanelHandler<DropTable, GiveRewardEditHandler> giveRewardMainEditMenu;
|
||||
@Getter private DropTableRewardMainEditorPanel<GiveRewardEditHandler> giveDropRewardMainEditPanel;
|
||||
@Getter private DropTableNewRewardEditorPanel<GiveRewardEditHandler> giveDropNewRewardEditPanel;
|
||||
@Getter private DropTableRewardsListEditorPanel<GiveRewardEditHandler> giveDropRewardListPanel;
|
||||
@ -264,9 +268,13 @@ public class BossPanelManager implements ILoadable, IReloadable {
|
||||
this.giveRewardPositionListMenu = new GiveRewardPositionListPanel(this, panelBuilder10, this.customBosses);
|
||||
this.giveRewardRewardsListMenu = new GiveRewardRewardsListPanel(this, panelBuilder11, this.customBosses);
|
||||
this.giveRewardMainEditMenu = new GiveRewardMainEditPanel(this, panelBuilder12, this.customBosses);
|
||||
|
||||
this.giveDropNewRewardEditPanel = new GiveDropNewRewardPanel(this, panelBuilder4, this.customBosses);
|
||||
this.giveDropRewardListPanel = new GiveDropRewardListPanel(this, panelBuilder5, this.customBosses);
|
||||
this.giveDropRewardMainEditPanel = new GiveDropRewardMainEditPanel(this, panelBuilder3, this.customBosses);
|
||||
this.giveCommandNewRewardPanel = new GiveCommandNewRewardPanel(this, panelBuilder4, this.customBosses);
|
||||
this.giveCommandRewardListPanel = new GiveCommandRewardListPanel(this, panelBuilder5, this.customBosses);
|
||||
this.giveCommandRewardMainEditMenu = new GiveCommandRewardMainEditPanel(this, panelBuilder3, this.customBosses);
|
||||
}
|
||||
|
||||
private void reloadDropTableEditMenus() {
|
||||
@ -304,6 +312,9 @@ public class BossPanelManager implements ILoadable, IReloadable {
|
||||
this.giveDropNewRewardEditPanel.initializePanel(panelBuilder4);
|
||||
this.giveDropRewardListPanel.initializePanel(panelBuilder5);
|
||||
this.giveDropRewardMainEditPanel.initializePanel(panelBuilder3);
|
||||
this.giveCommandNewRewardPanel.initializePanel(panelBuilder4);
|
||||
this.giveCommandRewardListPanel.initializePanel(panelBuilder5);
|
||||
this.giveCommandRewardMainEditMenu.initializePanel(panelBuilder3);
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
|
@ -19,7 +19,6 @@ import com.songoda.epicbosses.utils.panel.builder.PanelBuilderCounter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -71,7 +70,7 @@ public class GiveRewardMainEditPanel extends SubVariablePanelHandler<DropTable,
|
||||
counter.getSlotsWith("MaxDrops").forEach(slot -> panel.setOnClick(slot, getMaxDropsAction(dropTable, giveRewardEditHandler)));
|
||||
counter.getSlotsWith("ItemDrops").forEach(slot -> panel.setOnClick(slot, event -> this.bossPanelManager.getGiveDropRewardListPanel().openFor((Player) event.getWhoClicked(), dropTable, giveRewardEditHandler)));
|
||||
counter.getSlotsWith("RequiredPercentage").forEach(slot -> panel.setOnClick(slot, getRequiredPercentageAction(dropTable, giveRewardEditHandler)));
|
||||
counter.getSlotsWith("CommandDrops").forEach(slot -> {});
|
||||
counter.getSlotsWith("CommandDrops").forEach(slot -> panel.setOnClick(slot, event -> this.bossPanelManager.getGiveCommandRewardListPanel().openFor((Player) event.getWhoClicked(), dropTable, giveRewardEditHandler)));
|
||||
counter.getSlotsWith("MaxCommands").forEach(slot -> panel.setOnClick(slot, getMaxCommandsAction(dropTable, giveRewardEditHandler)));
|
||||
counter.getSlotsWith("RandomDrops").forEach(slot -> panel.setOnClick(slot, getRandomCommandsAction(dropTable, giveRewardEditHandler)));
|
||||
|
||||
|
@ -3,10 +3,16 @@ package com.songoda.epicbosses.panel.droptables.types.give.commands;
|
||||
import com.songoda.epicbosses.CustomBosses;
|
||||
import com.songoda.epicbosses.api.BossAPI;
|
||||
import com.songoda.epicbosses.droptable.DropTable;
|
||||
import com.songoda.epicbosses.droptable.elements.GiveTableElement;
|
||||
import com.songoda.epicbosses.droptable.elements.GiveTableSubElement;
|
||||
import com.songoda.epicbosses.managers.BossPanelManager;
|
||||
import com.songoda.epicbosses.managers.files.CommandsFileManager;
|
||||
import com.songoda.epicbosses.managers.files.DropTableFileManager;
|
||||
import com.songoda.epicbosses.panel.droptables.types.give.handlers.GiveRewardEditHandler;
|
||||
import com.songoda.epicbosses.utils.Message;
|
||||
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.SubVariablePanelHandler;
|
||||
@ -14,8 +20,10 @@ 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;
|
||||
|
||||
@ -26,13 +34,17 @@ import java.util.Map;
|
||||
*/
|
||||
public class GiveCommandNewRewardPanel extends SubVariablePanelHandler<DropTable, GiveRewardEditHandler> {
|
||||
|
||||
private DropTableFileManager dropTableFileManager;
|
||||
private CommandsFileManager commandsFileManager;
|
||||
private ItemStackConverter itemStackConverter;
|
||||
private CustomBosses plugin;
|
||||
|
||||
public GiveCommandNewRewardPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) {
|
||||
super(bossPanelManager, panelBuilder);
|
||||
|
||||
this.commandsFileManager = plugin.getBossCommandFileManager();
|
||||
this.dropTableFileManager = plugin.getDropTableFileManager();
|
||||
this.itemStackConverter = new ItemStackConverter();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@ -55,8 +67,8 @@ public class GiveCommandNewRewardPanel extends SubVariablePanelHandler<DropTable
|
||||
|
||||
@Override
|
||||
public void openFor(Player player, DropTable dropTable, GiveRewardEditHandler giveRewardEditHandler) {
|
||||
Panel panel = getPanelBuilder().getPanel();
|
||||
// .setParentPanelHandler(this.bossPanelManager.getGiveCommandRewardListPanel(), dropTable, giveRewardEditHandler);
|
||||
Panel panel = getPanelBuilder().getPanel()
|
||||
.setParentPanelHandler(this.bossPanelManager.getGiveCommandRewardListPanel(), dropTable, giveRewardEditHandler);
|
||||
|
||||
fillPanel(panel, dropTable, giveRewardEditHandler);
|
||||
panel.openFor(player);
|
||||
@ -67,29 +79,54 @@ public class GiveCommandNewRewardPanel extends SubVariablePanelHandler<DropTable
|
||||
|
||||
}
|
||||
|
||||
private void loadPage(Panel panel, int page, DropTable dropTable, GiveRewardEditHandler subVariable, List<String> filteredKeys, Map<String, List<String>> commands) {
|
||||
private void loadPage(Panel panel, int page, DropTable dropTable, GiveRewardEditHandler giveRewardEditHandler, List<String> filteredKeys, Map<String, List<String>> commands) {
|
||||
panel.loadPage(page, (slot, realisticSlot) -> {
|
||||
if(slot >= filteredKeys.size()) {
|
||||
panel.setItem(realisticSlot, new ItemStack(Material.AIR), e->{});
|
||||
} else {
|
||||
String name = filteredKeys.get(slot);
|
||||
// ItemStackHolder itemStackHolder = itemStacks.get(name);
|
||||
// ItemStack itemStack = this.itemsFileManager.getItemStackConverter().from(itemStackHolder);
|
||||
List<String> innerCommands = commands.get(name);
|
||||
ItemStackHolder itemStackHolder = BossAPI.getStoredItemStack("DefaultTextMenuItem");
|
||||
ItemStack itemStack = this.itemStackConverter.from(itemStackHolder);
|
||||
|
||||
// panel.setItem(realisticSlot, itemStack, event -> {
|
||||
// Map<String, Double> currentRewards = getRewards(subVariable);
|
||||
//
|
||||
// currentRewards.put(name, 50.0);
|
||||
// saveDropTable(this.plugin.getDropTableFileManager(), dropTable, subVariable);
|
||||
//
|
||||
// getRewardMainEditMenu().openFor((Player) event.getWhoClicked(), dropTable, subVariable, name);
|
||||
// Message.Boss_DropTable_AddedNewReward.msg(event.getWhoClicked(), BossAPI.getDropTableName(dropTable));
|
||||
// });
|
||||
Map<String, String> replaceMap = new HashMap<>();
|
||||
|
||||
replaceMap.put("{name}", name);
|
||||
|
||||
ItemStackUtils.applyDisplayName(itemStack, this.plugin.getConfig().getString("Display.Boss.Commands.name"), replaceMap);
|
||||
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
List<String> presetLore = this.plugin.getConfig().getStringList("Display.Boss.Commands.lore");
|
||||
List<String> newLore = new ArrayList<>();
|
||||
|
||||
for(String s : presetLore) {
|
||||
if(s.contains("{commands}")) {
|
||||
for(String command : innerCommands) {
|
||||
newLore.add(StringUtils.get().translateColor("&7" + command));
|
||||
}
|
||||
} else {
|
||||
newLore.add(StringUtils.get().translateColor(s));
|
||||
}
|
||||
}
|
||||
|
||||
itemMeta.setLore(newLore);
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
|
||||
panel.setItem(realisticSlot, itemStack, event -> {
|
||||
Map<String, Double> rewards = giveRewardEditHandler.getGiveTableSubElement().getCommands();
|
||||
|
||||
rewards.put(name, 50.0);
|
||||
saveDropTable(this.dropTableFileManager, dropTable, giveRewardEditHandler);
|
||||
|
||||
this.bossPanelManager.getGiveCommandRewardMainEditMenu().openFor((Player) event.getWhoClicked(), dropTable, giveRewardEditHandler, name);
|
||||
Message.Boss_DropTable_AddedNewReward.msg(event.getWhoClicked(), BossAPI.getDropTableName(dropTable));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
private List<String> getCurrentKeys(GiveRewardEditHandler giveRewardEditHandler) {
|
||||
return new ArrayList<>(giveRewardEditHandler.getGiveTableSubElement().getCommands().keySet());
|
||||
}
|
||||
@ -105,4 +142,17 @@ public class GiveCommandNewRewardPanel extends SubVariablePanelHandler<DropTable
|
||||
|
||||
return filteredList;
|
||||
}
|
||||
|
||||
private void saveDropTable(DropTableFileManager dropTableFileManager, DropTable dropTable, GiveRewardEditHandler giveRewardEditHandler) {
|
||||
GiveTableSubElement giveTableSubElement = giveRewardEditHandler.getGiveTableSubElement();
|
||||
GiveTableElement giveTableElement = giveRewardEditHandler.getGiveTableElement();
|
||||
Map<String, Map<String, GiveTableSubElement>> positionMap = giveTableElement.getGiveRewards();
|
||||
Map<String, GiveTableSubElement> rewardMap = positionMap.get(giveRewardEditHandler.getDamagePosition());
|
||||
|
||||
rewardMap.put(giveRewardEditHandler.getDropSection(), giveTableSubElement);
|
||||
positionMap.put(giveRewardEditHandler.getDamagePosition(), rewardMap);
|
||||
giveTableElement.setGiveRewards(positionMap);
|
||||
dropTable.setRewards(BossAPI.convertObjectToJsonObject(giveTableElement));
|
||||
dropTableFileManager.save();
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,109 @@
|
||||
package com.songoda.epicbosses.panel.droptables.types.give.commands;
|
||||
|
||||
import com.songoda.epicbosses.CustomBosses;
|
||||
import com.songoda.epicbosses.api.BossAPI;
|
||||
import com.songoda.epicbosses.droptable.DropTable;
|
||||
import com.songoda.epicbosses.managers.BossPanelManager;
|
||||
import com.songoda.epicbosses.managers.files.ItemsFileManager;
|
||||
import com.songoda.epicbosses.panel.droptables.types.give.handlers.GiveRewardEditHandler;
|
||||
import com.songoda.epicbosses.utils.NumberUtils;
|
||||
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.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 02-Jan-19
|
||||
*/
|
||||
public class GiveCommandRewardListPanel {
|
||||
public class GiveCommandRewardListPanel extends SubVariablePanelHandler<DropTable, GiveRewardEditHandler> {
|
||||
|
||||
private ItemsFileManager itemsFileManager;
|
||||
private CustomBosses plugin;
|
||||
|
||||
public GiveCommandRewardListPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) {
|
||||
super(bossPanelManager, panelBuilder);
|
||||
|
||||
this.plugin = plugin;
|
||||
this.itemsFileManager = plugin.getItemStackManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillPanel(Panel panel, DropTable dropTable, GiveRewardEditHandler giveRewardEditHandler) {
|
||||
Map<String, Double> rewardMap = getRewards(giveRewardEditHandler);
|
||||
List<String> 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, giveRewardEditHandler, rewardMap, keyList);
|
||||
return true;
|
||||
});
|
||||
|
||||
loadPage(panel, 0, dropTable, giveRewardEditHandler, rewardMap, keyList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openFor(Player player, DropTable dropTable, GiveRewardEditHandler giveRewardEditHandler) {
|
||||
PanelBuilder panelBuilder = getPanelBuilder().cloneBuilder();
|
||||
Map<String, String> replaceMap = new HashMap<>();
|
||||
|
||||
replaceMap.put("{name}", BossAPI.getDropTableName(dropTable));
|
||||
panelBuilder.addReplaceData(replaceMap);
|
||||
|
||||
PanelBuilderCounter panelBuilderCounter = panelBuilder.getPanelBuilderCounter();
|
||||
Panel panel = panelBuilder.getPanel()
|
||||
.setParentPanelHandler(this.bossPanelManager.getGiveRewardMainEditMenu(), dropTable, giveRewardEditHandler);
|
||||
|
||||
panelBuilderCounter.getSlotsWith("NewReward").forEach(slot -> panel.setOnClick(slot, event -> this.bossPanelManager.getGiveCommandNewRewardPanel().openFor((Player) event.getWhoClicked(), dropTable, giveRewardEditHandler)));
|
||||
fillPanel(panel, dropTable, giveRewardEditHandler);
|
||||
|
||||
panel.openFor(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializePanel(PanelBuilder panelBuilder) {
|
||||
|
||||
}
|
||||
|
||||
private void loadPage(Panel panel, int page, DropTable dropTable, GiveRewardEditHandler giveRewardEditHandler, Map<String, Double> rewardMap, List<String> 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<String, String> replaceMap = new HashMap<>();
|
||||
|
||||
if(chance == null) chance = 100.0;
|
||||
|
||||
replaceMap.put("{commandName}", name);
|
||||
replaceMap.put("{chance}", NumberUtils.get().formatDouble(chance));
|
||||
|
||||
ItemStackHolder itemStackHolder = BossAPI.getStoredItemStack("DefaultTextMenuItem");
|
||||
ItemStack itemStack = this.itemsFileManager.getItemStackConverter().from(itemStackHolder);
|
||||
|
||||
ItemStackUtils.applyDisplayName(itemStack, this.plugin.getConfig().getString("Display.DropTable.CommandRewardList.name"), replaceMap);
|
||||
ItemStackUtils.applyDisplayLore(itemStack, this.plugin.getConfig().getStringList("Display.DropTable.CommandRewardList.lore"), replaceMap);
|
||||
|
||||
panel.setItem(realisticSlot, itemStack, event -> this.bossPanelManager.getGiveCommandRewardMainEditMenu().openFor((Player) event.getWhoClicked(), dropTable, giveRewardEditHandler, name));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Map<String, Double> getRewards(GiveRewardEditHandler giveRewardEditHandler) {
|
||||
return giveRewardEditHandler.getGiveTableSubElement().getCommands();
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,128 @@
|
||||
package com.songoda.epicbosses.panel.droptables.types.give.commands;
|
||||
|
||||
import com.songoda.epicbosses.CustomBosses;
|
||||
import com.songoda.epicbosses.api.BossAPI;
|
||||
import com.songoda.epicbosses.droptable.DropTable;
|
||||
import com.songoda.epicbosses.droptable.elements.GiveTableElement;
|
||||
import com.songoda.epicbosses.droptable.elements.GiveTableSubElement;
|
||||
import com.songoda.epicbosses.managers.BossPanelManager;
|
||||
import com.songoda.epicbosses.managers.files.DropTableFileManager;
|
||||
import com.songoda.epicbosses.panel.droptables.types.give.handlers.GiveRewardEditHandler;
|
||||
import com.songoda.epicbosses.utils.Message;
|
||||
import com.songoda.epicbosses.utils.NumberUtils;
|
||||
import com.songoda.epicbosses.utils.ObjectUtils;
|
||||
import com.songoda.epicbosses.utils.panel.Panel;
|
||||
import com.songoda.epicbosses.utils.panel.base.ClickAction;
|
||||
import com.songoda.epicbosses.utils.panel.base.handlers.SubSubVariablePanelHandler;
|
||||
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 02-Jan-19
|
||||
*/
|
||||
public class GiveCommandRewardMainEditPanel {
|
||||
public class GiveCommandRewardMainEditPanel extends SubSubVariablePanelHandler<DropTable, GiveRewardEditHandler, String> {
|
||||
|
||||
private DropTableFileManager dropTableFileManager;
|
||||
|
||||
public GiveCommandRewardMainEditPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) {
|
||||
super(bossPanelManager, panelBuilder);
|
||||
|
||||
this.dropTableFileManager = plugin.getDropTableFileManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openFor(Player player, DropTable dropTable, GiveRewardEditHandler giveRewardEditHandler, String s) {
|
||||
PanelBuilder panelBuilder = getPanelBuilder().cloneBuilder();
|
||||
Map<String, Double> rewardMap = giveRewardEditHandler.getGiveTableSubElement().getCommands();
|
||||
Map<String, String> replaceMap = new HashMap<>();
|
||||
double chance = ObjectUtils.getValue(rewardMap.get(s), 50.0);
|
||||
|
||||
replaceMap.put("{chance}", NumberUtils.get().formatDouble(chance));
|
||||
replaceMap.put("{itemStack}", s);
|
||||
panelBuilder.addReplaceData(replaceMap);
|
||||
|
||||
PanelBuilderCounter panelBuilderCounter = panelBuilder.getPanelBuilderCounter();
|
||||
Panel panel = panelBuilder.getPanel()
|
||||
.setParentPanelHandler(this.bossPanelManager.getGiveCommandRewardListPanel(), dropTable, giveRewardEditHandler);
|
||||
|
||||
panelBuilderCounter.getSlotsWith("Chance").forEach(slot -> panel.setOnClick(slot, getChanceAction(dropTable, giveRewardEditHandler, s)));
|
||||
panelBuilderCounter.getSlotsWith("Remove").forEach(slot -> panel.setOnClick(slot, getRemoveAction(dropTable, giveRewardEditHandler, s)));
|
||||
|
||||
panel.openFor(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializePanel(PanelBuilder panelBuilder) {
|
||||
|
||||
}
|
||||
|
||||
private ClickAction getChanceAction(DropTable dropTable, GiveRewardEditHandler giveRewardEditHandler, String name) {
|
||||
return event -> {
|
||||
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<String, Double> rewards = giveRewardEditHandler.getGiveTableSubElement().getCommands();
|
||||
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);
|
||||
giveRewardEditHandler.getGiveTableSubElement().setItems(rewards);
|
||||
saveDropTable(this.dropTableFileManager, dropTable, giveRewardEditHandler);
|
||||
openFor((Player) event.getWhoClicked(), dropTable, giveRewardEditHandler, name);
|
||||
|
||||
Message.Boss_DropTable_RewardChance.msg(event.getWhoClicked(), modifyValue, BossAPI.getDropTableName(dropTable), NumberUtils.get().formatDouble(newValue));
|
||||
};
|
||||
}
|
||||
|
||||
private ClickAction getRemoveAction(DropTable dropTable, GiveRewardEditHandler giveRewardEditHandler, String name) {
|
||||
return event -> {
|
||||
Map<String, Double> rewards = giveRewardEditHandler.getGiveTableSubElement().getItems();
|
||||
|
||||
rewards.remove(name);
|
||||
giveRewardEditHandler.getGiveTableSubElement().setItems(rewards);
|
||||
saveDropTable(this.dropTableFileManager, dropTable, giveRewardEditHandler);
|
||||
|
||||
Message.Boss_DropTable_RewardRemoved.msg(event.getWhoClicked());
|
||||
this.bossPanelManager.getGiveCommandRewardListPanel().openFor((Player) event.getWhoClicked(), dropTable, giveRewardEditHandler);
|
||||
};
|
||||
}
|
||||
|
||||
private void saveDropTable(DropTableFileManager dropTableFileManager, DropTable dropTable, GiveRewardEditHandler giveRewardEditHandler) {
|
||||
GiveTableSubElement giveTableSubElement = giveRewardEditHandler.getGiveTableSubElement();
|
||||
GiveTableElement giveTableElement = giveRewardEditHandler.getGiveTableElement();
|
||||
Map<String, Map<String, GiveTableSubElement>> positionMap = giveTableElement.getGiveRewards();
|
||||
Map<String, GiveTableSubElement> rewardMap = positionMap.get(giveRewardEditHandler.getDamagePosition());
|
||||
|
||||
rewardMap.put(giveRewardEditHandler.getDropSection(), giveTableSubElement);
|
||||
positionMap.put(giveRewardEditHandler.getDamagePosition(), rewardMap);
|
||||
giveTableElement.setGiveRewards(positionMap);
|
||||
dropTable.setRewards(BossAPI.convertObjectToJsonObject(giveTableElement));
|
||||
dropTableFileManager.save();
|
||||
}
|
||||
}
|
||||
|
2
pom.xml
2
pom.xml
@ -20,7 +20,7 @@
|
||||
|
||||
<properties>
|
||||
<!--<plugin.version>maven-version-number-SNAPSHOT-U90</plugin.version>-->
|
||||
<plugin.version>1.0.0-U164</plugin.version>
|
||||
<plugin.version>1.0.0-U165</plugin.version>
|
||||
<plugin.name>EpicBosses</plugin.name>
|
||||
<plugin.main>com.songoda.epicbosses.CustomBosses</plugin.main>
|
||||
<plugin.author>AMinecraftDev</plugin.author>
|
||||
|
Loading…
Reference in New Issue
Block a user