mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-12-24 20:07:34 +01:00
Refactored Lore to Display
This commit is contained in:
parent
e0cd90fb4c
commit
7314eba1ee
@ -3,7 +3,6 @@ package com.willfp.ecoenchants.anvil;
|
|||||||
import com.willfp.ecoenchants.config.ConfigManager;
|
import com.willfp.ecoenchants.config.ConfigManager;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||||
import com.willfp.ecoenchants.lore.EnchantLore;
|
|
||||||
import com.willfp.ecoenchants.nms.Target;
|
import com.willfp.ecoenchants.nms.Target;
|
||||||
import com.willfp.ecoenchants.util.Pair;
|
import com.willfp.ecoenchants.util.Pair;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
@ -4,7 +4,7 @@ import com.willfp.ecoenchants.Main;
|
|||||||
import com.willfp.ecoenchants.config.ConfigManager;
|
import com.willfp.ecoenchants.config.ConfigManager;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||||
import com.willfp.ecoenchants.enchantments.EnchantmentRarity;
|
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.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
@ -24,7 +24,7 @@ public class CommandEcoreload implements CommandExecutor {
|
|||||||
ConfigManager.updateConfigs();
|
ConfigManager.updateConfigs();
|
||||||
EnchantmentRarity.update();
|
EnchantmentRarity.update();
|
||||||
EcoEnchants.update();
|
EcoEnchants.update();
|
||||||
EnchantLore.update();
|
EnchantDisplay.update();
|
||||||
|
|
||||||
EcoEnchants.getAll().forEach((ecoEnchant -> {
|
EcoEnchants.getAll().forEach((ecoEnchant -> {
|
||||||
HandlerList.unregisterAll(ecoEnchant);
|
HandlerList.unregisterAll(ecoEnchant);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.willfp.ecoenchants.commands;
|
package com.willfp.ecoenchants.commands;
|
||||||
|
|
||||||
import com.willfp.ecoenchants.config.ConfigManager;
|
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.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -29,11 +29,11 @@ public class CommandEcoskip implements CommandExecutor {
|
|||||||
if(meta == null) {
|
if(meta == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(meta.getPersistentDataContainer().has(EnchantLore.keySkip, PersistentDataType.INTEGER)) {
|
if(meta.getPersistentDataContainer().has(EnchantDisplay.keySkip, PersistentDataType.INTEGER)) {
|
||||||
meta.getPersistentDataContainer().remove(EnchantLore.keySkip);
|
meta.getPersistentDataContainer().remove(EnchantDisplay.keySkip);
|
||||||
player.sendMessage(ConfigManager.getLang().getMessage("skip-removed"));
|
player.sendMessage(ConfigManager.getLang().getMessage("skip-removed"));
|
||||||
} else {
|
} else {
|
||||||
meta.getPersistentDataContainer().set(EnchantLore.keySkip, PersistentDataType.INTEGER, 1);
|
meta.getPersistentDataContainer().set(EnchantDisplay.keySkip, PersistentDataType.INTEGER, 1);
|
||||||
player.sendMessage(ConfigManager.getLang().getMessage("skip-added"));
|
player.sendMessage(ConfigManager.getLang().getMessage("skip-added"));
|
||||||
}
|
}
|
||||||
item.setItemMeta(meta);
|
item.setItemMeta(meta);
|
||||||
|
@ -1,14 +1,10 @@
|
|||||||
package com.willfp.ecoenchants.lore;
|
package com.willfp.ecoenchants.display;
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.protocol.PacketType;
|
||||||
import com.comphenix.protocol.events.PacketAdapter;
|
import com.comphenix.protocol.events.PacketAdapter;
|
||||||
import com.comphenix.protocol.events.PacketEvent;
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
import com.comphenix.protocol.events.PacketListener;
|
|
||||||
import com.willfp.ecoenchants.Main;
|
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.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -30,12 +26,12 @@ public class DisplayPacketAdapter extends PacketAdapter {
|
|||||||
PacketType packetType = event.getPacketType();
|
PacketType packetType = event.getPacketType();
|
||||||
if (PacketType.Play.Server.WINDOW_ITEMS.equals(packetType)) {
|
if (PacketType.Play.Server.WINDOW_ITEMS.equals(packetType)) {
|
||||||
event.getPacket().getItemListModifier().modify(0, (itemStacks) -> {
|
event.getPacket().getItemListModifier().modify(0, (itemStacks) -> {
|
||||||
itemStacks.forEach(EnchantLore::convertEnchantsToLore);
|
itemStacks.forEach(EnchantDisplay::displayEnchantments);
|
||||||
return itemStacks;
|
return itemStacks;
|
||||||
});
|
});
|
||||||
} else if (PacketType.Play.Server.SET_SLOT.equals(packetType)) {
|
} else if (PacketType.Play.Server.SET_SLOT.equals(packetType)) {
|
||||||
event.getPacket().getItemModifier().modify(0, (item) -> {
|
event.getPacket().getItemModifier().modify(0, (item) -> {
|
||||||
item = EnchantLore.convertEnchantsToLore(item);
|
item = EnchantDisplay.displayEnchantments(item);
|
||||||
return item;
|
return item;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -48,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 = EnchantLore.convertEnchantsToLore(item);
|
item = EnchantDisplay.displayEnchantments(item);
|
||||||
return item;
|
return item;
|
||||||
});
|
});
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.willfp.ecoenchants.lore;
|
package com.willfp.ecoenchants.display;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.willfp.ecoenchants.Main;
|
import com.willfp.ecoenchants.Main;
|
||||||
@ -10,16 +10,13 @@ import com.willfp.ecoenchants.util.Numeral;
|
|||||||
import n3kas.ae.api.AEAPI;
|
import n3kas.ae.api.AEAPI;
|
||||||
import org.apache.commons.lang.WordUtils;
|
import org.apache.commons.lang.WordUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
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.EnchantmentStorageMeta;
|
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
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.
|
* 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
|
* The meta key of the length of enchantments in lore
|
||||||
@ -89,7 +86,7 @@ public class EnchantLore {
|
|||||||
* @param item The item to update
|
* @param item The item to update
|
||||||
* @return The item, updated
|
* @return The item, updated
|
||||||
*/
|
*/
|
||||||
public static ItemStack convertEnchantsToLore(ItemStack item) {
|
public static ItemStack displayEnchantments(ItemStack item) {
|
||||||
if(item == null) return null;
|
if(item == null) return null;
|
||||||
|
|
||||||
ItemStack oldItem = item.clone();
|
ItemStack oldItem = item.clone();
|
@ -1,7 +1,6 @@
|
|||||||
package com.willfp.ecoenchants.grindstone;
|
package com.willfp.ecoenchants.grindstone;
|
||||||
|
|
||||||
import com.willfp.ecoenchants.Main;
|
import com.willfp.ecoenchants.Main;
|
||||||
import com.willfp.ecoenchants.lore.EnchantLore;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
@ -4,7 +4,6 @@ import com.willfp.ecoenchants.Main;
|
|||||||
import com.willfp.ecoenchants.config.ConfigManager;
|
import com.willfp.ecoenchants.config.ConfigManager;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||||
import com.willfp.ecoenchants.lore.EnchantLore;
|
|
||||||
import com.willfp.ecoenchants.nms.Target;
|
import com.willfp.ecoenchants.nms.Target;
|
||||||
import com.willfp.ecoenchants.util.Bias;
|
import com.willfp.ecoenchants.util.Bias;
|
||||||
import com.willfp.ecoenchants.util.EqualIfOver;
|
import com.willfp.ecoenchants.util.EqualIfOver;
|
||||||
|
@ -3,7 +3,6 @@ package com.willfp.ecoenchants.listeners;
|
|||||||
import com.willfp.ecoenchants.config.ConfigManager;
|
import com.willfp.ecoenchants.config.ConfigManager;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||||
import com.willfp.ecoenchants.lore.EnchantLore;
|
|
||||||
import com.willfp.ecoenchants.nms.Target;
|
import com.willfp.ecoenchants.nms.Target;
|
||||||
import com.willfp.ecoenchants.util.Bias;
|
import com.willfp.ecoenchants.util.Bias;
|
||||||
import com.willfp.ecoenchants.util.Rand;
|
import com.willfp.ecoenchants.util.Rand;
|
||||||
|
@ -23,8 +23,8 @@ import com.willfp.ecoenchants.integrations.antigrief.plugins.*;
|
|||||||
import com.willfp.ecoenchants.listeners.EnchantingListeners;
|
import com.willfp.ecoenchants.listeners.EnchantingListeners;
|
||||||
import com.willfp.ecoenchants.listeners.PlayerJoinListener;
|
import com.willfp.ecoenchants.listeners.PlayerJoinListener;
|
||||||
import com.willfp.ecoenchants.listeners.VillagerListeners;
|
import com.willfp.ecoenchants.listeners.VillagerListeners;
|
||||||
import com.willfp.ecoenchants.lore.DisplayPacketAdapter;
|
import com.willfp.ecoenchants.display.DisplayPacketAdapter;
|
||||||
import com.willfp.ecoenchants.lore.EnchantLore;
|
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||||
import com.willfp.ecoenchants.naturalloot.LootPopulator;
|
import com.willfp.ecoenchants.naturalloot.LootPopulator;
|
||||||
import com.willfp.ecoenchants.nms.BlockBreak;
|
import com.willfp.ecoenchants.nms.BlockBreak;
|
||||||
import com.willfp.ecoenchants.nms.Cooldown;
|
import com.willfp.ecoenchants.nms.Cooldown;
|
||||||
@ -84,7 +84,7 @@ public class Loader {
|
|||||||
|
|
||||||
Bukkit.getLogger().info("Loading Configs...");
|
Bukkit.getLogger().info("Loading Configs...");
|
||||||
ConfigManager.updateConfigs();
|
ConfigManager.updateConfigs();
|
||||||
EnchantLore.update();
|
EnchantDisplay.update();
|
||||||
Main.getInstance().saveResource("README.txt", true);
|
Main.getInstance().saveResource("README.txt", true);
|
||||||
Bukkit.getLogger().info("");
|
Bukkit.getLogger().info("");
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ package com.willfp.ecoenchants.naturalloot;
|
|||||||
import com.willfp.ecoenchants.config.ConfigManager;
|
import com.willfp.ecoenchants.config.ConfigManager;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||||
import com.willfp.ecoenchants.lore.EnchantLore;
|
|
||||||
import com.willfp.ecoenchants.nms.Target;
|
import com.willfp.ecoenchants.nms.Target;
|
||||||
import com.willfp.ecoenchants.util.Bias;
|
import com.willfp.ecoenchants.util.Bias;
|
||||||
import com.willfp.ecoenchants.util.Rand;
|
import com.willfp.ecoenchants.util.Rand;
|
||||||
|
Loading…
Reference in New Issue
Block a user