Refactored Lore to Display

This commit is contained in:
Auxilor 2020-08-28 17:20:07 +01:00
parent e0cd90fb4c
commit 7314eba1ee
10 changed files with 16 additions and 28 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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;
});
}

View File

@ -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();

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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("");

View File

@ -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;