1.0.0-SNAPSHOT-U148

+ Started the implementation of the DropReward Editor Panels
This commit is contained in:
Charles 2018-12-29 22:09:41 +08:00
parent e154cd25cf
commit c9e055f4b9
7 changed files with 332 additions and 8 deletions

View File

@ -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'

View File

@ -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<DropTable, SprayTableElement> sprayDropTableMainEditMenu, sprayRewardListEditMenu, sprayNewRewardEditMenu;
@Getter private ISubSubVariablePanelHandler<DropTable, SprayTableElement, String> sprayRewardMainEditMenu;
@Getter private ISubVariablePanelHandler<DropTable, GiveTableElement> giveDropTableMainEditMenu;
@Getter private ISubVariablePanelHandler<DropTable, DropTableElement> dropDropTableMainEditMenu;
@Getter private ISubVariablePanelHandler<DropTable, DropTableElement> dropDropTableMainEditMenu, dropRewardListEditMenu, dropNewRewardEditMenu;
@Getter private ISubSubVariablePanelHandler<DropTable, DropTableElement, String> 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);
}
//---------------------------------------------

View File

@ -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<DropTable, DropTableElement> {
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<DropTa
public void openFor(Player player, DropTable dropTable, DropTableElement dropTableElement) {
PanelBuilder panelBuilder = getPanelBuilder().cloneBuilder();
Map<String, String> 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<DropTa
public void initializePanel(PanelBuilder panelBuilder) {
}
private ClickAction getRandomDropsAction(DropTable dropTable, DropTableElement dropTableElement) {
return event -> {
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);
}
}

View File

@ -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<DropTable, DropTableElement> {
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) {
}
}

View File

@ -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<DropTable, DropTableElement, String> {
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) {
}
}

View File

@ -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<DropTable, DropTableElement> {
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<String, Double> rewardMap = dropTableElement.getDropRewards();
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, 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<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.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<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("{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));
}
});
}
}

View File

@ -20,7 +20,7 @@
<properties>
<!--<plugin.version>maven-version-number-SNAPSHOT-U90</plugin.version>-->
<plugin.version>1.0.0-U147</plugin.version>
<plugin.version>1.0.0-U148</plugin.version>
<plugin.name>EpicBosses</plugin.name>
<plugin.main>com.songoda.epicbosses.CustomBosses</plugin.main>
<plugin.author>AMinecraftDev</plugin.author>