Added support for HideEnchants
This commit is contained in:
@@ -140,13 +140,17 @@ public final class EnchantDisplay {
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack displayEnchantments(ItemStack item) {
|
||||
return displayEnchantments(item, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all enchantments in item lore
|
||||
* @param item The item to update
|
||||
* @return The item, updated
|
||||
*/
|
||||
public static ItemStack displayEnchantments(ItemStack item) {
|
||||
if(item == null || item.getItemMeta() == null || !EnchantmentTarget.ALL.getMaterials().contains(item.getType()) || item.getItemMeta().getPersistentDataContainer().has(KEY_SKIP, PersistentDataType.INTEGER))
|
||||
public static ItemStack displayEnchantments(ItemStack item, boolean hideEnchants) {
|
||||
if(item == null || item.getItemMeta() == null || !EnchantmentTarget.ALL.getMaterials().contains(item.getType()))
|
||||
return item;
|
||||
|
||||
item = revertDisplay(item);
|
||||
@@ -155,6 +159,14 @@ public final class EnchantDisplay {
|
||||
if(meta == null) return item;
|
||||
List<String> itemLore = new ArrayList<>();
|
||||
|
||||
if(hideEnchants || meta.getPersistentDataContainer().has(KEY_SKIP, PersistentDataType.INTEGER)) {
|
||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
|
||||
meta.getPersistentDataContainer().set(KEY_SKIP, PersistentDataType.INTEGER, 1);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
if(meta.hasLore())
|
||||
itemLore = meta.getLore();
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@ import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.willfp.ecoenchants.display.AbstractPacketAdapter;
|
||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||
import com.willfp.ecoenchants.util.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
|
||||
public final class PacketSetSlot extends AbstractPacketAdapter {
|
||||
public PacketSetSlot() {
|
||||
@@ -13,7 +16,13 @@ public final class PacketSetSlot extends AbstractPacketAdapter {
|
||||
@Override
|
||||
public void onSend(PacketContainer packet) {
|
||||
packet.getItemModifier().modify(0, (item) -> {
|
||||
item = EnchantDisplay.displayEnchantments(item);
|
||||
boolean hideEnchants = false;
|
||||
|
||||
if(item != null && item.getItemMeta() != null) {
|
||||
hideEnchants = item.getItemMeta().getItemFlags().contains(ItemFlag.HIDE_ENCHANTS);
|
||||
}
|
||||
|
||||
item = EnchantDisplay.displayEnchantments(item, hideEnchants);
|
||||
return item;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.willfp.ecoenchants.display.AbstractPacketAdapter;
|
||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
|
||||
public final class PacketWindowItems extends AbstractPacketAdapter {
|
||||
public PacketWindowItems() {
|
||||
@@ -13,7 +14,15 @@ public final class PacketWindowItems extends AbstractPacketAdapter {
|
||||
@Override
|
||||
public void onSend(PacketContainer packet) {
|
||||
packet.getItemListModifier().modify(0, (itemStacks) -> {
|
||||
itemStacks.forEach(EnchantDisplay::displayEnchantments);
|
||||
itemStacks.forEach(item -> {
|
||||
boolean hideEnchants = false;
|
||||
|
||||
if(item != null && item.getItemMeta() != null) {
|
||||
hideEnchants = item.getItemMeta().getItemFlags().contains(ItemFlag.HIDE_ENCHANTS);
|
||||
}
|
||||
|
||||
EnchantDisplay.displayEnchantments(item, hideEnchants);
|
||||
});
|
||||
return itemStacks;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user