mirror of
https://github.com/songoda/EpicBosses.git
synced 2025-01-11 01:37:40 +01:00
1.0.0-SNAPSHOT-U61
+ Started to work on the AddItems GUI + Fixed a few issues where items weren't saving to their true self
This commit is contained in:
parent
8341fe3eab
commit
2851beb1f2
@ -1,6 +1,7 @@
|
||||
{
|
||||
"DefaultBossMenuItem": {
|
||||
"type": "BARRIER"
|
||||
"type": "BARRIER",
|
||||
"name": "&c&lDefault Boss Menu Item"
|
||||
},
|
||||
"SKSpawnItem": {
|
||||
"type": "SKELETON_SPAWN_EGG",
|
||||
|
@ -128,4 +128,32 @@ ListPanel:
|
||||
name: '&7'
|
||||
'54':
|
||||
type: GLASS_PANE
|
||||
name: '&7'
|
||||
name: '&7'
|
||||
AddItemsMenu:
|
||||
name: '&b&lAdd Item Menu'
|
||||
slots: 27
|
||||
Settings:
|
||||
emptySpaceFiller: true
|
||||
EmptySpaceFiller:
|
||||
name: '&7'
|
||||
type: LIGHT_BLUE_STAINED_GLASS_PANE
|
||||
Items:
|
||||
'11':
|
||||
type: REDSTONE
|
||||
name: '&c&lCancel'
|
||||
lore:
|
||||
- '&7Click here to cancel the transaction'
|
||||
- '&7of adding the item to the EpicBosses'
|
||||
- '&7database.'
|
||||
Button: Cancel
|
||||
'14':
|
||||
type: AIR
|
||||
Button: SelectedSlot
|
||||
'17':
|
||||
type: LIME_DYE
|
||||
name: '&a&lAccept'
|
||||
lore:
|
||||
- '&7Click here to accept the transaction'
|
||||
- '&7of adding the item to the EpicBosses'
|
||||
- '&7database.'
|
||||
Button: Accept
|
||||
|
@ -1,5 +1,10 @@
|
||||
package com.songoda.epicbosses.managers;
|
||||
|
||||
import com.songoda.epicbosses.droptable.DropTable;
|
||||
import com.songoda.epicbosses.entity.BossEntity;
|
||||
import com.songoda.epicbosses.entity.elements.EntityStatsElement;
|
||||
import com.songoda.epicbosses.entity.elements.EquipmentElement;
|
||||
import com.songoda.epicbosses.entity.elements.HandsElement;
|
||||
import lombok.Getter;
|
||||
import com.songoda.epicbosses.CustomBosses;
|
||||
import com.songoda.epicbosses.panel.*;
|
||||
@ -9,7 +14,9 @@ import com.songoda.epicbosses.utils.StringUtils;
|
||||
import com.songoda.epicbosses.utils.panel.base.IPanelHandler;
|
||||
import com.songoda.epicbosses.utils.panel.builder.PanelBuilder;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -20,6 +27,7 @@ import java.util.Map;
|
||||
public class BossPanelManager implements ILoadable, IReloadable {
|
||||
|
||||
@Getter private IPanelHandler mainMenu, customItems, bosses, autoSpawns, dropTables, customSkills, shopPanel;
|
||||
@Getter private IPanelHandler addItemsMenu;
|
||||
|
||||
private final CustomBosses customBosses;
|
||||
|
||||
@ -38,6 +46,7 @@ public class BossPanelManager implements ILoadable, IReloadable {
|
||||
loadCustomSkillsMenu();
|
||||
loadDropTableMenu();
|
||||
|
||||
loadAddItemsMenu();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -51,6 +60,50 @@ public class BossPanelManager implements ILoadable, IReloadable {
|
||||
reloadCustomSkills();
|
||||
reloadDropTable();
|
||||
|
||||
reloadAddItemsMenu();
|
||||
}
|
||||
|
||||
public int isItemStackUsed(String name) {
|
||||
Collection<BossEntity> values = this.customBosses.getBossEntityContainer().getData().values();
|
||||
int timesUsed = 0;
|
||||
|
||||
for(BossEntity bossEntity : values) {
|
||||
if(bossEntity.getSpawnItem().equalsIgnoreCase(name)) timesUsed += 1;
|
||||
|
||||
List<EntityStatsElement> entityStatsElements = bossEntity.getEntityStats();
|
||||
|
||||
for(EntityStatsElement entityStatsElement : entityStatsElements) {
|
||||
EquipmentElement equipmentElement = entityStatsElement.getEquipment();
|
||||
HandsElement handsElement = entityStatsElement.getHands();
|
||||
|
||||
if(handsElement.getMainHand().equalsIgnoreCase(name)) timesUsed += 1;
|
||||
if(handsElement.getOffHand().equalsIgnoreCase(name)) timesUsed += 1;
|
||||
if(equipmentElement.getHelmet().equalsIgnoreCase(name)) timesUsed += 1;
|
||||
if(equipmentElement.getChestplate().equalsIgnoreCase(name)) timesUsed += 1;
|
||||
if(equipmentElement.getLeggings().equalsIgnoreCase(name)) timesUsed += 1;
|
||||
if(equipmentElement.getBoots().equalsIgnoreCase(name)) timesUsed += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return timesUsed;
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
//
|
||||
// A D D I T E M S P A N E L
|
||||
//
|
||||
//---------------------------------------------
|
||||
|
||||
private void loadAddItemsMenu() {
|
||||
PanelBuilder panelBuilder = new PanelBuilder(this.customBosses.getEditor().getConfigurationSection("AddItemsMenu"));
|
||||
|
||||
this.addItemsMenu = new AddItemsPanel(this, panelBuilder, this.customBosses);
|
||||
}
|
||||
|
||||
private void reloadAddItemsMenu() {
|
||||
PanelBuilder panelBuilder = new PanelBuilder(this.customBosses.getEditor().getConfigurationSection("AddItemsMenu"));
|
||||
|
||||
this.addItemsMenu.initializePanel(panelBuilder);
|
||||
}
|
||||
|
||||
//---------------------------------------------
|
||||
@ -148,7 +201,7 @@ public class BossPanelManager implements ILoadable, IReloadable {
|
||||
//---------------------------------------------
|
||||
|
||||
private void loadCustomItemsMenu() {
|
||||
this.customItems = new CustomItemsPanel(this, getListMenu("Items"));
|
||||
this.customItems = new CustomItemsPanel(this, getListMenu("Items"), this.customBosses);
|
||||
}
|
||||
|
||||
private void reloadCustomItems() {
|
||||
|
@ -7,6 +7,7 @@ import com.songoda.epicbosses.utils.ISavable;
|
||||
import com.songoda.epicbosses.utils.itemstack.ItemStackConverter;
|
||||
import com.songoda.epicbosses.file.ItemStackFileHandler;
|
||||
import com.songoda.epicbosses.utils.itemstack.holder.ItemStackHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
@ -50,6 +51,16 @@ public class ItemsFileManager implements ILoadable, ISavable, IReloadable {
|
||||
return this.itemStackHolders.getOrDefault(name, null);
|
||||
}
|
||||
|
||||
public void addItemStack(String name, ItemStack itemStack) {
|
||||
this.itemStackHolders.put(name, this.itemStackConverter.to(itemStack));
|
||||
save();
|
||||
}
|
||||
|
||||
public void removeItemStack(String name) {
|
||||
this.itemStackHolders.remove(name);
|
||||
save();
|
||||
}
|
||||
|
||||
public Map<String, ItemStackHolder> getItemStackHolders() {
|
||||
return new HashMap<>(this.itemStackHolders);
|
||||
}
|
||||
|
@ -0,0 +1,129 @@
|
||||
package com.songoda.epicbosses.panel;
|
||||
|
||||
import com.songoda.epicbosses.CustomBosses;
|
||||
import com.songoda.epicbosses.managers.BossPanelManager;
|
||||
import com.songoda.epicbosses.managers.files.ItemsFileManager;
|
||||
import com.songoda.epicbosses.utils.Message;
|
||||
import com.songoda.epicbosses.utils.panel.Panel;
|
||||
import com.songoda.epicbosses.utils.panel.base.ClickAction;
|
||||
import com.songoda.epicbosses.utils.panel.base.PanelHandler;
|
||||
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.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 18-Nov-18
|
||||
*/
|
||||
public class AddItemsPanel extends PanelHandler {
|
||||
|
||||
private Map<UUID, ItemStack> storedItemStacks = new HashMap<>();
|
||||
private ItemsFileManager itemsFileManager;
|
||||
|
||||
public AddItemsPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) {
|
||||
super(bossPanelManager, panelBuilder);
|
||||
|
||||
this.itemsFileManager = plugin.getItemStackManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializePanel(PanelBuilder panelBuilder) {
|
||||
PanelBuilderCounter panelBuilderCounter = panelBuilder.getPanelBuilderCounter();
|
||||
|
||||
panelBuilderCounter
|
||||
.addSlotCounter("Cancel", getCancelAction())
|
||||
.addSlotCounter("Accept", getAcceptAction())
|
||||
.addSlotCounter("SelectedSlot", getSelectedSlotAction(panelBuilderCounter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillPanel(Panel panel) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openFor(Player player) {
|
||||
Panel panel = getPanelBuilder().getPanel()
|
||||
.setDestroyWhenDone(true)
|
||||
.setCancelClick(true)
|
||||
.setCancelLowerClick(false);
|
||||
|
||||
panel.setOnClick(event -> {
|
||||
Player playerWhoClicked = (Player) event.getWhoClicked();
|
||||
UUID uuid = playerWhoClicked.getUniqueId();
|
||||
int rawSlot = event.getRawSlot();
|
||||
int slot = event.getSlot();
|
||||
|
||||
if(panel.isLowerClick(rawSlot)) {
|
||||
if(this.storedItemStacks.containsKey(uuid)) {
|
||||
Message.Boss_Items_AlreadySet.msg(playerWhoClicked);
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack itemStack = event.getClickedInventory().getItem(slot);
|
||||
|
||||
this.storedItemStacks.put(uuid, itemStack.clone());
|
||||
panel.getPanelBuilderCounter().getSlotsWith("SelectedSlot").forEach(s -> event.getInventory().setItem(s, itemStack.clone()));
|
||||
event.getClickedInventory().setItem(slot, new ItemStack(Material.AIR));
|
||||
}
|
||||
});
|
||||
|
||||
panel.openFor(player);
|
||||
}
|
||||
|
||||
private ClickAction getSelectedSlotAction(PanelBuilderCounter panelBuilderCounter) {
|
||||
return event -> {
|
||||
System.out.println("CALLED 1");
|
||||
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
UUID uuid = player.getUniqueId();
|
||||
|
||||
if(this.storedItemStacks.containsKey(uuid)) {
|
||||
player.getInventory().addItem(this.storedItemStacks.get(uuid));
|
||||
this.storedItemStacks.remove(uuid);
|
||||
|
||||
panelBuilderCounter.getSlotsWith("SelectedSlot").forEach(slot -> event.getInventory().setItem(slot, new ItemStack(Material.AIR)));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private ClickAction getAcceptAction() {
|
||||
return event -> {
|
||||
System.out.println("CALLED 2");
|
||||
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
UUID uuid = player.getUniqueId();
|
||||
|
||||
if(this.storedItemStacks.containsKey(uuid)) {
|
||||
this.itemsFileManager.addItemStack(UUID.randomUUID().toString(), this.storedItemStacks.get(uuid));
|
||||
Message.Boss_Items_Added.msg(player);
|
||||
this.storedItemStacks.remove(uuid);
|
||||
}
|
||||
|
||||
this.bossPanelManager.getCustomItems().openFor(player);
|
||||
};
|
||||
}
|
||||
|
||||
private ClickAction getCancelAction() {
|
||||
return event -> {
|
||||
System.out.println("CALLED 3");
|
||||
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
UUID uuid = player.getUniqueId();
|
||||
|
||||
if(this.storedItemStacks.containsKey(uuid)) {
|
||||
player.getInventory().addItem(this.storedItemStacks.get(uuid));
|
||||
this.storedItemStacks.remove(uuid);
|
||||
}
|
||||
|
||||
this.bossPanelManager.getCustomItems().openFor(player);
|
||||
};
|
||||
}
|
||||
}
|
@ -1,22 +1,39 @@
|
||||
package com.songoda.epicbosses.panel;
|
||||
|
||||
import com.songoda.epicbosses.CustomBosses;
|
||||
import com.songoda.epicbosses.entity.BossEntity;
|
||||
import com.songoda.epicbosses.managers.BossPanelManager;
|
||||
import com.songoda.epicbosses.managers.files.ItemsFileManager;
|
||||
import com.songoda.epicbosses.utils.Debug;
|
||||
import com.songoda.epicbosses.utils.Message;
|
||||
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.PanelHandler;
|
||||
import com.songoda.epicbosses.utils.panel.builder.PanelBuilder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
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 10-Oct-18
|
||||
*
|
||||
* TODO
|
||||
*/
|
||||
public class CustomItemsPanel extends PanelHandler {
|
||||
|
||||
public CustomItemsPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder) {
|
||||
private ItemsFileManager itemsFileManager;
|
||||
|
||||
public CustomItemsPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) {
|
||||
super(bossPanelManager, panelBuilder);
|
||||
|
||||
this.itemsFileManager = plugin.getItemStackManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -26,11 +43,67 @@ public class CustomItemsPanel extends PanelHandler {
|
||||
|
||||
@Override
|
||||
public void fillPanel(Panel panel) {
|
||||
Map<String, ItemStackHolder> currentItemStacks = this.itemsFileManager.getItemStackHolders();
|
||||
List<String> entryList = new ArrayList<>(currentItemStacks.keySet());
|
||||
int maxPage = panel.getMaxPage(entryList);
|
||||
|
||||
panel.setOnPageChange(((player, currentPage, requestedPage) -> {
|
||||
if(requestedPage < 0 || requestedPage > maxPage) return false;
|
||||
|
||||
loadPage(panel, requestedPage, currentItemStacks, entryList);
|
||||
return true;
|
||||
}));
|
||||
|
||||
loadPage(panel, 0, currentItemStacks, entryList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openFor(Player player) {
|
||||
Panel panel = getPanelBuilder().getPanel()
|
||||
.setDestroyWhenDone(true)
|
||||
.setCancelClick(true)
|
||||
.setCancelLowerClick(true)
|
||||
.setParentPanel(this.bossPanelManager.getMainMenu().getPanel());
|
||||
|
||||
fillPanel(panel);
|
||||
|
||||
panel.openFor(player);
|
||||
}
|
||||
|
||||
private void loadPage(Panel panel, int requestedPage, Map<String, ItemStackHolder> currentItemStacks, List<String> entryList) {
|
||||
panel.loadPage(requestedPage, (slot, realisticSlot) -> {
|
||||
if(slot >= currentItemStacks.size()) {
|
||||
panel.setItem(realisticSlot, new ItemStack(Material.AIR), e -> {});
|
||||
} else {
|
||||
String name = entryList.get(slot);
|
||||
ItemStackHolder itemStackHolder = currentItemStacks.get(name);
|
||||
ItemStack itemStack = this.itemsFileManager.getItemStackConverter().from(itemStackHolder);
|
||||
ItemStack cloneStack = itemStack.clone();
|
||||
|
||||
panel.setItem(realisticSlot, itemStack, e -> {
|
||||
if(e.getClick() == ClickType.RIGHT || e.getClick() == ClickType.SHIFT_RIGHT) {
|
||||
int timesUsed = this.bossPanelManager.isItemStackUsed(name);
|
||||
|
||||
if(timesUsed > 0) {
|
||||
Message.Boss_Items_CannotBeRemoved.msg(e.getWhoClicked(), timesUsed);
|
||||
} else {
|
||||
this.itemsFileManager.removeItemStack(name);
|
||||
currentItemStacks.remove(name);
|
||||
entryList.remove(name);
|
||||
|
||||
loadPage(panel, requestedPage, currentItemStacks, entryList);
|
||||
Message.Boss_Items_Removed.msg(e.getWhoClicked());
|
||||
}
|
||||
} else if(e.getClick() == ClickType.LEFT || e.getClick() == ClickType.SHIFT_LEFT) {
|
||||
if(cloneStack == null) {
|
||||
Debug.FAILED_TO_GIVE_CUSTOM_ITEM.debug(e.getWhoClicked().getName());
|
||||
return;
|
||||
}
|
||||
|
||||
e.getWhoClicked().getInventory().addItem(cloneStack);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import com.songoda.epicbosses.utils.panel.base.ClickAction;
|
||||
import com.songoda.epicbosses.utils.panel.base.PanelHandler;
|
||||
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.event.inventory.ClickType;
|
||||
|
||||
@ -68,8 +69,7 @@ public class MainMenuPanel extends PanelHandler {
|
||||
if(event.getClick() == ClickType.LEFT || event.getClick() == ClickType.SHIFT_LEFT) {
|
||||
this.bossPanelManager.getCustomItems().openFor(player);
|
||||
} else if(event.getClick() == ClickType.RIGHT || event.getClick() == ClickType.SHIFT_RIGHT) {
|
||||
//TODO: Set up create item inventory
|
||||
player.closeInventory();
|
||||
this.bossPanelManager.getAddItemsMenu().openFor(player);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ public enum Debug {
|
||||
FAILED_TO_GIVE_SPAWN_EGG("{0} tried to obtain a spawn egg for the boss {1} but it has not been set yet."),
|
||||
FAILED_TO_CONNECT_TO_VAULT("Something went wrong while trying to connect to Vault. Please make sure you have an Economy and Permission plugin connected to your Vault plugin such as Essentials and GroupManager."),
|
||||
FAILED_TO_OBTAIN_THE_SKILL_HANDLER("Something went wrong when trying to detect the skill handler for {0}."),
|
||||
FAILED_TO_GIVE_CUSTOM_ITEM("{0} tried to obtain a custom item from the Custom Items list but failed due to the item not being set properly."),
|
||||
|
||||
DROP_TABLE_FAILED_INVALID_NUMBER("The specified position ({0}) on the drop table is not a valid number."),
|
||||
DROP_TABLE_FAILED_TO_GET_ITEM("The drop table failed to get the specific item for the list."),
|
||||
|
@ -89,6 +89,10 @@ public enum Message {
|
||||
"&bComplete enough to spawn: &f{3}"),
|
||||
|
||||
Boss_Items_NoPermission("&c&l(!) &cYou do not have access to this command."),
|
||||
Boss_Items_CannotBeRemoved("&c&l(!) &cThe selected item cannot be removed because it is still used in {0} different positions on the bosses."),
|
||||
Boss_Items_Removed("&b&lEpicBosses &8» &7The selected item has been removed from the EpicBosses custom items database."),
|
||||
Boss_Items_Added("&b&lEpicBosses &8» &7You have added an item to the EpicBosses custom items database."),
|
||||
Boss_Items_AlreadySet("&c&l(!) &cYou must take out the item you have set to add before you can add another."),
|
||||
|
||||
Boss_KillAll_WorldNotFound("&c&l(!) &cThe specified world was not found. If you'd like to kill every boss/minion just use &f/boss killall&c without any arguments."),
|
||||
Boss_KillAll_KilledAll("&b&lEpicBosses &8» &7You have killed {0} boss(es) and minions that were currently active on the server."),
|
||||
|
@ -53,14 +53,14 @@ public class ItemStackConverter implements IReplaceableConverter<ItemStackHolder
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
if(itemMeta.hasDisplayName()) {
|
||||
name = StringUtils.get().stripColor(itemMeta.getDisplayName());
|
||||
name = itemMeta.getDisplayName().replace('§', '&');
|
||||
}
|
||||
|
||||
if(itemMeta.hasLore()) {
|
||||
lore = new ArrayList<>();
|
||||
|
||||
for(String string : itemMeta.getLore()) {
|
||||
lore.add(StringUtils.get().stripColor(string));
|
||||
lore.add(string.replace('§', '&'));
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,14 +88,14 @@ public class ItemStackConverter implements IReplaceableConverter<ItemStackHolder
|
||||
}
|
||||
}
|
||||
|
||||
if(enchants == null) {
|
||||
ItemStack craftStack = NbtFactory.getCraftItemStack(itemStack);
|
||||
NbtFactory.NbtCompound compound = NbtFactory.fromItemTag(craftStack);
|
||||
// if(enchants == null) {
|
||||
// ItemStack craftStack = NbtFactory.getCraftItemStack(itemStack);
|
||||
// NbtFactory.NbtCompound compound = NbtFactory.fromItemTag(craftStack);
|
||||
//
|
||||
// if(compound.containsKey("ench")) isGlowing = true;
|
||||
// }
|
||||
|
||||
if(compound.containsKey("ench")) isGlowing = true;
|
||||
}
|
||||
|
||||
return new ItemStackHolder(amount, type, durability, name, lore, enchants, skullOwner, spawnerId, isGlowing);
|
||||
return new ItemStackHolder(amount, type, durability, name, lore, enchants, skullOwner, spawnerId, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -115,13 +115,14 @@ public class ItemStackConverter implements IReplaceableConverter<ItemStackHolder
|
||||
|
||||
itemStack.setType(material);
|
||||
|
||||
Integer amount = itemStackHolder.getAmount();
|
||||
Short durability = itemStackHolder.getDurability(), spawnerId = itemStackHolder.getSpawnerId();
|
||||
String name = itemStackHolder.getName(), skullOwner = itemStackHolder.getSkullOwner();
|
||||
List<String> lore = itemStackHolder.getLore(), enchants = itemStackHolder.getEnchants();
|
||||
Boolean isGlowing = itemStackHolder.getIsGlowing();
|
||||
|
||||
if(durability != null) itemStack.setDurability(durability);
|
||||
if(enchants != null) itemStack.addEnchantments(this.enchantConverter.from(enchants));
|
||||
if(enchants != null) itemStack.addUnsafeEnchantments(this.enchantConverter.from(enchants));
|
||||
|
||||
if(name != null || skullOwner != null || lore != null || spawnerId != null) {
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
@ -176,6 +177,10 @@ public class ItemStackConverter implements IReplaceableConverter<ItemStackHolder
|
||||
return craftStack;
|
||||
}
|
||||
|
||||
if(amount != null && amount > 1) {
|
||||
itemStack.setAmount(amount);
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package com.songoda.epicbosses.utils.panel;
|
||||
|
||||
import com.songoda.epicbosses.utils.panel.base.IPageHandler;
|
||||
import com.songoda.epicbosses.utils.panel.builder.PanelBuilder;
|
||||
import com.songoda.epicbosses.utils.panel.builder.PanelBuilderCounter;
|
||||
import lombok.Getter;
|
||||
import com.songoda.epicbosses.utils.ICloneable;
|
||||
import com.songoda.epicbosses.utils.StringUtils;
|
||||
@ -55,11 +56,11 @@ public class Panel implements Listener, ICloneable<Panel> {
|
||||
private final List<ClickAction> allSlotActions = new ArrayList<>();
|
||||
|
||||
private final Map<UUID, Integer> currentPageContainer = new HashMap<>();
|
||||
private final Map<Integer, Integer> pageData = new HashMap<>();
|
||||
private final List<UUID> openedUsers = new ArrayList<>();
|
||||
|
||||
@Getter private boolean cancelClick = true, destroyWhenDone = true, cancelLowerClick = true;
|
||||
@Getter private PanelBuilderSettings panelBuilderSettings;
|
||||
@Getter private PanelBuilderCounter panelBuilderCounter;
|
||||
@Getter private Sound clickSound = null;
|
||||
@Getter private Inventory inventory;
|
||||
@Getter private int viewers = 0;
|
||||
@ -104,14 +105,13 @@ public class Panel implements Listener, ICloneable<Panel> {
|
||||
* Creates a Panel with the specified arguments
|
||||
*
|
||||
* @param inventory - Panel inventory
|
||||
* @param pageData - Panel page data
|
||||
*/
|
||||
public Panel(Inventory inventory, Map<Integer, Integer> pageData, PanelBuilderSettings panelBuilderSettings) {
|
||||
public Panel(Inventory inventory, PanelBuilderSettings panelBuilderSettings, PanelBuilderCounter panelBuilderCounter) {
|
||||
Bukkit.getPluginManager().registerEvents(this, PLUGIN);
|
||||
|
||||
this.inventory = inventory;
|
||||
this.pageData.putAll(pageData);
|
||||
this.panelBuilderSettings = panelBuilderSettings;
|
||||
this.panelBuilderCounter = panelBuilderCounter;
|
||||
|
||||
fillEmptySpace();
|
||||
|
||||
@ -132,7 +132,8 @@ public class Panel implements Listener, ICloneable<Panel> {
|
||||
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
|
||||
if((!isCancelClick()) && (event.getRawSlot() > inventory.getSize())) {
|
||||
if(isCancelLowerClick() && isLowerClick(event.getRawSlot())) {
|
||||
System.out.println("CANCELLED ");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -165,10 +166,10 @@ public class Panel implements Listener, ICloneable<Panel> {
|
||||
private void executeAction(int slot, InventoryClickEvent e) {
|
||||
Player clicker = (Player) e.getWhoClicked();
|
||||
|
||||
if(this.pageData.containsKey(slot)) {
|
||||
if(getPanelBuilderCounter().getPageData().containsKey(slot)) {
|
||||
int currentPage = this.currentPageContainer.getOrDefault(clicker.getUniqueId(), 0);
|
||||
|
||||
if(this.pageData.get(slot) > 0) {
|
||||
if(getPanelBuilderCounter().getPageData().get(slot) > 0) {
|
||||
if(this.onPageChange.onPageAction(clicker, currentPage, currentPage+1)) {
|
||||
this.currentPageContainer.put(clicker.getUniqueId(), currentPage+1);
|
||||
}
|
||||
@ -348,6 +349,9 @@ public class Panel implements Listener, ICloneable<Panel> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isLowerClick(int rawSlot) {
|
||||
return rawSlot > inventory.getSize();
|
||||
}
|
||||
|
||||
public void loadPage(int page, IPageHandler pageHandler) {
|
||||
int fillTo = getPanelBuilderSettings().getFillTo();
|
||||
@ -418,7 +422,6 @@ public class Panel implements Listener, ICloneable<Panel> {
|
||||
this.currentPageContainer.clear();
|
||||
this.targettedSlotActions.clear();
|
||||
this.allSlotActions.clear();
|
||||
this.pageData.clear();
|
||||
this.inventory = null;
|
||||
|
||||
this.openedUsers.forEach(uuid -> {
|
||||
@ -451,6 +454,8 @@ public class Panel implements Listener, ICloneable<Panel> {
|
||||
for(int i = 0; i < getInventory().getSize(); i++) {
|
||||
ItemStack itemAtSlot = getInventory().getItem(i);
|
||||
|
||||
if(getPanelBuilderCounter().isButtonAtSlot(i)) continue;
|
||||
|
||||
if(itemAtSlot == null || itemAtSlot.getType() == Material.AIR) {
|
||||
getInventory().setItem(i, itemStack);
|
||||
}
|
||||
@ -486,6 +491,7 @@ public class Panel implements Listener, ICloneable<Panel> {
|
||||
panel.destroyWhenDone = this.destroyWhenDone;
|
||||
panel.cancelLowerClick = this.cancelLowerClick;
|
||||
panel.panelBuilderSettings = this.panelBuilderSettings;
|
||||
panel.panelBuilderCounter = this.panelBuilderCounter;
|
||||
panel.clickSound = this.clickSound;
|
||||
panel.onPageChange = this.onPageChange;
|
||||
panel.panelClose = this.panelClose;
|
||||
|
@ -57,7 +57,7 @@ public class PanelBuilder {
|
||||
public Panel getPanel() {
|
||||
build();
|
||||
|
||||
Panel panel = new Panel(this.inventory, this.panelBuilderCounter.getPageData(), this.panelBuilderSettings);
|
||||
Panel panel = new Panel(this.inventory, this.panelBuilderSettings, this.panelBuilderCounter);
|
||||
|
||||
Map<String, ItemStack> itemStackMap = this.panelBuilderCounter.getItemStacks();
|
||||
Map<String, ClickAction> clickActionMap = this.panelBuilderCounter.getClickActions();
|
||||
|
@ -23,6 +23,18 @@ public class PanelBuilderCounter {
|
||||
@Getter private final Map<String, ItemStack> itemStacks = new HashMap<>();
|
||||
@Getter private final Map<Integer, Integer> pageData = new HashMap<>();
|
||||
|
||||
public boolean isButtonAtSlot(int slot) {
|
||||
for (Set<Integer> integers : this.slotsWithCounter.values()) {
|
||||
if(integers.contains(slot)) return true;
|
||||
}
|
||||
|
||||
for(Map<Integer, Object> map : this.specialValuesCounter.values()) {
|
||||
if(map.containsKey(slot)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public PanelBuilderCounter addSpecialCounter(String identifier) {
|
||||
this.specialValuesCounter.put(identifier, new HashMap<>());
|
||||
|
||||
|
2
pom.xml
2
pom.xml
@ -19,7 +19,7 @@
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<plugin.version>1.0.0-SNAPSHOT-U60</plugin.version>
|
||||
<plugin.version>1.0.0-SNAPSHOT-U61</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