mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-29 16:15:17 +01:00
Fixed lore duplication from creative mode
Reworked /ecoskip
This commit is contained in:
parent
d46f715bab
commit
bf92af0a93
@ -44,7 +44,7 @@ public class DisplayPacketAdapter extends PacketAdapter {
|
|||||||
if(!event.getPacketType().equals(PacketType.Play.Client.SET_CREATIVE_SLOT)) return;
|
if(!event.getPacketType().equals(PacketType.Play.Client.SET_CREATIVE_SLOT)) return;
|
||||||
|
|
||||||
event.getPacket().getItemModifier().modify(0, (item) -> {
|
event.getPacket().getItemModifier().modify(0, (item) -> {
|
||||||
item = EnchantDisplay.displayEnchantments(item);
|
item = EnchantDisplay.revertDisplay(item);
|
||||||
return item;
|
return item;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -34,12 +34,7 @@ public class EnchantDisplay {
|
|||||||
private static final NamespacedKey key = new NamespacedKey(Main.getInstance(), "ecoenchantlore-len");
|
private static final NamespacedKey key = new NamespacedKey(Main.getInstance(), "ecoenchantlore-len");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The meta key of the length of advancedenchantments enchantments in lore
|
* The meta key to hide enchantments in lore
|
||||||
*/
|
|
||||||
private static final NamespacedKey keyAE = new NamespacedKey(Main.getInstance(), "ecoenchantlore-aelen");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The meta key to function like {@link ItemFlag#HIDE_ENCHANTS}
|
|
||||||
*/
|
*/
|
||||||
public static final NamespacedKey keySkip = new NamespacedKey(Main.getInstance(), "ecoenchantlore-skip");
|
public static final NamespacedKey keySkip = new NamespacedKey(Main.getInstance(), "ecoenchantlore-skip");
|
||||||
|
|
||||||
@ -81,6 +76,51 @@ public class EnchantDisplay {
|
|||||||
shrinkPerLine = ConfigManager.getConfig().getInt("lore.shrink.maximum-per-line");
|
shrinkPerLine = ConfigManager.getConfig().getInt("lore.shrink.maximum-per-line");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Revert display
|
||||||
|
* @param item The item to revert
|
||||||
|
* @return The item, updated
|
||||||
|
*/
|
||||||
|
public static ItemStack revertDisplay(ItemStack item) {
|
||||||
|
if(item == null) return null;
|
||||||
|
|
||||||
|
if(!Target.Applicable.ALL.getMaterials().contains(item.getType()))
|
||||||
|
return item;
|
||||||
|
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
List<String> itemLore = new ArrayList<>();
|
||||||
|
|
||||||
|
if(meta == null) return item;
|
||||||
|
|
||||||
|
if(meta.hasLore())
|
||||||
|
itemLore = meta.getLore();
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (meta.getPersistentDataContainer().has(key, PersistentDataType.INTEGER)) {
|
||||||
|
int enchantLoreLength = meta.getPersistentDataContainer().get(key, PersistentDataType.INTEGER);
|
||||||
|
if(itemLore.size() >= enchantLoreLength) {
|
||||||
|
itemLore.subList(0, enchantLoreLength).clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (NullPointerException ignored) {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (meta instanceof EnchantmentStorageMeta) {
|
||||||
|
EnchantmentStorageMeta metaBook = (EnchantmentStorageMeta) meta;
|
||||||
|
metaBook.removeItemFlags(ItemFlag.HIDE_POTION_EFFECTS); // Thanks ShaneBee!
|
||||||
|
metaBook.removeItemFlags(ItemFlag.HIDE_ENCHANTS); // Here just in case
|
||||||
|
metaBook.setLore(itemLore);
|
||||||
|
item.setItemMeta(metaBook);
|
||||||
|
} else {
|
||||||
|
meta.removeItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||||
|
meta.setLore(itemLore);
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show all enchantments in item lore
|
* Show all enchantments in item lore
|
||||||
* @param item The item to update
|
* @param item The item to update
|
||||||
@ -94,6 +134,8 @@ public class EnchantDisplay {
|
|||||||
if(!Target.Applicable.ALL.getMaterials().contains(item.getType()))
|
if(!Target.Applicable.ALL.getMaterials().contains(item.getType()))
|
||||||
return oldItem;
|
return oldItem;
|
||||||
|
|
||||||
|
item = revertDisplay(item);
|
||||||
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
List<String> itemLore = new ArrayList<>();
|
List<String> itemLore = new ArrayList<>();
|
||||||
|
|
||||||
@ -105,7 +147,7 @@ public class EnchantDisplay {
|
|||||||
if(meta == null) return oldItem;
|
if(meta == null) return oldItem;
|
||||||
|
|
||||||
if(meta.getPersistentDataContainer().has(keySkip, PersistentDataType.INTEGER))
|
if(meta.getPersistentDataContainer().has(keySkip, PersistentDataType.INTEGER))
|
||||||
return item;
|
return oldItem;
|
||||||
|
|
||||||
if(meta.hasLore())
|
if(meta.hasLore())
|
||||||
itemLore = meta.getLore();
|
itemLore = meta.getLore();
|
||||||
@ -115,25 +157,6 @@ public class EnchantDisplay {
|
|||||||
|
|
||||||
List<String> enchantLore = new ArrayList<>();
|
List<String> enchantLore = new ArrayList<>();
|
||||||
|
|
||||||
try {
|
|
||||||
if (meta.getPersistentDataContainer().has(key, PersistentDataType.INTEGER)) {
|
|
||||||
int enchantLoreLength = meta.getPersistentDataContainer().get(key, PersistentDataType.INTEGER);
|
|
||||||
int loreEnd = loreStart;
|
|
||||||
if (meta.getPersistentDataContainer().has(keyAE, PersistentDataType.INTEGER)) {
|
|
||||||
int oldAEenchantLoreLength = meta.getPersistentDataContainer().get(keyAE, PersistentDataType.INTEGER);
|
|
||||||
loreEnd += oldAEenchantLoreLength;
|
|
||||||
}
|
|
||||||
if(itemLore.size() >= loreStart + enchantLoreLength + loreEnd) {
|
|
||||||
itemLore.subList(loreStart, enchantLoreLength + loreEnd).clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (NullPointerException ignored) {}
|
|
||||||
|
|
||||||
if(Main.hasAE) {
|
|
||||||
int totalAE = AEAPI.getEnchantmentsOnItem(item).size();
|
|
||||||
meta.getPersistentDataContainer().set(key, PersistentDataType.INTEGER, totalAE);
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<Enchantment, Integer> enchantments;
|
Map<Enchantment, Integer> enchantments;
|
||||||
List<Enchantment> forRemoval = new ArrayList<>();
|
List<Enchantment> forRemoval = new ArrayList<>();
|
||||||
|
|
||||||
@ -143,6 +166,7 @@ public class EnchantDisplay {
|
|||||||
enchantments = meta.getEnchants();
|
enchantments = meta.getEnchants();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final ItemStack finalItem = item;
|
||||||
enchantments.forEach(((enchantment, integer) -> {
|
enchantments.forEach(((enchantment, integer) -> {
|
||||||
boolean isEcoEnchant = EcoEnchants.getFromEnchantment(enchantment) != null;
|
boolean isEcoEnchant = EcoEnchants.getFromEnchantment(enchantment) != null;
|
||||||
|
|
||||||
@ -189,7 +213,7 @@ public class EnchantDisplay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!(isMaxLevelOne || type == EcoEnchant.EnchantmentType.CURSE)) {
|
if(!(isMaxLevelOne || type == EcoEnchant.EnchantmentType.CURSE)) {
|
||||||
if (useNumerals && item.getEnchantmentLevel(enchantment) < numbersThreshold) {
|
if (useNumerals && finalItem.getEnchantmentLevel(enchantment) < numbersThreshold) {
|
||||||
name += " " + Numeral.getNumeral(integer);
|
name += " " + Numeral.getNumeral(integer);
|
||||||
} else {
|
} else {
|
||||||
name += " " + integer;
|
name += " " + integer;
|
||||||
|
@ -374,8 +374,8 @@ public class Loader {
|
|||||||
Bukkit.getLogger().info("Loading Commands...");
|
Bukkit.getLogger().info("Loading Commands...");
|
||||||
Bukkit.getPluginCommand("ecoreload").setExecutor(new CommandEcoreload());
|
Bukkit.getPluginCommand("ecoreload").setExecutor(new CommandEcoreload());
|
||||||
Bukkit.getPluginCommand("ecodebug").setExecutor(new CommandEcodebug());
|
Bukkit.getPluginCommand("ecodebug").setExecutor(new CommandEcodebug());
|
||||||
Bukkit.getPluginCommand("ecoskip").setExecutor(new CommandEcoskip());
|
|
||||||
Bukkit.getPluginCommand("enchantinfo").setExecutor(new CommandEnchantinfo());
|
Bukkit.getPluginCommand("enchantinfo").setExecutor(new CommandEnchantinfo());
|
||||||
|
Bukkit.getPluginCommand("ecoskip").setExecutor(new CommandEcoskip());
|
||||||
Bukkit.getLogger().info("");
|
Bukkit.getLogger().info("");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user