mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2024-12-22 04:37:42 +01:00
Added delete mode to Item Browser
This commit is contained in:
parent
99040e0636
commit
4f5683c1b5
@ -29,6 +29,7 @@ import net.Indyuce.mmoitems.version.nms.ItemTag;
|
|||||||
|
|
||||||
public class ItemBrowser extends PluginInventory {
|
public class ItemBrowser extends PluginInventory {
|
||||||
private Type type;
|
private Type type;
|
||||||
|
private boolean deleteMode;
|
||||||
private Map<String, ItemStack> cached = new HashMap<>();
|
private Map<String, ItemStack> cached = new HashMap<>();
|
||||||
|
|
||||||
private static final int[] slots = { 10, 11, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34 };
|
private static final int[] slots = { 10, 11, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34 };
|
||||||
@ -111,7 +112,7 @@ public class ItemBrowser extends PluginInventory {
|
|||||||
* displays every item in a specific type. items are cached inside the
|
* displays every item in a specific type. items are cached inside the
|
||||||
* map at the top to reduce performance impact and are directly rendered
|
* map at the top to reduce performance impact and are directly rendered
|
||||||
*/
|
*/
|
||||||
Inventory inv = Bukkit.createInventory(this, 54, ChatColor.UNDERLINE + "Item Explorer: " + type.getName());
|
Inventory inv = Bukkit.createInventory(this, 54, (deleteMode ? (ChatColor.UNDERLINE + "DELETE MODE: ") : (ChatColor.UNDERLINE + "Item Explorer: ")) + type.getName());
|
||||||
for (int j = min; j < Math.min(max, itemIds.size()); j++) {
|
for (int j = min; j < Math.min(max, itemIds.size()); j++) {
|
||||||
String id = itemIds.get(j);
|
String id = itemIds.get(j);
|
||||||
if (!cached.containsKey(id)) {
|
if (!cached.containsKey(id)) {
|
||||||
@ -125,8 +126,16 @@ public class ItemBrowser extends PluginInventory {
|
|||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
|
List<String> lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
|
||||||
lore.add("");
|
lore.add("");
|
||||||
lore.add(ChatColor.YELLOW + AltChar.smallListDash + " Left click to obtain this item.");
|
if(deleteMode)
|
||||||
lore.add(ChatColor.YELLOW + AltChar.smallListDash + " Right click to edit this item.");
|
{
|
||||||
|
lore.add(ChatColor.RED + AltChar.cross + " CLICK TO DELETE " + AltChar.cross);
|
||||||
|
meta.setDisplayName(ChatColor.RED + "DELETE: " + meta.getDisplayName());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lore.add(ChatColor.YELLOW + AltChar.smallListDash + " Left click to obtain this item.");
|
||||||
|
lore.add(ChatColor.YELLOW + AltChar.smallListDash + " Right click to edit this item.");
|
||||||
|
}
|
||||||
meta.setLore(lore);
|
meta.setLore(lore);
|
||||||
item.setItemMeta(meta);
|
item.setItemMeta(meta);
|
||||||
|
|
||||||
@ -146,16 +155,21 @@ public class ItemBrowser extends PluginInventory {
|
|||||||
nextMeta.setDisplayName(ChatColor.GREEN + "Next Page");
|
nextMeta.setDisplayName(ChatColor.GREEN + "Next Page");
|
||||||
next.setItemMeta(nextMeta);
|
next.setItemMeta(nextMeta);
|
||||||
|
|
||||||
ItemStack back = new ItemStack(Material.ARROW);
|
ItemStack back = new ItemStack(deleteMode ? Material.BARRIER : Material.ARROW);
|
||||||
ItemMeta backMeta = back.getItemMeta();
|
ItemMeta backMeta = back.getItemMeta();
|
||||||
backMeta.setDisplayName(ChatColor.GREEN + AltChar.rightArrow + " Back");
|
backMeta.setDisplayName(deleteMode ? (ChatColor.RED + "Cancel") : (ChatColor.GREEN + AltChar.rightArrow + " Back"));
|
||||||
back.setItemMeta(backMeta);
|
back.setItemMeta(backMeta);
|
||||||
|
|
||||||
ItemStack create = new ItemStack(Material.GREEN_STAINED_GLASS_PANE);
|
ItemStack create = new ItemStack(VersionMaterial.GREEN_STAINED_GLASS_PANE.toItem());
|
||||||
ItemMeta createMeta = create.getItemMeta();
|
ItemMeta createMeta = create.getItemMeta();
|
||||||
createMeta.setDisplayName(ChatColor.GREEN + "Create New");
|
createMeta.setDisplayName(ChatColor.GREEN + "Create New");
|
||||||
create.setItemMeta(createMeta);
|
create.setItemMeta(createMeta);
|
||||||
|
|
||||||
|
ItemStack delete = new ItemStack(VersionMaterial.RED_STAINED_GLASS_PANE.toItem());
|
||||||
|
ItemMeta deleteMeta = delete.getItemMeta();
|
||||||
|
deleteMeta.setDisplayName(ChatColor.RED + "Delete Item");
|
||||||
|
delete.setItemMeta(deleteMeta);
|
||||||
|
|
||||||
ItemStack previous = new ItemStack(Material.ARROW);
|
ItemStack previous = new ItemStack(Material.ARROW);
|
||||||
ItemMeta previousMeta = previous.getItemMeta();
|
ItemMeta previousMeta = previous.getItemMeta();
|
||||||
previousMeta.setDisplayName(ChatColor.GREEN + "Previous Page");
|
previousMeta.setDisplayName(ChatColor.GREEN + "Previous Page");
|
||||||
@ -163,8 +177,12 @@ public class ItemBrowser extends PluginInventory {
|
|||||||
|
|
||||||
while (n < slots.length)
|
while (n < slots.length)
|
||||||
inv.setItem(slots[n++], noItem);
|
inv.setItem(slots[n++], noItem);
|
||||||
|
if(!deleteMode)
|
||||||
|
{
|
||||||
|
inv.setItem(47, delete);
|
||||||
|
inv.setItem(51, create);
|
||||||
|
}
|
||||||
inv.setItem(49, back);
|
inv.setItem(49, back);
|
||||||
inv.setItem(51, create);
|
|
||||||
inv.setItem(18, page > 1 ? previous : null);
|
inv.setItem(18, page > 1 ? previous : null);
|
||||||
inv.setItem(26, max >= itemIds.size() ? null : next);
|
inv.setItem(26, max >= itemIds.size() ? null : next);
|
||||||
return inv;
|
return inv;
|
||||||
@ -197,9 +215,20 @@ public class ItemBrowser extends PluginInventory {
|
|||||||
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + AltChar.rightArrow + " Back"))
|
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + AltChar.rightArrow + " Back"))
|
||||||
new ItemBrowser(player).open();
|
new ItemBrowser(player).open();
|
||||||
|
|
||||||
|
if (item.getItemMeta().getDisplayName().equals(ChatColor.RED + "Cancel"))
|
||||||
|
{
|
||||||
|
deleteMode = false;
|
||||||
|
open();
|
||||||
|
}
|
||||||
|
|
||||||
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Create New"))
|
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Create New"))
|
||||||
new NewItemEdition(this).enable("Write in the chat the text you want.");
|
new NewItemEdition(this).enable("Write in the chat the text you want.");
|
||||||
|
|
||||||
|
if (type != null && item.getItemMeta().getDisplayName().equals(ChatColor.RED + "Delete Item")) {
|
||||||
|
deleteMode = true;
|
||||||
|
open();
|
||||||
|
}
|
||||||
|
|
||||||
if (type == null && !item.getItemMeta().getDisplayName().equals(ChatColor.RED + "- No type -")) {
|
if (type == null && !item.getItemMeta().getDisplayName().equals(ChatColor.RED + "- No type -")) {
|
||||||
Type type = MMOItems.plugin.getTypes().get(NBTItem.get(item).getString("typeId"));
|
Type type = MMOItems.plugin.getTypes().get(NBTItem.get(item).getString("typeId"));
|
||||||
new ItemBrowser(player, type).open();
|
new ItemBrowser(player, type).open();
|
||||||
@ -210,13 +239,26 @@ public class ItemBrowser extends PluginInventory {
|
|||||||
if (id.equals(""))
|
if (id.equals(""))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (event.getAction() == InventoryAction.PICKUP_ALL) {
|
if (deleteMode) {
|
||||||
player.getInventory().addItem(removeLastLoreLines(item, 3));
|
Bukkit.getScheduler().runTask(MMOItems.plugin, () -> Bukkit.dispatchCommand(player, "mi delete " + type.getId() + " " + id));
|
||||||
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2);
|
deleteMode = false;
|
||||||
|
ItemStack newItem = new ItemStack(VersionMaterial.GRAY_STAINED_GLASS_PANE.toItem());
|
||||||
|
ItemMeta noItemMeta = newItem.getItemMeta();
|
||||||
|
noItemMeta.setDisplayName(ChatColor.RED + "- No Item -");
|
||||||
|
item.setType(newItem.getType());
|
||||||
|
item.setItemMeta(noItemMeta);
|
||||||
|
open();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (event.getAction() == InventoryAction.PICKUP_ALL) {
|
||||||
|
player.getInventory().addItem(removeLastLoreLines(item, 3));
|
||||||
|
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2);
|
||||||
|
}
|
||||||
|
|
||||||
if (event.getAction() == InventoryAction.PICKUP_HALF)
|
if (event.getAction() == InventoryAction.PICKUP_HALF)
|
||||||
new ItemEdition(player, type, id, removeLastLoreLines(item, 3)).open();
|
new ItemEdition(player, type, id, removeLastLoreLines(item, 3)).open();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemStack removeLastLoreLines(ItemStack item, int amount) {
|
private ItemStack removeLastLoreLines(ItemStack item, int amount) {
|
||||||
|
@ -23,6 +23,7 @@ public enum VersionMaterial {
|
|||||||
BONE_MEAL("BONE_MEAL", "INK_SACK", 18),
|
BONE_MEAL("BONE_MEAL", "INK_SACK", 18),
|
||||||
GRAY_STAINED_GLASS_PANE("GRAY_STAINED_GLASS_PANE", "STAINED_GLASS_PANE", 7),
|
GRAY_STAINED_GLASS_PANE("GRAY_STAINED_GLASS_PANE", "STAINED_GLASS_PANE", 7),
|
||||||
RED_STAINED_GLASS_PANE("RED_STAINED_GLASS_PANE", "STAINED_GLASS_PANE", 14),
|
RED_STAINED_GLASS_PANE("RED_STAINED_GLASS_PANE", "STAINED_GLASS_PANE", 14),
|
||||||
|
GREEN_STAINED_GLASS_PANE("GREEN_STAINED_GLASS_PANE", "STAINED_GLASS_PANE", 13),
|
||||||
LIME_STAINED_GLASS("LIME_STAINED_GLASS", "STAINED_GLASS", 5),
|
LIME_STAINED_GLASS("LIME_STAINED_GLASS", "STAINED_GLASS", 5),
|
||||||
PINK_STAINED_GLASS("PINK_STAINED_GLASS", "STAINED_GLASS", 6),
|
PINK_STAINED_GLASS("PINK_STAINED_GLASS", "STAINED_GLASS", 6),
|
||||||
PLAYER_HEAD("PLAYER_HEAD", "SKULL_ITEM", 3),
|
PLAYER_HEAD("PLAYER_HEAD", "SKULL_ITEM", 3),
|
||||||
|
Loading…
Reference in New Issue
Block a user