9
0
mirror of https://github.com/Auxilor/EcoArmor.git synced 2025-12-27 02:49:22 +00:00

Updated to eco 3.8.0 and removed NMS + Proxy component

This commit is contained in:
Auxilor
2021-02-16 20:00:45 +00:00
parent a77251a6b2
commit 97ff8f4913
16 changed files with 5 additions and 286 deletions

View File

@@ -47,7 +47,7 @@ allprojects {
}
dependencies {
compileOnly 'com.willfp:eco:3.6.0'
compileOnly 'com.willfp:eco:3.8.0'
compileOnly 'org.jetbrains:annotations:19.0.0'

View File

@@ -1,9 +0,0 @@
group 'com.willfp'
version rootProject.version
subprojects {
dependencies {
compileOnly project(':eco-core:core-proxy')
compileOnly project(':eco-core:core-plugin')
}
}

View File

@@ -1,6 +0,0 @@
group 'com.willfp'
version rootProject.version
dependencies {
compileOnly 'org.spigotmc:spigot:1.16.1-R0.1-SNAPSHOT'
}

View File

@@ -1,41 +0,0 @@
package com.willfp.ecoarmor.proxy.v1_16_R1;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.willfp.ecoarmor.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 class Skull implements SkullProxy {
/**
* Cached method to set the gameProfile.
*/
private Method setProfile = null;
@Override
public void setTexture(@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();
}
}
}

View File

@@ -1,6 +0,0 @@
group 'com.willfp'
version rootProject.version
dependencies {
compileOnly 'org.spigotmc:spigot:1.16.3-R0.1-SNAPSHOT'
}

View File

@@ -1,41 +0,0 @@
package com.willfp.ecoarmor.proxy.v1_16_R2;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.willfp.ecoarmor.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 class Skull implements SkullProxy {
/**
* Cached method to set the gameProfile.
*/
private Method setProfile = null;
@Override
public void setTexture(@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();
}
}
}

View File

@@ -1,6 +0,0 @@
group 'com.willfp'
version rootProject.version
dependencies {
compileOnly 'org.spigotmc:spigot:1.16.4-R0.1-SNAPSHOT'
}

View File

@@ -1,41 +0,0 @@
package com.willfp.ecoarmor.proxy.v1_16_R3;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.willfp.ecoarmor.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 class Skull implements SkullProxy {
/**
* Cached method to set the gameProfile.
*/
private Method setProfile = null;
@Override
public void setTexture(@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();
}
}
}

View File

@@ -2,11 +2,5 @@ group 'com.willfp'
version rootProject.version
dependencies {
compileOnly project(":eco-core:core-proxy")
compileOnly 'org.spigotmc:spigot-api:1.16.4-R0.1-SNAPSHOT'
compileOnly 'commons-io:commons-io:2.8.0'
compileOnly 'com.comphenix.protocol:ProtocolLib:4.6.0-SNAPSHOT'
compileOnly 'net.ess3:EssentialsX:2.18.1'
compileOnly 'com.destroystokyo.paper:paper-api:1.16.3-R0.1-SNAPSHOT'
compileOnly 'com.gmail.nossr50.mcMMO:mcMMO:2.1.157'
}

View File

@@ -1,12 +1,11 @@
package com.willfp.ecoarmor.display;
import com.willfp.eco.util.SkullUtils;
import com.willfp.ecoarmor.config.EcoArmorConfigs;
import com.willfp.ecoarmor.proxy.proxies.SkullProxy;
import com.willfp.ecoarmor.sets.ArmorSet;
import com.willfp.ecoarmor.sets.meta.ArmorSlot;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import com.willfp.ecoarmor.upgrades.crystal.UpgradeCrystal;
import com.willfp.ecoarmor.util.ProxyUtils;
import lombok.experimental.UtilityClass;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@@ -122,7 +121,7 @@ public class ArmorDisplay {
if (meta instanceof SkullMeta && slotMeta instanceof SkullMeta) {
String base64 = EcoArmorConfigs.SETS.getString(set.getName() + "." + slot.name().toLowerCase() + ".skull-texture");
ProxyUtils.getProxy(SkullProxy.class).setTexture((SkullMeta) meta, base64);
SkullUtils.setSkullTexture((SkullMeta) meta, base64);
}
if (meta instanceof LeatherArmorMeta && slotMeta instanceof LeatherArmorMeta) {

View File

@@ -1,5 +1,6 @@
package com.willfp.ecoarmor.sets;
import com.willfp.eco.util.SkullUtils;
import com.willfp.eco.util.StringUtils;
import com.willfp.eco.util.recipe.EcoShapedRecipe;
import com.willfp.eco.util.recipe.lookup.RecipePartUtils;
@@ -9,10 +10,8 @@ import com.willfp.ecoarmor.config.EcoArmorConfigs;
import com.willfp.ecoarmor.display.ArmorDisplay;
import com.willfp.ecoarmor.effects.Effect;
import com.willfp.ecoarmor.effects.Effects;
import com.willfp.ecoarmor.proxy.proxies.SkullProxy;
import com.willfp.ecoarmor.sets.meta.ArmorSlot;
import com.willfp.ecoarmor.sets.util.ArmorUtils;
import com.willfp.ecoarmor.util.ProxyUtils;
import lombok.Getter;
import org.bukkit.Color;
import org.bukkit.Material;
@@ -231,7 +230,7 @@ public class ArmorSet {
if (meta instanceof SkullMeta) {
String base64 = EcoArmorConfigs.SETS.getString(name + "." + pieceName + ".skull-texture");
ProxyUtils.getProxy(SkullProxy.class).setTexture((SkullMeta) meta, base64);
SkullUtils.setSkullTexture((SkullMeta) meta, base64);
}
if (meta instanceof LeatherArmorMeta) {

View File

@@ -1,21 +0,0 @@
package com.willfp.ecoarmor.util;
import com.willfp.eco.util.proxy.AbstractProxy;
import com.willfp.ecoarmor.EcoArmorPlugin;
import com.willfp.ecoarmor.proxy.util.ProxyFactory;
import lombok.experimental.UtilityClass;
import org.jetbrains.annotations.NotNull;
@UtilityClass
public class ProxyUtils {
/**
* Get the implementation of a specified proxy.
*
* @param proxyClass The proxy interface.
* @param <T> The type of the proxy.
* @return The proxy implementation.
*/
public @NotNull <T extends AbstractProxy> T getProxy(@NotNull final Class<T> proxyClass) {
return new ProxyFactory<>(EcoArmorPlugin.getInstance(), proxyClass).getProxy();
}
}

View File

@@ -1,6 +0,0 @@
group 'com.willfp'
version rootProject.version
dependencies {
compileOnly 'org.spigotmc:spigot-api:1.16.4-R0.1-SNAPSHOT'
}

View File

@@ -1,16 +0,0 @@
package com.willfp.ecoarmor.proxy.proxies;
import com.willfp.eco.util.proxy.AbstractProxy;
import org.bukkit.inventory.meta.SkullMeta;
import org.jetbrains.annotations.NotNull;
public interface SkullProxy extends AbstractProxy {
/**
* Set the texture of a skull from base64.
*
* @param meta The meta to modify.
* @param base64 The base64 texture.
*/
void setTexture(@NotNull SkullMeta meta,
@NotNull String base64);
}

View File

@@ -1,75 +0,0 @@
package com.willfp.ecoarmor.proxy.util;
import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.util.proxy.AbstractProxy;
import com.willfp.eco.util.proxy.ProxyConstants;
import com.willfp.eco.util.proxy.UnsupportedVersionException;
import org.jetbrains.annotations.NotNull;
import java.util.IdentityHashMap;
import java.util.Map;
public class ProxyFactory<T extends AbstractProxy> extends PluginDependent {
/**
* Cached proxy implementations in order to not perform expensive reflective class-finding.
*/
private static final Map<Class<? extends AbstractProxy>, AbstractProxy> CACHE = new IdentityHashMap<>();
/**
* The class of the proxy interface.
*/
private final Class<T> proxyClass;
/**
* Create a new Proxy Factory for a specific type.
*
* @param plugin The plugin to create proxies for.
* @param proxyClass The class of the proxy interface.
*/
public ProxyFactory(@NotNull final AbstractEcoPlugin plugin,
@NotNull final Class<T> proxyClass) {
super(plugin);
this.proxyClass = proxyClass;
}
/**
* Get the implementation of a proxy.
*
* @return The proxy implementation.
*/
public @NotNull T getProxy() {
try {
T cachedProxy = attemptCache();
if (cachedProxy != null) {
return cachedProxy;
}
String className = this.getPlugin().getProxyPackage() + "." + ProxyConstants.NMS_VERSION + "." + proxyClass.getSimpleName().replace("Proxy", "");
final Class<?> class2 = Class.forName(className);
Object instance = class2.getConstructor().newInstance();
if (proxyClass.isAssignableFrom(class2) && proxyClass.isInstance(instance)) {
T proxy = proxyClass.cast(instance);
CACHE.put(proxyClass, proxy);
return proxy;
}
} catch (Exception e) {
// If not returned, then throw error
}
throw new UnsupportedVersionException("You're running an unsupported server version: " + ProxyConstants.NMS_VERSION);
}
private T attemptCache() {
Object proxy = CACHE.get(proxyClass);
if (proxy == null) {
return null;
}
if (proxyClass.isInstance(proxy)) {
return proxyClass.cast(proxy);
}
return null;
}
}

View File

@@ -2,9 +2,4 @@ rootProject.name = 'EcoArmor'
// Core
include ':eco-core'
include ':eco-core:core-nms'
include ':eco-core:core-nms:v1_16_R1'
include ':eco-core:core-nms:v1_16_R2'
include ':eco-core:core-nms:v1_16_R3'
include ':eco-core:core-proxy'
include ':eco-core:core-plugin'