mirror of
https://github.com/songoda/EpicBosses.git
synced 2025-01-23 07:11:28 +01:00
1.0.0-SNAPSHOT-U73
+ Added Leggings, Chestplate and Boots Editor Panels + Completed the Helmet Editor Panel
This commit is contained in:
parent
ccf471b16d
commit
31af773426
@ -421,7 +421,7 @@ HelmetEditorPanel:
|
||||
fillTo: 45
|
||||
backButton: true
|
||||
Buttons:
|
||||
BackButton: 54
|
||||
backButton: 54
|
||||
Items:
|
||||
'46':
|
||||
type: DIAMOND
|
||||
|
@ -9,7 +9,10 @@ import com.songoda.epicbosses.panel.bosses.BossListEquipmentEditorPanel;
|
||||
import com.songoda.epicbosses.panel.bosses.DropsEditorPanel;
|
||||
import com.songoda.epicbosses.panel.bosses.EquipmentEditorPanel;
|
||||
import com.songoda.epicbosses.panel.bosses.MainBossEditPanel;
|
||||
import com.songoda.epicbosses.panel.bosses.equipment.BootsEditorPanel;
|
||||
import com.songoda.epicbosses.panel.bosses.equipment.ChestplateEditorPanel;
|
||||
import com.songoda.epicbosses.panel.bosses.equipment.HelmetEditorPanel;
|
||||
import com.songoda.epicbosses.panel.bosses.equipment.LeggingsEditorPanel;
|
||||
import com.songoda.epicbosses.utils.panel.base.ISubVariablePanelHandler;
|
||||
import com.songoda.epicbosses.utils.panel.base.IVariablePanelHandler;
|
||||
import lombok.Getter;
|
||||
@ -37,7 +40,7 @@ public class BossPanelManager implements ILoadable, IReloadable {
|
||||
@Getter private IPanelHandler addItemsMenu;
|
||||
|
||||
@Getter private IVariablePanelHandler<BossEntity> mainBossEditMenu, dropsEditMenu, equipmentListEditMenu;
|
||||
@Getter private ISubVariablePanelHandler<BossEntity, EntityStatsElement> equipmentEditMenu, helmetEditorMenu;
|
||||
@Getter private ISubVariablePanelHandler<BossEntity, EntityStatsElement> equipmentEditMenu, helmetEditorMenu, chestplateEditorMenu, leggingsEditorMenu, bootsEditorMenu;
|
||||
|
||||
private final CustomBosses customBosses;
|
||||
|
||||
@ -63,6 +66,9 @@ public class BossPanelManager implements ILoadable, IReloadable {
|
||||
|
||||
loadEquipmentEditMenu();
|
||||
loadHelmetEditMenu();
|
||||
loadChestplateEditMenu();
|
||||
loadLeggingsEditMenu();
|
||||
loadBootsEditMenu();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -83,6 +89,9 @@ public class BossPanelManager implements ILoadable, IReloadable {
|
||||
|
||||
reloadEquipmentEditMenu();
|
||||
reloadHelmetEditMenu();
|
||||
reloadChestplateEditMenu();
|
||||
reloadLeggingsEditMenu();
|
||||
reloadBootsEditMenu();
|
||||
}
|
||||
|
||||
public int isItemStackUsed(String name) {
|
||||
@ -112,7 +121,7 @@ public class BossPanelManager implements ILoadable, IReloadable {
|
||||
|
||||
//---------------------------------------------
|
||||
//
|
||||
// H E L ME T E D I T P A N E L
|
||||
// E Q U I P M E N T E D I T P A N E L S
|
||||
//
|
||||
//---------------------------------------------
|
||||
|
||||
@ -128,6 +137,42 @@ public class BossPanelManager implements ILoadable, IReloadable {
|
||||
this.helmetEditorMenu.initializePanel(panelBuilder);
|
||||
}
|
||||
|
||||
private void loadChestplateEditMenu() {
|
||||
PanelBuilder panelBuilder = new PanelBuilder(this.customBosses.getEditor().getConfigurationSection("ChestplateEditorPanel"));
|
||||
|
||||
this.chestplateEditorMenu = new ChestplateEditorPanel(this, panelBuilder, this.customBosses);
|
||||
}
|
||||
|
||||
private void reloadChestplateEditMenu() {
|
||||
PanelBuilder panelBuilder = new PanelBuilder(this.customBosses.getEditor().getConfigurationSection("ChestplateEditorPanel"));
|
||||
|
||||
this.chestplateEditorMenu.initializePanel(panelBuilder);
|
||||
}
|
||||
|
||||
private void loadLeggingsEditMenu() {
|
||||
PanelBuilder panelBuilder = new PanelBuilder(this.customBosses.getEditor().getConfigurationSection("LeggingsEditorPanel"));
|
||||
|
||||
this.leggingsEditorMenu = new LeggingsEditorPanel(this, panelBuilder, this.customBosses);
|
||||
}
|
||||
|
||||
private void reloadLeggingsEditMenu() {
|
||||
PanelBuilder panelBuilder = new PanelBuilder(this.customBosses.getEditor().getConfigurationSection("LeggingsEditorPanel"));
|
||||
|
||||
this.leggingsEditorMenu.initializePanel(panelBuilder);
|
||||
}
|
||||
|
||||
private void loadBootsEditMenu() {
|
||||
PanelBuilder panelBuilder = new PanelBuilder(this.customBosses.getEditor().getConfigurationSection("BootsEditorPanel"));
|
||||
|
||||
this.bootsEditorMenu = new BootsEditorPanel(this, panelBuilder, this.customBosses);
|
||||
}
|
||||
|
||||
private void reloadBootsEditMenu() {
|
||||
PanelBuilder panelBuilder = new PanelBuilder(this.customBosses.getEditor().getConfigurationSection("BootsEditorPanel"));
|
||||
|
||||
this.bootsEditorMenu.initializePanel(panelBuilder);
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
//
|
||||
// E Q U I P M E N T L I S T E D I T P A N E L
|
||||
|
@ -55,8 +55,9 @@ public class EquipmentEditorPanel extends SubVariablePanelHandler<BossEntity, En
|
||||
.setCancelLowerClick(true)
|
||||
.setCancelClick(true)
|
||||
.setParentPanelHandler(this.bossPanelManager.getEquipmentListEditMenu(), bossEntity);
|
||||
PanelBuilderCounter panelBuilderCounter = panel.getPanelBuilderCounter();
|
||||
|
||||
|
||||
panelBuilderCounter.getSlotsWith("Helmet").forEach(slot -> panel.setOnClick(slot, event -> this.bossPanelManager.getHelmetEditorMenu().openFor(player, bossEntity, entityStatsElement)));
|
||||
|
||||
panel.openFor(player);
|
||||
}
|
||||
|
@ -0,0 +1,149 @@
|
||||
package com.songoda.epicbosses.panel.bosses.equipment;
|
||||
|
||||
import com.songoda.epicbosses.CustomBosses;
|
||||
import com.songoda.epicbosses.api.BossAPI;
|
||||
import com.songoda.epicbosses.entity.BossEntity;
|
||||
import com.songoda.epicbosses.entity.elements.EntityStatsElement;
|
||||
import com.songoda.epicbosses.managers.BossPanelManager;
|
||||
import com.songoda.epicbosses.managers.files.BossesFileManager;
|
||||
import com.songoda.epicbosses.managers.files.ItemsFileManager;
|
||||
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.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 19-Nov-18
|
||||
*/
|
||||
public class BootsEditorPanel extends SubVariablePanelHandler<BossEntity, EntityStatsElement> {
|
||||
|
||||
private ItemStackConverter itemStackConverter;
|
||||
private BossesFileManager bossesFileManager;
|
||||
private ItemsFileManager itemsFileManager;
|
||||
private CustomBosses plugin;
|
||||
|
||||
public BootsEditorPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) {
|
||||
super(bossPanelManager, panelBuilder);
|
||||
|
||||
this.plugin = plugin;
|
||||
this.itemStackConverter = new ItemStackConverter();
|
||||
this.itemsFileManager = plugin.getItemStackManager();
|
||||
this.bossesFileManager = plugin.getBossesFileManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillPanel(Panel panel, BossEntity bossEntity, EntityStatsElement entityStatsElement) {
|
||||
Map<String, ItemStackHolder> itemStackHolderMap = this.itemsFileManager.getItemStackHolders();
|
||||
Map<String, ItemStackHolder> filteredMap = filterMap(itemStackHolderMap);
|
||||
List<String> entryList = new ArrayList<>(filteredMap.keySet());
|
||||
int maxPage = panel.getMaxPage(entryList);
|
||||
|
||||
panel.setOnPageChange(((player, currentPage, requestedPage) -> {
|
||||
if(requestedPage < 0 || requestedPage > maxPage) return false;
|
||||
|
||||
loadPage(panel, requestedPage, filteredMap, entryList, bossEntity, entityStatsElement);
|
||||
return true;
|
||||
}));
|
||||
|
||||
loadPage(panel, 0, filteredMap, entryList, bossEntity, entityStatsElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openFor(Player player, BossEntity bossEntity, EntityStatsElement entityStatsElement) {
|
||||
Map<String, String> replaceMap = new HashMap<>();
|
||||
|
||||
replaceMap.put("{name}", BossAPI.getBossEntityName(bossEntity));
|
||||
|
||||
PanelBuilder panelBuilder = getPanelBuilder().cloneBuilder();
|
||||
|
||||
panelBuilder.addReplaceData(replaceMap);
|
||||
|
||||
Panel panel = panelBuilder.getPanel()
|
||||
.setDestroyWhenDone(true)
|
||||
.setCancelLowerClick(true)
|
||||
.setCancelClick(true)
|
||||
.setParentPanelHandler(this.bossPanelManager.getEquipmentEditMenu(), bossEntity, entityStatsElement);
|
||||
PanelBuilderCounter panelBuilderCounter = panel.getPanelBuilderCounter();
|
||||
|
||||
panelBuilderCounter.getSlotsWith("AddNew").forEach(slot -> panel.setOnClick(slot, event -> this.bossPanelManager.getAddItemsMenu().openFor(player)));
|
||||
panelBuilderCounter.getSlotsWith("Remove").forEach(slot -> panel.setOnClick(slot, event -> {
|
||||
entityStatsElement.getEquipment().setHelmet("");
|
||||
this.bossesFileManager.save();
|
||||
|
||||
openFor((Player) event.getWhoClicked(), bossEntity, entityStatsElement);
|
||||
}));
|
||||
|
||||
fillPanel(panel, bossEntity, entityStatsElement);
|
||||
|
||||
panel.openFor(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializePanel(PanelBuilder panelBuilder) {
|
||||
PanelBuilderCounter panelBuilderCounter = panelBuilder.getPanelBuilderCounter();
|
||||
|
||||
panelBuilderCounter
|
||||
.addSlotCounter("Remove")
|
||||
.addSlotCounter("AddNew");
|
||||
}
|
||||
|
||||
private void loadPage(Panel panel, int requestedPage, Map<String, ItemStackHolder> itemStackHolderMap, List<String> entryList, BossEntity bossEntity, EntityStatsElement entityStatsElement) {
|
||||
String helmet = entityStatsElement.getEquipment().getHelmet();
|
||||
|
||||
panel.loadPage(requestedPage, (slot, realisticSlot) -> {
|
||||
if(slot >= itemStackHolderMap.size()) {
|
||||
panel.setItem(realisticSlot, new ItemStack(Material.AIR), e -> {});
|
||||
} else {
|
||||
String name = entryList.get(slot);
|
||||
ItemStackHolder itemStackHolder = itemStackHolderMap.get(name);
|
||||
ItemStack itemStack = this.itemStackConverter.from(itemStackHolder);
|
||||
|
||||
if(itemStack == null) {
|
||||
itemStack = new ItemStack(Material.BARRIER);
|
||||
}
|
||||
|
||||
if(name.equalsIgnoreCase(helmet)) {
|
||||
Map<String, String> replaceMap = new HashMap<>();
|
||||
|
||||
replaceMap.put("{name}", ItemStackUtils.getName(itemStack));
|
||||
|
||||
ItemStackUtils.applyDisplayName(itemStack, this.plugin.getConfig().getString("Display.EquipmentEditor.name"), replaceMap);
|
||||
}
|
||||
|
||||
panel.setItem(realisticSlot, itemStack, e -> {
|
||||
entityStatsElement.getEquipment().setHelmet(name);
|
||||
this.bossesFileManager.save();
|
||||
|
||||
openFor((Player) e.getWhoClicked(), bossEntity, entityStatsElement);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Map<String, ItemStackHolder> filterMap(Map<String, ItemStackHolder> itemStackHolderMap) {
|
||||
Map<String, ItemStackHolder> newMap = new HashMap<>();
|
||||
|
||||
itemStackHolderMap.forEach((string, holder) -> {
|
||||
ItemStack itemStack = this.itemStackConverter.from(holder);
|
||||
|
||||
if(itemStack.getType().name().contains("BOOTS")) {
|
||||
newMap.put(string, holder);
|
||||
}
|
||||
});
|
||||
|
||||
return newMap;
|
||||
}
|
||||
}
|
@ -0,0 +1,149 @@
|
||||
package com.songoda.epicbosses.panel.bosses.equipment;
|
||||
|
||||
import com.songoda.epicbosses.CustomBosses;
|
||||
import com.songoda.epicbosses.api.BossAPI;
|
||||
import com.songoda.epicbosses.entity.BossEntity;
|
||||
import com.songoda.epicbosses.entity.elements.EntityStatsElement;
|
||||
import com.songoda.epicbosses.managers.BossPanelManager;
|
||||
import com.songoda.epicbosses.managers.files.BossesFileManager;
|
||||
import com.songoda.epicbosses.managers.files.ItemsFileManager;
|
||||
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.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 19-Nov-18
|
||||
*/
|
||||
public class ChestplateEditorPanel extends SubVariablePanelHandler<BossEntity, EntityStatsElement> {
|
||||
|
||||
private ItemStackConverter itemStackConverter;
|
||||
private BossesFileManager bossesFileManager;
|
||||
private ItemsFileManager itemsFileManager;
|
||||
private CustomBosses plugin;
|
||||
|
||||
public ChestplateEditorPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) {
|
||||
super(bossPanelManager, panelBuilder);
|
||||
|
||||
this.plugin = plugin;
|
||||
this.itemStackConverter = new ItemStackConverter();
|
||||
this.itemsFileManager = plugin.getItemStackManager();
|
||||
this.bossesFileManager = plugin.getBossesFileManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillPanel(Panel panel, BossEntity bossEntity, EntityStatsElement entityStatsElement) {
|
||||
Map<String, ItemStackHolder> itemStackHolderMap = this.itemsFileManager.getItemStackHolders();
|
||||
Map<String, ItemStackHolder> filteredMap = filterMap(itemStackHolderMap);
|
||||
List<String> entryList = new ArrayList<>(filteredMap.keySet());
|
||||
int maxPage = panel.getMaxPage(entryList);
|
||||
|
||||
panel.setOnPageChange(((player, currentPage, requestedPage) -> {
|
||||
if(requestedPage < 0 || requestedPage > maxPage) return false;
|
||||
|
||||
loadPage(panel, requestedPage, filteredMap, entryList, bossEntity, entityStatsElement);
|
||||
return true;
|
||||
}));
|
||||
|
||||
loadPage(panel, 0, filteredMap, entryList, bossEntity, entityStatsElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openFor(Player player, BossEntity bossEntity, EntityStatsElement entityStatsElement) {
|
||||
Map<String, String> replaceMap = new HashMap<>();
|
||||
|
||||
replaceMap.put("{name}", BossAPI.getBossEntityName(bossEntity));
|
||||
|
||||
PanelBuilder panelBuilder = getPanelBuilder().cloneBuilder();
|
||||
|
||||
panelBuilder.addReplaceData(replaceMap);
|
||||
|
||||
Panel panel = panelBuilder.getPanel()
|
||||
.setDestroyWhenDone(true)
|
||||
.setCancelLowerClick(true)
|
||||
.setCancelClick(true)
|
||||
.setParentPanelHandler(this.bossPanelManager.getEquipmentEditMenu(), bossEntity, entityStatsElement);
|
||||
PanelBuilderCounter panelBuilderCounter = panel.getPanelBuilderCounter();
|
||||
|
||||
panelBuilderCounter.getSlotsWith("AddNew").forEach(slot -> panel.setOnClick(slot, event -> this.bossPanelManager.getAddItemsMenu().openFor(player)));
|
||||
panelBuilderCounter.getSlotsWith("Remove").forEach(slot -> panel.setOnClick(slot, event -> {
|
||||
entityStatsElement.getEquipment().setHelmet("");
|
||||
this.bossesFileManager.save();
|
||||
|
||||
openFor((Player) event.getWhoClicked(), bossEntity, entityStatsElement);
|
||||
}));
|
||||
|
||||
fillPanel(panel, bossEntity, entityStatsElement);
|
||||
|
||||
panel.openFor(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializePanel(PanelBuilder panelBuilder) {
|
||||
PanelBuilderCounter panelBuilderCounter = panelBuilder.getPanelBuilderCounter();
|
||||
|
||||
panelBuilderCounter
|
||||
.addSlotCounter("Remove")
|
||||
.addSlotCounter("AddNew");
|
||||
}
|
||||
|
||||
private void loadPage(Panel panel, int requestedPage, Map<String, ItemStackHolder> itemStackHolderMap, List<String> entryList, BossEntity bossEntity, EntityStatsElement entityStatsElement) {
|
||||
String helmet = entityStatsElement.getEquipment().getHelmet();
|
||||
|
||||
panel.loadPage(requestedPage, (slot, realisticSlot) -> {
|
||||
if(slot >= itemStackHolderMap.size()) {
|
||||
panel.setItem(realisticSlot, new ItemStack(Material.AIR), e -> {});
|
||||
} else {
|
||||
String name = entryList.get(slot);
|
||||
ItemStackHolder itemStackHolder = itemStackHolderMap.get(name);
|
||||
ItemStack itemStack = this.itemStackConverter.from(itemStackHolder);
|
||||
|
||||
if(itemStack == null) {
|
||||
itemStack = new ItemStack(Material.BARRIER);
|
||||
}
|
||||
|
||||
if(name.equalsIgnoreCase(helmet)) {
|
||||
Map<String, String> replaceMap = new HashMap<>();
|
||||
|
||||
replaceMap.put("{name}", ItemStackUtils.getName(itemStack));
|
||||
|
||||
ItemStackUtils.applyDisplayName(itemStack, this.plugin.getConfig().getString("Display.EquipmentEditor.name"), replaceMap);
|
||||
}
|
||||
|
||||
panel.setItem(realisticSlot, itemStack, e -> {
|
||||
entityStatsElement.getEquipment().setHelmet(name);
|
||||
this.bossesFileManager.save();
|
||||
|
||||
openFor((Player) e.getWhoClicked(), bossEntity, entityStatsElement);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Map<String, ItemStackHolder> filterMap(Map<String, ItemStackHolder> itemStackHolderMap) {
|
||||
Map<String, ItemStackHolder> newMap = new HashMap<>();
|
||||
|
||||
itemStackHolderMap.forEach((string, holder) -> {
|
||||
ItemStack itemStack = this.itemStackConverter.from(holder);
|
||||
|
||||
if(itemStack.getType().name().contains("CHESTPLATE")) {
|
||||
newMap.put(string, holder);
|
||||
}
|
||||
});
|
||||
|
||||
return newMap;
|
||||
}
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
package com.songoda.epicbosses.panel.bosses.equipment;
|
||||
|
||||
import com.songoda.epicbosses.CustomBosses;
|
||||
import com.songoda.epicbosses.api.BossAPI;
|
||||
import com.songoda.epicbosses.entity.BossEntity;
|
||||
import com.songoda.epicbosses.entity.elements.EntityStatsElement;
|
||||
import com.songoda.epicbosses.managers.BossPanelManager;
|
||||
import com.songoda.epicbosses.managers.files.BossesFileManager;
|
||||
import com.songoda.epicbosses.managers.files.ItemsFileManager;
|
||||
import com.songoda.epicbosses.utils.itemstack.ItemStackConverter;
|
||||
import com.songoda.epicbosses.utils.itemstack.ItemStackUtils;
|
||||
@ -11,6 +13,7 @@ import com.songoda.epicbosses.utils.itemstack.holder.ItemStackHolder;
|
||||
import com.songoda.epicbosses.utils.panel.Panel;
|
||||
import com.songoda.epicbosses.utils.panel.base.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;
|
||||
@ -28,6 +31,7 @@ import java.util.Map;
|
||||
public class HelmetEditorPanel extends SubVariablePanelHandler<BossEntity, EntityStatsElement> {
|
||||
|
||||
private ItemStackConverter itemStackConverter;
|
||||
private BossesFileManager bossesFileManager;
|
||||
private ItemsFileManager itemsFileManager;
|
||||
private CustomBosses plugin;
|
||||
|
||||
@ -37,35 +41,66 @@ public class HelmetEditorPanel extends SubVariablePanelHandler<BossEntity, Entit
|
||||
this.plugin = plugin;
|
||||
this.itemStackConverter = new ItemStackConverter();
|
||||
this.itemsFileManager = plugin.getItemStackManager();
|
||||
this.bossesFileManager = plugin.getBossesFileManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillPanel(Panel panel, BossEntity bossEntity, EntityStatsElement entityStatsElement) {
|
||||
Map<String, ItemStackHolder> itemStackHolderMap = this.itemsFileManager.getItemStackHolders();
|
||||
List<String> entryList = new ArrayList<>(itemStackHolderMap.keySet());
|
||||
Map<String, ItemStackHolder> filteredMap = filterMap(itemStackHolderMap);
|
||||
List<String> entryList = new ArrayList<>(filteredMap.keySet());
|
||||
int maxPage = panel.getMaxPage(entryList);
|
||||
|
||||
panel.setOnPageChange(((player, currentPage, requestedPage) -> {
|
||||
if(requestedPage < 0 || requestedPage > maxPage) return false;
|
||||
|
||||
loadPage(panel, requestedPage, itemStackHolderMap, entryList, entityStatsElement);
|
||||
loadPage(panel, requestedPage, filteredMap, entryList, bossEntity, entityStatsElement);
|
||||
return true;
|
||||
}));
|
||||
|
||||
loadPage(panel, 0, itemStackHolderMap, entryList, entityStatsElement);
|
||||
loadPage(panel, 0, filteredMap, entryList, bossEntity, entityStatsElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openFor(Player player, BossEntity bossEntity, EntityStatsElement entityStatsElement) {
|
||||
Map<String, String> replaceMap = new HashMap<>();
|
||||
|
||||
replaceMap.put("{name}", BossAPI.getBossEntityName(bossEntity));
|
||||
|
||||
PanelBuilder panelBuilder = getPanelBuilder().cloneBuilder();
|
||||
|
||||
panelBuilder.addReplaceData(replaceMap);
|
||||
|
||||
Panel panel = panelBuilder.getPanel()
|
||||
.setDestroyWhenDone(true)
|
||||
.setCancelLowerClick(true)
|
||||
.setCancelClick(true)
|
||||
.setParentPanelHandler(this.bossPanelManager.getEquipmentEditMenu(), bossEntity, entityStatsElement);
|
||||
PanelBuilderCounter panelBuilderCounter = panel.getPanelBuilderCounter();
|
||||
|
||||
panelBuilderCounter.getSlotsWith("AddNew").forEach(slot -> panel.setOnClick(slot, event -> this.bossPanelManager.getAddItemsMenu().openFor(player)));
|
||||
panelBuilderCounter.getSlotsWith("Remove").forEach(slot -> panel.setOnClick(slot, event -> {
|
||||
entityStatsElement.getEquipment().setHelmet("");
|
||||
this.bossesFileManager.save();
|
||||
|
||||
openFor((Player) event.getWhoClicked(), bossEntity, entityStatsElement);
|
||||
}));
|
||||
|
||||
fillPanel(panel, bossEntity, entityStatsElement);
|
||||
|
||||
panel.openFor(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializePanel(PanelBuilder panelBuilder) {
|
||||
PanelBuilderCounter panelBuilderCounter = panelBuilder.getPanelBuilderCounter();
|
||||
|
||||
panelBuilderCounter
|
||||
.addSlotCounter("Remove")
|
||||
.addSlotCounter("AddNew");
|
||||
}
|
||||
|
||||
private void loadPage(Panel panel, int requestedPage, Map<String, ItemStackHolder> itemStackHolderMap, List<String> entryList, EntityStatsElement entityStatsElement) {
|
||||
private void loadPage(Panel panel, int requestedPage, Map<String, ItemStackHolder> itemStackHolderMap, List<String> entryList, BossEntity bossEntity, EntityStatsElement entityStatsElement) {
|
||||
String helmet = entityStatsElement.getEquipment().getHelmet();
|
||||
|
||||
panel.loadPage(requestedPage, (slot, realisticSlot) -> {
|
||||
@ -80,16 +115,35 @@ public class HelmetEditorPanel extends SubVariablePanelHandler<BossEntity, Entit
|
||||
itemStack = new ItemStack(Material.BARRIER);
|
||||
}
|
||||
|
||||
Map<String, String> replaceMap = new HashMap<>();
|
||||
if(name.equalsIgnoreCase(helmet)) {
|
||||
Map<String, String> replaceMap = new HashMap<>();
|
||||
|
||||
replaceMap.put("{name}", ItemStackUtils.getName(itemStack));
|
||||
replaceMap.put("{name}", ItemStackUtils.getName(itemStack));
|
||||
|
||||
ItemStackUtils.applyDisplayName(itemStack, this.plugin.getConfig().getString("Display.EquipmentEditor.name"), replaceMap);
|
||||
ItemStackUtils.applyDisplayName(itemStack, this.plugin.getConfig().getString("Display.EquipmentEditor.name"), replaceMap);
|
||||
}
|
||||
|
||||
panel.setItem(realisticSlot, itemStack, e -> {
|
||||
entityStatsElement.getEquipment().setHelmet(name);
|
||||
this.bossesFileManager.save();
|
||||
|
||||
openFor((Player) e.getWhoClicked(), bossEntity, entityStatsElement);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Map<String, ItemStackHolder> filterMap(Map<String, ItemStackHolder> itemStackHolderMap) {
|
||||
Map<String, ItemStackHolder> newMap = new HashMap<>();
|
||||
|
||||
itemStackHolderMap.forEach((string, holder) -> {
|
||||
ItemStack itemStack = this.itemStackConverter.from(holder);
|
||||
|
||||
if(itemStack.getType().name().contains("HELMET") || itemStack.getType().isBlock()) {
|
||||
newMap.put(string, holder);
|
||||
}
|
||||
});
|
||||
|
||||
return newMap;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,149 @@
|
||||
package com.songoda.epicbosses.panel.bosses.equipment;
|
||||
|
||||
import com.songoda.epicbosses.CustomBosses;
|
||||
import com.songoda.epicbosses.api.BossAPI;
|
||||
import com.songoda.epicbosses.entity.BossEntity;
|
||||
import com.songoda.epicbosses.entity.elements.EntityStatsElement;
|
||||
import com.songoda.epicbosses.managers.BossPanelManager;
|
||||
import com.songoda.epicbosses.managers.files.BossesFileManager;
|
||||
import com.songoda.epicbosses.managers.files.ItemsFileManager;
|
||||
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.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 19-Nov-18
|
||||
*/
|
||||
public class LeggingsEditorPanel extends SubVariablePanelHandler<BossEntity, EntityStatsElement> {
|
||||
|
||||
private ItemStackConverter itemStackConverter;
|
||||
private BossesFileManager bossesFileManager;
|
||||
private ItemsFileManager itemsFileManager;
|
||||
private CustomBosses plugin;
|
||||
|
||||
public LeggingsEditorPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) {
|
||||
super(bossPanelManager, panelBuilder);
|
||||
|
||||
this.plugin = plugin;
|
||||
this.itemStackConverter = new ItemStackConverter();
|
||||
this.itemsFileManager = plugin.getItemStackManager();
|
||||
this.bossesFileManager = plugin.getBossesFileManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillPanel(Panel panel, BossEntity bossEntity, EntityStatsElement entityStatsElement) {
|
||||
Map<String, ItemStackHolder> itemStackHolderMap = this.itemsFileManager.getItemStackHolders();
|
||||
Map<String, ItemStackHolder> filteredMap = filterMap(itemStackHolderMap);
|
||||
List<String> entryList = new ArrayList<>(filteredMap.keySet());
|
||||
int maxPage = panel.getMaxPage(entryList);
|
||||
|
||||
panel.setOnPageChange(((player, currentPage, requestedPage) -> {
|
||||
if(requestedPage < 0 || requestedPage > maxPage) return false;
|
||||
|
||||
loadPage(panel, requestedPage, filteredMap, entryList, bossEntity, entityStatsElement);
|
||||
return true;
|
||||
}));
|
||||
|
||||
loadPage(panel, 0, filteredMap, entryList, bossEntity, entityStatsElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openFor(Player player, BossEntity bossEntity, EntityStatsElement entityStatsElement) {
|
||||
Map<String, String> replaceMap = new HashMap<>();
|
||||
|
||||
replaceMap.put("{name}", BossAPI.getBossEntityName(bossEntity));
|
||||
|
||||
PanelBuilder panelBuilder = getPanelBuilder().cloneBuilder();
|
||||
|
||||
panelBuilder.addReplaceData(replaceMap);
|
||||
|
||||
Panel panel = panelBuilder.getPanel()
|
||||
.setDestroyWhenDone(true)
|
||||
.setCancelLowerClick(true)
|
||||
.setCancelClick(true)
|
||||
.setParentPanelHandler(this.bossPanelManager.getEquipmentEditMenu(), bossEntity, entityStatsElement);
|
||||
PanelBuilderCounter panelBuilderCounter = panel.getPanelBuilderCounter();
|
||||
|
||||
panelBuilderCounter.getSlotsWith("AddNew").forEach(slot -> panel.setOnClick(slot, event -> this.bossPanelManager.getAddItemsMenu().openFor(player)));
|
||||
panelBuilderCounter.getSlotsWith("Remove").forEach(slot -> panel.setOnClick(slot, event -> {
|
||||
entityStatsElement.getEquipment().setHelmet("");
|
||||
this.bossesFileManager.save();
|
||||
|
||||
openFor((Player) event.getWhoClicked(), bossEntity, entityStatsElement);
|
||||
}));
|
||||
|
||||
fillPanel(panel, bossEntity, entityStatsElement);
|
||||
|
||||
panel.openFor(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializePanel(PanelBuilder panelBuilder) {
|
||||
PanelBuilderCounter panelBuilderCounter = panelBuilder.getPanelBuilderCounter();
|
||||
|
||||
panelBuilderCounter
|
||||
.addSlotCounter("Remove")
|
||||
.addSlotCounter("AddNew");
|
||||
}
|
||||
|
||||
private void loadPage(Panel panel, int requestedPage, Map<String, ItemStackHolder> itemStackHolderMap, List<String> entryList, BossEntity bossEntity, EntityStatsElement entityStatsElement) {
|
||||
String helmet = entityStatsElement.getEquipment().getHelmet();
|
||||
|
||||
panel.loadPage(requestedPage, (slot, realisticSlot) -> {
|
||||
if(slot >= itemStackHolderMap.size()) {
|
||||
panel.setItem(realisticSlot, new ItemStack(Material.AIR), e -> {});
|
||||
} else {
|
||||
String name = entryList.get(slot);
|
||||
ItemStackHolder itemStackHolder = itemStackHolderMap.get(name);
|
||||
ItemStack itemStack = this.itemStackConverter.from(itemStackHolder);
|
||||
|
||||
if(itemStack == null) {
|
||||
itemStack = new ItemStack(Material.BARRIER);
|
||||
}
|
||||
|
||||
if(name.equalsIgnoreCase(helmet)) {
|
||||
Map<String, String> replaceMap = new HashMap<>();
|
||||
|
||||
replaceMap.put("{name}", ItemStackUtils.getName(itemStack));
|
||||
|
||||
ItemStackUtils.applyDisplayName(itemStack, this.plugin.getConfig().getString("Display.EquipmentEditor.name"), replaceMap);
|
||||
}
|
||||
|
||||
panel.setItem(realisticSlot, itemStack, e -> {
|
||||
entityStatsElement.getEquipment().setHelmet(name);
|
||||
this.bossesFileManager.save();
|
||||
|
||||
openFor((Player) e.getWhoClicked(), bossEntity, entityStatsElement);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Map<String, ItemStackHolder> filterMap(Map<String, ItemStackHolder> itemStackHolderMap) {
|
||||
Map<String, ItemStackHolder> newMap = new HashMap<>();
|
||||
|
||||
itemStackHolderMap.forEach((string, holder) -> {
|
||||
ItemStack itemStack = this.itemStackConverter.from(holder);
|
||||
|
||||
if(itemStack.getType().name().contains("LEGGINGS")) {
|
||||
newMap.put(string, holder);
|
||||
}
|
||||
});
|
||||
|
||||
return newMap;
|
||||
}
|
||||
}
|
@ -409,6 +409,15 @@ public class Panel implements Listener, ICloneable<Panel> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T, Y> Panel setParentPanelHandler(ISubVariablePanelHandler<T, Y> variablePanelHandler, T variable, Y subVariable) {
|
||||
if(!this.panelBuilderSettings.isBackButton()) return this;
|
||||
|
||||
int slot = this.panelBuilderSettings.getBackButtonSlot() - 1;
|
||||
|
||||
setOnClick(slot, event -> variablePanelHandler.openFor((Player) event.getWhoClicked(), variable, subVariable));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Panel setExitButton() {
|
||||
if(!this.panelBuilderSettings.isExitButton()) return this;
|
||||
|
||||
|
2
pom.xml
2
pom.xml
@ -19,7 +19,7 @@
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<plugin.version>maven-version-number-SNAPSHOT-U72</plugin.version>
|
||||
<plugin.version>maven-version-number-SNAPSHOT-U73</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