From 7314eba1ee98e834855913d2142e11c08f80c9cd Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 28 Aug 2020 17:20:07 +0100 Subject: [PATCH] Refactored Lore to Display --- .../com/willfp/ecoenchants/anvil/AnvilMerge.java | 1 - .../ecoenchants/commands/CommandEcoreload.java | 4 ++-- .../willfp/ecoenchants/commands/CommandEcoskip.java | 8 ++++---- .../{lore => display}/DisplayPacketAdapter.java | 12 ++++-------- .../EnchantLore.java => display/EnchantDisplay.java} | 9 +++------ .../ecoenchants/grindstone/GrindstoneListeners.java | 1 - .../ecoenchants/listeners/EnchantingListeners.java | 1 - .../ecoenchants/listeners/VillagerListeners.java | 1 - .../java/com/willfp/ecoenchants/loader/Loader.java | 6 +++--- .../ecoenchants/naturalloot/LootPopulator.java | 1 - 10 files changed, 16 insertions(+), 28 deletions(-) rename Plugin/src/main/java/com/willfp/ecoenchants/{lore => display}/DisplayPacketAdapter.java (79%) rename Plugin/src/main/java/com/willfp/ecoenchants/{lore/EnchantLore.java => display/EnchantDisplay.java} (97%) diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/anvil/AnvilMerge.java b/Plugin/src/main/java/com/willfp/ecoenchants/anvil/AnvilMerge.java index c735c93a..185bb990 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/anvil/AnvilMerge.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/anvil/AnvilMerge.java @@ -3,7 +3,6 @@ package com.willfp.ecoenchants.anvil; import com.willfp.ecoenchants.config.ConfigManager; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; -import com.willfp.ecoenchants.lore.EnchantLore; import com.willfp.ecoenchants.nms.Target; import com.willfp.ecoenchants.util.Pair; import org.bukkit.enchantments.Enchantment; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/commands/CommandEcoreload.java b/Plugin/src/main/java/com/willfp/ecoenchants/commands/CommandEcoreload.java index a4d2bb61..7c1863f0 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/commands/CommandEcoreload.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/commands/CommandEcoreload.java @@ -4,7 +4,7 @@ import com.willfp.ecoenchants.Main; import com.willfp.ecoenchants.config.ConfigManager; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.EnchantmentRarity; -import com.willfp.ecoenchants.lore.EnchantLore; +import com.willfp.ecoenchants.display.EnchantDisplay; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -24,7 +24,7 @@ public class CommandEcoreload implements CommandExecutor { ConfigManager.updateConfigs(); EnchantmentRarity.update(); EcoEnchants.update(); - EnchantLore.update(); + EnchantDisplay.update(); EcoEnchants.getAll().forEach((ecoEnchant -> { HandlerList.unregisterAll(ecoEnchant); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/commands/CommandEcoskip.java b/Plugin/src/main/java/com/willfp/ecoenchants/commands/CommandEcoskip.java index 9fb3d40e..a6eee923 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/commands/CommandEcoskip.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/commands/CommandEcoskip.java @@ -1,7 +1,7 @@ package com.willfp.ecoenchants.commands; import com.willfp.ecoenchants.config.ConfigManager; -import com.willfp.ecoenchants.lore.EnchantLore; +import com.willfp.ecoenchants.display.EnchantDisplay; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -29,11 +29,11 @@ public class CommandEcoskip implements CommandExecutor { if(meta == null) { return true; } - if(meta.getPersistentDataContainer().has(EnchantLore.keySkip, PersistentDataType.INTEGER)) { - meta.getPersistentDataContainer().remove(EnchantLore.keySkip); + if(meta.getPersistentDataContainer().has(EnchantDisplay.keySkip, PersistentDataType.INTEGER)) { + meta.getPersistentDataContainer().remove(EnchantDisplay.keySkip); player.sendMessage(ConfigManager.getLang().getMessage("skip-removed")); } else { - meta.getPersistentDataContainer().set(EnchantLore.keySkip, PersistentDataType.INTEGER, 1); + meta.getPersistentDataContainer().set(EnchantDisplay.keySkip, PersistentDataType.INTEGER, 1); player.sendMessage(ConfigManager.getLang().getMessage("skip-added")); } item.setItemMeta(meta); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/lore/DisplayPacketAdapter.java b/Plugin/src/main/java/com/willfp/ecoenchants/display/DisplayPacketAdapter.java similarity index 79% rename from Plugin/src/main/java/com/willfp/ecoenchants/lore/DisplayPacketAdapter.java rename to Plugin/src/main/java/com/willfp/ecoenchants/display/DisplayPacketAdapter.java index 582d70d2..12e6317e 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/lore/DisplayPacketAdapter.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/display/DisplayPacketAdapter.java @@ -1,14 +1,10 @@ -package com.willfp.ecoenchants.lore; +package com.willfp.ecoenchants.display; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketEvent; -import com.comphenix.protocol.events.PacketListener; import com.willfp.ecoenchants.Main; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -30,12 +26,12 @@ public class DisplayPacketAdapter extends PacketAdapter { PacketType packetType = event.getPacketType(); if (PacketType.Play.Server.WINDOW_ITEMS.equals(packetType)) { event.getPacket().getItemListModifier().modify(0, (itemStacks) -> { - itemStacks.forEach(EnchantLore::convertEnchantsToLore); + itemStacks.forEach(EnchantDisplay::displayEnchantments); return itemStacks; }); } else if (PacketType.Play.Server.SET_SLOT.equals(packetType)) { event.getPacket().getItemModifier().modify(0, (item) -> { - item = EnchantLore.convertEnchantsToLore(item); + item = EnchantDisplay.displayEnchantments(item); return item; }); } @@ -48,7 +44,7 @@ public class DisplayPacketAdapter extends PacketAdapter { if(!event.getPacketType().equals(PacketType.Play.Client.SET_CREATIVE_SLOT)) return; event.getPacket().getItemModifier().modify(0, (item) -> { - item = EnchantLore.convertEnchantsToLore(item); + item = EnchantDisplay.displayEnchantments(item); return item; }); } diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/lore/EnchantLore.java b/Plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java similarity index 97% rename from Plugin/src/main/java/com/willfp/ecoenchants/lore/EnchantLore.java rename to Plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java index 94628963..30c3650f 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/lore/EnchantLore.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java @@ -1,4 +1,4 @@ -package com.willfp.ecoenchants.lore; +package com.willfp.ecoenchants.display; import com.google.common.collect.Lists; import com.willfp.ecoenchants.Main; @@ -10,16 +10,13 @@ import com.willfp.ecoenchants.util.Numeral; import n3kas.ae.api.AEAPI; import org.apache.commons.lang.WordUtils; import org.bukkit.ChatColor; -import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Player; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataType; -import org.bukkit.scheduler.BukkitRunnable; import java.util.ArrayList; import java.util.Arrays; @@ -29,7 +26,7 @@ import java.util.Map; /** * All methods and fields pertaining to showing players the enchantments on their items. */ -public class EnchantLore { +public class EnchantDisplay { /** * The meta key of the length of enchantments in lore @@ -89,7 +86,7 @@ public class EnchantLore { * @param item The item to update * @return The item, updated */ - public static ItemStack convertEnchantsToLore(ItemStack item) { + public static ItemStack displayEnchantments(ItemStack item) { if(item == null) return null; ItemStack oldItem = item.clone(); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/grindstone/GrindstoneListeners.java b/Plugin/src/main/java/com/willfp/ecoenchants/grindstone/GrindstoneListeners.java index 297d4a84..d2c3dae3 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/grindstone/GrindstoneListeners.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/grindstone/GrindstoneListeners.java @@ -1,7 +1,6 @@ package com.willfp.ecoenchants.grindstone; import com.willfp.ecoenchants.Main; -import com.willfp.ecoenchants.lore.EnchantLore; import org.bukkit.Bukkit; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Entity; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/listeners/EnchantingListeners.java b/Plugin/src/main/java/com/willfp/ecoenchants/listeners/EnchantingListeners.java index 4aff59a2..56ab8f88 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/listeners/EnchantingListeners.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/listeners/EnchantingListeners.java @@ -4,7 +4,6 @@ import com.willfp.ecoenchants.Main; import com.willfp.ecoenchants.config.ConfigManager; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; -import com.willfp.ecoenchants.lore.EnchantLore; import com.willfp.ecoenchants.nms.Target; import com.willfp.ecoenchants.util.Bias; import com.willfp.ecoenchants.util.EqualIfOver; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/listeners/VillagerListeners.java b/Plugin/src/main/java/com/willfp/ecoenchants/listeners/VillagerListeners.java index d6a37923..a6ff484f 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/listeners/VillagerListeners.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/listeners/VillagerListeners.java @@ -3,7 +3,6 @@ package com.willfp.ecoenchants.listeners; import com.willfp.ecoenchants.config.ConfigManager; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; -import com.willfp.ecoenchants.lore.EnchantLore; import com.willfp.ecoenchants.nms.Target; import com.willfp.ecoenchants.util.Bias; import com.willfp.ecoenchants.util.Rand; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java b/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java index 093fa8f4..9cc58ae5 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java @@ -23,8 +23,8 @@ import com.willfp.ecoenchants.integrations.antigrief.plugins.*; import com.willfp.ecoenchants.listeners.EnchantingListeners; import com.willfp.ecoenchants.listeners.PlayerJoinListener; import com.willfp.ecoenchants.listeners.VillagerListeners; -import com.willfp.ecoenchants.lore.DisplayPacketAdapter; -import com.willfp.ecoenchants.lore.EnchantLore; +import com.willfp.ecoenchants.display.DisplayPacketAdapter; +import com.willfp.ecoenchants.display.EnchantDisplay; import com.willfp.ecoenchants.naturalloot.LootPopulator; import com.willfp.ecoenchants.nms.BlockBreak; import com.willfp.ecoenchants.nms.Cooldown; @@ -84,7 +84,7 @@ public class Loader { Bukkit.getLogger().info("Loading Configs..."); ConfigManager.updateConfigs(); - EnchantLore.update(); + EnchantDisplay.update(); Main.getInstance().saveResource("README.txt", true); Bukkit.getLogger().info(""); diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/naturalloot/LootPopulator.java b/Plugin/src/main/java/com/willfp/ecoenchants/naturalloot/LootPopulator.java index b04bc66c..6d181120 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/naturalloot/LootPopulator.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/naturalloot/LootPopulator.java @@ -3,7 +3,6 @@ package com.willfp.ecoenchants.naturalloot; import com.willfp.ecoenchants.config.ConfigManager; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; -import com.willfp.ecoenchants.lore.EnchantLore; import com.willfp.ecoenchants.nms.Target; import com.willfp.ecoenchants.util.Bias; import com.willfp.ecoenchants.util.Rand;