mirror of
https://github.com/Auxilor/EcoArmor.git
synced 2026-01-06 15:42:07 +00:00
Updated to use eco 3 and revamped give command
This commit is contained in:
@@ -7,7 +7,6 @@ plugins {
|
||||
|
||||
dependencies {
|
||||
implementation project(":eco-core").getSubprojects()
|
||||
implementation 'com.willfp:eco:1.3.1'
|
||||
}
|
||||
|
||||
allprojects {
|
||||
@@ -48,7 +47,7 @@ allprojects {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'com.willfp:eco:1.3.1'
|
||||
compileOnly 'com.willfp:eco:3.0.0'
|
||||
|
||||
compileOnly 'org.jetbrains:annotations:19.0.0'
|
||||
|
||||
@@ -83,9 +82,6 @@ clean.doLast {
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
relocate('org.apache.maven', 'com.willfp.ecoarmor.eco.shaded.maven')
|
||||
relocate('org.bstats', 'com.willfp.ecoarmor.eco.shaded.bstats')
|
||||
relocate('com.willfp.eco.util', 'com.willfp.ecoarmor.eco.util') // Dot is to prevent plugin being shaded into itself
|
||||
archiveFileName = findProperty("plugin-name") + " v" + findProperty("version") + ".jar"
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.willfp.ecoarmor.effects.Effects;
|
||||
import com.willfp.ecoarmor.sets.ArmorSets;
|
||||
import com.willfp.ecoarmor.tiers.CrystalListener;
|
||||
import com.willfp.ecoarmor.tiers.UpgradeCrystal;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -24,11 +25,18 @@ import java.util.List;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class EcoArmorPlugin extends AbstractEcoPlugin {
|
||||
/**
|
||||
* Instance of EcoArmor
|
||||
*/
|
||||
@Getter
|
||||
private static EcoArmorPlugin instance;
|
||||
|
||||
/**
|
||||
* Internal constructor called by bukkit on plugin load.
|
||||
*/
|
||||
public EcoArmorPlugin() {
|
||||
super("EcoArmor", 0, 10002, "com.willfp.ecoarmor.proxy", "&5");
|
||||
super("EcoArmor", 0, 10002, "com.willfp.ecoarmor.proxy", "&c");
|
||||
instance = this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,11 +2,11 @@ package com.willfp.ecoarmor.commands;
|
||||
|
||||
import com.willfp.eco.util.command.AbstractCommand;
|
||||
import com.willfp.eco.util.command.AbstractTabCompleter;
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.ecoarmor.sets.ArmorSet;
|
||||
import com.willfp.ecoarmor.sets.ArmorSets;
|
||||
import com.willfp.ecoarmor.sets.meta.ArmorSlot;
|
||||
import com.willfp.ecoarmor.tiers.UpgradeCrystal;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -34,12 +34,12 @@ public class CommandEagive extends AbstractCommand {
|
||||
public void onExecute(@NotNull final CommandSender sender,
|
||||
@NotNull final List<String> args) {
|
||||
if (args.isEmpty()) {
|
||||
sender.sendMessage(Configs.LANG.getMessage("needs-player"));
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("needs-player"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.size() == 1) {
|
||||
sender.sendMessage(Configs.LANG.getMessage("needs-set"));
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("needs-item"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -47,22 +47,48 @@ public class CommandEagive extends AbstractCommand {
|
||||
Player reciever = Bukkit.getPlayer(recieverName);
|
||||
|
||||
if (reciever == null) {
|
||||
sender.sendMessage(Configs.LANG.getMessage("invalid-player"));
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-player"));
|
||||
return;
|
||||
}
|
||||
|
||||
String setName = args.get(1);
|
||||
ArmorSet set = ArmorSets.getByName(setName);
|
||||
if (set == null) {
|
||||
sender.sendMessage(Configs.LANG.getMessage("invalid-set"));
|
||||
String itemName = args.get(1);
|
||||
if (!itemName.contains(":")) {
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-item"));
|
||||
return;
|
||||
}
|
||||
|
||||
String message = Configs.LANG.getMessage("give-success");
|
||||
message = message.replace("%set%", set.getName()).replace("%recipient%", reciever.getName());
|
||||
sender.sendMessage(message);
|
||||
for (ArmorSlot slot : ArmorSlot.values()) {
|
||||
reciever.getInventory().addItem(set.getItemStack(slot));
|
||||
if (itemName.split(":")[0].equals("set")) {
|
||||
ArmorSet set = ArmorSets.getByName(itemName.split(":")[1]);
|
||||
if (set == null) {
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-item"));
|
||||
return;
|
||||
}
|
||||
|
||||
String message = this.getPlugin().getLangYml().getMessage("give-success");
|
||||
message = message.replace("%item%", set.getName() + " Set").replace("%recipient%", reciever.getName());
|
||||
sender.sendMessage(message);
|
||||
for (ArmorSlot slot : ArmorSlot.values()) {
|
||||
reciever.getInventory().addItem(set.getItemStack(slot));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (itemName.split(":")[0].equals("crystal")) {
|
||||
UpgradeCrystal crystal = UpgradeCrystal.getByName(itemName.split(":")[1]);
|
||||
if (crystal == null) {
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-item"));
|
||||
return;
|
||||
}
|
||||
|
||||
String message = this.getPlugin().getLangYml().getMessage("give-success");
|
||||
message = message.replace("%item%", crystal.getItemStack().getItemMeta().getDisplayName()).replace("%recipient%", reciever.getName());
|
||||
sender.sendMessage(message);
|
||||
reciever.getInventory().addItem(crystal.getItemStack());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-item"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.willfp.ecoarmor.commands;
|
||||
|
||||
import com.willfp.eco.util.command.AbstractCommand;
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -22,6 +21,6 @@ public class CommandEareload extends AbstractCommand {
|
||||
public void onExecute(@NotNull final CommandSender sender,
|
||||
@NotNull final List<String> args) {
|
||||
this.getPlugin().reload();
|
||||
sender.sendMessage(Configs.LANG.getMessage("reloaded"));
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("reloaded"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ package com.willfp.ecoarmor.commands;
|
||||
import com.willfp.eco.util.command.AbstractCommand;
|
||||
import com.willfp.eco.util.command.AbstractTabCompleter;
|
||||
import com.willfp.eco.util.config.updating.annotations.ConfigUpdater;
|
||||
import com.willfp.ecoarmor.sets.ArmorSet;
|
||||
import com.willfp.ecoarmor.sets.ArmorSets;
|
||||
import com.willfp.ecoarmor.tiers.UpgradeCrystal;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -21,13 +21,14 @@ public class TabcompleterEagive extends AbstractTabCompleter {
|
||||
/**
|
||||
* The cached enchantment names.
|
||||
*/
|
||||
private static final List<String> SET_NAMES = ArmorSets.values().stream().map(ArmorSet::getName).collect(Collectors.toList());
|
||||
private static final List<String> SET_NAMES = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Instantiate a new tab-completer for /eagive.
|
||||
*/
|
||||
public TabcompleterEagive() {
|
||||
super((AbstractCommand) Objects.requireNonNull(Bukkit.getPluginCommand("eagive")).getExecutor());
|
||||
reload();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,7 +37,8 @@ public class TabcompleterEagive extends AbstractTabCompleter {
|
||||
@ConfigUpdater
|
||||
public static void reload() {
|
||||
SET_NAMES.clear();
|
||||
SET_NAMES.addAll(ArmorSets.values().stream().map(ArmorSet::getName).collect(Collectors.toList()));
|
||||
SET_NAMES.addAll(ArmorSets.values().stream().map(armorSet -> "set:" + armorSet.getName()).collect(Collectors.toList()));
|
||||
SET_NAMES.addAll(UpgradeCrystal.values().stream().map(crystal -> "crystal:" + crystal.getTier()).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.willfp.ecoarmor.config.configs;
|
||||
|
||||
import com.willfp.eco.util.config.BaseConfig;
|
||||
import com.willfp.ecoarmor.EcoArmorPlugin;
|
||||
|
||||
public class Sets extends BaseConfig {
|
||||
/**
|
||||
* sets.yml.
|
||||
*/
|
||||
public Sets() {
|
||||
super("sets", false);
|
||||
super("sets", false, EcoArmorPlugin.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.willfp.ecoarmor.display;
|
||||
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.ecoarmor.EcoArmorPlugin;
|
||||
import com.willfp.ecoarmor.sets.ArmorSet;
|
||||
import com.willfp.ecoarmor.sets.meta.ArmorSlot;
|
||||
import com.willfp.ecoarmor.sets.util.ArmorUtils;
|
||||
@@ -101,7 +101,7 @@ public class ArmorDisplay {
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
for (String s : slotMeta.getLore()) {
|
||||
lore.add(s.replace("%tier%", Configs.CONFIG.getString("tier." + tier + ".display")));
|
||||
lore.add(s.replace("%tier%", EcoArmorPlugin.getInstance().getLangYml().getString("tier." + tier + ".display")));
|
||||
}
|
||||
|
||||
meta.setLore(lore);
|
||||
|
||||
@@ -4,10 +4,10 @@ import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
|
||||
import com.willfp.ecoarmor.proxy.proxies.ChatComponentProxy;
|
||||
import com.willfp.ecoarmor.util.ProxyUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.willfp.ecoarmor.effects;
|
||||
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.ecoarmor.EcoArmorPlugin;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -11,7 +11,7 @@ public abstract class Effect<T> implements Listener {
|
||||
* Instance of EcoArmor.
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final AbstractEcoPlugin plugin = AbstractEcoPlugin.getInstance();
|
||||
private final EcoArmorPlugin plugin = EcoArmorPlugin.getInstance();
|
||||
|
||||
/**
|
||||
* The name of the effect.
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package com.willfp.ecoarmor.sets;
|
||||
|
||||
import com.willfp.eco.common.recipes.lookup.RecipePartUtils;
|
||||
import com.willfp.eco.util.ProxyUtils;
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.recipe.EcoShapedRecipe;
|
||||
import com.willfp.eco.util.recipe.lookup.RecipePartUtils;
|
||||
import com.willfp.ecoarmor.EcoArmorPlugin;
|
||||
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.util.ProxyUtils;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
@@ -37,7 +37,7 @@ public class ArmorSet {
|
||||
/**
|
||||
* Instance of EcoArmor.
|
||||
*/
|
||||
private static final AbstractEcoPlugin PLUGIN = AbstractEcoPlugin.getInstance();
|
||||
private static final EcoArmorPlugin PLUGIN = EcoArmorPlugin.getInstance();
|
||||
|
||||
/**
|
||||
* The name of the set.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.willfp.ecoarmor.sets.util;
|
||||
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.ecoarmor.EcoArmorPlugin;
|
||||
import com.willfp.ecoarmor.effects.Effect;
|
||||
import com.willfp.ecoarmor.sets.ArmorSet;
|
||||
import com.willfp.ecoarmor.sets.ArmorSets;
|
||||
@@ -25,7 +25,7 @@ public class ArmorUtils {
|
||||
/**
|
||||
* Instance of EcoArmor.
|
||||
*/
|
||||
private static final AbstractEcoPlugin PLUGIN = AbstractEcoPlugin.getInstance();
|
||||
private static final EcoArmorPlugin PLUGIN = EcoArmorPlugin.getInstance();
|
||||
|
||||
/**
|
||||
* Get armor set on an item.
|
||||
|
||||
@@ -2,13 +2,13 @@ package com.willfp.ecoarmor.tiers;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.willfp.eco.common.recipes.lookup.RecipePartUtils;
|
||||
import com.willfp.eco.common.recipes.parts.ComplexRecipePart;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.eco.util.config.updating.annotations.ConfigUpdater;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.recipe.EcoShapedRecipe;
|
||||
import com.willfp.eco.util.recipe.lookup.RecipePartUtils;
|
||||
import com.willfp.eco.util.recipe.parts.ComplexRecipePart;
|
||||
import com.willfp.ecoarmor.EcoArmorPlugin;
|
||||
import com.willfp.ecoarmor.display.ArmorDisplay;
|
||||
import com.willfp.ecoarmor.sets.util.ArmorUtils;
|
||||
import lombok.Getter;
|
||||
@@ -47,10 +47,10 @@ public class UpgradeCrystal {
|
||||
public static final UpgradeCrystal NETHERITE = new UpgradeCrystal("netherite");
|
||||
|
||||
/**
|
||||
* Instance of ItemStats to create keys for.
|
||||
* Instance of EcoArmor to create keys for.
|
||||
*/
|
||||
@Getter
|
||||
private final AbstractEcoPlugin plugin = AbstractEcoPlugin.getInstance();
|
||||
private final EcoArmorPlugin plugin = EcoArmorPlugin.getInstance();
|
||||
|
||||
/**
|
||||
* The tier of the crystal.
|
||||
@@ -91,7 +91,7 @@ public class UpgradeCrystal {
|
||||
* Update the tracker's crafting recipe.
|
||||
*/
|
||||
public void update() {
|
||||
this.enabled = Configs.CONFIG.getBool("tier." + tier + ".crystal-craftable");
|
||||
this.enabled = plugin.getConfigYml().getBool("tier." + tier + ".crystal-craftable");
|
||||
NamespacedKey key = this.getPlugin().getNamespacedKeyFactory().create("upgrade_crystal");
|
||||
|
||||
ItemStack out = new ItemStack(Material.END_CRYSTAL);
|
||||
@@ -100,10 +100,10 @@ public class UpgradeCrystal {
|
||||
PersistentDataContainer container = outMeta.getPersistentDataContainer();
|
||||
container.set(key, PersistentDataType.STRING, tier);
|
||||
|
||||
outMeta.setDisplayName(Configs.CONFIG.getString("tier." + tier + ".crystal-name"));
|
||||
outMeta.setDisplayName(plugin.getConfigYml().getString("tier." + tier + ".crystal-name"));
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
for (String loreLine : Configs.CONFIG.getStrings("tier." + tier + ".crystal-lore")) {
|
||||
for (String loreLine : plugin.getConfigYml().getStrings("tier." + tier + ".crystal-lore")) {
|
||||
lore.add(ArmorDisplay.PREFIX + StringUtils.translate(loreLine));
|
||||
}
|
||||
outMeta.setLore(lore);
|
||||
@@ -115,7 +115,7 @@ public class UpgradeCrystal {
|
||||
EcoShapedRecipe.Builder builder = EcoShapedRecipe.builder(this.getPlugin(), "upgrade_crystal_" + tier)
|
||||
.setOutput(out);
|
||||
|
||||
List<String> recipeStrings = Configs.CONFIG.getStrings("tier." + tier + ".crystal-recipe");
|
||||
List<String> recipeStrings = plugin.getConfigYml().getStrings("tier." + tier + ".crystal-recipe");
|
||||
|
||||
RecipePartUtils.registerLookup("ecoarmor:upgrade_crystal_" + tier, s -> new ComplexRecipePart(test -> Objects.equals(tier, ArmorUtils.getCrystalTier(test)), out));
|
||||
|
||||
@@ -138,6 +138,15 @@ public class UpgradeCrystal {
|
||||
return BY_NAME.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all registered {@link UpgradeCrystal}s.
|
||||
*
|
||||
* @return A list of all {@link UpgradeCrystal}s.
|
||||
*/
|
||||
public static List<UpgradeCrystal> values() {
|
||||
return ImmutableList.copyOf(BY_NAME.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
messages:
|
||||
prefix: "&5&lEcoArmor&r &8» &r"
|
||||
prefix: "&c&lEcoArmor&r &8» &r"
|
||||
no-permission: "&cYou don't have permission to do this!"
|
||||
not-player: "&cThis command must be run by a player"
|
||||
reloaded: "Reloaded! (Restart if you're removed armor sets!)"
|
||||
needs-player: "&cYou must specify a player"
|
||||
invalid-player: "&cInvalid player!"
|
||||
needs-set: "&cYou must specify a set"
|
||||
invalid-set: "&cInvalid set!"
|
||||
give-success: "Gave &a%set% Set&r to &a%recipient%"
|
||||
needs-item: "&cYou must specify an item!"
|
||||
invalid-item: "&cInvalid item!"
|
||||
give-success: "Gave &a%item%&r to &a%recipient%"
|
||||
|
||||
description-color: "&8"
|
||||
@@ -6,6 +6,7 @@ authors: [ Auxilor ]
|
||||
website: willfp.com
|
||||
load: STARTUP
|
||||
depend:
|
||||
- eco
|
||||
- ProtocolLib
|
||||
softdepend:
|
||||
- WorldGuard
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user