1.0.0-SNAPSHOT-U145

+ Fully implemented the new Reward section for the Spray DropTable.
This commit is contained in:
Charles 2018-12-29 01:36:21 +08:00
parent ca3f6c83af
commit 28d036cf97
5 changed files with 72 additions and 4 deletions

View File

@ -2142,7 +2142,7 @@ SprayNewRewardEditMenu:
type: BOOK
name: '&c&lNew Spray Reward Guide'
lore:
- '&7Once u click an item within this'
- '&7Once you click an item within this'
- '&7menu it will create a new reward'
- '&7section with that selected item'
- '&7to the drop table you were working'

View File

@ -216,7 +216,7 @@ public class BossPanelManager implements ILoadable, IReloadable {
PanelBuilder panelBuilder2 = new PanelBuilder(editor.getConfigurationSection("SprayDropTableMainEditMenu"));
PanelBuilder panelBuilder3 = new PanelBuilder(editor.getConfigurationSection("SprayRewardsListEditMenu"));
PanelBuilder panelBuilder4 = new PanelBuilder(editor.getConfigurationSection("SprayDropTableMainEditMenu")); //TODO
PanelBuilder panelBuilder5 = new PanelBuilder(editor.getConfigurationSection("SprayDropTableMainEditMenu")); //TODO
PanelBuilder panelBuilder5 = new PanelBuilder(editor.getConfigurationSection("SprayNewRewardEditMenu"));
this.mainDropTableEditMenu = new MainDropTableEditorPanel(this, panelBuilder);
this.dropTableTypeEditMenu = new DropTableTypeEditorPanel(this, panelBuilder1, this.customBosses);
@ -233,7 +233,7 @@ public class BossPanelManager implements ILoadable, IReloadable {
PanelBuilder panelBuilder2 = new PanelBuilder(editor.getConfigurationSection("SprayDropTableMainEditMenu"));
PanelBuilder panelBuilder3 = new PanelBuilder(editor.getConfigurationSection("SprayRewardsListEditMenu"));
PanelBuilder panelBuilder4 = new PanelBuilder(editor.getConfigurationSection("SprayDropTableMainEditMenu")); //TODO
PanelBuilder panelBuilder5 = new PanelBuilder(editor.getConfigurationSection("SprayDropTableMainEditMenu")); //TODO
PanelBuilder panelBuilder5 = new PanelBuilder(editor.getConfigurationSection("SprayNewRewardEditMenu"));
this.mainDropTableEditMenu.initializePanel(panelBuilder);
this.dropTableTypeEditMenu.initializePanel(panelBuilder1);

View File

@ -1,13 +1,23 @@
package com.songoda.epicbosses.panel.droptables.types.spray;
import com.songoda.epicbosses.CustomBosses;
import com.songoda.epicbosses.api.BossAPI;
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.ItemsFileManager;
import com.songoda.epicbosses.utils.Message;
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 org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author Charles Cullen
@ -16,22 +26,79 @@ import org.bukkit.entity.Player;
*/
public class SprayNewRewardEditorPanel extends SubVariablePanelHandler<DropTable, SprayTableElement> {
private ItemsFileManager itemsFileManager;
private CustomBosses plugin;
public SprayNewRewardEditorPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) {
super(bossPanelManager, panelBuilder);
this.itemsFileManager = plugin.getItemStackManager();
this.plugin = plugin;
}
@Override
public void fillPanel(Panel panel, DropTable dropTable, SprayTableElement sprayTableElement) {
Map<String, ItemStackHolder> itemStacks = this.itemsFileManager.getItemStackHolders();
List<String> currentKeys = new ArrayList<>(sprayTableElement.getSprayRewards().keySet());
List<String> filteredKeys = getFilteredKeys(itemStacks, currentKeys);
int maxPage = panel.getMaxPage(filteredKeys);
panel.setOnPageChange(((player, currentPage, requestedPage) -> {
if(requestedPage < 0 || requestedPage > maxPage) return false;
loadPage(panel, requestedPage, dropTable, sprayTableElement, filteredKeys, itemStacks);
return true;
}));
loadPage(panel, 0, dropTable, sprayTableElement, filteredKeys, itemStacks);
}
@Override
public void openFor(Player player, DropTable dropTable, SprayTableElement sprayTableElement) {
Panel panel = getPanelBuilder().getPanel()
.setParentPanelHandler(this.bossPanelManager.getSprayRewardListEditMenu(), dropTable, sprayTableElement);
fillPanel(panel, dropTable, sprayTableElement);
panel.openFor(player);
}
@Override
public void initializePanel(PanelBuilder panelBuilder) {
}
private void loadPage(Panel panel, int page, DropTable dropTable, SprayTableElement sprayTableElement, List<String> filteredKeys, Map<String, ItemStackHolder> itemStacks) {
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);
panel.setItem(realisticSlot, itemStack, event -> {
Map<String, Double> currentRewards = sprayTableElement.getSprayRewards();
currentRewards.put(name, 50.0);
dropTable.setRewards(BossAPI.convertObjectToJsonObject(sprayTableElement));
this.plugin.getDropTableFileManager().save();
this.bossPanelManager.getSprayRewardMainEditMenu().openFor((Player) event.getWhoClicked(), dropTable, sprayTableElement, name);
Message.Boss_DropTable_SprayAddedNewReward.msg(event.getWhoClicked(), BossAPI.getDropTableName(dropTable));
});
}
});
}
private List<String> getFilteredKeys(Map<String, ItemStackHolder> itemStacks, List<String> currentKeys) {
List<String> filteredList = new ArrayList<>();
itemStacks.keySet().forEach(string -> {
if(currentKeys.contains(string)) return;
filteredList.add(string);
});
return filteredList;
}
}

View File

@ -38,6 +38,7 @@ public enum Message {
Boss_DropTable_SetMaxDrops("&b&lEpicBosses &8» &7You have {0} the max drops for the drop table to &f{1}&7."),
Boss_DropTable_SetMaxDistance("&b&lEpicBosses &8» &7You have {0} the max distance for the drop table to &f{1}&7."),
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_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."),

View File

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