Removed 1.15 support
This commit is contained in:
@@ -51,7 +51,7 @@ allprojects {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT'
|
||||
compileOnly 'org.spigotmc:spigot-api:1.16.4-R0.1-SNAPSHOT'
|
||||
compileOnly 'org.jetbrains:annotations:19.0.0'
|
||||
|
||||
// Lombok
|
||||
|
||||
@@ -23,7 +23,6 @@ import com.willfp.eco.internal.factory.EcoNamespacedKeyFactory;
|
||||
import com.willfp.eco.internal.factory.EcoRunnableFactory;
|
||||
import com.willfp.eco.internal.integration.PlaceholderIntegrationPAPI;
|
||||
import com.willfp.eco.internal.scheduling.EcoScheduler;
|
||||
import com.willfp.eco.util.Prerequisite;
|
||||
import lombok.Getter;
|
||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.willfp.eco.util;
|
||||
package com.willfp.eco.core;
|
||||
|
||||
import com.willfp.eco.core.proxy.ProxyConstants;
|
||||
import com.willfp.eco.util.ClassUtils;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -14,15 +14,6 @@ public class Prerequisite {
|
||||
* All existing prerequisites are registered on creation.
|
||||
*/
|
||||
private static final List<Prerequisite> VALUES = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Requires the server to be running minecraft version 1.16 or higher.
|
||||
*/
|
||||
public static final Prerequisite MINIMUM_1_16 = new Prerequisite(
|
||||
() -> !ProxyConstants.NMS_VERSION.contains("15"),
|
||||
"Requires minimum server version of 1.16"
|
||||
);
|
||||
|
||||
/**
|
||||
* Requires the server to be running an implementation of paper.
|
||||
*/
|
||||
@@ -1,164 +0,0 @@
|
||||
package com.willfp.eco.core.fast;
|
||||
|
||||
import com.willfp.eco.internal.fast.AbstractFastItemStackHandler;
|
||||
import com.willfp.eco.internal.fast.FastItemStackHandlerFactory;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class FastItemStack {
|
||||
/**
|
||||
* The ItemStack handler.
|
||||
*/
|
||||
private static FastItemStackHandlerFactory factory;
|
||||
|
||||
/**
|
||||
* The ItemStack to interface with.
|
||||
*/
|
||||
private final AbstractFastItemStackHandler handle;
|
||||
|
||||
/**
|
||||
* Create a new fast ItemStack.
|
||||
*
|
||||
* @param itemStack The ItemStack.
|
||||
*/
|
||||
public FastItemStack(@NotNull final ItemStack itemStack) {
|
||||
this.handle = factory.create(itemStack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the enchantments on the item.
|
||||
*
|
||||
* @return The enchantments.
|
||||
*/
|
||||
public Map<Enchantment, Integer> getEnchantments() {
|
||||
return handle.getEnchantments();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the level of a specific enchantment.
|
||||
*
|
||||
* @param enchantment The enchantments.
|
||||
* @return The level, or 0 if not found.
|
||||
*/
|
||||
public int getEnchantmentLevel(@NotNull final Enchantment enchantment) {
|
||||
return handle.getEnchantmentLevel(enchantment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the lore of an item.
|
||||
*
|
||||
* @return The lore.
|
||||
*/
|
||||
public List<String> getLore() {
|
||||
return handle.getLore();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the lore of an item.
|
||||
*
|
||||
* @param lore The lore.
|
||||
*/
|
||||
public void setLore(@NotNull final List<String> lore) {
|
||||
handle.setLore(lore);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the item flags on an item.
|
||||
*
|
||||
* @return The item flags.
|
||||
*/
|
||||
public Set<ItemFlag> getItemFlags() {
|
||||
return handle.getItemFlags();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the item flags on an item.
|
||||
*
|
||||
* @param flags The flags.
|
||||
*/
|
||||
public void setItemFlags(@NotNull final Set<ItemFlag> flags) {
|
||||
handle.setItemFlags(flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a key in persistent meta.
|
||||
*
|
||||
* @param key The key.
|
||||
* @param type The type.
|
||||
* @param value The value.
|
||||
* @param <T> The type.
|
||||
* @param <Z> The type.
|
||||
*/
|
||||
public <T, Z> void writePersistentKey(@NotNull final NamespacedKey key,
|
||||
@NotNull final PersistentDataType<T, Z> type,
|
||||
@NotNull final Z value) {
|
||||
handle.writePersistentKey(key, type, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a key from persistent meta.
|
||||
*
|
||||
* @param key The key.
|
||||
* @param type The type.
|
||||
* @param <T> The type.
|
||||
* @param <Z> The type.
|
||||
* @return The value.
|
||||
*/
|
||||
public <T, Z> Z readPersistentKey(@NotNull final NamespacedKey key,
|
||||
@NotNull final PersistentDataType<T, Z> type) {
|
||||
return handle.readPersistentKey(key, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get persistent meta keys.
|
||||
*
|
||||
* @return The keys.
|
||||
*/
|
||||
public Set<NamespacedKey> getPersistentKeys() {
|
||||
return handle.getPersistentKeys();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the display name
|
||||
*
|
||||
* @return The display name.
|
||||
*/
|
||||
public String getDisplayName() {
|
||||
return handle.getDisplayName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the display name.
|
||||
*
|
||||
* @param name The name.
|
||||
*/
|
||||
public void setDisplayName(@NotNull final String name) {
|
||||
handle.setDisplayName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply changes.
|
||||
*/
|
||||
public void apply() {
|
||||
handle.apply();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the ItemStack handler factory.
|
||||
*
|
||||
* @param handlerFactory The handler factory.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public static void initialize(@NotNull final FastItemStackHandlerFactory handlerFactory) {
|
||||
factory = handlerFactory;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.willfp.eco.internal.fast;
|
||||
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public interface AbstractFastItemStackHandler {
|
||||
Map<Enchantment, Integer> getEnchantments();
|
||||
|
||||
int getEnchantmentLevel(@NotNull Enchantment enchantment);
|
||||
|
||||
List<String> getLore();
|
||||
|
||||
void setLore(@NotNull List<String> lore);
|
||||
|
||||
Set<ItemFlag> getItemFlags();
|
||||
|
||||
void setItemFlags(@NotNull Set<ItemFlag> flags);
|
||||
|
||||
<T, Z> void writePersistentKey(@NotNull NamespacedKey key,
|
||||
@NotNull PersistentDataType<T, Z> type,
|
||||
@NotNull Z value);
|
||||
|
||||
<T, Z> Z readPersistentKey(@NotNull NamespacedKey key,
|
||||
@NotNull PersistentDataType<T, Z> type);
|
||||
|
||||
Set<NamespacedKey> getPersistentKeys();
|
||||
|
||||
String getDisplayName();
|
||||
|
||||
void setDisplayName(@NotNull String name);
|
||||
|
||||
void apply();
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.willfp.eco.internal.fast;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface FastItemStackHandlerFactory {
|
||||
/**
|
||||
* Create new FastItemStackHandler.
|
||||
*
|
||||
* @param itemStack The ItemStack to handle.
|
||||
* @return The handler.
|
||||
*/
|
||||
AbstractFastItemStackHandler create(@NotNull ItemStack itemStack);
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@UtilityClass
|
||||
public class PlayerUtils {
|
||||
/**
|
||||
* If the meta set function has been set.
|
||||
*/
|
||||
private boolean initialized = false;
|
||||
|
||||
/**
|
||||
* The cooldown function.
|
||||
*/
|
||||
private Function<Player, Double> cooldownFunction = null;
|
||||
|
||||
/**
|
||||
* Get the attack cooldown for a player.
|
||||
*
|
||||
* @param player The player's attack cooldown.
|
||||
* @return A value between 0 and 1, with 1 representing full power.
|
||||
*/
|
||||
public double getAttackCooldown(@NotNull final Player player) {
|
||||
Validate.isTrue(initialized, "Must be initialized!");
|
||||
Validate.notNull(cooldownFunction, "Must be initialized!");
|
||||
|
||||
if (Prerequisite.MINIMUM_1_16.isMet()) {
|
||||
return player.getAttackCooldown();
|
||||
}
|
||||
|
||||
return cooldownFunction.apply(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the cooldown function.
|
||||
*
|
||||
* @param function The function.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public void initialize(@NotNull final Function<Player, Double> function) {
|
||||
Validate.isTrue(!initialized, "Already initialized!");
|
||||
|
||||
cooldownFunction = function;
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
@@ -44,9 +44,7 @@ public class StringUtils {
|
||||
public String translate(@NotNull final String message,
|
||||
@Nullable final Player player) {
|
||||
String processedMessage = message;
|
||||
if (Prerequisite.MINIMUM_1_16.isMet()) {
|
||||
processedMessage = translateGradients(processedMessage);
|
||||
}
|
||||
processedMessage = translateGradients(processedMessage);
|
||||
processedMessage = PlaceholderManager.translatePlaceholders(processedMessage, player);
|
||||
processedMessage = translateHexColorCodes(processedMessage);
|
||||
processedMessage = ChatColor.translateAlternateColorCodes('&', processedMessage);
|
||||
|
||||
@@ -79,9 +79,6 @@ public class TeamUtils {
|
||||
MATERIAL_COLORS.forcePut(Material.LAPIS_ORE, ChatColor.BLUE);
|
||||
MATERIAL_COLORS.forcePut(Material.REDSTONE_ORE, ChatColor.RED);
|
||||
MATERIAL_COLORS.forcePut(Material.DIAMOND_ORE, ChatColor.AQUA);
|
||||
|
||||
if (Prerequisite.MINIMUM_1_16.isMet()) {
|
||||
MATERIAL_COLORS.forcePut(Material.ANCIENT_DEBRIS, ChatColor.DARK_RED);
|
||||
}
|
||||
MATERIAL_COLORS.forcePut(Material.ANCIENT_DEBRIS, ChatColor.DARK_RED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot:1.15.2-R0.1-SNAPSHOT'
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.willfp.eco.proxy.v1_15_R1;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.AutoCraftProxy;
|
||||
import net.minecraft.server.v1_15_R1.MinecraftKey;
|
||||
import net.minecraft.server.v1_15_R1.PacketPlayOutAutoRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public final class AutoCraft implements AutoCraftProxy {
|
||||
@Override
|
||||
public void modifyPacket(@NotNull final Object packet) throws NoSuchFieldException, IllegalAccessException {
|
||||
PacketPlayOutAutoRecipe recipePacket = (PacketPlayOutAutoRecipe) packet;
|
||||
Field fKey = recipePacket.getClass().getDeclaredField("b");
|
||||
fKey.setAccessible(true);
|
||||
MinecraftKey key = (MinecraftKey) fKey.get(recipePacket);
|
||||
fKey.set(recipePacket, new MinecraftKey(key.getNamespace(), key.getKey() + "_displayed"));
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.willfp.eco.proxy.v1_15_R1;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.BlockBreakProxy;
|
||||
import net.minecraft.server.v1_15_R1.BlockPosition;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class BlockBreak implements BlockBreakProxy {
|
||||
@Override
|
||||
public void breakBlock(@NotNull final Player player,
|
||||
@NotNull final Block block) {
|
||||
((CraftPlayer) player).getHandle().playerInteractManager.breakBlock(new BlockPosition(block.getX(), block.getY(), block.getZ()));
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.willfp.eco.proxy.v1_15_R1;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.ChatComponentProxy;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class ChatComponent implements ChatComponentProxy {
|
||||
@Override
|
||||
public Object modifyComponent(@NotNull final Object object) {
|
||||
return object;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.willfp.eco.proxy.v1_15_R1;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.CooldownProxy;
|
||||
import net.minecraft.server.v1_15_R1.EntityHuman;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class Cooldown implements CooldownProxy {
|
||||
@Override
|
||||
public double getAttackCooldown(@NotNull final Player player) {
|
||||
EntityHuman entityHuman = ((CraftPlayer) player).getHandle();
|
||||
return entityHuman.s(0);
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package com.willfp.eco.proxy.v1_15_R1;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.willfp.eco.proxy.proxies.SkullProxy;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class Skull implements SkullProxy {
|
||||
/**
|
||||
* Cached method to set the gameProfile.
|
||||
*/
|
||||
private Method setProfile = null;
|
||||
|
||||
@Override
|
||||
public void setSkullTexture(@NotNull final SkullMeta meta,
|
||||
@NotNull final String base64) {
|
||||
try {
|
||||
if (setProfile == null) {
|
||||
setProfile = meta.getClass().getDeclaredMethod("setProfile", GameProfile.class);
|
||||
setProfile.setAccessible(true);
|
||||
}
|
||||
|
||||
UUID uuid = new UUID(
|
||||
base64.substring(base64.length() - 20).hashCode(),
|
||||
base64.substring(base64.length() - 10).hashCode()
|
||||
);
|
||||
|
||||
GameProfile profile = new GameProfile(uuid, "talismans");
|
||||
profile.getProperties().put("textures", new Property("textures", base64));
|
||||
|
||||
setProfile.invoke(meta, profile);
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.willfp.eco.proxy.v1_15_R1;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.TridentStackProxy;
|
||||
import net.minecraft.server.v1_15_R1.EntityThrownTrident;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftTrident;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class TridentStack implements TridentStackProxy {
|
||||
@Override
|
||||
public ItemStack getTridentStack(@NotNull final Trident trident) {
|
||||
EntityThrownTrident t = ((CraftTrident) trident).getHandle();
|
||||
return CraftItemStack.asBukkitCopy(t.trident);
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.willfp.eco.proxy.v1_15_R1;
|
||||
|
||||
import com.willfp.eco.proxy.proxies.VillagerTradeProxy;
|
||||
import com.willfp.eco.core.display.Display;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftMerchantRecipe;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public final class VillagerTrade implements VillagerTradeProxy {
|
||||
@Override
|
||||
public void displayTrade(@NotNull final MerchantRecipe merchantRecipe) {
|
||||
try {
|
||||
// Bukkit MerchantRecipe result
|
||||
Field fResult = MerchantRecipe.class.getDeclaredField("result");
|
||||
fResult.setAccessible(true);
|
||||
|
||||
ItemStack result = merchantRecipe.getResult();
|
||||
Display.displayAndFinalize(result);
|
||||
fResult.set(merchantRecipe, result);
|
||||
|
||||
// Get NMS MerchantRecipe from CraftMerchantRecipe
|
||||
Field fHandle = CraftMerchantRecipe.class.getDeclaredField("handle");
|
||||
fHandle.setAccessible(true);
|
||||
net.minecraft.server.v1_15_R1.MerchantRecipe handle = (net.minecraft.server.v1_15_R1.MerchantRecipe) fHandle.get(merchantRecipe); // NMS Recipe
|
||||
|
||||
Field fSelling = net.minecraft.server.v1_15_R1.MerchantRecipe.class.getDeclaredField("sellingItem");
|
||||
fSelling.setAccessible(true);
|
||||
|
||||
ItemStack selling = CraftItemStack.asBukkitCopy(handle.sellingItem);
|
||||
Display.displayAndFinalize(selling);
|
||||
fSelling.set(handle, CraftItemStack.asNMSCopy(selling));
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package com.willfp.eco.proxy.v1_16_R3;
|
||||
|
||||
import com.willfp.eco.internal.fast.AbstractFastItemStackHandler;
|
||||
import com.willfp.eco.proxy.proxies.FastItemStackHandlerFactoryProxy;
|
||||
import com.willfp.eco.proxy.v1_16_R3.fast.FastItemStackHandler;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class FastItemStackHandlerFactory implements FastItemStackHandlerFactoryProxy {
|
||||
/**
|
||||
* The field to get the handle without a copy.
|
||||
*/
|
||||
private static final Field HANDLE_FIELD;
|
||||
|
||||
@Override
|
||||
public AbstractFastItemStackHandler create(@NotNull final ItemStack itemStack) {
|
||||
return new FastItemStackHandler(get(itemStack));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get from field.
|
||||
*
|
||||
* @param itemStack The ItemStack.
|
||||
* @return The NMS ItemStack.
|
||||
*/
|
||||
public net.minecraft.server.v1_16_R3.ItemStack get(@NotNull final ItemStack itemStack) {
|
||||
Validate.isTrue(itemStack instanceof CraftItemStack, "Must be a CraftItemStack!");
|
||||
|
||||
try {
|
||||
return (net.minecraft.server.v1_16_R3.ItemStack) HANDLE_FIELD.get(itemStack);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static {
|
||||
Field handle = null;
|
||||
try {
|
||||
handle = CraftItemStack.class.getDeclaredField("handle");
|
||||
handle.setAccessible(true);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
HANDLE_FIELD = handle;
|
||||
}
|
||||
}
|
||||
@@ -1,164 +0,0 @@
|
||||
package com.willfp.eco.proxy.v1_16_R3.fast;
|
||||
|
||||
import com.willfp.eco.internal.fast.AbstractFastItemStackHandler;
|
||||
import net.minecraft.server.v1_16_R3.NBTBase;
|
||||
import net.minecraft.server.v1_16_R3.NBTTagCompound;
|
||||
import net.minecraft.server.v1_16_R3.NBTTagList;
|
||||
import net.minecraft.server.v1_16_R3.NBTTagString;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.util.CraftChatMessage;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.util.CraftNamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class FastItemStackHandler implements AbstractFastItemStackHandler {
|
||||
/**
|
||||
* The ItemStack.
|
||||
*/
|
||||
private final net.minecraft.server.v1_16_R3.ItemStack itemStack;
|
||||
|
||||
/**
|
||||
* The nbt tag.
|
||||
*/
|
||||
private final NBTTagCompound tag;
|
||||
|
||||
/**
|
||||
* Create new FastItemStack handler.
|
||||
*
|
||||
* @param itemStack The ItemStack.
|
||||
*/
|
||||
public FastItemStackHandler(@NotNull final net.minecraft.server.v1_16_R3.ItemStack itemStack) {
|
||||
this.itemStack = itemStack;
|
||||
|
||||
this.tag = itemStack.getOrCreateTag();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<Enchantment, Integer> getEnchantments() {
|
||||
NBTTagList enchantmentNBT = itemStack.getEnchantments();
|
||||
HashMap<Enchantment, Integer> foundEnchantments = new HashMap<>();
|
||||
|
||||
for (NBTBase base : enchantmentNBT) {
|
||||
NBTTagCompound compound = (NBTTagCompound) base;
|
||||
String key = compound.getString("id");
|
||||
int level = '\uffff' & compound.getShort("lvl");
|
||||
|
||||
Enchantment found = Enchantment.getByKey(CraftNamespacedKey.fromStringOrNull(key));
|
||||
if (found != null) {
|
||||
foundEnchantments.put(found, level);
|
||||
}
|
||||
}
|
||||
|
||||
return foundEnchantments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnchantmentLevel(@NotNull final Enchantment enchantment) {
|
||||
NBTTagList enchantmentNBT = itemStack.getEnchantments();
|
||||
|
||||
for (NBTBase base : enchantmentNBT) {
|
||||
NBTTagCompound compound = (NBTTagCompound) base;
|
||||
String key = compound.getString("id");
|
||||
if (!key.equals(enchantment.getKey().toString())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return '\uffff' & compound.getShort("lvl");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getLore() {
|
||||
NBTTagCompound displayTag = getDisplayTag(this.tag);
|
||||
if (displayTag.hasKey("Lore")) {
|
||||
NBTTagList list = displayTag.getList("Lore", CraftMagicNumbers.NBT.TAG_STRING);
|
||||
List<String> lore = new ArrayList<>(list.size());
|
||||
|
||||
for (int index = 0; index < list.size(); index++) {
|
||||
String line = list.getString(index);
|
||||
lore.add(CraftChatMessage.fromJSONComponent(line));
|
||||
}
|
||||
|
||||
return lore;
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLore(@NotNull final List<String> lore) {
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
for (String value : lore) {
|
||||
tagList.add(NBTTagString.a(CraftChatMessage.fromJSONComponent(value)));
|
||||
}
|
||||
|
||||
setDisplayTag("Lore", tagList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ItemFlag> getItemFlags() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemFlags(@NotNull final Set<ItemFlag> flags) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, Z> void writePersistentKey(@NotNull final NamespacedKey key,
|
||||
@NotNull final PersistentDataType<T, Z> type,
|
||||
@NotNull final Z value) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, Z> Z readPersistentKey(@NotNull final NamespacedKey key,
|
||||
@NotNull final PersistentDataType<T, Z> type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<NamespacedKey> getPersistentKeys() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return CraftChatMessage.fromComponent(itemStack.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDisplayName(@NotNull final String name) {
|
||||
itemStack.a(CraftChatMessage.fromStringOrNull(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
itemStack.setTag(tag);
|
||||
}
|
||||
|
||||
private NBTTagCompound getDisplayTag(@NotNull final NBTTagCompound base) {
|
||||
return base.getCompound("display");
|
||||
}
|
||||
|
||||
private void setDisplayTag(@NotNull final String key,
|
||||
@NotNull final NBTBase value) {
|
||||
final NBTTagCompound display = tag.getCompound("display");
|
||||
|
||||
display.set(key, value);
|
||||
|
||||
tag.set("display", display);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,14 @@
|
||||
package com.willfp.eco.spigot;
|
||||
|
||||
import com.willfp.eco.core.AbstractPacketAdapter;
|
||||
import com.willfp.eco.core.command.AbstractCommand;
|
||||
import com.willfp.eco.core.display.Display;
|
||||
import com.willfp.eco.core.display.DisplayModule;
|
||||
import com.willfp.eco.core.integrations.IntegrationLoader;
|
||||
import com.willfp.eco.core.integrations.anticheat.AnticheatManager;
|
||||
import com.willfp.eco.core.integrations.antigrief.AntigriefManager;
|
||||
import com.willfp.eco.core.integrations.mcmmo.McmmoManager;
|
||||
import com.willfp.eco.proxy.proxies.BlockBreakProxy;
|
||||
import com.willfp.eco.proxy.proxies.CooldownProxy;
|
||||
import com.willfp.eco.proxy.proxies.FastItemStackHandlerFactoryProxy;
|
||||
import com.willfp.eco.proxy.proxies.SkullProxy;
|
||||
import com.willfp.eco.proxy.proxies.TridentStackProxy;
|
||||
import com.willfp.eco.spigot.display.PacketAutoRecipe;
|
||||
@@ -29,18 +35,8 @@ import com.willfp.eco.spigot.integrations.antigrief.AntigriefWorldGuard;
|
||||
import com.willfp.eco.spigot.integrations.mcmmo.McmmoIntegrationImpl;
|
||||
import com.willfp.eco.spigot.recipes.RecipeListener;
|
||||
import com.willfp.eco.util.BlockUtils;
|
||||
import com.willfp.eco.util.PlayerUtils;
|
||||
import com.willfp.eco.util.SkullUtils;
|
||||
import com.willfp.eco.util.TridentUtils;
|
||||
import com.willfp.eco.core.command.AbstractCommand;
|
||||
import com.willfp.eco.core.display.Display;
|
||||
import com.willfp.eco.core.display.DisplayModule;
|
||||
import com.willfp.eco.core.fast.FastItemStack;
|
||||
import com.willfp.eco.core.integrations.IntegrationLoader;
|
||||
import com.willfp.eco.core.integrations.anticheat.AnticheatManager;
|
||||
import com.willfp.eco.core.integrations.antigrief.AntigriefManager;
|
||||
import com.willfp.eco.core.integrations.mcmmo.McmmoManager;
|
||||
import com.willfp.eco.core.AbstractPacketAdapter;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -65,9 +61,7 @@ public class EcoSpigotPlugin extends com.willfp.eco.core.EcoPlugin {
|
||||
Display.setFinalizeKey(this.getNamespacedKeyFactory().create("finalized"));
|
||||
SkullUtils.initialize((skullMeta, base64) -> InternalProxyUtils.getProxy(SkullProxy.class).setSkullTexture(skullMeta, base64));
|
||||
BlockUtils.initialize(((player, block) -> InternalProxyUtils.getProxy(BlockBreakProxy.class).breakBlock(player, block)));
|
||||
PlayerUtils.initialize(((player) -> InternalProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown(player)));
|
||||
TridentUtils.initialize(((trident) -> InternalProxyUtils.getProxy(TridentStackProxy.class).getTridentStack(trident)));
|
||||
FastItemStack.initialize(InternalProxyUtils.getProxy(FastItemStackHandlerFactoryProxy.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
name: eco
|
||||
version: ${projectVersion}
|
||||
main: com.willfp.eco.spigot.EcoPlugin
|
||||
api-version: 1.15
|
||||
api-version: 1.16
|
||||
authors: [Auxilor]
|
||||
website: willfp.com
|
||||
loadbefore:
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.willfp.eco.proxy.proxies;
|
||||
|
||||
import com.willfp.eco.core.proxy.AbstractProxy;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface CooldownProxy extends AbstractProxy {
|
||||
/**
|
||||
* Get the attack cooldown for a player.
|
||||
*
|
||||
* @param player The player's attack cooldown.
|
||||
* @return A value between 0 and 1, with 1 representing full power.
|
||||
*/
|
||||
double getAttackCooldown(@NotNull Player player);
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package com.willfp.eco.proxy.proxies;
|
||||
|
||||
import com.willfp.eco.internal.fast.FastItemStackHandlerFactory;
|
||||
import com.willfp.eco.core.proxy.AbstractProxy;
|
||||
|
||||
public interface FastItemStackHandlerFactoryProxy extends AbstractProxy, FastItemStackHandlerFactory {
|
||||
}
|
||||
@@ -4,7 +4,6 @@ rootProject.name = 'eco'
|
||||
include ':eco-api'
|
||||
include ':eco-core'
|
||||
include ':eco-core:core-nms'
|
||||
include ':eco-core:core-nms:v1_15_R1'
|
||||
include ':eco-core:core-nms:v1_16_R1'
|
||||
include ':eco-core:core-nms:v1_16_R2'
|
||||
include ':eco-core:core-nms:v1_16_R3'
|
||||
|
||||
Reference in New Issue
Block a user