mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-02-28 15:41:04 +01:00
fixed an issue with citizens
This commit is contained in:
parent
3e90285fdd
commit
d555fe71b4
@ -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;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
*/
|
*/
|
||||||
|
@ -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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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
|
|
||||||
public Inventory getInventory() {
|
|
||||||
int[] usedSlots = getUsedSlots(type);
|
|
||||||
int min = (page - 1) * usedSlots.length;
|
|
||||||
int max = page * usedSlots.length;
|
|
||||||
int n = 0;
|
|
||||||
|
|
||||||
/*
|
@Override
|
||||||
* displays all possible item types if no type was previously selected
|
public Inventory getInventory() {
|
||||||
* by the player
|
int[] usedSlots = type != null && type.isFourGUIMode() ? slotsAlt : slots;
|
||||||
*/
|
int min = (page - 1) * usedSlots.length;
|
||||||
if (type == null) {
|
int max = page * usedSlots.length;
|
||||||
Inventory inv = Bukkit.createInventory(this, 54, "Item Explorer");
|
int n = 0;
|
||||||
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();
|
|
||||||
|
|
||||||
ItemStack item = type.getItem();
|
/*
|
||||||
item.setAmount(Math.max(1, Math.min(64, items)));
|
* Displays all possible item types if no
|
||||||
ItemMeta meta = item.getItemMeta();
|
* type was previously selected by the player
|
||||||
meta.setDisplayName(ChatColor.GREEN + type.getName() + ChatColor.DARK_GRAY + " (Click to browse)");
|
*/
|
||||||
meta.addItemFlags(ItemFlag.values());
|
if (type == null) {
|
||||||
List<String> lore = new ArrayList<>();
|
Inventory inv = Bukkit.createInventory(this, 54, "Item Explorer");
|
||||||
lore.add(ChatColor.GRAY + "" + ChatColor.ITALIC + "There " + (items != 1 ? "are" : "is") + " "
|
List<Type> types = new ArrayList<>(MMOItems.plugin.getTypes().getAll());
|
||||||
+ (items < 1 ? "" + ChatColor.RED + ChatColor.ITALIC + "no" : "" + ChatColor.GOLD + ChatColor.ITALIC + items) + ChatColor.GRAY
|
for (int j = min; j < Math.min(max, types.size()); j++) {
|
||||||
+ ChatColor.ITALIC + " item" + (items != 1 ? "s" : "") + " in that type.");
|
Type type = types.get(j);
|
||||||
meta.setLore(lore);
|
int items = MMOItems.plugin.getTemplates().getTemplates(type).size();
|
||||||
item.setItemMeta(meta);
|
|
||||||
|
|
||||||
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();
|
inv.setItem(slots[n++], NBTItem.get(item).addTag(new ItemTag("typeId", type.getId())).toItem());
|
||||||
ItemMeta glassMeta = glass.getItemMeta();
|
}
|
||||||
glassMeta.setDisplayName(ChatColor.RED + "- No type -");
|
|
||||||
glass.setItemMeta(glassMeta);
|
|
||||||
|
|
||||||
ItemStack next = new ItemStack(Material.ARROW);
|
ItemStack glass = VersionMaterial.GRAY_STAINED_GLASS_PANE.toItem();
|
||||||
ItemMeta nextMeta = next.getItemMeta();
|
ItemMeta glassMeta = glass.getItemMeta();
|
||||||
nextMeta.setDisplayName(ChatColor.GREEN + "Next Page");
|
glassMeta.setDisplayName(ChatColor.RED + "- No type -");
|
||||||
next.setItemMeta(nextMeta);
|
glass.setItemMeta(glassMeta);
|
||||||
|
|
||||||
ItemStack previous = new ItemStack(Material.ARROW);
|
ItemStack next = new ItemStack(Material.ARROW);
|
||||||
ItemMeta previousMeta = previous.getItemMeta();
|
ItemMeta nextMeta = next.getItemMeta();
|
||||||
previousMeta.setDisplayName(ChatColor.GREEN + "Previous Page");
|
nextMeta.setDisplayName(ChatColor.GREEN + "Next Page");
|
||||||
previous.setItemMeta(previousMeta);
|
next.setItemMeta(nextMeta);
|
||||||
|
|
||||||
while (n < slots.length)
|
ItemStack previous = new ItemStack(Material.ARROW);
|
||||||
inv.setItem(slots[n++], glass);
|
ItemMeta previousMeta = previous.getItemMeta();
|
||||||
inv.setItem(18, page > 1 ? previous : null);
|
previousMeta.setDisplayName(ChatColor.GREEN + "Previous Page");
|
||||||
inv.setItem(26, max >= MMOItems.plugin.getTypes().getAll().size() ? null : next);
|
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();
|
return inv;
|
||||||
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);
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
/*
|
List<MMOItemTemplate> templates = new ArrayList<>(MMOItems.plugin.getTemplates().getTemplates(type));
|
||||||
* 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();
|
|
||||||
|
|
||||||
lore.add(Component.empty());
|
/*
|
||||||
if (deleteMode) {
|
* Displays every item in a specific type. Items are cached inside the
|
||||||
lore.add(LegacyComponent.parse(
|
* map at the top to reduce performance impact and are directly rendered
|
||||||
ChatColor.RED + AltChar.cross + " CLICK TO DELETE " + AltChar.cross));
|
*/
|
||||||
nbtItem.setDisplayNameComponent(Component.text()
|
Inventory inv = Bukkit.createInventory(this, 54, (deleteMode ? ("Delete Mode: ") : ("Item Explorer: ")) + type.getName());
|
||||||
.append(LegacyComponent.parse(ChatColor.RED + "DELETE: "))
|
for (int j = min; j < Math.min(max, templates.size()); j++) {
|
||||||
.append(nbtItem.getDisplayNameComponent())
|
MMOItemTemplate template = templates.get(j);
|
||||||
.build());
|
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."));
|
ItemMeta meta = item.getItemMeta();
|
||||||
lore.add(LegacyComponent.parse(ChatColor.YELLOW + AltChar.smallListDash + " Right click to edit this item."));
|
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();
|
ItemStack noItem = VersionMaterial.GRAY_STAINED_GLASS_PANE.toItem();
|
||||||
ItemMeta noItemMeta = noItem.getItemMeta();
|
ItemMeta noItemMeta = noItem.getItemMeta();
|
||||||
noItemMeta.setDisplayName(ChatColor.RED + "- No Item -");
|
noItemMeta.setDisplayName(ChatColor.RED + "- No Item -");
|
||||||
noItem.setItemMeta(noItemMeta);
|
noItem.setItemMeta(noItemMeta);
|
||||||
|
|
||||||
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 back = new ItemStack(Material.ARROW);
|
ItemStack back = new ItemStack(Material.ARROW);
|
||||||
ItemMeta backMeta = back.getItemMeta();
|
ItemMeta backMeta = back.getItemMeta();
|
||||||
backMeta.setDisplayName(ChatColor.GREEN + AltChar.rightArrow + " Back");
|
backMeta.setDisplayName(ChatColor.GREEN + AltChar.rightArrow + " Back");
|
||||||
back.setItemMeta(backMeta);
|
back.setItemMeta(backMeta);
|
||||||
|
|
||||||
ItemStack create = new ItemStack(VersionMaterial.WRITABLE_BOOK.toMaterial());
|
ItemStack create = new ItemStack(VersionMaterial.WRITABLE_BOOK.toMaterial());
|
||||||
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.CAULDRON.toMaterial());
|
ItemStack delete = new ItemStack(VersionMaterial.CAULDRON.toMaterial());
|
||||||
ItemMeta deleteMeta = delete.getItemMeta();
|
ItemMeta deleteMeta = delete.getItemMeta();
|
||||||
deleteMeta.setDisplayName(ChatColor.RED + (deleteMode ? "Cancel Deletion" : "Delete Item"));
|
deleteMeta.setDisplayName(ChatColor.RED + (deleteMode ? "Cancel Deletion" : "Delete Item"));
|
||||||
delete.setItemMeta(deleteMeta);
|
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");
|
||||||
previous.setItemMeta(previousMeta);
|
previous.setItemMeta(previousMeta);
|
||||||
|
|
||||||
if (type == Type.BLOCK) {
|
if (type == Type.BLOCK) {
|
||||||
ItemStack downloadPack = new ItemStack(Material.HOPPER);
|
ItemStack downloadPack = new ItemStack(Material.HOPPER);
|
||||||
ItemMeta downloadMeta = downloadPack.getItemMeta();
|
ItemMeta downloadMeta = downloadPack.getItemMeta();
|
||||||
downloadMeta.setDisplayName(ChatColor.GREEN + "Download Default Resourcepack");
|
downloadMeta.setDisplayName(ChatColor.GREEN + "Download Default Resourcepack");
|
||||||
downloadMeta.setLore(Arrays.asList(ChatColor.LIGHT_PURPLE + "Only seeing stone blocks?", "",
|
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 + "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!"));
|
ChatColor.RED + "You will still have to add it to your server!"));
|
||||||
downloadPack.setItemMeta(downloadMeta);
|
downloadPack.setItemMeta(downloadMeta);
|
||||||
inv.setItem(45, downloadPack);
|
inv.setItem(45, downloadPack);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (n < usedSlots.length)
|
while (n < usedSlots.length)
|
||||||
inv.setItem(usedSlots[n++], noItem);
|
inv.setItem(usedSlots[n++], noItem);
|
||||||
if (!deleteMode)
|
if (!deleteMode)
|
||||||
inv.setItem(51, create);
|
inv.setItem(51, create);
|
||||||
inv.setItem(47, delete);
|
inv.setItem(47, delete);
|
||||||
inv.setItem(49, back);
|
inv.setItem(49, back);
|
||||||
inv.setItem(18, page > 1 ? previous : null);
|
inv.setItem(18, page > 1 ? previous : null);
|
||||||
inv.setItem(26, max >= templates.size() ? null : next);
|
inv.setItem(26, max >= templates.size() ? null : next);
|
||||||
return inv;
|
return inv;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Type getType() {
|
public Type getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void whenClicked(InventoryClickEvent event) {
|
public void whenClicked(InventoryClickEvent event) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
if (event.getInventory() != event.getClickedInventory())
|
if (event.getInventory() != event.getClickedInventory())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ItemStack item = event.getCurrentItem();
|
ItemStack item = event.getCurrentItem();
|
||||||
if (MMOUtils.isMetaItem(item, false)) {
|
if (MMOUtils.isMetaItem(item, false)) {
|
||||||
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Next Page")) {
|
if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Next Page")) {
|
||||||
page++;
|
page++;
|
||||||
open();
|
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")) {
|
else if (item.getItemMeta().getDisplayName().equals(ChatColor.RED + "Cancel Deletion")) {
|
||||||
page--;
|
deleteMode = false;
|
||||||
open();
|
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"))
|
else if (type != null && item.getItemMeta().getDisplayName().equals(ChatColor.RED + "Delete Item")) {
|
||||||
new ItemBrowser(getPlayer()).open();
|
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")) {
|
String id = NBTItem.get(item).getString("MMOITEMS_ITEM_ID");
|
||||||
deleteMode = false;
|
if (id.equals(""))
|
||||||
open();
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
else if (item.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Create New"))
|
if (deleteMode) {
|
||||||
new NewItemEdition(this).enable("Write in the chat the text you want.");
|
MMOItems.plugin.getTemplates().deleteTemplate(type, id);
|
||||||
|
deleteMode = false;
|
||||||
|
open();
|
||||||
|
|
||||||
else if (type != null && item.getItemMeta().getDisplayName().equals(ChatColor.RED + "Delete Item")) {
|
} else {
|
||||||
deleteMode = true;
|
if (event.getAction() == InventoryAction.PICKUP_ALL) {
|
||||||
open();
|
// 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")) {
|
if (event.getAction() == InventoryAction.PICKUP_HALF)
|
||||||
MythicLib.plugin.getVersion().getWrapper().sendJson(getPlayer(),
|
new ItemEdition(getPlayer(), MMOItems.plugin.getTemplates().getTemplate(type, id)).open();
|
||||||
"[{\"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 -"))
|
private ItemStack removeLastLoreLines(NBTItem item) {
|
||||||
new ItemBrowser(getPlayer(), MMOItems.plugin.getTypes().get(NBTItem.get(item).getString("typeId"))).open();
|
List<Component> lore = item.getLoreComponents();
|
||||||
}
|
item.setLoreComponents(lore.subList(0, lore.size() - 3));
|
||||||
|
return item.toItem();
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -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() {
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user