9
0
mirror of https://github.com/Auxilor/EcoMobs.git synced 2025-12-20 15:39:31 +00:00

Updated to eco 6

This commit is contained in:
Auxilor
2021-07-21 18:28:42 +01:00
parent 3e4d3af215
commit 950bfab5f3
3 changed files with 0 additions and 112 deletions

View File

@@ -1,30 +0,0 @@
package com.willfp.ecobosses.proxy.util;
import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap;
import com.willfp.ecobosses.proxy.proxies.CustomIllusionerProxy;
import lombok.experimental.UtilityClass;
import org.bukkit.entity.LivingEntity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@UtilityClass
public class CustomEntities {
/**
* Registered custom entities.
*/
private static final BiMap<String, Class<? extends CustomEntity<? extends LivingEntity>>> REGISTRY = new ImmutableBiMap.Builder<String, Class<? extends CustomEntity<? extends LivingEntity>>>()
.put("custom_illusioner", CustomIllusionerProxy.class)
.build();
/**
* Get entity class.
*
* @param id The entity id.
* @return The class.
*/
@Nullable
public Class<? extends CustomEntity<? extends LivingEntity>> getEntityClass(@NotNull final String id) {
return REGISTRY.get(id);
}
}

View File

@@ -1,7 +0,0 @@
package com.willfp.ecobosses.proxy.util;
import org.bukkit.entity.LivingEntity;
public interface CustomEntity<T extends LivingEntity> {
}

View File

@@ -1,75 +0,0 @@
package com.willfp.ecobosses.proxy.util;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.PluginDependent;
import com.willfp.eco.core.proxy.AbstractProxy;
import com.willfp.eco.core.proxy.ProxyConstants;
import com.willfp.eco.core.proxy.UnsupportedVersionException;
import org.jetbrains.annotations.NotNull;
import java.util.IdentityHashMap;
import java.util.Map;
public class ProxyFactory<T extends AbstractProxy> extends PluginDependent<EcoPlugin> {
/**
* 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 EcoPlugin 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;
}
}