Skip to content

Instantly share code, notes, and snippets.

@riking
Created May 14, 2014 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riking/6d2965debbffc5f3c857 to your computer and use it in GitHub Desktop.
Save riking/6d2965debbffc5f3c857 to your computer and use it in GitHub Desktop.
package eu.phiwa.dt.anticheatplugins;
import org.bukkit.entity.Player;
public interface AbstractHandler {
public void startExempting(Player player);
public void stopExempting(Player player);
}
package eu.phiwa.dt.anticheatplugins;
import net.h31ix.anticheat.api.AnticheatAPI;
import org.bukkit.entity.Player;
public class AntiCheatHandler implements AbstractHandler {
static {
// This throws an exception if the class isn't loaded
AnticheatAPI.getManager();
}
@Override
public void startExempting(Player player) {
if (!AnticheatAPI.isExempt(player, net.h31ix.anticheat.manage.CheckType.FLY)) {
AnticheatAPI.exemptPlayer(player, net.h31ix.anticheat.manage.CheckType.FLY);
}
}
@Override
public void stopExempting(Player player) {
if (AnticheatAPI.isExempt(player, net.h31ix.anticheat.manage.CheckType.FLY)) {
AnticheatAPI.unexemptPlayer(player, net.h31ix.anticheat.manage.CheckType.FLY);
}
}
}
package eu.phiwa.dt.anticheatplugins;
import org.bukkit.entity.Player;
import eu.phiwa.dt.DragonTravelMain;
public class CheatProtectionHandler {
private static NoCheatPlusHandler ncpHandle = null;
private static AntiCheatHandler acHandle = null;
public static void setup() {
try {
acHandle = new AntiCheatHandler();
} catch (Throwable t) {
acHandle = null;
}
if (acHandle != null) {
DragonTravelMain.plugin.getLogger().info("[DragonTravel] AntiCheat support enabled");
}
try {
ncpHandle = new NoCheatPlusHandler();
} catch (Throwable t) {
ncpHandle = null;
}
if (ncpHandle != null) {
DragonTravelMain.plugin.getLogger().info("[DragonTravel] NoCheatPlus support enabled");
}
}
/**
* Exempts a player from the Cheat-check of AntiCheat-plugins
*
* @param player the player to exempt from the check
*/
public static void exemptPlayerFromCheatChecks(Player player) {
// AntiCheat
if (acHandle != null) {
acHandle.startExempting(player);
}
// NoCheatPlus
if (ncpHandle != null) {
ncpHandle.startExempting(player);
}
}
/**
* Unexempts a player from the Cheat-check of AntiCheat-plugins
*
* @param player the player to unexempt from the check
*/
public static void unexemptPlayerFromCheatChecks(Player player) {
// AntiCheat
if (acHandle != null) {
acHandle.stopExempting(player);
}
// NoCheatPlus
if (ncpHandle != null) {
ncpHandle.stopExempting(player);
}
}
}
package eu.phiwa.dt.anticheatplugins;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager;
public class NoCheatPlusHandler implements AbstractHandler {
static {
// This throws an exception if the class isn't loaded
NCPExemptionManager.getListener();
}
@Override
public void startExempting(Player player) {
if (!NCPExemptionManager.isExempted(player, CheckType.MOVING_SURVIVALFLY) || !NCPExemptionManager.isExempted(player, CheckType.MOVING_CREATIVEFLY)) {
NCPExemptionManager.exemptPermanently(player, CheckType.MOVING_SURVIVALFLY);
NCPExemptionManager.exemptPermanently(player, CheckType.MOVING_CREATIVEFLY);
}
}
@Override
public void stopExempting(Player player) {
if (NCPExemptionManager.isExempted(player, CheckType.MOVING_SURVIVALFLY) || NCPExemptionManager.isExempted(player, CheckType.MOVING_CREATIVEFLY)) {
NCPExemptionManager.unexempt(player, CheckType.MOVING_SURVIVALFLY);
NCPExemptionManager.unexempt(player, CheckType.MOVING_CREATIVEFLY);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment