Compare commits

..
45 Commits
Author SHA1 Message Date
Rammelkast acea36929b Nevermind 2020-02-28 12:57:24 +01:00
Rammelkast 8da9d7f365 Add Travis CI 2020-02-28 12:55:18 +01:00
Rammelkast c9c3b2397f Updated Metrics, made small code changes 2020-02-28 12:40:27 +01:00
Rammelkast a140afe33e Update copyright 2020-02-27 21:01:10 +01:00
Rammelkast 08c484bfb1 Merge branch 'master' of https://github.com/Rammelkast/AntiCheatReloaded 2020-02-27 20:48:11 +01:00
Rammelkast ae66b0ed3c Changes 2020-02-27 20:47:46 +01:00
Rammelkast 0963458be5 Updated to 1.15, fixed issues and made changes to some checks 2020-02-27 20:46:20 +01:00
BuildTools d9639c81d9 Updated to 1.15, fixed issues and made changes to some checks 2020-02-27 20:44:47 +01:00
Rammelkast 0428c4796a Merge branch 'master' of https://github.com/Rammelkast/AntiCheatReloaded 2018-08-15 20:29:14 +02:00
Rammelkast 8e92077bb6 More small changes 2018-08-15 20:28:52 +02:00
Rammelkast 9d32c8f2de Create CNAME 2018-08-14 22:55:01 +02:00
Rammelkast d6917b81f7 Set theme jekyll-theme-cayman 2018-08-14 22:54:16 +02:00
Rammelkast 1a64403223 Update copyright & big fixes 2018-08-14 22:42:46 +02:00
Rammelkast 7ae3f010a3 Fixes regarding 1.9+ support 2018-08-14 11:37:17 +02:00
marcomoesman 06c1eab2e6 Fixed a lot of things. Plugin should work a lot better on 1.12 now. 2018-08-13 14:36:05 +02:00
Rammelkast f609758d28 Ready for Minecraft 1.12 2017-11-20 19:34:51 +01:00
Rammelkast 2d064ee849 1.12 fixes 2017-11-18 17:04:03 +01:00
Rammelkast 717b7acb67 Quick metrics fix 2017-11-18 16:55:20 +01:00
Rammelkast 2617aa1225 Cleanup 2017-05-06 16:00:08 +02:00
Rammelkast dd8c495ee6 Modify Metrics data & fix 2017-03-03 12:40:30 +01:00
Rammelkast 09ddbfba8f Fixed stuff, added new metrics graphs 2017-03-02 15:08:45 +01:00
Rammelkast 7f13a0ad4c Renamed package and groupId 2017-02-05 13:47:13 +01:00
Rammelkast 21d0108c16 Added extra strings to NameGenerator for more randomization 2017-02-05 13:42:31 +01:00
Rammelkast 15181ab6ad Cleanup 2017-02-05 13:34:51 +01:00
Rammelkast 347eec8ff0 Added glide check 2017-02-05 13:34:26 +01:00
Rammelkast 518e4c32e7 Fix #32 2017-02-04 20:45:55 +01:00
Rammelkast 583d2de244 Fix #33 2017-02-04 20:44:34 +01:00
Rammelkast 792a4ae0a5 Replace mcstats metrics with bStats metrics 2017-02-04 20:43:28 +01:00
Rammelkast 406ba01523 Fix #27 2017-01-15 16:44:42 +01:00
Rammelkast b2571a32f1 Fix #29 2017-01-15 16:27:24 +01:00
Rammelkast 52b96bedc4 Add metrics 2017-01-15 16:12:41 +01:00
Rammelkast 01602e187c Update Readme 2017-01-03 16:23:27 +01:00
Rammelkast db13527498 Fix #26 2017-01-03 16:14:29 +01:00
Rammelkast 1e4aaab2c0 Fix #21 2016-12-01 15:30:24 +01:00
Rammelkast 3baa074b6f Remove debug messages 2016-11-22 17:57:17 +01:00
Rammelkast b264bb1e43 Fix #18 2016-11-22 17:56:18 +01:00
Rammelkast 57d7ee9b62 Fix #17 and #19 2016-11-22 17:32:31 +01:00
Rammelkast 24125e9195 YAxis is now REALLY fixed in 1.8 :3 2016-11-18 16:48:40 +01:00
Rammelkast eca5a60d22 Fixed YAxis check for 1.8, removed messages 2016-11-18 16:48:00 +01:00
Rammelkast 8e4cef9a7d Changed magic, stronger default blink check 2016-11-18 16:44:15 +01:00
Rammelkast db821e4809 Plugin should now work on 1.7.10, started on Glide v2 2016-11-18 16:42:21 +01:00
Rammelkast c229252f7a Glide is just broken. 2016-11-18 16:38:57 +01:00
Rammelkast 93a5595bb1 Change version and remember that the Glide check is broken af 2016-11-18 16:38:15 +01:00
Rammelkast 92f5f30188 Fixed #6 a while ago, forgot to mark it as fixed. 2016-11-18 16:34:28 +01:00
Rammelkast 8773c05000 1.11 update 2016-11-17 19:03:05 +01:00
99 changed files with 4408 additions and 3742 deletions

No files matched your search

+21 -18
View File
@@ -1,13 +1,28 @@
AntiCheatReloaded AntiCheatReloaded
============= =============
AntiCheatReloaded is a fork of the old 'AntiCheat' project. AntiCheatReloaded helps server admins easily identify and block malicious users by monitoring and analyzing the behaviour of their players. It is based on one of the oldest anti-cheats in the community, AntiCheat.
AntiCheat helps server admins easily identify and block malicious users by monitoring and analyzing the behaviour of their players.
###Want to help me out? + BTC donations: bc1q5qgmzq9e63h7ptf3kneg78uf0mghtwsmvwxt8m
First of all, i've put a lot of time and work in this project, so donations (especially in (m)BTC) are appreciated! + LTC donations: LYZLe6AGRQZTey5UHe7CCF3e9HAyQooSmh
My BTC address is 1JfyX6hvGUazHTtKVLaNcYaUxnyjR5HtMY + ETH donations: 0x2a2171fB3600fc67951734c2872E0Ad742741Cf2
###Hacks blocked Bug Reporting
------------
Issues should be filed by hitting the [issues](https://github.com/Rammelkast/AntiCheatReloaded/issues?state=open) tab above. Please make sure you search your issue before opening a new ticket.
Please include the following information with your issue, this allows me to fix it quicker;
* The `/anticheat debug` log
* Your AntiCheatReloaded version
* Your server software (Bukkit/Spigot/Other) and it's version
* If you use ProtocolLib, your ProtocolLib version
* Whether or not you are using protocol hacks (ViaVersion etc.)
Usage
-------
Simply drag and drop the plugin file and the ProtocolLib jar into your Plugins folder.
Hacks blocked
------- -------
* Blink * Blink
* Flight * Flight
@@ -15,7 +30,6 @@ My BTC address is 1JfyX6hvGUazHTtKVLaNcYaUxnyjR5HtMY
* Jesus * Jesus
* Step * Step
* Criticals * Criticals
* KillAura
* Anti-Knockback * Anti-Knockback
* FastBow * FastBow
* FastDrop * FastDrop
@@ -30,14 +44,3 @@ My BTC address is 1JfyX6hvGUazHTtKVLaNcYaUxnyjR5HtMY
* FastPlace * FastPlace
* Spam * Spam
* FastEat * FastEat
Usage
-------
Simply drag and drop the plugin and the ProtoclLib into your Plugins folder.
Bug Reporting/Support/Questions
------------
Issues should be filed by hitting the [issues](https://github.com/Rammelkast/AntiCheatReloaded/issues?state=open) tab above. Please make sure you search your issue before opening a new ticket.
All opened tickets that are bug reports require a debug log that includes logs of the issue in question. To obtain this, type `/anticheat debug` on your server. Note that for the debug output to contain valid information and help us diagnose your issue, you need to issue this command AFTER the issue occurs at least once and BEFORE you reload or restart it.
+92 -109
View File
@@ -1,110 +1,93 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <?xml version="1.0" encoding="UTF-8"?>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>net.gravitydevelopment.anticheat</groupId> <groupId>com.rammelkast.anticheatreloaded</groupId>
<artifactId>AntiCheat</artifactId> <artifactId>AntiCheatReloaded</artifactId>
<version>1.5.1-ALPHA</version> <version>1.7.1-ALPHA</version>
<name>AntiCheatReloaded</name> <name>AntiCheatReloaded</name>
<url>https://rammelkast.com</url> <url>https://rammelkast.com</url>
<properties> <properties>
<project.build.version>${project.version}</project.build.version> <project.build.version>${project.version}</project.build.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<repositories> <repositories>
<repository> <repository>
<id>dmulloy2-repo</id> <id>dmulloy2-repo</id>
<url>http://repo.dmulloy2.net/content/groups/public/</url> <url>https://repo.dmulloy2.net/nexus/repository/public/</url>
</repository> </repository>
<repository> </repositories>
<id>spigot-repo</id> <build>
<url>http://maven.elmakers.com/repository/</url> <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
</repository> <plugins>
</repositories> <plugin>
<build> <groupId>org.apache.maven.plugins</groupId>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory> <artifactId>maven-compiler-plugin</artifactId>
<plugins> <version>3.5</version>
<plugin> <configuration>
<groupId>org.apache.maven.plugins</groupId> <source>1.8</source>
<artifactId>maven-compiler-plugin</artifactId> <target>1.8</target>
<version>3.1</version> </configuration>
<configuration> </plugin>
<source>1.6</source> <plugin>
<target>1.6</target> <groupId>org.apache.maven.plugins</groupId>
</configuration> <artifactId>maven-shade-plugin</artifactId>
</plugin> <version>3.1.1</version>
<plugin> <executions>
<groupId>org.apache.maven.plugins</groupId> <execution>
<artifactId>maven-shade-plugin</artifactId> <phase>package</phase>
<version>1.3</version> <goals>
<executions> <goal>shade</goal>
<execution> </goals>
<phase>package</phase> </execution>
<goals> </executions>
<goal>shade</goal> <configuration>
</goals> <artifactSet>
</execution> <includes>
</executions> <include>com.rammelkast.*</include>
<configuration> </includes>
<artifactSet> </artifactSet>
<includes> </configuration>
<include>net.gravitydevelopment.*</include> </plugin>
</includes> </plugins>
</artifactSet> <finalName>AntiCheatReloaded</finalName>
</configuration> <extensions>
</plugin> <extension>
</plugins> <groupId>org.apache.maven.wagon</groupId>
<finalName>AntiCheatReloaded</finalName> <artifactId>wagon-file</artifactId>
<extensions> <version>2.2</version>
<extension> </extension>
<groupId>org.apache.maven.wagon</groupId> </extensions>
<artifactId>wagon-file</artifactId> <resources>
<version>2.2</version> <resource>
</extension> <directory>src/main/resources</directory>
</extensions> <filtering>true</filtering>
<resources> </resource>
<resource> </resources>
<directory>src/main/resources</directory> </build>
<filtering>true</filtering> <profiles>
</resource> <profile>
</resources> <id>jenkins</id>
</build> <activation>
<profiles> <property>
<profile> <name>env.BUILD_NUMBER</name>
<id>jenkins</id> </property>
<activation> </activation>
<property> <properties>
<name>env.BUILD_NUMBER</name> <project.build.version>${project.version}-b${env.BUILD_NUMBER}</project.build.version>
</property> </properties>
</activation> </profile>
<properties> </profiles>
<project.build.version>${project.version}-b${env.BUILD_NUMBER}</project.build.version> <dependencies>
</properties> <dependency>
</profile> <groupId>com.comphenix.protocol</groupId>
</profiles> <artifactId>ProtocolLib</artifactId>
<dependencies> <version>4.5.0</version>
<dependency> </dependency>
<groupId>com.comphenix.protocol</groupId> <dependency>
<artifactId>ProtocolLib</artifactId> <groupId>org.spigotmc</groupId>
<version>4.1.0-SNAPSHOT</version> <artifactId>spigot</artifactId>
</dependency> <version>1.15.2-R0.1-SNAPSHOT</version>
<dependency> <scope>provided</scope>
<groupId>junit</groupId> </dependency>
<artifactId>junit</artifactId> </dependencies>
<version>4.11</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.10-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<distributionManagement>
<repository>
<id>anticheat-repo</id>
<url>file:///var/lib/jenkins/repo</url>
</repository>
</distributionManagement>
</project> </project>
@@ -0,0 +1,320 @@
/*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.Callable;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.rammelkast.anticheatreloaded.check.movement.BlinkCheck;
import com.rammelkast.anticheatreloaded.command.CommandHandler;
import com.rammelkast.anticheatreloaded.config.Configuration;
import com.rammelkast.anticheatreloaded.event.BlockListener;
import com.rammelkast.anticheatreloaded.event.EntityListener;
import com.rammelkast.anticheatreloaded.event.InventoryListener;
import com.rammelkast.anticheatreloaded.event.PlayerListener;
import com.rammelkast.anticheatreloaded.event.VehicleListener;
import com.rammelkast.anticheatreloaded.manage.AntiCheatManager;
import com.rammelkast.anticheatreloaded.metrics.Metrics;
import com.rammelkast.anticheatreloaded.util.User;
import com.rammelkast.anticheatreloaded.util.VersionUtil;
public class AntiCheatReloaded extends JavaPlugin {
private static AntiCheatManager manager;
private static AntiCheatReloaded plugin;
private static List<Listener> eventList = new ArrayList<Listener>();
private static Configuration config;
private static boolean verbose;
private static boolean developer;
private static ProtocolManager protocolManager;
private static SecureRandom random;
private static Long loadTime;
@Override
public void onEnable() {
plugin = this;
random = new SecureRandom();
loadTime = System.currentTimeMillis();
manager = new AntiCheatManager(this, getLogger());
eventList.add(new PlayerListener());
eventList.add(new BlockListener());
eventList.add(new EntityListener());
eventList.add(new VehicleListener());
eventList.add(new InventoryListener());
// Order is important in some cases, don't screw with these unless
// needed, especially config
this.setupConfig();
this.setupEvents();
this.setupCommands();
// Enterprise must come before levels
this.setupEnterprise();
this.restoreLevels();
if (Bukkit.getPluginManager().getPlugin("ProtocolLib") != null) {
this.setupProtocol();
} else {
Bukkit.getConsoleSender().sendMessage("[ACR] " + ChatColor.RED + "Shutting down, ProtocolLib not found!");
Bukkit.getPluginManager().disablePlugin(this);
return;
}
getLogger().info("NMS version is " + VersionUtil.getVersion());
if (!VersionUtil.isSupported()) {
Bukkit.getConsoleSender().sendMessage("[ACR] " + ChatColor.RED + "The version of this server is NOT supported by ACR! The plugin will be buggy!");
}
getLogger().info("Found ProtocolLib, enabling checks that use ProtcolLib...");
// Enable packetlisteners
BlinkCheck.startTimer();
BlinkCheck.listenPackets();
// Check if other AC's are installed
Bukkit.getScheduler().runTaskLater(this, new Runnable() {
public void run() {
if (Bukkit.getPluginManager().getPlugin("NoCheatPlus") != null) {
getLogger().severe("*----------------------------------------------*");
getLogger().severe("You are also running NoCheatPlus!");
getLogger().severe("Multiple anticheats create false cheat detections.");
getLogger().severe("Please remove or disable NoCheatPlus to silence this warning.");
getLogger().severe("*----------------------------------------------*");
}
if (Bukkit.getPluginManager().getPlugin("Matrix") != null) {
getLogger().severe("*----------------------------------------------*");
getLogger().severe("You are also running Matrix!");
getLogger().severe("Multiple anticheats create false cheat detections.");
getLogger().severe("Please remove or disable NoCheatPlus to silence this warning.");
getLogger().severe("*----------------------------------------------*");
}
if (Bukkit.getPluginManager().getPlugin("AAC") != null) {
getLogger().severe("*----------------------------------------------*");
getLogger().severe("You are also running AAC!");
getLogger().severe("Multiple anticheats create false cheat detections.");
getLogger().severe("Please remove or disable AAC to silence this warning.");
getLogger().severe("*----------------------------------------------*");
}
if (Bukkit.getPluginManager().getPlugin("Spartan") != null) {
getLogger().severe("*----------------------------------------------*");
getLogger().severe("You are also running Spartan!");
getLogger().severe("Multiple anticheats create false cheat detections.");
getLogger().severe("Please remove or disable AAC to silence this warning.");
getLogger().severe("*----------------------------------------------*");
}
if (Bukkit.getPluginManager().getPlugin("NoAura") != null) {
getLogger().severe("*----------------------------------------------*");
getLogger().severe("You are also running NoAura!");
getLogger().severe("Multiple anticheats create false cheat detections.");
getLogger().severe("Please remove or disable AAC to silence this warning.");
getLogger().severe("*----------------------------------------------*");
}
if (Bukkit.getPluginManager().getPlugin("AntiCheat") != null || Bukkit.getPluginManager().getPlugin("AntiCheatPlus") != null) {
getLogger().severe("*----------------------------------------------*");
getLogger().severe("You are also running AntiCheat!");
getLogger().severe("Multiple anticheats create false cheat detections.");
getLogger().severe("Please remove or disable AntiCheat to silence this warning.");
getLogger().severe("*----------------------------------------------*");
}
}
}, 90L);
// End tests
verboseLog("Finished loading.");
// Metrics
try {
Metrics metrics = new Metrics(this, 202);
metrics.addCustomChart(new Metrics.SingleLineChart("cheaters_kicked", new Callable<Integer>() {
@Override
public Integer call() throws Exception {
int kicked = playersKicked;
// Reset so we don't keep sending the same value
playersKicked = 0;
return kicked;
}
}));
metrics.addCustomChart(new Metrics.SingleLineChart("glide_violations", new Callable<Integer>() {
@Override
public Integer call() throws Exception {
int violations = glideViolations;
// Reset so we don't keep sending the same value
glideViolations = 0;
return violations;
}
}));
metrics.addCustomChart(new Metrics.SimplePie("protocollib_version", new Callable<String>() {
@Override
public String call() throws Exception {
return Bukkit.getPluginManager().getPlugin("ProtocolLib").getDescription().getVersion();
}
}));
metrics.addCustomChart(new Metrics.SimplePie("nms_version", new Callable<String>() {
@Override
public String call() throws Exception {
return VersionUtil.getVersion();
}
}));
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onDisable() {
verboseLog("Saving user levels...");
config.getLevels().saveLevelsFromUsers(getManager().getUserManager().getUsers());
AntiCheatManager.close();
getServer().getScheduler().cancelTasks(this);
cleanup();
}
private void setupProtocol() {
protocolManager = ProtocolLibrary.getProtocolManager();
verboseLog("Hooked into ProtocolLib");
}
private void setupEvents() {
for (Listener listener : eventList) {
getServer().getPluginManager().registerEvents(listener, this);
verboseLog("Registered events for ".concat(listener.toString().split("@")[0].split(".anticheat.")[1]));
}
}
private void setupCommands() {
getCommand("anticheat").setExecutor(new CommandHandler());
verboseLog("Registered commands.");
}
private void setupConfig() {
config = manager.getConfiguration();
verboseLog("Setup the config.");
}
private void setupEnterprise() {
if (config.getConfig().enterprise.getValue()) {
if (config.getEnterprise().loggingEnabled.getValue()) {
config.getEnterprise().database.cleanEvents();
}
}
}
private void restoreLevels() {
for (Player player : getServer().getOnlinePlayers()) {
UUID uuid = player.getUniqueId();
User user = new User(uuid);
user.setIsWaitingOnLevelSync(true);
config.getLevels().loadLevelToUser(user);
manager.getUserManager().addUser(user);
verboseLog("Data for " + uuid + " loaded");
}
}
public static AntiCheatReloaded getPlugin() {
return plugin;
}
public static AntiCheatManager getManager() {
return manager;
}
public static SecureRandom getRandom() {
return random;
}
public static String getVersion() {
return manager.getPlugin().getDescription().getVersion();
}
private void cleanup() {
eventList = null;
manager = null;
config = null;
}
public static boolean developerMode() {
return developer;
}
public static void setDeveloperMode(boolean b) {
developer = b;
}
public static void debugLog(final String string) {
Bukkit.getScheduler().runTask(getPlugin(), new Runnable() {
public void run() {
if (developer) {
manager.debugLog("[DEBUG] " + string);
}
}
});
}
public void verboseLog(final String string) {
if (verbose) {
getLogger().info(string);
}
}
public void setVerbose(boolean b) {
verbose = b;
}
public Long getLoadTime() {
return loadTime;
}
public static ProtocolManager getProtocolManager() {
return protocolManager;
}
/**
* Amount of players kicked since start
*/
private int playersKicked = 0;
/**
* Amount of glide violations since start
*/
private int glideViolations = 0;
public void onPlayerKicked() {
this.playersKicked++;
}
public void onGlideViolation() {
this.glideViolations++;
}
public static void sendToMainThread(Runnable runnable) {
Bukkit.getServer().getScheduler().runTask(AntiCheatReloaded.getPlugin(), runnable);
}
}
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,26 +17,26 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.api; package com.rammelkast.anticheatreloaded.api;
import java.util.List; import java.util.List;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import net.gravitydevelopment.anticheat.AntiCheat; import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import net.gravitydevelopment.anticheat.check.CheckType; import com.rammelkast.anticheatreloaded.check.CheckType;
import net.gravitydevelopment.anticheat.manage.AntiCheatManager; import com.rammelkast.anticheatreloaded.manage.AntiCheatManager;
import net.gravitydevelopment.anticheat.manage.CheckManager; import com.rammelkast.anticheatreloaded.manage.CheckManager;
import net.gravitydevelopment.anticheat.manage.UserManager; import com.rammelkast.anticheatreloaded.manage.UserManager;
import net.gravitydevelopment.anticheat.util.Group; import com.rammelkast.anticheatreloaded.util.Group;
/** /**
* Developer's interface for all things AntiCheat. * Developer's interface for all things AntiCheat.
*/ */
public class AntiCheatAPI { public class AntiCheatAPI {
private static CheckManager chk = AntiCheat.getManager().getCheckManager(); private static CheckManager chk = AntiCheatReloaded.getManager().getCheckManager();
private static UserManager umr = AntiCheat.getManager().getUserManager(); private static UserManager umr = AntiCheatReloaded.getManager().getUserManager();
// CheckManager API // CheckManager API
@@ -44,7 +45,7 @@ public class AntiCheatAPI {
* *
* @param type Check to start watching for * @param type Check to start watching for
*/ */
public static void activateCheck(CheckType type, Class caller) { public static void activateCheck(CheckType type, Class<?> caller) {
chk.activateCheck(type, caller.getName()); chk.activateCheck(type, caller.getName());
} }
@@ -53,7 +54,7 @@ public class AntiCheatAPI {
* *
* @param type Check to stop watching for * @param type Check to stop watching for
*/ */
public static void deactivateCheck(CheckType type, Class caller) { public static void deactivateCheck(CheckType type, Class<?> caller) {
chk.deactivateCheck(type, caller.getName()); chk.deactivateCheck(type, caller.getName());
} }
@@ -73,7 +74,7 @@ public class AntiCheatAPI {
* @param player Player to stop watching * @param player Player to stop watching
* @param type Check to stop watching for * @param type Check to stop watching for
*/ */
public static void exemptPlayer(Player player, CheckType type, Class caller) { public static void exemptPlayer(Player player, CheckType type, Class<?> caller) {
chk.exemptPlayer(player, type, caller.getName()); chk.exemptPlayer(player, type, caller.getName());
} }
@@ -83,7 +84,7 @@ public class AntiCheatAPI {
* @param player Player to start watching * @param player Player to start watching
* @param type Check to start watching for * @param type Check to start watching for
*/ */
public static void unexemptPlayer(Player player, CheckType type, Class caller) { public static void unexemptPlayer(Player player, CheckType type, Class<?> caller) {
chk.unexemptPlayer(player, type, caller.getName()); chk.unexemptPlayer(player, type, caller.getName());
} }
@@ -111,31 +112,6 @@ public class AntiCheatAPI {
// PlayerManager API // PlayerManager API
/**
* Get a player's integer hack level
*
* @param player Player to check
* @return player's hack level
* @deprecated see {@link #getGroup(org.bukkit.entity.Player)}
*/
@Deprecated
public static int getLevel(Player player) {
return umr.safeGetLevel(player.getUniqueId());
}
/**
* Set a player's hack level
*
* @param player Player to set
* @param level Group to set to
* @deprecated see {@link #resetPlayer(org.bukkit.entity.Player)}
*/
@Deprecated
public static void setLevel(Player player, int level) {
umr.safeSetLevel(player.getUniqueId(), level);
}
/** /**
* Reset a player's hack level to 0 * Reset a player's hack level to 0
* *
@@ -146,7 +122,7 @@ public class AntiCheatAPI {
} }
/** /**
* Get a user's {@link net.gravitydevelopment.anticheat.util.Group} * Get a user's {@link com.rammelkast.anticheatreloaded.util.Group}
* *
* @param player Player whose group to find * @param player Player whose group to find
* @return The player's group * @return The player's group
@@ -159,7 +135,7 @@ public class AntiCheatAPI {
* Get all configured Groups * Get all configured Groups
* *
* @return List of all groups * @return List of all groups
* @see net.gravitydevelopment.anticheat.util.Group * @see com.rammelkast.anticheatreloaded.util.Group
*/ */
public static List<Group> getGroups() { public static List<Group> getGroups() {
return getManager().getConfiguration().getGroups().getGroups(); return getManager().getConfiguration().getGroups().getGroups();
@@ -173,7 +149,7 @@ public class AntiCheatAPI {
* @return the AntiCheat Manager * @return the AntiCheat Manager
*/ */
public static AntiCheatManager getManager() { public static AntiCheatManager getManager() {
return AntiCheat.getManager(); return AntiCheatReloaded.getManager();
} }
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,13 +17,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.api; package com.rammelkast.anticheatreloaded.api;
import net.gravitydevelopment.anticheat.check.CheckType;
import net.gravitydevelopment.anticheat.util.User;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import com.rammelkast.anticheatreloaded.check.CheckType;
import com.rammelkast.anticheatreloaded.util.User;
/** /**
* Fired when a player fails an AntiCheat check * Fired when a player fails an AntiCheat check
*/ */
@@ -40,18 +42,18 @@ public class CheckFailEvent extends Event {
} }
/** /**
* Get the {@link net.gravitydevelopment.anticheat.util.User} who failed the check * Get the {@link com.rammelkast.anticheatreloaded.util.User} who failed the check
* *
* @return a {@link net.gravitydevelopment.anticheat.util.User} * @return a {@link com.rammelkast.anticheatreloaded.util.User}
*/ */
public User getUser() { public User getUser() {
return user; return user;
} }
/** /**
* Get the {@link net.gravitydevelopment.anticheat.check.CheckType} failed * Get the {@link com.rammelkast.anticheatreloaded.check.CheckType} failed
* *
* @return a {@link net.gravitydevelopment.anticheat.check.CheckType} * @return a {@link com.rammelkast.anticheatreloaded.check.CheckType}
*/ */
public CheckType getCheck() { public CheckType getCheck() {
return type; return type;
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,8 +17,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.check; package com.rammelkast.anticheatreloaded.check;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@@ -25,7 +27,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@@ -37,23 +38,22 @@ import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerToggleSprintEvent; import org.bukkit.event.player.PlayerToggleSprintEvent;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import net.gravitydevelopment.anticheat.AntiCheat; import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import net.gravitydevelopment.anticheat.check.combat.KillAuraCheck; import com.rammelkast.anticheatreloaded.check.combat.VelocityCheck;
import net.gravitydevelopment.anticheat.check.combat.VelocityCheck; import com.rammelkast.anticheatreloaded.check.movement.BlinkCheck;
import net.gravitydevelopment.anticheat.check.movement.BlinkCheck; import com.rammelkast.anticheatreloaded.check.movement.FlightCheck;
import net.gravitydevelopment.anticheat.check.movement.FlightCheck; import com.rammelkast.anticheatreloaded.check.movement.GlideCheck;
import net.gravitydevelopment.anticheat.check.movement.GlideCheck; import com.rammelkast.anticheatreloaded.check.movement.SpeedCheck;
import net.gravitydevelopment.anticheat.check.movement.SpeedCheck; import com.rammelkast.anticheatreloaded.check.movement.WaterWalkCheck;
import net.gravitydevelopment.anticheat.check.movement.WaterWalkCheck; import com.rammelkast.anticheatreloaded.check.movement.YAxisCheck;
import net.gravitydevelopment.anticheat.check.movement.YAxisCheck; import com.rammelkast.anticheatreloaded.config.Configuration;
import net.gravitydevelopment.anticheat.config.Configuration; import com.rammelkast.anticheatreloaded.config.providers.Lang;
import net.gravitydevelopment.anticheat.config.providers.Lang; import com.rammelkast.anticheatreloaded.config.providers.Magic;
import net.gravitydevelopment.anticheat.config.providers.Magic; import com.rammelkast.anticheatreloaded.manage.AntiCheatManager;
import net.gravitydevelopment.anticheat.manage.AntiCheatManager; import com.rammelkast.anticheatreloaded.util.Distance;
import net.gravitydevelopment.anticheat.util.Distance; import com.rammelkast.anticheatreloaded.util.User;
import net.gravitydevelopment.anticheat.util.User; import com.rammelkast.anticheatreloaded.util.Utilities;
import net.gravitydevelopment.anticheat.util.Utilities; import com.rammelkast.anticheatreloaded.util.VersionUtil;
import net.gravitydevelopment.anticheat.util.VersionUtil;
public class Backend { public class Backend {
private List<UUID> isAscending = new ArrayList<UUID>(); private List<UUID> isAscending = new ArrayList<UUID>();
@@ -120,29 +120,28 @@ public class Backend {
UUID pU = player.getUniqueId(); UUID pU = player.getUniqueId();
VelocityCheck.cleanPlayer(player); VelocityCheck.cleanPlayer(player);
KillAuraCheck.cleanPlayer(player);
BlinkCheck.MOVE_COUNT.remove(player.getUniqueId()); BlinkCheck.MOVE_COUNT.remove(player.getUniqueId());
blocksDropped.remove(pU); blocksDropped.remove(pU);
blockTime.remove(pU); blockTime.remove(pU);
FlightCheck.movingExempt.remove(pU); FlightCheck.MOVING_EXEMPT.remove(pU);
brokenBlock.remove(pU); brokenBlock.remove(pU);
placedBlock.remove(pU); placedBlock.remove(pU);
bowWindUp.remove(pU); bowWindUp.remove(pU);
startEat.remove(pU); startEat.remove(pU);
lastHeal.remove(pU); lastHeal.remove(pU);
sprinted.remove(pU); sprinted.remove(pU);
WaterWalkCheck.isInWater.remove(pU); WaterWalkCheck.IS_IN_WATER.remove(pU);
WaterWalkCheck.isInWaterCache.remove(pU); WaterWalkCheck.IS_IN_WATER_CACHE.remove(pU);
instantBreakExempt.remove(pU); instantBreakExempt.remove(pU);
isAscending.remove(player.getUniqueId()); isAscending.remove(player.getUniqueId());
ascensionCount.remove(player.getUniqueId()); ascensionCount.remove(player.getUniqueId());
FlightCheck.blocksOverFlight.remove(pU); FlightCheck.BLOCKS_OVER_FLIGHT.remove(pU);
nofallViolation.remove(pU); nofallViolation.remove(pU);
fastBreakViolation.remove(pU); fastBreakViolation.remove(pU);
YAxisCheck.yAxisViolations.remove(pU); YAxisCheck.Y_AXIS_VIOLATIONS.remove(pU);
YAxisCheck.yAxisLastViolation.remove(pU); YAxisCheck.LAST_Y_AXIS_VIOLATION.remove(pU);
YAxisCheck.lastYcoord.remove(pU); YAxisCheck.LAST_Y_COORD_CACHE.remove(pU);
YAxisCheck.lastYtime.remove(pU); YAxisCheck.LAST_Y_TIME.remove(pU);
fastBreaks.remove(pU); fastBreaks.remove(pU);
blockBreakHolder.remove(pU); blockBreakHolder.remove(pU);
lastBlockBroken.remove(pU); lastBlockBroken.remove(pU);
@@ -150,8 +149,8 @@ public class Backend {
lastBlockPlaced.remove(pU); lastBlockPlaced.remove(pU);
lastBlockPlaceTime.remove(pU); lastBlockPlaceTime.remove(pU);
blockPunches.remove(pU); blockPunches.remove(pU);
WaterWalkCheck.waterAscensionViolation.remove(pU); WaterWalkCheck.WATER_ASCENSION_VIOLATIONS.remove(pU);
WaterWalkCheck.waterSpeedViolation.remove(pU); WaterWalkCheck.WATER_SPEED_VIOLATIONS.remove(pU);
projectilesShot.remove(pU); projectilesShot.remove(pU);
velocitized.remove(pU); velocitized.remove(pU);
velocitytrack.remove(pU); velocitytrack.remove(pU);
@@ -163,20 +162,24 @@ public class Backend {
sprinted.remove(pU); sprinted.remove(pU);
brokenBlock.remove(pU); brokenBlock.remove(pU);
placedBlock.remove(pU); placedBlock.remove(pU);
FlightCheck.movingExempt.remove(pU); FlightCheck.MOVING_EXEMPT.remove(pU);
blockTime.remove(pU); blockTime.remove(pU);
blocksDropped.remove(pU); blocksDropped.remove(pU);
lastInventoryTime.remove(pU); lastInventoryTime.remove(pU);
inventoryTime.remove(pU); inventoryTime.remove(pU);
inventoryClicks.remove(pU); inventoryClicks.remove(pU);
lastFallPacket.remove(pU); lastFallPacket.remove(pU);
GlideCheck.lastYDelta.remove(pU); GlideCheck.LAST_DIFFERENCE.remove(pU);
GlideCheck.glideBuffer.remove(pU); GlideCheck.LAST_FALL_DISTANCE.remove(pU);
SpeedCheck.speedViolation.remove(player.getUniqueId()); GlideCheck.VIOLATIONS.remove(pU);
SpeedCheck.SPEED_VIOLATIONS.remove(player.getUniqueId());
} }
public CheckResult checkFastBow(Player player, float force) { public CheckResult checkFastBow(Player player, float force) {
// Ignore magic numbers here, they are minecrafty vanilla stuff. // Ignore magic numbers here, they are minecrafty vanilla stuff.
if (!bowWindUp.containsKey(player.getUniqueId())) {
return PASS;
}
int ticks = (int) ((((System.currentTimeMillis() - bowWindUp.get(player.getUniqueId())) * 20) / 1000) + 3); int ticks = (int) ((((System.currentTimeMillis() - bowWindUp.get(player.getUniqueId())) * 20) / 1000) + 3);
bowWindUp.remove(player.getUniqueId()); bowWindUp.remove(player.getUniqueId());
float f = (float) ticks / 20.0F; float f = (float) ticks / 20.0F;
@@ -258,7 +261,7 @@ public class Backend {
} }
public CheckResult checkYSpeed(Player player, double y) { public CheckResult checkYSpeed(Player player, double y) {
if (!isMovingExempt(player) && !player.isInsideVehicle() && !player.isSleeping() && y > magic.Y_SPEED_MAX() && !isDoing(player, velocitized, magic.VELOCITY_TIME()) && !player.hasPotionEffect(PotionEffectType.JUMP)) { if (!isMovingExempt(player) && !player.isInsideVehicle() && !player.isSleeping() && (y > magic.Y_SPEED_MAX()) && !isDoing(player, velocitized, magic.VELOCITY_TIME()) && !player.hasPotionEffect(PotionEffectType.JUMP) && !VersionUtil.isFlying(player)) {
return new CheckResult(CheckResult.Result.FAILED, player.getName() + "'s y speed was too high (speed=" + y + ", max=" + magic.Y_SPEED_MAX() + ")"); return new CheckResult(CheckResult.Result.FAILED, player.getName() + "'s y speed was too high (speed=" + y + ", max=" + magic.Y_SPEED_MAX() + ")");
} else { } else {
return PASS; return PASS;
@@ -291,7 +294,7 @@ public class Backend {
} }
public CheckResult checkSneak(Player player, double x, double z) { public CheckResult checkSneak(Player player, double x, double z) {
if (player.isSneaking() && !player.isFlying() && !isMovingExempt(player) && !player.isInsideVehicle()) { if (player.isSneaking() && !VersionUtil.isFlying(player) && !isMovingExempt(player) && !player.isInsideVehicle()) {
double i = x > magic.XZ_SPEED_MAX_SNEAK() ? x : z > magic.XZ_SPEED_MAX_SNEAK() ? z : -1; double i = x > magic.XZ_SPEED_MAX_SNEAK() ? x : z > magic.XZ_SPEED_MAX_SNEAK() ? z : -1;
if (i != -1) { if (i != -1) {
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " was sneaking too fast (speed=" + i + ", max=" + magic.XZ_SPEED_MAX_SNEAK() + ")"); return new CheckResult(CheckResult.Result.FAILED, player.getName() + " was sneaking too fast (speed=" + i + ", max=" + magic.XZ_SPEED_MAX_SNEAK() + ")");
@@ -410,7 +413,7 @@ public class Backend {
string = " with jump potion"; string = " with jump potion";
} }
Block block = player.getLocation().getBlock(); Block block = player.getLocation().getBlock();
if (!isMovingExempt(player) && !Utilities.isInWater(player) && !justBroke(player) && !Utilities.isClimbableBlock(player.getLocation().getBlock()) && !player.isInsideVehicle() && !YAxisCheck.isMoveUpBlock(player.getLocation().add(0, -1, 0).getBlock()) && !YAxisCheck.isMoveUpBlock(player.getLocation().add(0, -1.5, 0).getBlock())) { if (!isMovingExempt(player) && !Utilities.isInWater(player) && !VersionUtil.isFlying(player) && !justBroke(player) && !Utilities.isClimbableBlock(player.getLocation().getBlock()) && !player.isInsideVehicle() && !YAxisCheck.isMoveUpBlock(player.getLocation().add(0, -1, 0).getBlock()) && !YAxisCheck.isMoveUpBlock(player.getLocation().add(0, -1.5, 0).getBlock())) {
if (y1 < y2) { if (y1 < y2) {
if (!block.getRelative(BlockFace.NORTH).isLiquid() && !block.getRelative(BlockFace.SOUTH).isLiquid() && !block.getRelative(BlockFace.EAST).isLiquid() && !block.getRelative(BlockFace.WEST).isLiquid()) { if (!block.getRelative(BlockFace.NORTH).isLiquid() && !block.getRelative(BlockFace.SOUTH).isLiquid() && !block.getRelative(BlockFace.EAST).isLiquid() && !block.getRelative(BlockFace.WEST).isLiquid()) {
increment(player, ascensionCount, max); increment(player, ascensionCount, max);
@@ -428,7 +431,7 @@ public class Backend {
public CheckResult checkSwing(Player player, Block block) { public CheckResult checkSwing(Player player, Block block) {
UUID uuid = player.getUniqueId(); UUID uuid = player.getUniqueId();
if (!isInstantBreakExempt(player)) { if (!isInstantBreakExempt(player)) {
if (!player.getInventory().getItemInHand().containsEnchantment(Enchantment.DIG_SPEED) && !(player.getInventory().getItemInHand().getType() == Material.SHEARS && block.getType() == Material.LEAVES)) { if (!VersionUtil.getItemInHand(player).containsEnchantment(Enchantment.DIG_SPEED) && !(VersionUtil.getItemInHand(player).getType() == Material.SHEARS && block.getType().name().endsWith("LEAVES"))) {
if (blockPunches.get(uuid) != null && player.getGameMode() != GameMode.CREATIVE) { if (blockPunches.get(uuid) != null && player.getGameMode() != GameMode.CREATIVE) {
int i = blockPunches.get(uuid); int i = blockPunches.get(uuid);
if (i < magic.BLOCK_PUNCH_MIN()) { if (i < magic.BLOCK_PUNCH_MIN()) {
@@ -444,7 +447,7 @@ public class Backend {
public CheckResult checkFastBreak(Player player, Block block) { public CheckResult checkFastBreak(Player player, Block block) {
int violations = magic.FASTBREAK_MAXVIOLATIONS(); int violations = magic.FASTBREAK_MAXVIOLATIONS();
long timemax = isInstantBreakExempt(player) ? 0 : Utilities.calcSurvivalFastBreak(player.getInventory().getItemInHand(), block.getType()); long timemax = isInstantBreakExempt(player) ? 0 : Utilities.calcSurvivalFastBreak(VersionUtil.getItemInHand(player), block.getType());
if (player.getGameMode() == GameMode.CREATIVE) { if (player.getGameMode() == GameMode.CREATIVE) {
violations = magic.FASTBREAK_MAXVIOLATIONS_CREATIVE(); violations = magic.FASTBREAK_MAXVIOLATIONS_CREATIVE();
timemax = magic.FASTBREAK_TIMEMAX_CREATIVE(); timemax = magic.FASTBREAK_TIMEMAX_CREATIVE();
@@ -457,9 +460,6 @@ public class Backend {
int i = fastBreakViolation.get(uuid); int i = fastBreakViolation.get(uuid);
if (i > violations && math < magic.FASTBREAK_MAXVIOLATIONTIME()) { if (i > violations && math < magic.FASTBREAK_MAXVIOLATIONTIME()) {
lastBlockBroken.put(uuid, System.currentTimeMillis()); lastBlockBroken.put(uuid, System.currentTimeMillis());
if (!silentMode()) {
player.sendMessage(ChatColor.RED + "[AntiCheat] Fastbreaking detected. Please wait 10 seconds before breaking blocks.");
}
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " broke blocks too fast " + i + " times in a row (max=" + violations + ")"); return new CheckResult(CheckResult.Result.FAILED, player.getName() + " broke blocks too fast " + i + " times in a row (max=" + violations + ")");
} else if (fastBreakViolation.get(uuid) > 0 && math > magic.FASTBREAK_MAXVIOLATIONTIME()) { } else if (fastBreakViolation.get(uuid) > 0 && math > magic.FASTBREAK_MAXVIOLATIONTIME()) {
fastBreakViolation.put(uuid, 0); fastBreakViolation.put(uuid, 0);
@@ -516,17 +516,14 @@ public class Backend {
fastPlaceViolation.put(uuid, 0); fastPlaceViolation.put(uuid, 0);
} }
} else if (fastPlaceViolation.containsKey(uuid) && fastPlaceViolation.get(uuid) > violations) { } else if (fastPlaceViolation.containsKey(uuid) && fastPlaceViolation.get(uuid) > violations) {
AntiCheat.debugLog("Noted that fastPlaceViolation contains key " + uuid + " with value " + fastPlaceViolation.get(uuid)); AntiCheatReloaded.debugLog("Noted that fastPlaceViolation contains key " + uuid + " with value " + fastPlaceViolation.get(uuid));
Long math = System.currentTimeMillis() - lastBlockPlaced.get(uuid); Long math = System.currentTimeMillis() - lastBlockPlaced.get(uuid);
AntiCheat.debugLog("Player lastBlockPlaced value = " + lastBlockPlaced + ", diff=" + math); AntiCheatReloaded.debugLog("Player lastBlockPlaced value = " + lastBlockPlaced + ", diff=" + math);
if (lastBlockPlaced.get(uuid) > 0 && math < magic.FASTPLACE_MAXVIOLATIONTIME()) { if (lastBlockPlaced.get(uuid) > 0 && math < magic.FASTPLACE_MAXVIOLATIONTIME()) {
lastBlockPlaced.put(uuid, time); lastBlockPlaced.put(uuid, time);
if (!silentMode()) {
player.sendMessage(ChatColor.RED + "[AntiCheat] Fastplacing detected. Please wait 10 seconds before placing blocks.");
}
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " placed blocks too fast " + fastBreakViolation.get(uuid) + " times in a row (max=" + violations + ")"); return new CheckResult(CheckResult.Result.FAILED, player.getName() + " placed blocks too fast " + fastBreakViolation.get(uuid) + " times in a row (max=" + violations + ")");
} else if (lastBlockPlaced.get(uuid) > 0 && math > magic.FASTPLACE_MAXVIOLATIONTIME()) { } else if (lastBlockPlaced.get(uuid) > 0 && math > magic.FASTPLACE_MAXVIOLATIONTIME()) {
AntiCheat.debugLog("Reset facePlaceViolation for " + uuid); AntiCheatReloaded.debugLog("Reset facePlaceViolation for " + uuid);
fastPlaceViolation.put(uuid, 0); fastPlaceViolation.put(uuid, 0);
} }
} else if (lastBlockPlaced.containsKey(uuid)) { } else if (lastBlockPlaced.containsKey(uuid)) {
@@ -587,6 +584,20 @@ public class Backend {
return PASS; return PASS;
} }
public CheckResult checkChatUnicode(Player player, String msg) {
UUID uuid = player.getUniqueId();
User user = manager.getUserManager().getUser(uuid);
if (!isPureAscii(msg)) {
return new CheckResult(CheckResult.Result.FAILED, "Unicode chat is not allowed.");
}
user.addMessage(msg);
return PASS;
}
private boolean isPureAscii(String v) {
return StandardCharsets.US_ASCII.newEncoder().canEncode(v.replaceAll("¡", "!").replaceAll("¿", "?"));
}
public CheckResult checkCommandSpam(Player player, String cmd) { public CheckResult checkCommandSpam(Player player, String cmd) {
UUID uuid = player.getUniqueId(); UUID uuid = player.getUniqueId();
User user = manager.getUserManager().getUser(uuid); User user = manager.getUserManager().getUser(uuid);
@@ -637,8 +648,8 @@ public class Backend {
} }
public CheckResult checkAutoTool(Player player) { public CheckResult checkAutoTool(Player player) {
if (itemInHand.containsKey(player.getUniqueId()) && itemInHand.get(player.getUniqueId()) != player.getItemInHand().getType()) { if (itemInHand.containsKey(player.getUniqueId()) && itemInHand.get(player.getUniqueId()) != VersionUtil.getItemInHand(player).getType()) {
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " switched tools too fast (had " + itemInHand.get(player.getName()) + ", has " + player.getItemInHand().getType() + ")"); return new CheckResult(CheckResult.Result.FAILED, player.getName() + " switched tools too fast (had " + itemInHand.get(player.getUniqueId()) + ", has " + VersionUtil.getItemInHand(player).getType() + ")");
} else { } else {
return PASS; return PASS;
} }
@@ -655,10 +666,11 @@ public class Backend {
public CheckResult checkFastHeal(Player player) { public CheckResult checkFastHeal(Player player) {
if (lastHeal.containsKey(player.getUniqueId())) // Otherwise it was modified by a plugin, don't worry about it. if (lastHeal.containsKey(player.getUniqueId())) // Otherwise it was modified by a plugin, don't worry about it.
{ {
long healTime = VersionUtil.getHealTime();
long l = lastHeal.get(player.getUniqueId()); long l = lastHeal.get(player.getUniqueId());
lastHeal.remove(player.getUniqueId()); lastHeal.remove(player.getUniqueId());
if ((System.currentTimeMillis() - l) < magic.HEAL_TIME_MIN()) { if ((System.currentTimeMillis() - l) < healTime) {
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " healed too quickly (time=" + (System.currentTimeMillis() - l) + " ms, min=" + magic.HEAL_TIME_MIN() + " ms)"); return new CheckResult(CheckResult.Result.FAILED, player.getName() + " healed too quickly (time=" + (System.currentTimeMillis() - l) + " ms, min=" + healTime + " ms)");
} }
} }
return PASS; return PASS;
@@ -689,8 +701,8 @@ public class Backend {
} }
public boolean isHoveringOverWaterAfterViolation(Player player) { public boolean isHoveringOverWaterAfterViolation(Player player) {
if (WaterWalkCheck.waterSpeedViolation.containsKey(player.getUniqueId())) { if (WaterWalkCheck.WATER_SPEED_VIOLATIONS.containsKey(player.getUniqueId())) {
if (WaterWalkCheck.waterSpeedViolation.get(player.getUniqueId()) >= magic.WATER_SPEED_VIOLATION_MAX() && Utilities.isHoveringOverWater(player.getLocation())) { if (WaterWalkCheck.WATER_SPEED_VIOLATIONS.get(player.getUniqueId()) >= magic.WATER_SPEED_VIOLATION_MAX() && Utilities.isHoveringOverWater(player.getLocation())) {
return true; return true;
} }
} }
@@ -757,42 +769,43 @@ public class Backend {
break; break;
} }
FlightCheck.movingExempt.put(player.getUniqueId(), System.currentTimeMillis() + time); FlightCheck.MOVING_EXEMPT.put(player.getUniqueId(), System.currentTimeMillis() + time);
// Only map in which termination time is calculated beforehand. // Only map in which termination time is calculated beforehand.
} }
public void logEnterExit(final Player player) { public void logEnterExit(final Player player) {
FlightCheck.movingExempt.put(player.getUniqueId(), System.currentTimeMillis() + magic.ENTERED_EXITED_TIME()); FlightCheck.MOVING_EXEMPT.put(player.getUniqueId(), System.currentTimeMillis() + magic.ENTERED_EXITED_TIME());
} }
public void logToggleSneak(final Player player) { public void logToggleSneak(final Player player) {
FlightCheck.movingExempt.put(player.getUniqueId(), System.currentTimeMillis() + magic.SNEAK_TIME()); FlightCheck.MOVING_EXEMPT.put(player.getUniqueId(), System.currentTimeMillis() + magic.SNEAK_TIME());
} }
public void logTeleport(final Player player) { public void logTeleport(final Player player) {
FlightCheck.movingExempt.put(player.getUniqueId(), System.currentTimeMillis() + magic.TELEPORT_TIME()); FlightCheck.MOVING_EXEMPT.put(player.getUniqueId(), System.currentTimeMillis() + magic.TELEPORT_TIME());
/* Data for fly/speed should be reset */ /* Data for fly/speed should be reset */
nofallViolation.remove(player.getUniqueId()); nofallViolation.remove(player.getUniqueId());
FlightCheck.blocksOverFlight.remove(player.getUniqueId()); FlightCheck.BLOCKS_OVER_FLIGHT.remove(player.getUniqueId());
YAxisCheck.yAxisViolations.remove(player.getUniqueId()); YAxisCheck.Y_AXIS_VIOLATIONS.remove(player.getUniqueId());
YAxisCheck.yAxisLastViolation.remove(player.getUniqueId()); YAxisCheck.LAST_Y_AXIS_VIOLATION.remove(player.getUniqueId());
YAxisCheck.lastYcoord.remove(player.getUniqueId()); YAxisCheck.LAST_Y_COORD_CACHE.remove(player.getUniqueId());
YAxisCheck.lastYtime.remove(player.getUniqueId()); YAxisCheck.LAST_Y_TIME.remove(player.getUniqueId());
GlideCheck.lastYDelta.remove(player.getUniqueId()); GlideCheck.LAST_FALL_DISTANCE.remove(player.getUniqueId());
GlideCheck.glideBuffer.remove(player.getUniqueId()); GlideCheck.LAST_DIFFERENCE.remove(player.getUniqueId());
GlideCheck.VIOLATIONS.remove(player.getUniqueId());
} }
public void logExitFly(final Player player) { public void logExitFly(final Player player) {
FlightCheck.movingExempt.put(player.getUniqueId(), System.currentTimeMillis() + magic.EXIT_FLY_TIME()); FlightCheck.MOVING_EXEMPT.put(player.getUniqueId(), System.currentTimeMillis() + magic.EXIT_FLY_TIME());
} }
public void logJoin(final Player player) { public void logJoin(final Player player) {
FlightCheck.movingExempt.put(player.getUniqueId(), System.currentTimeMillis() + magic.JOIN_TIME()); FlightCheck.MOVING_EXEMPT.put(player.getUniqueId(), System.currentTimeMillis() + magic.JOIN_TIME());
} }
public boolean isMovingExempt(Player player) { public boolean isMovingExempt(Player player) {
return isDoing(player, FlightCheck.movingExempt, -1); return isDoing(player, FlightCheck.MOVING_EXEMPT, -1);
} }
public boolean isAscending(Player player) { public boolean isAscending(Player player) {
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.check; package com.rammelkast.anticheatreloaded.check;
public class CheckResult { public class CheckResult {
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,14 +17,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.check; package com.rammelkast.anticheatreloaded.check;
import net.gravitydevelopment.anticheat.api.CheckFailEvent;
import net.gravitydevelopment.anticheat.util.User;
import net.gravitydevelopment.anticheat.util.Permission;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.rammelkast.anticheatreloaded.api.CheckFailEvent;
import com.rammelkast.anticheatreloaded.util.Permission;
import com.rammelkast.anticheatreloaded.util.User;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@@ -37,7 +39,8 @@ public enum CheckType {
ZOMBE_FLY(Permission.CHECK_ZOMBE_FLY), ZOMBE_FLY(Permission.CHECK_ZOMBE_FLY),
ZOMBE_NOCLIP(Permission.CHECK_ZOMBE_NOCLIP), ZOMBE_NOCLIP(Permission.CHECK_ZOMBE_NOCLIP),
ZOMBE_CHEAT(Permission.CHECK_ZOMBE_CHEAT), ZOMBE_CHEAT(Permission.CHECK_ZOMBE_CHEAT),
FLY(Permission.CHECK_FLY), FLIGHT(Permission.CHECK_FLIGHT),
ELYTRA(Permission.CHECK_FLIGHT),
WATER_WALK(Permission.CHECK_WATERWALK), WATER_WALK(Permission.CHECK_WATERWALK),
NO_SWING(Permission.CHECK_NOSWING), NO_SWING(Permission.CHECK_NOSWING),
FAST_BREAK(Permission.CHECK_FASTBREAK), FAST_BREAK(Permission.CHECK_FASTBREAK),
@@ -59,10 +62,10 @@ public enum CheckType {
ITEM_SPAM(Permission.CHECK_ITEMSPAM), ITEM_SPAM(Permission.CHECK_ITEMSPAM),
FAST_INVENTORY(Permission.CHECK_FASTINVENTORY), FAST_INVENTORY(Permission.CHECK_FASTINVENTORY),
AUTOTOOL(Permission.CHECK_AUTOTOOL), AUTOTOOL(Permission.CHECK_AUTOTOOL),
KILLAURA(Permission.CHECK_KILLAURA),
BLINK(Permission.CHECK_BLINK), BLINK(Permission.CHECK_BLINK),
VELOCITY(Permission.VELOCITY), VELOCITY(Permission.CHECK_VELOCITY),
CRITICALS(Permission.CRITICALS); CRITICALS(Permission.CHECK_CRITICALS),
CHAT_UNICODE(Permission.CHECK_UNICODE);
private final Permission permission; private final Permission permission;
private final Map<UUID, Integer> level = new HashMap<UUID, Integer>(); private final Map<UUID, Integer> level = new HashMap<UUID, Integer>();
@@ -0,0 +1,57 @@
/*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded.check.combat;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.potion.PotionEffectType;
import com.rammelkast.anticheatreloaded.check.CheckResult;
import com.rammelkast.anticheatreloaded.check.CheckType;
import com.rammelkast.anticheatreloaded.event.EventListener;
import com.rammelkast.anticheatreloaded.util.Utilities;
public class CriticalsCheck {
public static void doDamageEvent(EntityDamageByEntityEvent e, Player damager) {
if (!(e.getDamager() instanceof Player) || e.getCause() != DamageCause.ENTITY_ATTACK)
return;
Player p = (Player) e.getDamager();
if (isCritical(p)) {
if ((p.getLocation().getY() % 1.0 == 0 || p.getLocation().getY() % 0.5 == 0)
&& p.getLocation().clone().subtract(0, 1.0, 0).getBlock().getType().isSolid()) {
e.setCancelled(true);
EventListener.log(new CheckResult(CheckResult.Result.FAILED,
p.getName() + " failed Criticals, tried to do a critical without needed conditions")
.getMessage(),
p, CheckType.CRITICALS);
}
}
}
private static boolean isCritical(Player player) {
return player.getFallDistance() > 0.0f && !player.isOnGround() && !player.isInsideVehicle()
&& !player.hasPotionEffect(PotionEffectType.BLINDNESS)
&& !Utilities.isHoveringOverWater(player.getLocation())
&& player.getEyeLocation().getBlock().getType() != Material.LADDER;
}
}
@@ -0,0 +1,77 @@
/*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded.check.combat;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.scheduler.BukkitRunnable;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.CheckResult;
import com.rammelkast.anticheatreloaded.check.CheckType;
import com.rammelkast.anticheatreloaded.event.EventListener;
public class VelocityCheck {
private static final Map<UUID, Integer> VL_COUNT = new HashMap<UUID, Integer>();
public static void cleanPlayer(Player p) {
VL_COUNT.remove(p.getUniqueId());
}
public static void runCheck(EntityDamageByEntityEvent e, final Player p) {
if (AntiCheatReloaded.getManager().getCheckManager().isOpExempt(p)
|| AntiCheatReloaded.getManager().getCheckManager().isExempt(p, CheckType.VELOCITY))
return;
final Location then = p.getLocation();
new BukkitRunnable() {
@Override
public void run() {
if (!p.isOnline())
return;
if (then.distance(p.getLocation()) < 0.125) {
if (!VL_COUNT.containsKey(p.getUniqueId()))
VL_COUNT.put(p.getUniqueId(), 1);
else {
VL_COUNT.put(p.getUniqueId(), VL_COUNT.get(p.getUniqueId()) + 1);
if (VL_COUNT.get(p.getUniqueId()) > AntiCheatReloaded.getManager().getBackend().getMagic()
.VELOCITY_AMT()) {
EventListener.log(new CheckResult(CheckResult.Result.FAILED,
p.getName() + " failed Velocity, had zero/low velocity "
+ VL_COUNT.get(p.getUniqueId()) + " times (max="
+ AntiCheatReloaded.getManager().getBackend().getMagic().VELOCITY_AMT()
+ ", dist=" + then.distance(p.getLocation()) + ")").getMessage(),
p, CheckType.VELOCITY);
VL_COUNT.remove(p.getUniqueId());
}
}
} else {
VL_COUNT.remove(p.getUniqueId());
}
}
}.runTaskLater(AntiCheatReloaded.getPlugin(), 4);
}
}
@@ -0,0 +1,108 @@
/*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded.check.movement;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.CheckResult;
import com.rammelkast.anticheatreloaded.check.CheckType;
import com.rammelkast.anticheatreloaded.event.EventListener;
import com.rammelkast.anticheatreloaded.util.VersionUtil;
/**
* @author Rammelkast
*/
public class BlinkCheck {
public static final Map<UUID, Integer> MOVE_COUNT = new HashMap<UUID, Integer>();
public static void startTimer() {
new BukkitRunnable() {
@Override
public void run() {
MOVE_COUNT.clear();
}
}.runTaskTimer(AntiCheatReloaded.getPlugin(), 20, 20);
}
public static void listenPackets() {
AntiCheatReloaded.getProtocolManager()
.addPacketListener(new PacketAdapter(AntiCheatReloaded.getPlugin(), ListenerPriority.NORMAL,
new PacketType[] { PacketType.Play.Client.POSITION, PacketType.Play.Client.POSITION_LOOK }) {
@Override
public void onPacketReceiving(PacketEvent e) {
Player p = e.getPlayer();
Location cur = e.getPlayer().getLocation();
if (!MOVE_COUNT.containsKey(p.getUniqueId())) {
MOVE_COUNT.put(p.getUniqueId(), 1);
} else {
MOVE_COUNT.put(p.getUniqueId(), MOVE_COUNT.get(p.getUniqueId()) + 1);
if (AntiCheatReloaded.getManager().getCheckManager().checkInWorld(p)
&& !AntiCheatReloaded.getManager().getCheckManager().isOpExempt(p)
&& !AntiCheatReloaded.getManager().getCheckManager().isExempt(p, CheckType.BLINK)) {
int ping = VersionUtil.getPlayerPing(p);
int blinkMagic = AntiCheatReloaded.getManager().getBackend()
.getMagic().BLINK_PACKET();
float pingLeniency = (float) ((ping / 120));
if (pingLeniency < 1) pingLeniency = 1;
if (pingLeniency > 3) pingLeniency = 3;
blinkMagic = Math.round(pingLeniency * blinkMagic);
final float finalPingLeniency = pingLeniency;
try {
if (MOVE_COUNT.get(p.getUniqueId()) > blinkMagic) {
final int packets = MOVE_COUNT.get(p.getUniqueId());
MOVE_COUNT.remove(p.getUniqueId());
AntiCheatReloaded.sendToMainThread(new Runnable() {
@Override
public void run() {
EventListener.log(
new CheckResult(CheckResult.Result.FAILED, p.getName()
+ " failed Blink, sent " + packets
+ " packets in one second (max=" + AntiCheatReloaded.getManager()
.getBackend().getMagic().BLINK_PACKET()
+ ", leniency=" + finalPingLeniency + ", ping=" + ping + ")").getMessage(),
p, CheckType.BLINK);
e.setCancelled(true);
e.getPlayer().teleport(cur);
}
});
}
} catch (NullPointerException nullPointer) {
// TODO this is thrown sometimes, might have something to do with line 83
}
}
}
}
});
}
}
@@ -0,0 +1,58 @@
/*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded.check.movement;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.CheckResult;
import com.rammelkast.anticheatreloaded.util.Distance;
import com.rammelkast.anticheatreloaded.util.Utilities;
/**
* TODO
*/
public class ElytraCheck {
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
public static CheckResult runCheck(Player player, Distance distance) {
if (distance.getYDifference() > AntiCheatReloaded.getManager().getBackend().getMagic().TELEPORT_MIN()) {
// This was a teleport, so skip check.
return PASS;
}
/*if (!FlightCheck.isMovingExempt(player) && !Utilities.isHoveringOverWater(player.getLocation(), 1)
&& Utilities.cantStandAtExp(player.getLocation())
&& Utilities.blockIsnt(player.getLocation().getBlock().getRelative(BlockFace.DOWN),
new Material[] { Material.FENCE, Material.FENCE_GATE, Material.COBBLE_WALL,
Material.ACACIA_FENCE, Material.ACACIA_FENCE_GATE, Material.BIRCH_FENCE,
Material.BIRCH_FENCE_GATE, Material.DARK_OAK_FENCE, Material.DARK_OAK_FENCE_GATE,
Material.IRON_FENCE, Material.JUNGLE_FENCE, Material.JUNGLE_FENCE_GATE,
Material.fence, Material.SPRUCE_FENCE, Material.SPRUCE_FENCE_GATE, Material.IRON_BARS })) {
}*/
//TODO 1.15 update
return PASS;
}
}
@@ -0,0 +1,115 @@
/*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded.check.movement;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.CheckResult;
import com.rammelkast.anticheatreloaded.util.Distance;
import com.rammelkast.anticheatreloaded.util.Utilities;
import com.rammelkast.anticheatreloaded.util.VersionUtil;
/**
* @author Rammelkast TODO rewrite this check
*/
public class FlightCheck {
public static final Map<UUID, Double> BLOCKS_OVER_FLIGHT = new HashMap<UUID, Double>();
public static final Map<UUID, Long> MOVING_EXEMPT = new HashMap<UUID, Long>();
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
public static CheckResult runCheck(Player player, Distance distance) {
if (distance.getYDifference() > AntiCheatReloaded.getManager().getBackend().getMagic().TELEPORT_MIN()
|| VersionUtil.isFlying(player)) {
// This was a teleport or user is flying/using elytra, so we don't care
// about it.
return PASS;
}
final UUID uuid = player.getUniqueId();
final double y1 = distance.fromY();
final double y2 = distance.toY();
if (!isMovingExempt(player) && !Utilities.isHoveringOverWater(player.getLocation(), 1)
&& Utilities.cantStandAtExp(player.getLocation())
&& Utilities.blockIsnt(player.getLocation().getBlock().getRelative(BlockFace.DOWN),
new Material[] { Material.IRON_BARS })
&& Utilities.blockIsnt(player.getLocation().getBlock().getRelative(BlockFace.DOWN), new String[] {
"FENCE",
"FENCE_GATE"
})) {
if (!BLOCKS_OVER_FLIGHT.containsKey(uuid)) {
BLOCKS_OVER_FLIGHT.put(uuid, 0D);
}
BLOCKS_OVER_FLIGHT.put(uuid, (BLOCKS_OVER_FLIGHT.get(uuid) + distance.getXDifference()
+ distance.getYDifference() + distance.getZDifference()));
if (y1 > y2) {
BLOCKS_OVER_FLIGHT.put(uuid, (BLOCKS_OVER_FLIGHT.get(uuid) - distance.getYDifference()));
}
if (BLOCKS_OVER_FLIGHT.get(uuid) > AntiCheatReloaded.getManager().getBackend().getMagic().FLIGHT_BLOCK_LIMIT()
&& (y1 <= y2)) {
return new CheckResult(CheckResult.Result.FAILED,
player.getName() + " flew over " + BLOCKS_OVER_FLIGHT.get(uuid) + " blocks (max="
+ AntiCheatReloaded.getManager().getBackend().getMagic().FLIGHT_BLOCK_LIMIT() + ")");
}
} else {
BLOCKS_OVER_FLIGHT.put(uuid, 0D);
}
return PASS;
}
public static boolean isMovingExempt(Player player) {
return isDoing(player, MOVING_EXEMPT, -1);
}
private static boolean isDoing(Player player, Map<UUID, Long> map, double max) {
if (map.containsKey(player.getUniqueId())) {
if (max != -1) {
if (((System.currentTimeMillis() - map.get(player.getUniqueId())) / 1000) > max) {
map.remove(player.getUniqueId());
return false;
} else {
return true;
}
} else {
// Termination time has already been calculated
if (map.get(player.getUniqueId()) < System.currentTimeMillis()) {
map.remove(player.getUniqueId());
return false;
} else {
return true;
}
}
} else {
return false;
}
}
}
@@ -0,0 +1,98 @@
/*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded.check.movement;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.CheckResult;
import com.rammelkast.anticheatreloaded.util.Distance;
import com.rammelkast.anticheatreloaded.util.VersionUtil;
public class GlideCheck {
public static final Map<UUID, Double> LAST_DIFFERENCE = new HashMap<UUID, Double>();
public static final Map<UUID, Float> LAST_FALL_DISTANCE = new HashMap<UUID, Float>();
public static final Map<UUID, Integer> VIOLATIONS = new HashMap<UUID, Integer>();
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
public static CheckResult runCheck(Player player, Distance distance) {
if (VersionUtil.isFlying(player)) {
return PASS;
}
if (player.getLocation().getBlock().getType() == Material.LADDER
|| player.getLocation().getBlock().getRelative(0, 1, 0).getType() == Material.LADDER) {
return PASS;
}
if (!LAST_DIFFERENCE.containsKey(player.getUniqueId())) {
LAST_DIFFERENCE.put(player.getUniqueId(), distance.getYDifference());
return PASS;
}
if (!LAST_FALL_DISTANCE.containsKey(player.getUniqueId())) {
LAST_FALL_DISTANCE.put(player.getUniqueId(), player.getFallDistance());
return PASS;
}
double yDiff = distance.getYDifference();
float fallDistance = player.getFallDistance();
if (yDiff == LAST_DIFFERENCE.get(player.getUniqueId())
&& fallDistance > LAST_FALL_DISTANCE.get(player.getUniqueId())) {
if (!VIOLATIONS.containsKey(player.getUniqueId())) {
VIOLATIONS.put(player.getUniqueId(), 1);
} else {
if (VIOLATIONS.get(player.getUniqueId()) + 1 >= AntiCheatReloaded.getManager().getBackend().getMagic()
.GLIDE_LIMIT()) {
VIOLATIONS.remove(player.getUniqueId());
Location to = player.getLocation();
to.setY(to.getY() - distanceToFall(to));
player.teleport(to);
// Report glide violation to statistics, just for the lulz jk
AntiCheatReloaded.getPlugin().onGlideViolation();
return new CheckResult(CheckResult.Result.FAILED,
player.getName() + " was set back for gliding (yDiff="
+ new BigDecimal(yDiff).setScale(2, RoundingMode.HALF_UP) + ")");
} else {
VIOLATIONS.put(player.getUniqueId(), VIOLATIONS.get(player.getUniqueId()) + 1);
}
}
} else {
// TODO more sophisticated check
}
LAST_DIFFERENCE.put(player.getUniqueId(), distance.getYDifference());
LAST_FALL_DISTANCE.put(player.getUniqueId(), player.getFallDistance());
return PASS;
}
private static double distanceToFall(Location location) {
location = location.clone();
double firstY = location.getY();
while (location.clone().add(0, -0.1, 0).getBlock().getType() == Material.AIR)
location.add(0, -0.1, 0);
return firstY - location.getY();
}
}
@@ -0,0 +1,97 @@
/*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded.check.movement;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.CheckResult;
import com.rammelkast.anticheatreloaded.util.VersionUtil;
public class SpeedCheck {
public static final Map<UUID, Integer> SPEED_VIOLATIONS = new HashMap<UUID, Integer>();
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
public static boolean isSpeedExempt(Player player) {
return AntiCheatReloaded.getManager().getBackend().isMovingExempt(player)
|| AntiCheatReloaded.getManager().getBackend().justVelocity(player) || VersionUtil.isFlying(player);
}
public static CheckResult checkXZSpeed(Player player, double x, double z) {
if (!isSpeedExempt(player) && player.getVehicle() == null) {
String reason = "";
double max = AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX();
if (player.getLocation().getBlock().getType() == Material.SOUL_SAND) {
if (player.isSprinting()) {
reason = "on soulsand while sprinting ";
max = AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX_SOULSAND_SPRINT();
} else if (player.hasPotionEffect(PotionEffectType.SPEED)) {
reason = "on soulsand with speed potion ";
max = AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX_SOULSAND_POTION();
} else {
reason = "on soulsand ";
max = AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX_SOULSAND();
}
} else if (VersionUtil.isFlying(player)) {
reason = "while flying ";
max = AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX_FLY();
} else if (player.hasPotionEffect(PotionEffectType.SPEED)) {
if (player.isSprinting()) {
reason = "with speed potion while sprinting ";
max = AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX_POTION_SPRINT();
} else {
reason = "with speed potion ";
max = AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX_POTION();
}
} else if (player.isSprinting()) {
reason = "while sprinting ";
max = AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX_SPRINT();
}
float speed = player.getWalkSpeed();
max += speed > 0 ? player.getWalkSpeed() - 0.2f : 0;
if (x > max || z > max) {
int num = AntiCheatReloaded.getManager().getBackend().increment(player, SPEED_VIOLATIONS,
AntiCheatReloaded.getManager().getBackend().getMagic().SPEED_MAX());
if (num >= AntiCheatReloaded.getManager().getBackend().getMagic().SPEED_MAX()) {
return new CheckResult(CheckResult.Result.FAILED,
player.getName() + "'s speed was too high " + reason + num + " times in a row (max="
+ AntiCheatReloaded.getManager().getBackend().getMagic().SPEED_MAX() + ", speed="
+ (x > z ? x : z) + ", max speed=" + max + ")");
} else {
return PASS;
}
} else {
SPEED_VIOLATIONS.put(player.getUniqueId(), 0);
return PASS;
}
} else {
return PASS;
}
}
}
@@ -0,0 +1,124 @@
/*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded.check.movement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.CheckResult;
import com.rammelkast.anticheatreloaded.util.Utilities;
import com.rammelkast.anticheatreloaded.util.VersionUtil;
/**
* This check seems to be broken/outdated
*/
public class WaterWalkCheck {
public static final List<UUID> IS_IN_WATER = new ArrayList<UUID>();
public static final List<UUID> IS_IN_WATER_CACHE = new ArrayList<UUID>();
public static final Map<UUID, Integer> WATER_SPEED_VIOLATIONS = new HashMap<UUID, Integer>();
public static final Map<UUID, Integer> WATER_ASCENSION_VIOLATIONS = new HashMap<UUID, Integer>();
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
public static CheckResult runCheck(Player player, double x, double y, double z) {
Block block = player.getLocation().getBlock();
UUID uuid = player.getUniqueId();
if (player.getVehicle() == null && !player.isFlying() && !VersionUtil.isFrostWalk(player)) {
if (block.isLiquid()) {
if (IS_IN_WATER.contains(uuid)) {
if (IS_IN_WATER_CACHE.contains(uuid)) {
if (player.getNearbyEntities(1, 1, 1).isEmpty()) {
boolean b;
if (!Utilities.sprintFly(player)) {
b = x > AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX_WATER()
|| z > AntiCheatReloaded.getManager().getBackend().getMagic()
.XZ_SPEED_MAX_WATER();
} else {
b = x > AntiCheatReloaded.getManager().getBackend().getMagic()
.XZ_SPEED_MAX_WATER_SPRINT()
|| z > AntiCheatReloaded.getManager().getBackend().getMagic()
.XZ_SPEED_MAX_WATER_SPRINT();
}
if (!b && !Utilities.isFullyInWater(player.getLocation())
&& Utilities.isHoveringOverWater(player.getLocation(), 1) && y == 0D
&& !block.getType().equals(Material.LILY_PAD)) {
b = true;
}
if (b) {
if (WATER_SPEED_VIOLATIONS.containsKey(uuid)) {
int v = WATER_SPEED_VIOLATIONS.get(uuid);
if (v >= AntiCheatReloaded.getManager().getBackend().getMagic()
.WATER_SPEED_VIOLATION_MAX()) {
WATER_SPEED_VIOLATIONS.put(uuid, 0);
return new CheckResult(CheckResult.Result.FAILED,
player.getName() + " stood on water " + v + " times (can't stand on "
+ block.getType() + " or "
+ block.getRelative(BlockFace.DOWN).getType() + ")");
} else {
WATER_SPEED_VIOLATIONS.put(uuid, v + 1);
}
} else {
WATER_SPEED_VIOLATIONS.put(uuid, 1);
}
}
}
} else {
IS_IN_WATER_CACHE.add(uuid);
return PASS;
}
} else {
IS_IN_WATER.add(uuid);
return PASS;
}
} else if (block.getRelative(BlockFace.DOWN).isLiquid()
&& !AntiCheatReloaded.getManager().getBackend().isAscending(player) && Utilities.cantStandAt(block)
&& Utilities.cantStandAt(block.getRelative(BlockFace.DOWN))) {
if (WATER_ASCENSION_VIOLATIONS.containsKey(uuid)) {
int v = WATER_ASCENSION_VIOLATIONS.get(uuid);
if (v >= AntiCheatReloaded.getManager().getBackend().getMagic().WATER_ASCENSION_VIOLATION_MAX()) {
WATER_ASCENSION_VIOLATIONS.put(uuid, 0);
return new CheckResult(CheckResult.Result.FAILED,
player.getName() + " stood on water " + v + " times (can't stand on " + block.getType()
+ " or " + block.getRelative(BlockFace.DOWN).getType() + ")");
} else {
WATER_ASCENSION_VIOLATIONS.put(uuid, v + 1);
}
} else {
WATER_ASCENSION_VIOLATIONS.put(uuid, 1);
}
} else {
IS_IN_WATER.remove(uuid);
IS_IN_WATER_CACHE.remove(uuid);
}
}
return PASS;
}
}
@@ -0,0 +1,132 @@
/*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded.check.movement;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.CheckResult;
import com.rammelkast.anticheatreloaded.util.Distance;
import com.rammelkast.anticheatreloaded.util.Utilities;
import com.rammelkast.anticheatreloaded.util.VersionUtil;
public class YAxisCheck {
public static final Map<UUID, Double> LAST_Y_COORD_CACHE = new HashMap<UUID, Double>();
public static final Map<UUID, Long> LAST_Y_TIME = new HashMap<UUID, Long>();
public static final Map<UUID, Integer> Y_AXIS_VIOLATIONS = new HashMap<UUID, Integer>();
public static final Map<UUID, Long> LAST_Y_AXIS_VIOLATION = new HashMap<UUID, Long>();
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
private static boolean hasJumpPotion(Player player) {
return player.hasPotionEffect(PotionEffectType.JUMP);
}
public static CheckResult runCheck(Player player, Distance distance) {
if (distance.getYDifference() > AntiCheatReloaded.getManager().getBackend().getMagic().TELEPORT_MIN()
|| distance.getYDifference() < 0 || VersionUtil.isFlying(player)) {
return PASS;
}
if (!FlightCheck.isMovingExempt(player) && !Utilities.isClimbableBlock(player.getLocation().getBlock())
&& !Utilities.isClimbableBlock(player.getLocation().add(0, -1, 0).getBlock())
&& !player.isInsideVehicle() && !Utilities.isInWater(player) && !hasJumpPotion(player)
&& !isMoveUpBlock(player.getLocation().add(0, -1, 0).getBlock())
&& !isMoveUpBlock(player.getLocation().add(0, -1.5, 0).getBlock())) {
double y1 = player.getLocation().getY();
UUID uuid = player.getUniqueId();
// Fix Y axis spam.
if (!LAST_Y_COORD_CACHE.containsKey(uuid) || !LAST_Y_TIME.containsKey(uuid)
|| !LAST_Y_AXIS_VIOLATION.containsKey(uuid)) {
LAST_Y_COORD_CACHE.put(uuid, y1);
Y_AXIS_VIOLATIONS.put(uuid, 0);
LAST_Y_AXIS_VIOLATION.put(uuid, 0L);
LAST_Y_TIME.put(uuid, System.currentTimeMillis());
} else {
if (y1 > LAST_Y_COORD_CACHE.get(uuid)
&& Y_AXIS_VIOLATIONS.get(uuid) > AntiCheatReloaded.getManager().getBackend().getMagic()
.Y_MAXVIOLATIONS()
&& (System.currentTimeMillis() - LAST_Y_AXIS_VIOLATION.get(uuid)) < AntiCheatReloaded.getManager()
.getBackend().getMagic().Y_MAXVIOTIME()) {
Location g = player.getLocation();
Y_AXIS_VIOLATIONS.put(uuid, Y_AXIS_VIOLATIONS.get(uuid) + 1);
LAST_Y_AXIS_VIOLATION.put(uuid, System.currentTimeMillis());
if (!AntiCheatReloaded.getManager().getBackend().silentMode()) {
g.setY(LAST_Y_COORD_CACHE.get(uuid));
if (g.getBlock().getType() == Material.AIR) {
player.teleport(g);
}
}
return new CheckResult(CheckResult.Result.FAILED,
player.getName() + " tried to fly on y-axis " + Y_AXIS_VIOLATIONS.get(uuid) + " times (max ="
+ AntiCheatReloaded.getManager().getBackend().getMagic().Y_MAXVIOLATIONS() + ")");
} else {
if (Y_AXIS_VIOLATIONS.get(uuid) > AntiCheatReloaded.getManager().getBackend().getMagic()
.Y_MAXVIOLATIONS()
&& (System.currentTimeMillis() - LAST_Y_AXIS_VIOLATION.get(uuid)) > AntiCheatReloaded
.getManager().getBackend().getMagic().Y_MAXVIOTIME()) {
Y_AXIS_VIOLATIONS.put(uuid, 0);
LAST_Y_AXIS_VIOLATION.put(uuid, 0L);
}
}
long i = System.currentTimeMillis() - LAST_Y_TIME.get(uuid);
double diff = AntiCheatReloaded.getManager().getBackend().getMagic().Y_MAXDIFF()
+ (Utilities.isStair(player.getLocation().add(0, -1, 0).getBlock()) ? 0.5 : 0.0);
if ((y1 - LAST_Y_COORD_CACHE.get(uuid)) > diff
&& i < AntiCheatReloaded.getManager().getBackend().getMagic().Y_TIME()) {
Location g = player.getLocation();
Y_AXIS_VIOLATIONS.put(uuid, Y_AXIS_VIOLATIONS.get(uuid) + 1);
LAST_Y_AXIS_VIOLATION.put(uuid, System.currentTimeMillis());
if (!AntiCheatReloaded.getManager().getBackend().silentMode()) {
g.setY(LAST_Y_COORD_CACHE.get(uuid));
if (g.getBlock().getType() == Material.AIR) {
player.teleport(g);
}
}
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " tried to fly on y-axis in "
+ i + " ms (min =" + AntiCheatReloaded.getManager().getBackend().getMagic().Y_TIME() + ")");
} else {
if ((y1 - LAST_Y_COORD_CACHE.get(uuid)) > AntiCheatReloaded.getManager().getBackend().getMagic().Y_MAXDIFF()
+ 1
|| (System.currentTimeMillis() - LAST_Y_TIME.get(uuid)) > AntiCheatReloaded.getManager()
.getBackend().getMagic().Y_TIME()) {
LAST_Y_TIME.put(uuid, System.currentTimeMillis());
LAST_Y_COORD_CACHE.put(uuid, y1);
}
}
}
}
// Fix Y axis spam
return PASS;
}
public static boolean isMoveUpBlock(Block block) {
Material type = block.getType();
return type.name().endsWith("STAIRS"); // TODO slabs/others?
}
}
@@ -0,0 +1,36 @@
/*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded.check.player;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
*
* @author Rammelkast
*
*/
public class GhosthandCheck {
public static final Map<UUID, Integer> FLAG_COUNT = new HashMap<UUID, Integer>();
public static final int MAX_FLAGS = 3; // TODO config?
}
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.command; package com.rammelkast.anticheatreloaded.command;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@@ -24,17 +25,17 @@ import org.bukkit.Server;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import net.gravitydevelopment.anticheat.AntiCheat; import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import net.gravitydevelopment.anticheat.config.Configuration; import com.rammelkast.anticheatreloaded.config.Configuration;
import net.gravitydevelopment.anticheat.manage.CheckManager; import com.rammelkast.anticheatreloaded.manage.CheckManager;
import net.gravitydevelopment.anticheat.manage.UserManager; import com.rammelkast.anticheatreloaded.manage.UserManager;
import net.gravitydevelopment.anticheat.util.Permission; import com.rammelkast.anticheatreloaded.util.Permission;
public class CommandBase { public class CommandBase {
public static final Configuration CONFIG = AntiCheat.getManager().getConfiguration(); public static final Configuration CONFIG = AntiCheatReloaded.getManager().getConfiguration();
public static final UserManager USER_MANAGER = AntiCheat.getManager().getUserManager(); public static final UserManager USER_MANAGER = AntiCheatReloaded.getManager().getUserManager();
public static final CheckManager CHECK_MANAGER = AntiCheat.getManager().getCheckManager(); public static final CheckManager CHECK_MANAGER = AntiCheatReloaded.getManager().getCheckManager();
public static final ChatColor RED = ChatColor.RED; public static final ChatColor RED = ChatColor.RED;
public static final ChatColor YELLOW = ChatColor.YELLOW; public static final ChatColor YELLOW = ChatColor.YELLOW;
public static final ChatColor GREEN = ChatColor.GREEN; public static final ChatColor GREEN = ChatColor.GREEN;
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.command; package com.rammelkast.anticheatreloaded.command;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -25,14 +26,13 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import net.gravitydevelopment.anticheat.command.executors.CommandCheck; import com.rammelkast.anticheatreloaded.command.executors.CommandCheck;
import net.gravitydevelopment.anticheat.command.executors.CommandDebug; import com.rammelkast.anticheatreloaded.command.executors.CommandDeveloper;
import net.gravitydevelopment.anticheat.command.executors.CommandDeveloper; import com.rammelkast.anticheatreloaded.command.executors.CommandHelp;
import net.gravitydevelopment.anticheat.command.executors.CommandHelp; import com.rammelkast.anticheatreloaded.command.executors.CommandLog;
import net.gravitydevelopment.anticheat.command.executors.CommandLog; import com.rammelkast.anticheatreloaded.command.executors.CommandReload;
import net.gravitydevelopment.anticheat.command.executors.CommandReload; import com.rammelkast.anticheatreloaded.command.executors.CommandReport;
import net.gravitydevelopment.anticheat.command.executors.CommandReport; import com.rammelkast.anticheatreloaded.command.executors.CommandReset;
import net.gravitydevelopment.anticheat.command.executors.CommandReset;
public class CommandHandler implements CommandExecutor { public class CommandHandler implements CommandExecutor {
@@ -41,7 +41,6 @@ public class CommandHandler implements CommandExecutor {
public CommandHandler() { public CommandHandler() {
commands.add(new CommandHelp()); commands.add(new CommandHelp());
commands.add(new CommandCheck()); commands.add(new CommandCheck());
commands.add(new CommandDebug());
commands.add(new CommandDeveloper()); commands.add(new CommandDeveloper());
commands.add(new CommandLog()); commands.add(new CommandLog());
commands.add(new CommandReload()); commands.add(new CommandReload());
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,13 +17,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.command.executors; package com.rammelkast.anticheatreloaded.command.executors;
import net.gravitydevelopment.anticheat.check.CheckType;
import net.gravitydevelopment.anticheat.command.CommandBase;
import net.gravitydevelopment.anticheat.util.Permission;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.rammelkast.anticheatreloaded.check.CheckType;
import com.rammelkast.anticheatreloaded.command.CommandBase;
import com.rammelkast.anticheatreloaded.util.Permission;
import java.util.List; import java.util.List;
public class CommandCheck extends CommandBase { public class CommandCheck extends CommandBase {
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -15,14 +16,14 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.rammelkast.anticheatreloaded.command.executors;
package net.gravitydevelopment.anticheat.command.executors;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.command.CommandBase;
import net.gravitydevelopment.anticheat.util.Permission;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.command.CommandBase;
import com.rammelkast.anticheatreloaded.util.Permission;
public class CommandDeveloper extends CommandBase { public class CommandDeveloper extends CommandBase {
private static final String NAME = "AntiCheat Developer Mode"; private static final String NAME = "AntiCheat Developer Mode";
@@ -39,7 +40,7 @@ public class CommandDeveloper extends CommandBase {
@Override @Override
protected void execute(CommandSender cs, String[] args) { protected void execute(CommandSender cs, String[] args) {
AntiCheat.setDeveloperMode(!AntiCheat.developerMode()); AntiCheatReloaded.setDeveloperMode(!AntiCheatReloaded.developerMode());
cs.sendMessage(GREEN + "Developer mode " + (AntiCheat.developerMode() ? "ON" : "OFF")); cs.sendMessage(GREEN + "Developer mode " + (AntiCheatReloaded.developerMode() ? "ON" : "OFF"));
} }
} }
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,12 +17,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.command.executors; package com.rammelkast.anticheatreloaded.command.executors;
import net.gravitydevelopment.anticheat.command.CommandBase;
import net.gravitydevelopment.anticheat.util.Permission;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.rammelkast.anticheatreloaded.command.CommandBase;
import com.rammelkast.anticheatreloaded.util.Permission;
public class CommandHelp extends CommandBase { public class CommandHelp extends CommandBase {
private static final String NAME = "AntiCheatReloaded Help"; private static final String NAME = "AntiCheatReloaded Help";
@@ -29,14 +31,13 @@ public class CommandHelp extends CommandBase {
private static final String USAGE = "anticheat help"; private static final String USAGE = "anticheat help";
private static final Permission PERMISSION = Permission.SYSTEM_HELP; private static final Permission PERMISSION = Permission.SYSTEM_HELP;
private static final String[] HELP = { private static final String[] HELP = {
RED + "/anti " + GRAY + "help", RED + "/acr " + GRAY + "help",
RED + "/anti " + GRAY + "reload", RED + "/acr " + GRAY + "reload",
RED + "/anti " + GRAY + "update", RED + "/acr " + GRAY + "update",
RED + "/anti " + GRAY + "debug " + WHITE + "<user>", RED + "/acr " + GRAY + "check " + WHITE + "[check] [on/off]",
RED + "/anti " + GRAY + "check " + WHITE + "[check] [on/off]", RED + "/acr " + GRAY + "log " + WHITE + "[file/console] [on/off]",
RED + "/anti " + GRAY + "log " + WHITE + "[file/console] [on/off]", RED + "/acr " + GRAY + "report " + WHITE + "[group/user]",
RED + "/anti " + GRAY + "report " + WHITE + "[group/user]", RED + "/acr " + GRAY + "reset " + WHITE + "[user]",
RED + "/anti " + GRAY + "reset " + WHITE + "[user]",
}; };
public CommandHelp() { public CommandHelp() {
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,13 +17,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.command.executors; package com.rammelkast.anticheatreloaded.command.executors;
import net.gravitydevelopment.anticheat.command.CommandBase;
import net.gravitydevelopment.anticheat.config.ConfigurationFile;
import net.gravitydevelopment.anticheat.util.Permission;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.rammelkast.anticheatreloaded.command.CommandBase;
import com.rammelkast.anticheatreloaded.config.ConfigurationFile;
import com.rammelkast.anticheatreloaded.util.Permission;
public class CommandLog extends CommandBase { public class CommandLog extends CommandBase {
private static final String NAME = "AntiCheat Logging"; private static final String NAME = "AntiCheat Logging";
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,12 +17,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.command.executors; package com.rammelkast.anticheatreloaded.command.executors;
import net.gravitydevelopment.anticheat.command.CommandBase;
import net.gravitydevelopment.anticheat.util.Permission;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import com.rammelkast.anticheatreloaded.command.CommandBase;
import com.rammelkast.anticheatreloaded.util.Permission;
public class CommandReload extends CommandBase { public class CommandReload extends CommandBase {
private static final String NAME = "AntiCheat Reload"; private static final String NAME = "AntiCheat Reload";
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,18 +17,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.command.executors; package com.rammelkast.anticheatreloaded.command.executors;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.check.CheckType;
import net.gravitydevelopment.anticheat.command.CommandBase;
import net.gravitydevelopment.anticheat.manage.CheckManager;
import net.gravitydevelopment.anticheat.util.*;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.CheckType;
import com.rammelkast.anticheatreloaded.command.CommandBase;
import com.rammelkast.anticheatreloaded.manage.CheckManager;
import com.rammelkast.anticheatreloaded.util.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@@ -82,7 +84,7 @@ public class CommandReport extends CommandBase {
// Test users // Test users
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
if (player.getUniqueId().equals(Bukkit.getPlayer(args[0]).getUniqueId())) { if (player.getUniqueId().equals(Bukkit.getPlayer(args[0]).getUniqueId())) {
User user = AntiCheat.getManager().getUserManager().getUser(player.getUniqueId()); User user = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId());
playerReport(cs, user, page); playerReport(cs, user, page);
return; return;
} }
@@ -175,13 +177,13 @@ public class CommandReport extends CommandBase {
} }
} }
if (AntiCheat.developerMode()) { if (AntiCheatReloaded.developerMode()) {
int permission = 0; int permission = 0;
int check = 0; int check = 0;
for (Permission perm : Permission.values()) { for (Permission perm : Permission.values()) {
if (perm.get(user.getPlayer())) permission++; if (perm.get(user.getPlayer())) permission++;
} }
CheckManager manager = AntiCheat.getManager().getCheckManager(); CheckManager manager = AntiCheatReloaded.getManager().getCheckManager();
for (CheckType type : CheckType.values()) { for (CheckType type : CheckType.values()) {
if (manager.willCheck(user.getPlayer(), type)) check++; if (manager.willCheck(user.getPlayer(), type)) check++;
} }
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,17 +17,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.command.executors; package com.rammelkast.anticheatreloaded.command.executors;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.command.CommandBase;
import net.gravitydevelopment.anticheat.util.Permission;
import net.gravitydevelopment.anticheat.util.User;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.command.CommandBase;
import com.rammelkast.anticheatreloaded.util.Permission;
import com.rammelkast.anticheatreloaded.util.User;
public class CommandReset extends CommandBase { public class CommandReset extends CommandBase {
private static final String NAME = "AntiCheat Resetting"; private static final String NAME = "AntiCheat Resetting";
@@ -53,7 +54,7 @@ public class CommandReset extends CommandBase {
if (user != null) { if (user != null) {
user.resetLevel(); user.resetLevel();
user.clearMessages(); user.clearMessages();
AntiCheat.getManager().getBackend().resetChatLevel(user); AntiCheatReloaded.getManager().getBackend().resetChatLevel(user);
cs.sendMessage(args[0] + GREEN + " has been reset."); cs.sendMessage(args[0] + GREEN + " has been reset.");
} else { } else {
cs.sendMessage(RED + "Player: " +args[0] + " not found."); cs.sendMessage(RED + "Player: " +args[0] + " not found.");
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,17 +17,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.config; package com.rammelkast.anticheatreloaded.config;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.config.files.Config;
import net.gravitydevelopment.anticheat.config.files.Enterprise;
import net.gravitydevelopment.anticheat.config.holders.mysql.*;
import net.gravitydevelopment.anticheat.config.holders.yaml.*;
import net.gravitydevelopment.anticheat.config.providers.*;
import net.gravitydevelopment.anticheat.manage.AntiCheatManager;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.config.files.Config;
import com.rammelkast.anticheatreloaded.config.files.Enterprise;
import com.rammelkast.anticheatreloaded.config.holders.mysql.*;
import com.rammelkast.anticheatreloaded.config.holders.yaml.*;
import com.rammelkast.anticheatreloaded.config.providers.*;
import com.rammelkast.anticheatreloaded.manage.AntiCheatManager;
import java.io.File; import java.io.File;
import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy; import java.lang.reflect.Proxy;
@@ -47,7 +49,7 @@ public class Configuration {
private ArrayList<ConfigurationFile> flatfiles; private ArrayList<ConfigurationFile> flatfiles;
private ArrayList<ConfigurationTable> dbfiles; private ArrayList<ConfigurationTable> dbfiles;
public Configuration(AntiCheat plugin, AntiCheatManager manager) { public Configuration(AntiCheatReloaded plugin, AntiCheatManager manager) {
removeOldFiles(); removeOldFiles();
this.manager = manager; this.manager = manager;
config = new Config(plugin, this); config = new Config(plugin, this);
@@ -145,20 +147,20 @@ public class Configuration {
private void removeOldFiles() { private void removeOldFiles() {
ArrayList<String> removed = new ArrayList<String>(); ArrayList<String> removed = new ArrayList<String>();
File configFile = new File(AntiCheat.getPlugin().getDataFolder(), "config.yml"); File configFile = new File(AntiCheatReloaded.getPlugin().getDataFolder(), "config.yml");
if (configFile.exists() && YamlConfiguration.loadConfiguration(configFile).getString("System.Auto update") != null) { if (configFile.exists() && YamlConfiguration.loadConfiguration(configFile).getString("System.Auto update") != null) {
configFile.renameTo(new File(AntiCheat.getPlugin().getDataFolder(), "config.old")); configFile.renameTo(new File(AntiCheatReloaded.getPlugin().getDataFolder(), "config.old"));
removed.add("config.yml has been renamed to config.old and replaced with the new config.yml"); removed.add("config.yml has been renamed to config.old and replaced with the new config.yml");
} }
File eventsFile = new File(AntiCheat.getPlugin().getDataFolder(), "events.yml"); File eventsFile = new File(AntiCheatReloaded.getPlugin().getDataFolder(), "events.yml");
if (eventsFile.exists()) { if (eventsFile.exists()) {
eventsFile.renameTo(new File(AntiCheat.getPlugin().getDataFolder(), "events.old")); eventsFile.renameTo(new File(AntiCheatReloaded.getPlugin().getDataFolder(), "events.old"));
removed.add("events.yml has been renamed to events.old and replaced with groups.yml and rules.yml"); removed.add("events.yml has been renamed to events.old and replaced with groups.yml and rules.yml");
} }
if (removed.size() > 0) { if (removed.size() > 0) {
AntiCheat.getPlugin().getLogger().info("You are upgrading from an old version of AntiCheat. Due to configuration changes, the following files have been modified:"); AntiCheatReloaded.getPlugin().getLogger().info("You are upgrading from an old version of AntiCheat. Due to configuration changes, the following files have been modified:");
for (String s : removed) { for (String s : removed) {
AntiCheat.getPlugin().getLogger().info(s); AntiCheatReloaded.getPlugin().getLogger().info(s);
} }
} }
} }
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,15 +17,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.config; package com.rammelkast.anticheatreloaded.config;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.config.yaml.CommentedConfiguration;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.config.yaml.CommentedConfiguration;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
public class ConfigurationFile { public class ConfigurationFile {
@@ -35,21 +38,21 @@ public class ConfigurationFile {
private FileConfiguration defaultConfigFile; private FileConfiguration defaultConfigFile;
private Configuration config; private Configuration config;
private AntiCheat plugin; private AntiCheatReloaded plugin;
private boolean saveDefault; private boolean saveDefault;
protected boolean needsReload; protected boolean needsReload;
public ConfigurationFile(AntiCheat plugin, Configuration config, String fileName) { public ConfigurationFile(AntiCheatReloaded plugin, Configuration config, String fileName) {
this(plugin, config, fileName, true); this(plugin, config, fileName, true);
} }
public ConfigurationFile(AntiCheat plugin, Configuration config, String fileName, boolean saveDefault) { public ConfigurationFile(AntiCheatReloaded plugin, Configuration config, String fileName, boolean saveDefault) {
this(plugin, config, fileName, saveDefault, new File(plugin.getDataFolder(), fileName)); this(plugin, config, fileName, saveDefault, new File(plugin.getDataFolder(), fileName));
} }
public ConfigurationFile(AntiCheat plugin, Configuration config, String fileName, boolean saveDefault, File rawFile) { public ConfigurationFile(AntiCheatReloaded plugin, Configuration config, String fileName, boolean saveDefault, File rawFile) {
// Can't change with user editing // Can't change with user editing
this.plugin = plugin; this.plugin = plugin;
this.config = config; this.config = config;
@@ -58,7 +61,13 @@ public class ConfigurationFile {
this.saveDefault = saveDefault; this.saveDefault = saveDefault;
if (saveDefault) { if (saveDefault) {
defaultConfigFile = YamlConfiguration.loadConfiguration(plugin.getResource(fileName)); InputStreamReader reader = new InputStreamReader(plugin.getResource(fileName));
defaultConfigFile = YamlConfiguration.loadConfiguration(reader);
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
} }
load(); load();
} }
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,12 +17,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.config; package com.rammelkast.anticheatreloaded.config;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.util.enterprise.Database;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.util.enterprise.Database;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
@@ -58,7 +60,7 @@ public class ConfigurationTable {
public void reload() { public void reload() {
// For after sql inserts have been made // For after sql inserts have been made
Bukkit.getScheduler().runTask(AntiCheat.getPlugin(), new Runnable() { Bukkit.getScheduler().runTask(AntiCheatReloaded.getPlugin(), new Runnable() {
@Override @Override
public void run() { public void run() {
load(); load();
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,20 +17,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.config.files; package com.rammelkast.anticheatreloaded.config.files;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.config.Configuration;
import net.gravitydevelopment.anticheat.config.ConfigurationFile;
import java.util.List; import java.util.List;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.config.Configuration;
import com.rammelkast.anticheatreloaded.config.ConfigurationFile;
public class Config extends ConfigurationFile { public class Config extends ConfigurationFile {
public static final String FILENAME = "config.yml"; public static final String FILENAME = "config.yml";
public ConfigValue<Boolean> logToConsole; public ConfigValue<Boolean> logToConsole;
public ConfigValue<Boolean> autoUpdate;
public ConfigValue<Boolean> verboseStartup; public ConfigValue<Boolean> verboseStartup;
public ConfigValue<Boolean> silentMode; public ConfigValue<Boolean> silentMode;
public ConfigValue<Boolean> exemptOp; public ConfigValue<Boolean> exemptOp;
@@ -51,7 +51,7 @@ public class Config extends ConfigurationFile {
public ConfigValue<List<String>> disabledWorlds; public ConfigValue<List<String>> disabledWorlds;
public ConfigValue<List<String>> disabledChecks; public ConfigValue<List<String>> disabledChecks;
public Config(AntiCheat plugin, Configuration config) { public Config(AntiCheatReloaded plugin, Configuration config) {
super(plugin, config, FILENAME); super(plugin, config, FILENAME);
} }
@@ -59,7 +59,6 @@ public class Config extends ConfigurationFile {
public void open() { public void open() {
logToConsole = new ConfigValue<Boolean>("system.log-to-console"); logToConsole = new ConfigValue<Boolean>("system.log-to-console");
autoUpdate = new ConfigValue<Boolean>("system.auto-update");
verboseStartup = new ConfigValue<Boolean>("system.verbose-startup"); verboseStartup = new ConfigValue<Boolean>("system.verbose-startup");
silentMode = new ConfigValue<Boolean>("system.silent-mode"); silentMode = new ConfigValue<Boolean>("system.silent-mode");
exemptOp = new ConfigValue<Boolean>("system.exempt-op"); exemptOp = new ConfigValue<Boolean>("system.exempt-op");
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,12 +17,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.config.files; package com.rammelkast.anticheatreloaded.config.files;
import net.gravitydevelopment.anticheat.AntiCheat; import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import net.gravitydevelopment.anticheat.config.Configuration; import com.rammelkast.anticheatreloaded.config.Configuration;
import net.gravitydevelopment.anticheat.config.ConfigurationFile; import com.rammelkast.anticheatreloaded.config.ConfigurationFile;
import net.gravitydevelopment.anticheat.util.enterprise.Database; import com.rammelkast.anticheatreloaded.util.enterprise.Database;
public class Enterprise extends ConfigurationFile { public class Enterprise extends ConfigurationFile {
@@ -43,7 +44,7 @@ public class Enterprise extends ConfigurationFile {
public Database database; public Database database;
public Enterprise(AntiCheat plugin, Configuration config) { public Enterprise(AntiCheatReloaded plugin, Configuration config) {
super(plugin, config, FILENAME); super(plugin, config, FILENAME);
} }
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,12 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.config.holders.mysql; package com.rammelkast.anticheatreloaded.config.holders.mysql;
import net.gravitydevelopment.anticheat.config.Configuration;
import net.gravitydevelopment.anticheat.config.ConfigurationTable;
import net.gravitydevelopment.anticheat.config.providers.Groups;
import net.gravitydevelopment.anticheat.util.Group;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@@ -29,6 +25,11 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import com.rammelkast.anticheatreloaded.config.Configuration;
import com.rammelkast.anticheatreloaded.config.ConfigurationTable;
import com.rammelkast.anticheatreloaded.config.providers.Groups;
import com.rammelkast.anticheatreloaded.util.Group;
public class MySQLGroupsHolder extends ConfigurationTable implements Groups { public class MySQLGroupsHolder extends ConfigurationTable implements Groups {
private static final String TABLE = "groups"; private static final String TABLE = "groups";
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,15 +17,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.config.holders.mysql; package com.rammelkast.anticheatreloaded.config.holders.mysql;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.config.Configuration;
import net.gravitydevelopment.anticheat.config.ConfigurationTable;
import net.gravitydevelopment.anticheat.config.providers.Lang;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.config.Configuration;
import com.rammelkast.anticheatreloaded.config.ConfigurationTable;
import com.rammelkast.anticheatreloaded.config.providers.Lang;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@@ -49,7 +53,13 @@ public class MySQLLangHolder extends ConfigurationTable implements InvocationHan
@Override @Override
public void open() { public void open() {
defaults = YamlConfiguration.loadConfiguration(AntiCheat.getPlugin().getResource("lang.yml")); InputStreamReader reader = new InputStreamReader(AntiCheatReloaded.getPlugin().getResource("lang.yml"));
defaults = YamlConfiguration.loadConfiguration(reader);
try {
reader.close();
} catch (IOException e1) {
e1.printStackTrace();
}
stringValues = new HashMap<String, String>(); stringValues = new HashMap<String, String>();
listValues = new HashMap<String, List<String>>(); listValues = new HashMap<String, List<String>>();
@@ -141,7 +151,7 @@ public class MySQLLangHolder extends ConfigurationTable implements InvocationHan
return value; return value;
} }
} }
AntiCheat.getPlugin().getLogger().severe("The lang value " + key + " couldn't be found."); AntiCheatReloaded.getPlugin().getLogger().severe("The lang value " + key + " couldn't be found.");
return "Language error. See console for details."; return "Language error. See console for details.";
} }
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,15 +17,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.config.holders.mysql; package com.rammelkast.anticheatreloaded.config.holders.mysql;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.config.Configuration;
import net.gravitydevelopment.anticheat.config.ConfigurationTable;
import net.gravitydevelopment.anticheat.config.providers.Levels;
import net.gravitydevelopment.anticheat.util.User;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.config.Configuration;
import com.rammelkast.anticheatreloaded.config.ConfigurationTable;
import com.rammelkast.anticheatreloaded.config.providers.Levels;
import com.rammelkast.anticheatreloaded.util.User;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@@ -80,11 +82,11 @@ public class MySQLLevelsHolder extends ConfigurationTable implements Levels {
@Override @Override
public void saveLevelFromUser(final User user) { public void saveLevelFromUser(final User user) {
Bukkit.getScheduler().runTaskAsynchronously(AntiCheat.getPlugin(), new Runnable() { Bukkit.getScheduler().runTaskAsynchronously(AntiCheatReloaded.getPlugin(), new Runnable() {
@Override @Override
public void run() { public void run() {
if (!user.isWaitingOnLevelSync()) { if (!user.isWaitingOnLevelSync()) {
AntiCheat.debugLog("Saving level from " + user.getUUID() + ". Value: " + user.getLevel()); AntiCheatReloaded.debugLog("Saving level from " + user.getUUID() + ". Value: " + user.getLevel());
try { try {
PreparedStatement statement = getConnection().prepareStatement(sqlSave); PreparedStatement statement = getConnection().prepareStatement(sqlSave);
statement.setString(1, user.getUUID().toString()); statement.setString(1, user.getUUID().toString());
@@ -100,14 +102,14 @@ public class MySQLLevelsHolder extends ConfigurationTable implements Levels {
e.printStackTrace(); e.printStackTrace();
} }
} }
AntiCheat.getManager().getUserManager().remove(user); AntiCheatReloaded.getManager().getUserManager().remove(user);
} }
}); });
} }
@Override @Override
public void loadLevelToUser(final User user) { public void loadLevelToUser(final User user) {
Bukkit.getScheduler().runTaskAsynchronously(AntiCheat.getPlugin(), new Runnable() { Bukkit.getScheduler().runTaskAsynchronously(AntiCheatReloaded.getPlugin(), new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
@@ -119,7 +121,7 @@ public class MySQLLevelsHolder extends ConfigurationTable implements Levels {
boolean has = false; boolean has = false;
while (set.next()) { while (set.next()) {
has = true; has = true;
AntiCheat.debugLog("Syncing level to " + user.getUUID() + ". Value: " + set.getInt("level")); AntiCheatReloaded.debugLog("Syncing level to " + user.getUUID() + ". Value: " + set.getInt("level"));
user.setLevel(set.getInt("level")); user.setLevel(set.getInt("level"));
user.setLevelSyncTimestamp(set.getTimestamp("last_update")); user.setLevelSyncTimestamp(set.getTimestamp("last_update"));
} }
@@ -161,7 +163,7 @@ public class MySQLLevelsHolder extends ConfigurationTable implements Levels {
@Override @Override
public void updateLevelToUser(final User user) { public void updateLevelToUser(final User user) {
Bukkit.getScheduler().runTaskAsynchronously(AntiCheat.getPlugin(), new Runnable() { Bukkit.getScheduler().runTaskAsynchronously(AntiCheatReloaded.getPlugin(), new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
@@ -173,7 +175,7 @@ public class MySQLLevelsHolder extends ConfigurationTable implements Levels {
ResultSet set = statement.executeQuery(); ResultSet set = statement.executeQuery();
while (set.next()) { while (set.next()) {
AntiCheat.debugLog("Syncing level to " + user.getUUID() + ". Value: " + set.getInt("level")); AntiCheatReloaded.debugLog("Syncing level to " + user.getUUID() + ". Value: " + set.getInt("level"));
user.setLevel(set.getInt("level")); user.setLevel(set.getInt("level"));
user.setLevelSyncTimestamp(set.getTimestamp("last_update")); user.setLevelSyncTimestamp(set.getTimestamp("last_update"));
} }
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,15 +17,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.config.holders.mysql; package com.rammelkast.anticheatreloaded.config.holders.mysql;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.config.Configuration;
import net.gravitydevelopment.anticheat.config.ConfigurationTable;
import net.gravitydevelopment.anticheat.config.providers.Magic;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.config.Configuration;
import com.rammelkast.anticheatreloaded.config.ConfigurationTable;
import com.rammelkast.anticheatreloaded.config.providers.Magic;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.sql.ResultSet; import java.sql.ResultSet;
@@ -46,7 +50,13 @@ public class MySQLMagicHolder extends ConfigurationTable implements InvocationHa
@Override @Override
public void open() { public void open() {
defaults = YamlConfiguration.loadConfiguration(AntiCheat.getPlugin().getResource("magic.yml")); InputStreamReader reader = new InputStreamReader(AntiCheatReloaded.getPlugin().getResource("magic.yml"));
defaults = YamlConfiguration.loadConfiguration(reader);
try {
reader.close();
} catch (IOException e1) {
e1.printStackTrace();
}
ints = new HashMap<String, Integer>(); ints = new HashMap<String, Integer>();
doubles = new HashMap<String, Double>(); doubles = new HashMap<String, Double>();
@@ -93,7 +103,7 @@ public class MySQLMagicHolder extends ConfigurationTable implements InvocationHa
} else if (set.getObject("value_double") != null) { } else if (set.getObject("value_double") != null) {
doubles.put(key, set.getDouble("value_double")); doubles.put(key, set.getDouble("value_double"));
} else { } else {
AntiCheat.getPlugin().getLogger().severe("The magic value " + key + " loaded from the database did not have a value configured. Using the default value."); AntiCheatReloaded.getPlugin().getLogger().severe("The magic value " + key + " loaded from the database did not have a value configured. Using the default value.");
for (int i=1;i<=methods.length;i++) { for (int i=1;i<=methods.length;i++) {
String name = methods[i-1].getName(); String name = methods[i-1].getName();
if (name.equalsIgnoreCase(key)) { if (name.equalsIgnoreCase(key)) {
@@ -140,7 +150,7 @@ public class MySQLMagicHolder extends ConfigurationTable implements InvocationHa
return value; return value;
} }
} }
AntiCheat.getPlugin().getLogger().severe("The magic value " + key + " couldn't be found."); AntiCheatReloaded.getPlugin().getLogger().severe("The magic value " + key + " couldn't be found.");
return 0; return 0;
} }
} }
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,19 +17,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.config.holders.mysql; package com.rammelkast.anticheatreloaded.config.holders.mysql;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.config.Configuration;
import net.gravitydevelopment.anticheat.config.ConfigurationTable;
import net.gravitydevelopment.anticheat.config.providers.Rules;
import net.gravitydevelopment.anticheat.util.rule.Rule;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.config.Configuration;
import com.rammelkast.anticheatreloaded.config.ConfigurationTable;
import com.rammelkast.anticheatreloaded.config.providers.Rules;
import com.rammelkast.anticheatreloaded.util.rule.Rule;
public class MySQLRulesHolder extends ConfigurationTable implements Rules { public class MySQLRulesHolder extends ConfigurationTable implements Rules {
private static final String TABLE = "rules"; private static final String TABLE = "rules";
@@ -65,7 +66,7 @@ public class MySQLRulesHolder extends ConfigurationTable implements Rules {
if (rule != null) { if (rule != null) {
this.rules.add(rule); this.rules.add(rule);
} else { } else {
AntiCheat.getPlugin().getLogger().warning("Couldn't load rule '" + string + "' from the database. Improper format used."); AntiCheatReloaded.getPlugin().getLogger().warning("Couldn't load rule '" + string + "' from the database. Improper format used.");
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,16 +17,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.config.holders.yaml; package com.rammelkast.anticheatreloaded.config.holders.yaml;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.config.Configuration;
import net.gravitydevelopment.anticheat.config.ConfigurationFile;
import net.gravitydevelopment.anticheat.config.providers.Groups;
import net.gravitydevelopment.anticheat.util.Group;
import java.util.*; import java.util.*;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.config.Configuration;
import com.rammelkast.anticheatreloaded.config.ConfigurationFile;
import com.rammelkast.anticheatreloaded.config.providers.Groups;
import com.rammelkast.anticheatreloaded.util.Group;
public class YamlGroupsHolder extends ConfigurationFile implements Groups { public class YamlGroupsHolder extends ConfigurationFile implements Groups {
public static final String FILENAME = "groups.yml"; public static final String FILENAME = "groups.yml";
@@ -34,7 +35,7 @@ public class YamlGroupsHolder extends ConfigurationFile implements Groups {
private int highestLevel; private int highestLevel;
public YamlGroupsHolder(AntiCheat plugin, Configuration config) { public YamlGroupsHolder(AntiCheatReloaded plugin, Configuration config) {
super(plugin, config, FILENAME); super(plugin, config, FILENAME);
} }
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,21 +17,21 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.config.holders.yaml; package com.rammelkast.anticheatreloaded.config.holders.yaml;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.config.Configuration;
import net.gravitydevelopment.anticheat.config.ConfigurationFile;
import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.List; import java.util.List;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.config.Configuration;
import com.rammelkast.anticheatreloaded.config.ConfigurationFile;
public class YamlLangHolder extends ConfigurationFile implements InvocationHandler { public class YamlLangHolder extends ConfigurationFile implements InvocationHandler {
public static final String FILENAME = "lang.yml"; public static final String FILENAME = "lang.yml";
public YamlLangHolder(AntiCheat plugin, Configuration config) { public YamlLangHolder(AntiCheatReloaded plugin, Configuration config) {
super(plugin, config, FILENAME); super(plugin, config, FILENAME);
} }
@@ -76,7 +77,7 @@ public class YamlLangHolder extends ConfigurationFile implements InvocationHandl
return value.getValue(); return value.getValue();
} }
} }
AntiCheat.getPlugin().getLogger().severe("The lang value " + key + " couldn't be found."); AntiCheatReloaded.getPlugin().getLogger().severe("The lang value " + key + " couldn't be found.");
return "Language error. See console for details."; return "Language error. See console for details.";
} }
} }
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,22 +17,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.config.holders.yaml; package com.rammelkast.anticheatreloaded.config.holders.yaml;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.config.Configuration;
import net.gravitydevelopment.anticheat.config.ConfigurationFile;
import net.gravitydevelopment.anticheat.config.providers.Levels;
import net.gravitydevelopment.anticheat.util.User;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.config.Configuration;
import com.rammelkast.anticheatreloaded.config.ConfigurationFile;
import com.rammelkast.anticheatreloaded.config.providers.Levels;
import com.rammelkast.anticheatreloaded.util.User;
public class YamlLevelsHolder extends ConfigurationFile implements Levels { public class YamlLevelsHolder extends ConfigurationFile implements Levels {
public static final String FILENAME = "data/levels.yml"; public static final String FILENAME = "data/levels.yml";
public YamlLevelsHolder(AntiCheat plugin, Configuration config) { public YamlLevelsHolder(AntiCheatReloaded plugin, Configuration config) {
super(plugin, config, FILENAME, false); super(plugin, config, FILENAME, false);
} }
@@ -47,7 +48,7 @@ public class YamlLevelsHolder extends ConfigurationFile implements Levels {
private void saveLevelFromUser(User user, boolean remove) { private void saveLevelFromUser(User user, boolean remove) {
saveLevel(user.getUUID(), user.getLevel()); saveLevel(user.getUUID(), user.getLevel());
if (remove) AntiCheat.getManager().getUserManager().remove(user); if (remove) AntiCheatReloaded.getManager().getUserManager().remove(user);
} }
@Override @Override
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,20 +17,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.config.holders.yaml; package com.rammelkast.anticheatreloaded.config.holders.yaml;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.config.Configuration;
import net.gravitydevelopment.anticheat.config.ConfigurationFile;
import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.config.Configuration;
import com.rammelkast.anticheatreloaded.config.ConfigurationFile;
public class YamlMagicHolder extends ConfigurationFile implements InvocationHandler { public class YamlMagicHolder extends ConfigurationFile implements InvocationHandler {
public static final String FILENAME = "magic.yml"; public static final String FILENAME = "magic.yml";
public YamlMagicHolder(AntiCheat plugin, Configuration config) { public YamlMagicHolder(AntiCheatReloaded plugin, Configuration config) {
super(plugin, config, FILENAME); super(plugin, config, FILENAME);
} }
@@ -41,7 +42,7 @@ public class YamlMagicHolder extends ConfigurationFile implements InvocationHand
} else if (method.getReturnType().getSimpleName().equals("double")) { } else if (method.getReturnType().getSimpleName().equals("double")) {
return new ConfigValue<Double>(key).getValue(); return new ConfigValue<Double>(key).getValue();
} else { } else {
AntiCheat.getPlugin().getLogger().severe("The magic value " + key + " couldn't be found."); AntiCheatReloaded.getPlugin().getLogger().severe("The magic value " + key + " couldn't be found.");
return -1; return -1;
} }
} }
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,24 +17,24 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.config.holders.yaml; package com.rammelkast.anticheatreloaded.config.holders.yaml;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.config.Configuration;
import net.gravitydevelopment.anticheat.config.ConfigurationFile;
import net.gravitydevelopment.anticheat.config.providers.Rules;
import net.gravitydevelopment.anticheat.util.rule.Rule;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.config.Configuration;
import com.rammelkast.anticheatreloaded.config.ConfigurationFile;
import com.rammelkast.anticheatreloaded.config.providers.Rules;
import com.rammelkast.anticheatreloaded.util.rule.Rule;
public class YamlRulesHolder extends ConfigurationFile implements Rules { public class YamlRulesHolder extends ConfigurationFile implements Rules {
public static final String FILENAME = "rules.yml"; public static final String FILENAME = "rules.yml";
private List<Rule> rules; private List<Rule> rules;
public YamlRulesHolder(AntiCheat plugin, Configuration config) { public YamlRulesHolder(AntiCheatReloaded plugin, Configuration config) {
super(plugin, config, FILENAME); super(plugin, config, FILENAME);
} }
@@ -61,7 +62,7 @@ public class YamlRulesHolder extends ConfigurationFile implements Rules {
if (rule != null) { if (rule != null) {
this.rules.add(rule); this.rules.add(rule);
} else { } else {
AntiCheat.getPlugin().getLogger().warning("Couldn't load rule '" + string + "' from config. Improper format used."); AntiCheatReloaded.getPlugin().getLogger().warning("Couldn't load rule '" + string + "' from config. Improper format used.");
} }
} }
} }
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,12 +17,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.config.providers; package com.rammelkast.anticheatreloaded.config.providers;
import net.gravitydevelopment.anticheat.util.Group;
import java.util.List; import java.util.List;
import com.rammelkast.anticheatreloaded.util.Group;
public interface Groups { public interface Groups {
/** /**
@@ -1,4 +1,23 @@
package net.gravitydevelopment.anticheat.config.providers; /*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded.config.providers;
import java.util.List; import java.util.List;
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,12 +17,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.config.providers; package com.rammelkast.anticheatreloaded.config.providers;
import net.gravitydevelopment.anticheat.util.User;
import java.util.List; import java.util.List;
import com.rammelkast.anticheatreloaded.util.User;
public interface Levels { public interface Levels {
/** /**
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.config.providers; package com.rammelkast.anticheatreloaded.config.providers;
/** /**
* Magic number class. Modifications to values in magic.yml will be accepted here. * Magic number class. Modifications to values in magic.yml will be accepted here.
@@ -161,10 +162,6 @@ public interface Magic {
* Number of times a player can be caught in-glide before action is taken; Type=INTEGER, Leniency=INCREASE. * Number of times a player can be caught in-glide before action is taken; Type=INTEGER, Leniency=INCREASE.
*/ */
public int GLIDE_LIMIT(); public int GLIDE_LIMIT();
/**
* The max fallspeed after which glide check is disabled; Type=DOUBLE
*/
public double GLIDE_MAX();
/** /**
* How many blocks you can travel before action is taken; Type=INTEGER, Leniency=INCREASE. * How many blocks you can travel before action is taken; Type=INTEGER, Leniency=INCREASE.
*/ */
@@ -257,10 +254,6 @@ public interface Magic {
* Minimum time in between block placing; Type=INTEGER, Leniency=DECREASE. * Minimum time in between block placing; Type=INTEGER, Leniency=DECREASE.
*/ */
public double BLOCK_PLACE_MIN(); public double BLOCK_PLACE_MIN();
/**
* Minimum time in between healing; Type=SYSTEM, Leniency=DECREASE.
*/
public int HEAL_TIME_MIN();
/** /**
* Minimum time in between eating; Type=SYSTEM, Leniency=DECREASE. * Minimum time in between eating; Type=SYSTEM, Leniency=DECREASE.
*/ */
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,13 +17,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.rammelkast.anticheatreloaded.config.providers;
package net.gravitydevelopment.anticheat.config.providers;
import net.gravitydevelopment.anticheat.util.rule.Rule;
import java.util.List; import java.util.List;
import com.rammelkast.anticheatreloaded.util.rule.Rule;
public interface Rules { public interface Rules {
/** /**
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.config.yaml; package com.rammelkast.anticheatreloaded.config.yaml;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@@ -33,6 +34,7 @@ import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@@ -188,7 +190,9 @@ public class CommentedConfiguration extends YamlConfiguration {
CommentedConfiguration config = new CommentedConfiguration(); CommentedConfiguration config = new CommentedConfiguration();
try { try {
config.load(stream); InputStreamReader reader = new InputStreamReader(stream);
config.load(reader);
reader.close();
} catch (IOException ex) { } catch (IOException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Cannot load configuration from stream", ex); Bukkit.getLogger().log(Level.SEVERE, "Cannot load configuration from stream", ex);
} catch (InvalidConfigurationException ex) { } catch (InvalidConfigurationException ex) {
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,13 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.event; package com.rammelkast.anticheatreloaded.event;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.check.CheckType;
import net.gravitydevelopment.anticheat.check.CheckResult;
import net.gravitydevelopment.anticheat.util.Distance;
import net.gravitydevelopment.anticheat.util.Utilities;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@@ -31,6 +27,12 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.CheckResult;
import com.rammelkast.anticheatreloaded.check.CheckType;
import com.rammelkast.anticheatreloaded.util.Distance;
import com.rammelkast.anticheatreloaded.util.Utilities;
public class BlockListener extends EventListener { public class BlockListener extends EventListener {
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
@@ -47,7 +49,7 @@ public class BlockListener extends EventListener {
} }
} }
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
@@ -64,7 +66,7 @@ public class BlockListener extends EventListener {
} }
} }
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,10 +17,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.event; package com.rammelkast.anticheatreloaded.event;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Creeper; import org.bukkit.entity.Creeper;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.TNTPrimed;
@@ -32,14 +32,12 @@ import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import org.bukkit.event.entity.EntityShootBowEvent; import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.FoodLevelChangeEvent;
import net.gravitydevelopment.anticheat.AntiCheat; import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import net.gravitydevelopment.anticheat.check.CheckResult; import com.rammelkast.anticheatreloaded.check.CheckResult;
import net.gravitydevelopment.anticheat.check.CheckType; import com.rammelkast.anticheatreloaded.check.CheckType;
import net.gravitydevelopment.anticheat.check.combat.CriticalsCheck; import com.rammelkast.anticheatreloaded.check.combat.CriticalsCheck;
import net.gravitydevelopment.anticheat.check.combat.KillAuraCheck; import com.rammelkast.anticheatreloaded.check.combat.VelocityCheck;
import net.gravitydevelopment.anticheat.check.combat.VelocityCheck; import com.rammelkast.anticheatreloaded.util.Distance;
import net.gravitydevelopment.anticheat.util.Distance;
import net.gravitydevelopment.anticheat.util.Utilities;
public class EntityListener extends EventListener { public class EntityListener extends EventListener {
@@ -58,7 +56,7 @@ public class EntityListener extends EventListener {
} }
} }
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler @EventHandler
@@ -77,7 +75,7 @@ public class EntityListener extends EventListener {
} }
} }
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler @EventHandler
@@ -96,7 +94,7 @@ public class EntityListener extends EventListener {
} }
} }
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled = true)
@@ -105,9 +103,6 @@ public class EntityListener extends EventListener {
if (event instanceof EntityDamageByEntityEvent) { if (event instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event; EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
if (e.getDamager() instanceof Player) { if (e.getDamager() instanceof Player) {
if (getCheckManager().willCheck((Player)e.getDamager(), CheckType.KILLAURA)) {
KillAuraCheck.doDamageEvent(e, (Player)e.getDamager());
}
if (getCheckManager().willCheck((Player)e.getDamager(), CheckType.CRITICALS)) { if (getCheckManager().willCheck((Player)e.getDamager(), CheckType.CRITICALS)) {
CriticalsCheck.doDamageEvent(e, (Player)e.getDamager()); CriticalsCheck.doDamageEvent(e, (Player)e.getDamager());
} }
@@ -118,7 +113,7 @@ public class EntityListener extends EventListener {
if (e.getDamager() instanceof Player) { if (e.getDamager() instanceof Player) {
Player p = (Player) e.getDamager(); Player p = (Player) e.getDamager();
getBackend().logDamage(p, 1); getBackend().logDamage(p, 1);
int value = p.getInventory().getItemInHand().containsEnchantment(Enchantment.KNOCKBACK) ? 2 : 1; int value = p.getInventory().getItemInMainHand().containsEnchantment(Enchantment.KNOCKBACK) ? 2 : 1;
getBackend().logDamage(player, value); getBackend().logDamage(player, value);
if (getCheckManager().willCheck(p, CheckType.LONG_REACH)) { if (getCheckManager().willCheck(p, CheckType.LONG_REACH)) {
Distance distance = new Distance(player.getLocation(), p.getLocation()); Distance distance = new Distance(player.getLocation(), p.getLocation());
@@ -170,6 +165,6 @@ public class EntityListener extends EventListener {
} }
} }
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
} }
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,17 +17,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.event; package com.rammelkast.anticheatreloaded.event;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.check.Backend;
import net.gravitydevelopment.anticheat.check.CheckType;
import net.gravitydevelopment.anticheat.config.Configuration;
import net.gravitydevelopment.anticheat.manage.*;
import net.gravitydevelopment.anticheat.util.User;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.Backend;
import com.rammelkast.anticheatreloaded.check.CheckType;
import com.rammelkast.anticheatreloaded.config.Configuration;
import com.rammelkast.anticheatreloaded.manage.*;
import com.rammelkast.anticheatreloaded.util.User;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@@ -35,18 +37,18 @@ import java.util.UUID;
public class EventListener implements Listener { public class EventListener implements Listener {
private static final Map<CheckType, Integer> USAGE_LIST = new EnumMap<CheckType, Integer>(CheckType.class); private static final Map<CheckType, Integer> USAGE_LIST = new EnumMap<CheckType, Integer>(CheckType.class);
private static final Map<UUID, Integer> DECREASE_LIST = new HashMap<UUID, Integer>(); private static final Map<UUID, Integer> DECREASE_LIST = new HashMap<UUID, Integer>();
private static final CheckManager CHECK_MANAGER = AntiCheat.getManager().getCheckManager(); private static final CheckManager CHECK_MANAGER = AntiCheatReloaded.getManager().getCheckManager();
private static final Backend BACKEND = AntiCheat.getManager().getBackend(); private static final Backend BACKEND = AntiCheatReloaded.getManager().getBackend();
private static final AntiCheat PLUGIN = AntiCheat.getManager().getPlugin(); private static final AntiCheatReloaded PLUGIN = AntiCheatReloaded.getManager().getPlugin();
private static final UserManager USER_MANAGER = AntiCheat.getManager().getUserManager(); private static final UserManager USER_MANAGER = AntiCheatReloaded.getManager().getUserManager();
private static final Configuration CONFIG = AntiCheat.getManager().getConfiguration(); private static final Configuration CONFIG = AntiCheatReloaded.getManager().getConfiguration();
public static void log(String message, Player player, CheckType type) { public static void log(String message, Player player, CheckType type) {
User user = getUserManager().getUser(player.getUniqueId()); User user = getUserManager().getUser(player.getUniqueId());
if (user != null) { // npc if (user != null) { // npc
logCheat(type, user); logCheat(type, user);
if (user.increaseLevel(type) && message != null) { if (user.increaseLevel(type) && message != null) {
AntiCheat.getManager().log(message); AntiCheatReloaded.getManager().log(message);
} }
removeDecrease(user); removeDecrease(user);
} }
@@ -115,7 +117,7 @@ public class EventListener implements Listener {
} }
public static AntiCheatManager getManager() { public static AntiCheatManager getManager() {
return AntiCheat.getManager(); return AntiCheatReloaded.getManager();
} }
public static Backend getBackend() { public static Backend getBackend() {
@@ -126,7 +128,7 @@ public class EventListener implements Listener {
return USER_MANAGER; return USER_MANAGER;
} }
public static AntiCheat getPlugin() { public static AntiCheatReloaded getPlugin() {
return PLUGIN; return PLUGIN;
} }
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,12 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.event; package com.rammelkast.anticheatreloaded.event;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.check.CheckType;
import net.gravitydevelopment.anticheat.util.User;
import net.gravitydevelopment.anticheat.check.CheckResult;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
@@ -29,6 +26,11 @@ import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.inventory.InventoryType;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.CheckResult;
import com.rammelkast.anticheatreloaded.check.CheckType;
import com.rammelkast.anticheatreloaded.util.User;
public class InventoryListener extends EventListener { public class InventoryListener extends EventListener {
@EventHandler @EventHandler
@@ -50,7 +52,7 @@ public class InventoryListener extends EventListener {
} }
} }
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler @EventHandler
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.event; package com.rammelkast.anticheatreloaded.event;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@@ -51,20 +52,20 @@ import org.bukkit.event.player.PlayerToggleSprintEvent;
import org.bukkit.event.player.PlayerVelocityEvent; import org.bukkit.event.player.PlayerVelocityEvent;
import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.PlayerInventory;
import net.gravitydevelopment.anticheat.AntiCheat; import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import net.gravitydevelopment.anticheat.check.CheckResult; import com.rammelkast.anticheatreloaded.check.CheckResult;
import net.gravitydevelopment.anticheat.check.CheckType; import com.rammelkast.anticheatreloaded.check.CheckType;
import net.gravitydevelopment.anticheat.check.combat.KillAuraCheck; import com.rammelkast.anticheatreloaded.check.movement.ElytraCheck;
import net.gravitydevelopment.anticheat.check.movement.FlightCheck; import com.rammelkast.anticheatreloaded.check.movement.FlightCheck;
import net.gravitydevelopment.anticheat.check.movement.GlideCheck; import com.rammelkast.anticheatreloaded.check.movement.GlideCheck;
import net.gravitydevelopment.anticheat.check.movement.SpeedCheck; import com.rammelkast.anticheatreloaded.check.movement.SpeedCheck;
import net.gravitydevelopment.anticheat.check.movement.WaterWalkCheck; import com.rammelkast.anticheatreloaded.check.movement.WaterWalkCheck;
import net.gravitydevelopment.anticheat.check.movement.YAxisCheck; import com.rammelkast.anticheatreloaded.check.movement.YAxisCheck;
import net.gravitydevelopment.anticheat.util.Distance; import com.rammelkast.anticheatreloaded.util.Distance;
import net.gravitydevelopment.anticheat.util.Permission; import com.rammelkast.anticheatreloaded.util.Permission;
import net.gravitydevelopment.anticheat.util.User; import com.rammelkast.anticheatreloaded.util.User;
import net.gravitydevelopment.anticheat.util.Utilities; import com.rammelkast.anticheatreloaded.util.Utilities;
import net.gravitydevelopment.anticheat.util.VersionUtil; import com.rammelkast.anticheatreloaded.util.VersionUtil;
public class PlayerListener extends EventListener { public class PlayerListener extends EventListener {
@@ -81,7 +82,7 @@ public class PlayerListener extends EventListener {
} }
} }
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler @EventHandler
@@ -90,7 +91,7 @@ public class PlayerListener extends EventListener {
getBackend().logEnterExit(event.getPlayer()); getBackend().logEnterExit(event.getPlayer());
} }
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler @EventHandler
@@ -99,7 +100,7 @@ public class PlayerListener extends EventListener {
getBackend().logEnterExit(event.getPlayer()); getBackend().logEnterExit(event.getPlayer());
} }
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler @EventHandler
@@ -120,7 +121,7 @@ public class PlayerListener extends EventListener {
} }
} }
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler @EventHandler
@@ -129,14 +130,14 @@ public class PlayerListener extends EventListener {
getBackend().logTeleport(event.getPlayer()); getBackend().logTeleport(event.getPlayer());
} }
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler @EventHandler
public void onPlayerChangeWorlds(PlayerChangedWorldEvent event) { public void onPlayerChangeWorlds(PlayerChangedWorldEvent event) {
getBackend().logTeleport(event.getPlayer()); getBackend().logTeleport(event.getPlayer());
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler @EventHandler
@@ -145,13 +146,13 @@ public class PlayerListener extends EventListener {
getBackend().logToggleSneak(event.getPlayer()); getBackend().logToggleSneak(event.getPlayer());
} }
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler @EventHandler
public void onPlayerVelocity(PlayerVelocityEvent event) { public void onPlayerVelocity(PlayerVelocityEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (getCheckManager().willCheck(player, CheckType.FLY)) { if (getCheckManager().willCheck(player, CheckType.FLIGHT)) {
if (getBackend().justVelocity(player) && getBackend().extendVelocityTime(player)) { if (getBackend().justVelocity(player) && getBackend().extendVelocityTime(player)) {
event.setCancelled(!silentMode()); event.setCancelled(!silentMode());
return; return;
@@ -159,7 +160,7 @@ public class PlayerListener extends EventListener {
getBackend().logVelocity(player); getBackend().logVelocity(player);
} }
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
@@ -174,18 +175,37 @@ public class PlayerListener extends EventListener {
player.sendMessage(ChatColor.RED + result.getMessage()); player.sendMessage(ChatColor.RED + result.getMessage());
} }
getBackend().processChatSpammer(player); getBackend().processChatSpammer(player);
log(null, player, CheckType.CHAT_SPAM); AntiCheatReloaded.sendToMainThread(new Runnable() {
@Override
public void run() {
log(null, player, CheckType.CHAT_SPAM);
}
});
} }
} }
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); if (getCheckManager().willCheck(player, CheckType.CHAT_UNICODE)) {
CheckResult result = getBackend().checkChatUnicode(player, event.getMessage());
if (result.failed()) {
event.setCancelled(true);
player.sendMessage(ChatColor.RED + result.getMessage());
AntiCheatReloaded.sendToMainThread(new Runnable() {
@Override
public void run() {
log(null, player, CheckType.CHAT_UNICODE);
}
});
}
}
AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler @EventHandler
public void onPlayerKick(PlayerKickEvent event) { public void onPlayerKick(PlayerKickEvent event) {
getBackend().garbageClean(event.getPlayer()); getBackend().garbageClean(event.getPlayer());
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler @EventHandler
@@ -196,7 +216,7 @@ public class PlayerListener extends EventListener {
getConfig().getLevels().saveLevelFromUser(user); getConfig().getLevels().saveLevelFromUser(user);
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler @EventHandler
@@ -215,7 +235,7 @@ public class PlayerListener extends EventListener {
} }
} }
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler @EventHandler
@@ -223,10 +243,9 @@ public class PlayerListener extends EventListener {
Player player = event.getPlayer(); Player player = event.getPlayer();
PlayerInventory inv = player.getInventory(); PlayerInventory inv = player.getInventory();
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Material m = inv.getItemInHand().getType(); if (inv.getItemInMainHand().getType() == Material.BOW) {
if (m == Material.BOW) {
getBackend().logBowWindUp(player); getBackend().logBowWindUp(player);
} else if (Utilities.isFood(m)) { } else if (Utilities.isFood(inv.getItemInMainHand().getType()) || Utilities.isFood(inv.getItemInOffHand().getType())) {
getBackend().logEatingStart(player); getBackend().logEatingStart(player);
} }
} }
@@ -237,7 +256,7 @@ public class PlayerListener extends EventListener {
getBackend().checkLongReachBlock(player, distance.getXDifference(), distance.getYDifference(), distance.getZDifference()); getBackend().checkLongReachBlock(player, distance.getXDifference(), distance.getYDifference(), distance.getZDifference());
} }
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
@@ -251,28 +270,28 @@ public class PlayerListener extends EventListener {
} }
} }
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onPlayerEnterBed(PlayerBedEnterEvent event) { public void onPlayerEnterBed(PlayerBedEnterEvent event) {
if (event.getBed().getType() != Material.BED) return; if (event.getBed().getType().name().endsWith("BED")) return;
getBackend().logEnterExit(event.getPlayer()); getBackend().logEnterExit(event.getPlayer());
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onPlayerExitBed(PlayerBedLeaveEvent event) { public void onPlayerExitBed(PlayerBedLeaveEvent event) {
if (event.getBed().getType() != Material.BED) return; if (event.getBed().getType().name().endsWith("BED")) return;
getBackend().logEnterExit(event.getPlayer()); getBackend().logEnterExit(event.getPlayer());
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler @EventHandler
public void onPlayerAnimation(PlayerAnimationEvent event) { public void onPlayerAnimation(PlayerAnimationEvent event) {
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler @EventHandler
@@ -299,12 +318,12 @@ public class PlayerListener extends EventListener {
if (player.hasMetadata(Utilities.SPY_METADATA)) { if (player.hasMetadata(Utilities.SPY_METADATA)) {
for (Player p : player.getServer().getOnlinePlayers()) { for (Player p : player.getServer().getOnlinePlayers()) {
if (!Permission.SYSTEM_SPY.get(p)) { if (!Permission.SYSTEM_SPY.get(p)) {
p.hidePlayer(player); p.hidePlayer(AntiCheatReloaded.getPlugin(), player);
} }
} }
} }
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
@@ -321,7 +340,8 @@ public class PlayerListener extends EventListener {
final User user = getUserManager().getUser(player.getUniqueId()); final User user = getUserManager().getUser(player.getUniqueId());
user.setTo(to.getX(), to.getY(), to.getZ()); user.setTo(to.getX(), to.getY(), to.getZ());
KillAuraCheck.doMove(event); //KillAuraCheck.doMove(event);
//TODO
if (getCheckManager().willCheckQuick(player, CheckType.SPRINT)) { if (getCheckManager().willCheckQuick(player, CheckType.SPRINT)) {
CheckResult result = getBackend().checkSprintStill(player, from, to); CheckResult result = getBackend().checkSprintStill(player, from, to);
@@ -330,22 +350,28 @@ public class PlayerListener extends EventListener {
log(result.getMessage(), player, CheckType.SPRINT); log(result.getMessage(), player, CheckType.SPRINT);
} }
} }
if (getCheckManager().willCheckQuick(player, CheckType.FLY) && !VersionUtil.isFlying(player)) { if (getCheckManager().willCheckQuick(player, CheckType.FLIGHT) && !VersionUtil.isFlying(player)) {
CheckResult result = FlightCheck.runCheck(player, distance); CheckResult result = FlightCheck.runCheck(player, distance);
if (result.failed()) { if (result.failed()) {
if (!silentMode()) { if (!silentMode()) {
event.setTo(user.getGoodLocation(from.clone())); event.setTo(user.getGoodLocation(from.clone()));
} }
log(result.getMessage(), player, CheckType.FLY); log(result.getMessage(), player, CheckType.FLIGHT);
} }
} }
if (getCheckManager().willCheckQuick(player, CheckType.FLY) && !VersionUtil.isFlying(player)) { if (getCheckManager().willCheckQuick(player, CheckType.FLIGHT) && !VersionUtil.isFlying(player)) {
CheckResult result = GlideCheck.runCheck(player, distance); CheckResult result = GlideCheck.runCheck(player, distance);
if (result.failed()) { if (result.failed()) {
// NO TELEPORT NEEDED HERE, HANDLED BY CHECK ITSELF // NO TELEPORT NEEDED HERE, HANDLED BY CHECK ITSELF
log(result.getMessage(), player, CheckType.FLY); log(result.getMessage(), player, CheckType.FLIGHT);
} }
} }
if (getCheckManager().willCheckQuick(player, CheckType.ELYTRA)) {
CheckResult result = ElytraCheck.runCheck(player, distance);
if (result.failed()) {
log(result.getMessage(), player, CheckType.ELYTRA);
}
}
if (getCheckManager().willCheckQuick(player, CheckType.VCLIP) && event.getFrom().getY() > event.getTo().getY()) { if (getCheckManager().willCheckQuick(player, CheckType.VCLIP) && event.getFrom().getY() > event.getTo().getY()) {
CheckResult result = getBackend().checkVClip(player, new Distance(event.getFrom(), event.getTo())); CheckResult result = getBackend().checkVClip(player, new Distance(event.getFrom(), event.getTo()));
if (result.failed()) { if (result.failed()) {
@@ -362,7 +388,7 @@ public class PlayerListener extends EventListener {
log(result.getMessage(), player, CheckType.VCLIP); log(result.getMessage(), player, CheckType.VCLIP);
} }
} }
if (getCheckManager().willCheckQuick(player, CheckType.NOFALL) && getCheckManager().willCheck(player, CheckType.FLY) && !Utilities.isClimbableBlock(player.getLocation().getBlock()) && event.getFrom().getY() > event.getTo().getY()) { if (getCheckManager().willCheckQuick(player, CheckType.NOFALL) && getCheckManager().willCheck(player, CheckType.FLIGHT) && !Utilities.isClimbableBlock(player.getLocation().getBlock()) && event.getFrom().getY() > event.getTo().getY()) {
CheckResult result = getBackend().checkNoFall(player, y); CheckResult result = getBackend().checkNoFall(player, y);
if (result.failed()) { if (result.failed()) {
if (!silentMode()) { if (!silentMode()) {
@@ -377,7 +403,7 @@ public class PlayerListener extends EventListener {
if (event.getTo() != event.getFrom()) { if (event.getTo() != event.getFrom()) {
double x = distance.getXDifference(); double x = distance.getXDifference();
double z = distance.getZDifference(); double z = distance.getZDifference();
if (getCheckManager().willCheckQuick(player, CheckType.SPEED) && getCheckManager().willCheck(player, CheckType.FLY)) { if (getCheckManager().willCheckQuick(player, CheckType.SPEED) && getCheckManager().willCheck(player, CheckType.FLIGHT)) {
if (event.getFrom().getY() < event.getTo().getY()) { if (event.getFrom().getY() < event.getTo().getY()) {
CheckResult result = getBackend().checkYSpeed(player, y); CheckResult result = getBackend().checkYSpeed(player, y);
if (result.failed()) { if (result.failed()) {
@@ -433,12 +459,13 @@ public class PlayerListener extends EventListener {
} }
} }
} }
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler(priority=EventPriority.HIGHEST) @EventHandler(priority=EventPriority.HIGHEST)
public void onDeath(PlayerDeathEvent e) { public void onDeath(PlayerDeathEvent e) {
KillAuraCheck.cleanPlayer(e.getEntity()); // Remove bots on death to reduce lag //KillAuraCheck.cleanPlayer(e.getEntity()); // Remove bots on death to reduce lag
//TODO
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@@ -454,7 +481,7 @@ public class PlayerListener extends EventListener {
return; return;
} }
if (getCheckManager().willCheck(player, CheckType.FLY) && !player.isFlying()) { if (getCheckManager().willCheck(player, CheckType.FLIGHT) && !player.isFlying()) {
CheckResult result1 = YAxisCheck.runCheck(player, new Distance(from, to)); CheckResult result1 = YAxisCheck.runCheck(player, new Distance(from, to));
CheckResult result2 = getBackend().checkAscension(player, from.getY(), to.getY()); CheckResult result2 = getBackend().checkAscension(player, from.getY(), to.getY());
String log = result1.failed() ? result1.getMessage() : result2.failed() ? result2.getMessage() : ""; String log = result1.failed() ? result1.getMessage() : result2.failed() ? result2.getMessage() : "";
@@ -462,7 +489,7 @@ public class PlayerListener extends EventListener {
if (!silentMode()) { if (!silentMode()) {
event.setTo(user.getGoodLocation(from.clone())); event.setTo(user.getGoodLocation(from.clone()));
} }
log(log, player, CheckType.FLY); log(log, player, CheckType.FLIGHT);
} }
} }
} }
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,15 +17,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.event; package com.rammelkast.anticheatreloaded.event;
import net.gravitydevelopment.anticheat.AntiCheat; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.vehicle.VehicleDestroyEvent; import org.bukkit.event.vehicle.VehicleDestroyEvent;
import org.bukkit.event.vehicle.VehicleEnterEvent; import org.bukkit.event.vehicle.VehicleEnterEvent;
import org.bukkit.event.vehicle.VehicleExitEvent; import org.bukkit.event.vehicle.VehicleExitEvent;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
public class VehicleListener extends EventListener { public class VehicleListener extends EventListener {
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
@@ -33,7 +36,7 @@ public class VehicleListener extends EventListener {
getBackend().logEnterExit((Player) event.getEntered()); getBackend().logEnterExit((Player) event.getEntered());
} }
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
@@ -42,16 +45,26 @@ public class VehicleListener extends EventListener {
getBackend().logEnterExit((Player) event.getExited()); getBackend().logEnterExit((Player) event.getExited());
} }
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onVehicleDestroy(VehicleDestroyEvent event) { public void onVehicleDestroy(VehicleDestroyEvent event) {
if (event.getVehicle().getPassenger() != null && event.getVehicle().getPassenger() instanceof Player) { // TODO fix deprecations
getBackend().logEnterExit((Player) event.getVehicle().getPassenger()); //if (event.getVehicle().getPassenger() != null && event.getVehicle().getPassenger() instanceof Player) {
} // getBackend().logEnterExit((Player) event.getVehicle().getPassenger());
//}
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners()); // TODO this should work, untested though.
if (!event.getVehicle().getPassengers().isEmpty()) {
for (Entity entity: event.getVehicle().getPassengers()) {
if (entity instanceof Player) {
getBackend().logEnterExit((Player) entity);
}
}
}
AntiCheatReloaded.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
} }
} }
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.manage; package com.rammelkast.anticheatreloaded.manage;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@@ -25,16 +26,16 @@ import java.util.logging.Logger;
import org.bukkit.plugin.RegisteredListener; import org.bukkit.plugin.RegisteredListener;
import net.gravitydevelopment.anticheat.AntiCheat; import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import net.gravitydevelopment.anticheat.check.Backend; import com.rammelkast.anticheatreloaded.check.Backend;
import net.gravitydevelopment.anticheat.config.Configuration; import com.rammelkast.anticheatreloaded.config.Configuration;
/** /**
* The internal hub for all managers. * The internal hub for all managers.
*/ */
public class AntiCheatManager { public class AntiCheatManager {
private static AntiCheat plugin = null; private static AntiCheatReloaded plugin = null;
private static Configuration configuration; private static Configuration configuration;
private static UserManager userManager = null; private static UserManager userManager = null;
private static CheckManager checkManager = null; private static CheckManager checkManager = null;
@@ -43,7 +44,7 @@ public class AntiCheatManager {
private static Map<String, RegisteredListener[]> eventchains = new ConcurrentHashMap<String, RegisteredListener[]>(); private static Map<String, RegisteredListener[]> eventchains = new ConcurrentHashMap<String, RegisteredListener[]>();
private static Map<String, Long> eventcache = new ConcurrentHashMap<String, Long>(); private static Map<String, Long> eventcache = new ConcurrentHashMap<String, Long>();
public AntiCheatManager(AntiCheat instance, Logger logger) { public AntiCheatManager(AntiCheatReloaded instance, Logger logger) {
plugin = instance; plugin = instance;
configuration = new Configuration(plugin, this); configuration = new Configuration(plugin, this);
loggingManager = new LoggingManager(plugin, logger, configuration); loggingManager = new LoggingManager(plugin, logger, configuration);
@@ -104,7 +105,7 @@ public class AntiCheatManager {
return gen; return gen;
} }
public AntiCheat getPlugin() { public AntiCheatReloaded getPlugin() {
return plugin; return plugin;
} }
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,14 +17,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.manage; package com.rammelkast.anticheatreloaded.manage;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.check.CheckType;
import net.gravitydevelopment.anticheat.config.Configuration;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.CheckType;
import com.rammelkast.anticheatreloaded.config.Configuration;
import com.rammelkast.anticheatreloaded.util.VersionUtil;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@@ -174,9 +177,8 @@ public class CheckManager {
&& !isExempt(player, type) && !isExempt(player, type)
&& !type.checkPermission(player) && !type.checkPermission(player)
&& !isOpExempt(player); && !isOpExempt(player);
AntiCheat.debugLog("Check " + type + (check ? " run " : " not run ") + "on " + player.getName()); AntiCheatReloaded.debugLog("Check " + type + (check ? " run " : " not run ") + "on " + player.getName());
// TODO temp fix if ((type == CheckType.FLIGHT || type == CheckType.SPEED) && VersionUtil.isFlying(player))
if ((type == CheckType.FLY || type == CheckType.SPEED) && player.isFlying())
return false; return false;
return check; return check;
} }
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,16 +17,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.manage; package com.rammelkast.anticheatreloaded.manage;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.config.Configuration;
import net.gravitydevelopment.anticheat.util.FileFormatter;
import net.gravitydevelopment.anticheat.util.Permission;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.config.Configuration;
import com.rammelkast.anticheatreloaded.util.FileFormatter;
import com.rammelkast.anticheatreloaded.util.Permission;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
@@ -41,8 +43,8 @@ public class LoggingManager {
private static List<String> logs = new CopyOnWriteArrayList<String>(); private static List<String> logs = new CopyOnWriteArrayList<String>();
private final Configuration config; private final Configuration config;
public LoggingManager(AntiCheat plugin, Logger logger, Configuration config) { public LoggingManager(AntiCheatReloaded plugin, Logger logger, Configuration config) {
this.fileLogger = Logger.getLogger("net.gravitydevelopment.anticheat.AntiCheat"); this.fileLogger = Logger.getLogger("com.rammelkast.anticheatreloaded.AntiCheatReloaded");
this.config = config; this.config = config;
try { try {
File file = new File(plugin.getDataFolder(), "log"); File file = new File(plugin.getDataFolder(), "log");
@@ -69,12 +71,12 @@ public class LoggingManager {
} }
public void debugLog(String message) { public void debugLog(String message) {
Bukkit.getConsoleSender().sendMessage("[AntiCheat] " + ChatColor.GRAY + message); Bukkit.getConsoleSender().sendMessage("[ACR] " + ChatColor.GRAY + message);
logToLogs(message); logToLogs(message);
} }
public void logToConsole(String message) { public void logToConsole(String message) {
Bukkit.getConsoleSender().sendMessage("[AntiCheat] " + ChatColor.RED + message); Bukkit.getConsoleSender().sendMessage("[ACR] " + ChatColor.RED + message);
} }
public void logToFile(String message) { public void logToFile(String message) {
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,21 +17,23 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.manage; package com.rammelkast.anticheatreloaded.manage;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.check.CheckType;
import net.gravitydevelopment.anticheat.config.Configuration;
import net.gravitydevelopment.anticheat.util.Group;
import net.gravitydevelopment.anticheat.util.User;
import net.gravitydevelopment.anticheat.util.Utilities;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.bukkit.BanList.Type;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.CheckType;
import com.rammelkast.anticheatreloaded.config.Configuration;
import com.rammelkast.anticheatreloaded.util.Group;
import com.rammelkast.anticheatreloaded.util.User;
import com.rammelkast.anticheatreloaded.util.Utilities;
public class UserManager { public class UserManager {
private List<User> users = new ArrayList<User>(); private List<User> users = new ArrayList<User>();
private static AntiCheatManager manager; private static AntiCheatManager manager;
@@ -215,9 +218,12 @@ public class UserManager {
*/ */
public void execute(final User user, final List<String> actions, final CheckType type, final String kickReason, final List<String> warning, final String banReason) { public void execute(final User user, final List<String> actions, final CheckType type, final String kickReason, final List<String> warning, final String banReason) {
// Execute synchronously for thread safety when called from AsyncPlayerChatEvent // Execute synchronously for thread safety when called from AsyncPlayerChatEvent
Bukkit.getScheduler().scheduleSyncDelayedTask(AntiCheat.getPlugin(), new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(AntiCheatReloaded.getPlugin(), new Runnable() {
@Override @Override
public void run() { public void run() {
if (user.getPlayer() == null) {
return;
}
final String name = user.getName(); final String name = user.getName();
for (String event : actions) { for (String event : actions) {
event = event.replaceAll("&player", name).replaceAll("&world", user.getPlayer().getWorld().getName()).replaceAll("&check", type.name()); event = event.replaceAll("&player", name).replaceAll("&world", user.getPlayer().getWorld().getName()).replaceAll("&check", type.name());
@@ -228,6 +234,7 @@ public class UserManager {
} }
} else if (event.equalsIgnoreCase("KICK")) { } else if (event.equalsIgnoreCase("KICK")) {
user.getPlayer().kickPlayer(RED + kickReason); user.getPlayer().kickPlayer(RED + kickReason);
AntiCheatReloaded.getPlugin().onPlayerKicked();
String msg = RED + config.getLang().KICK_BROADCAST().replaceAll("&player", name) + " (" + CheckType.getName(type) + ")"; String msg = RED + config.getLang().KICK_BROADCAST().replaceAll("&player", name) + " (" + CheckType.getName(type) + ")";
if (!msg.equals("")) { if (!msg.equals("")) {
manager.log(msg); manager.log(msg);
@@ -241,7 +248,7 @@ public class UserManager {
} }
} }
} else if (event.equalsIgnoreCase("BAN")) { } else if (event.equalsIgnoreCase("BAN")) {
user.getPlayer().setBanned(true); Bukkit.getBanList(Type.NAME).addBan(user.getPlayer().getName(), RED + banReason, null, null);
user.getPlayer().kickPlayer(RED + banReason); user.getPlayer().kickPlayer(RED + banReason);
String msg = RED + config.getLang().BAN_BROADCAST().replaceAll("&player", name) + " (" + CheckType.getName(type) + ")"; String msg = RED + config.getLang().BAN_BROADCAST().replaceAll("&player", name) + " (" + CheckType.getName(type) + ")";
if (!msg.equals("")) { if (!msg.equals("")) {
@@ -0,0 +1,767 @@
/*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded.metrics;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.zip.GZIPOutputStream;
import javax.net.ssl.HttpsURLConnection;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.ServicePriority;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
/**
* bStats collects some data for plugin authors.
* <p>
* Check out https://bStats.org/ to learn more about bStats!
*/
@SuppressWarnings({ "WeakerAccess", "unused" })
public class Metrics {
static {
// You can use the property to disable the check in your test environment
if (System.getProperty("bstats.relocatecheck") == null
|| !System.getProperty("bstats.relocatecheck").equals("false")) {
// Maven's Relocate is clever and changes strings, too. So we have to use this
// little "trick" ... :D
final String defaultPackage = new String(
new byte[] { 'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't' });
final String examplePackage = new String(
new byte[] { 'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e' });
// We want to make sure nobody just copy & pastes the example and use the wrong
// package names
if (Metrics.class.getPackage().getName().equals(defaultPackage)
|| Metrics.class.getPackage().getName().equals(examplePackage)) {
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
}
}
}
// The version of this bStats class
public static final int B_STATS_VERSION = 1;
// The url to which the data is sent
private static final String URL = "https://bStats.org/submitData/bukkit";
// Is bStats enabled on this server?
private boolean enabled;
// Should failed requests be logged?
private static boolean logFailedRequests;
// Should the sent data be logged?
private static boolean logSentData;
// Should the response text be logged?
private static boolean logResponseStatusText;
// The uuid of the server
private static String serverUUID;
// The plugin
private final Plugin plugin;
// The plugin id
private final int pluginId;
// A list with all custom charts
private final List<CustomChart> charts = new ArrayList<>();
/**
* Class constructor.
*
* @param plugin The plugin which stats should be submitted.
* @param pluginId The id of the plugin. It can be found at
* <a href="https://bstats.org/what-is-my-plugin-id">What is my
* plugin id?</a>
*/
public Metrics(Plugin plugin, int pluginId) {
if (plugin == null) {
throw new IllegalArgumentException("Plugin cannot be null!");
}
this.plugin = plugin;
this.pluginId = pluginId;
// Get the config file
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
File configFile = new File(bStatsFolder, "config.yml");
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
// Check if the config file exists
if (!config.isSet("serverUuid")) {
// Add default values
config.addDefault("enabled", true);
// Every server gets it's unique random id.
config.addDefault("serverUuid", UUID.randomUUID().toString());
// Should failed request be logged?
config.addDefault("logFailedRequests", false);
// Should the sent data be logged?
config.addDefault("logSentData", false);
// Should the response text be logged?
config.addDefault("logResponseStatusText", false);
// Inform the server owners about bStats
config.options().header(
"bStats collects some data for plugin authors like how many servers are using their plugins.\n"
+ "To honor their work, you should not disable it.\n"
+ "This has nearly no effect on the server performance!\n"
+ "Check out https://bStats.org/ to learn more :)")
.copyDefaults(true);
try {
config.save(configFile);
} catch (IOException ignored) {
}
}
// Load the data
enabled = config.getBoolean("enabled", true);
serverUUID = config.getString("serverUuid");
logFailedRequests = config.getBoolean("logFailedRequests", false);
logSentData = config.getBoolean("logSentData", false);
logResponseStatusText = config.getBoolean("logResponseStatusText", false);
if (enabled) {
boolean found = false;
// Search for all other bStats Metrics classes to see if we are the first one
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
try {
service.getField("B_STATS_VERSION"); // Our identifier :)
found = true; // We aren't the first
break;
} catch (NoSuchFieldException ignored) {
}
}
// Register our service
Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal);
if (!found) {
// We are the first!
startSubmitting();
}
}
}
/**
* Checks if bStats is enabled.
*
* @return Whether bStats is enabled or not.
*/
public boolean isEnabled() {
return enabled;
}
/**
* Adds a custom chart.
*
* @param chart The chart to add.
*/
public void addCustomChart(CustomChart chart) {
if (chart == null) {
throw new IllegalArgumentException("Chart cannot be null!");
}
charts.add(chart);
}
/**
* Starts the Scheduler which submits our data every 30 minutes.
*/
private void startSubmitting() {
final Timer timer = new Timer(true); // We use a timer cause the Bukkit scheduler is affected by server lags
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if (!plugin.isEnabled()) { // Plugin was disabled
timer.cancel();
return;
}
// Nevertheless we want our code to run in the Bukkit main thread, so we have to
// use the Bukkit scheduler
// Don't be afraid! The connection to the bStats server is still async, only the
// stats collection is sync ;)
Bukkit.getScheduler().runTask(plugin, () -> submitData());
}
}, 1000 * 60 * 5, 1000 * 60 * 30);
// Submit the data every 30 minutes, first time after 5 minutes to give other
// plugins enough time to start
// WARNING: Changing the frequency has no effect but your plugin WILL be
// blocked/deleted!
// WARNING: Just don't do it!
}
/**
* Gets the plugin specific data. This method is called using Reflection.
*
* @return The plugin specific data.
*/
public JsonObject getPluginData() {
JsonObject data = new JsonObject();
String pluginName = plugin.getDescription().getName();
String pluginVersion = plugin.getDescription().getVersion();
data.addProperty("pluginName", pluginName); // Append the name of the plugin
data.addProperty("id", pluginId); // Append the id of the plugin
data.addProperty("pluginVersion", pluginVersion); // Append the version of the plugin
JsonArray customCharts = new JsonArray();
for (CustomChart customChart : charts) {
// Add the data of the custom charts
JsonObject chart = customChart.getRequestJsonObject();
if (chart == null) { // If the chart is null, we skip it
continue;
}
customCharts.add(chart);
}
data.add("customCharts", customCharts);
return data;
}
/**
* Gets the server specific data.
*
* @return The server specific data.
*/
private JsonObject getServerData() {
// Minecraft specific data
int playerAmount;
try {
// Around MC 1.8 the return type was changed to a collection from an array,
// This fixes java.lang.NoSuchMethodError:
// org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class)
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
} catch (Exception e) {
playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed
}
int onlineMode = Bukkit.getOnlineMode() ? 1 : 0;
String bukkitVersion = Bukkit.getVersion();
String bukkitName = Bukkit.getName();
// OS/Java specific data
String javaVersion = System.getProperty("java.version");
String osName = System.getProperty("os.name");
String osArch = System.getProperty("os.arch");
String osVersion = System.getProperty("os.version");
int coreCount = Runtime.getRuntime().availableProcessors();
JsonObject data = new JsonObject();
data.addProperty("serverUUID", serverUUID);
data.addProperty("playerAmount", playerAmount);
data.addProperty("onlineMode", onlineMode);
data.addProperty("bukkitVersion", bukkitVersion);
data.addProperty("bukkitName", bukkitName);
data.addProperty("javaVersion", javaVersion);
data.addProperty("osName", osName);
data.addProperty("osArch", osArch);
data.addProperty("osVersion", osVersion);
data.addProperty("coreCount", coreCount);
return data;
}
/**
* Collects the data and sends it afterwards.
*/
private void submitData() {
final JsonObject data = getServerData();
JsonArray pluginData = new JsonArray();
// Search for all other bStats Metrics classes to get their plugin data
for (Class<?> service : Bukkit.getServicesManager().getKnownServices()) {
try {
service.getField("B_STATS_VERSION"); // Our identifier :)
for (RegisteredServiceProvider<?> provider : Bukkit.getServicesManager().getRegistrations(service)) {
try {
Object plugin = provider.getService().getMethod("getPluginData").invoke(provider.getProvider());
if (plugin instanceof JsonObject) {
pluginData.add((JsonObject) plugin);
} else { // old bstats version compatibility
try {
Class<?> jsonObjectJsonSimple = Class.forName("org.json.simple.JSONObject");
if (plugin.getClass().isAssignableFrom(jsonObjectJsonSimple)) {
Method jsonStringGetter = jsonObjectJsonSimple.getDeclaredMethod("toJSONString");
jsonStringGetter.setAccessible(true);
String jsonString = (String) jsonStringGetter.invoke(plugin);
JsonObject object = new JsonParser().parse(jsonString).getAsJsonObject();
pluginData.add(object);
}
} catch (ClassNotFoundException e) {
// minecraft version 1.14+
if (logFailedRequests) {
this.plugin.getLogger().log(Level.SEVERE, "Encountered unexpected exception", e);
}
}
}
} catch (NullPointerException | NoSuchMethodException | IllegalAccessException
| InvocationTargetException ignored) {
}
}
} catch (NoSuchFieldException ignored) {
}
}
data.add("plugins", pluginData);
// Create a new thread for the connection to the bStats server
new Thread(() -> {
try {
// Send the data
sendData(plugin, data);
} catch (Exception e) {
// Something went wrong! :(
if (logFailedRequests) {
plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e);
}
}
}).start();
}
/**
* Sends the data to the bStats server.
*
* @param plugin Any plugin. It's just used to get a logger instance.
* @param data The data to send.
* @throws Exception If the request failed.
*/
private static void sendData(Plugin plugin, JsonObject data) throws Exception {
if (data == null) {
throw new IllegalArgumentException("Data cannot be null!");
}
if (Bukkit.isPrimaryThread()) {
throw new IllegalAccessException("This method must not be called from the main thread!");
}
if (logSentData) {
plugin.getLogger().info("Sending data to bStats: " + data);
}
HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection();
// Compress the data to save bandwidth
byte[] compressedData = compress(data.toString());
// Add headers
connection.setRequestMethod("POST");
connection.addRequestProperty("Accept", "application/json");
connection.addRequestProperty("Connection", "close");
connection.addRequestProperty("Content-Encoding", "gzip"); // We gzip our request
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
connection.setRequestProperty("Content-Type", "application/json"); // We send our data in JSON format
connection.setRequestProperty("User-Agent", "MC-Server/" + B_STATS_VERSION);
// Send data
connection.setDoOutput(true);
try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
outputStream.write(compressedData);
}
StringBuilder builder = new StringBuilder();
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
String line;
while ((line = bufferedReader.readLine()) != null) {
builder.append(line);
}
}
if (logResponseStatusText) {
plugin.getLogger().info("Sent data to bStats and received response: " + builder);
}
}
/**
* Gzips the given String.
*
* @param str The string to gzip.
* @return The gzipped String.
* @throws IOException If the compression failed.
*/
private static byte[] compress(final String str) throws IOException {
if (str == null) {
return null;
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
gzip.write(str.getBytes(StandardCharsets.UTF_8));
}
return outputStream.toByteArray();
}
/**
* Represents a custom chart.
*/
public static abstract class CustomChart {
// The id of the chart
final String chartId;
/**
* Class constructor.
*
* @param chartId The id of the chart.
*/
CustomChart(String chartId) {
if (chartId == null || chartId.isEmpty()) {
throw new IllegalArgumentException("ChartId cannot be null or empty!");
}
this.chartId = chartId;
}
private JsonObject getRequestJsonObject() {
JsonObject chart = new JsonObject();
chart.addProperty("chartId", chartId);
try {
JsonObject data = getChartData();
if (data == null) {
// If the data is null we don't send the chart.
return null;
}
chart.add("data", data);
} catch (Throwable t) {
if (logFailedRequests) {
Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t);
}
return null;
}
return chart;
}
protected abstract JsonObject getChartData() throws Exception;
}
/**
* Represents a custom simple pie.
*/
public static class SimplePie extends CustomChart {
private final Callable<String> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public SimplePie(String chartId, Callable<String> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
String value = callable.call();
if (value == null || value.isEmpty()) {
// Null = skip the chart
return null;
}
data.addProperty("value", value);
return data;
}
}
/**
* Represents a custom advanced pie.
*/
public static class AdvancedPie extends CustomChart {
private final Callable<Map<String, Integer>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean allSkipped = true;
for (Map.Entry<String, Integer> entry : map.entrySet()) {
if (entry.getValue() == 0) {
continue; // Skip this invalid
}
allSkipped = false;
values.addProperty(entry.getKey(), entry.getValue());
}
if (allSkipped) {
// Null = skip the chart
return null;
}
data.add("values", values);
return data;
}
}
/**
* Represents a custom drilldown pie.
*/
public static class DrilldownPie extends CustomChart {
private final Callable<Map<String, Map<String, Integer>>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
super(chartId);
this.callable = callable;
}
@Override
public JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Map<String, Integer>> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean reallyAllSkipped = true;
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
JsonObject value = new JsonObject();
boolean allSkipped = true;
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
value.addProperty(valueEntry.getKey(), valueEntry.getValue());
allSkipped = false;
}
if (!allSkipped) {
reallyAllSkipped = false;
values.add(entryValues.getKey(), value);
}
}
if (reallyAllSkipped) {
// Null = skip the chart
return null;
}
data.add("values", values);
return data;
}
}
/**
* Represents a custom single line chart.
*/
public static class SingleLineChart extends CustomChart {
private final Callable<Integer> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public SingleLineChart(String chartId, Callable<Integer> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
int value = callable.call();
if (value == 0) {
// Null = skip the chart
return null;
}
data.addProperty("value", value);
return data;
}
}
/**
* Represents a custom multi line chart.
*/
public static class MultiLineChart extends CustomChart {
private final Callable<Map<String, Integer>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean allSkipped = true;
for (Map.Entry<String, Integer> entry : map.entrySet()) {
if (entry.getValue() == 0) {
continue; // Skip this invalid
}
allSkipped = false;
values.addProperty(entry.getKey(), entry.getValue());
}
if (allSkipped) {
// Null = skip the chart
return null;
}
data.add("values", values);
return data;
}
}
/**
* Represents a custom simple bar chart.
*/
public static class SimpleBarChart extends CustomChart {
private final Callable<Map<String, Integer>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
for (Map.Entry<String, Integer> entry : map.entrySet()) {
JsonArray categoryValues = new JsonArray();
categoryValues.add(new JsonPrimitive(entry.getValue()));
values.add(entry.getKey(), categoryValues);
}
data.add("values", values);
return data;
}
}
/**
* Represents a custom advanced bar chart.
*/
public static class AdvancedBarChart extends CustomChart {
private final Callable<Map<String, int[]>> callable;
/**
* Class constructor.
*
* @param chartId The id of the chart.
* @param callable The callable which is used to request the chart data.
*/
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
super(chartId);
this.callable = callable;
}
@Override
protected JsonObject getChartData() throws Exception {
JsonObject data = new JsonObject();
JsonObject values = new JsonObject();
Map<String, int[]> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean allSkipped = true;
for (Map.Entry<String, int[]> entry : map.entrySet()) {
if (entry.getValue().length == 0) {
continue; // Skip this invalid
}
allSkipped = false;
JsonArray categoryValues = new JsonArray();
for (int categoryValue : entry.getValue()) {
categoryValues.add(new JsonPrimitive(categoryValue));
}
values.add(entry.getKey(), categoryValues);
}
if (allSkipped) {
// Null = skip the chart
return null;
}
data.add("values", values);
return data;
}
}
}
@@ -0,0 +1,86 @@
/*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded.util;
import org.bukkit.Material;
public enum BlockHardness {
STONE(1.50D), GRASS(0.60D), DIRT(0.50D), COBBLESTONE(2.00D), WOOD(2.00D), SAPLING(0.00D), WATER(100.00D),
STATIONARY_WATER(100.00D), LAVA(0.00D), STATIONARY_LAVA(100.00D), SAND(0.50D), GRAVEL(0.60D), GOLD_ORE(3.00D),
IRON_ORE(3.00D), COAL_ORE(3.00D), LOG(2.00D), LOG_2(2.00D), LEAVES(0.20D), LEAVES_2(0.20D), SPONGE(0.60D),
GLASS(0.30D), LAPIS_ORE(3.00D), LAPIS_BLOCK(3.00D), DISPENSER(3.50D), DROPPER(3.50D), SANDSTONE(0.80D),
NOTE_BLOCK(0.80D), BED(0.20D), RAILS(0.70D), DETECTOR_RAIL(0.70D), POWERED_RAIL(0.70D), ACTIVATOR_RAIL(0.70D),
WEB(4.00D), LONG_GRASS(0.00D), DOUBLE_PLANT(0.00D), DEAD_BUSH(0.00D), WOOL(0.80D), YELLOW_FLOWER(0.00D),
RED_ROSE(0.00D), BROWN_MUSHROOM(0.00D), RED_MUSHROOM(0.00D), GOLD_BLOCK(3.00D), IRON_BLOCK(5.00D),
DOUBLE_STEP(2.00D), STEP(2.00D), BRICK(2.00D), TNT(0.00D), BOOKSHELF(1.50D), MOSSY_COBBLESTONE(2.00D),
OBSIDIAN(50.00D), TORCH(0.00D), FIRE(0.00D), MOB_SPAWNER(5.00D), CHEST(2.50D), TRAPPED_CHEST(2.50D),
REDSTONE_WIRE(0.00D), DIAMOND_ORE(3.00D), DIAMOND_BLOCK(5.00D), WORKBENCH(2.50D), SOIL(0.60D), FURNACE(3.50D),
BURNING_FURNACE(3.50D), WOODEN_DOOR(3.00D), LADDER(0.40D), LEVER(0.50D), IRON_DOOR_BLOCK(5.00D), HOPPER(2.00D),
STONE_PLATE(0.50D), WOOD_PLATE(0.50D), GOLD_PLATE(0.50D), IRON_PLATE(0.50D), QUARTZ_BLOCK(0.80D), QUARTZ_ORE(3.00D),
REDSTONE_BLOCK(5.00D), REDSTONE_ORE(3.00D), GLOWING_REDSTONE_ORE(3.00D), REDSTONE_TORCH_OFF(0.00D),
REDSTONE_TORCH_ON(0.00D), REDSTONE_COMPARATOR_OFF(0.00D), REDSTONE_COMPARATOR_ON(0.00D), DAYLIGHT_DETECTOR(0.20D),
STONE_BUTTON(0.50D), SNOW(0.10D), ICE(0.50D), PACKED_ICE(0.50D), SNOW_BLOCK(0.20D), CACTUS(0.40D), CLAY(0.60D),
HARD_CLAY(1.25D), STAINED_CLAY(1.25D), SUGAR_CANE_BLOCK(0.00D), JUKEBOX(2.00D), FENCE(2.00D), NETHERRACK(0.40D),
SOUL_SAND(0.50D), GLOWSTONE(0.30D), PORTAL(-1.00D), CAKE_BLOCK(0.50D), LOCKED_CHEST(0.00D), TRAP_DOOR(3.00D),
MONSTER_EGGS(0.750D), SMOOTH_BRICK(1.50D), IRON_FENCE(5.00D), THIN_GLASS(0.30D), STAINED_GLASS(0.30D),
STAINED_GLASS_PANE(0.30D), PUMPKIN_STEM(0.00D), MELON_STEM(0.00D), VINE(0.20D), FENCE_GATE(2.00D), MYCEL(0.60D),
WATER_LILY(0.00D), NETHER_BRICK(2.00D), NETHER_FENCE(2.00D), ENCHANTMENT_TABLE(5.00D), BREWING_STAND(0.50D),
CAULDRON(2.00D), ENDER_PORTAL(-1.00D), ENDER_PORTAL_FRAME(-1.00D), DRAGON_EGG(3.00D), REDSTONE_LAMP_OFF(0.30D),
REDSTONE_LAMP_ON(0.30D), WOOD_DOUBLE_STEP(2.00D), WOOD_STEP(2.00D), COCOA(0.20D), EMERALD_ORE(3.00D),
ENDER_CHEST(22.50D), EMERALD_BLOCK(5.00D), FLOWER_POT(0.00D), WOOD_BUTTON(0.50D), ANVIL(5.00D),
HUGE_MUSHROOM_1(0.20D), HUGE_MUSHROOM_2(0.20D), BED_BLOCK(0.20D), WOOD_STAIRS(2.00D), COBBLESTONE_STAIRS(2.00D),
BRICK_STAIRS(2.00D), SMOOTH_STAIRS(1.50D), NETHER_BRICK_STAIRS(2.00D), SPRUCE_WOOD_STAIRS(2.00D),
BIRCH_WOOD_STAIRS(2.00D), JUNGLE_WOOD_STAIRS(2.00D), DARK_OAK_STAIRS(2.00D), ACACIA_STAIRS(2.00D),
QUARTZ_STAIRS(0.80D), SANDSTONE_STAIRS(0.80D), COMMAND(0.00D), BEACON(3.00D), COBBLE_WALL(2.00D), CROPS(0.00D),
CARROT(0.00D), POTATO(0.00D), SKULL(1.00D), NETHER_WARTS(0.00D), SIGN_POST(1.00D), WALL_SIGN(1.00D), PUMPKIN(1.00D),
JACK_O_LANTERN(1.00D), DIODE_BLOCK_ON(0.00D), DIODE_BLOCK_OFF(0.00D), MELON_BLOCK(1.00D), ENDER_STONE(3.00D),
TRIPWIRE(0.00D), TRIPWIRE_HOOK(0.00D), HAY_BLOCK(0.50D), CARPET(0.10D), COAL_BLOCK(5.00D), PISTON_BASE(0.70D),
PISTON_EXTENSION(0.70D), PISTON_MOVING_PIECE(0.70D), PISTON_STICKY_BASE(0.70D);
Material mat;
double hardness;
BlockHardness(double hard) {
mat = Material.getMaterial(name());
hardness = hard;
}
public static double getBlockHardness(Material m) {
try {
BlockHardness h = getHardness(m);
return h == null ? 0D : h.hardness;
} catch (Exception e) {
return 0D;
}
}
public static boolean hasBlockHardness(Material m) {
return getHardness(m) != null;
}
public static BlockHardness getHardness(Material m) {
for (BlockHardness e : BlockHardness.values()) {
if (e.mat.equals(m)) {
return e;
}
}
return null;
}
}
@@ -0,0 +1,60 @@
/*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded.util;
import org.bukkit.Location;
public class Distance {
private final double l1Y;
private final double l2Y;
private final double XDiff;
private final double YDiff;
private final double ZDiff;
public Distance(Location from, Location to) {
l1Y = to.getY();
l2Y = from.getY();
XDiff = Math.abs(to.getX() - from.getX());
ZDiff = Math.abs(to.getZ() - from.getZ());
YDiff = Math.abs(l1Y - l2Y);
}
public double fromY() {
return l2Y;
}
public double toY() {
return l1Y;
}
public double getXDifference() {
return XDiff;
}
public double getZDifference() {
return ZDiff;
}
public double getYDifference() {
return YDiff;
}
}
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.util; package com.rammelkast.anticheatreloaded.util;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@@ -25,12 +26,14 @@ import java.util.logging.Formatter;
import java.util.logging.LogRecord; import java.util.logging.LogRecord;
public class FileFormatter extends Formatter { public class FileFormatter extends Formatter {
private static final DateFormat FORMAT = new SimpleDateFormat("h:mm:ss"); private static final DateFormat FORMAT = new SimpleDateFormat("h:mm:ss");
private static final String LINE_SEP = System.getProperty("line.separator"); private static final String LINE_SEP = System.getProperty("line.separator");
@Override @Override
public String format(LogRecord record) { public String format(LogRecord record) {
StringBuilder output = new StringBuilder().append("[").append(record.getLevel()).append('|').append(FORMAT.format(new Date(record.getMillis()))).append("]: ").append(record.getMessage()).append(' ').append(LINE_SEP); StringBuilder output = new StringBuilder().append("[").append(record.getLevel()).append('|')
return output.toString(); .append(FORMAT.format(new Date(record.getMillis()))).append("]: ").append(record.getMessage())
} .append(' ').append(LINE_SEP);
return output.toString();
}
} }
@@ -0,0 +1,95 @@
/*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded.util;
import org.bukkit.ChatColor;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Group {
private String name;
private int level;
private ChatColor color = ChatColor.RED;
private List<String> actions = new ArrayList<String>();
public Group(String name, int level, String color, List<String> actions) {
this.name = name;
this.level = level;
this.actions = actions;
ChatColor c = ChatColor.valueOf(color);
if (c == null) {
AntiCheatReloaded.getPlugin().getLogger()
.warning("Event '" + name + "' was initialized with the color '" + color + "' which is invalid.");
AntiCheatReloaded.getPlugin().getLogger().warning(
"This event will not run properly. See http://jd.bukkit.org/apidocs/org/bukkit/ChatColor.html#enum_constant_summary for a list of valid colors");
} else {
this.color = c;
}
}
public String getName() {
return name;
}
public int getLevel() {
return level;
}
public ChatColor getColor() {
return color;
}
public List<String> getActions() {
return actions;
}
public static Group load(String string) {
try {
if (string.split(" : ").length == 4) {
String name = string.split(" : ")[0];
int level = Integer.parseInt(string.split(" : ")[1]);
String color = string.split(" : ")[2];
List<String> actions = Arrays.asList(string.split(" : ")[3].split(","));
return new Group(name, level, color, actions);
} else {
throw new Exception();
}
} catch (Exception ex) {
AntiCheatReloaded.getPlugin().getLogger()
.warning("An event was initialized with an invalid string: '" + string + "'");
AntiCheatReloaded.getPlugin().getLogger().warning(
"The proper format is: 'name : threshold : color : action' such as 'High : 50 : RED : KICK'");
AntiCheatReloaded.getPlugin().getLogger().warning("This event will NOT run. (" + ex.getMessage() + ")");
return null;
}
}
@Override
public String toString() {
return name + " : " + level + " : " + color.name() + " : " + Utilities.listToCommaString(actions);
}
}
@@ -0,0 +1,44 @@
/*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded.util;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
public class NameGenerator {
private static final List<String> BEGIN = Arrays.asList(new String[] { "Pixel", "Pro", "NoHax", "Just", "That",
"New", "Ultra", "Killer", "Swift", "Anarchy", "Yolo", "Rammel" });
private static final List<String> END = Arrays.asList(new String[] { "Gamer", "PvP", "JustYolo", "Gaming",
"Minecraft", "Games", "Bawz", "Tech", "Noob", "Extra", "kast", "" + new Random().nextInt(100) });
public static String generateName() {
Random r = new Random();
String begin = BEGIN.get(r.nextInt(BEGIN.size() - 1));
String end = END.get(r.nextInt(END.size() - 1));
if (r.nextBoolean())
return begin + end + r.nextInt(9);
else
return begin + end;
}
}
@@ -0,0 +1,67 @@
/*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded.util;
import org.bukkit.command.CommandSender;
public enum Permission {
/* Check Nodes */
CHECK_ZOMBE_FLY, CHECK_ZOMBE_NOCLIP, CHECK_ZOMBE_CHEAT, CHECK_FLIGHT, CHECK_ELYTRA, CHECK_WATERWALK, CHECK_NOSWING, CHECK_FASTBREAK,
CHECK_FASTPLACE, CHECK_CHATSPAM, CHECK_COMMANDSPAM, CHECK_SPRINT, CHECK_SNEAK, CHECK_SPEED, CHECK_VCLIP,
CHECK_SPIDER, CHECK_NOFALL, CHECK_FASTBOW, CHECK_FASTEAT, CHECK_FASTHEAL, CHECK_FORCEFIELD, CHECK_LONGREACH,
CHECK_FASTPROJECTILE, CHECK_ITEMSPAM, CHECK_VISUAL, CHECK_FASTINVENTORY, CHECK_AUTOTOOL, CHECK_BLINK, CHECK_VELOCITY, CHECK_CRITICALS, CHECK_UNICODE,
/* System Nodes */
SYSTEM_LOG, SYSTEM_RESET, SYSTEM_SPY, SYSTEM_HELP, SYSTEM_UPDATE, SYSTEM_REPORT, SYSTEM_ALERT, SYSTEM_NOTICE,
SYSTEM_CALIBRATE, SYSTEM_CHECK, SYSTEM_DEBUG, SYSTEM_RELOAD;
private static final String PERMISSION_ALL = "anticheat.*";
private static final String PERMISSION_SPAM = "anticheat.check.spam";
public static boolean getCommandExempt(CommandSender cs, String commandLabel) {
// Check permission, base, and all will have already been checked
return cs.hasPermission(CHECK_COMMANDSPAM.toString() + commandLabel);
}
public boolean get(CommandSender cs) {
if ((this == CHECK_CHATSPAM || this == CHECK_COMMANDSPAM) && cs.hasPermission(PERMISSION_SPAM))
return true;
return cs.hasPermission(toString()) || cs.hasPermission(getBase()) || cs.hasPermission(PERMISSION_ALL);
}
public String getBase() {
return "anticheat." + this.name().toLowerCase().split("_")[0] + ".*";
}
public String whichPermission(CommandSender cs) {
for (String s : new String[] { PERMISSION_ALL, getBase(), toString() }) {
if (cs.hasPermission(s)) {
return s;
}
}
return null;
}
@Override
public String toString() {
return "anticheat." + this.name().toLowerCase().replace("_", ".");
}
}
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,33 +17,28 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.util; package com.rammelkast.anticheatreloaded.util;
import org.bukkit.Material; import org.bukkit.Material;
public enum ToolHardness { public enum ToolHardness {
// NOTHING(null, 1.5) // NOTHING(null, 1.5)
WOOD(0.75D), WOOD(0.75D), STONE(0.40D), IRON(0.25D), DIAMOND(0.20D), SHEARS(0.55D), GOLD(0.15D);
STONE(0.40D),
IRON(0.25D),
DIAMOND(0.20D),
SHEARS(0.55D),
GOLD(0.15D);
double hardness; double hardness;
ToolHardness(double hard) { ToolHardness(double hard) {
hardness = hard; hardness = hard;
} }
public static double getToolHardness(Material tool) { public static double getToolHardness(Material tool) {
for (ToolHardness e : ToolHardness.values()) { for (ToolHardness e : ToolHardness.values()) {
if (tool.name().contains(e.name())) { if (tool.name().contains(e.name())) {
return e.hardness; return e.hardness;
} }
} }
return 1.50D; return 1.50D;
} }
} }
@@ -0,0 +1,436 @@
/*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded.util;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.CheckType;
import com.rammelkast.anticheatreloaded.config.Configuration;
import com.rammelkast.anticheatreloaded.util.rule.Rule;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class User {
private final UUID uuid;
private final String name;
private final int id;
private int level = 0;
private Location goodLocation;
private List<ItemStack> inventorySnapshot = null;
private Configuration config = AntiCheatReloaded.getManager().getConfiguration();
private int toX, toY, toZ;
private String[] messages = new String[2];
private Long[] messageTimes = new Long[2];
private String[] commands = new String[2];
private Long[] commandTimes = new Long[2];
private boolean isWaitingOnLevelSync;
private Timestamp levelSyncTimestamp;
/**
* Initialize an AntiCheat user
*
* @param uuid Player's UUID
*/
public User(UUID uuid) {
this.uuid = uuid;
this.name = getPlayer() != null && getPlayer().isOnline() ? getPlayer().getName() : "";
this.id = getPlayer() != null && getPlayer().isOnline() ? getPlayer().getEntityId() : -1;
}
/**
* Initialize an AntiCheat user
*
* @param name Player's name
*/
/*
* public User(String name) { this.uuid = Bukkit.getPlayer(name).getUniqueId();
* this.name = name; this.id = getPlayer() != null && getPlayer().isOnline() ?
* getPlayer().getEntityId() : -1; }
*/
/**
* Get the player's UUID
*
* @return Player UUID
*/
public UUID getUUID() {
return uuid;
}
/**
* Get the player's name
*
* @return Player name
*/
public String getName() {
return name;
}
/**
* Get the player's entity ID
*
* @return Entity id
*/
public int getId() {
return id;
}
/**
* Get the Bukkit player
*
* @return Player
*/
public Player getPlayer() {
return Bukkit.getPlayer(uuid);
}
/**
* Get the user's level value
*
* @return level
*/
public int getLevel() {
return level;
}
/**
* Get the user's group
*
* @return group
*/
public Group getGroup() {
List<Group> groups = config.getGroups().getGroups();
for (int i = 0; i < groups.size(); i++) {
if (i == 0 && level < groups.get(i).getLevel())
break;
else if (i == groups.size() - 1)
return groups.get(i);
else if (level >= groups.get(i).getLevel() && level < groups.get(i + 1).getLevel())
return groups.get(i);
}
return null;
}
/**
* Increase the player's level (from failing a check)
*
* @param type The check failed
* @return true if the level was increased
*/
public boolean increaseLevel(CheckType type) {
if (getPlayer() != null && getPlayer().isOnline()) {
if (silentMode() && type.getUses(uuid) % 4 != 0) {
// Prevent silent mode from increasing the level way too fast
return false;
} else {
if (level < config.getGroups().getHighestLevel()) {
level++;
// Check levels
for (Group l : getLevels()) {
if (l.getLevel() == level) {
AntiCheatReloaded.getManager().getUserManager().alert(this, l, type);
if (l.getLevel() == config.getGroups().getHighestLevel()) {
level = l.getLevel() - 10;
}
}
}
// Execute rules
for (Rule rule : config.getRules().getRules()) {
rule.check(this, type);
}
return true;
}
return false;
}
} else {
return false;
}
}
/**
* Decrease the player's level by one value
*/
public void decreaseLevel() {
level = level != 0 ? level - 1 : 0;
}
/**
* Set the users level to a specific value. Must be 0 < level < config-defined
* highest level
*
* @param level level to set
* @return true if the level was valid and set properly
*/
public boolean setLevel(int level) {
isWaitingOnLevelSync = false;
if (level >= 0) {
if (level <= config.getGroups().getHighestLevel()) {
this.level = level;
return true;
} else {
this.level = config.getGroups().getHighestLevel();
return false;
}
} else {
return false;
}
}
/**
* Reset the user's level to zero and clear all check failures
*/
public void resetLevel() {
level = 0;
for (CheckType type : CheckType.values()) {
type.clearUse(uuid);
}
}
/**
* Get the last known valid location of the player for use in resetting
*
* @param location default value to be returned if no known good location exists
* @return last known valid location
*/
public Location getGoodLocation(Location location) {
if (goodLocation == null) {
return location;
}
return goodLocation;
}
/**
* Set the last known valid location of the player
*
* @param location location to be set
* @return true if the location was valid and set properly
*/
public boolean setGoodLocation(Location location) {
if (Utilities.cantStandAtExp(location)
|| (location.getBlock().isLiquid() && !Utilities.isFullyInWater(location))) {
return false;
}
goodLocation = location;
return true;
}
/**
* Store a copy of the player's inventory, for use in resetting
*
* @param is ItemStack list to store
*/
public void setInventorySnapshot(ItemStack[] is) {
inventorySnapshot = new ArrayList<ItemStack>();
for (int i = 0; i < is.length; i++) {
if (is[i] != null) {
inventorySnapshot.add(is[i].clone());
}
}
}
/**
* Remove the current inventory snapshot
*/
public void removeInventorySnapshot() {
inventorySnapshot = null;
}
/**
* Restore the player's inventory with the current inventory snapshot
*
* @param inventory Player's inventory
*/
public void restoreInventory(Inventory inventory) {
if (inventorySnapshot != null) {
inventory.clear();
for (ItemStack is : inventorySnapshot) {
if (is != null) {
inventory.addItem(is);
}
}
}
}
/**
* Set the player's to location
*
* @param x X value
* @param y Y value
* @param z Z value
*/
public void setTo(double x, double y, double z) {
toX = (int) x;
toY = (int) y;
toZ = (int) z;
}
/**
* Check if a given to value is the same as the stored value
*
* @param x X value
* @param y Y value
* @param z Z value
* @return true if coordinates are all equal
*/
public boolean checkTo(double x, double y, double z) {
return (int) x == toX && (int) y == toY && (int) z == toZ;
}
/**
* Log a player's chat message
*
* @param message Message to log
*/
public void addMessage(String message) {
addToSpamLog(message, messages, messageTimes);
}
/**
* Log a player's command
*
* @param command Command to log
*/
public void addCommand(String command) {
addToSpamLog(command, commands, commandTimes);
}
private void addToSpamLog(String string, String[] messages, Long[] times) {
messages[1] = messages[0];
messages[0] = string;
times[1] = times[0];
times[0] = System.currentTimeMillis();
}
/**
* Get a stored chat message
*
* @param index Index of the chat in storage
* @return the message
*/
public String getMessage(int index) {
return messages[index];
}
/**
* Get a stored command
*
* @param index Index of the command in storage
* @return the command
*/
public String getCommand(int index) {
return commands[index];
}
/**
* Get the time a message in storage was sent
*
* @param index Index of the chat in storage
* @return time the message was sent
*/
public Long getMessageTime(int index) {
return messageTimes[index];
}
/**
* Get the time a command in storage was sent
*
* @param index Index of the command in storage
* @return time the command was sent
*/
public Long getCommandTime(int index) {
return commandTimes[index];
}
/**
* Clear all stored messages
*/
public void clearMessages() {
messages = new String[2];
messageTimes = new Long[2];
}
/**
* Clear all stored commands
*/
public void clearCommands() {
commands = new String[2];
commandTimes = new Long[2];
}
/**
* Get the time the very last stored message was sent
*
* @return the last message's time
*/
public Long getLastMessageTime() {
return getMessageTime(0) == null ? -1 : getMessageTime(0);
}
/**
* Get the time the very last stored command was sent
*
* @return the last command's time
*/
public Long getLastCommandTime() {
return getCommandTime(0) == null ? -1 : getCommandTime(0);
}
private List<Group> getLevels() {
return config.getGroups().getGroups();
}
private boolean silentMode() {
return config.getConfig().silentMode.getValue();
}
public void setIsWaitingOnLevelSync(boolean b) {
this.isWaitingOnLevelSync = b;
}
public boolean isWaitingOnLevelSync() {
return isWaitingOnLevelSync;
}
public void setLevelSyncTimestamp(Timestamp timestamp) {
levelSyncTimestamp = timestamp;
}
public Timestamp getLevelSyncTimestamp() {
return levelSyncTimestamp;
}
@Override
public String toString() {
return "User {name = " + getName() + ", level = " + level + "}";
}
}
@@ -0,0 +1,647 @@
/*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded.util;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.NumberConversions;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public final class Utilities {
private static final List<Material> INSTANT_BREAK = new ArrayList<Material>();
private static final List<Material> FOOD = new ArrayList<Material>();
private static final Map<Material, Material> COMBO = new HashMap<Material, Material>();
public static final String SPY_METADATA = "ac-spydata";
/**
* Send a hack level alert to players and console
*
* @param message List of strings to send as the alert
*/
public static void alert(List<String> message) {
for (Player player : Bukkit.getOnlinePlayers()) {
if (Permission.SYSTEM_ALERT.get(player)) {
for (String msg : message) {
player.sendMessage(msg);
}
}
}
for (String msg : message) {
AntiCheatReloaded.getManager().log(msg);
}
}
/**
* Check if only the block beneath them is standable (includes water + lava)
*
* @param block the block to check (under)
* @return true if they cannot stand there
*/
public static boolean cantStandAtSingle(Block block) {
// TODO: Implement Better to reduce false positives (done? lets test...)
Block otherBlock = block.getLocation().add(0, -0.5, 0).getBlock();
boolean center = otherBlock.getType() == Material.AIR;
return center;
}
/**
* Determine whether a player cannot stand on or around the given block
*
* @param block the block to check
* @return true if the player should be unable to stand here
*/
public static boolean cantStandAt(Block block) {
return !canStand(block) && cantStandClose(block) && cantStandFar(block);
}
/**
* Determine whether a player should be unable to stand at a given location
*
* @param location the location to check
* @return true if the player should be unable to stand here
*/
public static boolean cantStandAtExp(Location location) {
return cantStandAt(new Location(location.getWorld(), fixXAxis(location.getX()), location.getY() - 0.01D,
location.getBlockZ()).getBlock());
}
/**
* Determine whether cannot stand on the block's immediately surroundings
* (North, East, South, West)
*
* @param block the block to check
* @return true if a player cannot stand in the immediate vicinity
*/
public static boolean cantStandClose(Block block) {
return !canStand(block.getRelative(BlockFace.NORTH)) && !canStand(block.getRelative(BlockFace.EAST))
&& !canStand(block.getRelative(BlockFace.SOUTH)) && !canStand(block.getRelative(BlockFace.WEST));
}
/**
* Determine whether cannot stand on the block's outer surroundings
*
* @param block the block to check
* @return true if a player cannot stand in areas further away from the block
*/
public static boolean cantStandFar(Block block) {
return !canStand(block.getRelative(BlockFace.NORTH_WEST)) && !canStand(block.getRelative(BlockFace.NORTH_EAST))
&& !canStand(block.getRelative(BlockFace.SOUTH_WEST))
&& !canStand(block.getRelative(BlockFace.SOUTH_EAST));
}
/**
* Determine whether a player can stand on the given block
*
* @param block the block to check
* @return true if the player can stand here
*/
public static boolean canStand(Block block) {
return !(block.isLiquid() || block.getType() == Material.AIR);
}
/**
* Determine whether a player is fully submerged in water
*
* @param player the player's location
* @return true if the player is fully in the water
*/
public static boolean isFullyInWater(Location player) {
double touchedX = fixXAxis(player.getX());
// Yes, this doesn't make sense, but it's supposed to fix some false positives
// in water walk.
// Think of it as 2 negatives = a positive :)
if (!(new Location(player.getWorld(), touchedX, player.getY(), player.getBlockZ()).getBlock()).isLiquid()
&& !(new Location(player.getWorld(), touchedX, Math.round(player.getY()), player.getBlockZ())
.getBlock()).isLiquid()) {
return true;
}
return (new Location(player.getWorld(), touchedX, player.getY(), player.getBlockZ()).getBlock()).isLiquid()
&& (new Location(player.getWorld(), touchedX, Math.round(player.getY()), player.getBlockZ()).getBlock())
.isLiquid();
}
/**
* Fixes a player's X position to determine the block they are on, even if
* they're on the edge
*
* @param x player's x position
* @return fixed x position
*/
public static double fixXAxis(double x) {
/* For Z axis, just use Math.round(xaxis); */
double touchedX = x;
double rem = touchedX - Math.round(touchedX) + 0.01D;
if (rem < 0.30D) {
touchedX = NumberConversions.floor(x) - 1;
}
return touchedX;
}
/**
* Determine if the player is hovering over water with the given limit
*
* @param player the player's location
* @param blocks max blocks to check
* @return true if the player is hovering over water
*/
public static boolean isHoveringOverWater(Location player, int blocks) {
for (int i = player.getBlockY(); i > player.getBlockY() - blocks; i--) {
Block newloc = (new Location(player.getWorld(), player.getBlockX(), i, player.getBlockZ())).getBlock();
if (newloc.getType() != Material.AIR) {
return newloc.isLiquid();
}
}
return false;
}
/**
* Determine if the player is hovering over water with a hard limit of 25 blocks
*
* @param player the player's location
* @return true if the player is hovering over water
*/
public static boolean isHoveringOverWater(Location player) {
return isHoveringOverWater(player, 25);
}
/**
* Determine whether a material will break instantly when hit
*
* @param m the material to check
* @return true if the material is instant break
*/
public static boolean isInstantBreak(Material m) {
return INSTANT_BREAK.contains(m);
}
/**
* Determine whether a material is edible
*
* @param m the material to check
* @return true if the material is food
*/
public static boolean isFood(Material m) {
return FOOD.contains(m);
}
/**
* Determine whether a block is a slab
*
* @param block block to check
* @return true if slab
*/
public static boolean isSlab(Block block) {
Material type = block.getType();
return type.name().endsWith("SLAB");
// TODO does this even work?
}
/**
* Determine whether a block is a stair
*
* @param block block to check
* @return true if stair
*/
public static boolean isStair(Block block) {
Material type = block.getType();
return type.name().endsWith("STAIRS");
// TODO does this even work?
}
/**
* Determine whether a player is sprinting or flying
*
* @param player player to check
* @return true if sprinting or flying
*/
public static boolean sprintFly(Player player) {
return player.isSprinting() || player.isFlying();
}
/**
* Determine whether a player is standing on a lily pad
*
* @param player player to check
* @return true if on lily pad
*/
public static boolean isOnLilyPad(Player player) {
Block block = player.getLocation().getBlock();
Material lily = Material.LILY_PAD;
// TODO: Can we fix X this?
return block.getType() == lily || block.getRelative(BlockFace.NORTH).getType() == lily
|| block.getRelative(BlockFace.SOUTH).getType() == lily
|| block.getRelative(BlockFace.EAST).getType() == lily
|| block.getRelative(BlockFace.WEST).getType() == lily;
}
/**
* Determine whether a player is fully submersed in liquid
*
* @param player player to check
* @return true if submersed
*/
public static boolean isSubmersed(Player player) {
return player.getLocation().getBlock().isLiquid()
&& player.getLocation().getBlock().getRelative(BlockFace.UP).isLiquid();
}
/**
* Determine whether a player is in water
*
* @param player player to check
* @return true if in water
*/
public static boolean isInWater(Player player) {
return player.getLocation().getBlock().isLiquid()
|| player.getLocation().getBlock().getRelative(BlockFace.DOWN).isLiquid()
|| player.getLocation().getBlock().getRelative(BlockFace.UP).isLiquid();
}
/**
* Determine whether a player is in a web
*
* @param player player to check
* @return true if in web
*/
public static boolean isInWeb(Player player) {
return player.getLocation().getBlock().getType() == Material.COBWEB
|| player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() == Material.COBWEB
|| player.getLocation().getBlock().getRelative(BlockFace.UP).getType() == Material.COBWEB;
}
/**
* Determine whether a block is climbable
*
* @param block block to check
* @return true if climbable
*/
public static boolean isClimbableBlock(Block block) {
return block.getType() == Material.VINE || block.getType() == Material.LADDER
|| block.getType() == Material.WATER;
}
/**
* Determine whether a player is on a vine (can be free hanging)
*
* @param player to check
* @return true if on vine
*/
public static boolean isOnVine(Player player) {
return player.getLocation().getBlock().getType() == Material.VINE;
}
/**
* Determine whether a String can be cast to an Integer
*
* @param string text to check
* @return true if int
*/
public static boolean isInt(String string) {
try {
Integer.parseInt(string);
return true;
} catch (Exception ex) {
return false;
}
}
/**
* Determine whether a String can be cast to a Double
*
* @param string text to check
* @return true if double
*/
public static boolean isDouble(String string) {
try {
Double.parseDouble(string);
return true;
} catch (Exception ex) {
return false;
}
}
/**
* Calculate the time in milliseconds that it should take to break the given
* block with the given tool
*
* @param tool tool to check
* @param block block to check
* @return time in milliseconds to break
*/
public static long calcSurvivalFastBreak(ItemStack tool, Material block) {
if (isInstantBreak(block) || (tool.getType() == Material.SHEARS && block.name().endsWith("LEAVES"))) {
return 0;
}
double bhardness = BlockHardness.getBlockHardness(block);
double thardness = ToolHardness.getToolHardness(tool.getType());
long enchantlvl = (long) tool.getEnchantmentLevel(Enchantment.DIG_SPEED);
long result = Math.round((bhardness * thardness) * 0.10 * 10000);
if (enchantlvl > 0) {
result /= enchantlvl * enchantlvl + 1L;
}
result = result > 25000 ? 25000 : result < 0 ? 0 : result;
if (isQuickCombo(tool, block)) {
result = result / 2;
}
return result;
}
/**
* Determine whether the given tool is a combination that makes the breaking of
* this block faster
*
* @param tool tool to check
* @param block block to check
* @return true if quick combo
*/
private static boolean isQuickCombo(ItemStack tool, Material block) {
for (Material t : COMBO.keySet()) {
if (tool.getType() == t && COMBO.get(t) == block) {
return true;
}
}
return false;
}
/**
* Determine if a block ISN'T one of the specified types
*
* @param block block to check
* @param materials array of possible materials
* @return true if the block isn't any of the materials
*/
public static boolean blockIsnt(Block block, Material[] materials) {
Material type = block.getType();
for (Material m : materials) {
if (m == type) {
return false;
}
}
return false;
}
/**
* Determine if a block ISN'T one of the specified types
*
* @param block block to check
* @param endTypes array of possible name endings
* @return true if the block isn't any of the materials
*/
public static boolean blockIsnt(Block block, String[] endTypes) {
Material type = block.getType();
for (String s : endTypes) {
if (type.name().endsWith(s)) {
return false;
}
}
return false;
}
/**
* Parse a COMMAND[] input to a set of commands to execute
*
* @param command input string
* @return parsed commands
*/
public static String[] getCommands(String command) {
return command.replaceAll("COMMAND\\[", "").replaceAll("]", "").split(";");
}
/**
* Remove all whitespace from the given string to ready it for parsing
*
* @param string the string to parse
* @return string with whitespace removed
*/
public static String removeWhitespace(String string) {
return string.replaceAll(" ", "");
}
/**
* Determine if a player has the given enchantment on their armor
*
* @param player player to check
* @param e enchantment to check
* @return true if the armor has this enchantment
*/
public static boolean hasArmorEnchantment(Player player, Enchantment e) {
for (ItemStack is : player.getInventory().getArmorContents()) {
if (is != null && is.containsEnchantment(e)) {
return true;
}
}
return false;
}
/**
* Create a list with the given string for execution
*
* @param string the string to parse
* @return ArrayList with string
*/
public static ArrayList<String> stringToList(final String string) {
return new ArrayList<String>() {
{
add(string);
}
};
}
/**
* Create a comma-delimited string from a list
*
* @param list the list to parse
* @return the list in a string format
*/
public static String listToCommaString(List<String> list) {
StringBuilder b = new StringBuilder();
for (int i = 0; i < list.size(); i++) {
b.append(list.get(i));
if (i < list.size() - 1) {
b.append(",");
}
}
return b.toString();
}
/**
* Parse a string in the format of "XdXhXmXs" to seconds
*
* @param string The string to parse
* @return seconds
*/
public static long lifeToSeconds(String string) {
if (string.equals("0") || string.equals(""))
return 0;
String[] lifeMatch = new String[] { "d", "h", "m", "s" };
int[] lifeInterval = new int[] { 86400, 3600, 60, 1 };
long seconds = 0L;
for (int i = 0; i < lifeMatch.length; i++) {
Matcher matcher = Pattern.compile("([0-9]*)" + lifeMatch[i]).matcher(string);
while (matcher.find()) {
seconds += Integer.parseInt(matcher.group(1)) * lifeInterval[i];
}
}
return seconds;
}
static {
// START INSTANT BREAK MATERIALS
INSTANT_BREAK.add(Material.COMPARATOR);
INSTANT_BREAK.add(Material.REPEATER);
INSTANT_BREAK.add(Material.TORCH);
INSTANT_BREAK.add(Material.REDSTONE_TORCH);
INSTANT_BREAK.add(Material.REDSTONE_WIRE);
INSTANT_BREAK.add(Material.TRIPWIRE);
INSTANT_BREAK.add(Material.TRIPWIRE_HOOK);
INSTANT_BREAK.add(Material.FIRE);
INSTANT_BREAK.add(Material.FLOWER_POT);
INSTANT_BREAK.add(Material.INFESTED_CHISELED_STONE_BRICKS);
INSTANT_BREAK.add(Material.INFESTED_COBBLESTONE);
INSTANT_BREAK.add(Material.INFESTED_CRACKED_STONE_BRICKS);
INSTANT_BREAK.add(Material.INFESTED_MOSSY_STONE_BRICKS);
INSTANT_BREAK.add(Material.INFESTED_STONE);
INSTANT_BREAK.add(Material.INFESTED_STONE_BRICKS);
INSTANT_BREAK.add(Material.TNT);
INSTANT_BREAK.add(Material.SLIME_BLOCK);
INSTANT_BREAK.add(Material.HONEY_BLOCK);
INSTANT_BREAK.add(Material.CARROTS);
INSTANT_BREAK.add(Material.DEAD_BUSH);
INSTANT_BREAK.add(Material.FERN);
INSTANT_BREAK.add(Material.LARGE_FERN);
INSTANT_BREAK.add(Material.CHORUS_FLOWER);
INSTANT_BREAK.add(Material.CORNFLOWER);
INSTANT_BREAK.add(Material.SUNFLOWER);
INSTANT_BREAK.add(Material.LILY_PAD);
INSTANT_BREAK.add(Material.MELON_STEM);
INSTANT_BREAK.add(Material.ATTACHED_MELON_STEM);
INSTANT_BREAK.add(Material.BROWN_MUSHROOM);
INSTANT_BREAK.add(Material.RED_MUSHROOM);
INSTANT_BREAK.add(Material.NETHER_WART);
INSTANT_BREAK.add(Material.POTATOES);
INSTANT_BREAK.add(Material.PUMPKIN_STEM);
INSTANT_BREAK.add(Material.ATTACHED_PUMPKIN_STEM);
INSTANT_BREAK.add(Material.ACACIA_SAPLING);
INSTANT_BREAK.add(Material.BAMBOO_SAPLING);
INSTANT_BREAK.add(Material.BIRCH_SAPLING);
INSTANT_BREAK.add(Material.DARK_OAK_SAPLING);
INSTANT_BREAK.add(Material.JUNGLE_SAPLING);
INSTANT_BREAK.add(Material.OAK_SAPLING);
INSTANT_BREAK.add(Material.SPRUCE_SAPLING);
INSTANT_BREAK.add(Material.SUGAR_CANE);
INSTANT_BREAK.add(Material.TALL_GRASS);
INSTANT_BREAK.add(Material.TALL_SEAGRASS);
INSTANT_BREAK.add(Material.WHEAT);
// END INSTANT BREAK MATERIALS
// START FOOD
FOOD.add(Material.APPLE);
FOOD.add(Material.BAKED_POTATO);
FOOD.add(Material.BEETROOT);
FOOD.add(Material.BEETROOT_SOUP);
FOOD.add(Material.BREAD);
FOOD.add(Material.CAKE);
FOOD.add(Material.CARROT);
FOOD.add(Material.CHORUS_FRUIT);
FOOD.add(Material.COOKED_BEEF);
FOOD.add(Material.COOKED_CHICKEN);
FOOD.add(Material.COOKED_COD);
FOOD.add(Material.COOKED_MUTTON);
FOOD.add(Material.COOKED_PORKCHOP);
FOOD.add(Material.COOKED_RABBIT);
FOOD.add(Material.COOKED_SALMON);
FOOD.add(Material.COOKIE);
FOOD.add(Material.DRIED_KELP);
FOOD.add(Material.ENCHANTED_GOLDEN_APPLE);
FOOD.add(Material.GOLDEN_APPLE);
FOOD.add(Material.GOLDEN_CARROT);
FOOD.add(Material.HONEY_BOTTLE);
FOOD.add(Material.MELON_SLICE);
FOOD.add(Material.MUSHROOM_STEW);
FOOD.add(Material.POISONOUS_POTATO);
FOOD.add(Material.POTATO);
FOOD.add(Material.PUFFERFISH);
FOOD.add(Material.PUMPKIN_PIE);
FOOD.add(Material.RABBIT_STEW);
FOOD.add(Material.BEEF);
FOOD.add(Material.CHICKEN);
FOOD.add(Material.COD);
FOOD.add(Material.MUTTON);
FOOD.add(Material.PORKCHOP);
FOOD.add(Material.RABBIT);
FOOD.add(Material.SALMON);
FOOD.add(Material.ROTTEN_FLESH);
FOOD.add(Material.SPIDER_EYE);
FOOD.add(Material.SUSPICIOUS_STEW);
FOOD.add(Material.SWEET_BERRIES);
FOOD.add(Material.TROPICAL_FISH);
// END FOOD
// START COMBOS
COMBO.put(Material.SHEARS, Material.BLACK_WOOL);
COMBO.put(Material.SHEARS, Material.BLUE_WOOL);
COMBO.put(Material.SHEARS, Material.BROWN_WOOL);
COMBO.put(Material.SHEARS, Material.CYAN_WOOL);
COMBO.put(Material.SHEARS, Material.GRAY_WOOL);
COMBO.put(Material.SHEARS, Material.GREEN_WOOL);
COMBO.put(Material.SHEARS, Material.LIGHT_BLUE_WOOL);
COMBO.put(Material.SHEARS, Material.LIGHT_GRAY_WOOL);
COMBO.put(Material.SHEARS, Material.LIME_WOOL);
COMBO.put(Material.SHEARS, Material.MAGENTA_WOOL);
COMBO.put(Material.SHEARS, Material.MAGENTA_WOOL);
COMBO.put(Material.SHEARS, Material.ORANGE_WOOL);
COMBO.put(Material.SHEARS, Material.PINK_WOOL);
COMBO.put(Material.SHEARS, Material.PURPLE_WOOL);
COMBO.put(Material.SHEARS, Material.RED_WOOL);
COMBO.put(Material.SHEARS, Material.WHITE_WOOL);
COMBO.put(Material.SHEARS, Material.YELLOW_WOOL);
COMBO.put(Material.IRON_SWORD, Material.COBWEB);
COMBO.put(Material.DIAMOND_SWORD, Material.COBWEB);
COMBO.put(Material.STONE_SWORD, Material.COBWEB);
COMBO.put(Material.WOODEN_SWORD, Material.COBWEB);
// END COMBOS
}
}
@@ -0,0 +1,78 @@
/*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded.util;
import java.util.Arrays;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType;
public class VersionUtil {
private static final List<String> SUPPORTED_VERSIONS = Arrays
.asList(new String[] { "v1_15" });
public static String getVersion() {
return Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
}
public static boolean isSupported() {
for (String versionId : SUPPORTED_VERSIONS) {
if (getVersion().startsWith(versionId)) {
return true;
}
}
return false;
}
public static boolean isFlying(Player p) {
return p.isFlying() || p.isGliding() || p.hasPotionEffect(PotionEffectType.LEVITATION);
}
public static long getHealTime() {
return 495;
}
public static boolean isFrostWalk(Player player) {
if (player.getInventory().getBoots() == null) {
return false;
}
return player.getInventory().getBoots().containsEnchantment(Enchantment.FROST_WALKER);
}
public static ItemStack getItemInHand(Player player) {
return player.getInventory().getItemInMainHand();
}
public static int getPlayerPing(Player player) {
try {
Object entityPlayer = player.getClass().getMethod("getHandle").invoke(player);
int ping = (int) entityPlayer.getClass().getField("ping").get(entityPlayer);
return ping;
} catch (Exception e) {
return -1;
}
}
}
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,15 +17,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.util.enterprise; package com.rammelkast.anticheatreloaded.util.enterprise;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.check.CheckType;
import net.gravitydevelopment.anticheat.util.User;
import net.gravitydevelopment.anticheat.util.Utilities;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.CheckType;
import com.rammelkast.anticheatreloaded.util.User;
import com.rammelkast.anticheatreloaded.util.Utilities;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@@ -136,7 +138,7 @@ public class Database {
connection.setAutoCommit(false); connection.setAutoCommit(false);
if (logInterval != 0) { if (logInterval != 0) {
eventTask = Bukkit.getScheduler().runTaskTimerAsynchronously(AntiCheat.getPlugin(), new Runnable() { eventTask = Bukkit.getScheduler().runTaskTimerAsynchronously(AntiCheatReloaded.getPlugin(), new Runnable() {
@Override @Override
public void run() { public void run() {
flushEvents(); flushEvents();
@@ -145,7 +147,7 @@ public class Database {
} }
if(syncLevels && syncInterval != 0) { if(syncLevels && syncInterval != 0) {
syncTask = Bukkit.getScheduler().runTaskTimerAsynchronously(AntiCheat.getPlugin(), new Runnable() { syncTask = Bukkit.getScheduler().runTaskTimerAsynchronously(AntiCheatReloaded.getPlugin(), new Runnable() {
@Override @Override
public void run() { public void run() {
syncUsers(); syncUsers();
@@ -153,7 +155,7 @@ public class Database {
}, syncInterval * 20, syncInterval * 20); }, syncInterval * 20, syncInterval * 20);
} }
AntiCheat.getPlugin().verboseLog("Connected to the database."); AntiCheatReloaded.getPlugin().verboseLog("Connected to the database.");
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
@@ -202,7 +204,7 @@ public class Database {
public void cleanEvents() { public void cleanEvents() {
if (logLife != 0) { if (logLife != 0) {
Bukkit.getScheduler().runTaskAsynchronously(AntiCheat.getPlugin(), new Runnable() { Bukkit.getScheduler().runTaskAsynchronously(AntiCheatReloaded.getPlugin(), new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
@@ -212,7 +214,7 @@ public class Database {
statement.executeUpdate(); statement.executeUpdate();
connection.commit(); connection.commit();
AntiCheat.getPlugin().verboseLog("Cleaned " + statement.getUpdateCount() + " old events from the database"); AntiCheatReloaded.getPlugin().verboseLog("Cleaned " + statement.getUpdateCount() + " old events from the database");
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
@@ -222,8 +224,8 @@ public class Database {
} }
private void syncUsers() { private void syncUsers() {
for (User user : AntiCheat.getManager().getUserManager().getUsers()) { for (User user : AntiCheatReloaded.getManager().getUserManager().getUsers()) {
AntiCheat.getManager().getConfiguration().getLevels().updateLevelToUser(user); AntiCheatReloaded.getManager().getConfiguration().getLevels().updateLevelToUser(user);
} }
} }
} }
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,14 +17,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.util.rule; package com.rammelkast.anticheatreloaded.util.rule;
import net.gravitydevelopment.anticheat.check.CheckType;
import net.gravitydevelopment.anticheat.util.User;
import javax.script.ScriptEngine; import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager; import javax.script.ScriptEngineManager;
import javax.script.ScriptException; import javax.script.ScriptException;
import com.rammelkast.anticheatreloaded.check.CheckType;
import com.rammelkast.anticheatreloaded.util.User;
import java.util.SortedMap; import java.util.SortedMap;
/** /**
@@ -42,7 +44,7 @@ import java.util.SortedMap;
* Check_SPIDER > 0 ? Player.KICK : null<br /> * Check_SPIDER > 0 ? Player.KICK : null<br />
* <i>The above statement would read 'If the spider check has been failed over zero times, kick the player. Otherwise, do nothing.'</i> * <i>The above statement would read 'If the spider check has been failed over zero times, kick the player. Otherwise, do nothing.'</i>
* <p/> * <p/>
* To see syntax for variables and functions that you may use, see {@link net.gravitydevelopment.anticheat.util.rule.Rule} * To see syntax for variables and functions that you may use, see {@link com.rammelkast.anticheatreloaded.util.rule.Rule}
*/ */
public class ConditionalRule extends Rule { public class ConditionalRule extends Rule {
@@ -1,6 +1,7 @@
/* /*
* AntiCheat for Bukkit. * AntiCheatReloaded for Bukkit and Spigot.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net * Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2020 Rammelkast
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -16,15 +17,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package net.gravitydevelopment.anticheat.util.rule; package com.rammelkast.anticheatreloaded.util.rule;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.check.CheckType;
import net.gravitydevelopment.anticheat.util.User;
import net.gravitydevelopment.anticheat.util.Group;
import net.gravitydevelopment.anticheat.util.Utilities;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.CheckType;
import com.rammelkast.anticheatreloaded.util.Group;
import com.rammelkast.anticheatreloaded.util.User;
import com.rammelkast.anticheatreloaded.util.Utilities;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -44,7 +46,7 @@ import java.util.TreeMap;
* <ul> * <ul>
* <li>Check * <li>Check
* <ul> * <ul>
* <li>Contains all valid checks as listed in {@link net.gravitydevelopment.anticheat.check.CheckType}</li> * <li>Contains all valid checks as listed in {@link com.rammelkast.anticheatreloaded.check.CheckType}</li>
* <li>Will return the number of times this user has failed the given check</li> * <li>Will return the number of times this user has failed the given check</li>
* <li><b>Example:</b> Check_SPRINT</li> * <li><b>Example:</b> Check_SPRINT</li>
* </ul> * </ul>
@@ -76,7 +78,7 @@ import java.util.TreeMap;
* <p/> * <p/>
* The Rule class itself is not an functional rule setup, * The Rule class itself is not an functional rule setup,
* it is inherited and made functional by different implementations of the rule parser.<br /> * it is inherited and made functional by different implementations of the rule parser.<br />
* The only current Rule implementation is the {@link net.gravitydevelopment.anticheat.util.rule.ConditionalRule} * The only current Rule implementation is the {@link com.rammelkast.anticheatreloaded.util.rule.ConditionalRule}
*/ */
public class Rule { public class Rule {
@@ -86,7 +88,7 @@ public class Rule {
private Type type; private Type type;
public enum Type { public enum Type {
CONDITIONAL(".*[?]*.*:.*", "net.gravitydevelopment.anticheat.util.rule.ConditionalRule"); CONDITIONAL(".*[?]*.*:.*", "com.rammelkast.anticheatreloaded.util.rule.ConditionalRule");
private String regex; private String regex;
private String c; private String c;
@@ -145,7 +147,7 @@ public class Rule {
/** /**
* Get the type of rule this is * Get the type of rule this is
* *
* @return a {@link net.gravitydevelopment.anticheat.util.rule.Rule.Type} * @return a {@link com.rammelkast.anticheatreloaded.util.rule.Rule.Type}
*/ */
public Type getType() { public Type getType() {
return type; return type;
@@ -174,7 +176,7 @@ public class Rule {
if (variable.equals("player_level") && Utilities.isInt(value)) { if (variable.equals("player_level") && Utilities.isInt(value)) {
user.setLevel(Integer.parseInt(value)); user.setLevel(Integer.parseInt(value));
} else if (variable.equals("player_group") && Utilities.isInt(value)) { } else if (variable.equals("player_group") && Utilities.isInt(value)) {
for (Group group : AntiCheat.getManager().getConfiguration().getGroups().getGroups()) { for (Group group : AntiCheatReloaded.getManager().getConfiguration().getGroups().getGroups()) {
if (group.getName().equalsIgnoreCase(value)) { if (group.getName().equalsIgnoreCase(value)) {
user.setLevel(group.getLevel()); user.setLevel(group.getLevel());
} }
@@ -195,7 +197,7 @@ public class Rule {
text = text.split("\\.")[1]; text = text.split("\\.")[1];
List<String> action = new ArrayList<String>(); List<String> action = new ArrayList<String>();
action.add(text); action.add(text);
AntiCheat.getManager().getUserManager().execute(user, action, type); AntiCheatReloaded.getManager().getUserManager().execute(user, action, type);
} }
} }
@@ -1,215 +0,0 @@
/*
* AntiCheat for Bukkit.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.gravitydevelopment.anticheat;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import net.gravitydevelopment.anticheat.check.combat.KillAuraCheck;
import net.gravitydevelopment.anticheat.check.movement.BlinkCheck;
import net.gravitydevelopment.anticheat.command.CommandHandler;
import net.gravitydevelopment.anticheat.config.Configuration;
import net.gravitydevelopment.anticheat.event.BlockListener;
import net.gravitydevelopment.anticheat.event.EntityListener;
import net.gravitydevelopment.anticheat.event.InventoryListener;
import net.gravitydevelopment.anticheat.event.PlayerListener;
import net.gravitydevelopment.anticheat.event.VehicleListener;
import net.gravitydevelopment.anticheat.manage.AntiCheatManager;
import net.gravitydevelopment.anticheat.util.User;
import net.gravitydevelopment.anticheat.util.VersionUtil;
public class AntiCheat extends JavaPlugin {
private static AntiCheatManager manager;
private static AntiCheat plugin;
private static List<Listener> eventList = new ArrayList<Listener>();
private static Configuration config;
private static boolean verbose;
private static boolean developer;
private static final int PROJECT_ID = 100229;
private static ProtocolManager protocolManager;
private static boolean protocolLib = false;
private static Long loadTime;
@Override
public void onEnable() {
plugin = this;
loadTime = System.currentTimeMillis();
manager = new AntiCheatManager(this, getLogger());
eventList.add(new PlayerListener());
eventList.add(new BlockListener());
eventList.add(new EntityListener());
eventList.add(new VehicleListener());
eventList.add(new InventoryListener());
// Order is important in some cases, don't screw with these unless needed, especially config
setupConfig();
setupEvents();
setupCommands();
setupProtocol();
// Enterprise must come before levels
setupEnterprise();
restoreLevels();
// Check if NoCheatPlus is installed
Bukkit.getScheduler().runTaskLater(this, new Runnable() {
public void run() {
if (Bukkit.getPluginManager().getPlugin("NoCheatPlus") != null) {
getLogger().severe("You are also running NoCheatPlus!");
getLogger().severe("Multiple anticheats create false cheat detections.");
getLogger().severe("Please remove or disable NoCheatPlus to silence this warning.");
}else if (Bukkit.getPluginManager().getPlugin("AAC") != null) {
getLogger().severe("You are also running AAC!");
getLogger().severe("Multiple anticheats create false cheat detections.");
getLogger().severe("Please remove or disable AAC to silence this warning.");
}
}
}, 40L);
// End tests
verboseLog("Finished loading.");
getLogger().info("Running version " + VersionUtil.getVersion() + "...");
// Enable packetlisteners
KillAuraCheck.listenPackets();
BlinkCheck.startTimer();
BlinkCheck.listenPackets();
}
@Override
public void onDisable() {
verboseLog("Saving user levels...");
config.getLevels().saveLevelsFromUsers(getManager().getUserManager().getUsers());
AntiCheatManager.close();
getServer().getScheduler().cancelTasks(this);
cleanup();
}
private void setupProtocol() {
if (Bukkit.getPluginManager().getPlugin("ProtocolLib") != null) {
protocolLib = true;
protocolManager = ProtocolLibrary.getProtocolManager();
verboseLog("Hooked into ProtocolLib");
}
}
private void setupEvents() {
for (Listener listener : eventList) {
getServer().getPluginManager().registerEvents(listener, this);
verboseLog("Registered events for ".concat(listener.toString().split("@")[0].split(".anticheat.")[1]));
}
}
private void setupCommands() {
getCommand("anticheat").setExecutor(new CommandHandler());
verboseLog("Registered commands.");
}
private void setupConfig() {
config = manager.getConfiguration();
verboseLog("Setup the config.");
}
private void setupEnterprise() {
if (config.getConfig().enterprise.getValue()) {
if (config.getEnterprise().loggingEnabled.getValue()) {
config.getEnterprise().database.cleanEvents();
}
}
}
private void restoreLevels() {
for (Player player : getServer().getOnlinePlayers()) {
UUID uuid = player.getUniqueId();
User user = new User(uuid);
user.setIsWaitingOnLevelSync(true);
config.getLevels().loadLevelToUser(user);
manager.getUserManager().addUser(user);
verboseLog("Data for " + uuid + " loaded");
}
}
public static AntiCheat getPlugin() {
return plugin;
}
public static AntiCheatManager getManager() {
return manager;
}
public static String getVersion() {
return manager.getPlugin().getDescription().getVersion();
}
private void cleanup() {
eventList = null;
manager = null;
config = null;
}
public static boolean developerMode() {
return developer;
}
public static void setDeveloperMode(boolean b) {
developer = b;
}
public static boolean isUsingProtocolLib() {
return protocolLib;
}
public static void debugLog(final String string) {
Bukkit.getScheduler().runTask(getPlugin(), new Runnable() {
public void run() {
if (developer) {
manager.debugLog("[DEBUG] " + string);
}
}
});
}
public void verboseLog(final String string) {
if (verbose) {
getLogger().info(string);
}
}
public void setVerbose(boolean b) {
verbose = b;
}
public Long getLoadTime() {
return loadTime;
}
public static ProtocolManager getProtocolManager() {
return protocolManager;
}
}
@@ -1,32 +0,0 @@
package net.gravitydevelopment.anticheat.check.combat;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.potion.PotionEffectType;
import net.gravitydevelopment.anticheat.check.CheckResult;
import net.gravitydevelopment.anticheat.check.CheckType;
import net.gravitydevelopment.anticheat.event.EventListener;
import net.gravitydevelopment.anticheat.util.Utilities;
public class CriticalsCheck {
public static void doDamageEvent(EntityDamageByEntityEvent e, Player damager) {
if (!(e.getDamager() instanceof Player) || e.getCause() != DamageCause.ENTITY_ATTACK)
return;
Player p = (Player)e.getDamager();
if (isCritical(p)) {
if ((p.getLocation().getY() % 1.0 == 0 || p.getLocation().getY() % 0.5 == 0) && p.getLocation().clone().subtract(0, 1.0, 0).getBlock().getType().isSolid()) {
e.setCancelled(true);
EventListener.log(new CheckResult(CheckResult.Result.FAILED, p.getName() + " failed Criticals, tried to do a critical without needed conditions").getMessage(), p, CheckType.CRITICALS);
}
}
}
private static boolean isCritical(Player player) {
return player.getFallDistance() > 0.0f && !player.isOnGround() && !player.isInsideVehicle() && !player.hasPotionEffect(PotionEffectType.BLINDNESS) && !Utilities.isHoveringOverWater(player.getLocation()) && player.getEyeLocation().getBlock().getType() != Material.LADDER;
}
}
@@ -1,90 +0,0 @@
package net.gravitydevelopment.anticheat.check.combat;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.check.CheckResult;
import net.gravitydevelopment.anticheat.check.CheckType;
import net.gravitydevelopment.anticheat.event.EventListener;
import net.gravitydevelopment.anticheat.util.NPC_1_10;
import net.gravitydevelopment.anticheat.util.VersionUtil;
/**
* @author Rammelkast
*/
public class KillAuraCheck {
private static final Map<UUID, NPC_1_10> NPC_LIST = new HashMap<UUID, NPC_1_10>();
private static final Map<UUID, Integer> VL_COUNT = new HashMap<UUID, Integer>();
public static void cleanPlayer(Player p) {
if (!VersionUtil.getVersion().equals("v1_10_R1")) {
return;
}
NPC_LIST.remove(p.getUniqueId());
}
public static void listenPackets() {
if (!VersionUtil.getVersion().equals("v1_10_R1")) {
return;
}
AntiCheat.getProtocolManager().addPacketListener(new PacketAdapter(AntiCheat.getPlugin(), ListenerPriority.NORMAL, new PacketType[] {PacketType.Play.Client.USE_ENTITY}) {
@Override
public void onPacketReceiving(PacketEvent e) {
Player p = e.getPlayer();
if (!NPC_LIST.containsKey(p.getUniqueId()))
return;
int id = e.getPacket().getIntegers().read(0);
if (NPC_LIST.containsKey(p.getUniqueId())) {
if (NPC_LIST.get(p.getUniqueId()).getID() != id) {
return;
}
}
if (!VL_COUNT.containsKey(p.getUniqueId())) {
VL_COUNT.put(p.getUniqueId(), 1);
NPC_LIST.get(p.getUniqueId()).damage();
}else {
VL_COUNT.put(p.getUniqueId(), VL_COUNT.get(p.getUniqueId()) + 1);
if (VL_COUNT.get(p.getUniqueId()) >= 5) {
EventListener.log(new CheckResult(CheckResult.Result.FAILED, p.getName() + " failed KillAura (botcheck), hit the bot " + VL_COUNT.get(p.getUniqueId()) + " times (max=5)").getMessage(), p, CheckType.BLINK);
VL_COUNT.remove(p.getUniqueId());
}
}
}
});
}
public static void doDamageEvent(EntityDamageByEntityEvent e, Player p) {
if (!VersionUtil.getVersion().equals("v1_10_R1")) {
return;
}
if (NPC_LIST.containsKey(p.getUniqueId()))
NPC_LIST.get(p.getUniqueId()).damage(e, p);
else {
NPC_1_10 npc = new NPC_1_10(p);
NPC_LIST.put(p.getUniqueId(), npc);
npc.spawn();
}
}
public static void doMove(PlayerMoveEvent e) {
if (!VersionUtil.getVersion().equals("v1_10_R1")) {
return;
}
if (NPC_LIST.containsKey(e.getPlayer().getUniqueId()))
NPC_LIST.get(e.getPlayer().getUniqueId()).move(e);
}
}
@@ -1,51 +0,0 @@
package net.gravitydevelopment.anticheat.check.combat;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.scheduler.BukkitRunnable;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.check.CheckResult;
import net.gravitydevelopment.anticheat.check.CheckType;
import net.gravitydevelopment.anticheat.event.EventListener;
public class VelocityCheck {
private static final Map<UUID, Integer> VL_COUNT = new HashMap<UUID, Integer>();
public static void cleanPlayer(Player p) {
VL_COUNT.remove(p.getUniqueId());
}
public static void runCheck(EntityDamageByEntityEvent e, final Player p) {
if (AntiCheat.getManager().getCheckManager().isOpExempt(p) || AntiCheat.getManager().getCheckManager().isExempt(p, CheckType.VELOCITY))
return;
final Location then = p.getLocation();
new BukkitRunnable() {
@Override
public void run() {
if (!p.isOnline())
return;
if (then.distance(p.getLocation()) < 0.125) {
if (!VL_COUNT.containsKey(p.getUniqueId()))
VL_COUNT.put(p.getUniqueId(), 1);
else {
VL_COUNT.put(p.getUniqueId(), VL_COUNT.get(p.getUniqueId()) + 1);
if (VL_COUNT.get(p.getUniqueId()) > AntiCheat.getManager().getBackend().getMagic().VELOCITY_AMT()) {
EventListener.log(new CheckResult(CheckResult.Result.FAILED, p.getName() + " failed Velocity, had zero/low velocity " + VL_COUNT.get(p.getUniqueId()) + " times (max=" + AntiCheat.getManager().getBackend().getMagic().VELOCITY_AMT() + ")").getMessage(), p, CheckType.VELOCITY);
VL_COUNT.remove(p.getUniqueId());
}
}
}else {
VL_COUNT.remove(p.getUniqueId());
}
}
}.runTaskLater(AntiCheat.getPlugin(), 4);
}
}
@@ -1,60 +0,0 @@
package net.gravitydevelopment.anticheat.check.movement;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.check.CheckResult;
import net.gravitydevelopment.anticheat.check.CheckType;
import net.gravitydevelopment.anticheat.event.EventListener;
/**
* @author Rammelkast
*/
public class BlinkCheck {
public static final Map<UUID, Integer> MOVE_COUNT = new HashMap<UUID, Integer>();
public static void startTimer() {
new BukkitRunnable() {
@Override
public void run() {
MOVE_COUNT.clear();
}
}.runTaskTimer(AntiCheat.getPlugin(), 0, 20);
}
public static void listenPackets() {
AntiCheat.getProtocolManager().addPacketListener(new PacketAdapter(AntiCheat.getPlugin(), ListenerPriority.NORMAL, new PacketType[] {PacketType.Play.Client.POSITION, PacketType.Play.Client.POSITION_LOOK}) {
@Override
public void onPacketReceiving(PacketEvent e) {
Player p = e.getPlayer();
Location cur = e.getPlayer().getLocation();
if (!MOVE_COUNT.containsKey(p.getUniqueId()))
MOVE_COUNT.put(p.getUniqueId(), 1);
else {
MOVE_COUNT.put(p.getUniqueId(), MOVE_COUNT.get(p.getUniqueId()) + 1);
if (AntiCheat.getManager().getCheckManager().checkInWorld(p) && !AntiCheat.getManager().getCheckManager().isOpExempt(p) && !AntiCheat.getManager().getCheckManager().isExempt(p, CheckType.BLINK))
if (MOVE_COUNT.get(p.getUniqueId()) > AntiCheat.getManager().getBackend().getMagic().BLINK_PACKET()) {
EventListener.log(new CheckResult(CheckResult.Result.FAILED, p.getName() + " failed Blink, sent " + MOVE_COUNT.get(p.getUniqueId()) + " packets in one second (max=" + AntiCheat.getManager().getBackend().getMagic().BLINK_PACKET() + ")").getMessage(), p, CheckType.BLINK);
MOVE_COUNT.remove(p.getUniqueId());
e.setCancelled(true);
e.getPlayer().teleport(cur);
}
}
}
});
}
}
@@ -1,86 +0,0 @@
package net.gravitydevelopment.anticheat.check.movement;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.check.CheckResult;
import net.gravitydevelopment.anticheat.util.Distance;
import net.gravitydevelopment.anticheat.util.Utilities;
import net.gravitydevelopment.anticheat.util.VersionUtil;
/**
*
* @author Marco
* TODO rewrite this check
*/
public class FlightCheck {
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
public static Map<UUID, Double> blocksOverFlight = new HashMap<UUID, Double>();
public static Map<UUID, Long> movingExempt = new HashMap<UUID, Long>();
public static CheckResult runCheck(Player player, Distance distance) {
if (distance.getYDifference() > AntiCheat.getManager().getBackend().getMagic().TELEPORT_MIN() || VersionUtil.isFlying(player)) {
// This was a teleport, so we don't care about it.
return PASS;
}
final UUID uuid = player.getUniqueId();
final double y1 = distance.fromY();
final double y2 = distance.toY();
if (!isMovingExempt(player) && !Utilities.isHoveringOverWater(player.getLocation(), 1) && Utilities.cantStandAtExp(player.getLocation()) && Utilities.blockIsnt(player.getLocation().getBlock().getRelative(BlockFace.DOWN), new Material[]{Material.FENCE, Material.FENCE_GATE, Material.COBBLE_WALL})) {
if (!blocksOverFlight.containsKey(uuid)) {
blocksOverFlight.put(uuid, 0D);
}
blocksOverFlight.put(uuid, (blocksOverFlight.get(uuid) + distance.getXDifference() + distance.getYDifference() + distance.getZDifference()));
if (y1 > y2) {
blocksOverFlight.put(uuid, (blocksOverFlight.get(uuid) - distance.getYDifference()));
}
if (blocksOverFlight.get(uuid) > AntiCheat.getManager().getBackend().getMagic().FLIGHT_BLOCK_LIMIT() && (y1 <= y2)) {
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " flew over " + blocksOverFlight.get(uuid) + " blocks (max=" + AntiCheat.getManager().getBackend().getMagic().FLIGHT_BLOCK_LIMIT() + ")");
}
} else {
blocksOverFlight.put(uuid, 0D);
}
return PASS;
}
public static boolean isMovingExempt(Player player) {
return isDoing(player, movingExempt, -1);
}
private static boolean isDoing(Player player, Map<UUID, Long> map, double max) {
if (map.containsKey(player.getUniqueId())) {
if (max != -1) {
if (((System.currentTimeMillis() - map.get(player.getUniqueId())) / 1000) > max) {
map.remove(player.getUniqueId());
return false;
} else {
return true;
}
} else {
// Termination time has already been calculated
if (map.get(player.getUniqueId()) < System.currentTimeMillis()) {
map.remove(player.getUniqueId());
return false;
} else {
return true;
}
}
} else {
return false;
}
}
}
@@ -1,75 +0,0 @@
package net.gravitydevelopment.anticheat.check.movement;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.check.CheckResult;
import net.gravitydevelopment.anticheat.util.Distance;
import net.gravitydevelopment.anticheat.util.Utilities;
/**
*
* @author Marco STILL IN ALPHA TESTING!
* TODO fix false positives
*/
public class GlideCheck {
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
public static Map<UUID, Double> lastYDelta = new HashMap<UUID, Double>();
public static Map<UUID, Integer> glideBuffer = new HashMap<UUID, Integer>();
public static CheckResult runCheck(Player player, Distance distance) {
UUID uuid = player.getUniqueId();
if(!lastYDelta.containsKey(uuid))
lastYDelta.put(uuid, 0.0);
if(!YAxisCheck.lastYcoord.containsKey(uuid))
YAxisCheck.lastYcoord.put(uuid, player.getLocation().getY());
double currentY = player.getLocation().getY();
double math = currentY - YAxisCheck.lastYcoord.get(uuid);
if((math < 0 && math > AntiCheat.getManager().getBackend().getMagic().GLIDE_MAX()) && !AntiCheat.getManager().getBackend().isMovingExempt(player))
{
if(math <= lastYDelta.get(uuid) && !(player.getEyeLocation().getBlock().getType() == Material.LADDER)
&& !Utilities.isInWater(player) && !Utilities.isInWeb(player)
&& Utilities.cantStandAt(player.getLocation().getBlock()) && !Utilities.cantStandAtSingle(player.getLocation().getBlock()) && !!Utilities.cantStandAtSingle(player.getLocation().getBlock().getRelative(BlockFace.DOWN)))
{
if(!glideBuffer.containsKey(uuid))
glideBuffer.put(uuid, 0);
int currentBuffer = glideBuffer.get(uuid);
glideBuffer.put(uuid, currentBuffer + 1);
if(currentBuffer >= AntiCheat.getManager().getBackend().getMagic().GLIDE_LIMIT())
{
double fallDist = distanceToFall(player.getLocation());
player.teleport(player.getLocation().add(0, -fallDist, 0));
player.setFallDistance((float) fallDist);
if(!AntiCheat.getManager().getBackend().silentMode())
{
player.sendMessage(ChatColor.RED + "[AntiCheat] Glide/Fly hacking detected.");
}
lastYDelta.put(uuid, math);
return new CheckResult(CheckResult.Result.FAILED, uuid + " attempted to fall too slowly!");
}
}
}else {
glideBuffer.remove(uuid);
}
lastYDelta.put(uuid, math);
return PASS;
}
private static double distanceToFall(Location location) {
double firstY = location.getY();
while (location.clone().add(0, -0.1, 0).getBlock().getType() == Material.AIR)
location.add(0, -0.1, 0);
return firstY - location.getY();
}
}
@@ -1,79 +0,0 @@
package net.gravitydevelopment.anticheat.check.movement;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.check.CheckResult;
import net.gravitydevelopment.anticheat.util.VersionUtil;
public class SpeedCheck {
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
public static Map<UUID, Integer> speedViolation = new HashMap<UUID, Integer>();
public static boolean isSpeedExempt(Player player) {
return AntiCheat.getManager().getBackend().isMovingExempt(player)
|| AntiCheat.getManager().getBackend().justVelocity(player) || VersionUtil.isFlying(player);
}
public static CheckResult checkXZSpeed(Player player, double x, double z) {
if (!isSpeedExempt(player) && player.getVehicle() == null) {
String reason = "";
double max = AntiCheat.getManager().getBackend().getMagic().XZ_SPEED_MAX();
if (player.getLocation().getBlock().getType() == Material.SOUL_SAND) {
if (player.isSprinting()) {
reason = "on soulsand while sprinting ";
max = AntiCheat.getManager().getBackend().getMagic().XZ_SPEED_MAX_SOULSAND_SPRINT();
} else if (player.hasPotionEffect(PotionEffectType.SPEED)) {
reason = "on soulsand with speed potion ";
max = AntiCheat.getManager().getBackend().getMagic().XZ_SPEED_MAX_SOULSAND_POTION();
} else {
reason = "on soulsand ";
max = AntiCheat.getManager().getBackend().getMagic().XZ_SPEED_MAX_SOULSAND();
}
} else if (player.isFlying()) {
reason = "while flying ";
max = AntiCheat.getManager().getBackend().getMagic().XZ_SPEED_MAX_FLY();
} else if (player.hasPotionEffect(PotionEffectType.SPEED)) {
if (player.isSprinting()) {
reason = "with speed potion while sprinting ";
max = AntiCheat.getManager().getBackend().getMagic().XZ_SPEED_MAX_POTION_SPRINT();
} else {
reason = "with speed potion ";
max = AntiCheat.getManager().getBackend().getMagic().XZ_SPEED_MAX_POTION();
}
} else if (player.isSprinting()) {
reason = "while sprinting ";
max = AntiCheat.getManager().getBackend().getMagic().XZ_SPEED_MAX_SPRINT();
}
float speed = player.getWalkSpeed();
max += speed > 0 ? player.getWalkSpeed() - 0.2f : 0;
if (x > max || z > max) {
int num = AntiCheat.getManager().getBackend().increment(player, speedViolation,
AntiCheat.getManager().getBackend().getMagic().SPEED_MAX());
if (num >= AntiCheat.getManager().getBackend().getMagic().SPEED_MAX()) {
return new CheckResult(CheckResult.Result.FAILED,
player.getName() + "'s speed was too high " + reason + num + " times in a row (max="
+ AntiCheat.getManager().getBackend().getMagic().SPEED_MAX() + ", speed="
+ (x > z ? x : z) + ", max speed=" + max + ")");
} else {
return PASS;
}
} else {
speedViolation.put(player.getUniqueId(), 0);
return PASS;
}
} else {
return PASS;
}
}
}
@@ -1,90 +0,0 @@
package net.gravitydevelopment.anticheat.check.movement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.check.CheckResult;
import net.gravitydevelopment.anticheat.util.Utilities;
/**
* This check seems to be broken/outdated
*/
public class WaterWalkCheck {
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
public static List<UUID> isInWater = new ArrayList<UUID>();
public static List<UUID> isInWaterCache = new ArrayList<UUID>();
public static Map<UUID, Integer> waterSpeedViolation = new HashMap<UUID, Integer>();
public static Map<UUID, Integer> waterAscensionViolation = new HashMap<UUID, Integer>();
public static CheckResult runCheck(Player player, double x, double y, double z) {
Block block = player.getLocation().getBlock();
UUID uuid = player.getUniqueId();
if (player.getVehicle() == null && !player.isFlying()) {
if (block.isLiquid()) {
if (isInWater.contains(uuid)) {
if (isInWaterCache.contains(uuid)) {
if (player.getNearbyEntities(1, 1, 1).isEmpty()) {
boolean b;
if (!Utilities.sprintFly(player)) {
b = x > AntiCheat.getManager().getBackend().getMagic().XZ_SPEED_MAX_WATER() || z > AntiCheat.getManager().getBackend().getMagic().XZ_SPEED_MAX_WATER();
} else {
b = x > AntiCheat.getManager().getBackend().getMagic().XZ_SPEED_MAX_WATER_SPRINT() || z > AntiCheat.getManager().getBackend().getMagic().XZ_SPEED_MAX_WATER_SPRINT();
}
if (!b && !Utilities.isFullyInWater(player.getLocation()) && Utilities.isHoveringOverWater(player.getLocation(), 1) && y == 0D && !block.getType().equals(Material.WATER_LILY)) {
b = true;
}
if (b) {
if (waterSpeedViolation.containsKey(uuid)) {
int v = waterSpeedViolation.get(uuid);
if (v >= AntiCheat.getManager().getBackend().getMagic().WATER_SPEED_VIOLATION_MAX()) {
waterSpeedViolation.put(uuid, 0);
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " stood on water " + v + " times (can't stand on " + block.getType() + " or " + block.getRelative(BlockFace.DOWN).getType() + ")");
} else {
waterSpeedViolation.put(uuid, v + 1);
}
} else {
waterSpeedViolation.put(uuid, 1);
}
}
}
} else {
isInWaterCache.add(uuid);
return PASS;
}
} else {
isInWater.add(uuid);
return PASS;
}
} else if (block.getRelative(BlockFace.DOWN).isLiquid() && !AntiCheat.getManager().getBackend().isAscending(player) && Utilities.cantStandAt(block) && Utilities.cantStandAt(block.getRelative(BlockFace.DOWN))) {
if (waterAscensionViolation.containsKey(uuid)) {
int v = waterAscensionViolation.get(uuid);
if (v >= AntiCheat.getManager().getBackend().getMagic().WATER_ASCENSION_VIOLATION_MAX()) {
waterAscensionViolation.put(uuid, 0);
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " stood on water " + v + " times (can't stand on " + block.getType() + " or " + block.getRelative(BlockFace.DOWN).getType() + ")");
} else {
waterAscensionViolation.put(uuid, v + 1);
}
} else {
waterAscensionViolation.put(uuid, 1);
}
} else {
isInWater.remove(uuid);
isInWaterCache.remove(uuid);
}
}
return PASS;
}
}
@@ -1,112 +0,0 @@
package net.gravitydevelopment.anticheat.check.movement;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.check.CheckResult;
import net.gravitydevelopment.anticheat.util.Distance;
import net.gravitydevelopment.anticheat.util.Utilities;
import net.gravitydevelopment.anticheat.util.VersionUtil;
public class YAxisCheck {
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
public static Map<UUID, Double> lastYcoord = new HashMap<UUID, Double>();
public static Map<UUID, Long> lastYtime = new HashMap<UUID, Long>();
public static Map<UUID, Integer> yAxisViolations = new HashMap<UUID, Integer>();
public static Map<UUID, Long> yAxisLastViolation = new HashMap<UUID, Long>();
private static boolean hasJumpPotion(Player player) {
return player.hasPotionEffect(PotionEffectType.JUMP);
}
public static CheckResult runCheck(Player player, Distance distance) {
if (distance.getYDifference() > AntiCheat.getManager().getBackend().getMagic().TELEPORT_MIN() || distance.getYDifference() < 0 || VersionUtil.isFlying(player)) {
return PASS;
}
if (!FlightCheck.isMovingExempt(player) && !Utilities.isClimbableBlock(player.getLocation().getBlock()) && !Utilities.isClimbableBlock(player.getLocation().add(0, -1, 0).getBlock()) && !player.isInsideVehicle() && !Utilities.isInWater(player) && !hasJumpPotion(player) && !isMoveUpBlock(player.getLocation().add(0, -1, 0).getBlock()) && !isMoveUpBlock(player.getLocation().add(0, -1.5, 0).getBlock())) {
double y1 = player.getLocation().getY();
UUID uuid = player.getUniqueId();
// Fix Y axis spam.
if (!lastYcoord.containsKey(uuid) || !lastYtime.containsKey(uuid) || !yAxisLastViolation.containsKey(uuid)) {
lastYcoord.put(uuid, y1);
yAxisViolations.put(uuid, 0);
yAxisLastViolation.put(uuid, 0L);
lastYtime.put(uuid, System.currentTimeMillis());
} else {
if (y1 > lastYcoord.get(uuid) && yAxisViolations.get(uuid) > AntiCheat.getManager().getBackend().getMagic().Y_MAXVIOLATIONS() && (System.currentTimeMillis() - yAxisLastViolation.get(uuid)) < AntiCheat.getManager().getBackend().getMagic().Y_MAXVIOTIME()) {
Location g = player.getLocation();
yAxisViolations.put(uuid, yAxisViolations.get(uuid) + 1);
yAxisLastViolation.put(uuid, System.currentTimeMillis());
if (!AntiCheat.getManager().getBackend().silentMode()) {
g.setY(lastYcoord.get(uuid));
player.sendMessage(ChatColor.RED + "[AntiCheat] Fly hacking on the y-axis detected. Please wait 5 seconds to prevent getting damage.");
if (g.getBlock().getType() == Material.AIR) {
player.teleport(g);
}
}
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " tried to fly on y-axis " + yAxisViolations.get(uuid) + " times (max =" + AntiCheat.getManager().getBackend().getMagic().Y_MAXVIOLATIONS() + ")");
} else {
if (yAxisViolations.get(uuid) > AntiCheat.getManager().getBackend().getMagic().Y_MAXVIOLATIONS() && (System.currentTimeMillis() - yAxisLastViolation.get(uuid)) > AntiCheat.getManager().getBackend().getMagic().Y_MAXVIOTIME()) {
yAxisViolations.put(uuid, 0);
yAxisLastViolation.put(uuid, 0L);
}
}
long i = System.currentTimeMillis() - lastYtime.get(uuid);
double diff = AntiCheat.getManager().getBackend().getMagic().Y_MAXDIFF() + (Utilities.isStair(player.getLocation().add(0, -1, 0).getBlock()) ? 0.5 : 0.0);
if ((y1 - lastYcoord.get(uuid)) > diff && i < AntiCheat.getManager().getBackend().getMagic().Y_TIME()) {
Location g = player.getLocation();
yAxisViolations.put(uuid, yAxisViolations.get(uuid) + 1);
yAxisLastViolation.put(uuid, System.currentTimeMillis());
if (!AntiCheat.getManager().getBackend().silentMode()) {
g.setY(lastYcoord.get(uuid));
if (g.getBlock().getType() == Material.AIR) {
player.teleport(g);
}
}
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " tried to fly on y-axis in " + i + " ms (min =" + AntiCheat.getManager().getBackend().getMagic().Y_TIME() + ")");
} else {
if ((y1 - lastYcoord.get(uuid)) > AntiCheat.getManager().getBackend().getMagic().Y_MAXDIFF() + 1 || (System.currentTimeMillis() - lastYtime.get(uuid)) > AntiCheat.getManager().getBackend().getMagic().Y_TIME()) {
lastYtime.put(uuid, System.currentTimeMillis());
lastYcoord.put(uuid, y1);
}
}
}
}
// Fix Y axis spam
return PASS;
}
public static boolean isMoveUpBlock(Block block) {
return MOVE_UP_BLOCKS.contains(block.getType());
}
private static final EnumSet<Material> MOVE_UP_BLOCKS = EnumSet.of(
Material.ACACIA_STAIRS,
Material.BIRCH_WOOD_STAIRS,
Material.BRICK_STAIRS,
Material.COBBLESTONE_STAIRS,
Material.DARK_OAK_STAIRS,
Material.JUNGLE_WOOD_STAIRS,
Material.NETHER_BRICK_STAIRS,
Material.QUARTZ_STAIRS,
Material.RED_SANDSTONE_STAIRS,
Material.SANDSTONE_STAIRS,
Material.SMOOTH_STAIRS,
Material.SPRUCE_WOOD_STAIRS,
Material.WOOD_STAIRS,
Material.PURPUR_STAIRS
);
}
@@ -1,59 +0,0 @@
/*
* AntiCheat for Bukkit.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.gravitydevelopment.anticheat.command.executors;
import net.gravitydevelopment.anticheat.command.CommandBase;
import net.gravitydevelopment.anticheat.util.PastebinReport;
import net.gravitydevelopment.anticheat.util.Permission;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class CommandDebug extends CommandBase {
private static final String NAME = "AntiCheat Debug Reporting";
private static final String COMMAND = "debug";
private static final String USAGE = "anticheat debug <user>";
private static final Permission PERMISSION = Permission.SYSTEM_DEBUG;
private static final String[] HELP = {
GRAY + "Use: " + AQUA + "/anticheat debug" + GRAY + " to create a debug report",
GRAY + "Use: " + AQUA + "/anticheat debug <user>" + GRAY + " to create a debug report for a user",
};
public CommandDebug() {
super(NAME, COMMAND, USAGE, HELP, PERMISSION);
}
@Override
protected void execute(CommandSender cs, String[] args) {
Player player = null;
if (args.length == 1) {
player = Bukkit.getPlayer(args[0]);
} else {
if (cs instanceof Player) {
player = (Player) cs;
}
}
cs.sendMessage(GRAY + "Please wait while I collect some data...");
PastebinReport report = new PastebinReport(cs, player);
cs.sendMessage(GREEN + "Debug information posted to: " + WHITE + report.getURL());
cs.sendMessage(GREEN + "Please include this link when making bug reports.");
}
}
@@ -1,37 +0,0 @@
package net.gravitydevelopment.anticheat.manage;
import com.comphenix.protocol.Packets;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.*;
import net.gravitydevelopment.anticheat.AntiCheat;
public class PacketManager {
private ProtocolManager protocolManager;
private AntiCheat plugin;
private AntiCheatManager manager;
public PacketManager(ProtocolManager protocolManager, AntiCheat plugin, AntiCheatManager manager) {
this.protocolManager = protocolManager;
this.plugin = plugin;
this.manager = manager;
addListeners();
}
private void addListeners() {
// Arm Animation
protocolManager.addPacketListener(new PacketAdapter(plugin,
ConnectionSide.CLIENT_SIDE,
ListenerPriority.NORMAL,
Packets.Client.ARM_ANIMATION) {
@Override
public void onPacketReceiving(PacketEvent event) {
if (event.getPacketID() == Packets.Client.ARM_ANIMATION) {
PacketContainer packet = event.getPacket();
//System.out.println("Arm animation from "+packet.getIntegers().read(0));
}
}
});
}
}
@@ -1,225 +0,0 @@
/*
* AntiCheat for Bukkit.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.gravitydevelopment.anticheat.util;
import org.bukkit.Material;
public enum BlockHardness {
STONE(1.50D),
GRASS(0.60D),
DIRT(0.50D),
COBBLESTONE(2.00D),
WOOD(2.00D),
SAPLING(0.00D),
WATER(100.00D),
STATIONARY_WATER(100.00D),
LAVA(0.00D),
STATIONARY_LAVA(100.00D),
SAND(0.50D),
GRAVEL(0.60D),
GOLD_ORE(3.00D),
IRON_ORE(3.00D),
COAL_ORE(3.00D),
LOG(2.00D),
LOG_2(2.00D),
LEAVES(0.20D),
LEAVES_2(0.20D),
SPONGE(0.60D),
GLASS(0.30D),
LAPIS_ORE(3.00D),
LAPIS_BLOCK(3.00D),
DISPENSER(3.50D),
DROPPER(3.50D),
SANDSTONE(0.80D),
NOTE_BLOCK(0.80D),
BED(0.20D),
RAILS(0.70D),
DETECTOR_RAIL(0.70D),
POWERED_RAIL(0.70D),
ACTIVATOR_RAIL(0.70D),
WEB(4.00D),
LONG_GRASS(0.00D),
DOUBLE_PLANT(0.00D),
DEAD_BUSH(0.00D),
WOOL(0.80D),
YELLOW_FLOWER(0.00D),
RED_ROSE(0.00D),
BROWN_MUSHROOM(0.00D),
RED_MUSHROOM(0.00D),
GOLD_BLOCK(3.00D),
IRON_BLOCK(5.00D),
DOUBLE_STEP(2.00D),
STEP(2.00D),
BRICK(2.00D),
TNT(0.00D),
BOOKSHELF(1.50D),
MOSSY_COBBLESTONE(2.00D),
OBSIDIAN(50.00D),
TORCH(0.00D),
FIRE(0.00D),
MOB_SPAWNER(5.00D),
CHEST(2.50D),
TRAPPED_CHEST(2.50D),
REDSTONE_WIRE(0.00D),
DIAMOND_ORE(3.00D),
DIAMOND_BLOCK(5.00D),
WORKBENCH(2.50D),
SOIL(0.60D),
FURNACE(3.50D),
BURNING_FURNACE(3.50D),
WOODEN_DOOR(3.00D),
LADDER(0.40D),
LEVER(0.50D),
IRON_DOOR_BLOCK(5.00D),
HOPPER(2.00D),
STONE_PLATE(0.50D),
WOOD_PLATE(0.50D),
GOLD_PLATE(0.50D),
IRON_PLATE(0.50D),
QUARTZ_BLOCK(0.80D),
QUARTZ_ORE(3.00D),
REDSTONE_BLOCK(5.00D),
REDSTONE_ORE(3.00D),
GLOWING_REDSTONE_ORE(3.00D),
REDSTONE_TORCH_OFF(0.00D),
REDSTONE_TORCH_ON(0.00D),
REDSTONE_COMPARATOR_OFF(0.00D),
REDSTONE_COMPARATOR_ON(0.00D),
DAYLIGHT_DETECTOR(0.20D),
STONE_BUTTON(0.50D),
SNOW(0.10D),
ICE(0.50D),
PACKED_ICE(0.50D),
SNOW_BLOCK(0.20D),
CACTUS(0.40D),
CLAY(0.60D),
HARD_CLAY(1.25D),
STAINED_CLAY(1.25D),
SUGAR_CANE_BLOCK(0.00D),
JUKEBOX(2.00D),
FENCE(2.00D),
NETHERRACK(0.40D),
SOUL_SAND(0.50D),
GLOWSTONE(0.30D),
PORTAL(-1.00D),
CAKE_BLOCK(0.50D),
LOCKED_CHEST(0.00D),
TRAP_DOOR(3.00D),
MONSTER_EGGS(0.750D),
SMOOTH_BRICK(1.50D),
IRON_FENCE(5.00D),
THIN_GLASS(0.30D),
STAINED_GLASS(0.30D),
STAINED_GLASS_PANE(0.30D),
PUMPKIN_STEM(0.00D),
MELON_STEM(0.00D),
VINE(0.20D),
FENCE_GATE(2.00D),
MYCEL(0.60D),
WATER_LILY(0.00D),
NETHER_BRICK(2.00D),
NETHER_FENCE(2.00D),
ENCHANTMENT_TABLE(5.00D),
BREWING_STAND(0.50D),
CAULDRON(2.00D),
ENDER_PORTAL(-1.00D),
ENDER_PORTAL_FRAME(-1.00D),
DRAGON_EGG(3.00D),
REDSTONE_LAMP_OFF(0.30D),
REDSTONE_LAMP_ON(0.30D),
WOOD_DOUBLE_STEP(2.00D),
WOOD_STEP(2.00D),
COCOA(0.20D),
EMERALD_ORE(3.00D),
ENDER_CHEST(22.50D),
EMERALD_BLOCK(5.00D),
FLOWER_POT(0.00D),
WOOD_BUTTON(0.50D),
ANVIL(5.00D),
HUGE_MUSHROOM_1(0.20D),
HUGE_MUSHROOM_2(0.20D),
BED_BLOCK(0.20D),
WOOD_STAIRS(2.00D),
COBBLESTONE_STAIRS(2.00D),
BRICK_STAIRS(2.00D),
SMOOTH_STAIRS(1.50D),
NETHER_BRICK_STAIRS(2.00D),
SPRUCE_WOOD_STAIRS(2.00D),
BIRCH_WOOD_STAIRS(2.00D),
JUNGLE_WOOD_STAIRS(2.00D),
DARK_OAK_STAIRS(2.00D),
ACACIA_STAIRS(2.00D),
QUARTZ_STAIRS(0.80D),
SANDSTONE_STAIRS(0.80D),
COMMAND(0.00D),
BEACON(3.00D),
COBBLE_WALL(2.00D),
CROPS(0.00D),
CARROT(0.00D),
POTATO(0.00D),
SKULL(1.00D),
NETHER_WARTS(0.00D),
SIGN_POST(1.00D),
WALL_SIGN(1.00D),
PUMPKIN(1.00D),
JACK_O_LANTERN(1.00D),
DIODE_BLOCK_ON(0.00D),
DIODE_BLOCK_OFF(0.00D),
MELON_BLOCK(1.00D),
ENDER_STONE(3.00D),
TRIPWIRE(0.00D),
TRIPWIRE_HOOK(0.00D),
HAY_BLOCK(0.50D),
CARPET(0.10D),
COAL_BLOCK(5.00D),
PISTON_BASE(0.70D),
PISTON_EXTENSION(0.70D),
PISTON_MOVING_PIECE(0.70D),
PISTON_STICKY_BASE(0.70D);
Material mat;
double hardness;
BlockHardness(double hard) {
mat = Material.getMaterial(name());
hardness = hard;
}
public static double getBlockHardness(Material m) {
try {
BlockHardness h = getHardness(m);
return h == null ? 0D : h.hardness;
}catch(Exception e) {
return 0D;
}
}
public static boolean hasBlockHardness(Material m) {
return getHardness(m) != null;
}
public static BlockHardness getHardness(Material m) {
for (BlockHardness e : BlockHardness.values()) {
if (e.mat.equals(m)) {
return e;
}
}
return null;
}
}
@@ -1,59 +0,0 @@
/*
* AntiCheat for Bukkit.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.gravitydevelopment.anticheat.util;
import org.bukkit.Location;
public class Distance {
private final double l1Y;
private final double l2Y;
private final double XDiff;
private final double YDiff;
private final double ZDiff;
public Distance(Location from, Location to) {
l1Y = to.getY();
l2Y = from.getY();
XDiff = Math.abs(to.getX() - from.getX());
ZDiff = Math.abs(to.getZ() - from.getZ());
YDiff = Math.abs(l1Y - l2Y);
}
public double fromY() {
return l2Y;
}
public double toY() {
return l1Y;
}
public double getXDifference() {
return XDiff;
}
public double getZDifference() {
return ZDiff;
}
public double getYDifference() {
return YDiff;
}
}
@@ -1,88 +0,0 @@
/*
* AntiCheat for Bukkit.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.gravitydevelopment.anticheat.util;
import net.gravitydevelopment.anticheat.AntiCheat;
import org.bukkit.ChatColor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Group {
private String name;
private int level;
private ChatColor color = ChatColor.RED;
private List<String> actions = new ArrayList<String>();
public Group(String name, int level, String color, List<String> actions) {
this.name = name;
this.level = level;
this.actions = actions;
ChatColor c = ChatColor.valueOf(color);
if (c == null) {
AntiCheat.getPlugin().getLogger().warning("Event '" + name + "' was initialized with the color '" + color + "' which is invalid.");
AntiCheat.getPlugin().getLogger().warning("This event will not run properly. See http://jd.bukkit.org/apidocs/org/bukkit/ChatColor.html#enum_constant_summary for a list of valid colors");
} else {
this.color = c;
}
}
public String getName() {
return name;
}
public int getLevel() {
return level;
}
public ChatColor getColor() {
return color;
}
public List<String> getActions() {
return actions;
}
public static Group load(String string) {
try {
if (string.split(" : ").length == 4) {
String name = string.split(" : ")[0];
int level = Integer.parseInt(string.split(" : ")[1]);
String color = string.split(" : ")[2];
List<String> actions = Arrays.asList(string.split(" : ")[3].split(","));
return new Group(name, level, color, actions);
} else {
throw new Exception();
}
} catch (Exception ex) {
AntiCheat.getPlugin().getLogger().warning("An event was initialized with an invalid string: '" + string + "'");
AntiCheat.getPlugin().getLogger().warning("The proper format is: 'name : threshold : color : action' such as 'High : 50 : RED : KICK'");
AntiCheat.getPlugin().getLogger().warning("This event will NOT run. (" + ex.getMessage() + ")");
return null;
}
}
@Override
public String toString() {
return name + " : " + level + " : " + color.name() + " : " + Utilities.listToCommaString(actions);
}
}
@@ -1,187 +0,0 @@
package net.gravitydevelopment.anticheat.util;
import java.util.Random;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_10_R1.CraftServer;
import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import com.mojang.authlib.GameProfile;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.minecraft.server.v1_10_R1.EntityHuman;
import net.minecraft.server.v1_10_R1.EntityPlayer;
import net.minecraft.server.v1_10_R1.MinecraftServer;
import net.minecraft.server.v1_10_R1.PacketPlayOutEntityMetadata;
import net.minecraft.server.v1_10_R1.PacketPlayOutEntityTeleport;
import net.minecraft.server.v1_10_R1.PacketPlayOutNamedEntitySpawn;
import net.minecraft.server.v1_10_R1.PacketPlayOutPlayerInfo;
import net.minecraft.server.v1_10_R1.PlayerConnection;
import net.minecraft.server.v1_10_R1.PlayerInteractManager;
import net.minecraft.server.v1_10_R1.World;
import net.minecraft.server.v1_10_R1.WorldServer;
public class NPC_1_10 {
private final UUID owner;
private final String name;
private UUID uuid;
private EntityPlayer npc;
private int entityId;
private Location location;
public int getID() {
return this.entityId;
}
public NPC_1_10(Player owner) {
this.owner = owner.getUniqueId();
this.name = NameGenerator.generateName();
Location eyelocation = owner.getEyeLocation();
Vector vec = owner.getLocation().getDirection();
vec.setX(-3 * vec.getX());
vec.setZ(-3 * vec.getZ());
Location back = eyelocation.add(vec);
this.location = back; // TODO
}
public void spawn() {
final MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
final WorldServer nmsWorld = ((CraftWorld) this.getOwner().getWorld()).getHandle();
this.uuid = UUID.randomUUID();
(this.npc = new EntityPlayer(nmsServer, nmsWorld, new GameProfile(this.uuid, this.name),
new PlayerInteractManager((World) nmsWorld))).setLocation(this.location.getX(), this.location.getY(),
this.location.getZ(), 0.0f, 0.0f);
this.npc.collides = false;
this.npc.setInvisible(true);
this.entityId = this.npc.getId();
final PlayerConnection connection = ((CraftPlayer) this.getOwner()).getHandle().playerConnection;
connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER,
new EntityPlayer[] { this.npc }));
connection.sendPacket(new PacketPlayOutNamedEntitySpawn((EntityHuman) this.npc));
}
public boolean up = true;
public void move(PlayerMoveEvent e) {
if (e.getTo().getPitch() <= -32.5) {
if (e.getTo().getPitch() <= -82.5) {
Location eyelocation = e.getPlayer().getEyeLocation();
Vector vec = e.getPlayer().getLocation().getDirection();
vec.setX(-3 * vec.getX());
vec.setY(e.getPlayer().getLocation().getY() - 8.25);
vec.setZ(-3 * vec.getZ());
Location back = eyelocation.add(vec);
this.location = back; // TODO
this.npc.teleportTo(back, false);
((CraftPlayer) this.getOwner()).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityTeleport(npc));
if (new Random().nextInt(50) == 25 && this.npc.isInvisible()) {
this.npc.setInvisible(false);
((CraftPlayer) this.getOwner()).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityMetadata(entityId, npc.getDataWatcher(), false));
new BukkitRunnable() {
@Override
public void run() {
npc.setInvisible(true);
((CraftPlayer) getOwner()).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityMetadata(entityId, npc.getDataWatcher(), false));
}
}.runTaskLater(AntiCheat.getPlugin(), 4);
}
}else {
Location eyelocation = e.getPlayer().getEyeLocation();
Vector vec = e.getPlayer().getLocation().getDirection();
vec.setX(-3 * vec.getX());
vec.setY(e.getPlayer().getLocation().getY());
vec.setZ(-3 * vec.getZ());
Location back = eyelocation.add(vec);
this.location = back; // TODO
this.npc.teleportTo(back, false);
((CraftPlayer) this.getOwner()).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityTeleport(npc));
}
} else if (e.getTo().getPitch() >= 22) {
Location eyelocation = e.getPlayer().getEyeLocation();
Vector vec = e.getPlayer().getLocation().getDirection();
vec.setX(-3 * vec.getX());
vec.setY(e.getPlayer().getLocation().getY() - 0.4);
vec.setZ(-3 * vec.getZ());
Location back = eyelocation.add(vec);
this.location = back; // TODO
this.npc.teleportTo(back, false);
((CraftPlayer) this.getOwner()).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityTeleport(npc));
} else {
Location eyelocation = e.getPlayer().getEyeLocation();
Vector vec = e.getPlayer().getLocation().getDirection();
vec.setX(-1.95 * vec.getX());
if (up)
vec.setY(vec.getY() + 0.5);
else
vec.setY(vec.getY() - 0.25);
if (new Random().nextInt(10) == 5)
up = !up;
vec.setZ(-1.95 * vec.getZ());
Location back = eyelocation.add(vec);
this.location = back; // TODO
this.npc.setPositionRotation(back.getX(), back.getY(), back.getZ(), (float)new Random().nextFloat() * 20, (float)new Random().nextFloat() * 20);
this.npc.teleportTo(back, false);
((CraftPlayer) this.getOwner()).getHandle().playerConnection
.sendPacket(new PacketPlayOutEntityTeleport(npc));
if (new Random().nextInt(1000) == 500 && this.npc.isInvisible()) {
this.npc.setInvisible(false);
((CraftPlayer) this.getOwner()).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityMetadata(entityId, npc.getDataWatcher(), false));
new BukkitRunnable() {
@Override
public void run() {
npc.setInvisible(true);
((CraftPlayer) getOwner()).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityMetadata(entityId, npc.getDataWatcher(), false));
}
}.runTaskLater(AntiCheat.getPlugin(), 6);
}
}
}
public Player getOwner() {
return Bukkit.getPlayer(owner);
}
public void damage(EntityDamageByEntityEvent e, Player p) {
if (p != getOwner() || this.npc == null) {
return;
}
if (new Random().nextBoolean() && this.npc.isInvisible()) {
this.npc.setInvisible(false);
((CraftPlayer) this.getOwner()).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityMetadata(entityId, npc.getDataWatcher(), false));
new BukkitRunnable() {
@Override
public void run() {
npc.setInvisible(true);
((CraftPlayer) getOwner()).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityMetadata(entityId, npc.getDataWatcher(), false));
}
}.runTaskLater(AntiCheat.getPlugin(), 6 + new Random().nextInt(7));
}
}
public void damage() {
if (this.npc == null) {
return;
}
if (new Random().nextBoolean() && this.npc.isInvisible()) {
this.npc.setInvisible(false);
((CraftPlayer) this.getOwner()).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityMetadata(entityId, npc.getDataWatcher(), false));
new BukkitRunnable() {
@Override
public void run() {
npc.setInvisible(true);
((CraftPlayer) getOwner()).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityMetadata(entityId, npc.getDataWatcher(), false));
}
}.runTaskLater(AntiCheat.getPlugin(), 6 + new Random().nextInt(8));
}
}
}
@@ -1,37 +0,0 @@
package net.gravitydevelopment.anticheat.util;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
public class NameGenerator {
private static final List<String> BEGIN = Arrays.asList(new String[]{
"Pixel",
"Pro",
"NoHax",
"Just",
"That",
"New"
});
private static final List<String> END = Arrays.asList(new String[]{
"Gamer",
"PvP",
"JustYolo",
"Gaming",
"Minecraft",
"Games"
});
public static String generateName() {
Random r = new Random();
String begin = BEGIN.get(r.nextInt(BEGIN.size() - 1));
String end = END.get(r.nextInt(END.size() - 1));
if (r.nextBoolean())
return begin + end + r.nextInt(9);
else
return begin + end;
}
}
@@ -1,37 +0,0 @@
package net.gravitydevelopment.anticheat.util;
import java.util.Random;
public class NameUtil {
private static String[] firstParts = new String[] {
"Gamer",
"Pixel",
"Derp",
"Random",
"That",
"NoHaxJust",
"Derp",
"Fun",
"Luigi"
};
private static String[] secondParts = new String[] {
"01",
"Boy",
"Guy",
"Mario",
"Plain",
"Simple",
"NotHacking",
"Random",
"11",
"06"
};
private static Random theRandom = new Random();
public static String getRandomName() {
return firstParts[theRandom.nextInt(firstParts.length - 1)] + secondParts[theRandom.nextInt(secondParts.length - 1)];
}
}
@@ -1,227 +0,0 @@
/*
* AntiCheat for Bukkit.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.gravitydevelopment.anticheat.util;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.config.Configuration;
import net.gravitydevelopment.anticheat.config.providers.Magic;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import java.io.*;
import java.lang.reflect.Field;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
public class PastebinReport {
private static final String DATE = new SimpleDateFormat("yyyy-MM-dd kk:mm Z").format(new Date());
private static final String API_KEY = "d5ac92da966edb97a97860e6a052784f";
private StringBuilder report = new StringBuilder();
private String url = "";
public PastebinReport(CommandSender cs) {
Player player = null;
if (cs instanceof Player) {
player = (Player) cs;
}
createReport(player);
try {
writeReport();
} catch (IOException e) {
}
postReport();
}
public PastebinReport(CommandSender cs, Player tp) {
createReport(tp);
try {
writeReport();
} catch (IOException e) {
}
postReport();
}
public String getURL() {
return url;
}
private void appendPermissionsTester(Player player) {
if (player == null) {
append("No player defined.");
return;
}
for (Permission node : Permission.values()) {
report.append(player.getName() + ": " + node.toString() + " " + node.get(player));
if (node.get(player) && !node.whichPermission(player).equals(node.toString())) {
report.append(" (Applied by " + node.whichPermission(player) + ")");
}
report.append('\n');
}
}
private void createReport(Player player) {
if (Bukkit.getPluginManager().getPlugin("NoCheatPlus") != null) {
append("------------ WARNING! ------------");
append("This report was run with NoCheatPlus enabled. Results may be inaccurate." + '\n');
}
append("------------ AntiCheat Report - " + DATE + " ------------");
appendSystemInfo();
append("------------Last 30 logs------------");
appendLogs();
append("------------Permission Tester------------");
appendPermissionsTester(player);
append("------------Event Chains------------");
appendEventHandlers();
append("------------Magic Diff------------");
appendMagicDiff();
append("-----------End Of Report------------");
}
private void appendLogs() {
List<String> logs = AntiCheat.getManager().getLoggingManager().getLastLogs();
if (logs.size() == 0) {
append("No recent logs.");
return;
}
for (String log : logs) {
append(log);
}
}
private void appendSystemInfo() {
Runtime runtime = Runtime.getRuntime();
Configuration config = AntiCheat.getManager().getConfiguration();
append("AntiCheat Version: " + AntiCheat.getVersion());
append("Server Version: " + Bukkit.getVersion());
append("Server Implementation: " + Bukkit.getName());
append("Server ID: " + Bukkit.getServerId());
append("NMS Version: " + VersionUtil.getVersion());
append("Java Version: " + System.getProperty("java.vendor") + " " + System.getProperty("java.version"));
append("OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version"));
append("Free Memory: " + runtime.freeMemory() / 1024 / 1024 + "MB");
append("Max Memory: " + runtime.maxMemory() / 1024 / 1024 + "MB");
append("Total Memory: " + runtime.totalMemory() / 1024 / 1024 + "MB");
append("Online Mode: " + Bukkit.getOnlineMode());
append("Players: " + Bukkit.getOnlinePlayers().size() + "/" + Bukkit.getMaxPlayers());
append("Plugin Count: " + Bukkit.getPluginManager().getPlugins().length);
append("Plugin Uptime: " + ((System.currentTimeMillis() - AntiCheat.getPlugin().getLoadTime()) / 1000) / 60 + " minutes");
append("Enterprise: " + config.getConfig().enterprise.getValue());
if (config.getConfig().enterprise.getValue()) {
append("- Server name: " + config.getEnterprise().serverName.getValue());
append("- Database type: " + config.getEnterprise().database.getType());
append("- Groups source: " + (config.getEnterprise().configGroups.getValue() ? "Database" : "Flatfile"));
append("- Rules source: " + (config.getEnterprise().configRules.getValue() ? "Database" : "Flatfile"));
append("- Levels source: " + (config.getEnterprise().syncLevels.getValue() ? "Database" : "Flatfile"));
}
}
private void appendMagicDiff() {
// This is hacky, and I like it
Magic magic = AntiCheat.getManager().getConfiguration().getMagic();
FileConfiguration file = YamlConfiguration.loadConfiguration(new File(AntiCheat.getPlugin().getDataFolder(), "magic.yml"));
boolean changed = false;
for (Field field : Magic.class.getFields()) {
Object defaultValue = file.get(field.getName());
try {
Field value = magic.getClass().getDeclaredField(field.getName());
String s1 = value.get(magic).toString();
String s2 = defaultValue.toString();
if (!s1.equals(s2) && !s1.equals(s2 + ".0")) {
changed = true;
append(field.getName() + ": " + s1 + " (Default: " + s2 + ")");
} else {
}
} catch (NoSuchFieldException ex) {
} catch (IllegalAccessException ex) {
}
}
if (!changed) {
append("No changes from default.");
}
}
private void appendEventHandlers() {
report.append(AntiCheat.getManager().getEventChainReport());
}
private void writeReport() throws IOException {
File f = new File(AntiCheat.getPlugin().getDataFolder() + "/report.txt");
FileWriter r = new FileWriter(f);
BufferedWriter writer = new BufferedWriter(r);
writer.write(report.toString());
writer.close();
}
private void postReport() {
try {
URL urls = new URL("http://pastebin.com/api/api_post.php");
HttpURLConnection conn = (HttpURLConnection) urls.openConnection();
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);
conn.setRequestMethod("POST");
conn.addRequestProperty("Content-type", "application/x-www-form-urlencoded");
conn.setInstanceFollowRedirects(false);
conn.setDoOutput(true);
OutputStream out = conn.getOutputStream();
out.write(("api_option=paste" + "&api_dev_key=" + URLEncoder.encode(API_KEY, "utf-8") + "&api_paste_code=" + URLEncoder.encode(report.toString(), "utf-8") + "&api_paste_private=" + URLEncoder.encode("1", "utf-8") + "&api_paste_name=" + URLEncoder.encode("", "utf-8") + "&api_paste_expire_date=" + URLEncoder.encode("1M", "utf-8") + "&api_paste_format=" + URLEncoder.encode("text", "utf-8") + "&api_user_key=" + URLEncoder.encode("", "utf-8")).getBytes());
out.flush();
out.close();
if (conn.getResponseCode() == 200) {
InputStream receive = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(receive));
String line;
StringBuffer response = new StringBuffer();
while ((line = reader.readLine()) != null) {
response.append(line);
response.append("\r\n");
}
reader.close();
String result = response.toString().trim();
if (!result.contains("http://")) {
url = "Failed to post. Check report.txt";
} else {
url = result.trim();
}
} else {
url = "Failed to post. Check report.txt";
}
} catch (Exception e) {
url = "Failed to post. Check report.txt";
}
}
private void append(String s) {
report.append(s + '\n');
}
}
@@ -1,97 +0,0 @@
/*
* AntiCheat for Bukkit.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.gravitydevelopment.anticheat.util;
import org.bukkit.command.CommandSender;
public enum Permission {
/* Check Nodes */
CHECK_ZOMBE_FLY,
CHECK_ZOMBE_NOCLIP,
CHECK_ZOMBE_CHEAT,
CHECK_FLY,
CHECK_WATERWALK,
CHECK_NOSWING,
CHECK_FASTBREAK,
CHECK_FASTPLACE,
CHECK_CHATSPAM,
CHECK_COMMANDSPAM,
CHECK_SPRINT,
CHECK_SNEAK,
CHECK_SPEED,
CHECK_VCLIP,
CHECK_SPIDER,
CHECK_NOFALL,
CHECK_FASTBOW,
CHECK_FASTEAT,
CHECK_FASTHEAL,
CHECK_FORCEFIELD,
CHECK_LONGREACH,
CHECK_FASTPROJECTILE,
CHECK_ITEMSPAM,
CHECK_VISUAL,
CHECK_FASTINVENTORY,
CHECK_AUTOTOOL,
/* System Nodes */
SYSTEM_LOG,
SYSTEM_RESET,
SYSTEM_SPY,
SYSTEM_HELP,
SYSTEM_UPDATE,
SYSTEM_REPORT,
SYSTEM_ALERT,
SYSTEM_NOTICE,
SYSTEM_CALIBRATE,
SYSTEM_CHECK,
SYSTEM_DEBUG,
SYSTEM_RELOAD, CHECK_KILLAURA, CHECK_BLINK, VELOCITY, CRITICALS;
private static final String PERMISSION_ALL = "anticheat.*";
private static final String PERMISSION_SPAM = "anticheat.check.spam";
public static boolean getCommandExempt(CommandSender cs, String commandLabel) {
// Check permission, base, and all will have already been checked
return cs.hasPermission(CHECK_COMMANDSPAM.toString() + commandLabel);
}
public boolean get(CommandSender cs) {
if ((this == CHECK_CHATSPAM || this == CHECK_COMMANDSPAM) && cs.hasPermission(PERMISSION_SPAM)) return true;
return cs.hasPermission(toString()) || cs.hasPermission(getBase()) || cs.hasPermission(PERMISSION_ALL);
}
public String getBase() {
return "anticheat." + this.name().toLowerCase().split("_")[0] + ".*";
}
public String whichPermission(CommandSender cs) {
for (String s : new String[]{PERMISSION_ALL, getBase(), toString()}) {
if (cs.hasPermission(s)) {
return s;
}
}
return null;
}
@Override
public String toString() {
return "anticheat." + this.name().toLowerCase().replace("_", ".");
}
}
@@ -1,430 +0,0 @@
/*
* AntiCheat for Bukkit.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.gravitydevelopment.anticheat.util;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.check.CheckType;
import net.gravitydevelopment.anticheat.config.Configuration;
import net.gravitydevelopment.anticheat.util.rule.Rule;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class User {
private final UUID uuid;
private final String name;
private final int id;
private int level = 0;
private Location goodLocation;
private List<ItemStack> inventorySnapshot = null;
private Configuration config = AntiCheat.getManager().getConfiguration();
private int toX, toY, toZ;
private String[] messages = new String[2];
private Long[] messageTimes = new Long[2];
private String[] commands = new String[2];
private Long[] commandTimes = new Long[2];
private boolean isWaitingOnLevelSync;
private Timestamp levelSyncTimestamp;
/**
* Initialize an AntiCheat user
*
* @param uuid Player's UUID
*/
public User(UUID uuid) {
this.uuid = uuid;
this.name = getPlayer() != null && getPlayer().isOnline() ? getPlayer().getName() : "";
this.id = getPlayer() != null && getPlayer().isOnline() ? getPlayer().getEntityId() : -1;
}
/**
* Initialize an AntiCheat user
*
* @param name Player's name
*/
/* public User(String name) {
this.uuid = Bukkit.getPlayer(name).getUniqueId();
this.name = name;
this.id = getPlayer() != null && getPlayer().isOnline() ? getPlayer().getEntityId() : -1;
}
*/
/**
* Get the player's UUID
*
* @return Player UUID
*/
public UUID getUUID() {
return uuid;
}
/**
* Get the player's name
*
* @return Player name
*/
public String getName() {
return name;
}
/**
* Get the player's entity ID
*
* @return Entity id
*/
public int getId() {
return id;
}
/**
* Get the Bukkit player
*
* @return Player
*/
public Player getPlayer() {
return Bukkit.getPlayer(uuid);
}
/**
* Get the user's level value
*
* @return level
*/
public int getLevel() {
return level;
}
/**
* Get the user's group
*
* @return group
*/
public Group getGroup() {
List<Group> groups = config.getGroups().getGroups();
for (int i = 0; i < groups.size(); i++) {
if (i == 0 && level < groups.get(i).getLevel()) break;
else if (i == groups.size() - 1) return groups.get(i);
else if (level >= groups.get(i).getLevel() && level < groups.get(i + 1).getLevel()) return groups.get(i);
}
return null;
}
/**
* Increase the player's level (from failing a check)
*
* @param type The check failed
* @return true if the level was increased
*/
public boolean increaseLevel(CheckType type) {
if (getPlayer() != null && getPlayer().isOnline()) {
if (silentMode() && type.getUses(uuid) % 4 != 0) {
// Prevent silent mode from increasing the level way too fast
return false;
} else {
if (level < config.getGroups().getHighestLevel()) {
level++;
// Check levels
for (Group l : getLevels()) {
if (l.getLevel() == level) {
AntiCheat.getManager().getUserManager().alert(this, l, type);
if (l.getLevel() == config.getGroups().getHighestLevel()) {
level = l.getLevel() - 10;
}
}
}
// Execute rules
for (Rule rule : config.getRules().getRules()) {
rule.check(this, type);
}
return true;
}
return false;
}
} else {
return false;
}
}
/**
* Decrease the player's level by one value
*/
public void decreaseLevel() {
level = level != 0 ? level - 1 : 0;
}
/**
* Set the users level to a specific value. Must be 0 < level < config-defined highest level
*
* @param level level to set
* @return true if the level was valid and set properly
*/
public boolean setLevel(int level) {
isWaitingOnLevelSync = false;
if (level >= 0) {
if (level <= config.getGroups().getHighestLevel()) {
this.level = level;
return true;
} else {
this.level = config.getGroups().getHighestLevel();
return false;
}
} else {
return false;
}
}
/**
* Reset the user's level to zero and clear all check failures
*/
public void resetLevel() {
level = 0;
for (CheckType type : CheckType.values()) {
type.clearUse(uuid);
}
}
/**
* Get the last known valid location of the player for use in resetting
*
* @param location default value to be returned if no known good location exists
* @return last known valid location
*/
public Location getGoodLocation(Location location) {
if (goodLocation == null) {
return location;
}
return goodLocation;
}
/**
* Set the last known valid location of the player
*
* @param location location to be set
* @return true if the location was valid and set properly
*/
public boolean setGoodLocation(Location location) {
if (Utilities.cantStandAtExp(location) || (location.getBlock().isLiquid() && !Utilities.isFullyInWater(location))) {
return false;
}
goodLocation = location;
return true;
}
/**
* Store a copy of the player's inventory, for use in resetting
*
* @param is ItemStack list to store
*/
public void setInventorySnapshot(ItemStack[] is) {
inventorySnapshot = new ArrayList<ItemStack>();
for (int i = 0; i < is.length; i++) {
if (is[i] != null) {
inventorySnapshot.add(is[i].clone());
}
}
}
/**
* Remove the current inventory snapshot
*/
public void removeInventorySnapshot() {
inventorySnapshot = null;
}
/**
* Restore the player's inventory with the current inventory snapshot
*
* @param inventory Player's inventory
*/
public void restoreInventory(Inventory inventory) {
if (inventorySnapshot != null) {
inventory.clear();
for (ItemStack is : inventorySnapshot) {
if (is != null) {
inventory.addItem(is);
}
}
}
}
/**
* Set the player's to location
*
* @param x X value
* @param y Y value
* @param z Z value
*/
public void setTo(double x, double y, double z) {
toX = (int) x;
toY = (int) y;
toZ = (int) z;
}
/**
* Check if a given to value is the same as the stored value
*
* @param x X value
* @param y Y value
* @param z Z value
* @return true if coordinates are all equal
*/
public boolean checkTo(double x, double y, double z) {
return (int) x == toX && (int) y == toY && (int) z == toZ;
}
/**
* Log a player's chat message
*
* @param message Message to log
*/
public void addMessage(String message) {
addToSpamLog(message, messages, messageTimes);
}
/**
* Log a player's command
*
* @param command Command to log
*/
public void addCommand(String command) {
addToSpamLog(command, commands, commandTimes);
}
private void addToSpamLog(String string, String[] messages, Long[] times) {
messages[1] = messages[0];
messages[0] = string;
times[1] = times[0];
times[0] = System.currentTimeMillis();
}
/**
* Get a stored chat message
*
* @param index Index of the chat in storage
* @return the message
*/
public String getMessage(int index) {
return messages[index];
}
/**
* Get a stored command
*
* @param index Index of the command in storage
* @return the command
*/
public String getCommand(int index) {
return commands[index];
}
/**
* Get the time a message in storage was sent
*
* @param index Index of the chat in storage
* @return time the message was sent
*/
public Long getMessageTime(int index) {
return messageTimes[index];
}
/**
* Get the time a command in storage was sent
*
* @param index Index of the command in storage
* @return time the command was sent
*/
public Long getCommandTime(int index) {
return commandTimes[index];
}
/**
* Clear all stored messages
*/
public void clearMessages() {
messages = new String[2];
messageTimes = new Long[2];
}
/**
* Clear all stored commands
*/
public void clearCommands() {
commands = new String[2];
commandTimes = new Long[2];
}
/**
* Get the time the very last stored message was sent
*
* @return the last message's time
*/
public Long getLastMessageTime() {
return getMessageTime(0) == null ? -1 : getMessageTime(0);
}
/**
* Get the time the very last stored command was sent
*
* @return the last command's time
*/
public Long getLastCommandTime() {
return getCommandTime(0) == null ? -1 : getCommandTime(0);
}
private List<Group> getLevels() {
return config.getGroups().getGroups();
}
private boolean silentMode() {
return config.getConfig().silentMode.getValue();
}
public void setIsWaitingOnLevelSync(boolean b) {
this.isWaitingOnLevelSync = b;
}
public boolean isWaitingOnLevelSync() {
return isWaitingOnLevelSync;
}
public void setLevelSyncTimestamp(Timestamp timestamp) {
levelSyncTimestamp = timestamp;
}
public Timestamp getLevelSyncTimestamp() {
return levelSyncTimestamp;
}
@Override
public String toString() {
return "User {name = " + getName() + ", level = " + level + "}";
}
}
@@ -1,575 +0,0 @@
/*
* AntiCheat for Bukkit.
* Copyright (C) 2012-2014 AntiCheat Team | http://gravitydevelopment.net
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.gravitydevelopment.anticheat.util;
import net.gravitydevelopment.anticheat.AntiCheat;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.NumberConversions;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public final class Utilities {
private static final List<Material> INSTANT_BREAK = new ArrayList<Material>();
private static final List<Material> FOOD = new ArrayList<Material>();
private static final List<Material> INTERACTABLE = new ArrayList<Material>();
private static final Map<Material, Material> COMBO = new HashMap<Material, Material>();
public static final String SPY_METADATA = "ac-spydata";
/**
* Send a hack level alert to players and console
*
* @param message List of strings to send as the alert
*/
public static void alert(List<String> message) {
for (Player player : Bukkit.getOnlinePlayers()) {
if (Permission.SYSTEM_ALERT.get(player)) {
for (String msg : message) {
player.sendMessage(msg);
}
}
}
for (String msg : message) {
AntiCheat.getManager().log(msg);
}
}
/**
* Check if only the block beneath them is standable (includes water + lava)
* @param block the block to check (under)
* @return true if they cannot stand there
*/
public static boolean cantStandAtSingle(Block block)
{
// TODO: Implement Better to reduce false positives (done? lets test...)
Block otherBlock = block.getLocation().add(0, -0.5, 0).getBlock();
boolean center = otherBlock.getType() == Material.AIR;
return center;
}
/**
* Determine whether a player cannot stand on or around the given block
*
* @param block the block to check
* @return true if the player should be unable to stand here
*/
public static boolean cantStandAt(Block block) {
return !canStand(block) && cantStandClose(block) && cantStandFar(block);
}
/**
* Determine whether a player should be unable to stand at a given location
*
* @param location the location to check
* @return true if the player should be unable to stand here
*/
public static boolean cantStandAtExp(Location location) {
return cantStandAt(new Location(location.getWorld(), fixXAxis(location.getX()), location.getY() - 0.01D, location.getBlockZ()).getBlock());
}
/**
* Determine whether cannot stand on the block's immediately surroundings (North, East, South, West)
*
* @param block the block to check
* @return true if a player cannot stand in the immediate vicinity
*/
public static boolean cantStandClose(Block block) {
return !canStand(block.getRelative(BlockFace.NORTH)) && !canStand(block.getRelative(BlockFace.EAST)) && !canStand(block.getRelative(BlockFace.SOUTH)) && !canStand(block.getRelative(BlockFace.WEST));
}
/**
* Determine whether cannot stand on the block's outer surroundings
*
* @param block the block to check
* @return true if a player cannot stand in areas further away from the block
*/
public static boolean cantStandFar(Block block) {
return !canStand(block.getRelative(BlockFace.NORTH_WEST)) && !canStand(block.getRelative(BlockFace.NORTH_EAST)) && !canStand(block.getRelative(BlockFace.SOUTH_WEST)) && !canStand(block.getRelative(BlockFace.SOUTH_EAST));
}
/**
* Determine whether a player can stand on the given block
*
* @param block the block to check
* @return true if the player can stand here
*/
public static boolean canStand(Block block) {
return !(block.isLiquid() || block.getType() == Material.AIR);
}
/**
* Determine whether a player is fully submerged in water
*
* @param player the player's location
* @return true if the player is fully in the water
*/
public static boolean isFullyInWater(Location player) {
double touchedX = fixXAxis(player.getX());
// Yes, this doesn't make sense, but it's supposed to fix some false positives in water walk.
// Think of it as 2 negatives = a positive :)
if (!(new Location(player.getWorld(), touchedX, player.getY(), player.getBlockZ()).getBlock()).isLiquid() && !(new Location(player.getWorld(), touchedX, Math.round(player.getY()), player.getBlockZ()).getBlock()).isLiquid()) {
return true;
}
return (new Location(player.getWorld(), touchedX, player.getY(), player.getBlockZ()).getBlock()).isLiquid() && (new Location(player.getWorld(), touchedX, Math.round(player.getY()), player.getBlockZ()).getBlock()).isLiquid();
}
/**
* Fixes a player's X position to determine the block they are on, even if they're on the edge
*
* @param x player's x position
* @return fixed x position
*/
public static double fixXAxis(double x) {
/* For Z axis, just use Math.round(xaxis); */
double touchedX = x;
double rem = touchedX - Math.round(touchedX) + 0.01D;
if (rem < 0.30D) {
touchedX = NumberConversions.floor(x) - 1;
}
return touchedX;
}
/**
* Determine if the player is hovering over water with the given limit
*
* @param player the player's location
* @param blocks max blocks to check
* @return true if the player is hovering over water
*/
public static boolean isHoveringOverWater(Location player, int blocks) {
for (int i = player.getBlockY(); i > player.getBlockY() - blocks; i--) {
Block newloc = (new Location(player.getWorld(), player.getBlockX(), i, player.getBlockZ())).getBlock();
if (newloc.getType() != Material.AIR) {
return newloc.isLiquid();
}
}
return false;
}
/**
* Determine if the player is hovering over water with a hard limit of 25 blocks
*
* @param player the player's location
* @return true if the player is hovering over water
*/
public static boolean isHoveringOverWater(Location player) {
return isHoveringOverWater(player, 25);
}
/**
* Determine whether a material will break instantly when hit
*
* @param m the material to check
* @return true if the material is instant break
*/
public static boolean isInstantBreak(Material m) {
return INSTANT_BREAK.contains(m);
}
/**
* Determine whether a material is edible
*
* @param m the material to check
* @return true if the material is food
*/
public static boolean isFood(Material m) {
return FOOD.contains(m);
}
/**
* Determine whether a block is a slab
*
* @param block block to check
* @return true if slab
*/
public static boolean isSlab(Block block) {
Material type = block.getType();
switch (type) {
case STEP:
case DOUBLE_STEP:
case WOOD_STEP:
case WOOD_DOUBLE_STEP:
return true;
default:
return false;
}
}
/**
* Determine whether a block is a stair
*
* @param block block to check
* @return true if stair
*/
public static boolean isStair(Block block) {
Material type = block.getType();
switch (type) {
case WOOD_STAIRS:
case SPRUCE_WOOD_STAIRS:
case SMOOTH_STAIRS:
case SANDSTONE_STAIRS:
case QUARTZ_STAIRS:
case JUNGLE_WOOD_STAIRS:
case NETHER_BRICK_STAIRS:
case BIRCH_WOOD_STAIRS:
case COBBLESTONE_STAIRS:
return true;
default:
return false;
}
}
/**
* Determine whether a player can interact with this material
*
* @param m material to check
* @return true if interactable
*/
public static boolean isInteractable(Material m) {
return INTERACTABLE.contains(m);
}
/**
* Determine whether a player is sprinting or flying
*
* @param player player to check
* @return true if sprinting or flying
*/
public static boolean sprintFly(Player player) {
return player.isSprinting() || player.isFlying();
}
/**
* Determine whether a player is standing on a lily pad
*
* @param player player to check
* @return true if on lily pad
*/
public static boolean isOnLilyPad(Player player) {
Block block = player.getLocation().getBlock();
Material lily = Material.WATER_LILY;
// TODO: Can we fix X this?
return block.getType() == lily || block.getRelative(BlockFace.NORTH).getType() == lily || block.getRelative(BlockFace.SOUTH).getType() == lily || block.getRelative(BlockFace.EAST).getType() == lily || block.getRelative(BlockFace.WEST).getType() == lily;
}
/**
* Determine whether a player is fully submersed in liquid
*
* @param player player to check
* @return true if submersed
*/
public static boolean isSubmersed(Player player) {
return player.getLocation().getBlock().isLiquid() && player.getLocation().getBlock().getRelative(BlockFace.UP).isLiquid();
}
/**
* Determine whether a player is in water
*
* @param player player to check
* @return true if in water
*/
public static boolean isInWater(Player player) {
return player.getLocation().getBlock().isLiquid() || player.getLocation().getBlock().getRelative(BlockFace.DOWN).isLiquid() || player.getLocation().getBlock().getRelative(BlockFace.UP).isLiquid();
}
/**
* Determine whether a player is in a web
*
* @param player player to check
* @return true if in web
*/
public static boolean isInWeb(Player player) {
return player.getLocation().getBlock().getType() == Material.WEB || player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() == Material.WEB || player.getLocation().getBlock().getRelative(BlockFace.UP).getType() == Material.WEB;
}
/**
* Determine whether a block is climbable
*
* @param block block to check
* @return true if climbable
*/
public static boolean isClimbableBlock(Block block) {
return block.getType() == Material.VINE || block.getType() == Material.LADDER || block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER;
}
/**
* Determine whether a player is on a vine (can be free hanging)
*
* @param player to check
* @return true if on vine
*/
public static boolean isOnVine(Player player) {
return player.getLocation().getBlock().getType() == Material.VINE;
}
/**
* Determine whether a String can be cast to an Integer
*
* @param string text to check
* @return true if int
*/
public static boolean isInt(String string) {
try {
Integer.parseInt(string);
return true;
} catch (Exception ex) {
return false;
}
}
/**
* Determine whether a String can be cast to a Double
*
* @param string text to check
* @return true if double
*/
public static boolean isDouble(String string) {
try {
Double.parseDouble(string);
return true;
} catch (Exception ex) {
return false;
}
}
/**
* Calculate the time in milliseconds that it should take to break the given block with the given tool
*
* @param tool tool to check
* @param block block to check
* @return time in milliseconds to break
*/
public static long calcSurvivalFastBreak(ItemStack tool, Material block) {
if (isInstantBreak(block) || (tool.getType() == Material.SHEARS && block == Material.LEAVES)) {
return 0;
}
double bhardness = BlockHardness.getBlockHardness(block);
double thardness = ToolHardness.getToolHardness(tool.getType());
long enchantlvl = (long) tool.getEnchantmentLevel(Enchantment.DIG_SPEED);
long result = Math.round((bhardness * thardness) * 0.10 * 10000);
if (enchantlvl > 0) {
result /= enchantlvl * enchantlvl + 1L;
}
result = result > 25000 ? 25000 : result < 0 ? 0 : result;
if (isQuickCombo(tool, block)) {
result = result / 2;
}
return result;
}
/**
* Determine whether the given tool is a combination that makes the breaking of this block faster
*
* @param tool tool to check
* @param block block to check
* @return true if quick combo
*/
private static boolean isQuickCombo(ItemStack tool, Material block) {
for (Material t : COMBO.keySet()) {
if (tool.getType() == t && COMBO.get(t) == block) {
return true;
}
}
return false;
}
/**
* Determine if a block ISN'T one of the specified types
*
* @param block block to check
* @param materials array of possible materials
* @return true if the block isn't any of the materials
*/
public static boolean blockIsnt(Block block, Material[] materials) {
Material type = block.getType();
for (Material m : materials) {
if (m == type) {
return false;
}
}
return false;
}
/**
* Parse a COMMAND[] input to a set of commands to execute
*
* @param command input string
* @return parsed commands
*/
public static String[] getCommands(String command) {
return command.replaceAll("COMMAND\\[", "").replaceAll("]", "").split(";");
}
/**
* Remove all whitespace from the given string to ready it for parsing
*
* @param string the string to parse
* @return string with whitespace removed
*/
public static String removeWhitespace(String string) {
return string.replaceAll(" ", "");
}
/**
* Determine if a player has the given enchantment on their armor
*
* @param player player to check
* @param e enchantment to check
* @return true if the armor has this enchantment
*/
public static boolean hasArmorEnchantment(Player player, Enchantment e) {
for (ItemStack is : player.getInventory().getArmorContents()) {
if (is != null && is.containsEnchantment(e)) {
return true;
}
}
return false;
}
/**
* Create a list with the given string for execution
*
* @param string the string to parse
* @return ArrayList with string
*/
public static ArrayList<String> stringToList(final String string) {
return new ArrayList<String>() {{ add(string); }};
}
/**
* Create a comma-delimited string from a list
*
* @param list the list to parse
* @return the list in a string format
*/
public static String listToCommaString(List<String> list) {
StringBuilder b = new StringBuilder();
for (int i = 0; i < list.size(); i++) {
b.append(list.get(i));
if (i < list.size() - 1) {
b.append(",");
}
}
return b.toString();
}
/**
* Parse a string in the format of "XdXhXmXs" to seconds
* @param string The string to parse
* @return seconds
*/
public static long lifeToSeconds(String string) {
if (string.equals("0") || string.equals("")) return 0;
String[] lifeMatch = new String[]{ "d", "h", "m", "s" };
int[] lifeInterval = new int[]{ 86400, 3600, 60, 1 };
long seconds = 0L;
for (int i=0;i<lifeMatch.length;i++) {
Matcher matcher = Pattern.compile("([0-9]*)" + lifeMatch[i]).matcher(string);
while (matcher.find()) {
seconds += Integer.parseInt(matcher.group(1)) * lifeInterval[i];
}
}
return seconds;
}
static {
// START INSTANT BREAK MATERIALS
INSTANT_BREAK.add(Material.RED_MUSHROOM);
INSTANT_BREAK.add(Material.RED_ROSE);
INSTANT_BREAK.add(Material.BROWN_MUSHROOM);
INSTANT_BREAK.add(Material.YELLOW_FLOWER);
INSTANT_BREAK.add(Material.REDSTONE);
INSTANT_BREAK.add(Material.REDSTONE_TORCH_OFF);
INSTANT_BREAK.add(Material.REDSTONE_TORCH_ON);
INSTANT_BREAK.add(Material.REDSTONE_WIRE);
INSTANT_BREAK.add(Material.LONG_GRASS);
INSTANT_BREAK.add(Material.PAINTING);
INSTANT_BREAK.add(Material.WHEAT);
INSTANT_BREAK.add(Material.SUGAR_CANE);
INSTANT_BREAK.add(Material.SUGAR_CANE_BLOCK);
INSTANT_BREAK.add(Material.DIODE);
INSTANT_BREAK.add(Material.DIODE_BLOCK_OFF);
INSTANT_BREAK.add(Material.DIODE_BLOCK_ON);
INSTANT_BREAK.add(Material.SAPLING);
INSTANT_BREAK.add(Material.TORCH);
INSTANT_BREAK.add(Material.CROPS);
INSTANT_BREAK.add(Material.SNOW);
INSTANT_BREAK.add(Material.TNT);
INSTANT_BREAK.add(Material.POTATO);
INSTANT_BREAK.add(Material.CARROT);
// END INSTANT BREAK MATERIALS
// START INTERACTABLE MATERIALS
INTERACTABLE.add(Material.STONE_BUTTON);
INTERACTABLE.add(Material.LEVER);
INTERACTABLE.add(Material.CHEST);
// END INTERACTABLE MATERIALS
// START FOOD
FOOD.add(Material.COOKED_BEEF);
FOOD.add(Material.COOKED_CHICKEN);
FOOD.add(Material.COOKED_FISH);
FOOD.add(Material.GRILLED_PORK);
FOOD.add(Material.PORK);
FOOD.add(Material.MUSHROOM_SOUP);
FOOD.add(Material.RAW_BEEF);
FOOD.add(Material.RAW_CHICKEN);
FOOD.add(Material.RAW_FISH);
FOOD.add(Material.APPLE);
FOOD.add(Material.GOLDEN_APPLE);
FOOD.add(Material.MELON);
FOOD.add(Material.COOKIE);
FOOD.add(Material.BREAD);
FOOD.add(Material.SPIDER_EYE);
FOOD.add(Material.ROTTEN_FLESH);
FOOD.add(Material.POTATO_ITEM);
// END FOOD
// START COMBOS
COMBO.put(Material.SHEARS, Material.WOOL);
COMBO.put(Material.IRON_SWORD, Material.WEB);
COMBO.put(Material.DIAMOND_SWORD, Material.WEB);
COMBO.put(Material.STONE_SWORD, Material.WEB);
COMBO.put(Material.WOOD_SWORD, Material.WEB);
// END COMBOS
}
}
@@ -1,20 +0,0 @@
package net.gravitydevelopment.anticheat.util;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class VersionUtil {
public static String getVersion() {
return Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
}
public static boolean isFlying(Player p) {
if (getVersion().equals("v1_8_R3")) {
return p.isFlying();
}else {
return p.isFlying() || p.isGliding();
}
}
}
-2
View File
@@ -15,8 +15,6 @@ spam:
action-one: KICK action-one: KICK
action-two: BAN action-two: BAN
system: system:
# Turning auto-update off is a _BAD_ idea. You will no longer be protected by the latest hacks/cheats if you do so, and will have to update manually.
auto-update: true
# Should AntiCheatReloaded log ALL failed checks to console? # Should AntiCheatReloaded log ALL failed checks to console?
log-to-console: false log-to-console: false
# Should AntiCheatReloaded log to file? # Should AntiCheatReloaded log to file?
+1 -1
View File
@@ -17,7 +17,7 @@ database:
# Password for the user # Password for the user
password: '' password: ''
# Prefix for the tables # Prefix for the tables
prefix: 'ac_' prefix: 'acr_'
# Database/Schema to use # Database/Schema to use
database: 'anticheat' database: 'anticheat'
# Logging settings # Logging settings
+13 -5
View File
@@ -1,4 +1,9 @@
# AntiCheatReloaded configuration file # AntiCheatReloaded configuration file
#
# This file is not yet fully documented
# For more information on the undocumented values visit:
# https://github.com/Rammelkast/AntiCheatReloaded/blob/master/src/main/java/com/rammelkast/anticheatreloaded/config/providers/Magic.java#L39-L380
#
ANIMATION_INTERACT_MAX: 3 ANIMATION_INTERACT_MAX: 3
ANIMATION_MIN: 200 ANIMATION_MIN: 200
ASCENSION_COUNT_MAX: 8 ASCENSION_COUNT_MAX: 8
@@ -40,7 +45,6 @@ FASTPLACE_TIMEMIN: 50
FASTPLACE_ZEROLIMIT: 3 FASTPLACE_ZEROLIMIT: 3
FLIGHT_BLOCK_LIMIT: 15.0 FLIGHT_BLOCK_LIMIT: 15.0
FLIGHT_LIMIT: 150 FLIGHT_LIMIT: 150
HEAL_TIME_MIN: 2000
INSTANT_BREAK_TIME: 2 INSTANT_BREAK_TIME: 2
INVENTORY_CHECK: 10 INVENTORY_CHECK: 10
INVENTORY_TIMEMIN: 50 INVENTORY_TIMEMIN: 50
@@ -81,10 +85,14 @@ XZ_SPEED_MAX_WATER_SPRINT: 0.3
Y_MAXDIFF: 5.0 Y_MAXDIFF: 5.0
Y_MAXVIOLATIONS: 1 Y_MAXVIOLATIONS: 1
Y_MAXVIOTIME: 5500 Y_MAXVIOTIME: 5500
Y_SPEED_MAX: 0.5125 Y_SPEED_MAX: 0.5175
Y_TIME: 800 Y_TIME: 800
# Amount of suspicious mid-air movements before a player is suspected of glide
# Increase this in case of false positives
GLIDE_LIMIT: 10 GLIDE_LIMIT: 10
GLIDE_MAX: -3.75 # Maximum amount of movement packets allowed per second
KILLAURA_BOTHITS: 5 # Increase this in case of false positives
BLINK_PACKET: 75 BLINK_PACKET: 25
# Maximum amount zero-velocity moments before a player is suspected
# Increase this in case of false positives
VELOCITY_AMT: 5 VELOCITY_AMT: 5
+24 -8
View File
@@ -1,16 +1,16 @@
name: AntiCheatReloaded name: AntiCheatReloaded
author: Rammelkast author: Rammelkast
description: AntiCheatReloaded helps easily identify and block malicious users on your server. description: AntiCheatReloaded helps easily identify and block malicious users on your server.
main: net.gravitydevelopment.anticheat.AntiCheat main: com.rammelkast.anticheatreloaded.AntiCheatReloaded
softdepend: [ProtocolLib] api-version: 1.13
depend: [ProtocolLib]
startup: postworld startup: postworld
url: http://gravitydevelopment.net
version: ${project.build.version} version: ${project.build.version}
commands: commands:
anticheat: anticheat:
description: Control and view info about AntiCheat description: Control and view info about AntiCheatReloaded
usage: /anticheat help usage: /anticheat help
aliases: anti aliases: acr
permissions: permissions:
anticheat.system.notice: anticheat.system.notice:
description: See broadcasts when a player is kicked or banned for hacking description: See broadcasts when a player is kicked or banned for hacking
@@ -61,9 +61,12 @@ permissions:
anticheat.check.zombe.cheat: anticheat.check.zombe.cheat:
description: Allow players to use zombe cheat hack description: Allow players to use zombe cheat hack
default: false default: false
anticheat.check.fly: anticheat.check.flight:
description: Allow players to fly description: Allow players to fly
default: false default: false
anticheat.check.elytra:
description: Allow players to fly when using elytra
default: false
anticheat.check.waterwalk: anticheat.check.waterwalk:
description: Allow players to walk on water description: Allow players to walk on water
default: false default: false
@@ -127,8 +130,17 @@ permissions:
anticheat.check.autotool: anticheat.check.autotool:
description: Allow players to use autotool to switch tools quickly description: Allow players to use autotool to switch tools quickly
default: false default: false
anticheat.check.fastanimation: anticheat.check.blink:
description: Allow players to attack or interact very quickly description: Allow players to send lots of movement packets
default: false
anticheat.check.velocity:
description: Allow players to use knockback prevention
default: false
anticheat.check.criticals:
description: Allow players to use criticals
default: false
anticheat.check.unicode:
description: Allow players to use unicode in chat
default: false default: false
anticheat.check.exempt: anticheat.check.exempt:
description: Total exemption from checks description: Total exemption from checks
@@ -160,3 +172,7 @@ permissions:
anticheat.check.fastinventory: true anticheat.check.fastinventory: true
anticheat.check.autotool: true anticheat.check.autotool: true
anticheat.check.fastanimation: true anticheat.check.fastanimation: true
anticheat.check.blink: true
anticheat.check.velocity: true
anticheat.check.criticals: true
anticheat.check.unicode: true