fixed an issue with citizens

This commit is contained in:
Indyuce 2021-10-29 16:26:38 +02:00
parent 3e90285fdd
commit d555fe71b4
6 changed files with 272 additions and 286 deletions

View File

@ -1,44 +1,50 @@
package net.Indyuce.mmoitems.api.event;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
public class ItemBuildEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
public class ItemBuildEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private ItemStack itemStack;
private boolean cancelled;
private ItemStack itemStack;
public ItemBuildEvent(ItemStack itemStack) {
this.itemStack = itemStack;
}
public ItemBuildEvent(ItemStack itemStack) {
this.itemStack = itemStack;
}
public ItemStack getItemStack() {
return itemStack;
}
public ItemStack getItemStack() {
return itemStack;
}
public HandlerList getHandlers() {
return handlers;
}
public ItemBuildEvent setItemStack(ItemStack itemStack) {
this.itemStack = itemStack;
return this;
}
public static HandlerList getHandlerList() {
return handlers;
}
/**
* @deprecated See {@link #setCancelled(boolean)}
*/
@Deprecated
public boolean isCancelled() {
return itemStack == null;
}
public ItemBuildEvent setItemStack(ItemStack itemStack) {
this.itemStack = itemStack;
return this;
}
/**
* @deprecated Set the generated item stack to null instead. Cancelling
* the build event does not cancel the process that generated the item
*/
@Deprecated
public void setCancelled(boolean cancel) {
if (cancel)
itemStack = null;
}
@Override
public boolean isCancelled() {
return cancelled;
}
public HandlerList getHandlers() {
return handlers;
}
@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -5,7 +5,6 @@ import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.util.LegacyComponent;
import io.lumine.mythic.lib.api.util.ui.FriendlyFeedbackProvider;
import io.lumine.mythicenchants.enchants.MythicEnchant;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type;
@ -15,7 +14,6 @@ import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
import net.Indyuce.mmoitems.api.util.message.FFPMMOItems;
import net.Indyuce.mmoitems.stat.DisplayName;
import net.Indyuce.mmoitems.stat.Enchants;
import net.Indyuce.mmoitems.stat.data.EnchantListData;
import net.Indyuce.mmoitems.stat.data.MaterialData;
import net.Indyuce.mmoitems.stat.data.StringListData;
import net.Indyuce.mmoitems.stat.type.ItemStat;
@ -26,7 +24,6 @@ import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.attribute.AttributeModifier.Operation;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -99,10 +96,10 @@ public class ItemStackBuilder {
/**
* @return Does NOT return the built item stack. It returns only returns the
* default item stack with material applied. Built item stack is given
* by build(). This method should only be used to check if the item is
* of a specific material (like the Shield Pattern stat which checks if
* the item is a shield)
* default item stack with material applied. Built item stack is given
* by build(). This method should only be used to check if the item is
* of a specific material (like the Shield Pattern stat which checks if
* the item is a shield)
*/
public ItemStack getItemStack() {
return item;
@ -261,19 +258,18 @@ public class ItemStackBuilder {
*/
@Nullable
public ItemStack build() {
ItemBuildEvent itemBuildEvent = new ItemBuildEvent(buildNBT().toItem());
Bukkit.getServer().getPluginManager().callEvent(itemBuildEvent);
if (itemBuildEvent.isCancelled()) {
return null;
}
return itemBuildEvent.getItemStack();
ItemBuildEvent event = new ItemBuildEvent(buildNBT().toItem());
Bukkit.getServer().getPluginManager().callEvent(event);
return event.getItemStack();
}
public ItemStack displayBuild() {
/**
* Builds the item without calling a build event
*/
public ItemStack buildSilently() {
return buildNBT().toItem();
}
/**
* @return Builds the item
*/

View File

@ -483,25 +483,30 @@ public class PlayerData {
return get(player.getUniqueId());
}
/**
* See {@link #has(UUID)}
*
* @return If player data is loaded for a player
*/
public static boolean has(Player player) {
return has(player.getUniqueId());
}
/**
* Used to check if the UUID is associated to a real player
* or a Citizens/Sentinel NPC. Citizens NPCs do not have
* a player data associated to them so it's an easy O(1) way
* to check instead of checking for an entity metadta.
*
* @return If player data is loaded for a player UUID
*/
public static boolean has(UUID uuid) {
return data.containsKey(uuid);
}
@NotNull
public static PlayerData get(@NotNull UUID uuid) {
// Already loaded? lets gooo
PlayerData pd = data.get(uuid);
// Attempt to load now
if (pd == null) {
load(uuid);
pd = data.get(uuid);
}
// Um shit
if (pd == null) {
MMOItems.print(Level.SEVERE, "Incomplete initialization of PlayerData. This error is only a result of another one caused EARLIER (probably during server startup).", null);
}
//noinspection ConstantConditions
return pd;
return Objects.requireNonNull(data.get(uuid), "Player data not loaded");
}
/**

View File

@ -4,7 +4,6 @@ import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.util.AltChar;
import io.lumine.mythic.lib.api.util.LegacyComponent;
import io.lumine.mythic.lib.version.VersionMaterial;
import io.lumine.mythic.utils.adventure.text.Component;
import net.Indyuce.mmoitems.MMOItems;
@ -24,265 +23,245 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
public class ItemBrowser extends PluginInventory {
private final Map<String, ItemStack> cached = new LinkedHashMap<>();
private final Map<String, ItemStack> cached = new LinkedHashMap<>();
private final Type type;
private boolean deleteMode;
private final Type type;
private boolean deleteMode;
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[] slotsAlt = { 10, 11, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34, 37, 38, 39, 40, 41, 42, 43 };
private static final int[] slotsAlt = { 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34 };
// Slots used to display items based on the item type explored
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[] slotsAlt = {1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34};
public ItemBrowser(Player player) {
this(player, null);
}
public ItemBrowser(Player player) {
this(player, null);
}
public ItemBrowser(Player player, Type type) {
super(player);
public ItemBrowser(Player player, Type type) {
super(player);
this.type = type;
}
int[] getUsedSlots(@Nullable Type forType) { return forType == null ? slots : forType.isFourGUIMode() ? slotsAlt : slots; }
this.type = type;
}
@Override
public Inventory getInventory() {
int[] usedSlots = getUsedSlots(type);
int min = (page - 1) * usedSlots.length;
int max = page * usedSlots.length;
int n = 0;
/*
* displays all possible item types if no type was previously selected
* by the player
*/
if (type == null) {
Inventory inv = Bukkit.createInventory(this, 54, "Item Explorer");
List<Type> types = new ArrayList<>(MMOItems.plugin.getTypes().getAll());
for (int j = min; j < Math.min(max, types.size()); j++) {
Type type = types.get(j);
int items = MMOItems.plugin.getTemplates().getTemplates(type).size();
@Override
public Inventory getInventory() {
int[] usedSlots = type != null && type.isFourGUIMode() ? slotsAlt : slots;
int min = (page - 1) * usedSlots.length;
int max = page * usedSlots.length;
int n = 0;
ItemStack item = type.getItem();
item.setAmount(Math.max(1, Math.min(64, items)));
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(ChatColor.GREEN + type.getName() + ChatColor.DARK_GRAY + " (Click to browse)");
meta.addItemFlags(ItemFlag.values());
List<String> lore = new ArrayList<>();
lore.add(ChatColor.GRAY + "" + ChatColor.ITALIC + "There " + (items != 1 ? "are" : "is") + " "
+ (items < 1 ? "" + ChatColor.RED + ChatColor.ITALIC + "no" : "" + ChatColor.GOLD + ChatColor.ITALIC + items) + ChatColor.GRAY
+ ChatColor.ITALIC + " item" + (items != 1 ? "s" : "") + " in that type.");
meta.setLore(lore);
item.setItemMeta(meta);
/*
* Displays all possible item types if no
* type was previously selected by the player
*/
if (type == null) {
Inventory inv = Bukkit.createInventory(this, 54, "Item Explorer");
List<Type> types = new ArrayList<>(MMOItems.plugin.getTypes().getAll());
for (int j = min; j < Math.min(max, types.size()); j++) {
Type type = types.get(j);
int items = MMOItems.plugin.getTemplates().getTemplates(type).size();
inv.setItem(slots[n++], NBTItem.get(item).addTag(new ItemTag("typeId", type.getId())).toItem());
}
ItemStack item = type.getItem();
item.setAmount(Math.max(1, Math.min(64, items)));
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(ChatColor.GREEN + type.getName() + ChatColor.DARK_GRAY + " (Click to browse)");
meta.addItemFlags(ItemFlag.values());
List<String> lore = new ArrayList<>();
lore.add(ChatColor.GRAY + "" + ChatColor.ITALIC + "There " + (items != 1 ? "are" : "is") + " "
+ (items < 1 ? "" + ChatColor.RED + ChatColor.ITALIC + "no" : "" + ChatColor.GOLD + ChatColor.ITALIC + items) + ChatColor.GRAY
+ ChatColor.ITALIC + " item" + (items != 1 ? "s" : "") + " in that type.");
meta.setLore(lore);
item.setItemMeta(meta);
ItemStack glass = VersionMaterial.GRAY_STAINED_GLASS_PANE.toItem();
ItemMeta glassMeta = glass.getItemMeta();
glassMeta.setDisplayName(ChatColor.RED + "- No type -");
glass.setItemMeta(glassMeta);
inv.setItem(slots[n++], NBTItem.get(item).addTag(new ItemTag("typeId", type.getId())).toItem());
}
ItemStack next = new ItemStack(Material.ARROW);
ItemMeta nextMeta = next.getItemMeta();
nextMeta.setDisplayName(ChatColor.GREEN + "Next Page");
next.setItemMeta(nextMeta);
ItemStack glass = VersionMaterial.GRAY_STAINED_GLASS_PANE.toItem();
ItemMeta glassMeta = glass.getItemMeta();
glassMeta.setDisplayName(ChatColor.RED + "- No type -");
glass.setItemMeta(glassMeta);
ItemStack previous = new ItemStack(Material.ARROW);
ItemMeta previousMeta = previous.getItemMeta();
previousMeta.setDisplayName(ChatColor.GREEN + "Previous Page");
previous.setItemMeta(previousMeta);
ItemStack next = new ItemStack(Material.ARROW);
ItemMeta nextMeta = next.getItemMeta();
nextMeta.setDisplayName(ChatColor.GREEN + "Next Page");
next.setItemMeta(nextMeta);
while (n < slots.length)
inv.setItem(slots[n++], glass);
inv.setItem(18, page > 1 ? previous : null);
inv.setItem(26, max >= MMOItems.plugin.getTypes().getAll().size() ? null : next);
ItemStack previous = new ItemStack(Material.ARROW);
ItemMeta previousMeta = previous.getItemMeta();
previousMeta.setDisplayName(ChatColor.GREEN + "Previous Page");
previous.setItemMeta(previousMeta);
return inv;
}
while (n < slots.length)
inv.setItem(slots[n++], glass);
inv.setItem(18, page > 1 ? previous : null);
inv.setItem(26, max >= MMOItems.plugin.getTypes().getAll().size() ? null : next);
ItemStack error = VersionMaterial.RED_STAINED_GLASS_PANE.toItem();
ItemMeta errorMeta = error.getItemMeta();
errorMeta.setDisplayName(ChatColor.RED + "- Error -");
List<String> errorLore = new ArrayList<>();
errorLore.add(ChatColor.GRAY + "" + ChatColor.ITALIC + "An error occurred while");
errorLore.add(ChatColor.GRAY + "" + ChatColor.ITALIC + "trying to generate that item.");
errorMeta.setLore(errorLore);
error.setItemMeta(errorMeta);
return inv;
}
List<MMOItemTemplate> templates = new ArrayList<>(MMOItems.plugin.getTemplates().getTemplates(type));
ItemStack error = VersionMaterial.RED_STAINED_GLASS_PANE.toItem();
ItemMeta errorMeta = error.getItemMeta();
errorMeta.setDisplayName(ChatColor.RED + "- Error -");
List<String> errorLore = new ArrayList<>();
errorLore.add(ChatColor.GRAY + "" + ChatColor.ITALIC + "An error occurred while");
errorLore.add(ChatColor.GRAY + "" + ChatColor.ITALIC + "trying to generate that item.");
errorMeta.setLore(errorLore);
error.setItemMeta(errorMeta);
/*
* displays every item in a specific type. items are cached inside the
* map at the top to reduce performance impact and are directly rendered
*/
Inventory inv = Bukkit.createInventory(this, 54, (deleteMode ? ("Delete Mode: ") : ("Item Explorer: ")) + type.getName());
for (int j = min; j < Math.min(max, templates.size()); j++) {
MMOItemTemplate template = templates.get(j);
ItemStack item = template.newBuilder(playerData.getRPG()).build().newBuilder().build();
if (item == null || item.getType() == Material.AIR) {
cached.put(template.getId(), error);
inv.setItem(usedSlots[n++], error);
continue;
}
NBTItem nbtItem = NBTItem.get(item);
List<Component> lore = nbtItem.getLoreComponents();
List<MMOItemTemplate> templates = new ArrayList<>(MMOItems.plugin.getTemplates().getTemplates(type));
lore.add(Component.empty());
if (deleteMode) {
lore.add(LegacyComponent.parse(
ChatColor.RED + AltChar.cross + " CLICK TO DELETE " + AltChar.cross));
nbtItem.setDisplayNameComponent(Component.text()
.append(LegacyComponent.parse(ChatColor.RED + "DELETE: "))
.append(nbtItem.getDisplayNameComponent())
.build());
}
/*
* Displays every item in a specific type. Items are cached inside the
* map at the top to reduce performance impact and are directly rendered
*/
Inventory inv = Bukkit.createInventory(this, 54, (deleteMode ? ("Delete Mode: ") : ("Item Explorer: ")) + type.getName());
for (int j = min; j < Math.min(max, templates.size()); j++) {
MMOItemTemplate template = templates.get(j);
ItemStack item = template.newBuilder(playerData.getRPG()).build().newBuilder().build();
if (item == null || item.getType() == Material.AIR) {
cached.put(template.getId(), error);
inv.setItem(usedSlots[n++], error);
continue;
}
lore.add(LegacyComponent.parse(ChatColor.YELLOW + AltChar.smallListDash + " Left click to obtain this item."));
lore.add(LegacyComponent.parse(ChatColor.YELLOW + AltChar.smallListDash + " Right click to edit this item."));
ItemMeta meta = item.getItemMeta();
List<String> lore = meta.getLore();
lore.add("");
nbtItem.setLoreComponents(lore);
if (deleteMode) {
lore.add(ChatColor.RED + AltChar.cross + " CLICK TO DELETE " + AltChar.cross);
meta.setDisplayName(ChatColor.RED + "DELETE: " + (meta.hasDisplayName() ? meta.getDisplayName() : MMOUtils.getDisplayName(item)));
} 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.");
}
cached.put(template.getId(), nbtItem.toItem());
item.setItemMeta(meta);
cached.put(template.getId(), item);
inv.setItem(usedSlots[n++], cached.get(template.getId()));
}
inv.setItem(usedSlots[n++], cached.get(template.getId()));
}
ItemStack noItem = VersionMaterial.GRAY_STAINED_GLASS_PANE.toItem();
ItemMeta noItemMeta = noItem.getItemMeta();
noItemMeta.setDisplayName(ChatColor.RED + "- No Item -");
noItem.setItemMeta(noItemMeta);
ItemStack noItem = VersionMaterial.GRAY_STAINED_GLASS_PANE.toItem();
ItemMeta noItemMeta = noItem.getItemMeta();
noItemMeta.setDisplayName(ChatColor.RED + "- No Item -");
noItem.setItemMeta(noItemMeta);
ItemStack next = new ItemStack(Material.ARROW);
ItemMeta nextMeta = next.getItemMeta();
nextMeta.setDisplayName(ChatColor.GREEN + "Next Page");
next.setItemMeta(nextMeta);
ItemStack next = new ItemStack(Material.ARROW);
ItemMeta nextMeta = next.getItemMeta();
nextMeta.setDisplayName(ChatColor.GREEN + "Next Page");
next.setItemMeta(nextMeta);
ItemStack back = new ItemStack(Material.ARROW);
ItemMeta backMeta = back.getItemMeta();
backMeta.setDisplayName(ChatColor.GREEN + AltChar.rightArrow + " Back");
back.setItemMeta(backMeta);
ItemStack back = new ItemStack(Material.ARROW);
ItemMeta backMeta = back.getItemMeta();
backMeta.setDisplayName(ChatColor.GREEN + AltChar.rightArrow + " Back");
back.setItemMeta(backMeta);
ItemStack create = new ItemStack(VersionMaterial.WRITABLE_BOOK.toMaterial());
ItemMeta createMeta = create.getItemMeta();
createMeta.setDisplayName(ChatColor.GREEN + "Create New");
create.setItemMeta(createMeta);
ItemStack create = new ItemStack(VersionMaterial.WRITABLE_BOOK.toMaterial());
ItemMeta createMeta = create.getItemMeta();
createMeta.setDisplayName(ChatColor.GREEN + "Create New");
create.setItemMeta(createMeta);
ItemStack delete = new ItemStack(VersionMaterial.CAULDRON.toMaterial());
ItemMeta deleteMeta = delete.getItemMeta();
deleteMeta.setDisplayName(ChatColor.RED + (deleteMode ? "Cancel Deletion" : "Delete Item"));
delete.setItemMeta(deleteMeta);
ItemStack delete = new ItemStack(VersionMaterial.CAULDRON.toMaterial());
ItemMeta deleteMeta = delete.getItemMeta();
deleteMeta.setDisplayName(ChatColor.RED + (deleteMode ? "Cancel Deletion" : "Delete Item"));
delete.setItemMeta(deleteMeta);
ItemStack previous = new ItemStack(Material.ARROW);
ItemMeta previousMeta = previous.getItemMeta();
previousMeta.setDisplayName(ChatColor.GREEN + "Previous Page");
previous.setItemMeta(previousMeta);
ItemStack previous = new ItemStack(Material.ARROW);
ItemMeta previousMeta = previous.getItemMeta();
previousMeta.setDisplayName(ChatColor.GREEN + "Previous Page");
previous.setItemMeta(previousMeta);
if (type == Type.BLOCK) {
ItemStack downloadPack = new ItemStack(Material.HOPPER);
ItemMeta downloadMeta = downloadPack.getItemMeta();
downloadMeta.setDisplayName(ChatColor.GREEN + "Download Default Resourcepack");
downloadMeta.setLore(Arrays.asList(ChatColor.LIGHT_PURPLE + "Only seeing stone blocks?", "",
ChatColor.RED + "By downloading the default resourcepack you can", ChatColor.RED + "edit the blocks however you want.",
ChatColor.RED + "You will still have to add it to your server!"));
downloadPack.setItemMeta(downloadMeta);
inv.setItem(45, downloadPack);
}
if (type == Type.BLOCK) {
ItemStack downloadPack = new ItemStack(Material.HOPPER);
ItemMeta downloadMeta = downloadPack.getItemMeta();
downloadMeta.setDisplayName(ChatColor.GREEN + "Download Default Resourcepack");
downloadMeta.setLore(Arrays.asList(ChatColor.LIGHT_PURPLE + "Only seeing stone blocks?", "",
ChatColor.RED + "By downloading the default resourcepack you can", ChatColor.RED + "edit the blocks however you want.",
ChatColor.RED + "You will still have to add it to your server!"));
downloadPack.setItemMeta(downloadMeta);
inv.setItem(45, downloadPack);
}
while (n < usedSlots.length)
inv.setItem(usedSlots[n++], noItem);
if (!deleteMode)
inv.setItem(51, create);
inv.setItem(47, delete);
inv.setItem(49, back);
inv.setItem(18, page > 1 ? previous : null);
inv.setItem(26, max >= templates.size() ? null : next);
return inv;
}
while (n < usedSlots.length)
inv.setItem(usedSlots[n++], noItem);
if (!deleteMode)
inv.setItem(51, create);
inv.setItem(47, delete);
inv.setItem(49, back);
inv.setItem(18, page > 1 ? previous : null);
inv.setItem(26, max >= templates.size() ? null : next);
return inv;
}
public Type getType() {
return type;
}
public Type getType() {
return type;
}
@Override
public void whenClicked(InventoryClickEvent event) {
event.setCancelled(true);
if (event.getInventory() != event.getClickedInventory())
return;
@Override
public void whenClicked(InventoryClickEvent event) {
event.setCancelled(true);
if (event.getInventory() != event.getClickedInventory())
return;
ItemStack item = event.getCurrentItem();
if (MMOUtils.isMetaItem(item, false)) {
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Next Page")) {
page++;
open();
}
ItemStack item = event.getCurrentItem();
if (MMOUtils.isMetaItem(item, false)) {
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Next Page")) {
page++;
open();
} else if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Previous Page")) {
page--;
open();
} else if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + AltChar.rightArrow + " Back"))
new ItemBrowser(getPlayer()).open();
else if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Previous Page")) {
page--;
open();
}
else if (item.getItemMeta().getDisplayName().equals(ChatColor.RED + "Cancel Deletion")) {
deleteMode = false;
open();
} else if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Create New"))
new NewItemEdition(this).enable("Write in the chat the text you want.");
else if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + AltChar.rightArrow + " Back"))
new ItemBrowser(getPlayer()).open();
else if (type != null && item.getItemMeta().getDisplayName().equals(ChatColor.RED + "Delete Item")) {
deleteMode = true;
open();
} else if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Download Default Resourcepack")) {
MythicLib.plugin.getVersion().getWrapper().sendJson(getPlayer(),
"[{\"text\":\"Click to download!\",\"color\":\"green\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://drive.google.com/uc?id=1FjV7y-2cn8qzSiktZ2CUXmkdjepXdj5N\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":[\"\",{\"text\":\"https://drive.google.com/uc?id=1FjV7y-2cn8qzSiktZ2CUXmkdjepXdj5N\",\"italic\":true,\"color\":\"white\"}]}}]");
getPlayer().closeInventory();
} else if (type == null && !item.getItemMeta().getDisplayName().equals(ChatColor.RED + "- No type -"))
new ItemBrowser(getPlayer(), MMOItems.plugin.getTypes().get(NBTItem.get(item).getString("typeId"))).open();
}
else if (item.getItemMeta().getDisplayName().equals(ChatColor.RED + "Cancel Deletion")) {
deleteMode = false;
open();
}
String id = NBTItem.get(item).getString("MMOITEMS_ITEM_ID");
if (id.equals(""))
return;
else if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Create New"))
new NewItemEdition(this).enable("Write in the chat the text you want.");
if (deleteMode) {
MMOItems.plugin.getTemplates().deleteTemplate(type, id);
deleteMode = false;
open();
else if (type != null && item.getItemMeta().getDisplayName().equals(ChatColor.RED + "Delete Item")) {
deleteMode = true;
open();
}
} else {
if (event.getAction() == InventoryAction.PICKUP_ALL) {
// this refreshes the item if it's unstackable
ItemStack generatedItem = (NBTItem.get(item).getBoolean("UNSTACKABLE")) ? MMOItems.plugin.getItem(type, id, playerData)
: removeLastLoreLines(NBTItem.get(item));
getPlayer().getInventory().addItem(generatedItem);
getPlayer().playSound(getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2);
}
else if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Download Default Resourcepack")) {
MythicLib.plugin.getVersion().getWrapper().sendJson(getPlayer(),
"[{\"text\":\"Click to download!\",\"color\":\"green\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://drive.google.com/uc?id=1FjV7y-2cn8qzSiktZ2CUXmkdjepXdj5N\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":[\"\",{\"text\":\"https://drive.google.com/uc?id=1FjV7y-2cn8qzSiktZ2CUXmkdjepXdj5N\",\"italic\":true,\"color\":\"white\"}]}}]");
getPlayer().closeInventory();
}
if (event.getAction() == InventoryAction.PICKUP_HALF)
new ItemEdition(getPlayer(), MMOItems.plugin.getTemplates().getTemplate(type, id)).open();
}
}
else if (type == null && !item.getItemMeta().getDisplayName().equals(ChatColor.RED + "- No type -"))
new ItemBrowser(getPlayer(), MMOItems.plugin.getTypes().get(NBTItem.get(item).getString("typeId"))).open();
}
String id = NBTItem.get(item).getString("MMOITEMS_ITEM_ID");
if (id.equals(""))
return;
if (deleteMode) {
MMOItems.plugin.getTemplates().deleteTemplate(type, id);
deleteMode = false;
open();
} else {
if (event.getAction() == InventoryAction.PICKUP_ALL) {
// this refreshes the item if it's unstackable
ItemStack generatedItem = (NBTItem.get(item).getBoolean("UNSTACKABLE")) ? MMOItems.plugin.getItem(type, id, playerData)
: removeLastLoreLines(NBTItem.get(item));
getPlayer().getInventory().addItem(generatedItem);
getPlayer().playSound(getPlayer().getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 2);
}
if (event.getAction() == InventoryAction.PICKUP_HALF)
new ItemEdition(getPlayer(), MMOItems.plugin.getTemplates().getTemplate(type, id)).open();
}
}
private ItemStack removeLastLoreLines(NBTItem item) {
List<Component> lore = item.getLoreComponents();
item.setLoreComponents(lore.subList(0, lore.size() - 3));
return item.toItem();
}
private ItemStack removeLastLoreLines(NBTItem item) {
List<Component> lore = item.getLoreComponents();
item.setLoreComponents(lore.subList(0, lore.size() - 3));
return item.toItem();
}
}

View File

@ -136,7 +136,7 @@ public abstract class EditionInventory extends PluginInventory {
* can reroll the stats.
*/
public void updateCachedItem() {
cachedItem = template.newBuilder(PlayerData.get(getPlayer()).getRPG()).build().newBuilder().displayBuild();
cachedItem = template.newBuilder(PlayerData.get(getPlayer()).getRPG()).build().newBuilder().buildSilently();
}
public ItemStack getCachedItem() {

View File

@ -13,7 +13,6 @@ import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.interaction.util.InteractItem;
import net.Indyuce.mmoitems.api.interaction.weapon.Weapon;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.player.RPGPlayer;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -136,11 +135,12 @@ public class PlayerListener implements Listener {
@EventHandler
public void onArmorEquip(ArmorEquipEvent event) {
Player p = event.getPlayer();
RPGPlayer rpgPlayer = PlayerData.get(p.getUniqueId()).getRPG();
NBTItem item = NBTItem.get(event.getNewArmorPiece());
Player player = event.getPlayer();
if (!PlayerData.has(player))
return;
if (!rpgPlayer.canUse(item, true))
NBTItem item = NBTItem.get(event.getNewArmorPiece());
if (!PlayerData.get(player).getRPG().canUse(item, true))
event.setCancelled(true);
}