Compare commits

...

3 Commits
1.0.3 ... 1.0.5

Author SHA1 Message Date
Auxilor
b83a3dd548 Fixed TelekinesisUtils and updated to 1.0.5 2021-01-05 09:09:05 +00:00
Auxilor
7f41eab5e4 Fixed compileOnly issues with jitpack 2021-01-04 12:46:00 +00:00
Auxilor
0d1c2364da Fixed telekinesistests registration and updated to 1.0.4 2021-01-04 12:45:05 +00:00
2 changed files with 39 additions and 7 deletions

View File

@@ -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.3'
version = '1.0.5'
java.sourceCompatibility = JavaVersion.VERSION_1_8

View File

@@ -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;
}
}