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

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

View File

@ -483,25 +483,30 @@ public class PlayerData {
return get(player.getUniqueId()); 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 @NotNull
public static PlayerData get(@NotNull UUID uuid) { public static PlayerData get(@NotNull UUID uuid) {
return Objects.requireNonNull(data.get(uuid), "Player data not loaded");
// 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;
} }
/** /**

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

View File

@ -136,7 +136,7 @@ public abstract class EditionInventory extends PluginInventory {
* can reroll the stats. * can reroll the stats.
*/ */
public void updateCachedItem() { 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() { 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.util.InteractItem;
import net.Indyuce.mmoitems.api.interaction.weapon.Weapon; import net.Indyuce.mmoitems.api.interaction.weapon.Weapon;
import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.player.RPGPlayer;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -136,11 +135,12 @@ public class PlayerListener implements Listener {
@EventHandler @EventHandler
public void onArmorEquip(ArmorEquipEvent event) { public void onArmorEquip(ArmorEquipEvent event) {
Player p = event.getPlayer(); Player player = event.getPlayer();
RPGPlayer rpgPlayer = PlayerData.get(p.getUniqueId()).getRPG(); if (!PlayerData.has(player))
NBTItem item = NBTItem.get(event.getNewArmorPiece()); return;
if (!rpgPlayer.canUse(item, true)) NBTItem item = NBTItem.get(event.getNewArmorPiece());
if (!PlayerData.get(player).getRPG().canUse(item, true))
event.setCancelled(true); event.setCancelled(true);
} }