Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b83a3dd548 | ||
|
|
7f41eab5e4 | ||
|
|
0d1c2364da | ||
|
|
5bca33a9f5 | ||
|
|
1196fe8004 | ||
|
|
98ae416fa7 |
@@ -20,7 +20,7 @@ dependencies {
|
||||
compileOnly 'fr.neatmonster:nocheatplus:3.16.1-SNAPSHOT'
|
||||
compileOnly 'com.github.jiangdashao:matrix-api-repo:317d4635fd'
|
||||
compileOnly 'org.jetbrains:annotations:19.0.0'
|
||||
compileOnly fileTree(dir: '/lib', include: ['*.jar'])
|
||||
compileOnly fileTree(dir: 'lib', include: ['*.jar'])
|
||||
|
||||
// Lombok
|
||||
compileOnly 'org.projectlombok:lombok:1.18.16'
|
||||
@@ -98,5 +98,5 @@ build.dependsOn publishToMavenLocal
|
||||
|
||||
group = 'com.willfp'
|
||||
archivesBaseName = project.name
|
||||
version = '1.0.1'
|
||||
version = '1.0.5'
|
||||
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
@@ -28,6 +28,7 @@ public abstract class BaseConfig extends PluginDependent implements ValueGetter
|
||||
/**
|
||||
* The physical config file, as stored on disk.
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final File configFile;
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,14 +7,21 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.function.Function;
|
||||
|
||||
@UtilityClass
|
||||
public final class TelekinesisUtils {
|
||||
private final Object instance;
|
||||
private final Class<?> clazz;
|
||||
|
||||
/**
|
||||
* The test service registered to bukkit.
|
||||
*/
|
||||
private final TelekinesisTests tests;
|
||||
private final Method testMethod;
|
||||
|
||||
private final Method registerMethod;
|
||||
|
||||
/**
|
||||
* Test the player for telekinesis.
|
||||
@@ -25,7 +32,13 @@ public final class TelekinesisUtils {
|
||||
* @return If the player is telekinetic.
|
||||
*/
|
||||
public boolean testPlayer(@NotNull final Player player) {
|
||||
return tests.testPlayer(player);
|
||||
try {
|
||||
return (boolean) testMethod.invoke(instance, player);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,14 +47,33 @@ public final class TelekinesisUtils {
|
||||
* @param test The test to register, where the boolean output is if the player is telekinetic.
|
||||
*/
|
||||
public void registerTest(@NotNull final Function<Player, Boolean> test) {
|
||||
tests.registerTest(test);
|
||||
try {
|
||||
registerMethod.invoke(instance, test);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
if (!Bukkit.getServicesManager().isProvidedFor(TelekinesisTests.class)) {
|
||||
Method testMethod1;
|
||||
Method registerMethod1;
|
||||
if (Bukkit.getServicesManager().getKnownServices().stream().noneMatch(clazz -> clazz.getName().contains("TelekinesisTests"))) {
|
||||
Bukkit.getServicesManager().register(TelekinesisTests.class, new EcoTelekinesisTests(), AbstractEcoPlugin.getInstance(), ServicePriority.Normal);
|
||||
}
|
||||
|
||||
tests = Bukkit.getServicesManager().load(TelekinesisTests.class);
|
||||
instance = Bukkit.getServicesManager().load(Bukkit.getServicesManager().getKnownServices().stream().filter(clazz -> clazz.getName().contains("TelekinesisTests")).findFirst().get());
|
||||
clazz = instance.getClass();
|
||||
|
||||
try {
|
||||
testMethod1 = clazz.getDeclaredMethod("testPlayer", Player.class);
|
||||
registerMethod1 = clazz.getDeclaredMethod("registerTest", Function.class);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
testMethod1 = null;
|
||||
registerMethod1 = null;
|
||||
}
|
||||
|
||||
testMethod = testMethod1;
|
||||
registerMethod = registerMethod1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -86,6 +87,18 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
@Getter
|
||||
private final String proxyPackage;
|
||||
|
||||
/**
|
||||
* The color of the plugin, used in messages.
|
||||
*/
|
||||
@Getter
|
||||
private final String color;
|
||||
|
||||
/**
|
||||
* Loaded integrations.
|
||||
*/
|
||||
@Getter
|
||||
private final Set<String> loadedIntegrations = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Set of external plugin integrations.
|
||||
*/
|
||||
@@ -159,15 +172,18 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
* @param resourceId The spigot resource ID for the plugin.
|
||||
* @param bStatsId The bStats resource ID for the plugin.
|
||||
* @param proxyPackage The package where proxy implementations are stored.
|
||||
* @param color The color of the plugin (used in messages, such as &a, &b)
|
||||
*/
|
||||
protected AbstractEcoPlugin(@NotNull final String pluginName,
|
||||
final int resourceId,
|
||||
final int bStatsId,
|
||||
@NotNull final String proxyPackage) {
|
||||
@NotNull final String proxyPackage,
|
||||
@NotNull final String color) {
|
||||
this.pluginName = pluginName;
|
||||
this.resourceId = resourceId;
|
||||
this.bStatsId = bStatsId;
|
||||
this.proxyPackage = proxyPackage;
|
||||
this.color = color;
|
||||
|
||||
this.log = new EcoLogger(this);
|
||||
this.scheduler = new EcoScheduler(this);
|
||||
@@ -187,10 +203,7 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
super.onLoad();
|
||||
|
||||
this.getLog().info("==========================================");
|
||||
this.getLog().info("");
|
||||
this.getLog().info("Loading &a" + this.pluginName);
|
||||
this.getLog().info("Made by &aAuxilor&f - willfp.com");
|
||||
this.getLog().info("");
|
||||
this.getLog().info("Loading " + this.color + this.pluginName);
|
||||
this.getLog().info("==========================================");
|
||||
|
||||
this.getEventManager().registerListener(new ArrowDataListener(this));
|
||||
@@ -219,16 +232,12 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
Set<String> enabledPlugins = Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(Plugin::getName).collect(Collectors.toSet());
|
||||
|
||||
this.getDefaultIntegrations().forEach((integrationLoader -> {
|
||||
StringBuilder infoBuilder = new StringBuilder();
|
||||
infoBuilder.append(integrationLoader.getPluginName()).append(": ");
|
||||
if (enabledPlugins.contains(integrationLoader.getPluginName())) {
|
||||
this.loadedIntegrations.add(integrationLoader.getPluginName());
|
||||
integrationLoader.load();
|
||||
infoBuilder.append("&aENABLED");
|
||||
} else {
|
||||
infoBuilder.append("&9DISABLED");
|
||||
}
|
||||
this.getLog().info(infoBuilder.toString());
|
||||
}));
|
||||
this.getLog().info("Loaded integrations: " + String.join(", ", this.getLoadedIntegrations()));
|
||||
this.getLog().info("");
|
||||
|
||||
Prerequisite.update();
|
||||
|
||||
Reference in New Issue
Block a user