Skip to content

Commit

Permalink
Fix AntiAura integration failing on startup (fixes #73)
Browse files Browse the repository at this point in the history
  • Loading branch information
2008Choco committed Dec 11, 2021
1 parent e53ace1 commit ef1069d
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import java.util.Set;
import java.util.UUID;

import org.apache.commons.lang.ClassUtils;
import org.apache.commons.lang.reflect.FieldUtils;
import org.apache.commons.lang.reflect.MethodUtils;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
Expand All @@ -18,7 +16,7 @@
*/
public final class AntiCheatHookAntiAura implements AntiCheatHook {

private Object antiAuraApi;
private Class<?> antiAuraApiClass;

private final Method methodIsExemptedFromFastBreak;
private final Method methodToggleExemptFromFastBreak;
Expand All @@ -33,13 +31,16 @@ public AntiCheatHookAntiAura(@NotNull VeinMiner plugin) {
this.compatible = true;

try {
this.antiAuraApi = FieldUtils.getField(ClassUtils.getClass("AntiAuraAPI"), "API").get(null);
this.antiAuraApiClass = Class.forName("AntiAuraAPI.API");
} catch (ReflectiveOperationException e) {
this.sendIncompatibleMessage();
this.methodIsExemptedFromFastBreak = null;
this.methodToggleExemptFromFastBreak = null;
return;
}

this.methodIsExemptedFromFastBreak = MethodUtils.getAccessibleMethod(antiAuraApi.getClass(), "isExemptedFromFastBreak", Player.class);
this.methodToggleExemptFromFastBreak = MethodUtils.getAccessibleMethod(antiAuraApi.getClass(), "toggleExemptFromFastBreak", Player.class);
this.methodIsExemptedFromFastBreak = MethodUtils.getAccessibleMethod(antiAuraApiClass, "isExemptedFromFastBreak", Player.class);
this.methodToggleExemptFromFastBreak = MethodUtils.getAccessibleMethod(antiAuraApiClass, "toggleExemptFromFastBreak", Player.class);

if (this.methodIsExemptedFromFastBreak == null || this.methodToggleExemptFromFastBreak == null) {
this.sendIncompatibleMessage();
Expand Down Expand Up @@ -70,12 +71,12 @@ public String getPluginName() {
@Override
public void exempt(@NotNull Player player) {
try {
if (isIncompatible() || Boolean.TRUE.equals(methodIsExemptedFromFastBreak.invoke(antiAuraApi, player))) {
if (isIncompatible() || Boolean.TRUE.equals(methodIsExemptedFromFastBreak.invoke(antiAuraApiClass, player))) {
return;
}

if (exempt.add(player.getUniqueId())) {
this.methodToggleExemptFromFastBreak.invoke(antiAuraApi, player);
this.methodToggleExemptFromFastBreak.invoke(antiAuraApiClass, player);
}
} catch (ReflectiveOperationException e) {
this.sendIncompatibleMessage();
Expand All @@ -90,7 +91,7 @@ public void unexempt(@NotNull Player player) {

if (exempt.remove(player.getUniqueId())) {
try {
this.methodToggleExemptFromFastBreak.invoke(antiAuraApi, player);
this.methodToggleExemptFromFastBreak.invoke(antiAuraApiClass, player);
} catch (ReflectiveOperationException e) {
this.sendIncompatibleMessage();
}
Expand Down

0 comments on commit ef1069d

Please sign in to comment.