-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update LightAntiCheat's hook implementation (fixes #120)
- Loading branch information
Showing
4 changed files
with
28 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 23 additions & 46 deletions
69
...miner-bukkit/src/main/java/wtf/choco/veinminer/anticheat/AntiCheatHookLightAntiCheat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,52 @@ | ||
package wtf.choco.veinminer.anticheat; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import com.google.common.collect.Multimap; | ||
import com.google.common.collect.MultimapBuilder; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import org.apache.commons.lang.reflect.MethodUtils; | ||
import me.vekster.lightanticheat.api.CheckType; | ||
import me.vekster.lightanticheat.api.DetectionStatus; | ||
import me.vekster.lightanticheat.api.LACApi; | ||
|
||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import wtf.choco.veinminer.VeinMinerPlugin; | ||
|
||
/** | ||
* The default LightAntiCheat hook implementation. | ||
*/ | ||
public final class AntiCheatHookLightAntiCheat implements AntiCheatHook { | ||
|
||
private Class<?> lightAntiCheatApiClass; | ||
private Method methodIsApiBypass, methodSetApiBypass; | ||
|
||
private boolean supported; | ||
|
||
private final Set<UUID> exempt = new HashSet<>(); | ||
|
||
public AntiCheatHookLightAntiCheat(@NotNull VeinMinerPlugin plugin) { | ||
try { | ||
this.lightAntiCheatApiClass = Class.forName("vekster.lightanticheat.api.Utils"); | ||
this.methodIsApiBypass = MethodUtils.getAccessibleMethod(lightAntiCheatApiClass, "isApiBypass", Player.class); | ||
this.methodSetApiBypass = MethodUtils.getAccessibleMethod(lightAntiCheatApiClass, "setApiBypass", new Class[] { | ||
Player.class, Boolean.TYPE | ||
}); | ||
|
||
this.supported = (methodIsApiBypass != null && methodSetApiBypass != null); | ||
} catch (ReflectiveOperationException e) { | ||
plugin.getLogger().severe("The version of LightAntiCheat on this server is incompatible with Veinminer. Please post information on the spigot resource discussion page."); | ||
e.printStackTrace(); | ||
} | ||
} | ||
private final Multimap<UUID, String> exempt = MultimapBuilder.hashKeys().arrayListValues().build(); | ||
|
||
@Override | ||
public void exempt(@NotNull Player player) { | ||
try { | ||
if (Boolean.TRUE.equals(methodIsApiBypass.invoke(null, player))) { | ||
return; | ||
} | ||
List<String> checks = new ArrayList<>(); | ||
|
||
if (exempt.add(player.getUniqueId())) { | ||
this.methodSetApiBypass.invoke(null, player, true); | ||
LACApi api = LACApi.getInstance(); | ||
for (String checkName : api.getCheckNames(CheckType.ALL)) { | ||
if (api.getDetectionStatus(player, checkName) == DetectionStatus.ENABLED) { | ||
api.disableDetection(player, checkName); | ||
checks.add(checkName); | ||
} | ||
} catch (ReflectiveOperationException e) { } // Ignore | ||
} | ||
|
||
this.exempt.putAll(player.getUniqueId(), checks); | ||
} | ||
|
||
@Override | ||
public void unexempt(@NotNull Player player) { | ||
if (!exempt.remove(player.getUniqueId())) { | ||
return; | ||
LACApi api = LACApi.getInstance(); | ||
for (String checkName : exempt.removeAll(player.getUniqueId())) { | ||
api.enableDetection(player, checkName); | ||
} | ||
|
||
try { | ||
this.methodSetApiBypass.invoke(null, player, false); | ||
} catch (ReflectiveOperationException e) { } // Ignore | ||
} | ||
|
||
@Override | ||
public boolean shouldUnexempt(@NotNull Player player) { | ||
return exempt.contains(player.getUniqueId()); | ||
} | ||
|
||
@Override | ||
public boolean isSupported() { | ||
return supported; | ||
return exempt.containsKey(player.getUniqueId()); | ||
} | ||
|
||
} |