added files.
This commit is contained in:
commit
8aa2a15c64
124 files changed
+14297
No files matched your search
+10
@@ -0,0 +1,10 @@
|
||||
.gradle/
|
||||
build/
|
||||
out/
|
||||
.idea/
|
||||
*.iml
|
||||
.classpath
|
||||
.project
|
||||
.settings/
|
||||
TEST*.jar
|
||||
DeobfMe-*.jar
|
||||
@@ -0,0 +1,61 @@
|
||||
<p align="center">
|
||||
<img src="assets/ss.png" alt="Skid Solutions Banner" width="350" />
|
||||
<br><br>
|
||||
<a href="https://discord.gg/skidsolutions">
|
||||
<img src="https://img.shields.io/badge/Discord-Skid%20Solutions-18181b?style=for-the-badge&logo=discord&logoColor=ffffff&labelColor=09090b" alt="Discord" />
|
||||
</a>
|
||||
<img src="https://img.shields.io/badge/Version-2.1.1-27272a?style=for-the-badge&labelColor=09090b" alt="Version 2.1.1" />
|
||||
<img src="https://img.shields.io/badge/Java-17-3f3f46?style=for-the-badge&logo=openjdk&logoColor=ffffff&labelColor=09090b" alt="Java 17" />
|
||||
<img src="https://img.shields.io/badge/Gradle-8.14.3-52525b?style=for-the-badge&logo=gradle&logoColor=ffffff&labelColor=09090b" alt="Gradle 8.14.3" />
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://discord.gg/skidsolutions">https://discord.gg/skidsolutions</a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<img src="assets/divider.svg" alt="" width="720" />
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<img src="assets/jak.jpg" alt="jak" height="150" />
|
||||
<img src="assets/hack.jpg" alt="hack" height="150" />
|
||||
<img src="assets/deobf2.png" alt="deobf2" height="150" />
|
||||
<img src="assets/deobf.jpg" alt="deobf" height="150" />
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<sub>This is NOT a recreation nor a remake.</sub>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<img src="assets/divider.svg" alt="" width="720" />
|
||||
</p>
|
||||
|
||||
## How to build
|
||||
|
||||
### Prerequisites
|
||||
- **Java Development Kit**: JDK 17 (the Gradle wrapper 8.14.3 does not run on newer JDKs)
|
||||
|
||||
### Building OpenAAC2
|
||||
|
||||
Run from this folder:
|
||||
|
||||
```powershell
|
||||
$env:JAVA_HOME = "C:\Program Files\Java\jdk-17"
|
||||
|
||||
.\gradlew.bat clean prepareIde build
|
||||
```
|
||||
|
||||
Generated `build/libs/`:
|
||||
- `AAC2-2.1.1-java17.jar`
|
||||
- `AAC2-2.1.1-plain.jar`
|
||||
- `AAC2-2.1.1-sources.jar`
|
||||
|
||||
### Usage
|
||||
|
||||
Place `build/libs/AAC2-2.1.1-java17.jar` alongside **ProtocolLib** in your Spigot `1.10` server's `plugins/` directory.
|
||||
|
||||
## Credits
|
||||
|
||||
- **konsolas** - Original author of AAC 2.1.1.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 76 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 135 KiB |
@@ -0,0 +1,26 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 820 20" width="820" height="20" role="img" aria-hidden="true">
|
||||
<defs>
|
||||
<linearGradient id="baseLine" x1="0%" y1="0%" x2="100%" y2="0%">
|
||||
<stop offset="0%" stop-color="#000000" stop-opacity="0" />
|
||||
<stop offset="25%" stop-color="#404040" stop-opacity="0.7" />
|
||||
<stop offset="50%" stop-color="#d4d4d4" stop-opacity="0.95" />
|
||||
<stop offset="75%" stop-color="#404040" stop-opacity="0.7" />
|
||||
<stop offset="100%" stop-color="#000000" stop-opacity="0" />
|
||||
</linearGradient>
|
||||
<linearGradient id="pulse" x1="0%" y1="0%" x2="100%" y2="0%">
|
||||
<stop offset="0%" stop-color="#ffffff" stop-opacity="0" />
|
||||
<stop offset="50%" stop-color="#ffffff" stop-opacity="1" />
|
||||
<stop offset="100%" stop-color="#ffffff" stop-opacity="0" />
|
||||
</linearGradient>
|
||||
<clipPath id="lineClip">
|
||||
<rect x="40" y="8" width="740" height="4" rx="2" />
|
||||
</clipPath>
|
||||
</defs>
|
||||
|
||||
<rect x="40" y="9.25" width="740" height="1.5" rx="0.75" fill="url(#baseLine)" />
|
||||
<g clip-path="url(#lineClip)">
|
||||
<rect x="-120" y="8.5" width="140" height="3" rx="1.5" fill="url(#pulse)">
|
||||
<animate attributeName="x" values="-120;820" dur="3.4s" repeatCount="indefinite" />
|
||||
</rect>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.0 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 323 KiB |
+119
@@ -0,0 +1,119 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'idea'
|
||||
id 'eclipse'
|
||||
id 'com.gradleup.shadow' version '8.3.8'
|
||||
}
|
||||
|
||||
group = 'me.konsolas.aac'
|
||||
version = '2.1.1'
|
||||
|
||||
def javaVersion = 17
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url = uri('https://hub.spigotmc.org/nexus/content/repositories/snapshots/') }
|
||||
}
|
||||
|
||||
configurations {
|
||||
apiGenerator
|
||||
}
|
||||
|
||||
def generatorClasses = layout.buildDirectory.dir('api-generator/classes')
|
||||
tasks.register('compileApiGenerator', JavaCompile) {
|
||||
source = files('gradle/GenerateCompileApis.java')
|
||||
classpath = configurations.apiGenerator
|
||||
destinationDirectory = generatorClasses
|
||||
javaCompiler = javaToolchains.compilerFor { languageVersion = JavaLanguageVersion.of(javaVersion) }
|
||||
options.release = javaVersion
|
||||
options.encoding = 'UTF-8'
|
||||
}
|
||||
tasks.register('generateCompileApis', JavaExec) {
|
||||
group = 'build setup'
|
||||
description = 'Generates compile-only API headers from text declarations.'
|
||||
dependsOn tasks.named('compileApiGenerator')
|
||||
inputs.dir('gradle/api-signatures')
|
||||
outputs.dir(layout.buildDirectory.dir('compile-apis'))
|
||||
classpath = files(generatorClasses) + configurations.apiGenerator
|
||||
javaLauncher = javaToolchains.launcherFor { languageVersion = JavaLanguageVersion.of(javaVersion) }
|
||||
mainClass = 'GenerateCompileApis'
|
||||
maxHeapSize = '2g'
|
||||
args file('gradle/api-signatures').absolutePath, layout.buildDirectory.dir('compile-apis').get().asFile.absolutePath
|
||||
}
|
||||
def compileApi = { String name ->
|
||||
files(layout.buildDirectory.file("compile-apis/${name}.jar")).builtBy(tasks.named('generateCompileApis'))
|
||||
}
|
||||
tasks.register('prepareIde') {
|
||||
group = 'ide'
|
||||
description = 'Generates the compile-only API headers used by the IDE import.'
|
||||
dependsOn tasks.named('generateCompileApis')
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain.languageVersion = JavaLanguageVersion.of(javaVersion)
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
apiGenerator 'org.ow2.asm:asm:9.8'
|
||||
apiGenerator 'com.google.code.gson:gson:2.10.1'
|
||||
|
||||
implementation 'net.jodah:expiringmap:0.5.5'
|
||||
|
||||
compileOnly compileApi('aac2')
|
||||
compileOnly 'com.google.guava:guava:21.0'
|
||||
compileOnly 'com.google.code.gson:gson:2.8.9'
|
||||
compileOnly 'org.yaml:snakeyaml:1.27'
|
||||
compileOnly 'commons-lang:commons-lang:2.6'
|
||||
compileOnly 'com.googlecode.json-simple:json-simple:1.1.1'
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
if (name != 'compileApiGenerator') {
|
||||
dependsOn tasks.named('generateCompileApis')
|
||||
}
|
||||
options.release = javaVersion
|
||||
options.encoding = 'UTF-8'
|
||||
options.compilerArgs += ['-parameters', '-Xmaxerrs', '1500']
|
||||
options.debug = true
|
||||
options.debugOptions.debugLevel = 'source,lines,vars'
|
||||
}
|
||||
|
||||
tasks.withType(AbstractArchiveTask).configureEach {
|
||||
preserveFileTimestamps = false
|
||||
reproducibleFileOrder = true
|
||||
filePermissions { unix('0644') }
|
||||
dirPermissions { unix('0755') }
|
||||
}
|
||||
|
||||
jar {
|
||||
archiveClassifier = 'plain'
|
||||
manifest.attributes('Implementation-Title': 'AAC', 'Implementation-Version': project.version)
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
archiveClassifier = 'java17'
|
||||
relocate 'net.jodah.expiringmap', 'me.konsolas.aac.lib.expiringmap'
|
||||
minimize()
|
||||
mergeServiceFiles()
|
||||
exclude 'META-INF/*.SF', 'META-INF/*.RSA', 'META-INF/*.DSA'
|
||||
exclude 'META-INF/INDEX.LIST', 'META-INF/maven/**'
|
||||
exclude 'META-INF/LICENSE', 'META-INF/LICENSE.txt', 'META-INF/NOTICE', 'META-INF/NOTICE.txt'
|
||||
manifest.attributes('Implementation-Title': 'AAC', 'Implementation-Version': project.version)
|
||||
}
|
||||
|
||||
assemble.dependsOn shadowJar
|
||||
|
||||
idea {
|
||||
module {
|
||||
downloadSources = true
|
||||
downloadJavadoc = true
|
||||
}
|
||||
}
|
||||
|
||||
eclipse {
|
||||
classpath {
|
||||
downloadSources = true
|
||||
downloadJavadoc = true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
org.gradle.jvmargs=-Xmx3g -Dfile.encoding=UTF-8
|
||||
org.gradle.workers.max=2
|
||||
org.gradle.parallel=false
|
||||
@@ -0,0 +1,66 @@
|
||||
import com.google.gson.*;
|
||||
import org.objectweb.asm.*;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import java.util.jar.*;
|
||||
|
||||
public final class GenerateCompileApis implements Opcodes {
|
||||
static String text(JsonObject o,String k){return o.has(k)&&!o.get(k).isJsonNull()?o.get(k).getAsString():null;}
|
||||
static int number(JsonObject o,String k){return o.get(k).getAsInt();}
|
||||
static JsonArray array(JsonObject o,String k){return o.has(k)?o.getAsJsonArray(k):new JsonArray();}
|
||||
static String[] strings(JsonObject o,String k){List<String> r=new ArrayList<>();for(JsonElement e:array(o,k))r.add(e.getAsString());return r.toArray(new String[0]);}
|
||||
static Object scalar(JsonObject o){String v=text(o,"value");return switch(text(o,"type")){
|
||||
case "Long"->Long.valueOf(v);case "Integer"->Integer.valueOf(v);case "Float"->Float.valueOf(v);case "Double"->Double.valueOf(v);case "Byte"->Byte.valueOf(v);case "Short"->Short.valueOf(v);case "Character"->v.charAt(0);default->throw new IllegalArgumentException(o.toString());};}
|
||||
static Object constant(JsonElement e){if(e==null||e.isJsonNull())return null;if(e.isJsonObject())return scalar(e.getAsJsonObject());return e.getAsString();}
|
||||
static void annotationValue(AnnotationVisitor visitor,String name,JsonElement value){
|
||||
if(value.isJsonArray()){AnnotationVisitor nested=visitor.visitArray(name);for(JsonElement e:value.getAsJsonArray())annotationValue(nested,null,e);nested.visitEnd();}
|
||||
else if(value.isJsonObject()){JsonObject o=value.getAsJsonObject();switch(text(o,"kind")){
|
||||
case "scalar"->visitor.visit(name,scalar(o));case "type"->visitor.visit(name,Type.getType(text(o,"descriptor")));
|
||||
case "enum"->visitor.visitEnum(name,text(o,"descriptor"),text(o,"name"));
|
||||
case "annotation"->{JsonObject a=o.getAsJsonObject("annotation");writeAnnotation(visitor.visitAnnotation(name,text(a,"descriptor")),a);}
|
||||
default->throw new IllegalArgumentException(o.toString());}}
|
||||
else if(value.getAsJsonPrimitive().isBoolean())visitor.visit(name,value.getAsBoolean());
|
||||
else visitor.visit(name,value.getAsString());
|
||||
}
|
||||
static void writeAnnotation(AnnotationVisitor visitor,JsonObject annotation){if(visitor==null)return;for(var e:annotation.getAsJsonObject("values").entrySet())annotationValue(visitor,e.getKey(),e.getValue());visitor.visitEnd();}
|
||||
interface Factory {AnnotationVisitor create(JsonObject annotation);}
|
||||
static void annotations(JsonObject o,String key,Factory factory){for(JsonElement a:array(o,key)){JsonObject obj=a.getAsJsonObject();writeAnnotation(factory.create(obj),obj);}}
|
||||
static TypePath path(JsonObject o){return TypePath.fromString(text(o,"typePath"));}
|
||||
static byte[] compile(JsonObject c){
|
||||
ClassWriter cw=new ClassWriter(0);cw.visit(number(c,"version"),number(c,"access"),text(c,"name"),text(c,"signature"),text(c,"superName"),strings(c,"interfaces"));
|
||||
if(c.has("outerClass"))cw.visitOuterClass(text(c,"outerClass"),text(c,"outerMethod"),text(c,"outerMethodDescriptor"));
|
||||
if(c.has("nestHostClass"))cw.visitNestHost(text(c,"nestHostClass"));
|
||||
for(String n:strings(c,"nestMembers"))cw.visitNestMember(n);for(String n:strings(c,"permittedSubclasses"))cw.visitPermittedSubclass(n);
|
||||
annotations(c,"annotations",a->cw.visitAnnotation(text(a,"descriptor"),a.get("visible").getAsBoolean()));
|
||||
annotations(c,"typeAnnotations",a->cw.visitTypeAnnotation(number(a,"typeRef"),path(a),text(a,"descriptor"),a.get("visible").getAsBoolean()));
|
||||
for(JsonElement el:array(c,"innerClasses")){var n=el.getAsJsonObject();cw.visitInnerClass(text(n,"name"),text(n,"outerName"),text(n,"innerName"),number(n,"access"));}
|
||||
for(JsonElement el:array(c,"recordComponents")){var r=el.getAsJsonObject();var rv=cw.visitRecordComponent(text(r,"name"),text(r,"descriptor"),text(r,"signature"));annotations(r,"annotations",a->rv.visitAnnotation(text(a,"descriptor"),a.get("visible").getAsBoolean()));annotations(r,"typeAnnotations",a->rv.visitTypeAnnotation(number(a,"typeRef"),path(a),text(a,"descriptor"),a.get("visible").getAsBoolean()));rv.visitEnd();}
|
||||
for(JsonElement el:array(c,"fields")){var f=el.getAsJsonObject();var fv=cw.visitField(number(f,"access"),text(f,"name"),text(f,"descriptor"),text(f,"signature"),constant(f.get("constant")));annotations(f,"annotations",a->fv.visitAnnotation(text(a,"descriptor"),a.get("visible").getAsBoolean()));annotations(f,"typeAnnotations",a->fv.visitTypeAnnotation(number(a,"typeRef"),path(a),text(a,"descriptor"),a.get("visible").getAsBoolean()));fv.visitEnd();}
|
||||
for(JsonElement el:array(c,"methods")){var m=el.getAsJsonObject();int access=number(m,"access");String descriptor=text(m,"descriptor");var mv=cw.visitMethod(access,text(m,"name"),descriptor,text(m,"signature"),strings(m,"exceptions"));
|
||||
for(JsonElement pe:array(m,"parameters")){var p=pe.getAsJsonObject();mv.visitParameter(text(p,"name"),number(p,"access"));}
|
||||
annotations(m,"annotations",a->mv.visitAnnotation(text(a,"descriptor"),a.get("visible").getAsBoolean()));annotations(m,"typeAnnotations",a->mv.visitTypeAnnotation(number(a,"typeRef"),path(a),text(a,"descriptor"),a.get("visible").getAsBoolean()));
|
||||
annotations(m,"parameterAnnotations",a->mv.visitParameterAnnotation(number(a,"parameter"),text(a,"descriptor"),a.get("visible").getAsBoolean()));
|
||||
if(m.has("annotationDefault")){var av=mv.visitAnnotationDefault();annotationValue(av,null,m.get("annotationDefault"));av.visitEnd();}
|
||||
if((access&(ACC_ABSTRACT|ACC_NATIVE))==0){mv.visitCode();mv.visitTypeInsn(NEW,"java/lang/UnsupportedOperationException");mv.visitInsn(DUP);mv.visitLdcInsn("Compile-only API header; use the real server or library at runtime");mv.visitMethodInsn(INVOKESPECIAL,"java/lang/UnsupportedOperationException","<init>","(Ljava/lang/String;)V",false);mv.visitInsn(ATHROW);int locals=(access&ACC_STATIC)==0?1:0;for(Type t:Type.getArgumentTypes(descriptor))locals+=t.getSize();mv.visitMaxs(3,locals);}
|
||||
mv.visitEnd();}
|
||||
cw.visitEnd();return cw.toByteArray();
|
||||
}
|
||||
static SortedMap<String,JsonObject> declarations(Path input,Path schema,Set<Path> active)throws Exception {
|
||||
if(!active.add(schema))throw new IllegalArgumentException("Cyclic API declaration inheritance: "+schema);
|
||||
JsonObject data;try(Reader r=Files.newBufferedReader(schema)){data=JsonParser.parseReader(r).getAsJsonObject();}
|
||||
SortedMap<String,JsonObject> classes=new TreeMap<>();
|
||||
if(data.has("base"))classes.putAll(declarations(input,input.resolve(text(data,"base")+".json"),active));
|
||||
for(JsonElement entry:array(data,"classes")){JsonObject c=entry.getAsJsonObject();classes.put(text(c,"name"),c);}
|
||||
active.remove(schema);return classes;
|
||||
}
|
||||
public static void main(String[] args)throws Exception{
|
||||
Path input=Path.of(args[0]),output=Path.of(args[1]);Files.createDirectories(output);
|
||||
for(Path schema:Files.list(input).filter(p->p.toString().endsWith(".json")).sorted().toList()){
|
||||
SortedMap<String,JsonObject> classes=declarations(input,schema,new HashSet<>());
|
||||
String name=schema.getFileName().toString().replace(".json",".jar");Path jar=output.resolve(name);
|
||||
try(var out=new JarOutputStream(Files.newOutputStream(jar))){for(JsonObject c:classes.values()){var entry=new JarEntry(text(c,"name")+".class");entry.setTime(0);out.putNextEntry(entry);out.write(compile(c));out.closeEntry();}}
|
||||
System.out.println("Generated compile API "+name+" ("+classes.size()+" declarations)");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"classes":[{"name":"com/comphenix/protocol/AsynchronousManager","version":52,"access":1537,"superName":"java/lang/Object","methods":[{"name":"registerAsyncHandler","access":1025,"descriptor":"(Lcom/comphenix/protocol/events/PacketListener;)Lcom/comphenix/protocol/async/AsyncListenerHandler;"},{"name":"unregisterAsyncHandler","access":1025,"descriptor":"(Lcom/comphenix/protocol/async/AsyncListenerHandler;)V"},{"name":"unregisterAsyncHandler","access":1025,"descriptor":"(Lcom/comphenix/protocol/events/PacketListener;)V"},{"name":"unregisterAsyncHandlers","access":1025,"descriptor":"(Lorg/bukkit/plugin/Plugin;)V"},{"name":"getSendingFilters","access":132097,"descriptor":"()Ljava/util/Set;","signature":"()Ljava/util/Set<Ljava/lang/Integer;>;","annotations":[{"descriptor":"Ljava/lang/Deprecated;","visible":true,"values":{}}]},{"name":"getSendingTypes","access":1025,"descriptor":"()Ljava/util/Set;","signature":"()Ljava/util/Set<Lcom/comphenix/protocol/PacketType;>;"},{"name":"getReceivingFilters","access":132097,"descriptor":"()Ljava/util/Set;","signature":"()Ljava/util/Set<Ljava/lang/Integer;>;","annotations":[{"descriptor":"Ljava/lang/Deprecated;","visible":true,"values":{}}]},{"name":"getReceivingTypes","access":1025,"descriptor":"()Ljava/util/Set;","signature":"()Ljava/util/Set<Lcom/comphenix/protocol/PacketType;>;"},{"name":"hasAsynchronousListeners","access":1025,"descriptor":"(Lcom/comphenix/protocol/events/PacketEvent;)Z"},{"name":"getPacketStream","access":1025,"descriptor":"()Lcom/comphenix/protocol/PacketStream;"},{"name":"getErrorReporter","access":1025,"descriptor":"()Lcom/comphenix/protocol/error/ErrorReporter;"},{"name":"cleanupAll","access":1025,"descriptor":"()V"},{"name":"signalPacketTransmission","access":1025,"descriptor":"(Lcom/comphenix/protocol/events/PacketEvent;)V"},{"name":"registerTimeoutHandler","access":1025,"descriptor":"(Lcom/comphenix/protocol/events/PacketListener;)V"},{"name":"unregisterTimeoutHandler","access":1025,"descriptor":"(Lcom/comphenix/protocol/events/PacketListener;)V"},{"name":"getTimeoutHandlers","access":1025,"descriptor":"()Ljava/util/Set;","signature":"()Ljava/util/Set<Lcom/comphenix/protocol/events/PacketListener;>;"},{"name":"getAsyncHandlers","access":1025,"descriptor":"()Ljava/util/Set;","signature":"()Ljava/util/Set<Lcom/comphenix/protocol/events/PacketListener;>;"}]},{"name":"com/comphenix/protocol/PacketStream","version":52,"access":1537,"superName":"java/lang/Object","methods":[{"name":"sendServerPacket","access":1025,"descriptor":"(Lorg/bukkit/entity/Player;Lcom/comphenix/protocol/events/PacketContainer;)V","exceptions":["java/lang/reflect/InvocationTargetException"]},{"name":"sendServerPacket","access":1025,"descriptor":"(Lorg/bukkit/entity/Player;Lcom/comphenix/protocol/events/PacketContainer;Z)V","exceptions":["java/lang/reflect/InvocationTargetException"]},{"name":"sendServerPacket","access":1025,"descriptor":"(Lorg/bukkit/entity/Player;Lcom/comphenix/protocol/events/PacketContainer;Lcom/comphenix/protocol/events/NetworkMarker;Z)V","exceptions":["java/lang/reflect/InvocationTargetException"]},{"name":"sendWirePacket","access":1025,"descriptor":"(Lorg/bukkit/entity/Player;I[B)V","exceptions":["java/lang/reflect/InvocationTargetException"]},{"name":"sendWirePacket","access":1025,"descriptor":"(Lorg/bukkit/entity/Player;Lcom/comphenix/protocol/injector/netty/WirePacket;)V","exceptions":["java/lang/reflect/InvocationTargetException"]},{"name":"recieveClientPacket","access":1025,"descriptor":"(Lorg/bukkit/entity/Player;Lcom/comphenix/protocol/events/PacketContainer;)V","exceptions":["java/lang/IllegalAccessException","java/lang/reflect/InvocationTargetException"]},{"name":"recieveClientPacket","access":1025,"descriptor":"(Lorg/bukkit/entity/Player;Lcom/comphenix/protocol/events/PacketContainer;Z)V","exceptions":["java/lang/IllegalAccessException","java/lang/reflect/InvocationTargetException"]},{"name":"recieveClientPacket","access":1025,"descriptor":"(Lorg/bukkit/entity/Player;Lcom/comphenix/protocol/events/PacketContainer;Lcom/comphenix/protocol/events/NetworkMarker;Z)V","exceptions":["java/lang/IllegalAccessException","java/lang/reflect/InvocationTargetException"]}]},{"name":"com/comphenix/protocol/PacketType","version":52,"access":33,"signature":"Ljava/lang/Object;Ljava/io/Serializable;Ljava/lang/Cloneable;Ljava/lang/Comparable<Lcom/comphenix/protocol/PacketType;>;","superName":"java/lang/Object","interfaces":["java/io/Serializable","java/lang/Cloneable","java/lang/Comparable"],"innerClasses":[{"name":"com/comphenix/protocol/PacketType$Sender","outerName":"com/comphenix/protocol/PacketType","innerName":"Sender","access":16409},{"name":"com/comphenix/protocol/PacketType$Protocol","outerName":"com/comphenix/protocol/PacketType","innerName":"Protocol","access":16409},{"name":"com/comphenix/protocol/PacketType$Legacy","outerName":"com/comphenix/protocol/PacketType","innerName":"Legacy","access":9},{"name":"com/comphenix/protocol/PacketType$Login","outerNaLine truncated
|
||||
Vendored
BIN
Binary file not shown.
+8
@@ -0,0 +1,8 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionSha256Sum=bd71102213493060956ec229d946beee57158dbd89d0e62b91bca0fa2c5f3531
|
||||
@@ -0,0 +1,251 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH="\\\"\\\""
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
Vendored
+94
@@ -0,0 +1,94 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@@ -0,0 +1 @@
|
||||
rootProject.name = 'AAC2'
|
||||
@@ -0,0 +1,165 @@
|
||||
package me.konsolas.aac;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Random;
|
||||
import me.konsolas.aac.api.AACAPI;
|
||||
import me.konsolas.aac.components.AACCommandExecutor;
|
||||
import me.konsolas.aac.components.AACLogger;
|
||||
import me.konsolas.aac.components.CombatTracker;
|
||||
import me.konsolas.aac.components.PlayerStateTracker;
|
||||
import me.konsolas.aac.components.PunishmentManager;
|
||||
import me.konsolas.aac.components.SetbackManager;
|
||||
import me.konsolas.aac.components.TPSManager;
|
||||
import me.konsolas.aac.hooks.McMMO;
|
||||
import me.konsolas.aac.lang.Messages;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class AAC extends JavaPlugin implements Listener {
|
||||
public static volatile AACAPI api = null;
|
||||
public static final String PLUGIN_NAME = "AAC";
|
||||
public static String messagePrefix = "§6[AAC] §r> §6";
|
||||
public static Random random = new Random();
|
||||
public AAC plugin = this;
|
||||
public Player debugPlayer;
|
||||
public AACLogger logger;
|
||||
public Messages messages;
|
||||
public TPSManager tpsManager;
|
||||
public PlayerStateTracker playerStateTracker;
|
||||
public SetbackManager setbackManager;
|
||||
public CheckManager checkManager;
|
||||
public CombatTracker combatTracker;
|
||||
public PunishmentManager punishmentManager;
|
||||
public AACCommandExecutor commandExecutor;
|
||||
private final SimpleDateFormat logFilenameFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
|
||||
private final SimpleDateFormat logTimestampFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss.SSS");
|
||||
private FileWriter logFileWriter;
|
||||
private PrintWriter logWriter;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Bukkit.getLogger().info("[AAC] IMPORTANT");
|
||||
this.getServer().getPluginManager().registerEvents(this, this);
|
||||
this.getLogger().warning("[AAC] IMPORTANT");
|
||||
this.getLogger().warning("[AAC] IMPORTANT");
|
||||
this.getLogger().warning("[AAC] THIS IS THE 1.10 PRE-RELEASE FOR AAC. EXPECT BUGS TO BE FIXED");
|
||||
this.getLogger().warning("[AAC] IMPORTANT");
|
||||
this.getLogger().warning("[AAC] IMPORTANT");
|
||||
|
||||
this.commandExecutor = new AACCommandExecutor(this);
|
||||
this.checkManager = new CheckManager(this);
|
||||
this.getServer().getPluginManager().registerEvents(this.commandExecutor, this);
|
||||
if (this.getConfig().getBoolean("usetps")) {
|
||||
this.tpsManager = new TPSManager(this);
|
||||
}
|
||||
|
||||
this.logger = new AACLogger(this);
|
||||
this.saveDefaultConfig();
|
||||
this.openLogFile();
|
||||
this.reloadConfig();
|
||||
this.punishmentManager = new PunishmentManager(this);
|
||||
this.registerCommands();
|
||||
this.getServer().getScheduler().scheduleSyncDelayedTask(this, new EnableSequence(this), 20L);
|
||||
this.setbackManager = new SetbackManager(this);
|
||||
this.getServer().getPluginManager().registerEvents(this.setbackManager, this);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
||||
if (api == null) {
|
||||
event.disallow(Result.KICK_OTHER, "Server still starting up");
|
||||
}
|
||||
}
|
||||
|
||||
public void initializeHooks() {
|
||||
if (Bukkit.getServer().getPluginManager().getPlugin("mcMMO") != null) {
|
||||
Bukkit.getLogger().info("[AAC] Detected mcMMO, setting up hooks...");
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new McMMO(this), this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (this.punishmentManager != null) {
|
||||
this.punishmentManager.saveBannedPlayers();
|
||||
}
|
||||
|
||||
this.closeLogFile();
|
||||
}
|
||||
|
||||
public void openLogFile() {
|
||||
try {
|
||||
if (!this.getConfig().getBoolean("log_file", true)) {
|
||||
Bukkit.getLogger().warning("[AAC] Logger functionality has been disabled in the configuration file.");
|
||||
return;
|
||||
}
|
||||
|
||||
File logsDir = new File(this.getDataFolder(), "logs");
|
||||
if (!logsDir.exists()) {
|
||||
logsDir.mkdir();
|
||||
}
|
||||
|
||||
Date now = new Date();
|
||||
File logFile = new File(this.getDataFolder(), "logs/aac_" + this.logFilenameFormat.format(now) + ".log");
|
||||
if (!logFile.exists()) {
|
||||
logFile.createNewFile();
|
||||
}
|
||||
|
||||
this.logFileWriter = new FileWriter(logFile, true);
|
||||
this.logWriter = new PrintWriter(this.logFileWriter);
|
||||
} catch (IOException ex) {
|
||||
Bukkit.getLogger().severe("[AAC] Error: Could not setup log file for writing");
|
||||
Bukkit.getLogger().severe("[AAC] " + ex.getMessage());
|
||||
Bukkit.getLogger().severe("[AAC] Logger functionality has been disabled.");
|
||||
}
|
||||
}
|
||||
|
||||
private void closeLogFile() {
|
||||
try {
|
||||
Bukkit.getLogger().info("[AAC] Saving log file...");
|
||||
this.logWriter.close();
|
||||
} catch (NullPointerException ex) {
|
||||
Bukkit.getLogger().warning("[AAC] Could not save log file as none was created.");
|
||||
}
|
||||
}
|
||||
|
||||
public void writeLog(String message) {
|
||||
if (this.logWriter != null) {
|
||||
Date now = new Date();
|
||||
this.logWriter.println("[" + this.logTimestampFormat.format(now) + "] " + message);
|
||||
this.logWriter.flush();
|
||||
}
|
||||
}
|
||||
|
||||
public void reloadPlugin() {
|
||||
Bukkit.getLogger().info("[AAC] Beginning disable...");
|
||||
Bukkit.getServer().getPluginManager().disablePlugin(this);
|
||||
ProtocolLibrary.getProtocolManager().removePacketListeners(this);
|
||||
Bukkit.getServer().getPluginManager().enablePlugin(this);
|
||||
}
|
||||
|
||||
private void registerCommands() {
|
||||
this.getCommand("aac").setExecutor(this.commandExecutor);
|
||||
this.getCommand("aacunban").setExecutor(this.commandExecutor);
|
||||
this.getCommand("aacban").setExecutor(this.commandExecutor);
|
||||
this.getCommand("aacadmin").setExecutor(this.commandExecutor);
|
||||
this.getCommand("aackick").setExecutor(this.commandExecutor);
|
||||
this.getCommand("aacreload").setExecutor(this.commandExecutor);
|
||||
this.getCommand("aacdebug").setExecutor(this.commandExecutor);
|
||||
this.getCommand("aacverbose").setExecutor(this.commandExecutor);
|
||||
this.getCommand("aacmessage").setExecutor(this.commandExecutor);
|
||||
this.getCommand("aacstaffnotify").setExecutor(this.commandExecutor);
|
||||
this.getCommand("aaccrash").setExecutor(this.commandExecutor);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
package me.konsolas.aac;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.DamageListener;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import me.konsolas.aac.detectors.MoveListener;
|
||||
import me.konsolas.aac.util.ground.GroundUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class CheckManager implements Listener {
|
||||
private final Map<HackType, Detector> checks = new HashMap<>();
|
||||
private final List<HackType> disabledChecks = new ArrayList<>();
|
||||
private final Set<UUID> bypassedPlayers = new HashSet<>();
|
||||
private final Map<UUID, Long> bypassRefreshTimes = new HashMap<>();
|
||||
private final AAC plugin;
|
||||
private long currentTick = 0L;
|
||||
|
||||
public CheckManager(AAC plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
for (HackType hackType : HackType.values()) {
|
||||
this.checks.put(hackType, null);
|
||||
}
|
||||
|
||||
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new TickTask(this), 1L, 1L);
|
||||
}
|
||||
|
||||
public boolean enableCheck(HackType hackType, boolean respectDisabled) {
|
||||
if (this.checks.get(hackType) != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (respectDisabled) {
|
||||
if (this.disabledChecks.contains(hackType)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
this.disabledChecks.remove(hackType);
|
||||
}
|
||||
|
||||
Class<?> detectorClass;
|
||||
try {
|
||||
detectorClass = Class.forName("me.konsolas.aac.detectors." + hackType);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
this.plugin.logger.log("Failed to initialize " + hackType.getName() + " (class not found)");
|
||||
return false;
|
||||
}
|
||||
|
||||
Constructor<?> constructor = null;
|
||||
for (Constructor<?> candidate : detectorClass.getDeclaredConstructors()) {
|
||||
constructor = candidate;
|
||||
if (constructor.getParameterTypes().length == 1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (constructor == null) {
|
||||
throw new RuntimeException("Could not get valid constuctor");
|
||||
}
|
||||
|
||||
Detector detector;
|
||||
try {
|
||||
constructor.setAccessible(true);
|
||||
detector = (Detector) constructor.newInstance(this.plugin);
|
||||
} catch (Exception ex) {
|
||||
this.plugin.logger.log("Failed to initialize " + hackType.getName() + " (instance creation failed)");
|
||||
ex.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
this.checks.put(hackType, detector);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(detector, this.plugin);
|
||||
this.plugin.logger.log("(CheckManager) Enabled check " + hackType);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean disableCheck(HackType hackType, boolean temporary) {
|
||||
if (!this.isCheckEnabled(hackType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!temporary) {
|
||||
this.disabledChecks.add(hackType);
|
||||
}
|
||||
|
||||
Detector detector = this.checks.get(hackType);
|
||||
detector.destroy();
|
||||
HandlerList.unregisterAll(detector);
|
||||
this.checks.put(hackType, null);
|
||||
this.plugin.logger.log("(CheckManager) Disabled check " + hackType);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void disableAllChecks() {
|
||||
for (HackType hackType : HackType.values()) {
|
||||
if (this.isCheckEnabled(hackType)) {
|
||||
this.plugin.getLogger().info("(CheckManager) Disabling check " + hackType);
|
||||
this.disableCheck(hackType, false);
|
||||
} else {
|
||||
this.plugin.getLogger().info("(CheckManager) Check " + hackType + " is not enabled");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void enableAllChecks() {
|
||||
for (HackType hackType : HackType.values()) {
|
||||
this.enableCheck(hackType, true);
|
||||
}
|
||||
}
|
||||
|
||||
public Detector getCheck(HackType hackType) {
|
||||
return this.checks.get(hackType);
|
||||
}
|
||||
|
||||
public boolean isCheckEnabled(HackType hackType) {
|
||||
return this.checks.get(hackType) != null;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerKick(PlayerKickEvent event) {
|
||||
for (HackType hackType : HackType.values()) {
|
||||
if (this.isCheckEnabled(hackType)) {
|
||||
this.getCheck(hackType).onPlayerKick(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
for (HackType hackType : HackType.values()) {
|
||||
if (this.isCheckEnabled(hackType)) {
|
||||
this.getCheck(hackType).onPlayerJoin(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
for (HackType hackType : HackType.values()) {
|
||||
if (this.isCheckEnabled(hackType)) {
|
||||
this.getCheck(hackType).onPlayerQuit(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
boolean bypassed = this.isBypassed(event.getPlayer());
|
||||
boolean fromOnGround = GroundUtil.isOnGround(event.getFrom());
|
||||
boolean toOnGround = GroundUtil.isOnGround(event.getTo());
|
||||
this.plugin.playerStateTracker.updateGroundState(event, fromOnGround, toOnGround);
|
||||
|
||||
for (HackType hackType : HackType.values()) {
|
||||
if (this.isCheckEnabled(hackType)) {
|
||||
Detector detector = this.getCheck(hackType);
|
||||
if (detector instanceof MoveListener) {
|
||||
MoveListener listener = (MoveListener) detector;
|
||||
if (listener.shouldProcessMove(event) && !bypassed) {
|
||||
listener.onPlayerMove(event, fromOnGround, toOnGround);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.plugin.setbackManager.shouldProcessMove(event) && !bypassed) {
|
||||
this.plugin.setbackManager.onPlayerMove(event, fromOnGround, toOnGround);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
boolean bypassed = event.getDamager().hasPermission("AAC.bypass") || event.getEntity().hasPermission("AAC.bypass");
|
||||
|
||||
for (HackType hackType : HackType.values()) {
|
||||
if (this.isCheckEnabled(hackType)) {
|
||||
Detector detector = this.getCheck(hackType);
|
||||
if (detector instanceof DamageListener) {
|
||||
DamageListener listener = (DamageListener) detector;
|
||||
if (listener.shouldProcessDamage(event) && !bypassed) {
|
||||
listener.onEntityDamageByEntity(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isBypassed(Player player) {
|
||||
UUID playerId = player.getUniqueId();
|
||||
Long nextRefresh = this.bypassRefreshTimes.get(playerId);
|
||||
if (nextRefresh == null) {
|
||||
this.bypassRefreshTimes.put(playerId, 0L);
|
||||
nextRefresh = 0L;
|
||||
}
|
||||
|
||||
if (System.currentTimeMillis() < nextRefresh) {
|
||||
return this.bypassedPlayers.contains(playerId);
|
||||
}
|
||||
|
||||
boolean bypassed = player.hasPermission("AAC.bypass");
|
||||
if (bypassed) {
|
||||
this.bypassedPlayers.add(playerId);
|
||||
} else {
|
||||
this.bypassedPlayers.remove(playerId);
|
||||
}
|
||||
|
||||
this.bypassRefreshTimes.put(playerId, System.currentTimeMillis() + AAC.random.nextInt(20000) + 20000L);
|
||||
return bypassed;
|
||||
}
|
||||
|
||||
public void clearBypassCache() {
|
||||
this.bypassRefreshTimes.clear();
|
||||
this.bypassedPlayers.clear();
|
||||
}
|
||||
|
||||
private static final class TickTask implements Runnable {
|
||||
private final CheckManager checkManager;
|
||||
|
||||
private TickTask(CheckManager checkManager) {
|
||||
this.checkManager = checkManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
this.checkManager.currentTick++;
|
||||
|
||||
for (HackType hackType : HackType.values()) {
|
||||
if (this.checkManager.isCheckEnabled(hackType)) {
|
||||
this.checkManager.getCheck(hackType).updateTick(this.checkManager.currentTick);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package me.konsolas.aac;
|
||||
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.api.internal.AACAPIImpl;
|
||||
import me.konsolas.aac.components.CombatTracker;
|
||||
import me.konsolas.aac.components.PlayerStateTracker;
|
||||
import me.konsolas.aac.lang.Messages;
|
||||
import me.konsolas.aac.util.TPS;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class EnableSequence implements Runnable {
|
||||
private final AAC plugin;
|
||||
|
||||
public EnableSequence(AAC plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
this.plugin.getLogger().info("Beginning Enable...");
|
||||
this.plugin.initializeHooks();
|
||||
Bukkit.getServer().getPluginManager().registerEvents(this.plugin.checkManager, this.plugin);
|
||||
this.plugin.getLogger().info("Checking config file...");
|
||||
|
||||
for (HackType hackType : HackType.values()) {
|
||||
if (this.plugin.getConfig().getBoolean(hackType.getName() + ".enabled")) {
|
||||
this.plugin.getLogger().info("(CheckManager) Enabling check " + hackType);
|
||||
this.plugin.checkManager.enableCheck(hackType, false);
|
||||
} else {
|
||||
this.plugin.getLogger().info("(CheckManager) Check " + hackType + " is disabled");
|
||||
}
|
||||
}
|
||||
|
||||
this.plugin.getLogger().info("Starting API...");
|
||||
AAC.api = new AACAPIImpl(this.plugin);
|
||||
this.plugin.combatTracker = new CombatTracker(this.plugin);
|
||||
this.plugin.playerStateTracker = new PlayerStateTracker(this.plugin);
|
||||
this.plugin.messages = new Messages(this.plugin);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(this.plugin.combatTracker, this.plugin);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(this.plugin.playerStateTracker, this.plugin);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(this.plugin.punishmentManager, this.plugin);
|
||||
this.plugin.logger.log("AAC has been enabled");
|
||||
this.plugin.getLogger().info("AAC has been enabled.");
|
||||
AAC.messagePrefix = ChatColor.translateAlternateColorCodes('&', this.plugin.messages.getMessage("prefix"));
|
||||
TPS.startMonitoring(this.plugin);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package me.konsolas.aac.api;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface AACAPI {
|
||||
void reloadAAC();
|
||||
|
||||
void reloadPermissionCache();
|
||||
|
||||
void invalidateMovementCaches();
|
||||
|
||||
void enableCheck(HackType hackType);
|
||||
|
||||
void disableCheck(HackType hackType);
|
||||
|
||||
boolean isEnabled(HackType hackType);
|
||||
|
||||
boolean isBypassed(Player player);
|
||||
|
||||
double getTPS();
|
||||
|
||||
int getPing(Player player);
|
||||
|
||||
int getViolationLevel(Player player, HackType hackType);
|
||||
|
||||
void setViolationLevel(Player player, HackType hackType, int level);
|
||||
|
||||
boolean isPlayerOnGround(Player player);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package me.konsolas.aac.api;
|
||||
|
||||
import me.konsolas.aac.AAC;
|
||||
|
||||
public final class AACAPIProvider {
|
||||
private AACAPIProvider() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static AACAPI getAPI() {
|
||||
if (AAC.api == null) {
|
||||
throw new APINotLoadedException();
|
||||
} else {
|
||||
return AAC.api;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isAPILoaded() {
|
||||
return AAC.api != null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package me.konsolas.aac.api;
|
||||
|
||||
public final class APINotLoadedException extends RuntimeException {
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package me.konsolas.aac.api;
|
||||
|
||||
public enum HackType {
|
||||
SPAM("chat.Spam", "spam"),
|
||||
COMBATIMPOSSIBLE("combat.CombatImpossible", "combatimpossible"),
|
||||
ANGLE("combat.Angle", "angle"),
|
||||
CRITICALS("combat.Criticals", "criticals"),
|
||||
FASTBOW("combat.Fastbow", "fastbow"),
|
||||
FIGHTSPEED("combat.FightSpeed", "fightspeed"),
|
||||
FORCEFIELD("combat.Forcefield", "forcefield"),
|
||||
KNOCKBACK("combat.Knockback", "knockback"),
|
||||
REACH("combat.Reach", "reach"),
|
||||
REGEN("combat.Regen", "regen"),
|
||||
FASTUSE("combat.FastUse", "fastuse"),
|
||||
KILLAURA("combat.KillauraCombined", "killaura"),
|
||||
BADPACKETS("movement.BadPackets", "badpackets"),
|
||||
GLIDE("movement.Glide", "glide"),
|
||||
NORMALMOVEMENTS("movement.NormalMovements", "normalmovements"),
|
||||
SPEED("movement.Speed", "speed"),
|
||||
PHASE("movement.Phase", "phase"),
|
||||
FLY("movement.Fly", "fly"),
|
||||
NOFALL("movement.NoFall", "nofall"),
|
||||
CLIMB("movement.Climb", "climb"),
|
||||
JESUS("movement.Jesus", "jesus"),
|
||||
ELYTRAMOVE("movement.ElytraMove", "elytramove"),
|
||||
BOATFLY("movement.BoatFly", "boatfly"),
|
||||
HEADROLL("movement.HeadRoll", "headroll"),
|
||||
FASTBREAK("world.FastBreak", "fastbreak"),
|
||||
FASTPLACE("world.FastPlace", "fastplace"),
|
||||
NUKER("world.Nuker", "nuker"),
|
||||
NOSWING("world.NoSwing", "noswing"),
|
||||
IMPOSSIBLEINTERACT("world.ImpossibleInteract", "impossibleinteract"),
|
||||
PLAYERRADAR("world.PlayerRadar", "playerradar");
|
||||
|
||||
private final String checkPath;
|
||||
private final String name;
|
||||
private final int id;
|
||||
|
||||
HackType(String checkPath, String name) {
|
||||
this.checkPath = checkPath;
|
||||
this.name = name;
|
||||
this.id = this.ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.checkPath;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package me.konsolas.aac.api;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
public final class PlayerViolationCommandEvent extends PlayerEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled;
|
||||
private final HackType hackType;
|
||||
private String command;
|
||||
|
||||
public PlayerViolationCommandEvent(Player player, HackType hackType, String command) {
|
||||
super(player);
|
||||
this.hackType = hackType;
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return this.command;
|
||||
}
|
||||
|
||||
public void setCommand(String command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public HackType getHackType() {
|
||||
return this.hackType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package me.konsolas.aac.api;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
public final class PlayerViolationEvent extends PlayerEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled;
|
||||
private final HackType hackType;
|
||||
private final int violations;
|
||||
private final String message;
|
||||
|
||||
public PlayerViolationEvent(Player player, HackType hackType, int violations, String message) {
|
||||
super(player);
|
||||
this.hackType = hackType;
|
||||
this.violations = violations;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public int getViolations() {
|
||||
return this.violations;
|
||||
}
|
||||
|
||||
public HackType getHackType() {
|
||||
return this.hackType;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package me.konsolas.aac.api.internal;
|
||||
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.AACAPI;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.movement.Fly;
|
||||
import me.konsolas.aac.detectors.movement.Phase;
|
||||
import me.konsolas.aac.detectors.movement.Speed;
|
||||
import me.konsolas.aac.util.Ping;
|
||||
import me.konsolas.aac.util.TPS;
|
||||
import me.konsolas.aac.util.ground.GroundUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public final class AACAPIImpl implements AACAPI {
|
||||
private final AAC plugin;
|
||||
|
||||
public AACAPIImpl(AAC plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadAAC() {
|
||||
this.plugin.reloadPlugin();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadPermissionCache() {
|
||||
this.plugin.checkManager.clearBypassCache();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateMovementCaches() {
|
||||
((Speed) this.plugin.checkManager.getCheck(HackType.SPEED)).clearCaches();
|
||||
((Fly) this.plugin.checkManager.getCheck(HackType.FLY)).clearCaches();
|
||||
((Phase) this.plugin.checkManager.getCheck(HackType.FLY)).clearCaches();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableCheck(HackType hackType) {
|
||||
this.plugin.checkManager.enableCheck(hackType, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableCheck(HackType hackType) {
|
||||
this.plugin.checkManager.disableCheck(hackType, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(HackType hackType) {
|
||||
return this.plugin.checkManager.isCheckEnabled(hackType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBypassed(Player player) {
|
||||
return this.plugin.checkManager.isBypassed(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTPS() {
|
||||
return TPS.getTps();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPing(Player player) {
|
||||
return Ping.getPing(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViolationLevel(Player player, HackType hackType) {
|
||||
return this.plugin.checkManager.getCheck(hackType).getViolationLevel(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setViolationLevel(Player player, HackType hackType, int level) {
|
||||
this.plugin.checkManager.getCheck(hackType).setViolationLevel(player, level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayerOnGround(Player player) {
|
||||
return GroundUtil.isOnGround(player.getLocation());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
package me.konsolas.aac.components;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.PacketType.Play.Client;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.gui.admin.HomeGUI;
|
||||
import me.konsolas.aac.util.CrashUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class AACCommandExecutor implements CommandExecutor, Listener {
|
||||
private final AAC plugin;
|
||||
private boolean disableVersionCommand = false;
|
||||
|
||||
public AACCommandExecutor(AAC plugin) {
|
||||
this.plugin = plugin;
|
||||
this.disableVersionCommand = plugin.getConfig().getBoolean("aac", false);
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new RegisterVersionListenerTask());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
|
||||
if (event.getPlayer().hasPermission("AAC.notify") && event.getMessage().startsWith(this.plugin.messages.getMessage("prefix_to_speak"))) {
|
||||
event.setCancelled(true);
|
||||
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new StaffChatDispatchTask(event));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (command.getName().equalsIgnoreCase("aac")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (command.getName().equalsIgnoreCase("aacban")) {
|
||||
if (args.length != 1) {
|
||||
sender.sendMessage(AAC.messagePrefix + "Incorrect number of arguments.");
|
||||
return false;
|
||||
} else if (this.plugin.punishmentManager.isBanned(args[0])) {
|
||||
sender.sendMessage(AAC.messagePrefix + args[0] + " is already banned");
|
||||
return false;
|
||||
} else if (Bukkit.getPlayer(args[0]) == null) {
|
||||
sender.sendMessage(AAC.messagePrefix + args[0] + " is not online");
|
||||
return false;
|
||||
} else {
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
this.plugin.punishmentManager.banPlayer(target);
|
||||
target.kickPlayer(AAC.messagePrefix + this.plugin.messages.getMessage("ban_message"));
|
||||
sender.sendMessage(AAC.messagePrefix + args[0] + " has been banned");
|
||||
this.plugin.logger.log(args[0] + " was banned by " + sender.getName());
|
||||
return true;
|
||||
}
|
||||
} else if (command.getName().equalsIgnoreCase("aacverbose")) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(AAC.messagePrefix + "You know there's this wonderful thing called a config file... read it");
|
||||
return true;
|
||||
}
|
||||
|
||||
Player player = (Player) sender;
|
||||
if (this.plugin.logger.verbosePlayerIds.contains(player.getUniqueId())) {
|
||||
this.plugin.logger.verbosePlayerIds.remove(player.getUniqueId());
|
||||
sender.sendMessage(AAC.messagePrefix + "AAC will now give you verbose output.");
|
||||
} else {
|
||||
this.plugin.logger.verbosePlayerIds.add(player.getUniqueId());
|
||||
sender.sendMessage(AAC.messagePrefix + "AAC will no longer give you verbose output.");
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (command.getName().equalsIgnoreCase("aacunban")) {
|
||||
if (args.length != 1) {
|
||||
sender.sendMessage(AAC.messagePrefix + "Incorrect number of arguments.");
|
||||
return false;
|
||||
} else if (!this.plugin.punishmentManager.isBanned(args[0])) {
|
||||
sender.sendMessage(AAC.messagePrefix + args[0] + " is not already banned");
|
||||
return false;
|
||||
} else {
|
||||
this.plugin.punishmentManager.unbanPlayer(args[0]);
|
||||
sender.sendMessage(AAC.messagePrefix + args[0] + " has been unbanned");
|
||||
this.plugin.logger.log(args[0] + " was unbanned by " + sender.getName());
|
||||
return true;
|
||||
}
|
||||
} else if (command.getName().equalsIgnoreCase("aacadmin")) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("You can't see an inventory GUI so...");
|
||||
return false;
|
||||
} else {
|
||||
new HomeGUI(this.plugin, (Player) sender);
|
||||
return true;
|
||||
}
|
||||
} else if (command.getName().equalsIgnoreCase("aacreload")) {
|
||||
sender.sendMessage(AAC.messagePrefix + "Reload request has been registered.");
|
||||
this.plugin.logger.log("Reload requested by " + sender.getName());
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new ReloadPluginTask(), 1L);
|
||||
return true;
|
||||
} else if (command.getName().equalsIgnoreCase("aackick")) {
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage(AAC.messagePrefix + "Incorrect number of arguments.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
if (target == null) {
|
||||
sender.sendMessage(args[0] + " is not online.");
|
||||
return false;
|
||||
}
|
||||
|
||||
this.plugin.punishmentManager.recordKick(target);
|
||||
StringBuilder reason = new StringBuilder();
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
reason.append(args[i]);
|
||||
reason.append(' ');
|
||||
}
|
||||
|
||||
target.kickPlayer(AAC.messagePrefix + reason.toString());
|
||||
if (this.plugin.getConfig().getBoolean("aackick_broadcast")) {
|
||||
Bukkit.broadcastMessage(AAC.messagePrefix + target.getName() + this.plugin.messages.getMessage("aac_kick_broadcast"));
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (command.getName().equalsIgnoreCase("aacdebug")) {
|
||||
if (args.length == 0) {
|
||||
if (this.plugin.debugPlayer != null) {
|
||||
sender.sendMessage(AAC.messagePrefix + "Ending debug for " + this.plugin.debugPlayer.getName());
|
||||
this.plugin.logger.stopDebugLog();
|
||||
return true;
|
||||
} else {
|
||||
sender.sendMessage(AAC.messagePrefix + "No active debug");
|
||||
return false;
|
||||
}
|
||||
} else if (args.length != 1) {
|
||||
sender.sendMessage("Incorrect number of arguments");
|
||||
return false;
|
||||
} else {
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
if (target == null) {
|
||||
sender.sendMessage(args[0] + " is not online");
|
||||
return false;
|
||||
} else {
|
||||
sender.sendMessage("Type /aacdebug without arguments to end the debug session.");
|
||||
sender.sendMessage(AAC.messagePrefix + this.plugin.logger.startDebugLog(target));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (command.getName().equalsIgnoreCase("aacmessage")) {
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage(AAC.messagePrefix + "Incorrect number of arguments.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
if (target == null) {
|
||||
sender.sendMessage(args[0] + " is not online.");
|
||||
return false;
|
||||
}
|
||||
|
||||
StringBuilder message = new StringBuilder();
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
message.append(args[i]);
|
||||
message.append(' ');
|
||||
}
|
||||
|
||||
target.sendMessage(AAC.messagePrefix + message.toString());
|
||||
return true;
|
||||
} else if (command.getName().equalsIgnoreCase("aacstaffnotify")) {
|
||||
StringBuilder message = new StringBuilder();
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
message.append(args[i]);
|
||||
message.append(' ');
|
||||
}
|
||||
|
||||
Bukkit.broadcast(
|
||||
ChatColor.translateAlternateColorCodes('&', this.plugin.messages.getMessage("format")).replace("{sender}", sender.getName())
|
||||
+ message.toString(),
|
||||
"AAC.notify"
|
||||
);
|
||||
return true;
|
||||
} else if (command.getName().equalsIgnoreCase("aaccrash")) {
|
||||
if (args.length != 1) {
|
||||
sender.sendMessage(AAC.messagePrefix + "Incorrect number of arguments.");
|
||||
return false;
|
||||
} else {
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
if (target == null) {
|
||||
sender.sendMessage(args[0] + " is not online.");
|
||||
return false;
|
||||
} else {
|
||||
CrashUtil.crashPlayer(target, sender);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private final class RegisterVersionListenerTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(new VersionPacketListener(AACCommandExecutor.this.plugin, ListenerPriority.LOWEST, Client.CHAT));
|
||||
}
|
||||
}
|
||||
|
||||
private final class VersionPacketListener extends PacketAdapter {
|
||||
private VersionPacketListener(Plugin plugin, ListenerPriority priority, PacketType... types) {
|
||||
super(plugin, priority, types);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
if (event.getPacket().getType().equals(Client.CHAT)) {
|
||||
String message = event.getPacket().getStrings().read(0);
|
||||
if ((message.equalsIgnoreCase("/aac") || message.startsWith("/aac ")) && !AACCommandExecutor.this.disableVersionCommand) {
|
||||
event.getPlayer().sendMessage(AAC.messagePrefix + "AAC " + AAC.class.getPackage().getImplementationVersion() + ": Haxor rekker (~konsolas)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class StaffChatDispatchTask implements Runnable {
|
||||
private final AsyncPlayerChatEvent event;
|
||||
|
||||
private StaffChatDispatchTask(AsyncPlayerChatEvent event) {
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
String prefix = AACCommandExecutor.this.plugin.messages.getMessage("prefix_to_speak");
|
||||
Bukkit.getServer().dispatchCommand(this.event.getPlayer(), "aacstaffnotify " + this.event.getMessage().substring(prefix.length()));
|
||||
}
|
||||
}
|
||||
|
||||
private final class ReloadPluginTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
AACCommandExecutor.this.plugin.reloadPlugin();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
package me.konsolas.aac.components;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.util.Ping;
|
||||
import me.konsolas.aac.util.TPS;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class AACLogger {
|
||||
public List<UUID> verbosePlayerIds = new ArrayList<>();
|
||||
private final SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss.SSS");
|
||||
private final AAC plugin;
|
||||
private FileWriter debugFileWriter;
|
||||
private PrintWriter debugWriter;
|
||||
private boolean logToConsole = true;
|
||||
private boolean verboseEnabled = false;
|
||||
|
||||
public AACLogger(AAC plugin) {
|
||||
this.plugin = plugin;
|
||||
this.logToConsole = this.plugin.getConfig().getBoolean("log_console", this.logToConsole);
|
||||
this.verboseEnabled = this.plugin.getConfig().getBoolean("verbose", this.verboseEnabled);
|
||||
}
|
||||
|
||||
public void log(String message) {
|
||||
if (this.verboseEnabled) {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
if (player.hasPermission("AAC.verbose") && !this.verbosePlayerIds.contains(player.getUniqueId())) {
|
||||
player.sendMessage(" * §4[AAC] §7" + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.logToConsole && this.verboseEnabled) {
|
||||
Bukkit.getConsoleSender().sendMessage(" * §4[AAC] §7" + message);
|
||||
}
|
||||
|
||||
this.plugin.writeLog(message);
|
||||
if (this.plugin.debugPlayer != null && message.startsWith(this.plugin.debugPlayer.getName())) {
|
||||
this.writeDebugLog(message);
|
||||
}
|
||||
}
|
||||
|
||||
public void logPlayerDebug(Player player, String message) {
|
||||
if (this.plugin.debugPlayer != null && this.plugin.debugPlayer.getUniqueId().equals(player.getUniqueId())) {
|
||||
this.writeDebugLog(message);
|
||||
}
|
||||
}
|
||||
|
||||
public String startDebugLog(Player player) {
|
||||
try {
|
||||
this.openDebugLog(player.getName());
|
||||
} catch (IOException ex) {
|
||||
return "Failed to setup debug log file for writing";
|
||||
}
|
||||
|
||||
this.debugWriter.println("AAC debug log for " + player.getName() + " (" + player.getUniqueId() + ")");
|
||||
this.debugWriter.println("version: " + AAC.class.getPackage().getImplementationVersion());
|
||||
this.debugWriter.println("");
|
||||
this.debugWriter.println("- Active configuration");
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(new File(this.plugin.getDataFolder(), "config.yml")))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.length() > 3 && line.charAt(0) != '#' && line.charAt(3) != '#') {
|
||||
this.debugWriter.println(line);
|
||||
}
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
return "Failed to read config.yml";
|
||||
}
|
||||
|
||||
this.debugWriter.println("");
|
||||
this.plugin.debugPlayer = player;
|
||||
this.debugWriter.println("- Shorthand reference");
|
||||
this.debugWriter.println(" - t:threshold");
|
||||
this.debugWriter.println(" - e:expected");
|
||||
this.debugWriter.println(" - r:recieved");
|
||||
this.debugWriter.println(" - m:maximum");
|
||||
this.debugWriter.println(" - n:minimum");
|
||||
this.debugWriter.println(" - u:using as");
|
||||
this.debugWriter.println(" - f:flags");
|
||||
this.debugWriter.println(" - !:not");
|
||||
this.debugWriter.println("");
|
||||
this.writeDebugLog("--- BEGIN DEBUG DATA ---");
|
||||
return "Now saving data for " + player.getName();
|
||||
}
|
||||
|
||||
public void stopDebugLog() {
|
||||
if (this.plugin.debugPlayer != null) {
|
||||
this.writeDebugLog("--- END DEBUG DATA ---");
|
||||
this.plugin.debugPlayer = null;
|
||||
this.closeDebugLog();
|
||||
}
|
||||
}
|
||||
|
||||
private void openDebugLog(String playerName) throws IOException {
|
||||
File dataFolder = this.plugin.getDataFolder();
|
||||
if (!dataFolder.exists()) {
|
||||
dataFolder.mkdir();
|
||||
}
|
||||
|
||||
File debugFile = new File(dataFolder, playerName + ".debug.log");
|
||||
if (!debugFile.exists()) {
|
||||
debugFile.createNewFile();
|
||||
} else {
|
||||
debugFile.delete();
|
||||
debugFile.createNewFile();
|
||||
}
|
||||
|
||||
this.debugFileWriter = new FileWriter(debugFile, true);
|
||||
this.debugWriter = new PrintWriter(this.debugFileWriter);
|
||||
}
|
||||
|
||||
private void closeDebugLog() {
|
||||
try {
|
||||
Bukkit.getLogger().info("[AAC] Saving log file...");
|
||||
this.debugWriter.close();
|
||||
} catch (NullPointerException ex) {
|
||||
Bukkit.getLogger().warning("[AAC] Could not save log file as none was created.");
|
||||
}
|
||||
}
|
||||
|
||||
public void writeDebugLog(String message) {
|
||||
if (this.debugWriter != null) {
|
||||
Date now = new Date();
|
||||
this.debugWriter.println(
|
||||
"at "
|
||||
+ this.timeFormat.format(now)
|
||||
+ ": "
|
||||
+ message
|
||||
+ " [ping:"
|
||||
+ Ping.getPing(this.plugin.debugPlayer)
|
||||
+ " tps:"
|
||||
+ Math.round(TPS.getTps() * 1000.0) / 1000.0
|
||||
+ "]"
|
||||
);
|
||||
this.debugWriter.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package me.konsolas.aac.components;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import me.konsolas.aac.AAC;
|
||||
import net.jodah.expiringmap.ExpirationPolicy;
|
||||
import net.jodah.expiringmap.ExpiringMap;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class CombatTracker implements Listener {
|
||||
private int combatDurationTicks = 50;
|
||||
private boolean punishCombatLoggers = true;
|
||||
private final ExpiringMap<UUID, UUID> combatPartners;
|
||||
private final List<UUID> punishedLoggers = new ArrayList<>();
|
||||
private final ExpiringMap<UUID, Boolean> recentDamage;
|
||||
private final Map<UUID, DamageCause> lastDamageCauses = new HashMap<>();
|
||||
private final JavaPlugin plugin;
|
||||
|
||||
public CombatTracker(JavaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.combatDurationTicks = this.plugin.getConfig().getInt("combat_time", this.combatDurationTicks);
|
||||
this.punishCombatLoggers = this.plugin.getConfig().getBoolean("kill_loggers", this.punishCombatLoggers);
|
||||
this.combatPartners = ExpiringMap.builder()
|
||||
.expirationPolicy(ExpirationPolicy.CREATED)
|
||||
.expiration(this.combatDurationTicks * 50L, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
this.recentDamage = ExpiringMap.builder()
|
||||
.expirationPolicy(ExpirationPolicy.CREATED)
|
||||
.expiration(3000L, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
if (event.getDamager().getType() == EntityType.PLAYER) {
|
||||
this.combatPartners.put(event.getDamager().getUniqueId(), event.getEntity().getUniqueId());
|
||||
this.combatPartners.resetExpiration(event.getDamager().getUniqueId());
|
||||
}
|
||||
|
||||
if (event.getEntity().getType() == EntityType.PLAYER) {
|
||||
this.combatPartners.put(event.getEntity().getUniqueId(), event.getDamager().getUniqueId());
|
||||
this.combatPartners.resetExpiration(event.getEntity().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public synchronized void onEntityDamage(EntityDamageEvent event) {
|
||||
if (event.getEntity().getType() == EntityType.PLAYER) {
|
||||
this.recentDamage.put(event.getEntity().getUniqueId(), true);
|
||||
this.recentDamage.resetExpiration(event.getEntity().getUniqueId());
|
||||
this.lastDamageCauses.put(event.getEntity().getUniqueId(), event.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInCombat(Player player) {
|
||||
return this.combatPartners.containsKey(player.getUniqueId());
|
||||
}
|
||||
|
||||
public synchronized boolean wasRecentlyDamaged(Player player) {
|
||||
return this.recentDamage.containsKey(player.getUniqueId());
|
||||
}
|
||||
|
||||
public synchronized DamageCause getLastDamageCause(Player player) {
|
||||
return this.lastDamageCauses.get(player.getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
if (this.punishCombatLoggers && this.combatPartners.containsKey(event.getPlayer().getUniqueId())) {
|
||||
Bukkit.broadcastMessage(
|
||||
AAC.messagePrefix + ((AAC) this.plugin).messages.getMessage("logging_broadcast").replace("{player}", event.getPlayer().getName())
|
||||
);
|
||||
event.getPlayer().setHealth(0.0);
|
||||
this.punishedLoggers.add(event.getPlayer().getUniqueId());
|
||||
this.combatPartners.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if (this.punishCombatLoggers && this.punishedLoggers.contains(event.getPlayer().getUniqueId())) {
|
||||
event.getPlayer().sendMessage(AAC.messagePrefix + ((AAC) this.plugin).messages.getMessage("killed_for_logging"));
|
||||
}
|
||||
|
||||
this.punishedLoggers.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
package me.konsolas.aac.components;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import me.konsolas.aac.AAC;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
||||
import org.bukkit.event.player.PlayerAnimationEvent;
|
||||
import org.bukkit.event.player.PlayerAnimationType;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerVelocityEvent;
|
||||
import org.bukkit.event.world.WorldUnloadEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class PlayerStateTracker implements Listener {
|
||||
private final AAC plugin;
|
||||
private final Set<UUID> recentlyLanded = new HashSet<>();
|
||||
private final Set<UUID> recentlyAirborne = new HashSet<>();
|
||||
private final Map<UUID, Long> lastArmSwingTimes = new HashMap<>();
|
||||
private final Map<UUID, Long> lastHealthRegainTimes = new HashMap<>();
|
||||
private final Map<UUID, RegainReason> lastHealthRegainReasons = new HashMap<>();
|
||||
private final Map<UUID, Long> lastInteractionTimes = new HashMap<>();
|
||||
private final ConcurrentMap<UUID, Vector> activeVelocities = new ConcurrentHashMap<>();
|
||||
private final ConcurrentMap<UUID, Long> lastVelocityTimes = new ConcurrentHashMap<>();
|
||||
private final Map<UUID, Location> lastMoveLocations = new HashMap<>();
|
||||
|
||||
public PlayerStateTracker(AAC plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void updateGroundState(PlayerMoveEvent event, boolean fromOnGround, boolean toOnGround) {
|
||||
UUID playerId = event.getPlayer().getUniqueId();
|
||||
if (fromOnGround && !toOnGround) {
|
||||
this.recentlyAirborne.add(playerId);
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new ClearTakeoffGraceTask(playerId), 3L);
|
||||
} else if (!fromOnGround && toOnGround) {
|
||||
this.recentlyLanded.add(playerId);
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new ClearLandingGraceTask(playerId), 3L);
|
||||
}
|
||||
|
||||
if (toOnGround) {
|
||||
this.activeVelocities.remove(playerId);
|
||||
} else {
|
||||
Vector velocity = event.getPlayer().getVelocity();
|
||||
if (velocity.getY() == 0.0 && velocity.getX() == 0.0 && velocity.getZ() == 0.0) {
|
||||
this.activeVelocities.remove(playerId);
|
||||
}
|
||||
}
|
||||
|
||||
this.lastMoveLocations.put(playerId, event.getFrom());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public synchronized void onPlayerVelocity(PlayerVelocityEvent event) {
|
||||
this.activeVelocities.put(event.getPlayer().getUniqueId(), event.getVelocity());
|
||||
this.lastVelocityTimes.put(event.getPlayer().getUniqueId(), System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerAnimation(PlayerAnimationEvent event) {
|
||||
if (event.getAnimationType() == PlayerAnimationType.ARM_SWING) {
|
||||
this.lastArmSwingTimes.put(event.getPlayer().getUniqueId(), System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
|
||||
if (event.getEntity().getType() == EntityType.PLAYER) {
|
||||
this.lastHealthRegainTimes.put(event.getEntity().getUniqueId(), System.currentTimeMillis());
|
||||
this.lastHealthRegainReasons.put(event.getEntity().getUniqueId(), event.getRegainReason());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
this.lastInteractionTimes.put(event.getPlayer().getUniqueId(), System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onWorldUnload(WorldUnloadEvent event) {
|
||||
Set<UUID> toRemove = new HashSet<>();
|
||||
|
||||
for (Map.Entry<UUID, Location> entry : this.lastMoveLocations.entrySet()) {
|
||||
if (entry.getValue().getWorld().equals(event.getWorld())) {
|
||||
toRemove.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
for (UUID playerId : toRemove) {
|
||||
this.lastMoveLocations.remove(playerId);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearTakeoffGrace(Player player) {
|
||||
this.recentlyAirborne.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
public boolean hasLandingGrace(Player player) {
|
||||
return this.recentlyLanded.contains(player.getUniqueId());
|
||||
}
|
||||
|
||||
public boolean hasTakeoffGrace(Player player) {
|
||||
return this.recentlyAirborne.contains(player.getUniqueId());
|
||||
}
|
||||
|
||||
public synchronized boolean hasActiveVelocity(Player player) {
|
||||
return this.activeVelocities.containsKey(player.getUniqueId());
|
||||
}
|
||||
|
||||
public synchronized Vector getActiveVelocity(Player player) {
|
||||
return this.activeVelocities.get(player.getUniqueId());
|
||||
}
|
||||
|
||||
public synchronized long getLastVelocityTime(Player player) {
|
||||
Long timestamp = this.lastVelocityTimes.get(player.getUniqueId());
|
||||
return timestamp != null ? timestamp : 0L;
|
||||
}
|
||||
|
||||
public long getLastArmSwingTime(Player player) {
|
||||
try {
|
||||
return this.lastArmSwingTimes.get(player.getUniqueId());
|
||||
} catch (NullPointerException ex) {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
public long getLastHealthRegainTime(Player player) {
|
||||
try {
|
||||
return this.lastHealthRegainTimes.get(player.getUniqueId());
|
||||
} catch (NullPointerException ex) {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
public RegainReason getLastHealthRegainReason(Player player) {
|
||||
try {
|
||||
return this.lastHealthRegainReasons.get(player.getUniqueId());
|
||||
} catch (NullPointerException ex) {
|
||||
return RegainReason.CUSTOM;
|
||||
}
|
||||
}
|
||||
|
||||
public long getLastInteractionTime(Player player) {
|
||||
try {
|
||||
return this.lastInteractionTimes.get(player.getUniqueId());
|
||||
} catch (NullPointerException ex) {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
private final class ClearTakeoffGraceTask implements Runnable {
|
||||
private final UUID playerId;
|
||||
|
||||
private ClearTakeoffGraceTask(UUID playerId) {
|
||||
this.playerId = playerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
PlayerStateTracker.this.recentlyAirborne.remove(this.playerId);
|
||||
}
|
||||
}
|
||||
|
||||
private final class ClearLandingGraceTask implements Runnable {
|
||||
private final UUID playerId;
|
||||
|
||||
private ClearLandingGraceTask(UUID playerId) {
|
||||
this.playerId = playerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
PlayerStateTracker.this.recentlyLanded.remove(this.playerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,314 @@
|
||||
package me.konsolas.aac.components;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.api.PlayerViolationCommandEvent;
|
||||
import me.konsolas.aac.internal.Destroyable;
|
||||
import me.konsolas.aac.util.Ping;
|
||||
import me.konsolas.aac.util.TPS;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class PunishmentManager implements Listener, Destroyable {
|
||||
public Map<UUID, Integer> kickCounts = new HashMap<>();
|
||||
private final AAC plugin;
|
||||
private final BukkitTask thresholdTask;
|
||||
private int banThreshold = 5;
|
||||
private int quitGraceTicks = 200;
|
||||
private final List<UUID> recentlyQuitPlayers = new ArrayList<>();
|
||||
private final Map<String, UUID> bannedPlayers = new HashMap<>();
|
||||
private final Map<HackType, List<ViolationCommandThreshold>> commandThresholds = new HashMap<>();
|
||||
private FileConfiguration banConfig = null;
|
||||
private File banConfigFile = null;
|
||||
|
||||
public PunishmentManager(AAC plugin) {
|
||||
this.plugin = plugin;
|
||||
this.banThreshold = this.plugin.getConfig().getInt("ban_threshold", this.banThreshold);
|
||||
this.quitGraceTicks = this.plugin.getConfig().getInt("kick_ticks", this.quitGraceTicks);
|
||||
this.saveDefaultBanConfig();
|
||||
|
||||
for (String entry : this.getBanConfig().getStringList("banned")) {
|
||||
String[] parts = entry.split(":");
|
||||
this.bannedPlayers.put(parts[0], UUID.fromString(parts[1]));
|
||||
}
|
||||
|
||||
for (HackType hackType : HackType.values()) {
|
||||
List<ViolationCommandThreshold> thresholds = new ArrayList<>();
|
||||
ConfigurationSection section = this.plugin.getConfig().getConfigurationSection(hackType.getName() + ".thresholds");
|
||||
if (section == null) {
|
||||
this.plugin.getLogger().warning("(Punisher) WARN: Failed to get thresholds for check " + hackType);
|
||||
} else {
|
||||
for (String key : section.getKeys(false)) {
|
||||
Object value = section.get(key);
|
||||
|
||||
int thresholdLevel;
|
||||
try {
|
||||
thresholdLevel = Integer.parseInt(key);
|
||||
} catch (NumberFormatException ex) {
|
||||
this.plugin.getLogger().warning("(Punisher) WARN: Failed to parse integer threshold: " + ex.getMessage());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (value instanceof String) {
|
||||
thresholds.add(new ViolationCommandThreshold(thresholdLevel, section.getString(key)));
|
||||
} else {
|
||||
List<String> commands = section.getStringList(key);
|
||||
if (!commands.isEmpty()) {
|
||||
for (String command : commands) {
|
||||
thresholds.add(new ViolationCommandThreshold(thresholdLevel, command));
|
||||
}
|
||||
} else {
|
||||
this.plugin.getLogger().warning("(Punisher) WARN: Failed to get multiple commands for check " + hackType + ", threshold " + thresholdLevel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.commandThresholds.put(hackType, thresholds);
|
||||
}
|
||||
}
|
||||
|
||||
this.thresholdTask = Bukkit.getServer().getScheduler().runTaskTimerAsynchronously(this.plugin, new ViolationThresholdScanTask(), 20L, 17L);
|
||||
}
|
||||
|
||||
public void saveBannedPlayers() {
|
||||
List<String> serialized = new ArrayList<>();
|
||||
|
||||
for (UUID playerId : this.bannedPlayers.values()) {
|
||||
serialized.add(Bukkit.getOfflinePlayer(playerId).getName() + ":" + playerId);
|
||||
}
|
||||
|
||||
this.getBanConfig().set("banned", serialized);
|
||||
this.saveBanConfig();
|
||||
}
|
||||
|
||||
public void recordKick(Player player) {
|
||||
UUID playerId = player.getUniqueId();
|
||||
if (this.kickCounts.containsKey(playerId)) {
|
||||
this.kickCounts.put(playerId, this.kickCounts.get(playerId) + 1);
|
||||
} else {
|
||||
this.kickCounts.put(playerId, 1);
|
||||
}
|
||||
|
||||
if (this.kickCounts.get(playerId) > this.banThreshold && this.banThreshold != -1) {
|
||||
this.kickCounts.remove(playerId);
|
||||
|
||||
for (String command : this.plugin.getConfig().getString("ban_command").split(";")) {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), this.formatCommand(command, player));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void banPlayer(Player player) {
|
||||
this.plugin.logger.log(player.getName() + " has been banned for hacking. (" + player.getUniqueId() + ")");
|
||||
this.bannedPlayers.put(player.getName(), player.getUniqueId());
|
||||
this.kickCounts.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
private String formatCommand(String command, Player player) {
|
||||
command = command.replace("{player}", player.getName());
|
||||
command = command.replace("{ping}", Ping.getPing(player) + "");
|
||||
return command.replace("{tps}", Math.round(TPS.getTps() * 100.0) / 100.0 + "");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
UUID playerId = event.getPlayer().getUniqueId();
|
||||
this.recentlyQuitPlayers.add(playerId);
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new ExpireQuitGraceTask(playerId), this.quitGraceTicks);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
||||
if (!event.getPlayer().hasPermission("AAC.bypass")) {
|
||||
UUID playerId = event.getPlayer().getUniqueId();
|
||||
if (this.recentlyQuitPlayers.contains(playerId)) {
|
||||
event.disallow(Result.KICK_OTHER, AAC.messagePrefix + this.plugin.messages.getMessage("relog_message"));
|
||||
}
|
||||
|
||||
if (!this.kickCounts.containsKey(playerId)) {
|
||||
this.kickCounts.put(playerId, 0);
|
||||
}
|
||||
|
||||
if (this.bannedPlayers.values().contains(playerId)) {
|
||||
event.disallow(Result.KICK_BANNED, AAC.messagePrefix + this.plugin.messages.getMessage("ban_message"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isBanned(String playerName) {
|
||||
return this.bannedPlayers.containsKey(playerName);
|
||||
}
|
||||
|
||||
public void unbanPlayer(String playerName) {
|
||||
this.kickCounts.put(this.bannedPlayers.get(playerName), 0);
|
||||
this.bannedPlayers.remove(playerName);
|
||||
}
|
||||
|
||||
public FileConfiguration getBanConfig() {
|
||||
if (this.banConfig == null) {
|
||||
this.reloadBanConfig();
|
||||
}
|
||||
|
||||
return this.banConfig;
|
||||
}
|
||||
|
||||
public void reloadBanConfig() {
|
||||
if (this.banConfigFile == null) {
|
||||
this.banConfigFile = new File(this.plugin.getDataFolder(), "banned.yml");
|
||||
}
|
||||
|
||||
this.banConfig = YamlConfiguration.loadConfiguration(this.banConfigFile);
|
||||
InputStream defaultStream = this.plugin.getResource("banned.yml");
|
||||
if (defaultStream != null) {
|
||||
InputStreamReader reader = new InputStreamReader(defaultStream, StandardCharsets.UTF_8);
|
||||
YamlConfiguration defaultConfig = YamlConfiguration.loadConfiguration(reader);
|
||||
this.banConfig.setDefaults(defaultConfig);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveDefaultBanConfig() {
|
||||
if (this.banConfigFile == null) {
|
||||
this.banConfigFile = new File(this.plugin.getDataFolder(), "banned.yml");
|
||||
}
|
||||
|
||||
if (!this.banConfigFile.exists()) {
|
||||
this.plugin.saveResource("banned.yml", false);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveBanConfig() {
|
||||
if (this.banConfig != null && this.banConfigFile != null) {
|
||||
try {
|
||||
this.getBanConfig().save(this.banConfigFile);
|
||||
} catch (IOException ex) {
|
||||
this.plugin.getLogger().log(Level.SEVERE, "Could not save config to " + this.banConfigFile, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
this.thresholdTask.cancel();
|
||||
this.saveBanConfig();
|
||||
}
|
||||
|
||||
private final class ViolationCommandThreshold {
|
||||
private final int violationThreshold;
|
||||
private final String commandTemplate;
|
||||
private final Map<UUID, Boolean> armedPlayers = new HashMap<>();
|
||||
|
||||
private ViolationCommandThreshold(int violationThreshold, String commandTemplate) {
|
||||
this.violationThreshold = violationThreshold;
|
||||
this.commandTemplate = commandTemplate;
|
||||
}
|
||||
|
||||
private void execute(Player player, HackType hackType) {
|
||||
PlayerViolationCommandEvent event = new PlayerViolationCommandEvent(player, hackType, this.commandTemplate);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), PunishmentManager.this.formatCommand(event.getCommand(), player));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shouldTrigger(Player player, int violationLevel) {
|
||||
UUID playerId = player.getUniqueId();
|
||||
if (!this.armedPlayers.containsKey(playerId)) {
|
||||
this.armedPlayers.put(playerId, true);
|
||||
}
|
||||
|
||||
if (this.armedPlayers.get(playerId)) {
|
||||
if (violationLevel > this.violationThreshold) {
|
||||
this.armedPlayers.put(playerId, false);
|
||||
return true;
|
||||
}
|
||||
} else if (violationLevel < this.violationThreshold) {
|
||||
this.armedPlayers.put(playerId, true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private String getCommandTemplate() {
|
||||
return this.commandTemplate;
|
||||
}
|
||||
}
|
||||
|
||||
private final class ViolationThresholdScanTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
for (HackType hackType : HackType.values()) {
|
||||
if (PunishmentManager.this.plugin.checkManager.isCheckEnabled(hackType)) {
|
||||
int violationLevel = PunishmentManager.this.plugin.checkManager.getCheck(hackType).getViolationLevel(player);
|
||||
List<ViolationCommandThreshold> thresholds = PunishmentManager.this.commandThresholds.get(hackType);
|
||||
if (thresholds != null) {
|
||||
for (ViolationCommandThreshold threshold : thresholds) {
|
||||
if (threshold.shouldTrigger(player, violationLevel)) {
|
||||
Bukkit.getServer()
|
||||
.getScheduler()
|
||||
.scheduleSyncDelayedTask(PunishmentManager.this.plugin, new ExecuteViolationCommandTask(hackType, threshold, player));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class ExecuteViolationCommandTask implements Runnable {
|
||||
private final HackType hackType;
|
||||
private final ViolationCommandThreshold threshold;
|
||||
private final Player player;
|
||||
|
||||
private ExecuteViolationCommandTask(HackType hackType, ViolationCommandThreshold threshold, Player player) {
|
||||
this.hackType = hackType;
|
||||
this.threshold = threshold;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
PunishmentManager.this.plugin.logger.log(
|
||||
"(Punisher) ->"
|
||||
+ this.hackType.toString()
|
||||
+ ": Dispatching command "
|
||||
+ PunishmentManager.this.formatCommand(this.threshold.getCommandTemplate(), this.player)
|
||||
);
|
||||
this.threshold.execute(this.player, this.hackType);
|
||||
}
|
||||
}
|
||||
|
||||
private final class ExpireQuitGraceTask implements Runnable {
|
||||
private final UUID playerId;
|
||||
|
||||
private ExpireQuitGraceTask(UUID playerId) {
|
||||
this.playerId = playerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
PunishmentManager.this.recentlyQuitPlayers.remove(this.playerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
package me.konsolas.aac.components;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import me.konsolas.aac.detectors.MoveListener;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.event.world.WorldUnloadEvent;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public class SetbackManager implements Listener, MoveListener {
|
||||
private final AAC plugin;
|
||||
private final Map<UUID, Location> safeLocations = new ConcurrentHashMap<>();
|
||||
private final Map<UUID, PlayerMoveEvent> pendingMoveEvents = new ConcurrentHashMap<>();
|
||||
private final Map<UUID, Detector> setbackChecks = new ConcurrentHashMap<>();
|
||||
|
||||
public SetbackManager(AAC plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void beginSetback(Detector detector, Player player) {
|
||||
this.setbackChecks.put(player.getUniqueId(), detector);
|
||||
}
|
||||
|
||||
public void endSetback(Player player) {
|
||||
this.setbackChecks.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = false, priority = EventPriority.MONITOR)
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
UUID playerId = event.getPlayer().getUniqueId();
|
||||
if (this.setbackChecks.containsKey(playerId) && event.getCause() == TeleportCause.UNKNOWN) {
|
||||
this.setbackChecks.remove(playerId);
|
||||
} else {
|
||||
if (event.getTo().equals(event.getFrom()) && event.getCause() == TeleportCause.UNKNOWN) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.safeLocations.put(playerId, event.getTo().clone());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = false, priority = EventPriority.MONITOR)
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
this.safeLocations.put(event.getPlayer().getUniqueId(), event.getRespawnLocation().clone());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = false, priority = EventPriority.MONITOR)
|
||||
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
|
||||
this.safeLocations.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
public Detector getSetbackCheck(Player player) {
|
||||
return this.setbackChecks.get(player.getUniqueId());
|
||||
}
|
||||
|
||||
private void saveDestination(PlayerMoveEvent event) {
|
||||
this.safeLocations.put(event.getPlayer().getUniqueId(), event.getTo().clone());
|
||||
}
|
||||
|
||||
private void saveOrigin(PlayerMoveEvent event) {
|
||||
UUID playerId = event.getPlayer().getUniqueId();
|
||||
if (this.pendingMoveEvents.containsKey(playerId)) {
|
||||
PlayerMoveEvent previousMove = this.pendingMoveEvents.get(playerId);
|
||||
double previousDeltaY = previousMove.getTo().getY() - previousMove.getFrom().getY();
|
||||
double currentDeltaY = event.getTo().getY() - event.getFrom().getY();
|
||||
if (previousDeltaY < 0.0 && currentDeltaY > 0.0) {
|
||||
this.safeLocations.put(playerId, event.getFrom().clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSafeLocation(PlayerMoveEvent event) {
|
||||
UUID playerId = event.getPlayer().getUniqueId();
|
||||
if (this.safeLocations.containsKey(playerId)) {
|
||||
if (event.getTo().getY() < this.safeLocations.get(playerId).getY()
|
||||
&& Math.abs(event.getFrom().getY() - event.getTo().getY()) < 3.0) {
|
||||
this.safeLocations.put(playerId, event.getTo().clone());
|
||||
return;
|
||||
}
|
||||
|
||||
this.pendingMoveEvents.put(playerId, event);
|
||||
} else {
|
||||
this.safeLocations.put(playerId, event.getPlayer().getLocation());
|
||||
}
|
||||
}
|
||||
|
||||
public Location getSafeLocation(Player player) {
|
||||
Location location = this.safeLocations.get(player.getUniqueId());
|
||||
return location != null ? location : player.getLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerMove(PlayerMoveEvent event, boolean fromOnGround, boolean toOnGround) {
|
||||
if (fromOnGround && toOnGround) {
|
||||
this.saveDestination(event);
|
||||
} else {
|
||||
if (fromOnGround) {
|
||||
this.saveOrigin(event);
|
||||
} else if (toOnGround) {
|
||||
this.updateSafeLocation(event);
|
||||
}
|
||||
|
||||
if (event.getPlayer().hasPotionEffect(PotionEffectType.LEVITATION)) {
|
||||
this.safeLocations.put(event.getPlayer().getUniqueId(), event.getPlayer().getLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldProcessMove(PlayerMoveEvent event) {
|
||||
if (event.getPlayer().isFlying()) {
|
||||
this.safeLocations.put(event.getPlayer().getUniqueId(), event.getPlayer().getLocation());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onWorldUnload(WorldUnloadEvent event) {
|
||||
Set<UUID> toRemove = new HashSet<>();
|
||||
|
||||
for (Map.Entry<UUID, Location> entry : this.safeLocations.entrySet()) {
|
||||
if (entry.getValue().getWorld().equals(event.getWorld())) {
|
||||
toRemove.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
for (UUID playerId : toRemove) {
|
||||
this.safeLocations.remove(playerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package me.konsolas.aac.components;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.util.TPS;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class TPSManager {
|
||||
private final AAC plugin;
|
||||
private final Set<HackType> managedChecks = new HashSet<>();
|
||||
|
||||
public TPSManager(AAC plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
for (HackType hackType : HackType.values()) {
|
||||
if (this.plugin.getConfig().getBoolean(hackType.getName() + ".enabled")) {
|
||||
this.managedChecks.add(hackType);
|
||||
}
|
||||
}
|
||||
|
||||
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new LagCompensationTask(), 20L, 13L);
|
||||
}
|
||||
|
||||
private final class LagCompensationTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
double tps = TPS.getTps();
|
||||
if (tps > 18.5) {
|
||||
for (HackType hackType : TPSManager.this.managedChecks) {
|
||||
TPSManager.this.plugin.checkManager.enableCheck(hackType, true);
|
||||
}
|
||||
} else {
|
||||
TPSManager.this.plugin.logger.log("(TPSManager) TPS dropped to " + tps);
|
||||
if (tps < 17.5) {
|
||||
TPSManager.this.plugin.checkManager.disableCheck(HackType.BADPACKETS, true);
|
||||
}
|
||||
|
||||
if (tps < 17.0) {
|
||||
TPSManager.this.plugin.checkManager.disableCheck(HackType.FIGHTSPEED, true);
|
||||
TPSManager.this.plugin.checkManager.disableCheck(HackType.REACH, true);
|
||||
TPSManager.this.plugin.checkManager.disableCheck(HackType.ANGLE, true);
|
||||
} else if (tps < 16.0) {
|
||||
TPSManager.this.plugin.checkManager.disableCheck(HackType.NORMALMOVEMENTS, true);
|
||||
} else if (tps < 13.0) {
|
||||
TPSManager.this.plugin.logger.log("(TPSManager) TPS is critical");
|
||||
TPSManager.this.plugin.checkManager.disableCheck(HackType.FLY, true);
|
||||
TPSManager.this.plugin.checkManager.disableCheck(HackType.GLIDE, true);
|
||||
} else if (tps < 10.0) {
|
||||
TPSManager.this.plugin.checkManager.disableCheck(HackType.FORCEFIELD, true);
|
||||
TPSManager.this.plugin.checkManager.disableCheck(HackType.SPEED, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package me.konsolas.aac.detectors;
|
||||
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
||||
public interface DamageListener {
|
||||
void onEntityDamageByEntity(EntityDamageByEntityEvent event);
|
||||
|
||||
boolean shouldProcessDamage(EntityDamageByEntityEvent event);
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package me.konsolas.aac.detectors;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.api.PlayerViolationEvent;
|
||||
import me.konsolas.aac.internal.Destroyable;
|
||||
import me.konsolas.aac.util.Ping;
|
||||
import me.konsolas.aac.util.TPS;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public abstract class Detector implements Listener, Destroyable {
|
||||
protected long currentTick = 0L;
|
||||
protected final AAC plugin;
|
||||
public Map<UUID, Integer> violationLevels = new HashMap<>();
|
||||
public Map<UUID, Integer> recentViolationCounts = new HashMap<>();
|
||||
public Map<UUID, Integer> totalViolationCounts = new HashMap<>();
|
||||
protected List<Integer> scheduledTaskIds = new ArrayList<>();
|
||||
protected List<PacketListener> packetListeners = new ArrayList<>();
|
||||
|
||||
public Detector(AAC plugin) {
|
||||
this.initializeOnlinePlayers();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public int getViolationLevel(Player player) {
|
||||
return this.violationLevels.get(player.getUniqueId()) != null ? this.violationLevels.get(player.getUniqueId()) : 0;
|
||||
}
|
||||
|
||||
public int getRecentViolationCount(Player player) {
|
||||
if (player == null) {
|
||||
return 0;
|
||||
} else {
|
||||
return this.recentViolationCounts.get(player.getUniqueId()) != null ? this.recentViolationCounts.get(player.getUniqueId()) : 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int getTotalViolationCount(Player player) {
|
||||
return this.totalViolationCounts.get(player.getUniqueId()) != null ? this.totalViolationCounts.get(player.getUniqueId()) : 0;
|
||||
}
|
||||
|
||||
public final void initializeOnlinePlayers() {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
this.violationLevels.put(player.getUniqueId(), 0);
|
||||
this.recentViolationCounts.put(player.getUniqueId(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
for (int taskId : this.scheduledTaskIds) {
|
||||
Bukkit.getServer().getScheduler().cancelTask(taskId);
|
||||
}
|
||||
|
||||
for (PacketListener listener : this.packetListeners) {
|
||||
ProtocolLibrary.getProtocolManager().removePacketListener(listener);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean recordViolation(UUID playerId, int amount, HackType hackType, String message) {
|
||||
Player player = Bukkit.getPlayer(playerId);
|
||||
PlayerViolationEvent violationEvent = new PlayerViolationEvent(player, hackType, this.getRecentViolationCount(Bukkit.getPlayer(playerId)), message);
|
||||
Bukkit.getServer().getPluginManager().callEvent(violationEvent);
|
||||
if (!violationEvent.isCancelled()) {
|
||||
if (!this.recentViolationCounts.containsKey(playerId)) {
|
||||
this.recentViolationCounts.put(playerId, 1);
|
||||
}
|
||||
|
||||
if (!this.totalViolationCounts.containsKey(playerId)) {
|
||||
this.totalViolationCounts.put(playerId, 1);
|
||||
}
|
||||
|
||||
if (!this.violationLevels.containsKey(playerId)) {
|
||||
this.violationLevels.put(playerId, 1);
|
||||
}
|
||||
|
||||
this.violationLevels.put(playerId, this.violationLevels.get(playerId) + amount);
|
||||
this.recentViolationCounts.put(playerId, this.recentViolationCounts.get(playerId) + 1);
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new ExpireRecentViolationTask(playerId), 1200L);
|
||||
this.totalViolationCounts.put(playerId, this.totalViolationCounts.get(playerId) + 1);
|
||||
this.plugin
|
||||
.logger
|
||||
.log(
|
||||
message
|
||||
+ " [ping:"
|
||||
+ Ping.getPing(player)
|
||||
+ " tps:"
|
||||
+ Math.round(TPS.getTps() * 100.0) / 100.0
|
||||
+ "] VL:"
|
||||
+ this.violationLevels.get(playerId)
|
||||
);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected void decreaseViolationLevel(UUID playerId, int amount) {
|
||||
if (this.violationLevels.containsKey(playerId)) {
|
||||
int updatedLevel = this.violationLevels.get(playerId) - amount;
|
||||
this.violationLevels.put(playerId, updatedLevel < 0 ? 0 : updatedLevel);
|
||||
} else {
|
||||
this.violationLevels.put(playerId, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void setViolationLevel(Player player, int level) {
|
||||
this.violationLevels.put(player.getUniqueId(), level);
|
||||
}
|
||||
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
this.violationLevels.put(event.getPlayer().getUniqueId(), 0);
|
||||
this.recentViolationCounts.put(event.getPlayer().getUniqueId(), 0);
|
||||
}
|
||||
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
this.violationLevels.remove(event.getPlayer().getUniqueId());
|
||||
this.recentViolationCounts.put(event.getPlayer().getUniqueId(), 0);
|
||||
}
|
||||
|
||||
public void onPlayerKick(PlayerKickEvent event) {
|
||||
this.violationLevels.remove(event.getPlayer().getUniqueId());
|
||||
this.recentViolationCounts.put(event.getPlayer().getUniqueId(), 0);
|
||||
}
|
||||
|
||||
public void updateTick(long tick) {
|
||||
this.currentTick = tick;
|
||||
}
|
||||
|
||||
private final class ExpireRecentViolationTask implements Runnable {
|
||||
private final UUID playerId;
|
||||
|
||||
private ExpireRecentViolationTask(UUID playerId) {
|
||||
this.playerId = playerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
int updatedCount = Detector.this.recentViolationCounts.get(this.playerId) - 1;
|
||||
Detector.this.recentViolationCounts.put(this.playerId, updatedCount < 0 ? 0 : updatedCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package me.konsolas.aac.detectors;
|
||||
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
public interface MoveListener {
|
||||
void onPlayerMove(PlayerMoveEvent event, boolean fromOnGround, boolean toOnGround);
|
||||
|
||||
boolean shouldProcessMove(PlayerMoveEvent event);
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
package me.konsolas.aac.detectors.chat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import net.jodah.expiringmap.ExpirationPolicy;
|
||||
import net.jodah.expiringmap.ExpiringMap;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
public final class Spam extends Detector {
|
||||
private final ConcurrentMap<UUID, Integer> messageCounts = new ConcurrentHashMap<>();
|
||||
private final ExpiringMap<UUID, String> lastMessages;
|
||||
private final ExpiringMap<String, Boolean> suspiciousMessages;
|
||||
private final ExpiringMap<UUID, Boolean> recentlyWarnedPlayers;
|
||||
private final ExpiringMap<UUID, Boolean> chatCooldowns;
|
||||
private volatile List<String> whitelist = new ArrayList<>();
|
||||
private int messageLimit = 5;
|
||||
private int chatSpeed = 10;
|
||||
|
||||
public Spam(AAC plugin) {
|
||||
super(plugin);
|
||||
this.messageLimit = this.plugin.getConfig().getInt("spam.message_limit");
|
||||
this.whitelist = this.plugin.getConfig().getStringList("spam.whitelist");
|
||||
this.chatSpeed = this.plugin.getConfig().getInt("spam.chat_speed");
|
||||
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new ResetChatCountTask(), 200L, 200L);
|
||||
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new SpamViolationDecayTask(), 200L, 300L);
|
||||
this.lastMessages = ExpiringMap.builder()
|
||||
.expirationPolicy(ExpirationPolicy.CREATED)
|
||||
.expiration(10L, TimeUnit.SECONDS)
|
||||
.build();
|
||||
this.suspiciousMessages = ExpiringMap.builder()
|
||||
.expirationPolicy(ExpirationPolicy.CREATED)
|
||||
.expiration(5L, TimeUnit.SECONDS)
|
||||
.build();
|
||||
this.recentlyWarnedPlayers = ExpiringMap.builder()
|
||||
.expirationPolicy(ExpirationPolicy.CREATED)
|
||||
.expiration(10L, TimeUnit.SECONDS)
|
||||
.build();
|
||||
this.chatCooldowns = ExpiringMap.builder()
|
||||
.expirationPolicy(ExpirationPolicy.CREATED)
|
||||
.expiration(this.chatSpeed * 50L, TimeUnit.MILLISECONDS)
|
||||
.build();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
|
||||
if (!this.plugin.checkManager.isBypassed(event.getPlayer())) {
|
||||
Player player = event.getPlayer();
|
||||
UUID playerId = player.getUniqueId();
|
||||
if (this.chatCooldowns.containsKey(playerId)) {
|
||||
if (this.recordViolation(playerId, 5, HackType.SPAM, player.getName() + " failed Spam: tried to chat too quickly")) {
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(AAC.messagePrefix + this.plugin.messages.getMessage("spam_too_fast"));
|
||||
}
|
||||
} else {
|
||||
if (this.messageCounts.containsKey(playerId)) {
|
||||
int count = this.messageCounts.get(playerId) + 1;
|
||||
this.messageCounts.put(playerId, count);
|
||||
if (count == this.messageLimit) {
|
||||
if (this.recentlyWarnedPlayers.containsKey(playerId)) {
|
||||
if (this.recordViolation(playerId, 6, HackType.SPAM, player.getName() + " failed Spam: sent too many messages")) {
|
||||
player.sendMessage(AAC.messagePrefix + this.plugin.messages.getMessage("spam_slow_chat"));
|
||||
}
|
||||
} else if (this.recordViolation(playerId, 4, HackType.SPAM, player.getName() + " failed Spam: sent too many messages")) {
|
||||
this.recentlyWarnedPlayers.put(playerId, true);
|
||||
player.sendMessage(AAC.messagePrefix + this.plugin.messages.getMessage("spam_slow_chat"));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String message = event.getMessage();
|
||||
|
||||
for (String allowedPhrase : this.whitelist) {
|
||||
if (isSimilarMessage(allowedPhrase, message)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.lastMessages.containsKey(playerId) && isSimilarMessage(message, this.lastMessages.get(playerId))) {
|
||||
if (this.recentlyWarnedPlayers.containsKey(playerId)) {
|
||||
if (this.recordViolation(playerId, 4, HackType.SPAM, player.getName() + " failed Spam: repeated last message")) {
|
||||
player.sendMessage(AAC.messagePrefix + this.plugin.messages.getMessage("spam_repeat"));
|
||||
}
|
||||
} else if (this.recordViolation(playerId, 2, HackType.SPAM, player.getName() + " failed Spam: repeated last message")) {
|
||||
this.recentlyWarnedPlayers.put(playerId, true);
|
||||
player.sendMessage(AAC.messagePrefix + this.plugin.messages.getMessage("spam_repeat"));
|
||||
}
|
||||
} else {
|
||||
for (String suspicious : this.suspiciousMessages.keySet()) {
|
||||
if (isSimilarMessage(message, suspicious)) {
|
||||
this.suspiciousMessages.put(message, true);
|
||||
if (this.recentlyWarnedPlayers.containsKey(playerId)) {
|
||||
if (this.recordViolation(
|
||||
playerId, 3, HackType.SPAM, player.getName() + " failed Spam: tried to repeat a suspicious message (" + message + ")"
|
||||
)) {
|
||||
player.sendMessage(AAC.messagePrefix + this.plugin.messages.getMessage("spam_repeat_other"));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (this.recordViolation(
|
||||
playerId, 2, HackType.SPAM, player.getName() + " failed Spam: tried to repeat a suspicious message (" + message + ")"
|
||||
)) {
|
||||
player.sendMessage(AAC.messagePrefix + this.plugin.messages.getMessage("spam_repeat_other"));
|
||||
event.setCancelled(true);
|
||||
this.recentlyWarnedPlayers.put(playerId, true);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (String previousMessage : this.lastMessages.values()) {
|
||||
if (isSimilarMessage(message, previousMessage)) {
|
||||
this.suspiciousMessages.put(message, true);
|
||||
}
|
||||
}
|
||||
|
||||
this.lastMessages.put(playerId, message);
|
||||
this.chatCooldowns.put(playerId, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isSimilarMessage(String first, String second) {
|
||||
if (first.equalsIgnoreCase(second)) {
|
||||
return true;
|
||||
} else if (first.length() < 3 || second.length() < 3) {
|
||||
return false;
|
||||
} else {
|
||||
String normalizedFirst = first.toLowerCase().replaceAll("[^a-z]", "");
|
||||
String normalizedSecond = second.toLowerCase().replaceAll("[^a-z]", "");
|
||||
return !normalizedFirst.isEmpty() && !normalizedSecond.isEmpty() && normalizedFirst.equals(normalizedSecond);
|
||||
}
|
||||
}
|
||||
|
||||
private final class ResetChatCountTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
Spam.this.messageCounts.put(player.getUniqueId(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class SpamViolationDecayTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
Spam.this.decreaseViolationLevel(player.getUniqueId(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package me.konsolas.aac.detectors.combat;
|
||||
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.DamageListener;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import me.konsolas.aac.util.general.NumberUtil;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public final class Angle extends Detector implements DamageListener {
|
||||
private double maxDiff = 0.2;
|
||||
private double maxPlayerDiff = 0.1;
|
||||
private boolean cancelFalseHit = true;
|
||||
private double minDist = 3.0;
|
||||
|
||||
public Angle(AAC plugin) {
|
||||
super(plugin);
|
||||
this.maxDiff = this.plugin.getConfig().getDouble("angle.max_diff", this.maxDiff);
|
||||
this.maxPlayerDiff = this.plugin.getConfig().getDouble("angle.max_player_diff", this.maxPlayerDiff);
|
||||
this.cancelFalseHit = this.plugin.getConfig().getBoolean("angle.cancel_false_hit", this.cancelFalseHit);
|
||||
this.minDist = this.plugin.getConfig().getDouble("angle.min_dist", this.minDist);
|
||||
}
|
||||
|
||||
public static double getLookDotProduct(Location attackerLoc, Location targetLoc) {
|
||||
attackerLoc.setY(1.0);
|
||||
targetLoc.setY(1.0);
|
||||
Vector toTarget = targetLoc.toVector().subtract(attackerLoc.toVector());
|
||||
Location horizontalLook = attackerLoc.clone();
|
||||
horizontalLook.setPitch(0.0F);
|
||||
Vector lookDirection = horizontalLook.getDirection();
|
||||
return toTarget.normalize().dot(lookDirection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldProcessDamage(EntityDamageByEntityEvent event) {
|
||||
return event.getCause() != DamageCause.THORNS && event.getDamager().getType() == EntityType.PLAYER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
Player attacker = (Player)event.getDamager();
|
||||
Location attackerLoc = attacker.getLocation();
|
||||
Location targetLoc = event.getEntity().getLocation();
|
||||
attackerLoc.setY(1.0);
|
||||
targetLoc.setY(1.0);
|
||||
double horizontalDistance = attackerLoc.distance(targetLoc);
|
||||
if (!(horizontalDistance < this.minDist)) {
|
||||
double dotProduct = getLookDotProduct(attackerLoc, targetLoc);
|
||||
if (event.getEntity().getType() == EntityType.PLAYER) {
|
||||
this.plugin
|
||||
.logger
|
||||
.logPlayerDebug(
|
||||
attacker,
|
||||
"(Angle) EntityDamageByEntityEvent dot[n:" + (1.0 - this.maxPlayerDiff) + ",m" + (1.0 + this.maxPlayerDiff) + ",r:" + dotProduct + "]"
|
||||
);
|
||||
if (!NumberUtil.approximatelyEqual(dotProduct, 1.0, this.maxPlayerDiff * 4.0 / horizontalDistance)) {
|
||||
if (this.recordViolation(
|
||||
attacker.getUniqueId(), 1, HackType.ANGLE, attacker.getName() + " failed Angle: tried to attack an entity out of his line of sight"
|
||||
)
|
||||
&& this.cancelFalseHit) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else {
|
||||
this.decreaseViolationLevel(attacker.getUniqueId(), 1);
|
||||
}
|
||||
} else {
|
||||
this.plugin
|
||||
.logger
|
||||
.logPlayerDebug(
|
||||
attacker, "(Angle) EntityDamageByEntityEvent dot[n:" + (1.0 - this.maxDiff) + ",m" + (1.0 + this.maxDiff) + ",r:" + dotProduct + "]"
|
||||
);
|
||||
if (!NumberUtil.approximatelyEqual(dotProduct, 1.0, this.maxDiff)) {
|
||||
if (this.recordViolation(
|
||||
attacker.getUniqueId(), 1, HackType.ANGLE, attacker.getName() + " failed Angle: tried to attack an entity out of his line of sight"
|
||||
)
|
||||
&& this.cancelFalseHit) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else {
|
||||
this.decreaseViolationLevel(attacker.getUniqueId(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package me.konsolas.aac.detectors.combat;
|
||||
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.DamageListener;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import me.konsolas.aac.util.general.ItemUseUtil;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
||||
public final class CombatImpossible extends Detector implements DamageListener {
|
||||
private boolean cancelDead = true;
|
||||
private boolean cancelUsingItem = true;
|
||||
|
||||
public CombatImpossible(AAC plugin) {
|
||||
super(plugin);
|
||||
this.cancelDead = this.plugin.getConfig().getBoolean("combatimpossible.cancel_dead", this.cancelDead);
|
||||
this.cancelUsingItem = this.plugin.getConfig().getBoolean("combatimpossible.cancel_using_item", this.cancelUsingItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldProcessDamage(EntityDamageByEntityEvent event) {
|
||||
return event.getDamager().getType() == EntityType.PLAYER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
Player attacker = (Player)event.getDamager();
|
||||
if (attacker.isDead() && this.cancelDead) {
|
||||
if (this.recordViolation(
|
||||
attacker.getUniqueId(), 1, HackType.COMBATIMPOSSIBLE, attacker.getName() + " failed CombatImpossible: Tried to attack whilst dead"
|
||||
)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (ItemUseUtil.isUsingItem(attacker)
|
||||
&& this.cancelUsingItem
|
||||
&& this.recordViolation(
|
||||
attacker.getUniqueId(), 1, HackType.COMBATIMPOSSIBLE, attacker.getName() + " failed CombatImpossible: Tried to attack whilst using an item"
|
||||
)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package me.konsolas.aac.detectors.combat;
|
||||
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.DamageListener;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import me.konsolas.aac.util.ground.GroundUtil;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public final class Criticals extends Detector implements DamageListener {
|
||||
private boolean cancelFalseHit = false;
|
||||
|
||||
public Criticals(AAC plugin) {
|
||||
super(plugin);
|
||||
this.cancelFalseHit = this.plugin.getConfig().getBoolean("criticals.cancel_false_hit", this.cancelFalseHit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldProcessDamage(EntityDamageByEntityEvent event) {
|
||||
return event.getDamager().getType() == EntityType.PLAYER && !((Player)event.getDamager()).isFlying();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
Player attacker = (Player)event.getDamager();
|
||||
if (this.isCriticalHit(attacker)) {
|
||||
this.plugin
|
||||
.logger
|
||||
.logPlayerDebug(
|
||||
attacker,
|
||||
"(Criticals) EntityDamageByEntityEvent critical location[r:"
|
||||
+ attacker.getLocation()
|
||||
+ "] velocity[r:"
|
||||
+ attacker.getVelocity()
|
||||
+ "] blockOn[r:"
|
||||
+ attacker.getLocation().subtract(0.0, 1.0, 0.0).getBlock().getType()
|
||||
+ "]"
|
||||
);
|
||||
if ((
|
||||
attacker.getLocation().getY() % 1.0 == 0.0
|
||||
&& GroundUtil.isSolidFullBlock(attacker.getLocation().subtract(0.0, 1.0, 0.0).getBlock())
|
||||
|| attacker.getLocation().getY() % 0.5 == 0.0
|
||||
&& GroundUtil.isSlabOrLowBlock(attacker.getLocation().getBlock().getType())
|
||||
&& !this.plugin.checkManager.isBypassed(attacker)
|
||||
)
|
||||
&& this.recordViolation(
|
||||
attacker.getUniqueId(), 2, HackType.CRITICALS, attacker.getName() + " failed Criticals: tried to perform a critical hit whilst on the ground"
|
||||
)
|
||||
&& this.cancelFalseHit) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else {
|
||||
this.plugin
|
||||
.logger
|
||||
.logPlayerDebug(
|
||||
attacker,
|
||||
"(Criticals) EntityDamageByEntityEvent !critical location[r:"
|
||||
+ attacker.getLocation()
|
||||
+ "] velocity[r:"
|
||||
+ attacker.getVelocity()
|
||||
+ "] blockOn[r:"
|
||||
+ attacker.getLocation().subtract(0.0, 1.0, 0.0).getBlock().getType()
|
||||
+ "]"
|
||||
);
|
||||
if (attacker.getLocation().getY() % 1.0 == 0.0 && GroundUtil.isSolidFullBlock(attacker.getLocation().subtract(0.0, 1.0, 0.0).getBlock())) {
|
||||
this.decreaseViolationLevel(attacker.getUniqueId(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isCriticalHit(Player player) {
|
||||
return player.getFallDistance() > 0.0F
|
||||
&& !player.isOnGround()
|
||||
&& !player.isInsideVehicle()
|
||||
&& !player.hasPotionEffect(PotionEffectType.BLINDNESS)
|
||||
&& !GroundUtil.isClimbable(player)
|
||||
&& !GroundUtil.isInLiquid(player);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package me.konsolas.aac.detectors.combat;
|
||||
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerItemConsumeEvent;
|
||||
|
||||
public final class FastUse extends Detector {
|
||||
private int msToUse = 2700;
|
||||
|
||||
public FastUse(AAC plugin) {
|
||||
super(plugin);
|
||||
this.msToUse = this.plugin.getConfig().getInt("fastuse.ms_to_use");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerItemConsume(PlayerItemConsumeEvent event) {
|
||||
if (!this.plugin.checkManager.isBypassed(event.getPlayer())) {
|
||||
long elapsedMs = System.currentTimeMillis() - this.plugin.playerStateTracker.getLastInteractionTime(event.getPlayer());
|
||||
if (elapsedMs < this.msToUse) {
|
||||
if (this.recordViolation(
|
||||
event.getPlayer().getUniqueId(),
|
||||
1,
|
||||
HackType.FASTUSE,
|
||||
event.getPlayer().getName() + " failed FastUse: Tried to consume an item too quickly (" + elapsedMs + "ms)"
|
||||
)) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().getInventory().setHeldItemSlot((event.getPlayer().getInventory().getHeldItemSlot() + 1) % 9);
|
||||
}
|
||||
} else {
|
||||
this.decreaseViolationLevel(event.getPlayer().getUniqueId(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
package me.konsolas.aac.detectors.combat;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.EntityShootBowEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public final class Fastbow extends Detector {
|
||||
private int shotsFiredThreshold = 2;
|
||||
private double minForce = 0.5;
|
||||
private final Map<UUID, Integer> shotCounts = new HashMap<>();
|
||||
private final Set<UUID> cooldownPlayers = new HashSet<>();
|
||||
|
||||
public Fastbow(AAC plugin) {
|
||||
super(plugin);
|
||||
this.minForce = this.plugin.getConfig().getDouble("fastbow.min_force", this.minForce);
|
||||
this.shotsFiredThreshold = this.plugin.getConfig().getInt("fastbow.shots_fired_threshold", this.shotsFiredThreshold);
|
||||
this.scheduledTaskIds.add(Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new FastBowSampleTask(), 30L, 20L));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityShootBow(EntityShootBowEvent event) {
|
||||
if (event.getEntity().getType() == EntityType.PLAYER) {
|
||||
Player shooter = (Player)event.getEntity();
|
||||
if (this.plugin.checkManager.isBypassed(shooter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
UUID playerId = shooter.getUniqueId();
|
||||
if (this.cooldownPlayers.contains(playerId)) {
|
||||
this.plugin
|
||||
.logger
|
||||
.logPlayerDebug(
|
||||
shooter,
|
||||
"(FastBow) EntityShootBowEvent !allowed force[n:"
|
||||
+ this.minForce
|
||||
+ ",r:"
|
||||
+ event.getForce()
|
||||
+ "] + totalShots[t:"
|
||||
+ this.shotsFiredThreshold
|
||||
+ ",r:"
|
||||
+ this.shotCounts.get(playerId)
|
||||
);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getForce() > this.minForce) {
|
||||
if (!this.shotCounts.containsKey(playerId)) {
|
||||
this.shotCounts.put(playerId, 1);
|
||||
} else {
|
||||
this.shotCounts.put(playerId, this.shotCounts.get(playerId) + 1);
|
||||
}
|
||||
|
||||
if (this.shotCounts.get(playerId) > this.shotsFiredThreshold) {
|
||||
event.setCancelled(true);
|
||||
this.plugin
|
||||
.logger
|
||||
.logPlayerDebug(
|
||||
shooter,
|
||||
"(FastBow) EntityShootBowEvent !allowed force[n:"
|
||||
+ this.minForce
|
||||
+ ",r:"
|
||||
+ event.getForce()
|
||||
+ "] + totalShots[t:"
|
||||
+ this.shotsFiredThreshold
|
||||
+ ",r:"
|
||||
+ this.shotCounts.get(playerId)
|
||||
);
|
||||
} else {
|
||||
this.plugin
|
||||
.logger
|
||||
.logPlayerDebug(
|
||||
shooter,
|
||||
"(FastBow) EntityShootBowEvent allowed force[n:"
|
||||
+ this.minForce
|
||||
+ ",r:"
|
||||
+ event.getForce()
|
||||
+ "] + totalShots[t:"
|
||||
+ this.shotsFiredThreshold
|
||||
+ ",r:"
|
||||
+ this.shotCounts.get(playerId)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@Override
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
super.onPlayerJoin(event);
|
||||
this.shotCounts.put(event.getPlayer().getUniqueId(), 0);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@Override
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
super.onPlayerQuit(event);
|
||||
this.shotCounts.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
private final class FastBowSampleTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
for (UUID playerId : Fastbow.this.shotCounts.keySet()) {
|
||||
int shots = Fastbow.this.shotCounts.get(playerId);
|
||||
if (shots > Fastbow.this.shotsFiredThreshold && !Fastbow.this.cooldownPlayers.contains(playerId)) {
|
||||
if (Fastbow.this.recordViolation(
|
||||
playerId,
|
||||
4,
|
||||
HackType.FASTBOW,
|
||||
Bukkit.getOfflinePlayer(playerId).getName() + " failed Fastbow: tried to fire " + shots + " arrows in 1 second."
|
||||
)) {
|
||||
Fastbow.this.cooldownPlayers.add(playerId);
|
||||
Bukkit.getPlayer(playerId).sendMessage(AAC.messagePrefix + Fastbow.this.plugin.messages.getMessage("too_many_shots"));
|
||||
Bukkit.getServer()
|
||||
.getScheduler()
|
||||
.scheduleSyncDelayedTask(Fastbow.this.plugin, new ExpireFastBowCooldownTask(playerId), 100L);
|
||||
}
|
||||
} else if (!Fastbow.this.cooldownPlayers.contains(playerId)) {
|
||||
Fastbow.this.decreaseViolationLevel(playerId, 1);
|
||||
}
|
||||
|
||||
Fastbow.this.shotCounts.put(playerId, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class ExpireFastBowCooldownTask implements Runnable {
|
||||
private final UUID playerId;
|
||||
|
||||
private ExpireFastBowCooldownTask(UUID playerId) {
|
||||
this.playerId = playerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Fastbow.this.cooldownPlayers.remove(this.playerId);
|
||||
Player player = Bukkit.getPlayer(this.playerId);
|
||||
if (player != null) {
|
||||
player.sendMessage(AAC.messagePrefix + Fastbow.this.plugin.messages.getMessage("allow_bow"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
package me.konsolas.aac.detectors.combat;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.PacketType.Play.Client;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.Map.Entry;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import me.konsolas.aac.internal.packetwrapper.WrapperPlayClientUseEntity;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public final class FightSpeed extends Detector {
|
||||
private int maxHitsPerSecond = 12;
|
||||
private int maxInteractPerSecond = 25;
|
||||
private boolean consistentCheck = true;
|
||||
private final Map<UUID, Integer> attackCounts = new HashMap<>();
|
||||
private final Map<UUID, Integer> interactCounts = new HashMap<>();
|
||||
private final Map<UUID, Integer> armSwingCounts = new HashMap<>();
|
||||
private final Map<UUID, Integer> previousArmSwingCounts = new HashMap<>();
|
||||
private final Map<UUID, Integer> secondPreviousArmSwingCounts = new HashMap<>();
|
||||
|
||||
public FightSpeed(AAC plugin) {
|
||||
super(plugin);
|
||||
this.maxHitsPerSecond = this.plugin.getConfig().getInt("fightspeed.max_hits_per_second", this.maxHitsPerSecond);
|
||||
this.maxInteractPerSecond = this.plugin.getConfig().getInt("fightspeed.max_interact_per_second", this.maxInteractPerSecond);
|
||||
this.consistentCheck = this.plugin.getConfig().getBoolean("fightspeed.consistent_check", this.consistentCheck);
|
||||
FightSpeedPacketListener listener = new FightSpeedPacketListener(this.plugin, Client.USE_ENTITY, Client.ARM_ANIMATION);
|
||||
this.packetListeners.add(listener);
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(listener);
|
||||
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new FightSpeedViolationDecayTask(), 10L, 59L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTick(long tick) {
|
||||
super.updateTick(tick);
|
||||
if (tick % 20L == 0L) {
|
||||
for (Entry<UUID, Integer> entry : this.attackCounts.entrySet()) {
|
||||
UUID playerId = entry.getKey();
|
||||
int attacks = entry.getValue();
|
||||
Player player = Bukkit.getPlayer(playerId);
|
||||
if (attacks > this.maxHitsPerSecond) {
|
||||
if (attacks != 20 && attacks != 21 && attacks != 19) {
|
||||
this.recordViolation(
|
||||
playerId,
|
||||
attacks - this.maxHitsPerSecond + 3,
|
||||
HackType.FIGHTSPEED,
|
||||
player.getName() + " failed FightSpeed: reached a CPS of " + attacks
|
||||
);
|
||||
} else {
|
||||
this.recordViolation(
|
||||
playerId,
|
||||
(attacks - this.maxHitsPerSecond + 3) * 2,
|
||||
HackType.FIGHTSPEED,
|
||||
player.getName() + " failed FightSpeed: reached a CPS of " + attacks
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
this.attackCounts.put(playerId, 0);
|
||||
}
|
||||
|
||||
for (Entry<UUID, Integer> entry : this.interactCounts.entrySet()) {
|
||||
UUID playerId = entry.getKey();
|
||||
int interactions = entry.getValue();
|
||||
Player player = Bukkit.getPlayer(playerId);
|
||||
if (interactions > this.maxInteractPerSecond) {
|
||||
this.recordViolation(
|
||||
playerId,
|
||||
interactions - this.maxHitsPerSecond + 3,
|
||||
HackType.FIGHTSPEED,
|
||||
player.getName() + " failed FightSpeed: interacting " + interactions + " times per second"
|
||||
);
|
||||
}
|
||||
|
||||
this.interactCounts.put(playerId, 0);
|
||||
}
|
||||
|
||||
for (Entry<UUID, Integer> entry : this.armSwingCounts.entrySet()) {
|
||||
UUID playerId = entry.getKey();
|
||||
int swings = entry.getValue();
|
||||
Player player = Bukkit.getPlayer(playerId);
|
||||
if (this.previousArmSwingCounts.get(playerId) != null && this.secondPreviousArmSwingCounts.get(playerId) != null) {
|
||||
int previousSwings = this.previousArmSwingCounts.get(playerId);
|
||||
int secondPreviousSwings = this.secondPreviousArmSwingCounts.get(playerId);
|
||||
if (swings < 9) {
|
||||
this.secondPreviousArmSwingCounts.put(playerId, this.previousArmSwingCounts.get(playerId));
|
||||
this.previousArmSwingCounts.put(playerId, swings);
|
||||
this.armSwingCounts.put(playerId, 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (this.consistentCheck && previousSwings == swings && swings == secondPreviousSwings) {
|
||||
if (previousSwings != 10 && previousSwings != 20) {
|
||||
this.recordViolation(
|
||||
playerId, 3, HackType.FIGHTSPEED, player.getName() + " failed FightSpeed: constantly clicking at a CPS of " + swings
|
||||
);
|
||||
} else {
|
||||
this.recordViolation(
|
||||
playerId, 7, HackType.FIGHTSPEED, player.getName() + " failed FightSpeed: constantly clicking at a CPS of " + swings
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.secondPreviousArmSwingCounts.put(playerId, this.previousArmSwingCounts.get(playerId));
|
||||
this.previousArmSwingCounts.put(playerId, swings);
|
||||
this.armSwingCounts.put(playerId, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
super.onPlayerJoin(event);
|
||||
this.attackCounts.put(event.getPlayer().getUniqueId(), 0);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@Override
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
super.onPlayerQuit(event);
|
||||
this.attackCounts.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@Override
|
||||
public void onPlayerKick(PlayerKickEvent event) {
|
||||
super.onPlayerKick(event);
|
||||
this.attackCounts.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
private final class FightSpeedPacketListener extends PacketAdapter {
|
||||
private FightSpeedPacketListener(Plugin plugin, PacketType... packetTypes) {
|
||||
super(plugin, packetTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (!FightSpeed.this.plugin.checkManager.isBypassed(player)) {
|
||||
UUID playerId = player.getUniqueId();
|
||||
if (event.getPacketType() == Client.USE_ENTITY) {
|
||||
if (new WrapperPlayClientUseEntity(event.getPacket()).getAction() == EntityUseAction.ATTACK) {
|
||||
FightSpeed.this.attackCounts.put(playerId, FightSpeed.this.attackCounts.getOrDefault(playerId, 0) + 1);
|
||||
} else {
|
||||
FightSpeed.this.interactCounts.put(playerId, FightSpeed.this.interactCounts.getOrDefault(playerId, 0) + 1);
|
||||
}
|
||||
} else if (FightSpeed.this.plugin.combatTracker.isInCombat(player)) {
|
||||
FightSpeed.this.armSwingCounts.put(playerId, FightSpeed.this.armSwingCounts.getOrDefault(playerId, 0) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class FightSpeedViolationDecayTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : FightSpeed.this.plugin.getServer().getOnlinePlayers()) {
|
||||
FightSpeed.this.decreaseViolationLevel(player.getUniqueId(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
package me.konsolas.aac.detectors.combat;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.PacketType.Play.Client;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import me.konsolas.aac.internal.packetwrapper.WrapperPlayClientUseEntity;
|
||||
import me.konsolas.aac.util.ForcefieldDecoyManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public final class Forcefield extends Detector {
|
||||
private static boolean sendDamageAnimation = true;
|
||||
private final Map<UUID, ForcefieldDecoyManager> playerDecoys = new HashMap<>();
|
||||
private final ConcurrentMap<UUID, Integer> weightedDecoyHitCounts = new ConcurrentHashMap<>();
|
||||
private final ConcurrentMap<UUID, Integer> decoyHitCounts = new ConcurrentHashMap<>();
|
||||
private final ConcurrentMap<UUID, Long> lastDamageAnimationTimes = new ConcurrentHashMap<>();
|
||||
|
||||
public Forcefield(AAC plugin) {
|
||||
super(plugin);
|
||||
ForceFieldPacketListener listener = new ForceFieldPacketListener(
|
||||
this.plugin, ListenerPriority.LOWEST, WrapperPlayClientUseEntity.TYPE, Client.ARM_ANIMATION
|
||||
);
|
||||
this.packetListeners.add(listener);
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(listener);
|
||||
this.scheduledTaskIds.add(Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new ForceFieldSampleTask(), 35L, 36L));
|
||||
this.scheduledTaskIds.add(Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new ForceFieldDecoyUpdateTask(), 30L, 602L));
|
||||
ForcefieldDecoyManager.loadConfig(this.plugin);
|
||||
sendDamageAnimation = this.plugin.getConfig().getBoolean("forcefield.magic.send_damaged_animation");
|
||||
}
|
||||
|
||||
public ForcefieldDecoyManager removeDecoys(UUID playerId) {
|
||||
return this.playerDecoys.containsKey(playerId) ? this.playerDecoys.remove(playerId) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
super.destroy();
|
||||
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
ForcefieldDecoyManager decoys = this.removeDecoys(player.getUniqueId());
|
||||
if (decoys != null) {
|
||||
decoys.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void spawnDecoys(Player player) {
|
||||
ForcefieldDecoyManager decoys = new ForcefieldDecoyManager(this.plugin, player, this);
|
||||
this.playerDecoys.put(player.getUniqueId(), decoys);
|
||||
decoys.spawn();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@Override
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
super.onPlayerQuit(event);
|
||||
ForcefieldDecoyManager decoys = this.removeDecoys(event.getPlayer().getUniqueId());
|
||||
if (decoys != null) {
|
||||
decoys.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@Override
|
||||
public void onPlayerKick(PlayerKickEvent event) {
|
||||
super.onPlayerKick(event);
|
||||
ForcefieldDecoyManager decoys = this.removeDecoys(event.getPlayer().getUniqueId());
|
||||
if (decoys != null) {
|
||||
decoys.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
private final class ForceFieldPacketListener extends PacketAdapter {
|
||||
private ForceFieldPacketListener(Plugin plugin, ListenerPriority listenerPriority, PacketType... packetTypes) {
|
||||
super(plugin, listenerPriority, packetTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
if (event.getPacketType() == WrapperPlayClientUseEntity.TYPE) {
|
||||
WrapperPlayClientUseEntity packet = new WrapperPlayClientUseEntity(event.getPacket());
|
||||
int targetId = packet.getTargetID();
|
||||
Player player = event.getPlayer();
|
||||
UUID playerId = player.getUniqueId();
|
||||
if (Forcefield.this.playerDecoys.containsKey(playerId) && packet.getAction().equals(EntityUseAction.ATTACK)) {
|
||||
ForcefieldDecoyManager decoys = Forcefield.this.playerDecoys.get(playerId);
|
||||
if (decoys.isSideDecoyId(targetId)) {
|
||||
Forcefield.this.weightedDecoyHitCounts.putIfAbsent(playerId, 0);
|
||||
Forcefield.this.weightedDecoyHitCounts.put(playerId, Forcefield.this.weightedDecoyHitCounts.get(playerId) + 1);
|
||||
Forcefield.this.decoyHitCounts.putIfAbsent(playerId, 0);
|
||||
Forcefield.this.decoyHitCounts.put(playerId, Forcefield.this.decoyHitCounts.get(playerId) + 1);
|
||||
event.setCancelled(true);
|
||||
} else if (decoys.isHeadDecoyId(targetId)) {
|
||||
Forcefield.this.weightedDecoyHitCounts.putIfAbsent(playerId, 0);
|
||||
Forcefield.this.weightedDecoyHitCounts.put(playerId, Forcefield.this.weightedDecoyHitCounts.get(playerId) + 2);
|
||||
Forcefield.this.decoyHitCounts.putIfAbsent(playerId, 0);
|
||||
Forcefield.this.decoyHitCounts.put(playerId, Forcefield.this.decoyHitCounts.get(playerId) + 1);
|
||||
event.setCancelled(true);
|
||||
if (Forcefield.sendDamageAnimation) {
|
||||
if (Forcefield.this.lastDamageAnimationTimes.containsKey(playerId)) {
|
||||
if (System.currentTimeMillis() - 500L > Forcefield.this.lastDamageAnimationTimes.get(playerId)) {
|
||||
ForcefieldDecoyManager.createDamageStatusPacket(targetId).sendPacket(player);
|
||||
Forcefield.this.lastDamageAnimationTimes.put(playerId, System.currentTimeMillis());
|
||||
}
|
||||
} else {
|
||||
Forcefield.this.lastDamageAnimationTimes.put(playerId, System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class ForceFieldSampleTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
if (!Forcefield.this.plugin.checkManager.isBypassed(player) && !player.getGameMode().equals(GameMode.SPECTATOR)) {
|
||||
UUID playerId = player.getUniqueId();
|
||||
if (Forcefield.this.weightedDecoyHitCounts.containsKey(playerId)) {
|
||||
int weightedHits = Forcefield.this.weightedDecoyHitCounts.get(playerId);
|
||||
if (weightedHits > 4) {
|
||||
Forcefield.this.recordViolation(
|
||||
playerId,
|
||||
(weightedHits - 2) * 2,
|
||||
HackType.FORCEFIELD,
|
||||
player.getName() + " failed Forcefield: hit " + Forcefield.this.decoyHitCounts.get(playerId) + " players when tested"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Forcefield.this.weightedDecoyHitCounts.put(playerId, 0);
|
||||
Forcefield.this.decoyHitCounts.put(playerId, 0);
|
||||
Forcefield.this.decreaseViolationLevel(playerId, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class ForceFieldDecoyUpdateTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
if (!Forcefield.this.plugin.checkManager.isBypassed(player) && !player.getGameMode().equals(GameMode.SPECTATOR)) {
|
||||
Forcefield.this.spawnDecoys(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
package me.konsolas.aac.detectors.combat;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.DamageListener;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import me.konsolas.aac.heuristics.combat.AccuracyHeuristic;
|
||||
import me.konsolas.aac.heuristics.combat.AimbotHeuristic;
|
||||
import me.konsolas.aac.heuristics.combat.ReachHeuristic;
|
||||
import me.konsolas.aac.internal.packetwrapper.WrapperPlayClientUseEntity;
|
||||
import me.konsolas.aac.util.CombatDecoyPair;
|
||||
import me.konsolas.aac.util.DecoyResultCallback;
|
||||
import me.konsolas.aac.util.EntityTargetCategories;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public final class KillauraCombined extends Detector implements DamageListener {
|
||||
private int npcCheckChance = 100;
|
||||
private int npcCheckDelayTicks = 8;
|
||||
private double minimumCheckDistance = 2.7;
|
||||
private int npcViolationMultiplier = 6;
|
||||
private int combatSuspensionTicks = 12;
|
||||
private boolean randomNpcType = true;
|
||||
private final Map<UUID, CombatDecoyPair> activeNpcChecks = new HashMap<>();
|
||||
private final Set<UUID> suspendedCombatPlayers = new HashSet<>();
|
||||
private final AimbotHeuristic aimbotHeuristic;
|
||||
private final ReachHeuristic reachHeuristic;
|
||||
private final AccuracyHeuristic accuracyHeuristic;
|
||||
private int aimbotThreshold = 80;
|
||||
private int reachThreshold = 80;
|
||||
private int accuracyThreshold = 80;
|
||||
|
||||
public KillauraCombined(AAC plugin) {
|
||||
super(plugin);
|
||||
this.npcCheckChance = this.plugin.getConfig().getInt("killaura.npc.check_chance", this.npcCheckChance);
|
||||
this.npcCheckDelayTicks = this.plugin.getConfig().getInt("killaura.npc.check_delay", this.npcCheckDelayTicks);
|
||||
this.minimumCheckDistance = this.plugin.getConfig().getDouble("killaura.npc.min_dist", this.minimumCheckDistance);
|
||||
this.npcViolationMultiplier = this.plugin.getConfig().getInt("killaura.npc.npc_multiplier", this.npcViolationMultiplier);
|
||||
this.combatSuspensionTicks = this.plugin.getConfig().getInt("killaura.npc.suspended_combat_time", this.combatSuspensionTicks);
|
||||
this.randomNpcType = this.plugin.getConfig().getBoolean("killaura.random_type", this.randomNpcType);
|
||||
this.aimbotThreshold = this.plugin.getConfig().getInt("killaura.aimbot", this.aimbotThreshold);
|
||||
this.reachThreshold = this.plugin.getConfig().getInt("killaura.reach", this.reachThreshold);
|
||||
this.accuracyThreshold = this.plugin.getConfig().getInt("killaura.accuracy", this.accuracyThreshold);
|
||||
this.scheduledTaskIds.add(Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new KillAuraViolationDecayTask(), 100L, 60L));
|
||||
CombatDecoyPair.loadConfig(this.plugin);
|
||||
KillAuraPacketListener listener = new KillAuraPacketListener(this.plugin, WrapperPlayClientUseEntity.TYPE);
|
||||
this.packetListeners.add(listener);
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(listener);
|
||||
this.aimbotHeuristic = new AimbotHeuristic(this.plugin);
|
||||
this.reachHeuristic = new ReachHeuristic(this.plugin);
|
||||
this.accuracyHeuristic = new AccuracyHeuristic(this.plugin);
|
||||
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new KillAuraHeuristicScanTask(), 31L, 29L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldProcessDamage(EntityDamageByEntityEvent event) {
|
||||
return event.getDamager().getType() == EntityType.PLAYER
|
||||
&& EntityTargetCategories.isKillauraTarget(event.getEntity().getType())
|
||||
&& !this.activeNpcChecks.containsKey(event.getDamager().getUniqueId())
|
||||
&& !(event.getDamager().getLocation().distance(event.getEntity().getLocation()) < this.minimumCheckDistance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
if (AAC.random.nextInt(100) < this.npcCheckChance) {
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new StartKillAuraDecoyTask(event), this.npcCheckDelayTicks);
|
||||
}
|
||||
}
|
||||
|
||||
private EntityType chooseRandomNpcType() {
|
||||
switch (AAC.random.nextInt(6)) {
|
||||
case 0:
|
||||
return EntityType.PLAYER;
|
||||
case 1:
|
||||
return EntityType.VILLAGER;
|
||||
case 2:
|
||||
return EntityType.ZOMBIE;
|
||||
case 3:
|
||||
return EntityType.SKELETON;
|
||||
case 4:
|
||||
return EntityType.PIG_ZOMBIE;
|
||||
case 5:
|
||||
return EntityType.WITCH;
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
super.onPlayerQuit(event);
|
||||
UUID playerId = event.getPlayer().getUniqueId();
|
||||
if (this.activeNpcChecks.containsKey(playerId)) {
|
||||
this.activeNpcChecks.get(playerId).destroy();
|
||||
this.activeNpcChecks.remove(playerId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerKick(PlayerKickEvent event) {
|
||||
super.onPlayerKick(event);
|
||||
UUID playerId = event.getPlayer().getUniqueId();
|
||||
if (this.activeNpcChecks.containsKey(playerId)) {
|
||||
this.activeNpcChecks.get(playerId).destroy();
|
||||
this.activeNpcChecks.remove(playerId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
super.destroy();
|
||||
this.aimbotHeuristic.destroy();
|
||||
}
|
||||
|
||||
private final class KillAuraViolationDecayTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
KillauraCombined.this.decreaseViolationLevel(player.getUniqueId(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class KillAuraPacketListener extends PacketAdapter {
|
||||
private KillAuraPacketListener(Plugin plugin, PacketType... packetTypes) {
|
||||
super(plugin, packetTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
if (event.getPacketType() == WrapperPlayClientUseEntity.TYPE
|
||||
&& KillauraCombined.this.suspendedCombatPlayers.contains(event.getPlayer().getUniqueId())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class KillAuraHeuristicScanTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
if (!KillauraCombined.this.plugin.checkManager.isBypassed(player)) {
|
||||
int aimbotProbability = KillauraCombined.this.aimbotHeuristic.getProbability(player);
|
||||
if (aimbotProbability > KillauraCombined.this.aimbotThreshold) {
|
||||
KillauraCombined.this.recordViolation(
|
||||
player.getUniqueId(),
|
||||
aimbotProbability / 5 + 2,
|
||||
HackType.KILLAURA,
|
||||
player.getName() + " failed KillauraCombined: (AimbotHeuristic) Chance of hacking = " + aimbotProbability
|
||||
);
|
||||
}
|
||||
|
||||
int reachProbability = KillauraCombined.this.reachHeuristic.getProbability(player);
|
||||
if (reachProbability > KillauraCombined.this.reachThreshold) {
|
||||
KillauraCombined.this.recordViolation(
|
||||
player.getUniqueId(),
|
||||
reachProbability / 5 + 2,
|
||||
HackType.KILLAURA,
|
||||
player.getName() + " failed KillauraCombined: (ReachHeuristic) Chance of hacking = " + reachProbability
|
||||
);
|
||||
}
|
||||
|
||||
int accuracyProbability = KillauraCombined.this.accuracyHeuristic.getProbability(player);
|
||||
if (accuracyProbability > KillauraCombined.this.accuracyThreshold) {
|
||||
KillauraCombined.this.recordViolation(
|
||||
player.getUniqueId(),
|
||||
accuracyProbability / 5 + 2,
|
||||
HackType.KILLAURA,
|
||||
player.getName() + " failed KillauraCombined: (AccuracyHeuristic) Chance of hacking = " + accuracyProbability
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class StartKillAuraDecoyTask implements Runnable {
|
||||
private final EntityDamageByEntityEvent damageEvent;
|
||||
|
||||
private StartKillAuraDecoyTask(EntityDamageByEntityEvent damageEvent) {
|
||||
this.damageEvent = damageEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Player attacker = (Player)this.damageEvent.getDamager();
|
||||
if (attacker.isOnline()) {
|
||||
CombatDecoyPair decoys = new CombatDecoyPair(
|
||||
KillauraCombined.this.plugin, attacker, this.damageEvent.getEntity(), new KillAuraDecoyCallback(attacker)
|
||||
);
|
||||
KillauraCombined.this.activeNpcChecks.put(attacker.getUniqueId(), decoys);
|
||||
if (KillauraCombined.this.randomNpcType) {
|
||||
decoys.spawn(KillauraCombined.this.chooseRandomNpcType());
|
||||
} else if (EntityTargetCategories.isPrimaryCombatTarget(this.damageEvent.getEntity().getType())) {
|
||||
decoys.spawn(this.damageEvent.getEntity().getType());
|
||||
} else {
|
||||
decoys.spawn(EntityType.PLAYER);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class KillAuraDecoyCallback implements DecoyResultCallback {
|
||||
private final Player attacker;
|
||||
|
||||
private KillAuraDecoyCallback(Player attacker) {
|
||||
this.attacker = attacker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDecoyResult(int decoyHits, int targetHits) {
|
||||
UUID attackerId = this.attacker.getUniqueId();
|
||||
if (targetHits > 0) {
|
||||
KillauraCombined.this.recordViolation(
|
||||
attackerId,
|
||||
KillauraCombined.this.npcViolationMultiplier,
|
||||
HackType.KILLAURA,
|
||||
this.attacker.getName() + " failed Killaura: attacked through another player"
|
||||
);
|
||||
KillauraCombined.this.suspendedCombatPlayers.add(attackerId);
|
||||
Bukkit.getServer()
|
||||
.getScheduler()
|
||||
.scheduleSyncDelayedTask(
|
||||
KillauraCombined.this.plugin, new ExpireKillAuraCooldownTask(attackerId), KillauraCombined.this.combatSuspensionTicks
|
||||
);
|
||||
} else {
|
||||
KillauraCombined.this.decreaseViolationLevel(attackerId, 1);
|
||||
}
|
||||
|
||||
KillauraCombined.this.activeNpcChecks.remove(attackerId);
|
||||
}
|
||||
}
|
||||
|
||||
private final class ExpireKillAuraCooldownTask implements Runnable {
|
||||
private final UUID playerId;
|
||||
|
||||
private ExpireKillAuraCooldownTask(UUID playerId) {
|
||||
this.playerId = playerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
KillauraCombined.this.suspendedCombatPlayers.remove(this.playerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
package me.konsolas.aac.detectors.combat;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import me.konsolas.aac.detectors.MoveListener;
|
||||
import me.konsolas.aac.util.BlockCache;
|
||||
import me.konsolas.aac.util.EntityTargetCategories;
|
||||
import me.konsolas.aac.util.KnockbackDistanceTracker;
|
||||
import me.konsolas.aac.util.Ping;
|
||||
import me.konsolas.aac.util.general.ItemUseUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
public final class Knockback extends Detector implements MoveListener {
|
||||
private int tickDelay = 7;
|
||||
private boolean addPing = true;
|
||||
private int maxPing = 500;
|
||||
private double minKnockbackDist = 0.1;
|
||||
private final ConcurrentHashMap<UUID, KnockbackDistanceTracker> activeTrackers = new ConcurrentHashMap<>();
|
||||
|
||||
public Knockback(AAC plugin) {
|
||||
super(plugin);
|
||||
this.tickDelay = this.plugin.getConfig().getInt("knockback.tick_delay", this.tickDelay);
|
||||
this.addPing = this.plugin.getConfig().getBoolean("knockback.add_ping", this.addPing);
|
||||
this.maxPing = this.plugin.getConfig().getInt("knockback.max_ping", this.maxPing);
|
||||
this.minKnockbackDist = this.plugin.getConfig().getDouble("knockback.min_knockback_dist", this.minKnockbackDist);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
if (event.getEntity().getType() == EntityType.PLAYER
|
||||
&& event.getEntity().getVehicle() == null
|
||||
&& !this.plugin.checkManager.isBypassed((Player)event.getEntity())
|
||||
&& event.getCause() != DamageCause.THORNS) {
|
||||
Player victim = (Player)event.getEntity();
|
||||
if (!ItemUseUtil.isUsingItem(victim)
|
||||
|| victim.getInventory().getItemInMainHand().getType() != Material.SHIELD
|
||||
&& victim.getInventory().getItemInOffHand().getType() != Material.SHIELD) {
|
||||
UUID victimId = victim.getUniqueId();
|
||||
if (this.activeTrackers.containsKey(victimId)) {
|
||||
this.activeTrackers.get(victimId).cancelTask();
|
||||
this.activeTrackers.remove(victimId);
|
||||
}
|
||||
|
||||
if (EntityTargetCategories.isKnockbackSource(event.getDamager().getType())) {
|
||||
if (!(event.getDamager().getLocation().distance(event.getEntity().getLocation()) < 1.2)) {
|
||||
if (event.getDamager().getType() == EntityType.ARROW) {
|
||||
Arrow arrow = (Arrow)event.getDamager();
|
||||
if (arrow.getShooter() instanceof LivingEntity) {
|
||||
LivingEntity shooter = (LivingEntity)arrow.getShooter();
|
||||
if (event.getEntity().getEntityId() == shooter.getEntityId()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BlockCache blocks = new BlockCache(victim.getLocation());
|
||||
if (!this.isObstructingMaterial(blocks.getOffsetMaterial(0.6, 0.0, 0.0))
|
||||
&& !this.isObstructingMaterial(blocks.getOffsetMaterial(-0.6, 0.0, 0.0))
|
||||
&& !this.isObstructingMaterial(blocks.getOffsetMaterial(0.0, 0.0, 0.6))
|
||||
&& !this.isObstructingMaterial(blocks.getOffsetMaterial(0.0, 0.0, -0.6))
|
||||
&& !this.isObstructingMaterial(blocks.getOffsetMaterial(0.6, 0.0, 0.6))
|
||||
&& !this.isObstructingMaterial(blocks.getOffsetMaterial(-0.6, 0.0, 0.6))
|
||||
&& !this.isObstructingMaterial(blocks.getOffsetMaterial(0.6, 0.0, -0.6))
|
||||
&& !this.isObstructingMaterial(blocks.getOffsetMaterial(-0.6, 0.0, -0.6))
|
||||
&& !this.isObstructingMaterial(blocks.getOffsetMaterial(0.6, 1.1, 0.0))
|
||||
&& !this.isObstructingMaterial(blocks.getOffsetMaterial(-0.6, 1.1, 0.0))
|
||||
&& !this.isObstructingMaterial(blocks.getOffsetMaterial(0.0, 1.1, 0.6))
|
||||
&& !this.isObstructingMaterial(blocks.getOffsetMaterial(0.0, 1.1, -0.6))
|
||||
&& !this.isObstructingMaterial(blocks.getOffsetMaterial(0.6, 1.1, 0.6))
|
||||
&& !this.isObstructingMaterial(blocks.getOffsetMaterial(-0.6, 1.1, 0.6))
|
||||
&& !this.isObstructingMaterial(blocks.getOffsetMaterial(0.6, 1.1, -0.6))
|
||||
&& !this.isObstructingMaterial(blocks.getOffsetMaterial(-0.6, 1.1, -0.6))
|
||||
&& !this.isObstructingMaterial(blocks.getOffsetMaterial(0.6, 2.1, 0.0))
|
||||
&& !this.isObstructingMaterial(blocks.getOffsetMaterial(-0.6, 2.1, 0.0))
|
||||
&& !this.isObstructingMaterial(blocks.getOffsetMaterial(0.0, 2.1, 0.6))
|
||||
&& !this.isObstructingMaterial(blocks.getOffsetMaterial(0.0, 2.1, -0.6))
|
||||
&& !this.isObstructingMaterial(blocks.getOffsetMaterial(0.6, 2.1, 0.6))
|
||||
&& !this.isObstructingMaterial(blocks.getOffsetMaterial(-0.6, 2.1, 0.6))
|
||||
&& !this.isObstructingMaterial(blocks.getOffsetMaterial(0.6, 2.1, -0.6))
|
||||
&& !this.isObstructingMaterial(blocks.getOffsetMaterial(-0.6, 2.1, -0.6))
|
||||
&& !this.isObstructingMaterial(blocks.getOffsetMaterial(0.0, 1.1, 0.0))
|
||||
&& !this.isObstructingMaterial(blocks.getOffsetMaterial(0.0, 2.1, 0.0))
|
||||
&& !this.isObstructingMaterial(blocks.getOriginBlock().getType())) {
|
||||
int evaluationDelay = this.tickDelay;
|
||||
int ping = Ping.getPing(victim);
|
||||
if (this.addPing) {
|
||||
evaluationDelay += ping < this.maxPing ? ping / 100 : this.maxPing / 100;
|
||||
}
|
||||
|
||||
KnockbackDistanceTracker tracker;
|
||||
try {
|
||||
tracker = new KnockbackDistanceTracker(event.getDamager(), event.getEntity(), false);
|
||||
} catch (IllegalStateException ex) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.activeTrackers.put(victimId, tracker);
|
||||
tracker.setTaskId(
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new KnockbackEvaluationTask(victim), evaluationDelay)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldProcessMove(PlayerMoveEvent event) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerMove(PlayerMoveEvent event, boolean fromOnGround, boolean toOnGround) {
|
||||
KnockbackDistanceTracker tracker = this.activeTrackers.get(event.getPlayer().getUniqueId());
|
||||
if (tracker != null) {
|
||||
tracker.updateLocation(event.getPlayer().getLocation());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isObstructingMaterial(Material material) {
|
||||
return material == Material.WEB
|
||||
|| material == Material.WATER
|
||||
|| material == Material.STATIONARY_WATER
|
||||
|| material == Material.LAVA
|
||||
|| material == Material.STATIONARY_LAVA
|
||||
|| material.isSolid()
|
||||
|| material == Material.SKULL
|
||||
|| material == Material.FLOWER_POT;
|
||||
}
|
||||
|
||||
private final class KnockbackEvaluationTask implements Runnable {
|
||||
private final Player player;
|
||||
|
||||
private KnockbackEvaluationTask(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
KnockbackDistanceTracker tracker = Knockback.this.activeTrackers.remove(this.player.getUniqueId());
|
||||
double knockbackDistance = tracker.getMaxDistance() - tracker.getInitialDistance();
|
||||
if (knockbackDistance == 0.0) {
|
||||
Knockback.this.recordViolation(
|
||||
this.player.getUniqueId(),
|
||||
2,
|
||||
HackType.KNOCKBACK,
|
||||
this.player.getName() + " failed Knockback: didn't move away from his attacker when hit"
|
||||
);
|
||||
} else if (knockbackDistance < Knockback.this.minKnockbackDist) {
|
||||
Knockback.this.recordViolation(
|
||||
this.player.getUniqueId(),
|
||||
2,
|
||||
HackType.KNOCKBACK,
|
||||
this.player.getName()
|
||||
+ " failed Knockback: didn't move far enough when hit ("
|
||||
+ knockbackDistance
|
||||
+ " blocks"
|
||||
+ (tracker.isExempt() ? ", inWater)" : ")")
|
||||
);
|
||||
} else {
|
||||
Knockback.this.decreaseViolationLevel(this.player.getUniqueId(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package me.konsolas.aac.detectors.combat;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.DamageListener;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import me.konsolas.aac.detectors.MoveListener;
|
||||
import me.konsolas.aac.util.EntityTargetCategories;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
public final class Reach extends Detector implements DamageListener, MoveListener {
|
||||
private double maxReach = 4.0;
|
||||
private double maxBukkitReach = 9.0;
|
||||
private double moveMultiplier = 3.0;
|
||||
public Map<UUID, PlayerMoveEvent> lastMoves = new HashMap<>();
|
||||
|
||||
public Reach(AAC plugin) {
|
||||
super(plugin);
|
||||
this.maxReach = this.plugin.getConfig().getDouble("reach.max_reach", this.maxReach);
|
||||
this.maxBukkitReach = this.plugin.getConfig().getDouble("reach.max_bukkit_reach", this.maxBukkitReach);
|
||||
this.moveMultiplier = this.plugin.getConfig().getDouble("reach.move_multiplier", this.moveMultiplier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldProcessDamage(EntityDamageByEntityEvent event) {
|
||||
return event.getDamager().getType() == EntityType.PLAYER
|
||||
&& !event.getCause().equals(DamageCause.THORNS)
|
||||
&& EntityTargetCategories.isReachTarget(event.getEntity().getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
Location attackerEye = event.getDamager().getLocation().add(0.0, 1.5, 0.0);
|
||||
Location targetFeet = event.getEntity().getLocation();
|
||||
Location targetEye = event.getEntity().getLocation().add(0.0, 1.5, 0.0);
|
||||
double reachDistance = Math.min(attackerEye.distance(targetFeet), attackerEye.distance(targetEye));
|
||||
this.plugin
|
||||
.logger
|
||||
.logPlayerDebug((Player)event.getDamager(), "(Reach) EntityDamageByEntityEvent dist[m:" + this.maxReach + ",r:" + reachDistance + "]");
|
||||
if (!(reachDistance > this.maxReach) || !(reachDistance < this.maxBukkitReach)) {
|
||||
this.decreaseViolationLevel(event.getDamager().getUniqueId(), 1);
|
||||
} else if (event.getEntity() instanceof Player) {
|
||||
PlayerMoveEvent lastTargetMove = this.lastMoves.get(event.getEntity().getUniqueId());
|
||||
double moveAllowance = lastTargetMove != null ? lastTargetMove.getFrom().distance(lastTargetMove.getTo()) * this.moveMultiplier : 0.0;
|
||||
if (reachDistance > this.maxReach + moveAllowance
|
||||
&& this.recordViolation(
|
||||
event.getDamager().getUniqueId(),
|
||||
1,
|
||||
HackType.REACH,
|
||||
event.getDamager().getName() + " failed Reach: Tried to hit a player " + reachDistance + " blocks away"
|
||||
)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (reachDistance > this.maxReach + 1.2
|
||||
&& this.recordViolation(
|
||||
event.getDamager().getUniqueId(),
|
||||
1,
|
||||
HackType.REACH,
|
||||
event.getDamager().getName() + " failed Reach: Tried to hit an entity " + reachDistance + " blocks away"
|
||||
)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerMove(PlayerMoveEvent event, boolean fromOnGround, boolean toOnGround) {
|
||||
this.lastMoves.put(event.getPlayer().getUniqueId(), new PlayerMoveEvent(event.getPlayer(), event.getFrom(), event.getTo()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldProcessMove(PlayerMoveEvent event) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package me.konsolas.aac.detectors.combat;
|
||||
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
||||
|
||||
public final class Regen extends Detector {
|
||||
private long minRegenDelay = 3600L;
|
||||
private long minSatiatedDelay = 3850L;
|
||||
private boolean cancelRegen = true;
|
||||
|
||||
public Regen(AAC plugin) {
|
||||
super(plugin);
|
||||
this.cancelRegen = this.plugin.getConfig().getBoolean("regen.cancel_regen", this.cancelRegen);
|
||||
this.minRegenDelay = this.plugin.getConfig().getLong("regen.min_regen_delay", this.minRegenDelay);
|
||||
this.minSatiatedDelay = this.plugin.getConfig().getLong("regen.min_satiated_delay", this.minSatiatedDelay);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
|
||||
if (event.getEntity().getType() == EntityType.PLAYER && !this.plugin.checkManager.isBypassed((Player)event.getEntity())) {
|
||||
Player player = (Player)event.getEntity();
|
||||
long lastRegainTime = this.plugin.playerStateTracker.getLastHealthRegainTime(player);
|
||||
RegainReason lastRegainReason = this.plugin.playerStateTracker.getLastHealthRegainReason(player);
|
||||
long elapsedMs = System.currentTimeMillis() - lastRegainTime;
|
||||
if (lastRegainReason == RegainReason.SATIATED && event.getRegainReason() == RegainReason.SATIATED) {
|
||||
if (elapsedMs < this.minSatiatedDelay) {
|
||||
if (this.recordViolation(
|
||||
player.getUniqueId(), 1, HackType.REGEN, player.getName() + " failed Regen: regenerated health too quickly (" + elapsedMs + "ms)"
|
||||
)
|
||||
&& this.cancelRegen) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else if (player.getFoodLevel() < 20) {
|
||||
if (elapsedMs < this.minRegenDelay
|
||||
&& this.recordViolation(
|
||||
player.getUniqueId(), 1, HackType.REGEN, player.getName() + " failed Regen: regenerated health too quickly (" + elapsedMs + "ms)"
|
||||
)
|
||||
&& this.cancelRegen) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else {
|
||||
this.decreaseViolationLevel(player.getUniqueId(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package me.konsolas.aac.detectors.movement;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.PacketType.Play.Client;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public final class BadPackets extends Detector {
|
||||
private int maxMoves = 50;
|
||||
private int cancelThreshold = 10;
|
||||
private final ConcurrentMap<UUID, Integer> movePacketCounts = new ConcurrentHashMap<>();
|
||||
private final Set<UUID> violationCooldownPlayers = new HashSet<>();
|
||||
|
||||
public BadPackets(AAC plugin) {
|
||||
super(plugin);
|
||||
this.maxMoves = this.plugin.getConfig().getInt("badpackets.max_moves", this.maxMoves);
|
||||
this.cancelThreshold = this.plugin.getConfig().getInt("badpackets.cancel_threshold", this.cancelThreshold);
|
||||
this.scheduledTaskIds.add(Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new SampleTask(), 3L, 3L));
|
||||
PacketListener packetListener = new PacketListener(
|
||||
this.plugin, ListenerPriority.LOWEST, Client.FLYING, Client.POSITION, Client.POSITION_LOOK, Client.LOOK
|
||||
);
|
||||
this.packetListeners.add(packetListener);
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(packetListener);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
UUID playerId = event.getPlayer().getUniqueId();
|
||||
this.violationLevels.put(playerId, 0);
|
||||
this.movePacketCounts.put(playerId, 0);
|
||||
}
|
||||
|
||||
private class PacketListener extends PacketAdapter {
|
||||
PacketListener(Plugin plugin, ListenerPriority priority, PacketType... packetTypes) {
|
||||
super(plugin, priority, packetTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
try {
|
||||
PacketType type = event.getPacketType();
|
||||
if (type == Client.FLYING || type == Client.POSITION || type == Client.POSITION_LOOK || type == Client.LOOK) {
|
||||
Player player = event.getPlayer();
|
||||
if (BadPackets.this.plugin.checkManager.isBypassed(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
UUID playerId = player.getUniqueId();
|
||||
BadPackets.this.movePacketCounts.putIfAbsent(playerId, 0);
|
||||
int count = BadPackets.this.movePacketCounts.get(playerId) + 1;
|
||||
BadPackets.this.movePacketCounts.put(playerId, count);
|
||||
if (count > BadPackets.this.cancelThreshold) {
|
||||
BadPackets.this.plugin
|
||||
.logger
|
||||
.logPlayerDebug(
|
||||
player,
|
||||
"(BadPackets) PacketPlayInFlying cancelled packets[m:"
|
||||
+ BadPackets.this.cancelThreshold
|
||||
+ ",r:"
|
||||
+ BadPackets.this.movePacketCounts.get(playerId)
|
||||
+ "]"
|
||||
);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class SampleTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Entry<UUID, Integer> entry : BadPackets.this.movePacketCounts.entrySet()) {
|
||||
UUID playerId = entry.getKey();
|
||||
if (BadPackets.this.movePacketCounts.containsKey(playerId)) {
|
||||
Player player = Bukkit.getPlayer(playerId);
|
||||
if (player == null) {
|
||||
BadPackets.this.movePacketCounts.remove(playerId);
|
||||
} else {
|
||||
int packetCount = entry.getValue();
|
||||
if (packetCount > BadPackets.this.maxMoves && !BadPackets.this.plugin.checkManager.isBypassed(player)) {
|
||||
if (!BadPackets.this.violationCooldownPlayers.contains(playerId)) {
|
||||
BadPackets.this.recordViolation(
|
||||
playerId,
|
||||
(packetCount - BadPackets.this.maxMoves) / 10,
|
||||
HackType.BADPACKETS,
|
||||
player.getName() + " failed BadPackets: sent " + BadPackets.this.movePacketCounts.get(playerId) + " moves in 3 ticks."
|
||||
);
|
||||
} else {
|
||||
BadPackets.this.recordViolation(
|
||||
playerId,
|
||||
(packetCount - BadPackets.this.maxMoves) / 50,
|
||||
HackType.BADPACKETS,
|
||||
player.getName() + " failed BadPackets: sent " + BadPackets.this.movePacketCounts.get(playerId) + " moves in 3 ticks."
|
||||
);
|
||||
BadPackets.this.violationCooldownPlayers.add(playerId);
|
||||
Bukkit.getServer()
|
||||
.getScheduler()
|
||||
.scheduleSyncDelayedTask(BadPackets.this.plugin, new ExpireCooldownTask(playerId), 50L);
|
||||
}
|
||||
} else {
|
||||
BadPackets.this.decreaseViolationLevel(playerId, 1);
|
||||
}
|
||||
|
||||
BadPackets.this.movePacketCounts.put(playerId, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ExpireCooldownTask implements Runnable {
|
||||
private final UUID playerId;
|
||||
|
||||
ExpireCooldownTask(UUID playerId) {
|
||||
this.playerId = playerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
BadPackets.this.violationCooldownPlayers.remove(this.playerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package me.konsolas.aac.detectors.movement;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import me.konsolas.aac.detectors.MoveListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Boat;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
|
||||
public class BoatFly extends Detector implements MoveListener {
|
||||
private double minDownwardDelta = 0.12;
|
||||
private boolean teleport = true;
|
||||
private int frictionTicks = 7;
|
||||
private final Map<UUID, Integer> airborneTicks = new HashMap<>();
|
||||
|
||||
public BoatFly(AAC plugin) {
|
||||
super(plugin);
|
||||
this.minDownwardDelta = this.plugin.getConfig().getDouble("boatfly.min_downward_delta", this.minDownwardDelta);
|
||||
this.teleport = this.plugin.getConfig().getBoolean("boatfly.teleport", this.teleport);
|
||||
this.frictionTicks = this.plugin.getConfig().getInt("boatfly.friction_ticks", this.frictionTicks);
|
||||
this.scheduledTaskIds.add(Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new ViolationDecayTask(), 19L, 51L));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerMove(PlayerMoveEvent event, boolean fromOnGround, boolean toOnGround) {
|
||||
Player player = event.getPlayer();
|
||||
UUID playerId = player.getUniqueId();
|
||||
double deltaY = event.getTo().getY() - event.getFrom().getY();
|
||||
Boat boat = (Boat) player.getVehicle();
|
||||
if (!(deltaY > -this.minDownwardDelta) || !this.isBoatAirborne(boat)) {
|
||||
this.airborneTicks.put(playerId, 0);
|
||||
} else if (deltaY > 0.0) {
|
||||
if (this.recordViolation(
|
||||
playerId,
|
||||
3,
|
||||
HackType.BOATFLY,
|
||||
player.getName() + " failed BoatFly: ascended incorrectly on a boat (dy:" + deltaY + ")"
|
||||
)
|
||||
&& this.teleport) {
|
||||
this.plugin.setbackManager.beginSetback(this, player);
|
||||
player.teleport(this.plugin.setbackManager.getSafeLocation(player), TeleportCause.UNKNOWN);
|
||||
}
|
||||
} else {
|
||||
if (this.airborneTicks.containsKey(playerId)) {
|
||||
this.airborneTicks.put(playerId, this.airborneTicks.get(playerId) + 1);
|
||||
} else {
|
||||
this.airborneTicks.put(playerId, 0);
|
||||
}
|
||||
|
||||
if (this.airborneTicks.get(playerId) >= this.frictionTicks
|
||||
&& this.recordViolation(
|
||||
playerId,
|
||||
3,
|
||||
HackType.BOATFLY,
|
||||
player.getName() + " failed BoatFly: moved incorrectly on a boat (dy:" + deltaY + ")"
|
||||
)
|
||||
&& this.teleport) {
|
||||
this.plugin.setbackManager.beginSetback(this, player);
|
||||
player.teleport(player.getLocation().subtract(0.0, 0.6, 0.0), TeleportCause.UNKNOWN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldProcessMove(PlayerMoveEvent event) {
|
||||
return event.getPlayer().getVehicle() != null && event.getPlayer().getVehicle() instanceof Boat;
|
||||
}
|
||||
|
||||
private boolean isBoatAirborne(Boat boat) {
|
||||
Material blockType = boat.getLocation().getBlock().getType();
|
||||
return blockType != Material.STATIONARY_WATER && blockType != Material.WATER && !boat.isOnGround();
|
||||
}
|
||||
|
||||
private class ViolationDecayTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
BoatFly.this.decreaseViolationLevel(player.getUniqueId(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package me.konsolas.aac.detectors.movement;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.DamageListener;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import me.konsolas.aac.detectors.MoveListener;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
public final class Climb extends Detector implements MoveListener, DamageListener {
|
||||
private double maxAscentSpeed = 0.15;
|
||||
private double maxStartSpeed = 0.6;
|
||||
private boolean teleport = true;
|
||||
private final Map<UUID, Double> climbStartHeights = new HashMap<>();
|
||||
|
||||
public Climb(AAC plugin) {
|
||||
super(plugin);
|
||||
this.maxAscentSpeed = this.plugin.getConfig().getDouble("climb.max_ascent_speed", this.maxAscentSpeed);
|
||||
this.maxStartSpeed = this.plugin.getConfig().getDouble("climb.max_start_speed", this.maxStartSpeed);
|
||||
this.teleport = this.plugin.getConfig().getBoolean("climb.teleport", this.teleport);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldProcessMove(PlayerMoveEvent event) {
|
||||
if (!event.getPlayer().isFlying() && event.getPlayer().getVehicle() == null) {
|
||||
if (!this.isClimbing(event.getPlayer())) {
|
||||
this.climbStartHeights.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldProcessDamage(EntityDamageByEntityEvent event) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerMove(PlayerMoveEvent event, boolean fromOnGround, boolean toOnGround) {
|
||||
if (fromOnGround && toOnGround) {
|
||||
double fromY = event.getFrom().getY();
|
||||
double deltaY = event.getTo().getY() - fromY;
|
||||
if (deltaY > 0.0) {
|
||||
Player player = event.getPlayer();
|
||||
UUID playerId = player.getUniqueId();
|
||||
if (deltaY > this.maxStartSpeed) {
|
||||
if (this.recordViolation(
|
||||
playerId, 2, HackType.CLIMB, player.getName() + " failed Climb: initiated a ladder climb too quickly"
|
||||
)
|
||||
&& this.teleport) {
|
||||
event.setTo(event.getFrom());
|
||||
}
|
||||
} else if (!this.climbStartHeights.containsKey(playerId)
|
||||
|| !(player.getLocation().getY() > this.climbStartHeights.get(playerId) + this.maxStartSpeed)) {
|
||||
this.decreaseViolationLevel(playerId, 1);
|
||||
} else if (deltaY > this.maxAscentSpeed
|
||||
&& this.recordViolation(
|
||||
playerId, 2, HackType.CLIMB, player.getName() + " failed Climb: climbed a ladder too quickly"
|
||||
)
|
||||
&& this.teleport) {
|
||||
event.setTo(event.getFrom());
|
||||
}
|
||||
|
||||
if (!this.climbStartHeights.containsKey(playerId)) {
|
||||
this.climbStartHeights.put(playerId, player.getLocation().getY());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
this.climbStartHeights.remove(event.getEntity().getUniqueId());
|
||||
}
|
||||
|
||||
public boolean isClimbing(Player player) {
|
||||
return this.isClimbableMaterial(player.getLocation().getBlock().getType());
|
||||
}
|
||||
|
||||
public boolean isClimbableMaterial(Material material) {
|
||||
return material == Material.VINE || material == Material.LADDER;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
package me.konsolas.aac.detectors.movement;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import me.konsolas.aac.detectors.MoveListener;
|
||||
import me.konsolas.aac.util.general.ElytraUtil;
|
||||
import me.konsolas.aac.util.general.NumberUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class ElytraMove extends Detector implements MoveListener {
|
||||
private double tolerance = 0.05;
|
||||
private boolean teleport = true;
|
||||
private final Map<UUID, Vector> lastMovementVectors = new HashMap<>();
|
||||
private final Set<UUID> glideGracePlayers = new HashSet<>();
|
||||
|
||||
public ElytraMove(AAC plugin) {
|
||||
super(plugin);
|
||||
this.tolerance = this.plugin.getConfig().getDouble("elytramove.tolerance", this.tolerance);
|
||||
this.teleport = this.plugin.getConfig().getBoolean("elytramove.teleport", this.teleport);
|
||||
this.scheduledTaskIds
|
||||
.add(this.plugin.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new ViolationDecayTask(), 50L, 79L));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerMove(PlayerMoveEvent event, boolean fromOnGround, boolean toOnGround) {
|
||||
if (!fromOnGround && !toOnGround) {
|
||||
Player player = event.getPlayer();
|
||||
UUID playerId = player.getUniqueId();
|
||||
|
||||
try {
|
||||
Vector actualDelta = new Vector(
|
||||
event.getTo().getX() - event.getFrom().getX(),
|
||||
event.getTo().getY() - event.getFrom().getY(),
|
||||
event.getTo().getZ() - event.getFrom().getZ()
|
||||
);
|
||||
Vector predictedDelta = this.lastMovementVectors.get(playerId);
|
||||
if (!this.lastMovementVectors.containsKey(playerId) && (Math.abs(actualDelta.getX()) > 0.4 || Math.abs(actualDelta.getZ()) > 0.4)) {
|
||||
if (this.recordViolation(
|
||||
playerId,
|
||||
1,
|
||||
HackType.ELYTRAMOVE,
|
||||
String.format(
|
||||
player.getName() + " failed ElytraMove: Initiated flight too quickly",
|
||||
actualDelta.getX(),
|
||||
actualDelta.getY(),
|
||||
actualDelta.getZ(),
|
||||
predictedDelta.getX(),
|
||||
predictedDelta.getY(),
|
||||
predictedDelta.getZ()
|
||||
)
|
||||
)
|
||||
&& this.teleport
|
||||
&& player.getLocation().subtract(0.0, 1.0, 0.0).getBlock().isEmpty()) {
|
||||
this.plugin.setbackManager.beginSetback(this, player);
|
||||
player.teleport(player.getLocation().subtract(0.0, 1.0, 0.0));
|
||||
event.setTo(event.getFrom());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.lastMovementVectors.put(playerId, actualDelta);
|
||||
if (predictedDelta == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
predictedDelta = predictedDelta.clone();
|
||||
Vector lookVector = this.getLookVector(player.getLocation().getPitch(), player.getLocation().getYaw());
|
||||
float pitchRadians = player.getLocation().getPitch() * (float) (Math.PI / 180.0);
|
||||
double lookHorizontal = Math.sqrt(lookVector.getX() * lookVector.getX() + lookVector.getZ() * lookVector.getZ());
|
||||
double motionHorizontal = Math.sqrt(predictedDelta.getX() * predictedDelta.getX() + predictedDelta.getZ() * predictedDelta.getZ());
|
||||
double lookLength = lookVector.length();
|
||||
float cosPitch = (float) Math.cos(pitchRadians);
|
||||
cosPitch = (float) ((double) cosPitch * cosPitch * Math.min(1.0, lookLength / 0.4));
|
||||
predictedDelta.setY(predictedDelta.getY() + -0.08 + cosPitch * 0.06);
|
||||
if (predictedDelta.getY() < 0.0 && lookHorizontal > 0.0) {
|
||||
double lift = predictedDelta.getY() * -0.1 * cosPitch;
|
||||
predictedDelta.setY(predictedDelta.getY() + lift);
|
||||
predictedDelta.setX(predictedDelta.getX() + lookVector.getX() * lift / lookHorizontal);
|
||||
predictedDelta.setZ(predictedDelta.getZ() + lookVector.getZ() * lift / lookHorizontal);
|
||||
}
|
||||
|
||||
if (pitchRadians < 0.0) {
|
||||
double climb = motionHorizontal * -Math.sin(pitchRadians) * 0.04;
|
||||
predictedDelta.setY(predictedDelta.getY() + climb * 3.2);
|
||||
predictedDelta.setX(predictedDelta.getX() - lookVector.getX() * climb / lookHorizontal);
|
||||
predictedDelta.setZ(predictedDelta.getZ() - lookVector.getZ() * climb / lookHorizontal);
|
||||
}
|
||||
|
||||
if (lookHorizontal > 0.0) {
|
||||
predictedDelta.setX(predictedDelta.getX() + (lookVector.getX() / lookHorizontal * motionHorizontal - predictedDelta.getX()) * 0.1);
|
||||
predictedDelta.setZ(predictedDelta.getZ() + (lookVector.getZ() / lookHorizontal * motionHorizontal - predictedDelta.getZ()) * 0.1);
|
||||
}
|
||||
|
||||
predictedDelta.setX(predictedDelta.getX() * 0.99);
|
||||
predictedDelta.setY(predictedDelta.getY() * 0.98);
|
||||
predictedDelta.setZ(predictedDelta.getZ() * 0.99);
|
||||
if (!NumberUtil.approximatelyEqual(predictedDelta.getX(), actualDelta.getX(), this.tolerance)
|
||||
|| !NumberUtil.approximatelyEqual(predictedDelta.getY(), actualDelta.getY(), this.tolerance / 1.5)
|
||||
|| !NumberUtil.approximatelyEqual(predictedDelta.getZ(), actualDelta.getZ(), this.tolerance)) {
|
||||
if (actualDelta.getX() < predictedDelta.getX()
|
||||
&& Math.abs(actualDelta.getZ()) < Math.abs(predictedDelta.getZ())
|
||||
&& NumberUtil.approximatelyEqual(predictedDelta.getY(), actualDelta.getY(), this.tolerance / 1.5)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.glideGracePlayers.contains(playerId) && Math.abs(actualDelta.getX()) < 0.5 && Math.abs(actualDelta.getZ()) < 0.5) {
|
||||
if (this.recordViolation(
|
||||
playerId,
|
||||
1,
|
||||
HackType.ELYTRAMOVE,
|
||||
String.format(
|
||||
player.getName() + " failed ElytraMove: moved incorrectly (%.4f, %.4f, %.4f), expected (%.4f, %.4f, %.4f)",
|
||||
actualDelta.getX(),
|
||||
actualDelta.getY(),
|
||||
actualDelta.getZ(),
|
||||
predictedDelta.getX(),
|
||||
predictedDelta.getY(),
|
||||
predictedDelta.getZ()
|
||||
)
|
||||
)
|
||||
&& this.teleport) {
|
||||
if (player.getLocation().subtract(0.0, 1.0, 0.0).getBlock().isEmpty()) {
|
||||
this.plugin.setbackManager.beginSetback(this, player);
|
||||
player.teleport(player.getLocation().subtract(0.0, 1.0, 0.0));
|
||||
this.lastMovementVectors.remove(playerId);
|
||||
} else {
|
||||
event.setTo(event.getFrom());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.glideGracePlayers.remove(playerId);
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Vector getLookVector(float pitch, float yaw) {
|
||||
double cosYaw = Math.cos(-yaw * (float) (Math.PI / 180.0) - Math.PI);
|
||||
double sinYaw = Math.sin(-yaw * (float) (Math.PI / 180.0) - Math.PI);
|
||||
double negCosPitch = -Math.cos(-pitch * (float) (Math.PI / 180.0));
|
||||
double sinPitch = Math.sin(-pitch * (float) (Math.PI / 180.0));
|
||||
return new Vector(sinYaw * negCosPitch, sinPitch, cosYaw * negCosPitch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldProcessMove(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (!ElytraUtil.isGliding(player)) {
|
||||
this.glideGracePlayers.add(player.getUniqueId());
|
||||
this.lastMovementVectors.remove(player.getUniqueId());
|
||||
return false;
|
||||
} else {
|
||||
return !player.isFlying() && player.getGameMode() != GameMode.SPECTATOR && !player.isDead();
|
||||
}
|
||||
}
|
||||
|
||||
private class ViolationDecayTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
ElytraMove.this.decreaseViolationLevel(player.getUniqueId(), 1);
|
||||
}
|
||||
|
||||
ElytraMove.this.glideGracePlayers.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
package me.konsolas.aac.detectors.movement;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import me.konsolas.aac.detectors.MoveListener;
|
||||
import me.konsolas.aac.util.general.ElytraUtil;
|
||||
import me.konsolas.aac.util.ground.GroundUtil;
|
||||
import net.jodah.expiringmap.ExpirationPolicy;
|
||||
import net.jodah.expiringmap.ExpiringMap;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerVelocityEvent;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public final class Fly extends Detector implements MoveListener {
|
||||
private double maxJumpHeight = 1.4;
|
||||
private double slimeJumpAllowance = 60.0;
|
||||
private double knockbackAllowance = 3.1;
|
||||
private double velocityMultiplier = 1.2;
|
||||
private double excessHeightAllowance = 0.8;
|
||||
private double naturalDamageAllowance = 2.1;
|
||||
private boolean teleportOnViolation = true;
|
||||
private final Map<UUID, Double> allowedJumpHeights = new ConcurrentHashMap<>();
|
||||
private final Set<UUID> flightExemptions = new HashSet<>();
|
||||
private final Set<UUID> slimeBouncingPlayers = new HashSet<>();
|
||||
private final ExpiringMap<UUID, Boolean> setbackCooldowns;
|
||||
private final Set<UUID> levitatingPlayers = new HashSet<>();
|
||||
|
||||
public Fly(AAC plugin) {
|
||||
super(plugin);
|
||||
this.maxJumpHeight = this.plugin.getConfig().getDouble("fly.max_jump", this.maxJumpHeight);
|
||||
this.slimeJumpAllowance = this.plugin.getConfig().getDouble("fly.slime_allow", this.slimeJumpAllowance);
|
||||
this.knockbackAllowance = this.plugin.getConfig().getDouble("fly.knockback_allow", this.knockbackAllowance);
|
||||
this.velocityMultiplier = this.plugin.getConfig().getDouble("fly.velocity_multiplier", this.velocityMultiplier);
|
||||
this.excessHeightAllowance = this.plugin.getConfig().getDouble("fly.allow", this.excessHeightAllowance);
|
||||
this.naturalDamageAllowance = this.plugin.getConfig().getDouble("fly.natural_allow", this.naturalDamageAllowance);
|
||||
this.teleportOnViolation = this.plugin.getConfig().getBoolean("fly.teleport", this.teleportOnViolation);
|
||||
this.scheduledTaskIds.add(Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new ViolationDecayTask(), 20L, 50L));
|
||||
this.setbackCooldowns = ExpiringMap.builder()
|
||||
.expiration(300L, TimeUnit.MILLISECONDS)
|
||||
.expirationPolicy(ExpirationPolicy.CREATED)
|
||||
.build();
|
||||
}
|
||||
|
||||
public boolean hasSetbackCooldown(Player player) {
|
||||
return this.setbackCooldowns.containsKey(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldProcessMove(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
return !player.isDead()
|
||||
&& !this.flightExemptions.contains(player.getUniqueId())
|
||||
&& !player.getGameMode().equals(GameMode.SPECTATOR)
|
||||
&& !ElytraUtil.isGliding(player)
|
||||
&& !player.getAllowFlight()
|
||||
&& player.getVehicle() == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerMove(PlayerMoveEvent event, boolean fromOnGround, boolean toOnGround) {
|
||||
Player player = event.getPlayer();
|
||||
UUID playerId = player.getUniqueId();
|
||||
int jumpAmplifier = -1;
|
||||
if (player.hasPotionEffect(PotionEffectType.JUMP)) {
|
||||
for (PotionEffect effect : player.getActivePotionEffects()) {
|
||||
if (effect.getType().equals(PotionEffectType.JUMP)) {
|
||||
jumpAmplifier = effect.getAmplifier();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.slimeBouncingPlayers.contains(playerId) && fromOnGround) {
|
||||
this.slimeBouncingPlayers.remove(playerId);
|
||||
}
|
||||
|
||||
if (!this.allowedJumpHeights.containsKey(playerId)) {
|
||||
this.allowedJumpHeights.put(playerId, this.maxJumpHeight);
|
||||
}
|
||||
|
||||
if (this.plugin.combatTracker.wasRecentlyDamaged(player) && this.allowedJumpHeights.get(playerId) < this.knockbackAllowance) {
|
||||
DamageCause lastCause = this.plugin.combatTracker.getLastDamageCause(player);
|
||||
if (lastCause == DamageCause.ENTITY_ATTACK || lastCause == DamageCause.PROJECTILE) {
|
||||
this.allowedJumpHeights.put(playerId, this.knockbackAllowance);
|
||||
} else if (this.allowedJumpHeights.get(playerId) < this.naturalDamageAllowance) {
|
||||
this.allowedJumpHeights.put(playerId, this.naturalDamageAllowance);
|
||||
}
|
||||
}
|
||||
|
||||
if (jumpAmplifier > -1) {
|
||||
double boostedJumpHeight = Math.pow(jumpAmplifier + 1 + 4.2, 2.0) / 16.0 + this.maxJumpHeight;
|
||||
double currentAllowed = this.allowedJumpHeights.get(playerId);
|
||||
this.allowedJumpHeights.put(playerId, boostedJumpHeight > currentAllowed ? boostedJumpHeight : currentAllowed);
|
||||
}
|
||||
|
||||
if (GroundUtil.isNearBounceBlock(player)) {
|
||||
this.allowedJumpHeights.put(playerId, this.slimeJumpAllowance);
|
||||
this.slimeBouncingPlayers.add(playerId);
|
||||
}
|
||||
|
||||
if (this.slimeBouncingPlayers.contains(playerId)) {
|
||||
if (fromOnGround) {
|
||||
this.slimeBouncingPlayers.remove(playerId);
|
||||
}
|
||||
|
||||
this.allowedJumpHeights.put(playerId, this.slimeJumpAllowance);
|
||||
}
|
||||
|
||||
if (player.hasPotionEffect(PotionEffectType.LEVITATION)) {
|
||||
boolean wasLevitating = this.levitatingPlayers.contains(playerId);
|
||||
double levitationAllowance = 0.0;
|
||||
|
||||
for (PotionEffect effect : player.getActivePotionEffects()) {
|
||||
if (effect.getType().equals(PotionEffectType.LEVITATION)) {
|
||||
levitationAllowance = (effect.getAmplifier() + 2) * 0.06;
|
||||
}
|
||||
}
|
||||
|
||||
this.allowedJumpHeights.put(playerId, wasLevitating ? levitationAllowance : this.maxJumpHeight);
|
||||
} else {
|
||||
this.levitatingPlayers.remove(playerId);
|
||||
}
|
||||
|
||||
double heightAboveGround = event.getTo().getY() - this.plugin.setbackManager.getSafeLocation(player).getY();
|
||||
double excessHeight = heightAboveGround - this.allowedJumpHeights.get(playerId);
|
||||
if (excessHeight > 0.0) {
|
||||
this.plugin
|
||||
.logger
|
||||
.logPlayerDebug(
|
||||
player,
|
||||
"(Fly) PlayerMoveEvent from "
|
||||
+ event.getFrom().getX()
|
||||
+ "x"
|
||||
+ event.getFrom().getY()
|
||||
+ "y"
|
||||
+ event.getFrom().getZ()
|
||||
+ "z to "
|
||||
+ event.getTo().getX()
|
||||
+ "x"
|
||||
+ event.getTo().getY()
|
||||
+ "y"
|
||||
+ event.getTo().getZ()
|
||||
+ "z ground[u:"
|
||||
+ this.plugin.setbackManager.getSafeLocation(player).getY()
|
||||
+ "] height[t:"
|
||||
+ this.allowedJumpHeights.get(playerId)
|
||||
+ ",r:"
|
||||
+ heightAboveGround
|
||||
+ "]"
|
||||
);
|
||||
if (this.recordViolation(playerId, 1, HackType.FLY, player.getName() + " failed Fly: tried to jump too high (" + heightAboveGround + " blocks)")
|
||||
&& (excessHeight > this.excessHeightAllowance || this.getViolationLevel(player) > 2)
|
||||
&& this.teleportOnViolation) {
|
||||
this.setbackCooldowns.putIfAbsent(playerId, false);
|
||||
this.setbackCooldowns.resetExpiration(playerId);
|
||||
float fallDistance = player.getFallDistance();
|
||||
event.setTo(this.plugin.setbackManager.getSafeLocation(player));
|
||||
player.setFallDistance(fallDistance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerVelocity(PlayerVelocityEvent event) {
|
||||
if (!(event.getVelocity().getY() <= 0.0)) {
|
||||
Player player = event.getPlayer();
|
||||
UUID playerId = player.getUniqueId();
|
||||
if (!this.allowedJumpHeights.containsKey(playerId)) {
|
||||
this.allowedJumpHeights.put(playerId, this.maxJumpHeight);
|
||||
}
|
||||
|
||||
double predictedHeight = this.predictJumpHeight(event.getVelocity().getY());
|
||||
double currentHeight = player.getLocation().getY() - this.plugin.setbackManager.getSafeLocation(player).getY();
|
||||
if (predictedHeight + currentHeight > this.allowedJumpHeights.get(playerId)) {
|
||||
this.allowedJumpHeights.put(playerId, (predictedHeight + currentHeight) * this.velocityMultiplier);
|
||||
}
|
||||
|
||||
this.plugin
|
||||
.logger
|
||||
.logPlayerDebug(
|
||||
player,
|
||||
"(Fly) PlayerVelocityEvent velocityY[r:"
|
||||
+ event.getVelocity().getY()
|
||||
+ "] newHeight[u:"
|
||||
+ this.allowedJumpHeights.get(playerId)
|
||||
+ "]"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private double predictJumpHeight(double initialVelocityY) {
|
||||
double totalHeight = 0.0;
|
||||
double verticalSpeed = 0.0;
|
||||
int tick = 0;
|
||||
|
||||
do {
|
||||
totalHeight += verticalSpeed;
|
||||
verticalSpeed = (initialVelocityY + 4.0) * StrictMath.exp(-0.02 * tick) - 4.0;
|
||||
tick++;
|
||||
} while (verticalSpeed > 0.0);
|
||||
|
||||
return totalHeight;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
UUID playerId = player.getUniqueId();
|
||||
this.violationLevels.put(playerId, 0);
|
||||
this.allowedJumpHeights.put(playerId, this.maxJumpHeight);
|
||||
Bukkit.getPluginManager().callEvent(new PlayerVelocityEvent(player, player.getVelocity()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
public void clearCaches() {
|
||||
this.slimeBouncingPlayers.clear();
|
||||
this.allowedJumpHeights.clear();
|
||||
this.setbackCooldowns.clear();
|
||||
this.flightExemptions.clear();
|
||||
}
|
||||
|
||||
private class ViolationDecayTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
Fly.this.decreaseViolationLevel(player.getUniqueId(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,423 @@
|
||||
package me.konsolas.aac.detectors.movement;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import me.konsolas.aac.detectors.MoveListener;
|
||||
import me.konsolas.aac.util.BlockCache;
|
||||
import me.konsolas.aac.util.general.ElytraUtil;
|
||||
import me.konsolas.aac.util.ground.GroundUtil;
|
||||
import me.konsolas.aac.util.movement.VerticalMotionModel;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public final class Glide extends Detector implements MoveListener {
|
||||
private double tolerance = 0.1;
|
||||
private boolean teleport = true;
|
||||
private double specialTolerance = 0.8;
|
||||
private int minVl = 5;
|
||||
private final Set<UUID> graceExemptPlayers = new HashSet<>();
|
||||
private final Map<UUID, Long> lastMoveTicks = new HashMap<>();
|
||||
private final Map<UUID, Double> previousDeltaYByPlayer = new HashMap<>();
|
||||
private final Map<UUID, Double> slimeImpactSpeedByPlayer = new HashMap<>();
|
||||
private final Map<UUID, Integer> slimeBounceTicksByPlayer = new HashMap<>();
|
||||
private final Set<UUID> deferredGroundPlayers = new HashSet<>();
|
||||
private final Set<UUID> levitatingPlayers = new HashSet<>();
|
||||
|
||||
public Glide(AAC plugin) {
|
||||
super(plugin);
|
||||
this.tolerance = this.plugin.getConfig().getDouble("glide.tolerance", this.tolerance);
|
||||
this.teleport = this.plugin.getConfig().getBoolean("glide.teleport", this.teleport);
|
||||
this.specialTolerance = this.plugin.getConfig().getDouble("glide.special_tolerance", this.specialTolerance);
|
||||
this.minVl = this.plugin.getConfig().getInt("glide.min_vl", this.minVl);
|
||||
this.scheduledTaskIds
|
||||
.add(Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new ResetExemptionsTask(), 32L, 23L));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldProcessMove(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
this.recordMoveTick(player);
|
||||
return player.getGameMode() != GameMode.SPECTATOR
|
||||
&& !player.getAllowFlight()
|
||||
&& !player.isDead()
|
||||
&& player.getLocation().getY() > -70.0
|
||||
&& !ElytraUtil.isGliding(player);
|
||||
}
|
||||
|
||||
private void recordMoveTick(Player player) {
|
||||
if (!player.isOnline()) {
|
||||
this.lastMoveTicks.remove(player.getUniqueId());
|
||||
} else {
|
||||
this.lastMoveTicks.put(player.getUniqueId(), this.currentTick);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTick(long tick) {
|
||||
super.updateTick(tick);
|
||||
if (tick % 29L == 0L) {
|
||||
this.graceExemptPlayers.clear();
|
||||
}
|
||||
|
||||
if (tick % 7L == 0L) {
|
||||
Iterator<Entry<UUID, Long>> iterator = this.lastMoveTicks.entrySet().iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
Entry<UUID, Long> entry = iterator.next();
|
||||
if (tick - entry.getValue() > 5L) {
|
||||
Player player = Bukkit.getPlayer(entry.getKey());
|
||||
if (player == null || !player.isOnline()) {
|
||||
iterator.remove();
|
||||
} else if (!this.plugin.checkManager.isBypassed(player)) {
|
||||
if (!GroundUtil.isOnGround(player.getLocation())) {
|
||||
PlayerMoveEvent syntheticEvent = new PlayerMoveEvent(player, player.getLocation(), player.getLocation());
|
||||
if (this.shouldProcessMove(syntheticEvent)) {
|
||||
this.onPlayerMove(syntheticEvent, false, false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerMove(PlayerMoveEvent event, boolean fromOnGround, boolean toOnGround) {
|
||||
Player player = event.getPlayer();
|
||||
UUID playerId = player.getUniqueId();
|
||||
double deltaY = event.getTo().getY() - event.getFrom().getY();
|
||||
double moveTolerance = this.tolerance;
|
||||
boolean hasActiveVelocity = this.plugin.playerStateTracker.hasActiveVelocity(player);
|
||||
double velocityY = this.plugin.playerStateTracker.getActiveVelocity(player) != null
|
||||
? this.plugin.playerStateTracker.getActiveVelocity(player).getY()
|
||||
: 0.0;
|
||||
long velocityAgeTicks = (System.currentTimeMillis() - this.plugin.playerStateTracker.getLastVelocityTime(player)) / 50L;
|
||||
int jumpBoostLevel = 0;
|
||||
|
||||
for (PotionEffect effect : player.getActivePotionEffects()) {
|
||||
if (effect.getType().equals(PotionEffectType.JUMP)) {
|
||||
jumpBoostLevel = effect.getAmplifier() + 1;
|
||||
}
|
||||
}
|
||||
|
||||
boolean wasDeferredGround = this.deferredGroundPlayers.contains(playerId);
|
||||
this.deferredGroundPlayers.remove(playerId);
|
||||
if (deltaY == 0.0 && fromOnGround) {
|
||||
this.deferredGroundPlayers.add(playerId);
|
||||
}
|
||||
|
||||
if (!fromOnGround && wasDeferredGround) {
|
||||
fromOnGround = true;
|
||||
}
|
||||
|
||||
if (!this.previousDeltaYByPlayer.containsKey(playerId)) {
|
||||
this.previousDeltaYByPlayer.put(playerId, deltaY);
|
||||
} else {
|
||||
if (!toOnGround
|
||||
&& VerticalMotionModel.predictNextDeltaY(this.previousDeltaYByPlayer.get(playerId)) < deltaY - moveTolerance / 2.0
|
||||
&& deltaY < 0.0
|
||||
&& GroundUtil.isNearGroundWide(event.getTo())) {
|
||||
toOnGround = true;
|
||||
this.deferredGroundPlayers.add(playerId);
|
||||
}
|
||||
|
||||
int levitationLevel = 0;
|
||||
boolean wasLevitating = this.levitatingPlayers.contains(playerId);
|
||||
if (player.hasPotionEffect(PotionEffectType.LEVITATION)) {
|
||||
this.levitatingPlayers.add(playerId);
|
||||
|
||||
for (PotionEffect effect : player.getActivePotionEffects()) {
|
||||
if (effect.getType().equals(PotionEffectType.LEVITATION)) {
|
||||
levitationLevel = effect.getAmplifier() + 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.levitatingPlayers.remove(playerId);
|
||||
}
|
||||
|
||||
boolean lowCeiling = Speed.hasLowCeiling(player);
|
||||
boolean validMotion = VerticalMotionModel.isValidVerticalMotion(
|
||||
deltaY,
|
||||
fromOnGround,
|
||||
toOnGround,
|
||||
hasActiveVelocity,
|
||||
velocityY,
|
||||
velocityAgeTicks,
|
||||
this.previousDeltaYByPlayer.get(playerId),
|
||||
moveTolerance,
|
||||
jumpBoostLevel,
|
||||
levitationLevel
|
||||
);
|
||||
if (isEligibleForVerticalCheck(event, fromOnGround, toOnGround)
|
||||
&& !lowCeiling
|
||||
&& !isNearPistonOrWeb(player)
|
||||
&& (levitationLevel == 0 || !wasLevitating)) {
|
||||
boolean fromSlime = event.getFrom().getBlock().getType() == Material.SLIME_BLOCK
|
||||
|| event.getFrom().clone().subtract(0.0, 0.1, 0.0).getBlock().getType() == Material.SLIME_BLOCK;
|
||||
boolean toSlime = event.getTo().getBlock().getType() == Material.SLIME_BLOCK
|
||||
|| event.getTo().clone().subtract(0.0, 0.1, 0.0).getBlock().getType() == Material.SLIME_BLOCK;
|
||||
if (fromSlime || toSlime) {
|
||||
validMotion = VerticalMotionModel.isWithinUpperBound(deltaY, 1.0, moveTolerance);
|
||||
if (!this.slimeImpactSpeedByPlayer.containsKey(playerId)) {
|
||||
this.slimeImpactSpeedByPlayer.put(playerId, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.slimeImpactSpeedByPlayer.containsKey(playerId)) {
|
||||
if (this.slimeBounceTicksByPlayer.containsKey(playerId) && this.slimeBounceTicksByPlayer.get(playerId) <= 2) {
|
||||
double expectedBounce = VerticalMotionModel.predictSlimeBounceDeltaY(this.slimeImpactSpeedByPlayer.get(playerId));
|
||||
validMotion = VerticalMotionModel.isWithinUpperBound(deltaY, expectedBounce, moveTolerance);
|
||||
if (this.slimeBounceTicksByPlayer.get(playerId) == 10) {
|
||||
this.slimeImpactSpeedByPlayer.remove(playerId);
|
||||
this.slimeBounceTicksByPlayer.remove(playerId);
|
||||
}
|
||||
} else {
|
||||
this.slimeBounceTicksByPlayer.put(playerId, 0);
|
||||
double expectedBounce = VerticalMotionModel.predictSlimeBounceDeltaY(this.slimeImpactSpeedByPlayer.get(playerId));
|
||||
validMotion = VerticalMotionModel.isWithinUpperBound(deltaY, expectedBounce, moveTolerance);
|
||||
}
|
||||
|
||||
if (this.slimeBounceTicksByPlayer.containsKey(playerId)) {
|
||||
this.slimeBounceTicksByPlayer.put(playerId, this.slimeBounceTicksByPlayer.get(playerId) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!fromSlime && toSlime && !fromOnGround && toOnGround) {
|
||||
double predictedNext = VerticalMotionModel.predictNextDeltaY(this.previousDeltaYByPlayer.get(playerId));
|
||||
this.slimeImpactSpeedByPlayer.put(playerId, predictedNext < 0.9 ? 0.9 : predictedNext);
|
||||
}
|
||||
|
||||
if (this.previousDeltaYByPlayer.get(playerId) > 0.0 && deltaY < 0.0) {
|
||||
validMotion = true;
|
||||
}
|
||||
|
||||
if (fromOnGround && toOnGround && deltaY > 0.0) {
|
||||
validMotion = true;
|
||||
}
|
||||
} else {
|
||||
validMotion = true;
|
||||
}
|
||||
|
||||
if (toOnGround && Math.abs(deltaY) < 0.8) {
|
||||
validMotion = true;
|
||||
}
|
||||
|
||||
if (!validMotion && !this.graceExemptPlayers.contains(playerId) && (deltaY < 0.0 && deltaY > 2.0 || hasActiveVelocity)) {
|
||||
this.graceExemptPlayers.add(playerId);
|
||||
validMotion = true;
|
||||
}
|
||||
|
||||
if (this.previousDeltaYByPlayer.get(playerId) >= 0.0 && deltaY < 0.0 && deltaY > -0.6) {
|
||||
validMotion = true;
|
||||
}
|
||||
|
||||
if (levitationLevel == 0 && wasLevitating && Math.abs(deltaY) < 1.0) {
|
||||
validMotion = true;
|
||||
}
|
||||
|
||||
if (!validMotion) {
|
||||
if (this.recordViolation(
|
||||
playerId,
|
||||
3,
|
||||
HackType.GLIDE,
|
||||
player.getName() + " failed Glide: didn't fall correctly (change in y:" + deltaY + ")"
|
||||
)
|
||||
&& this.teleport
|
||||
&& (this.getViolationLevel(player) > this.minVl || Math.abs(deltaY) > 1.5)) {
|
||||
applyVerticalSetback(player, event, this, this.plugin);
|
||||
this.previousDeltaYByPlayer.put(playerId, player.getVelocity().getY());
|
||||
}
|
||||
} else {
|
||||
this.decreaseViolationLevel(playerId, 1);
|
||||
}
|
||||
|
||||
if (validMotion) {
|
||||
this.previousDeltaYByPlayer.put(playerId, deltaY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isEligibleForVerticalCheck(PlayerMoveEvent event, boolean fromOnGround, boolean toOnGround) {
|
||||
Player player = event.getPlayer();
|
||||
return player.getVehicle() == null
|
||||
&& !Speed.isNearPartialHeightBlock(player)
|
||||
&& !Jesus.isOverLiquid(player)
|
||||
&& !isAboveLiquid(player);
|
||||
}
|
||||
|
||||
public static boolean isAboveLiquid(Player player) {
|
||||
BlockCache cache = new BlockCache(player.getLocation());
|
||||
return cache.getNegativeOffsetBlock(0.0, 0.5, 0.45).isLiquid()
|
||||
|| cache.getNegativeOffsetBlock(0.45, 0.6, 0.0).isLiquid()
|
||||
|| cache.getNegativeOffsetBlock(0.0, 0.6, -0.45).isLiquid()
|
||||
|| cache.getNegativeOffsetBlock(-0.45, 0.6, 0.0).isLiquid()
|
||||
|| cache.getNegativeOffsetBlock(-0.45, 0.6, -0.45).isLiquid()
|
||||
|| cache.getNegativeOffsetBlock(-0.45, 0.6, 0.45).isLiquid()
|
||||
|| cache.getNegativeOffsetBlock(0.45, 0.6, -0.45).isLiquid()
|
||||
|| cache.getNegativeOffsetBlock(0.45, 0.6, 0.45).isLiquid();
|
||||
}
|
||||
|
||||
public static boolean isNearPistonOrWeb(Player player) {
|
||||
Set<Block> blocks = new HashSet<>();
|
||||
BlockCache cache = new BlockCache(player.getLocation());
|
||||
blocks.add(cache.getNegativeOffsetBlock(0.0, 0.1, 0.3));
|
||||
blocks.add(cache.getNegativeOffsetBlock(0.3, 0.1, 0.0));
|
||||
blocks.add(cache.getNegativeOffsetBlock(0.0, 0.1, -0.3));
|
||||
blocks.add(cache.getNegativeOffsetBlock(-0.3, 0.1, 0.0));
|
||||
blocks.add(cache.getNegativeOffsetBlock(-0.3, 0.1, -0.3));
|
||||
blocks.add(cache.getNegativeOffsetBlock(-0.3, 0.1, 0.3));
|
||||
blocks.add(cache.getNegativeOffsetBlock(0.3, 0.1, -0.3));
|
||||
blocks.add(cache.getNegativeOffsetBlock(0.3, 0.1, 0.3));
|
||||
blocks.add(cache.getNegativeOffsetBlock(0.0, 0.1, 0.0));
|
||||
|
||||
for (Block block : blocks) {
|
||||
if (isPistonOrWeb(block)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Block above = block.getRelative(BlockFace.UP);
|
||||
if (above.getType() == Material.WEB || above.getRelative(BlockFace.UP).getType() == Material.WEB) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isPistonOrWeb(Block block) {
|
||||
Material type = block.getType();
|
||||
return type == Material.PISTON_BASE
|
||||
|| type == Material.PISTON_EXTENSION
|
||||
|| type == Material.PISTON_MOVING_PIECE
|
||||
|| type == Material.PISTON_STICKY_BASE
|
||||
|| type == Material.WEB;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerToggleFlight(PlayerToggleFlightEvent event) {
|
||||
this.previousDeltaYByPlayer.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
public static void applyVerticalSetback(Player player, PlayerMoveEvent event, Detector detector, AAC plugin) {
|
||||
applyVerticalSetback(player, event, plugin, detector, player.getVelocity().getY());
|
||||
}
|
||||
|
||||
private static void applyVerticalSetback(Player player, PlayerMoveEvent event, AAC plugin, Detector detector, double velocityY) {
|
||||
if (velocityY > -0.05) {
|
||||
velocityY = -0.05;
|
||||
}
|
||||
|
||||
Location safeLocation = plugin.setbackManager.getSafeLocation(player);
|
||||
if (safeLocation != null) {
|
||||
double dx = Math.abs(event.getTo().getX() - safeLocation.getX());
|
||||
double dz = Math.abs(event.getTo().getZ() - safeLocation.getZ());
|
||||
double horizontalDistance = Math.sqrt(Math.pow(dx, 2.0) + Math.pow(dz, 2.0));
|
||||
if (horizontalDistance < 3.0 && event.getFrom().getY() > safeLocation.getY()) {
|
||||
plugin.setbackManager.beginSetback(detector, player);
|
||||
player.teleport(safeLocation, TeleportCause.UNKNOWN);
|
||||
}
|
||||
}
|
||||
|
||||
Location firstTarget = event.getFrom();
|
||||
|
||||
for (double step = 0.0; step > velocityY && Phase.isLocationPassable(player.getLocation().add(0.0, step, 0.0)); step -= 0.3) {
|
||||
firstTarget = player.getLocation().add(0.0, step, 0.0);
|
||||
}
|
||||
|
||||
Location secondTarget = event.getFrom();
|
||||
|
||||
for (double fineStep = 0.0; fineStep > velocityY && Phase.isLocationPassable(firstTarget.clone().add(0.0, fineStep, 0.0)); fineStep -= 0.1) {
|
||||
secondTarget = firstTarget.clone().add(0.0, fineStep, 0.0);
|
||||
}
|
||||
|
||||
float previousFallDistance = player.getFallDistance();
|
||||
plugin.setbackManager.beginSetback(detector, player);
|
||||
player.teleport(firstTarget, TeleportCause.UNKNOWN);
|
||||
plugin.setbackManager.beginSetback(detector, player);
|
||||
player.setVelocity(new Vector(0.0, velocityY > 0.0 ? 0.0 : velocityY, 0.0));
|
||||
plugin.getServer()
|
||||
.getScheduler()
|
||||
.scheduleSyncDelayedTask(plugin, new VerticalSetbackTask(player, secondTarget, previousFallDistance, event, plugin, detector, velocityY));
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new ReleaseSetbackTask(plugin, player), 2L);
|
||||
}
|
||||
|
||||
private class ResetExemptionsTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
Glide.this.graceExemptPlayers.clear();
|
||||
}
|
||||
}
|
||||
|
||||
private static final class VerticalSetbackTask implements Runnable {
|
||||
private final Player player;
|
||||
private final Location targetLocation;
|
||||
private final float previousFallDistance;
|
||||
private final PlayerMoveEvent moveEvent;
|
||||
private final AAC plugin;
|
||||
private final Detector detector;
|
||||
private final double velocityY;
|
||||
|
||||
VerticalSetbackTask(
|
||||
Player player,
|
||||
Location targetLocation,
|
||||
float previousFallDistance,
|
||||
PlayerMoveEvent moveEvent,
|
||||
AAC plugin,
|
||||
Detector detector,
|
||||
double velocityY
|
||||
) {
|
||||
this.player = player;
|
||||
this.targetLocation = targetLocation;
|
||||
this.previousFallDistance = previousFallDistance;
|
||||
this.moveEvent = moveEvent;
|
||||
this.plugin = plugin;
|
||||
this.detector = detector;
|
||||
this.velocityY = velocityY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
this.player.teleport(this.targetLocation, TeleportCause.UNKNOWN);
|
||||
this.player.setFallDistance(this.previousFallDistance + (float) (this.moveEvent.getFrom().getY() - this.targetLocation.getY()));
|
||||
this.plugin.setbackManager.beginSetback(this.detector, this.player);
|
||||
this.player.setVelocity(new Vector(0.0, this.velocityY > 0.0 ? 0.0 : this.velocityY, 0.0));
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ReleaseSetbackTask implements Runnable {
|
||||
private final AAC plugin;
|
||||
private final Player player;
|
||||
|
||||
ReleaseSetbackTask(AAC plugin, Player player) {
|
||||
this.plugin = plugin;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
this.plugin.setbackManager.endSetback(this.player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package me.konsolas.aac.detectors.movement;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.PacketType.Play.Client;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public final class HeadRoll extends Detector {
|
||||
public HeadRoll(AAC plugin) {
|
||||
super(plugin);
|
||||
PacketListener packetListener = new PacketListener(this.plugin, Client.LOOK, Client.POSITION_LOOK);
|
||||
this.packetListeners.add(packetListener);
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(packetListener);
|
||||
}
|
||||
|
||||
private class PacketListener extends PacketAdapter {
|
||||
PacketListener(Plugin plugin, PacketType... packetTypes) {
|
||||
super(plugin, packetTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
if (event.getPacketType() == Client.LOOK || event.getPacketType() == Client.POSITION_LOOK) {
|
||||
try {
|
||||
Player player = event.getPlayer();
|
||||
if (HeadRoll.this.plugin.checkManager.isBypassed(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
float pitch = event.getPacket().getFloat().read(1);
|
||||
if (pitch > 90.1F || pitch < -90.1F) {
|
||||
event.setCancelled(true);
|
||||
HeadRoll.this.recordViolation(
|
||||
player.getUniqueId(),
|
||||
1,
|
||||
HackType.HEADROLL,
|
||||
player.getName() + " failed HeadRoll: Moved with an illegal pitch (" + pitch + ")"
|
||||
);
|
||||
}
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package me.konsolas.aac.detectors.movement;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import me.konsolas.aac.detectors.MoveListener;
|
||||
import me.konsolas.aac.util.BlockCache;
|
||||
import me.konsolas.aac.util.general.ElytraUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
public final class Jesus extends Detector implements MoveListener {
|
||||
private final Map<UUID, Location> lastSampledLocations = new HashMap<>();
|
||||
private final Map<UUID, Integer> floatingTicks = new HashMap<>();
|
||||
private final Set<UUID> touchedLiquidPlayers = new HashSet<>();
|
||||
private boolean teleport = true;
|
||||
|
||||
public Jesus(AAC plugin) {
|
||||
super(plugin);
|
||||
this.teleport = this.plugin.getConfig().getBoolean("jesus.teleport", this.teleport);
|
||||
this.scheduledTaskIds.add(Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new SampleTask(), 20L, 100L));
|
||||
}
|
||||
|
||||
public static boolean isOverLiquid(Player player) {
|
||||
BlockCache cache = new BlockCache(player.getLocation());
|
||||
return isSolidOrNonLiquid(cache.getNegativeOffsetBlock(0.0, 0.5, 0.3))
|
||||
|| isSolidOrNonLiquid(cache.getNegativeOffsetBlock(0.3, 0.6, 0.0))
|
||||
|| isSolidOrNonLiquid(cache.getNegativeOffsetBlock(0.0, 0.6, -0.3))
|
||||
|| isSolidOrNonLiquid(cache.getNegativeOffsetBlock(-0.3, 0.6, 0.0))
|
||||
|| isSolidOrNonLiquid(cache.getNegativeOffsetBlock(-0.3, 0.6, -0.3))
|
||||
|| isSolidOrNonLiquid(cache.getNegativeOffsetBlock(-0.3, 0.6, 0.3))
|
||||
|| isSolidOrNonLiquid(cache.getNegativeOffsetBlock(0.3, 0.6, -0.3))
|
||||
|| isSolidOrNonLiquid(cache.getNegativeOffsetBlock(0.3, 0.6, 0.3))
|
||||
|| isSolidOrNonLiquid(cache.getNegativeOffsetBlock(0.0, 0.0, 0.3))
|
||||
|| isSolidOrNonLiquid(cache.getNegativeOffsetBlock(0.3, 0.0, 0.0))
|
||||
|| isSolidOrNonLiquid(cache.getNegativeOffsetBlock(0.0, 0.0, -0.3))
|
||||
|| isSolidOrNonLiquid(cache.getNegativeOffsetBlock(-0.3, 0.0, 0.0))
|
||||
|| isSolidOrNonLiquid(cache.getNegativeOffsetBlock(-0.3, 0.0, -0.3))
|
||||
|| isSolidOrNonLiquid(cache.getNegativeOffsetBlock(-0.3, 0.0, 0.3))
|
||||
|| isSolidOrNonLiquid(cache.getNegativeOffsetBlock(0.3, 0.0, -0.3))
|
||||
? false
|
||||
: cache.getNegativeOffsetBlock(0.0, 0.5, 0.0).isLiquid()
|
||||
|| cache.getNegativeOffsetBlock(0.0, 1.5, 0.0).isLiquid()
|
||||
|| cache.getOriginBlock().isLiquid();
|
||||
}
|
||||
|
||||
private static boolean isSolidOrNonLiquid(Block block) {
|
||||
return !block.isLiquid() && !block.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldProcessMove(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (!player.isFlying() && player.getVehicle() == null) {
|
||||
for (Entity nearby : player.getNearbyEntities(2.0, 2.0, 2.0)) {
|
||||
if (nearby.getType() == EntityType.BOAT || nearby.getType() == EntityType.MINECART) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return !ElytraUtil.isGliding(player);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerMove(PlayerMoveEvent event, boolean fromOnGround, boolean toOnGround) {
|
||||
Player player = event.getPlayer();
|
||||
UUID playerId = player.getUniqueId();
|
||||
if (isOverLiquid(player)
|
||||
&& player.getLocation().add(0.0, 0.5, 0.0).getBlock().isEmpty()
|
||||
&& (
|
||||
player.getLocation().subtract(0.0, 1.5, 0.0).getBlock().isLiquid()
|
||||
|| player.getLocation().subtract(0.0, 0.5, 0.0).getBlock().isLiquid()
|
||||
)
|
||||
&& !this.plugin.combatTracker.wasRecentlyDamaged(player)) {
|
||||
if (player.getLocation().subtract(0.0, 0.2, 0.0).getBlock().isLiquid()) {
|
||||
if (event.getTo().getY() == event.getFrom().getY()
|
||||
&& this.floatingTicks.containsKey(playerId)
|
||||
&& this.recordViolation(playerId, 1, HackType.JESUS, player.getName() + " failed Jesus: didn't sink in water")
|
||||
&& this.teleport) {
|
||||
event.setTo(event.getFrom());
|
||||
}
|
||||
|
||||
if (!this.floatingTicks.containsKey(playerId)) {
|
||||
this.floatingTicks.put(playerId, 0);
|
||||
}
|
||||
|
||||
this.touchedLiquidPlayers.add(playerId);
|
||||
}
|
||||
|
||||
if (this.touchedLiquidPlayers.contains(playerId)) {
|
||||
if (!this.floatingTicks.containsKey(playerId)) {
|
||||
this.floatingTicks.put(playerId, 0);
|
||||
}
|
||||
|
||||
this.floatingTicks.put(playerId, this.floatingTicks.get(playerId) + 1);
|
||||
if (this.floatingTicks.get(playerId) > 20
|
||||
&& this.recordViolation(playerId, 1, HackType.JESUS, player.getName() + " failed Jesus: tried to float above water")
|
||||
&& this.teleport) {
|
||||
event.setTo(event.getFrom().subtract(0.0, 0.1, 0.0));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.floatingTicks.remove(playerId);
|
||||
}
|
||||
}
|
||||
|
||||
private class SampleTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
Jesus.this.lastSampledLocations.put(player.getUniqueId(), player.getLocation());
|
||||
Jesus.this.decreaseViolationLevel(player.getUniqueId(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
package me.konsolas.aac.detectors.movement;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.PacketType.Play.Client;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import me.konsolas.aac.detectors.MoveListener;
|
||||
import me.konsolas.aac.util.ground.GroundUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public final class NoFall extends Detector implements MoveListener {
|
||||
private double requiredVelocity = -0.2;
|
||||
private boolean dealDamage = true;
|
||||
private final Map<UUID, Double> highestAirY = new HashMap<>();
|
||||
private final Map<UUID, Double> pendingFallStartY = new HashMap<>();
|
||||
private final Set<UUID> stationaryGroundPlayers = new HashSet<>();
|
||||
private final Queue<PacketInfo> queuedPackets = new ConcurrentLinkedQueue<>();
|
||||
|
||||
public NoFall(AAC plugin) {
|
||||
super(plugin);
|
||||
this.requiredVelocity = this.plugin.getConfig().getDouble("nofall.required_velocity", this.requiredVelocity);
|
||||
this.dealDamage = this.plugin.getConfig().getBoolean("nofall.deal_damage", this.dealDamage);
|
||||
PacketListener packetListener = new PacketListener(this.plugin, Client.POSITION, Client.POSITION_LOOK, Client.FLYING);
|
||||
this.packetListeners.add(packetListener);
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(packetListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldProcessMove(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
return player.getGameMode() != GameMode.CREATIVE
|
||||
&& player.getGameMode() != GameMode.SPECTATOR
|
||||
&& !player.getAllowFlight()
|
||||
&& player.getVehicle() == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTick(long tick) {
|
||||
while (!this.queuedPackets.isEmpty()) {
|
||||
PacketInfo packetInfo = this.queuedPackets.poll();
|
||||
Player player = packetInfo.player;
|
||||
UUID playerId = player.getUniqueId();
|
||||
boolean serverOnGround = GroundUtil.isOnGround(packetInfo.location);
|
||||
boolean clientOnGround = packetInfo.onGround;
|
||||
double velocityY = packetInfo.velocityY;
|
||||
double playerY = packetInfo.playerY;
|
||||
this.plugin.logger.logPlayerDebug(player, "(NoFall) Packet [onGround r:" + clientOnGround + "]");
|
||||
if (!serverOnGround && this.highestAirY.containsKey(playerId)) {
|
||||
double startY = this.highestAirY.get(playerId);
|
||||
if (startY - playerY > 3.0) {
|
||||
if (velocityY < this.requiredVelocity) {
|
||||
if (clientOnGround
|
||||
&& this.recordViolation(
|
||||
playerId,
|
||||
1,
|
||||
HackType.NOFALL,
|
||||
player.getName() + " failed NoFall: Claimed to be on the ground midair"
|
||||
)
|
||||
&& this.dealDamage) {
|
||||
this.pendingFallStartY.put(playerId, startY);
|
||||
}
|
||||
} else if (clientOnGround) {
|
||||
this.pendingFallStartY.put(playerId, startY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerMove(PlayerMoveEvent event, boolean fromOnGround, boolean toOnGround) {
|
||||
Player player = event.getPlayer();
|
||||
UUID playerId = player.getUniqueId();
|
||||
double deltaY = event.getTo().getY() - event.getFrom().getY();
|
||||
double toY = event.getTo().getY();
|
||||
if (toOnGround && deltaY >= 0.0 && this.pendingFallStartY.containsKey(playerId)) {
|
||||
this.plugin.logger.logPlayerDebug(player, "(NoFall) " + player.getName() + " landed");
|
||||
float fallDamage = this.calculateFallDamage(this.pendingFallStartY.get(playerId), toY);
|
||||
if (fallDamage >= 1.0) {
|
||||
player.setFallDistance(fallDamage + 3.0F);
|
||||
PacketContainer flyingPacket = ProtocolLibrary.getProtocolManager().createPacket(Client.FLYING);
|
||||
flyingPacket.getBooleans().write(0, true);
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new ReplayPacketTask(event, flyingPacket), 1L);
|
||||
this.plugin.logger.log("(NoFall) Dealing " + fallDamage + " damage to " + player.getName());
|
||||
this.pendingFallStartY.remove(playerId);
|
||||
this.highestAirY.remove(playerId);
|
||||
}
|
||||
}
|
||||
|
||||
if (toOnGround && deltaY == 0.0) {
|
||||
this.stationaryGroundPlayers.add(playerId);
|
||||
} else {
|
||||
this.stationaryGroundPlayers.remove(playerId);
|
||||
}
|
||||
|
||||
if (!fromOnGround) {
|
||||
if (this.highestAirY.containsKey(playerId)) {
|
||||
if (toY > this.highestAirY.get(playerId)) {
|
||||
this.highestAirY.put(playerId, toY);
|
||||
this.plugin
|
||||
.logger
|
||||
.logPlayerDebug(player, "(NoFall) " + player.getName() + " New highestY for " + player.getName() + " [u:" + toY + "]");
|
||||
}
|
||||
} else {
|
||||
this.highestAirY.put(playerId, toY);
|
||||
this.plugin
|
||||
.logger
|
||||
.logPlayerDebug(player, "(NoFall) " + player.getName() + " created highestY for " + player.getName() + " [u:" + toY + "]");
|
||||
}
|
||||
} else {
|
||||
this.highestAirY.remove(playerId);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
UUID playerId = event.getPlayer().getUniqueId();
|
||||
this.highestAirY.put(playerId, event.getPlayer().getLocation().getY());
|
||||
this.pendingFallStartY.remove(playerId);
|
||||
}
|
||||
|
||||
private float calculateFallDamage(double startY, double endY) {
|
||||
return (float) (startY - endY - 3.0);
|
||||
}
|
||||
|
||||
public boolean hasPendingFallDamage(Player player) {
|
||||
return this.pendingFallStartY.containsKey(player.getUniqueId());
|
||||
}
|
||||
|
||||
private static final class PacketInfo {
|
||||
final Location location;
|
||||
final boolean onGround;
|
||||
final double playerY;
|
||||
final double velocityY;
|
||||
final Player player;
|
||||
|
||||
PacketInfo(Location location, boolean onGround, double playerY, double velocityY, Player player) {
|
||||
this.location = location;
|
||||
this.onGround = onGround;
|
||||
this.playerY = playerY;
|
||||
this.velocityY = velocityY;
|
||||
this.player = player;
|
||||
}
|
||||
}
|
||||
|
||||
private class PacketListener extends PacketAdapter {
|
||||
PacketListener(Plugin plugin, PacketType... packetTypes) {
|
||||
super(plugin, packetTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player.getGameMode() != GameMode.CREATIVE
|
||||
&& player.getGameMode() != GameMode.SPECTATOR
|
||||
&& !player.getAllowFlight()
|
||||
&& player.getVehicle() == null) {
|
||||
PacketContainer packet = event.getPacket();
|
||||
Location location = player.getLocation();
|
||||
if (event.getPacketType() == Client.POSITION_LOOK || event.getPacketType() == Client.POSITION) {
|
||||
location = new Location(
|
||||
player.getWorld(),
|
||||
packet.getDoubles().read(0),
|
||||
packet.getDoubles().read(1),
|
||||
packet.getDoubles().read(2)
|
||||
);
|
||||
}
|
||||
|
||||
NoFall.this.queuedPackets.add(
|
||||
new PacketInfo(
|
||||
location,
|
||||
packet.getBooleans().read(0),
|
||||
player.getLocation().getY(),
|
||||
player.getVelocity().getY(),
|
||||
player
|
||||
)
|
||||
);
|
||||
if (NoFall.this.stationaryGroundPlayers.contains(player.getUniqueId())) {
|
||||
packet.getBooleans().write(0, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ReplayPacketTask implements Runnable {
|
||||
private final PlayerMoveEvent moveEvent;
|
||||
private final PacketContainer packet;
|
||||
|
||||
ReplayPacketTask(PlayerMoveEvent moveEvent, PacketContainer packet) {
|
||||
this.moveEvent = moveEvent;
|
||||
this.packet = packet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().recieveClientPacket(this.moveEvent.getPlayer(), this.packet, false);
|
||||
} catch (Exception ex) {
|
||||
NoFall.this.plugin.logger.log("(NoFall) Failed to deal fall damage to player: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,291 @@
|
||||
package me.konsolas.aac.detectors.movement;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import me.konsolas.aac.detectors.MoveListener;
|
||||
import me.konsolas.aac.util.BlockCache;
|
||||
import me.konsolas.aac.util.general.ElytraUtil;
|
||||
import me.konsolas.aac.util.general.NumberUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public class NormalMovements extends Detector implements MoveListener {
|
||||
private static final double BASE_JUMP_HEIGHT = 0.42;
|
||||
private final Map<UUID, Integer> floatTicks = new HashMap<>();
|
||||
private final Map<UUID, Double> previousDeltaYByPlayer = new HashMap<>();
|
||||
private final Set<UUID> graceExemptPlayers = new HashSet<>();
|
||||
private boolean fJump = true;
|
||||
private boolean fStep = true;
|
||||
private boolean fFloat = true;
|
||||
private boolean fDy = true;
|
||||
private boolean teleport = true;
|
||||
|
||||
public NormalMovements(AAC plugin) {
|
||||
super(plugin);
|
||||
this.fJump = this.plugin.getConfig().getBoolean("normalmovements.f_jump", this.fJump);
|
||||
this.fStep = this.plugin.getConfig().getBoolean("normalmovements.f_step", this.fStep);
|
||||
this.fFloat = this.plugin.getConfig().getBoolean("normalmovements.f_float", this.fFloat);
|
||||
this.fDy = this.plugin.getConfig().getBoolean("normalmovements.f_dy", this.fDy);
|
||||
this.teleport = this.plugin.getConfig().getBoolean("normalmovements.teleport", this.teleport);
|
||||
this.scheduledTaskIds
|
||||
.add(Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new ViolationDecayTask(), 1L, 27L));
|
||||
this.scheduledTaskIds
|
||||
.add(Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new ResetExemptionsTask(), 22L, 19L));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerToggleFlight(PlayerToggleFlightEvent event) {
|
||||
UUID playerId = event.getPlayer().getUniqueId();
|
||||
this.floatTicks.remove(playerId);
|
||||
this.previousDeltaYByPlayer.remove(playerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerMove(PlayerMoveEvent event, boolean fromOnGround, boolean toOnGround) {
|
||||
Player player = event.getPlayer();
|
||||
UUID playerId = player.getUniqueId();
|
||||
int jumpBoostLevel = 0;
|
||||
|
||||
for (PotionEffect effect : player.getActivePotionEffects()) {
|
||||
if (effect.getType().equals(PotionEffectType.JUMP)) {
|
||||
jumpBoostLevel = effect.getAmplifier() + 1;
|
||||
}
|
||||
}
|
||||
|
||||
double deltaY = event.getTo().getY() - event.getFrom().getY();
|
||||
boolean nearSpecialBlock = isNearSpecialBlock(player);
|
||||
|
||||
if (this.fStep && fromOnGround && toOnGround) {
|
||||
if (jumpBoostLevel <= 1) {
|
||||
if (deltaY > 0.5625) {
|
||||
if (!this.graceExemptPlayers.contains(playerId)) {
|
||||
this.graceExemptPlayers.add(playerId);
|
||||
} else if (this.recordViolation(
|
||||
playerId,
|
||||
1,
|
||||
HackType.NORMALMOVEMENTS,
|
||||
player.getName() + " failed NormalMovements: moved unexpectedly f:step:0 (dY:" + deltaY + ")"
|
||||
)) {
|
||||
this.applySetback(event, MovementViolationType.FLY);
|
||||
}
|
||||
}
|
||||
} else if (deltaY > jumpBoostLevel / 10.0 + BASE_JUMP_HEIGHT) {
|
||||
if (!this.graceExemptPlayers.contains(playerId)) {
|
||||
this.graceExemptPlayers.add(playerId);
|
||||
} else if (this.recordViolation(
|
||||
playerId,
|
||||
1,
|
||||
HackType.NORMALMOVEMENTS,
|
||||
player.getName() + " failed NormalMovements: moved unexpectedly f:step:0 (dY:" + deltaY + ")"
|
||||
)) {
|
||||
this.applySetback(event, MovementViolationType.FLY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.fFloat) {
|
||||
if (!fromOnGround && !toOnGround && NumberUtil.approximatelyEqual(0.0, deltaY, 0.1) && !nearSpecialBlock) {
|
||||
if (!this.floatTicks.containsKey(playerId)) {
|
||||
this.floatTicks.put(playerId, 0);
|
||||
}
|
||||
|
||||
int currentFloatTicks = this.floatTicks.get(playerId);
|
||||
this.floatTicks.put(playerId, currentFloatTicks + 1);
|
||||
if (currentFloatTicks > 2) {
|
||||
if (!this.graceExemptPlayers.contains(playerId)) {
|
||||
this.graceExemptPlayers.add(playerId);
|
||||
} else if (this.recordViolation(
|
||||
playerId,
|
||||
1,
|
||||
HackType.NORMALMOVEMENTS,
|
||||
player.getName() + " failed NormalMovements: moved unexpectedly f:float:" + currentFloatTicks + " (dY:" + deltaY + ")"
|
||||
)) {
|
||||
if (currentFloatTicks < 4) {
|
||||
this.applySetback(event, MovementViolationType.SPEED);
|
||||
} else {
|
||||
this.applySetback(event, MovementViolationType.GLIDE);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.floatTicks.remove(playerId);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.fDy && this.previousDeltaYByPlayer.containsKey(playerId) && !nearSpecialBlock) {
|
||||
double previousDeltaY = this.previousDeltaYByPlayer.get(playerId);
|
||||
if (!fromOnGround && !toOnGround && deltaY == previousDeltaY) {
|
||||
if (!this.graceExemptPlayers.contains(playerId)) {
|
||||
this.graceExemptPlayers.add(playerId);
|
||||
} else if (this.recordViolation(
|
||||
playerId,
|
||||
1,
|
||||
HackType.NORMALMOVEMENTS,
|
||||
player.getName() + " failed NormalMovements: moved unexpectedly f:dy:= (dY:" + deltaY + ")"
|
||||
)) {
|
||||
this.applySetback(event, MovementViolationType.GLIDE);
|
||||
}
|
||||
}
|
||||
|
||||
if (player.getVelocity().getY() > -0.4 && previousDeltaY > -0.2 && deltaY < -0.6) {
|
||||
if (!this.graceExemptPlayers.contains(playerId)) {
|
||||
this.graceExemptPlayers.add(playerId);
|
||||
} else if (this.recordViolation(
|
||||
playerId,
|
||||
1,
|
||||
HackType.NORMALMOVEMENTS,
|
||||
player.getName() + " failed NormalMovements: moved unexpectedly f:dy:- (dY:" + deltaY + ")"
|
||||
)) {
|
||||
this.applySetback(event, MovementViolationType.GLIDE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.previousDeltaYByPlayer.put(playerId, deltaY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldProcessMove(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (!player.isFlying()
|
||||
&& player.getGameMode() != GameMode.CREATIVE
|
||||
&& player.getGameMode() != GameMode.SPECTATOR
|
||||
&& player.getVehicle() == null) {
|
||||
for (Entity nearby : player.getNearbyEntities(2.0, 2.0, 2.0)) {
|
||||
if (nearby.getType() == EntityType.BOAT || nearby.getType() == EntityType.MINECART) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return !ElytraUtil.isGliding(player)
|
||||
&& !this.plugin.combatTracker.wasRecentlyDamaged(player)
|
||||
&& !this.plugin.playerStateTracker.hasActiveVelocity(player)
|
||||
&& player.getVelocity().getY() < 0.5
|
||||
&& Math.abs(player.getVelocity().getX()) < 0.5
|
||||
&& Math.abs(player.getVelocity().getZ()) < 0.5;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void applySetback(PlayerMoveEvent event, MovementViolationType violationType) {
|
||||
if (this.teleport) {
|
||||
Player player = event.getPlayer();
|
||||
switch (violationType) {
|
||||
case FLY:
|
||||
this.plugin.setbackManager.beginSetback(this, player);
|
||||
player.teleport(this.plugin.setbackManager.getSafeLocation(player), TeleportCause.UNKNOWN);
|
||||
break;
|
||||
case SPEED:
|
||||
Speed speedCheck = (Speed) this.plugin.checkManager.getCheck(HackType.SPEED);
|
||||
if (speedCheck != null) {
|
||||
event.setTo(speedCheck.getSetbackLocation(player));
|
||||
} else {
|
||||
event.setTo(event.getFrom());
|
||||
}
|
||||
break;
|
||||
case GLIDE:
|
||||
Glide.applyVerticalSetback(player, event, this, this.plugin);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clearCaches() {
|
||||
this.floatTicks.clear();
|
||||
this.previousDeltaYByPlayer.clear();
|
||||
}
|
||||
|
||||
public static boolean isAdjacentToLiquid(Player player) {
|
||||
Block origin = player.getLocation().getBlock();
|
||||
|
||||
for (BlockFace face : BlockFace.values()) {
|
||||
if (origin.getRelative(face).isLiquid()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isStandingOnSlime(Player player) {
|
||||
return player.getLocation().subtract(0.0, 1.0, 0.0).getBlock().getType() == Material.SLIME_BLOCK;
|
||||
}
|
||||
|
||||
public static boolean isNearSpecialBlock(Player player) {
|
||||
Set<Block> blocks = new HashSet<>();
|
||||
BlockCache cache = new BlockCache(player.getLocation());
|
||||
blocks.add(cache.getNegativeOffsetBlock(0.0, 0.1, 0.3));
|
||||
blocks.add(cache.getNegativeOffsetBlock(0.3, 0.1, 0.0));
|
||||
blocks.add(cache.getNegativeOffsetBlock(0.0, 0.1, -0.3));
|
||||
blocks.add(cache.getNegativeOffsetBlock(-0.3, 0.1, 0.0));
|
||||
blocks.add(cache.getNegativeOffsetBlock(-0.3, 0.1, -0.3));
|
||||
blocks.add(cache.getNegativeOffsetBlock(-0.3, 0.1, 0.3));
|
||||
blocks.add(cache.getNegativeOffsetBlock(0.3, 0.1, -0.3));
|
||||
blocks.add(cache.getNegativeOffsetBlock(0.3, 0.1, 0.3));
|
||||
blocks.add(cache.getNegativeOffsetBlock(0.0, 0.1, 0.0));
|
||||
|
||||
for (Block block : blocks) {
|
||||
if (isSpecialBlock(block)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Block above = block.getRelative(BlockFace.UP);
|
||||
if (above.getType() == Material.WEB || above.getRelative(BlockFace.UP).getType() == Material.WEB) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isSpecialBlock(Block block) {
|
||||
Material type = block.getType();
|
||||
return type == Material.PISTON_BASE
|
||||
|| type == Material.PISTON_EXTENSION
|
||||
|| type == Material.PISTON_MOVING_PIECE
|
||||
|| type == Material.PISTON_STICKY_BASE
|
||||
|| type == Material.WEB
|
||||
|| type == Material.SNOW;
|
||||
}
|
||||
|
||||
private enum MovementViolationType {
|
||||
SPEED,
|
||||
FLY,
|
||||
GLIDE
|
||||
}
|
||||
|
||||
private class ViolationDecayTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
for (UUID playerId : NormalMovements.this.violationLevels.keySet()) {
|
||||
NormalMovements.this.decreaseViolationLevel(playerId, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ResetExemptionsTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
NormalMovements.this.graceExemptPlayers.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,352 @@
|
||||
package me.konsolas.aac.detectors.movement;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.PacketType.Play.Client;
|
||||
import com.comphenix.protocol.PacketType.Play.Server;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import me.konsolas.aac.detectors.MoveListener;
|
||||
import me.konsolas.aac.internal.packetwrapper.WrapperPlayServerPosition;
|
||||
import me.konsolas.aac.internal.packetwrapper.WrapperPlayServerPosition.PlayerTeleportFlag;
|
||||
import me.konsolas.aac.util.BlockCache;
|
||||
import me.konsolas.aac.util.general.ElytraUtil;
|
||||
import me.konsolas.aac.util.ground.GroundUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public final class Phase extends Detector implements MoveListener {
|
||||
private final Set<UUID> exemptPlayers = new HashSet<>();
|
||||
private final Map<UUID, Location> lastValidLocations = new HashMap<>();
|
||||
private final ConcurrentMap<UUID, Long> frozenPlayers = new ConcurrentHashMap<>();
|
||||
private final Set<UUID> pendingUnfreezeSetbacks = new HashSet<>();
|
||||
private final Map<UUID, Block> enclosedBlocks = new HashMap<>();
|
||||
private int freezeTime = 500;
|
||||
private double maxDist = 3.0;
|
||||
private boolean checkVclip = true;
|
||||
|
||||
public Phase(AAC plugin) {
|
||||
super(plugin);
|
||||
this.freezeTime = this.plugin.getConfig().getInt("phase.freeze_time", this.freezeTime);
|
||||
this.maxDist = this.plugin.getConfig().getDouble("phase.max_dist", this.maxDist);
|
||||
this.checkVclip = this.plugin.getConfig().getBoolean("phase.check_vclip", this.checkVclip);
|
||||
PacketListener packetListener = new PacketListener(this.plugin, Client.POSITION, Client.POSITION_LOOK, Client.LOOK, Server.POSITION);
|
||||
this.packetListeners.add(packetListener);
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(packetListener);
|
||||
this.scheduledTaskIds
|
||||
.add(Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new ViolationDecayTask(), 69L, 47L));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldProcessMove(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
return player.getVehicle() == null
|
||||
&& player.getGameMode() != GameMode.SPECTATOR
|
||||
&& player.getGameMode() != GameMode.CREATIVE
|
||||
&& !this.exemptPlayers.contains(player.getUniqueId())
|
||||
&& !ElytraUtil.isGliding(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerMove(PlayerMoveEvent event, boolean fromOnGround, boolean toOnGround) {
|
||||
Player player = event.getPlayer();
|
||||
UUID playerId = player.getUniqueId();
|
||||
if (this.pendingUnfreezeSetbacks.contains(playerId)) {
|
||||
event.setTo(this.lastValidLocations.get(playerId));
|
||||
this.pendingUnfreezeSetbacks.remove(playerId);
|
||||
} else if (this.frozenPlayers.containsKey(playerId)) {
|
||||
event.setTo(this.lastValidLocations.get(playerId));
|
||||
} else {
|
||||
if (this.enclosedBlocks.containsKey(playerId)) {
|
||||
Block enclosedBlock = this.enclosedBlocks.get(playerId);
|
||||
if (isEnclosedInSolidBlocks(enclosedBlock.getLocation())) {
|
||||
if (!player.getLocation().getBlock().equals(enclosedBlock)
|
||||
&& this.recordViolation(
|
||||
playerId,
|
||||
1,
|
||||
HackType.PHASE,
|
||||
player.getName()
|
||||
+ " failed Phase: Moved out of "
|
||||
+ enclosedBlock.getType()
|
||||
+ " at "
|
||||
+ enclosedBlock.getLocation().toVector().toString()
|
||||
)) {
|
||||
event.setTo(enclosedBlock.getLocation().add(0.5, 0.0, 0.5));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
this.enclosedBlocks.remove(playerId);
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.lastValidLocations.containsKey(playerId)) {
|
||||
this.lastValidLocations.put(playerId, event.getFrom());
|
||||
}
|
||||
|
||||
double deltaY = event.getTo().getY() - event.getFrom().getY();
|
||||
double horizontalDistance = Math.sqrt(
|
||||
Math.pow(event.getTo().getX() - event.getFrom().getX(), 2.0)
|
||||
+ Math.pow(event.getTo().getZ() - event.getFrom().getZ(), 2.0)
|
||||
);
|
||||
if (this.checkVclip && horizontalDistance < 0.9) {
|
||||
if (deltaY < -1.0) {
|
||||
Location cursor = event.getFrom().clone();
|
||||
int minY = (int) cursor.getY() - 10 > event.getTo().getY() ? (int) cursor.getY() - 10 : (int) event.getTo().getY();
|
||||
|
||||
for (Block block = cursor.subtract(0.0, 1.0, 0.0).getBlock();
|
||||
cursor.getY() > minY;
|
||||
block = cursor.subtract(0.0, 1.0, 0.0).getBlock()) {
|
||||
if (GroundUtil.isSolidFullBlock(block)
|
||||
&& this.recordViolation(
|
||||
playerId,
|
||||
1,
|
||||
HackType.PHASE,
|
||||
player.getName()
|
||||
+ " failed Phase: clipped down through "
|
||||
+ block.getType()
|
||||
+ " at "
|
||||
+ block.getLocation().toVector().toString()
|
||||
)) {
|
||||
this.frozenPlayers.put(playerId, System.currentTimeMillis());
|
||||
this.enclosedBlocks.remove(playerId);
|
||||
event.setTo(this.lastValidLocations.get(playerId));
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (deltaY > 1.0) {
|
||||
Location cursor = event.getFrom().clone();
|
||||
int maxY = (int) cursor.getY() + 10 < event.getTo().getY() ? (int) cursor.getY() + 10 : (int) event.getTo().getY();
|
||||
|
||||
while (cursor.getY() < maxY) {
|
||||
Block block = cursor.add(0.0, 1.0, 0.0).getBlock();
|
||||
if (GroundUtil.isSolidFullBlock(block)
|
||||
&& this.recordViolation(
|
||||
playerId,
|
||||
1,
|
||||
HackType.PHASE,
|
||||
player.getName()
|
||||
+ " failed Phase: clipped up through "
|
||||
+ block.getType()
|
||||
+ " at "
|
||||
+ block.getLocation().toVector().toString()
|
||||
)) {
|
||||
this.frozenPlayers.put(playerId, System.currentTimeMillis());
|
||||
this.enclosedBlocks.remove(playerId);
|
||||
event.setTo(this.lastValidLocations.get(playerId));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean fromPassable = isLocationPassable(event.getFrom());
|
||||
if (isLocationPassable(event.getTo())) {
|
||||
Location lastValid = this.lastValidLocations.get(playerId);
|
||||
if (!isLocationClearOfStandableBlocks(event.getTo()) || !toOnGround) {
|
||||
Location destination = event.getTo().clone();
|
||||
|
||||
double distanceSquared;
|
||||
try {
|
||||
distanceSquared = lastValid.distanceSquared(destination);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
this.lastValidLocations.put(playerId, destination);
|
||||
return;
|
||||
}
|
||||
|
||||
if (distanceSquared > this.maxDist * this.maxDist && !lastValid.equals(event.getFrom())) {
|
||||
this.lastValidLocations.put(playerId, destination);
|
||||
}
|
||||
} else if (!lastValid.equals(event.getFrom())) {
|
||||
this.lastValidLocations.put(playerId, event.getTo().clone());
|
||||
}
|
||||
} else {
|
||||
boolean fromEnclosed = isEnclosedInSolidBlocks(event.getFrom());
|
||||
if (fromPassable) {
|
||||
if (this.recordViolation(
|
||||
playerId,
|
||||
1,
|
||||
HackType.PHASE,
|
||||
player.getName()
|
||||
+ " failed Phase: moved into "
|
||||
+ event.getTo().getBlock().getType()
|
||||
+ " at "
|
||||
+ event.getTo().getBlock().getLocation().toVector().toString()
|
||||
)) {
|
||||
this.enclosedBlocks.remove(playerId);
|
||||
event.setTo(this.lastValidLocations.get(playerId));
|
||||
this.frozenPlayers.put(playerId, System.currentTimeMillis());
|
||||
}
|
||||
} else if (fromEnclosed) {
|
||||
this.enclosedBlocks.put(playerId, player.getLocation().getBlock());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isLocationPassable(Location location) {
|
||||
BlockCache cache = new BlockCache(location);
|
||||
return !GroundUtil.isSolidFullBlock(cache.getOffsetBlock(0.0, 0.0, 0.3))
|
||||
&& !GroundUtil.isSolidFullBlock(cache.getOffsetBlock(0.3, 0.0, 0.0))
|
||||
&& !GroundUtil.isSolidFullBlock(cache.getOffsetBlock(0.0, 0.0, -0.3))
|
||||
&& !GroundUtil.isSolidFullBlock(cache.getOffsetBlock(-0.3, 0.0, 0.0))
|
||||
&& !GroundUtil.isSolidFullBlock(cache.getOffsetBlock(-0.3, 0.0, -0.3))
|
||||
&& !GroundUtil.isSolidFullBlock(cache.getOffsetBlock(-0.3, 0.0, 0.3))
|
||||
&& !GroundUtil.isSolidFullBlock(cache.getOffsetBlock(0.3, 0.0, -0.3))
|
||||
&& !GroundUtil.isSolidFullBlock(cache.getOffsetBlock(0.3, 0.0, 0.3))
|
||||
&& !GroundUtil.isSolidFullBlock(cache.getOffsetBlock(0.0, 1.68, 0.3))
|
||||
&& !GroundUtil.isSolidFullBlock(cache.getOffsetBlock(0.3, 1.68, 0.0))
|
||||
&& !GroundUtil.isSolidFullBlock(cache.getOffsetBlock(0.0, 1.68, -0.3))
|
||||
&& !GroundUtil.isSolidFullBlock(cache.getOffsetBlock(-0.3, 1.68, 0.0))
|
||||
&& !GroundUtil.isSolidFullBlock(cache.getOffsetBlock(-0.3, 1.68, -0.3))
|
||||
&& !GroundUtil.isSolidFullBlock(cache.getOffsetBlock(-0.3, 1.68, 0.3))
|
||||
&& !GroundUtil.isSolidFullBlock(cache.getOffsetBlock(0.3, 1.68, -0.3))
|
||||
&& !GroundUtil.isSolidFullBlock(cache.getOffsetBlock(0.3, 1.68, 0.3))
|
||||
&& !GroundUtil.isSolidFullBlock(cache.getOffsetBlock(0.0, 0.9, 0.3))
|
||||
&& !GroundUtil.isSolidFullBlock(cache.getOffsetBlock(0.3, 0.9, 0.0))
|
||||
&& !GroundUtil.isSolidFullBlock(cache.getOffsetBlock(0.0, 0.9, -0.3))
|
||||
&& !GroundUtil.isSolidFullBlock(cache.getOffsetBlock(-0.3, 0.9, 0.0))
|
||||
&& !GroundUtil.isSolidFullBlock(cache.getOffsetBlock(-0.3, 0.9, -0.3))
|
||||
&& !GroundUtil.isSolidFullBlock(cache.getOffsetBlock(-0.3, 0.9, 0.3))
|
||||
&& !GroundUtil.isSolidFullBlock(cache.getOffsetBlock(0.3, 0.9, -0.3))
|
||||
&& !GroundUtil.isSolidFullBlock(cache.getOffsetBlock(0.3, 0.9, 0.3));
|
||||
}
|
||||
|
||||
public static boolean isLocationClearOfStandableBlocks(Location location) {
|
||||
BlockCache cache = new BlockCache(location);
|
||||
return !GroundUtil.isStandableBlock(cache.getOffsetBlock(0.0, 0.0, 0.3))
|
||||
&& !GroundUtil.isStandableBlock(cache.getOffsetBlock(0.3, 0.0, 0.0))
|
||||
&& !GroundUtil.isStandableBlock(cache.getOffsetBlock(0.0, 0.0, -0.3))
|
||||
&& !GroundUtil.isStandableBlock(cache.getOffsetBlock(-0.3, 0.0, 0.0))
|
||||
&& !GroundUtil.isStandableBlock(cache.getOffsetBlock(-0.3, 0.0, -0.3))
|
||||
&& !GroundUtil.isStandableBlock(cache.getOffsetBlock(-0.3, 0.0, 0.3))
|
||||
&& !GroundUtil.isStandableBlock(cache.getOffsetBlock(0.3, 0.0, -0.3))
|
||||
&& !GroundUtil.isStandableBlock(cache.getOffsetBlock(0.3, 0.0, 0.3))
|
||||
&& !GroundUtil.isStandableBlock(cache.getOffsetBlock(0.0, 1.68, 0.3))
|
||||
&& !GroundUtil.isStandableBlock(cache.getOffsetBlock(0.3, 1.68, 0.0))
|
||||
&& !GroundUtil.isStandableBlock(cache.getOffsetBlock(0.0, 1.68, -0.3))
|
||||
&& !GroundUtil.isStandableBlock(cache.getOffsetBlock(-0.3, 1.68, 0.0))
|
||||
&& !GroundUtil.isStandableBlock(cache.getOffsetBlock(-0.3, 1.68, -0.3))
|
||||
&& !GroundUtil.isStandableBlock(cache.getOffsetBlock(-0.3, 1.68, 0.3))
|
||||
&& !GroundUtil.isStandableBlock(cache.getOffsetBlock(0.3, 1.68, -0.3))
|
||||
&& !GroundUtil.isStandableBlock(cache.getOffsetBlock(0.3, 1.68, 0.3))
|
||||
&& !GroundUtil.isStandableBlock(cache.getOffsetBlock(0.0, 0.9, 0.3))
|
||||
&& !GroundUtil.isStandableBlock(cache.getOffsetBlock(0.3, 0.9, 0.0))
|
||||
&& !GroundUtil.isStandableBlock(cache.getOffsetBlock(0.0, 0.9, -0.3))
|
||||
&& !GroundUtil.isStandableBlock(cache.getOffsetBlock(-0.3, 0.9, 0.0))
|
||||
&& !GroundUtil.isStandableBlock(cache.getOffsetBlock(-0.3, 0.9, -0.3))
|
||||
&& !GroundUtil.isStandableBlock(cache.getOffsetBlock(-0.3, 0.9, 0.3))
|
||||
&& !GroundUtil.isStandableBlock(cache.getOffsetBlock(0.3, 0.9, -0.3))
|
||||
&& !GroundUtil.isStandableBlock(cache.getOffsetBlock(0.3, 0.9, 0.3));
|
||||
}
|
||||
|
||||
public static boolean isEnclosedInSolidBlocks(Location location) {
|
||||
BlockCache cache = new BlockCache(location);
|
||||
return GroundUtil.isSolidFullBlock(cache.getOffsetBlock(0.0, 0.0, 0.4))
|
||||
&& GroundUtil.isSolidFullBlock(cache.getOffsetBlock(0.4, 0.0, 0.0))
|
||||
&& GroundUtil.isSolidFullBlock(cache.getOffsetBlock(0.0, 0.0, -0.4))
|
||||
&& GroundUtil.isSolidFullBlock(cache.getOffsetBlock(-0.4, 0.0, 0.0))
|
||||
&& GroundUtil.isSolidFullBlock(cache.getOffsetBlock(-0.4, 0.0, -0.4))
|
||||
&& GroundUtil.isSolidFullBlock(cache.getOffsetBlock(-0.4, 0.0, 0.4))
|
||||
&& GroundUtil.isSolidFullBlock(cache.getOffsetBlock(0.4, 0.0, -0.4))
|
||||
&& GroundUtil.isSolidFullBlock(cache.getOffsetBlock(0.4, 0.0, 0.4))
|
||||
&& GroundUtil.isSolidFullBlock(cache.getOffsetBlock(0.0, 2.01, 0.4))
|
||||
&& GroundUtil.isSolidFullBlock(cache.getOffsetBlock(0.4, 2.01, 0.0))
|
||||
&& GroundUtil.isSolidFullBlock(cache.getOffsetBlock(0.0, 2.01, -0.4))
|
||||
&& GroundUtil.isSolidFullBlock(cache.getOffsetBlock(-0.4, 2.01, 0.0))
|
||||
&& GroundUtil.isSolidFullBlock(cache.getOffsetBlock(-0.4, 2.01, -0.4))
|
||||
&& GroundUtil.isSolidFullBlock(cache.getOffsetBlock(-0.4, 2.01, 0.4))
|
||||
&& GroundUtil.isSolidFullBlock(cache.getOffsetBlock(0.4, 2.01, -0.4))
|
||||
&& GroundUtil.isSolidFullBlock(cache.getOffsetBlock(0.4, 2.01, 0.4));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
if (!event.getCause().equals(TeleportCause.UNKNOWN)) {
|
||||
this.resetPlayerLocation(event.getPlayer(), event.getTo());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
this.resetPlayerLocation(event.getPlayer(), event.getRespawnLocation());
|
||||
}
|
||||
|
||||
private void resetPlayerLocation(Player player, Location location) {
|
||||
UUID playerId = player.getUniqueId();
|
||||
this.frozenPlayers.remove(playerId);
|
||||
this.lastValidLocations.put(playerId, location);
|
||||
this.enclosedBlocks.remove(playerId);
|
||||
}
|
||||
|
||||
public void clearCaches() {
|
||||
this.exemptPlayers.clear();
|
||||
this.lastValidLocations.clear();
|
||||
this.frozenPlayers.clear();
|
||||
this.enclosedBlocks.clear();
|
||||
}
|
||||
|
||||
private class PacketListener extends PacketAdapter {
|
||||
PacketListener(Plugin plugin, PacketType... packetTypes) {
|
||||
super(plugin, packetTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
UUID playerId = event.getPlayer().getUniqueId();
|
||||
if (Phase.this.frozenPlayers.containsKey(playerId) && Phase.this.lastValidLocations.get(playerId) != null) {
|
||||
event.setCancelled(true);
|
||||
long frozenAt = Phase.this.frozenPlayers.get(playerId);
|
||||
if (System.currentTimeMillis() > frozenAt + Phase.this.freezeTime) {
|
||||
Phase.this.frozenPlayers.remove(playerId);
|
||||
Phase.this.pendingUnfreezeSetbacks.add(playerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
UUID playerId = player.getUniqueId();
|
||||
if (Phase.this.frozenPlayers.containsKey(playerId)) {
|
||||
WrapperPlayServerPosition packet = new WrapperPlayServerPosition(event.getPacket());
|
||||
Set<PlayerTeleportFlag> flags = packet.getFlags();
|
||||
Location current = player.getLocation();
|
||||
double x = flags.contains(PlayerTeleportFlag.X) ? current.getX() + packet.getX() : packet.getX();
|
||||
double y = flags.contains(PlayerTeleportFlag.Y) ? current.getY() + packet.getY() : packet.getY();
|
||||
double z = flags.contains(PlayerTeleportFlag.Z) ? current.getZ() + packet.getZ() : packet.getZ();
|
||||
float pitch = flags.contains(PlayerTeleportFlag.Y_ROT) ? current.getPitch() + packet.getPitch() : current.getPitch();
|
||||
float yaw = flags.contains(PlayerTeleportFlag.X_ROT) ? current.getYaw() + packet.getYaw() : current.getYaw();
|
||||
Location target = new Location(player.getWorld(), x, y, z, yaw, pitch);
|
||||
Phase.this.lastValidLocations.put(playerId, target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ViolationDecayTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
Phase.this.decreaseViolationLevel(player.getUniqueId(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,109 @@
|
||||
package me.konsolas.aac.detectors.world;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import me.konsolas.aac.util.blocks.BlockUtil;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
public final class FastBreak extends Detector {
|
||||
private int letTicks = 2;
|
||||
private boolean cancelBreak = true;
|
||||
private boolean checkDelay = true;
|
||||
private final Map<UUID, Long> digStartTimes = new HashMap<>();
|
||||
private final Map<UUID, Block> targetBlocks = new HashMap<>();
|
||||
private final Map<UUID, Long> lastBreakTimes = new HashMap<>();
|
||||
|
||||
public FastBreak(AAC plugin) {
|
||||
super(plugin);
|
||||
this.letTicks = this.plugin.getConfig().getInt("fastbreak.let_ticks", this.letTicks);
|
||||
this.cancelBreak = this.plugin.getConfig().getBoolean("fastbreak.cancel_break", this.cancelBreak);
|
||||
this.checkDelay = this.plugin.getConfig().getBoolean("fastbreak.check_delay", this.checkDelay);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||
UUID playerId = event.getPlayer().getUniqueId();
|
||||
if (event.getClickedBlock().equals(this.targetBlocks.get(playerId))) {
|
||||
long now = System.currentTimeMillis();
|
||||
long digStart = this.digStartTimes.get(playerId);
|
||||
if (now - digStart / 50L >= BlockUtil.calculateBreakTimeTicks(event.getClickedBlock().getType(), event.getPlayer())) {
|
||||
this.digStartTimes.put(playerId, System.currentTimeMillis());
|
||||
}
|
||||
} else {
|
||||
this.targetBlocks.put(playerId, event.getClickedBlock());
|
||||
this.digStartTimes.put(playerId, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
if (this.checkDelay && this.lastBreakTimes.containsKey(playerId) && BlockUtil.getHasteLevel(event.getPlayer()) == 0) {
|
||||
long lastBreakTime = this.lastBreakTimes.get(playerId);
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - lastBreakTime < 100L
|
||||
&& event.getClickedBlock() != null
|
||||
&& BlockUtil.calculateBreakTimeTicks(event.getClickedBlock().getType(), event.getPlayer()) >= 1L
|
||||
&& this.recordViolation(
|
||||
playerId,
|
||||
2,
|
||||
HackType.FASTBREAK,
|
||||
event.getPlayer().getName() + " failed FastBreak: interacted too quickly after breaking a block"
|
||||
)
|
||||
&& this.cancelBreak) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (event.getPlayer().getGameMode() != GameMode.CREATIVE && !this.plugin.checkManager.isBypassed(event.getPlayer())) {
|
||||
UUID playerId = event.getPlayer().getUniqueId();
|
||||
if (!event.getBlock().equals(this.targetBlocks.get(playerId))
|
||||
&& this.recordViolation(playerId, 1, HackType.FASTBREAK, event.getPlayer().getName() + " failed FastBreak: broke the wrong block")
|
||||
&& this.cancelBreak) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
if (this.digStartTimes.containsKey(playerId)) {
|
||||
long now = System.currentTimeMillis();
|
||||
long digStart = this.digStartTimes.get(playerId);
|
||||
long actualTicks = (now - digStart) / 50L;
|
||||
long expectedTicks = BlockUtil.calculateBreakTimeTicks(event.getBlock().getType(), event.getPlayer());
|
||||
if (expectedTicks == 0L) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (actualTicks + this.letTicks < expectedTicks) {
|
||||
if (this.recordViolation(
|
||||
playerId,
|
||||
1,
|
||||
HackType.FASTBREAK,
|
||||
event.getPlayer().getName()
|
||||
+ " failed FastBreak: tried to break blocks too quickly ("
|
||||
+ actualTicks
|
||||
+ ", expected "
|
||||
+ expectedTicks
|
||||
+ ")"
|
||||
)
|
||||
&& this.cancelBreak) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else {
|
||||
this.decreaseViolationLevel(playerId, 1);
|
||||
}
|
||||
}
|
||||
|
||||
this.lastBreakTimes.put(playerId, System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package me.konsolas.aac.detectors.world;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public final class FastPlace extends Detector {
|
||||
private long minDelay = 200L;
|
||||
private boolean cancelPlace = true;
|
||||
private final Map<UUID, Long> lastPlaceTimes = new HashMap<>();
|
||||
|
||||
public FastPlace(AAC plugin) {
|
||||
super(plugin);
|
||||
this.minDelay = this.plugin.getConfig().getLong("fastplace.min_delay", this.minDelay);
|
||||
this.cancelPlace = this.plugin.getConfig().getBoolean("fastplace.cancel_place", this.cancelPlace);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (event.getPlayer().getInventory().getItemInMainHand().getType() != Material.FLINT_AND_STEEL
|
||||
&& event.getPlayer().getInventory().getItemInOffHand().getType() != Material.FLINT_AND_STEEL
|
||||
&& event.getPlayer().getGameMode() != GameMode.CREATIVE
|
||||
&& !this.plugin.checkManager.isBypassed(event.getPlayer())) {
|
||||
ItemStack boneMeal = new ItemStack(Material.INK_SACK, 1, (short)15);
|
||||
if (!event.getPlayer().getInventory().getItemInMainHand().isSimilar(boneMeal)
|
||||
&& !event.getPlayer().getInventory().getItemInOffHand().isSimilar(boneMeal)) {
|
||||
UUID playerId = event.getPlayer().getUniqueId();
|
||||
if (this.lastPlaceTimes.containsKey(playerId)) {
|
||||
long now = System.currentTimeMillis();
|
||||
long lastPlaceTime = this.lastPlaceTimes.get(playerId);
|
||||
if (now - lastPlaceTime < this.minDelay) {
|
||||
if (this.recordViolation(
|
||||
playerId,
|
||||
1,
|
||||
HackType.FASTBREAK,
|
||||
event.getPlayer().getName() + " failed FastPlace: tried to place blocks too quickly (" + (now - lastPlaceTime) + " ms)"
|
||||
)
|
||||
&& this.cancelPlace) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} else {
|
||||
this.decreaseViolationLevel(playerId, 1);
|
||||
}
|
||||
}
|
||||
|
||||
this.lastPlaceTimes.put(playerId, System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,299 @@
|
||||
package me.konsolas.aac.detectors.world;
|
||||
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import me.konsolas.aac.util.blocks.BlockUtil;
|
||||
import me.konsolas.aac.util.ground.GroundUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.DoubleChest;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Minecart;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.util.BlockIterator;
|
||||
|
||||
public class ImpossibleInteract extends Detector {
|
||||
private boolean cancelLiquids = true;
|
||||
private boolean cancelGhosthand = true;
|
||||
|
||||
public ImpossibleInteract(AAC plugin) {
|
||||
super(plugin);
|
||||
this.cancelLiquids = this.plugin.getConfig().getBoolean("impossibleinteract.cancel_liquids", this.cancelLiquids);
|
||||
this.cancelGhosthand = this.plugin.getConfig().getBoolean("impossibleinteract.cancel_ghosthand", this.cancelGhosthand);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getClickedBlock() != null && event.getClickedBlock().getType() != Material.AIR) {
|
||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
if (this.plugin.checkManager.isBypassed(event.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.cancelGhosthand) {
|
||||
if (BlockUtil.calculateBreakTimeTicks(event.getClickedBlock().getType(), event.getPlayer()) < 2L) {
|
||||
return;
|
||||
}
|
||||
|
||||
BlockIterator raycast;
|
||||
try {
|
||||
raycast = new BlockIterator(event.getPlayer(), 7);
|
||||
} catch (IllegalStateException ex) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean clearLineOfSight = true;
|
||||
boolean reachedTarget = false;
|
||||
|
||||
while (raycast.hasNext()) {
|
||||
Block block = raycast.next();
|
||||
if (block.equals(event.getClickedBlock())) {
|
||||
reachedTarget = true;
|
||||
}
|
||||
|
||||
if (GroundUtil.isSolidFullBlock(block) && !reachedTarget) {
|
||||
clearLineOfSight = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!clearLineOfSight && reachedTarget) {
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new InteractionOcclusionTask(event));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.decreaseViolationLevel(event.getPlayer().getUniqueId(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (event.getBlock() != null && event.getBlock().getType() != Material.AIR && !this.plugin.checkManager.isBypassed(event.getPlayer())) {
|
||||
if (BlockUtil.calculateBreakTimeTicks(event.getBlock().getType(), event.getPlayer()) > 2L) {
|
||||
if (this.cancelGhosthand) {
|
||||
BlockIterator raycast;
|
||||
try {
|
||||
raycast = new BlockIterator(event.getPlayer(), 6);
|
||||
} catch (IllegalStateException ex) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean reachedTarget = false;
|
||||
|
||||
while (raycast.hasNext()) {
|
||||
Block block = raycast.next();
|
||||
if (block.equals(event.getBlock())) {
|
||||
reachedTarget = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (GroundUtil.isSolidFullBlock(block)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!reachedTarget
|
||||
&& this.recordViolation(
|
||||
event.getPlayer().getUniqueId(),
|
||||
2,
|
||||
HackType.IMPOSSIBLEINTERACT,
|
||||
event.getPlayer().getName() + " failed ImpossibleInteract: broke through a block (GhostHand)"
|
||||
)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
this.decreaseViolationLevel(event.getPlayer().getUniqueId(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (!this.plugin.checkManager.isBypassed(event.getPlayer())) {
|
||||
Material againstType = event.getBlockAgainst().getType();
|
||||
if ((againstType == Material.LAVA || againstType == Material.WATER || againstType == Material.STATIONARY_LAVA || againstType == Material.STATIONARY_WATER)
|
||||
&& this.cancelLiquids
|
||||
&& event.getBlockPlaced().getType() != Material.WATER_LILY
|
||||
&& this.recordViolation(
|
||||
event.getPlayer().getUniqueId(),
|
||||
2,
|
||||
HackType.IMPOSSIBLEINTERACT,
|
||||
event.getPlayer().getName() + " failed ImpossibleInteract: Interacted with a liquid"
|
||||
)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
if (this.cancelGhosthand) {
|
||||
BlockIterator raycast;
|
||||
try {
|
||||
raycast = new BlockIterator(event.getPlayer(), 7);
|
||||
} catch (IllegalStateException ex) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean clearLineOfSight = true;
|
||||
boolean reachedTarget = false;
|
||||
|
||||
while (raycast.hasNext()) {
|
||||
Block block = raycast.next();
|
||||
if (block.equals(event.getBlockAgainst())) {
|
||||
reachedTarget = true;
|
||||
}
|
||||
|
||||
if (GroundUtil.isSolidFullBlock(block) && !block.equals(event.getBlock()) && !reachedTarget) {
|
||||
clearLineOfSight = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!clearLineOfSight) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryOpen(InventoryOpenEvent event) {
|
||||
if (this.cancelGhosthand) {
|
||||
try {
|
||||
if (this.plugin.checkManager.isBypassed((Player)event.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getInventory() != null && event.getInventory().getHolder() != null) {
|
||||
if (!(event.getInventory().getHolder() instanceof Minecart) && !(event.getInventory().getHolder() instanceof LivingEntity)) {
|
||||
if (event.getInventory().getHolder() instanceof DoubleChest) {
|
||||
DoubleChest doubleChest = (DoubleChest)event.getInventory().getHolder();
|
||||
|
||||
BlockIterator raycast;
|
||||
try {
|
||||
raycast = new BlockIterator(event.getPlayer(), 7);
|
||||
} catch (IllegalStateException ex) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean clearLineOfSight = true;
|
||||
boolean reachedTarget = false;
|
||||
|
||||
while (raycast.hasNext()) {
|
||||
Block block = raycast.next();
|
||||
if (block.equals(((BlockState)doubleChest.getLeftSide()).getBlock())
|
||||
|| block.equals(((BlockState)doubleChest.getRightSide()).getBlock())) {
|
||||
reachedTarget = true;
|
||||
}
|
||||
|
||||
if (GroundUtil.isSolidFullBlock(block) && !reachedTarget) {
|
||||
clearLineOfSight = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!clearLineOfSight
|
||||
&& this.recordViolation(
|
||||
event.getPlayer().getUniqueId(),
|
||||
2,
|
||||
HackType.IMPOSSIBLEINTERACT,
|
||||
event.getPlayer().getName() + " failed ImpossibleInteract: interacted through a block (GhostHand)"
|
||||
)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
Block containerBlock;
|
||||
try {
|
||||
containerBlock = ((BlockState)event.getInventory().getHolder()).getBlock();
|
||||
} catch (Exception ex) {
|
||||
return;
|
||||
}
|
||||
|
||||
BlockIterator raycast;
|
||||
try {
|
||||
raycast = new BlockIterator(event.getPlayer(), 7);
|
||||
} catch (IllegalStateException ex) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean clearLineOfSight = true;
|
||||
boolean reachedTarget = false;
|
||||
|
||||
while (raycast.hasNext()) {
|
||||
Block block = raycast.next();
|
||||
if (block.equals(containerBlock)) {
|
||||
reachedTarget = true;
|
||||
}
|
||||
|
||||
if (GroundUtil.isSolidFullBlock(block) && !reachedTarget) {
|
||||
clearLineOfSight = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!clearLineOfSight
|
||||
&& this.recordViolation(
|
||||
event.getPlayer().getUniqueId(),
|
||||
2,
|
||||
HackType.IMPOSSIBLEINTERACT,
|
||||
event.getPlayer().getName() + " failed ImpossibleInteract: interacted through a block (GhostHand)"
|
||||
)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (ClassCastException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class InteractionOcclusionTask implements Runnable {
|
||||
private final PlayerInteractEvent interactEvent;
|
||||
|
||||
private InteractionOcclusionTask(PlayerInteractEvent interactEvent) {
|
||||
this.interactEvent = interactEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
BlockIterator raycast;
|
||||
try {
|
||||
raycast = new BlockIterator(this.interactEvent.getPlayer(), 7);
|
||||
} catch (IllegalStateException ex) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean clearLineOfSight = true;
|
||||
boolean reachedTarget = false;
|
||||
|
||||
while (raycast.hasNext()) {
|
||||
Block block = raycast.next();
|
||||
if (block.equals(this.interactEvent.getClickedBlock())) {
|
||||
reachedTarget = true;
|
||||
}
|
||||
|
||||
if (GroundUtil.isSolidFullBlock(block) && !reachedTarget) {
|
||||
clearLineOfSight = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!clearLineOfSight
|
||||
&& reachedTarget
|
||||
&& ImpossibleInteract.this.recordViolation(
|
||||
this.interactEvent.getPlayer().getUniqueId(),
|
||||
2,
|
||||
HackType.IMPOSSIBLEINTERACT,
|
||||
this.interactEvent.getPlayer().getName() + " failed ImpossibleInteract: interacted through a block (GhostHand)"
|
||||
)) {
|
||||
this.interactEvent.getPlayer().closeInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package me.konsolas.aac.detectors.world;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import me.konsolas.aac.internal.packetwrapper.WrapperPlayClientUseEntity;
|
||||
import me.konsolas.aac.util.Ping;
|
||||
import me.konsolas.aac.util.general.NumberUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public final class NoSwing extends Detector {
|
||||
public NoSwing(AAC plugin) {
|
||||
super(plugin);
|
||||
NoSwingPacketListener listener = new NoSwingPacketListener(this.plugin, WrapperPlayClientUseEntity.TYPE);
|
||||
this.packetListeners.add(listener);
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(listener);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (event.getPlayer().getGameMode() != GameMode.CREATIVE && !this.plugin.checkManager.isBypassed(event.getPlayer())) {
|
||||
long breakTime = System.currentTimeMillis();
|
||||
Player player = event.getPlayer();
|
||||
this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new BlockSwingValidationTask(player, breakTime), 5L);
|
||||
}
|
||||
}
|
||||
|
||||
private final class NoSwingPacketListener extends PacketAdapter {
|
||||
private NoSwingPacketListener(Plugin plugin, PacketType... packetTypes) {
|
||||
super(plugin, packetTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
if (!NoSwing.this.plugin.checkManager.isBypassed(event.getPlayer())) {
|
||||
if (event.getPacketType() != WrapperPlayClientUseEntity.TYPE
|
||||
|| new WrapperPlayClientUseEntity(event.getPacket()).getAction() == EntityUseAction.ATTACK) {
|
||||
long attackTime = System.currentTimeMillis();
|
||||
Player player = event.getPlayer();
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new AttackSwingValidationTask(player, attackTime), 5L);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class AttackSwingValidationTask implements Runnable {
|
||||
private final Player player;
|
||||
private final long attackTime;
|
||||
|
||||
private AttackSwingValidationTask(Player player, long attackTime) {
|
||||
this.player = player;
|
||||
this.attackTime = attackTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
NoSwing.this.plugin
|
||||
.logger
|
||||
.logPlayerDebug(
|
||||
this.player,
|
||||
"(NoSwing) PlayClientUseEntity lastAnimated[e:"
|
||||
+ this.attackTime
|
||||
+ ",r:"
|
||||
+ NoSwing.this.plugin.playerStateTracker.getLastArmSwingTime(this.player)
|
||||
+ "]"
|
||||
);
|
||||
|
||||
try {
|
||||
if (!NumberUtil.approximatelyEqual(
|
||||
this.attackTime, NoSwing.this.plugin.playerStateTracker.getLastArmSwingTime(this.player), 300 + Ping.getPing(this.player)
|
||||
)) {
|
||||
NoSwing.this.recordViolation(
|
||||
this.player.getUniqueId(), 1, HackType.NOSWING, this.player.getName() + " failed NoSwing: didn't swing arm (attack)"
|
||||
);
|
||||
} else {
|
||||
NoSwing.this.decreaseViolationLevel(this.player.getUniqueId(), 2);
|
||||
}
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class BlockSwingValidationTask implements Runnable {
|
||||
private final Player player;
|
||||
private final long breakTime;
|
||||
|
||||
private BlockSwingValidationTask(Player player, long breakTime) {
|
||||
this.player = player;
|
||||
this.breakTime = breakTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
NoSwing.this.plugin
|
||||
.logger
|
||||
.logPlayerDebug(
|
||||
this.player,
|
||||
"(NoSwing) BlockBreakEvent lastAnimated[e:"
|
||||
+ this.breakTime
|
||||
+ ",r:"
|
||||
+ NoSwing.this.plugin.playerStateTracker.getLastArmSwingTime(this.player)
|
||||
+ "]"
|
||||
);
|
||||
|
||||
try {
|
||||
if (!NumberUtil.approximatelyEqual(
|
||||
this.breakTime, NoSwing.this.plugin.playerStateTracker.getLastArmSwingTime(this.player), 299 + Ping.getPing(this.player)
|
||||
)) {
|
||||
NoSwing.this.recordViolation(
|
||||
this.player.getUniqueId(), 1, HackType.NOSWING, this.player.getName() + " failed NoSwing: didn't swing arm (block break)"
|
||||
);
|
||||
} else {
|
||||
NoSwing.this.decreaseViolationLevel(this.player.getUniqueId(), 2);
|
||||
}
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package me.konsolas.aac.detectors.world;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public final class Nuker extends Detector {
|
||||
private int maxBreaksPerSecond = 40;
|
||||
private int vlDivisor = 41;
|
||||
private final Map<UUID, Integer> blockBreakCounts = new HashMap<>();
|
||||
private final Map<UUID, Vector> lastBrokenPositions = new HashMap<>();
|
||||
|
||||
public Nuker(AAC plugin) {
|
||||
super(plugin);
|
||||
this.maxBreaksPerSecond = this.plugin.getConfig().getInt("nuker.max_breaks_per_second", this.maxBreaksPerSecond);
|
||||
this.vlDivisor = this.plugin.getConfig().getInt("nuker.vl_divisor", this.vlDivisor);
|
||||
this.scheduledTaskIds.add(Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new ResetNukerBlockCountTask(), 6L, 20L));
|
||||
this.scheduledTaskIds.add(Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new NukerViolationDecayTask(), 6L, 50L));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (!this.plugin.checkManager.isBypassed(event.getPlayer())) {
|
||||
UUID playerId = event.getPlayer().getUniqueId();
|
||||
Vector brokenPosition = event.getBlock().getLocation().toVector();
|
||||
if (!this.lastBrokenPositions.containsKey(playerId) || !this.lastBrokenPositions.get(playerId).equals(brokenPosition)) {
|
||||
if (!this.blockBreakCounts.containsKey(playerId)) {
|
||||
this.blockBreakCounts.put(playerId, 1);
|
||||
} else {
|
||||
int breakCount = this.blockBreakCounts.get(playerId) + 1;
|
||||
this.blockBreakCounts.put(playerId, breakCount);
|
||||
if (breakCount > this.maxBreaksPerSecond) {
|
||||
if (breakCount % this.vlDivisor == 0
|
||||
&& this.recordViolation(
|
||||
playerId,
|
||||
1,
|
||||
HackType.NUKER,
|
||||
event.getPlayer().getName() + " failed Nuker: broke too many blocks (" + breakCount + " blocks/second)"
|
||||
)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.lastBrokenPositions.put(playerId, brokenPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class ResetNukerBlockCountTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
Nuker.this.blockBreakCounts.put(player.getUniqueId(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class NukerViolationDecayTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
Nuker.this.decreaseViolationLevel(player.getUniqueId(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
package me.konsolas.aac.detectors.world;
|
||||
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.detectors.Detector;
|
||||
import me.konsolas.aac.detectors.MoveListener;
|
||||
import me.konsolas.aac.util.blocks.BlockUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public final class PlayerRadar extends Detector implements MoveListener {
|
||||
private double requiredDist = 15.0;
|
||||
private double maxDist = 48.0;
|
||||
|
||||
public PlayerRadar(AAC plugin) {
|
||||
super(plugin);
|
||||
this.requiredDist = this.plugin.getConfig().getDouble("playerradar.required_dist");
|
||||
this.maxDist = this.plugin.getConfig().getDouble("playerradar.max_dist");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldProcessMove(PlayerMoveEvent event) {
|
||||
return event.getTo().getX() != event.getFrom().getX()
|
||||
|| event.getTo().getY() != event.getFrom().getY()
|
||||
|| event.getTo().getZ() != event.getFrom().getZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerMove(PlayerMoveEvent event, boolean fromOnGround, boolean toOnGround) {
|
||||
Player mover = event.getPlayer();
|
||||
|
||||
for (Player other : Bukkit.getServer().getOnlinePlayers()) {
|
||||
if (other.getWorld().equals(mover.getWorld()) && !other.equals(mover)) {
|
||||
double distanceSquared = mover.getLocation().distanceSquared(other.getLocation());
|
||||
if (!(distanceSquared < this.requiredDist * this.requiredDist) && !(distanceSquared > this.maxDist * this.maxDist)) {
|
||||
Vector otherFeet = other.getLocation().toVector();
|
||||
Vector otherHead = other.getLocation().add(0.0, 1.9, 0.0).toVector();
|
||||
Vector moverFeet = mover.getLocation().toVector();
|
||||
Vector moverHead = mover.getLocation().add(0.0, 1.9, 0.0).toVector();
|
||||
int steps = (int)moverFeet.distance(otherFeet);
|
||||
Vector feetToFeetStep = moverFeet.clone().subtract(otherFeet).normalize();
|
||||
Vector feetToHeadStep = moverHead.clone().subtract(otherFeet).normalize();
|
||||
Vector headToFeetStep = moverFeet.clone().subtract(otherHead).normalize();
|
||||
Vector headToHeadStep = moverHead.clone().subtract(otherHead).normalize();
|
||||
Vector rayPos = otherFeet.clone();
|
||||
boolean visible = true;
|
||||
|
||||
for (int i = 0; i < steps; i++) {
|
||||
Block block = mover.getWorld().getBlockAt(rayPos.toLocation(mover.getWorld()));
|
||||
if (!BlockUtil.isTransparent(block.getType())) {
|
||||
visible = false;
|
||||
break;
|
||||
}
|
||||
|
||||
rayPos.add(feetToFeetStep);
|
||||
}
|
||||
|
||||
rayPos = otherFeet.clone();
|
||||
if (!visible) {
|
||||
visible = true;
|
||||
|
||||
for (int i = 0; i < steps; i++) {
|
||||
Block block = mover.getWorld().getBlockAt(rayPos.toLocation(mover.getWorld()));
|
||||
if (!BlockUtil.isTransparent(block.getType())) {
|
||||
if (other.canSee(mover)) {
|
||||
other.hidePlayer(mover);
|
||||
}
|
||||
|
||||
if (mover.canSee(other)) {
|
||||
mover.hidePlayer(other);
|
||||
}
|
||||
|
||||
visible = false;
|
||||
break;
|
||||
}
|
||||
|
||||
rayPos.add(feetToHeadStep);
|
||||
}
|
||||
}
|
||||
|
||||
rayPos = otherHead.clone();
|
||||
if (!visible) {
|
||||
visible = true;
|
||||
|
||||
for (int i = 0; i < steps; i++) {
|
||||
Block block = mover.getWorld().getBlockAt(rayPos.toLocation(mover.getWorld()));
|
||||
if (!BlockUtil.isTransparent(block.getType())) {
|
||||
if (other.canSee(mover)) {
|
||||
other.hidePlayer(mover);
|
||||
}
|
||||
|
||||
if (mover.canSee(other)) {
|
||||
mover.hidePlayer(other);
|
||||
}
|
||||
|
||||
visible = false;
|
||||
break;
|
||||
}
|
||||
|
||||
rayPos.add(headToFeetStep);
|
||||
}
|
||||
}
|
||||
|
||||
rayPos = otherHead.clone();
|
||||
if (!visible) {
|
||||
visible = true;
|
||||
|
||||
for (int i = 0; i < steps; i++) {
|
||||
Block block = mover.getWorld().getBlockAt(rayPos.toLocation(mover.getWorld()));
|
||||
if (!BlockUtil.isTransparent(block.getType())) {
|
||||
if (other.canSee(mover)) {
|
||||
other.hidePlayer(mover);
|
||||
}
|
||||
|
||||
if (mover.canSee(other)) {
|
||||
mover.hidePlayer(other);
|
||||
}
|
||||
|
||||
visible = false;
|
||||
break;
|
||||
}
|
||||
|
||||
rayPos.add(headToHeadStep);
|
||||
}
|
||||
}
|
||||
|
||||
if (visible && !other.canSee(mover)) {
|
||||
other.showPlayer(mover);
|
||||
}
|
||||
|
||||
if (visible && !mover.canSee(other)) {
|
||||
mover.showPlayer(other);
|
||||
}
|
||||
} else {
|
||||
if (!other.canSee(mover)) {
|
||||
other.showPlayer(mover);
|
||||
}
|
||||
|
||||
if (!mover.canSee(other)) {
|
||||
mover.showPlayer(other);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
super.destroy();
|
||||
|
||||
for (Player viewer : Bukkit.getServer().getOnlinePlayers()) {
|
||||
for (Player target : Bukkit.getServer().getOnlinePlayers()) {
|
||||
viewer.showPlayer(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package me.konsolas.aac.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.internal.Destroyable;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public abstract class GUIBase implements Destroyable, Listener {
|
||||
protected AAC plugin;
|
||||
protected Inventory inventory;
|
||||
private final Player player;
|
||||
|
||||
public GUIBase(Player player, AAC plugin, int size, String title) {
|
||||
this.player = player;
|
||||
this.plugin = plugin;
|
||||
player.closeInventory();
|
||||
this.inventory = Bukkit.createInventory(null, size, title);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
protected void setSlotItem(int slot, ItemStack item, int actionId, String displayName, List<String> lore) {
|
||||
ItemStack copy = new ItemStack(item);
|
||||
ItemMeta meta = copy.getItemMeta();
|
||||
meta.setLore(lore);
|
||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
meta.addEnchant(Enchantment.DURABILITY, actionId, true);
|
||||
meta.setDisplayName(displayName);
|
||||
copy.setItemMeta(meta);
|
||||
this.inventory.setItem(slot, copy);
|
||||
}
|
||||
|
||||
protected List<String> createLore(String text, String delimiter) {
|
||||
List<String> lines = new ArrayList<>();
|
||||
String[] parts = text.split(delimiter);
|
||||
Collections.addAll(lines, parts);
|
||||
return lines;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
if (event.getInventory().getName().equals(this.inventory.getName())
|
||||
&& event.getWhoClicked().getUniqueId().equals(this.getPlayer().getUniqueId())
|
||||
&& event.getCurrentItem() != null
|
||||
&& event.getCurrentItem().getType() != Material.AIR) {
|
||||
event.setCancelled(true);
|
||||
this.destroy();
|
||||
int actionId = event.getCurrentItem().getEnchantmentLevel(Enchantment.DURABILITY);
|
||||
this.onSlotClick(actionId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
HandlerList.unregisterAll(this);
|
||||
this.player.closeInventory();
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
protected abstract void onSlotClick(int actionId);
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package me.konsolas.aac.gui.admin;
|
||||
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.gui.GUIBase;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class CheckGUI extends GUIBase {
|
||||
public CheckGUI(AAC plugin, Player player) {
|
||||
super(player, plugin, calculateInventorySize(HackType.values().length), "§6AAC: Manage checks");
|
||||
|
||||
for (HackType hackType : HackType.values()) {
|
||||
if (this.plugin.checkManager.isCheckEnabled(hackType)) {
|
||||
this.setSlotItem(
|
||||
hackType.getId(),
|
||||
new ItemStack(Material.EMERALD_BLOCK),
|
||||
hackType.getId(),
|
||||
hackType.toString(),
|
||||
this.createLore("Click to disable the /" + hackType.getName() + " check.", "/")
|
||||
);
|
||||
} else {
|
||||
this.setSlotItem(
|
||||
hackType.getId(),
|
||||
new ItemStack(Material.REDSTONE_BLOCK),
|
||||
hackType.getId(),
|
||||
hackType.toString(),
|
||||
this.createLore("Click to enable the /" + hackType.getName() + " check.", "/")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
player.openInventory(this.inventory);
|
||||
}
|
||||
|
||||
private static int calculateInventorySize(int itemCount) {
|
||||
if (itemCount <= 0) {
|
||||
return 9;
|
||||
}
|
||||
|
||||
int rows = (int) Math.ceil(itemCount / 9.0);
|
||||
return rows > 5 ? 54 : rows * 9;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSlotClick(int actionId) {
|
||||
for (HackType hackType : HackType.values()) {
|
||||
if (hackType.getId() == actionId) {
|
||||
if (this.plugin.checkManager.isCheckEnabled(hackType)) {
|
||||
this.plugin.checkManager.disableCheck(hackType, false);
|
||||
this.plugin.logger.log("Check " + hackType + " was disabled by " + this.getPlayer().getName());
|
||||
} else {
|
||||
this.plugin.checkManager.enableCheck(hackType, false);
|
||||
this.plugin.logger.log("Check " + hackType + " was enabled by " + this.getPlayer().getName());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package me.konsolas.aac.gui.admin;
|
||||
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.gui.GUIBase;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class HomeGUI extends GUIBase {
|
||||
public HomeGUI(AAC plugin, Player player) {
|
||||
super(player, plugin, 27, "§6AAC: Admin home");
|
||||
this.setSlotItem(
|
||||
10,
|
||||
new ItemStack(Material.BED),
|
||||
1,
|
||||
"Reload AAC",
|
||||
this.createLore("Use this when you make changes/to the configuration file", "/")
|
||||
);
|
||||
this.setSlotItem(
|
||||
16,
|
||||
new ItemStack(Material.REDSTONE_COMPARATOR),
|
||||
2,
|
||||
"Manage Checks",
|
||||
this.createLore("Enable or disable checks in /AAC", "/")
|
||||
);
|
||||
this.setSlotItem(
|
||||
12,
|
||||
new ItemStack(Material.BOOK),
|
||||
3,
|
||||
"List possible hackers",
|
||||
this.createLore("List players in order of their /violations", "/")
|
||||
);
|
||||
this.setSlotItem(
|
||||
14,
|
||||
new ItemStack(Material.REDSTONE),
|
||||
4,
|
||||
"Toggle verbose output",
|
||||
this.createLore("Toggle verbose output generated /by AAC for yourself", "/")
|
||||
);
|
||||
player.openInventory(this.inventory);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSlotClick(int actionId) {
|
||||
switch (actionId) {
|
||||
case 1:
|
||||
this.getPlayer().sendMessage(AAC.messagePrefix + "Reload request has been registered.");
|
||||
this.plugin.logger.log("Reload requested by " + this.getPlayer().getName());
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new ReloadTask(), 1L);
|
||||
break;
|
||||
case 2:
|
||||
new CheckGUI(this.plugin, this.getPlayer());
|
||||
break;
|
||||
case 3:
|
||||
new PlayerViolationsGUI(this.plugin, this.getPlayer());
|
||||
break;
|
||||
case 4:
|
||||
if (this.plugin.logger.verbosePlayerIds.contains(this.getPlayer().getUniqueId())) {
|
||||
this.plugin.logger.verbosePlayerIds.remove(this.getPlayer().getUniqueId());
|
||||
this.getPlayer().sendMessage(AAC.messagePrefix + "AAC will now give you verbose output.");
|
||||
} else {
|
||||
this.plugin.logger.verbosePlayerIds.add(this.getPlayer().getUniqueId());
|
||||
this.getPlayer().sendMessage(AAC.messagePrefix + "AAC will no longer give you verbose output.");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private final class ReloadTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
HomeGUI.this.plugin.reloadPlugin();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package me.konsolas.aac.gui.admin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.HackType;
|
||||
import me.konsolas.aac.gui.GUIBase;
|
||||
import me.konsolas.aac.util.general.MapUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.SkullType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
public class PlayerViolationsGUI extends GUIBase {
|
||||
public PlayerViolationsGUI(AAC plugin, Player player) {
|
||||
super(player, plugin, 54, "§6AAC: Manage player");
|
||||
Map<String, Integer> violationTotals = new HashMap<>();
|
||||
int count = 0;
|
||||
|
||||
for (Player online : Bukkit.getServer().getOnlinePlayers()) {
|
||||
if (++count >= 54) {
|
||||
break;
|
||||
}
|
||||
|
||||
violationTotals.put(online.getName(), 0);
|
||||
|
||||
for (HackType hackType : HackType.values()) {
|
||||
if (this.plugin.checkManager.isCheckEnabled(hackType)) {
|
||||
violationTotals.put(
|
||||
online.getName(),
|
||||
violationTotals.get(online.getName()) + this.plugin.checkManager.getCheck(hackType).getRecentViolationCount(online)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Integer> sortedViolations = MapUtil.sortByValueDescending(violationTotals);
|
||||
int slot = 0;
|
||||
|
||||
for (Map.Entry<String, Integer> entry : sortedViolations.entrySet()) {
|
||||
this.setSlotItem(
|
||||
slot++,
|
||||
createPlayerHead(Bukkit.getPlayer(entry.getKey()), entry.getKey()),
|
||||
slot,
|
||||
entry.getKey(),
|
||||
this.createLore("VL: " + entry.getValue(), "/")
|
||||
);
|
||||
}
|
||||
|
||||
player.openInventory(this.inventory);
|
||||
}
|
||||
|
||||
private static ItemStack createPlayerHead(Player player, String displayName) {
|
||||
ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (short) SkullType.PLAYER.ordinal());
|
||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
||||
meta.setOwner(player.getName());
|
||||
meta.setDisplayName(displayName);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSlotClick(int actionId) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package me.konsolas.aac.heuristics.base;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.internal.Destroyable;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public abstract class Heuristic implements Listener, Destroyable {
|
||||
protected AAC plugin;
|
||||
private final Map<UUID, Integer> scores = new HashMap<>();
|
||||
|
||||
public Heuristic(AAC plugin) {
|
||||
this.plugin = plugin;
|
||||
Bukkit.getServer().getPluginManager().registerEvents(this, this.plugin);
|
||||
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
this.scores.put(player.getUniqueId(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setRawScore(Player player, int score) {
|
||||
this.scores.put(player.getUniqueId(), score > 0 ? score : 0);
|
||||
}
|
||||
|
||||
public int getRawScore(Player player) {
|
||||
try {
|
||||
this.updateScore(player);
|
||||
return this.scores.get(player.getUniqueId());
|
||||
} catch (NullPointerException ex) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract int getProbability(Player player);
|
||||
|
||||
protected void updateScore(Player player) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
HandlerList.unregisterAll(this);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
this.scores.put(event.getPlayer().getUniqueId(), 0);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
this.scores.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerKick(PlayerKickEvent event) {
|
||||
this.scores.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package me.konsolas.aac.heuristics.combat;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.PacketType.Play.Client;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.events.PacketListener;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.heuristics.base.Heuristic;
|
||||
import me.konsolas.aac.internal.packetwrapper.WrapperPlayClientUseEntity;
|
||||
import net.jodah.expiringmap.ExpirationPolicy;
|
||||
import net.jodah.expiringmap.ExpiringMap;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class AccuracyHeuristic extends Heuristic {
|
||||
private final PacketListener packetListener;
|
||||
private final ExpiringMap<UUID, Boolean> recentMovementPackets = ExpiringMap.builder()
|
||||
.expiration(8L, TimeUnit.MILLISECONDS)
|
||||
.expirationPolicy(ExpirationPolicy.CREATED)
|
||||
.build();
|
||||
|
||||
public AccuracyHeuristic(AAC plugin) {
|
||||
super(plugin);
|
||||
this.packetListener = new AttackTimingPacketListener(
|
||||
this.plugin, Client.FLYING, Client.POSITION, Client.POSITION_LOOK, Client.USE_ENTITY, Client.LOOK
|
||||
);
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(this.packetListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
super.destroy();
|
||||
ProtocolLibrary.getProtocolManager().removePacketListener(this.packetListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProbability(Player player) {
|
||||
int probability = (int) (Math.pow(this.getRawScore(player), 0.8) / 2.0);
|
||||
return probability >= 100 ? 99 : probability;
|
||||
}
|
||||
|
||||
private final class AttackTimingPacketListener extends PacketAdapter {
|
||||
private AttackTimingPacketListener(Plugin plugin, PacketType... types) {
|
||||
super(plugin, types);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
if (event.getPacketType() == Client.USE_ENTITY) {
|
||||
if (new WrapperPlayClientUseEntity(event.getPacket()).getAction() == EntityUseAction.ATTACK) {
|
||||
if (AccuracyHeuristic.this.recentMovementPackets.containsKey(event.getPlayer().getUniqueId())) {
|
||||
AccuracyHeuristic.this.plugin
|
||||
.getServer()
|
||||
.getScheduler()
|
||||
.scheduleSyncDelayedTask(AccuracyHeuristic.this.plugin, new AttackTimingViolationTask(event.getPlayer()), 150L);
|
||||
} else {
|
||||
AccuracyHeuristic.this.setRawScore(event.getPlayer(), (int) (AccuracyHeuristic.this.getRawScore(event.getPlayer()) * 0.85));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
AccuracyHeuristic.this.recentMovementPackets.put(event.getPlayer().getUniqueId(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class AttackTimingViolationTask implements Runnable {
|
||||
private final Player player;
|
||||
|
||||
private AttackTimingViolationTask(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
AccuracyHeuristic.this.setRawScore(this.player, AccuracyHeuristic.this.getRawScore(this.player) + 50);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
package me.konsolas.aac.heuristics.combat;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.PacketType.Play.Client;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.events.PacketListener;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.heuristics.base.Heuristic;
|
||||
import me.konsolas.aac.internal.packetwrapper.WrapperPlayClientUseEntity;
|
||||
import net.jodah.expiringmap.ExpirationPolicy;
|
||||
import net.jodah.expiringmap.ExpiringMap;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class AimbotHeuristic extends Heuristic {
|
||||
private final Map<UUID, AimHistory> aimHistory = new HashMap<>();
|
||||
private final PacketListener packetListener;
|
||||
private final int scoreDecayTaskId;
|
||||
private final ExpiringMap<UUID, Boolean> recentAttackPackets;
|
||||
private final Map<UUID, Float> previousPacketYaw = new HashMap<>();
|
||||
private final Map<UUID, Float> postAttackYaw = new HashMap<>();
|
||||
|
||||
public AimbotHeuristic(AAC plugin) {
|
||||
super(plugin);
|
||||
this.recentAttackPackets = ExpiringMap.builder()
|
||||
.expiration(12L, TimeUnit.MILLISECONDS)
|
||||
.expirationPolicy(ExpirationPolicy.CREATED)
|
||||
.build();
|
||||
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
this.aimHistory.put(player.getUniqueId(), new AimHistory(player));
|
||||
}
|
||||
|
||||
this.packetListener = new AimPacketListener(this.plugin, Client.FLYING, Client.POSITION, Client.POSITION_LOOK, Client.USE_ENTITY, Client.LOOK);
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(this.packetListener);
|
||||
this.scoreDecayTaskId = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new AimScoreDecayTask(), 50L, 73L);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
try {
|
||||
if (event.getDamager().getType() == EntityType.PLAYER && !this.plugin.checkManager.isBypassed((Player) event.getDamager())) {
|
||||
AimHistory history = this.aimHistory.get(event.getDamager().getUniqueId());
|
||||
Player attacker = (Player) event.getDamager();
|
||||
double currentYaw = attacker.getEyeLocation().getYaw();
|
||||
double currentPitch = attacker.getEyeLocation().getPitch();
|
||||
double yawDelta = Math.abs(history.lastYaw - currentYaw);
|
||||
double pitchDelta = history.lastPitch - currentPitch;
|
||||
long attackInterval = System.currentTimeMillis() - history.lastAttackTime;
|
||||
if (attackInterval < 650L) {
|
||||
if (pitchDelta >= 13.0) {
|
||||
if (attackInterval <= 510L) {
|
||||
this.setRawScore(attacker, this.getRawScore(attacker) + 70);
|
||||
}
|
||||
|
||||
this.setRawScore(attacker, this.getRawScore(attacker) + 101);
|
||||
} else if (pitchDelta >= 10.0) {
|
||||
if (attackInterval <= 510L) {
|
||||
this.setRawScore(attacker, this.getRawScore(attacker) + 55);
|
||||
}
|
||||
|
||||
this.setRawScore(attacker, this.getRawScore(attacker) + 74);
|
||||
}
|
||||
|
||||
try {
|
||||
if (history.lastTarget != null && history.lastTarget.equals(event.getEntity())) {
|
||||
double targetMoved = history.lastTargetLocation.distance(event.getEntity().getLocation());
|
||||
if (targetMoved <= 0.05 && attacker.getLocation().distanceSquared(event.getEntity().getLocation()) <= 1.0) {
|
||||
this.setRawScore(attacker, this.getRawScore(attacker) - 27);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
history.lastTarget = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (yawDelta > 100.0 && yawDelta < 270.0) {
|
||||
this.setRawScore(attacker, this.getRawScore(attacker) + 109);
|
||||
if (attackInterval <= 510L) {
|
||||
this.setRawScore(attacker, this.getRawScore(attacker) + 79);
|
||||
}
|
||||
|
||||
if (yawDelta > 150.0) {
|
||||
this.setRawScore(attacker, this.getRawScore(attacker) + 89);
|
||||
}
|
||||
} else {
|
||||
this.setRawScore(attacker, this.getRawScore(attacker) - 60);
|
||||
}
|
||||
}
|
||||
|
||||
history.lastYaw = attacker.getLocation().getYaw();
|
||||
history.lastPitch = attacker.getLocation().getPitch();
|
||||
history.lastAttackTime = System.currentTimeMillis();
|
||||
history.lastTargetLocation = event.getEntity().getLocation();
|
||||
history.lastTarget = event.getEntity();
|
||||
}
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
super.destroy();
|
||||
ProtocolLibrary.getProtocolManager().removePacketListener(this.packetListener);
|
||||
Bukkit.getServer().getScheduler().cancelTask(this.scoreDecayTaskId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProbability(Player player) {
|
||||
double probability = Math.pow(this.getRawScore(player), 0.9) / 400.0;
|
||||
return (int) Math.round(probability * 100.0 > 99.0 ? 99.0 : probability * 100.0);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@Override
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
super.onPlayerJoin(event);
|
||||
this.aimHistory.put(event.getPlayer().getUniqueId(), new AimHistory(event.getPlayer()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@Override
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
super.onPlayerQuit(event);
|
||||
this.aimHistory.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@Override
|
||||
public void onPlayerKick(PlayerKickEvent event) {
|
||||
super.onPlayerKick(event);
|
||||
this.aimHistory.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
private static final class AimHistory {
|
||||
private double lastYaw;
|
||||
private double lastPitch;
|
||||
private long lastAttackTime;
|
||||
private Location lastTargetLocation;
|
||||
private Entity lastTarget;
|
||||
|
||||
private AimHistory(Player player) {
|
||||
this.lastYaw = player.getLocation().getYaw();
|
||||
this.lastPitch = player.getLocation().getPitch();
|
||||
this.lastAttackTime = System.currentTimeMillis();
|
||||
this.lastTargetLocation = null;
|
||||
this.lastTarget = null;
|
||||
}
|
||||
}
|
||||
|
||||
private final class AimPacketListener extends PacketAdapter {
|
||||
private AimPacketListener(Plugin plugin, PacketType... types) {
|
||||
super(plugin, types);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
UUID playerId = event.getPlayer().getUniqueId();
|
||||
PacketType packetType = event.getPacketType();
|
||||
if (packetType == Client.USE_ENTITY) {
|
||||
WrapperPlayClientUseEntity wrapper = new WrapperPlayClientUseEntity(event.getPacket());
|
||||
if (wrapper.getAction() == EntityUseAction.ATTACK) {
|
||||
AimbotHeuristic.this.recentAttackPackets.put(playerId, false);
|
||||
}
|
||||
} else if (AimbotHeuristic.this.recentAttackPackets.containsKey(playerId)) {
|
||||
if (packetType != Client.POSITION && packetType != Client.FLYING) {
|
||||
AimbotHeuristic.this.postAttackYaw.put(playerId, event.getPacket().getFloat().read(0));
|
||||
AimbotHeuristic.this.recentAttackPackets.remove(playerId);
|
||||
} else {
|
||||
AimbotHeuristic.this.recentAttackPackets.remove(playerId);
|
||||
}
|
||||
} else if (AimbotHeuristic.this.postAttackYaw.containsKey(playerId)) {
|
||||
if (packetType != Client.POSITION && packetType != Client.FLYING) {
|
||||
Float previousYaw = AimbotHeuristic.this.previousPacketYaw.get(playerId);
|
||||
if (previousYaw != null) {
|
||||
float currentYaw = event.getPacket().getFloat().read(0);
|
||||
int diffFromPrevious = (int) Math.abs((double) currentYaw - previousYaw);
|
||||
int diffFromPostAttack = (int) Math.abs((double) currentYaw - AimbotHeuristic.this.postAttackYaw.get(playerId));
|
||||
if (diffFromPrevious < diffFromPostAttack - 5) {
|
||||
AimbotHeuristic.this.setRawScore(event.getPlayer(), AimbotHeuristic.this.getRawScore(event.getPlayer()) + 91);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
AimbotHeuristic.this.setRawScore(event.getPlayer(), AimbotHeuristic.this.getRawScore(event.getPlayer()) + 49);
|
||||
}
|
||||
|
||||
AimbotHeuristic.this.postAttackYaw.remove(playerId);
|
||||
} else if (packetType == Client.LOOK || packetType == Client.POSITION_LOOK) {
|
||||
float yaw = event.getPacket().getFloat().read(0);
|
||||
AimbotHeuristic.this.previousPacketYaw.put(playerId, yaw);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class AimScoreDecayTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
AimbotHeuristic.this.setRawScore(player, (int) (AimbotHeuristic.this.getRawScore(player) * 0.99));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package me.konsolas.aac.heuristics.combat;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.heuristics.base.Heuristic;
|
||||
import me.konsolas.aac.heuristics.util.SampleData;
|
||||
import me.konsolas.aac.util.EntityTargetCategories;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class ReachHeuristic extends Heuristic {
|
||||
private final Map<UUID, ReachHistory> reachHistory = new HashMap<>();
|
||||
|
||||
public ReachHeuristic(AAC plugin) {
|
||||
super(plugin);
|
||||
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
this.reachHistory.put(player.getUniqueId(), new ReachHistory());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
|
||||
if (event.getCause() != DamageCause.ENTITY_ATTACK) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (!EntityTargetCategories.isReachTarget(event.getEntity().getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getDamager().getType() == EntityType.PLAYER && !this.plugin.checkManager.isBypassed((Player) event.getDamager())) {
|
||||
ReachHistory history = this.reachHistory.get(event.getDamager().getUniqueId());
|
||||
if (System.currentTimeMillis() - history.lastAttackTime > 1200L) {
|
||||
history.lastAttackTime = System.currentTimeMillis();
|
||||
return;
|
||||
}
|
||||
|
||||
Player attacker = (Player) event.getDamager();
|
||||
|
||||
try {
|
||||
if (history.lastTarget != null && history.lastTarget.equals(event.getEntity())) {
|
||||
double targetMoved = history.lastTargetLocation.distance(event.getEntity().getLocation());
|
||||
if (targetMoved <= 0.1 || attacker.getLocation().distanceSquared(event.getEntity().getLocation()) <= 1.2) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
return;
|
||||
}
|
||||
|
||||
history.distances.add(attacker.getLocation().distance(event.getEntity().getLocation()));
|
||||
if (history.distances.getSamples().size() > 12) {
|
||||
double averageDistance = history.distances.getAverage();
|
||||
this.setRawScore(attacker, (int) ((averageDistance - 2.9) * 1000.0));
|
||||
}
|
||||
|
||||
history.lastAttackTime = System.currentTimeMillis();
|
||||
history.lastTargetLocation = event.getEntity().getLocation();
|
||||
history.lastTarget = event.getEntity();
|
||||
}
|
||||
} catch (NullPointerException ex) {
|
||||
this.plugin.logger.log("(ReachHeuristic) caught an NPE");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateScore(Player player) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProbability(Player player) {
|
||||
double probability = Math.pow(this.getRawScore(player), 0.9) / 440.0;
|
||||
return (int) Math.round(probability * 100.0 > 99.0 ? 99.0 : probability * 100.0);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@Override
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
super.onPlayerJoin(event);
|
||||
this.reachHistory.put(event.getPlayer().getUniqueId(), new ReachHistory());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@Override
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
super.onPlayerQuit(event);
|
||||
this.reachHistory.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@Override
|
||||
public void onPlayerKick(PlayerKickEvent event) {
|
||||
super.onPlayerKick(event);
|
||||
this.reachHistory.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
private static final class ReachHistory {
|
||||
private final SampleData<Double> distances = new SampleData<>(16);
|
||||
private long lastAttackTime = System.currentTimeMillis();
|
||||
private Location lastTargetLocation = null;
|
||||
private Entity lastTarget = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package me.konsolas.aac.heuristics.util;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Collection;
|
||||
import java.util.Deque;
|
||||
|
||||
public class SampleData<T extends Number> {
|
||||
private final Deque<T> samples;
|
||||
private final int capacity;
|
||||
|
||||
public SampleData(int capacity) {
|
||||
this.capacity = capacity;
|
||||
this.samples = new ArrayDeque<>(capacity);
|
||||
}
|
||||
|
||||
public void add(T sample) {
|
||||
if (this.samples.size() >= this.capacity) {
|
||||
this.samples.poll();
|
||||
}
|
||||
|
||||
this.samples.add(sample);
|
||||
}
|
||||
|
||||
public Collection<T> getSamples() {
|
||||
return this.samples;
|
||||
}
|
||||
|
||||
public double getAverage() {
|
||||
double sum = 0.0;
|
||||
|
||||
for (T sample : this.samples) {
|
||||
sum += sample.doubleValue();
|
||||
}
|
||||
|
||||
return sum / this.samples.size();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.samples.clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package me.konsolas.aac.hooks;
|
||||
|
||||
import me.konsolas.aac.AAC;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public abstract class Hook implements Listener {
|
||||
protected AAC plugin;
|
||||
|
||||
public Hook(AAC plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package me.konsolas.aac.hooks;
|
||||
|
||||
import com.gmail.nossr50.api.AbilityAPI;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.api.PlayerViolationEvent;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
|
||||
public class McMMO extends Hook {
|
||||
public McMMO(AAC plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerViolation(PlayerViolationEvent event) {
|
||||
try {
|
||||
if (event.getPlayer() == null || !event.getPlayer().isOnline()) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event.getHackType()) {
|
||||
case ANGLE:
|
||||
case REACH:
|
||||
case KILLAURA:
|
||||
if (AbilityAPI.serratedStrikesEnabled(event.getPlayer()) || AbilityAPI.skullSplitterEnabled(event.getPlayer())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
for (Entity nearby : event.getPlayer().getNearbyEntities(7.0, 7.0, 7.0)) {
|
||||
if (nearby instanceof LivingEntity && AbilityAPI.isBleeding((LivingEntity) nearby)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NOSWING:
|
||||
if (AbilityAPI.isAnyAbilityEnabled(event.getPlayer())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
break;
|
||||
case FASTBREAK:
|
||||
case NUKER:
|
||||
case IMPOSSIBLEINTERACT:
|
||||
case PHASE:
|
||||
if (AbilityAPI.berserkEnabled(event.getPlayer())
|
||||
|| AbilityAPI.gigaDrillBreakerEnabled(event.getPlayer())
|
||||
|| AbilityAPI.superBreakerEnabled(event.getPlayer())
|
||||
|| AbilityAPI.treeFellerEnabled(event.getPlayer())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package me.konsolas.aac.internal;
|
||||
|
||||
public interface Destroyable {
|
||||
void destroy();
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package me.konsolas.aac.internal.packetwrapper;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.google.common.base.Objects;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class AbstractPacket {
|
||||
protected PacketContainer handle;
|
||||
|
||||
protected AbstractPacket(PacketContainer handle, PacketType type) {
|
||||
if (handle == null) {
|
||||
throw new IllegalArgumentException("Packet handle cannot be NULL.");
|
||||
}
|
||||
|
||||
if (!Objects.equal(handle.getType(), type)) {
|
||||
throw new IllegalArgumentException(handle.getHandle() + " is not a packet of type " + type);
|
||||
}
|
||||
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
public PacketContainer getHandle() {
|
||||
return this.handle;
|
||||
}
|
||||
|
||||
public void sendPacket(Player receiver) {
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(receiver, this.getHandle());
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException("Cannot send packet.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void receivePacket(Player sender) {
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().recieveClientPacket(sender, this.getHandle());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Cannot recieve packet.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package me.konsolas.aac.internal.packetwrapper;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class WrapperPlayClientUseEntity extends AbstractPacket {
|
||||
public static final PacketType TYPE = PacketType.Play.Client.USE_ENTITY;
|
||||
|
||||
public WrapperPlayClientUseEntity() {
|
||||
super(new PacketContainer(TYPE), TYPE);
|
||||
this.handle.getModifier().writeDefaults();
|
||||
}
|
||||
|
||||
public WrapperPlayClientUseEntity(PacketContainer packet) {
|
||||
super(packet, TYPE);
|
||||
}
|
||||
|
||||
public int getTargetID() {
|
||||
return this.handle.getIntegers().read(0);
|
||||
}
|
||||
|
||||
public void setTargetID(int value) {
|
||||
this.handle.getIntegers().write(0, value);
|
||||
}
|
||||
|
||||
public EntityUseAction getAction() {
|
||||
return this.handle.getEntityUseActions().read(0);
|
||||
}
|
||||
|
||||
public void setAction(EntityUseAction value) {
|
||||
this.handle.getEntityUseActions().write(0, value);
|
||||
}
|
||||
|
||||
public Vector getTargetVector() {
|
||||
return this.handle.getVectors().read(0);
|
||||
}
|
||||
|
||||
public void setTargetVector(Vector value) {
|
||||
this.handle.getVectors().write(0, value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package me.konsolas.aac.internal.packetwrapper;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
public class WrapperPlayServerAnimation extends AbstractPacket {
|
||||
public static final PacketType TYPE = PacketType.Play.Server.ANIMATION;
|
||||
|
||||
public WrapperPlayServerAnimation() {
|
||||
super(new PacketContainer(TYPE), TYPE);
|
||||
this.handle.getModifier().writeDefaults();
|
||||
}
|
||||
|
||||
public WrapperPlayServerAnimation(PacketContainer packet) {
|
||||
super(packet, TYPE);
|
||||
}
|
||||
|
||||
public int getEntityID() {
|
||||
return this.handle.getIntegers().read(0);
|
||||
}
|
||||
|
||||
public void setEntityID(int value) {
|
||||
this.handle.getIntegers().write(0, value);
|
||||
}
|
||||
|
||||
public Entity getEntity(World world) {
|
||||
return this.handle.getEntityModifier(world).read(0);
|
||||
}
|
||||
|
||||
public Entity getEntity(PacketEvent event) {
|
||||
return this.getEntity(event.getPlayer().getWorld());
|
||||
}
|
||||
|
||||
public int getAnimation() {
|
||||
return this.handle.getIntegers().read(1);
|
||||
}
|
||||
|
||||
public void setAnimation(int value) {
|
||||
this.handle.getIntegers().write(1, value);
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package me.konsolas.aac.internal.packetwrapper;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
|
||||
public class WrapperPlayServerEntityDestroy extends AbstractPacket {
|
||||
public static final PacketType TYPE = PacketType.Play.Server.ENTITY_DESTROY;
|
||||
|
||||
public WrapperPlayServerEntityDestroy() {
|
||||
super(new PacketContainer(TYPE), TYPE);
|
||||
this.handle.getModifier().writeDefaults();
|
||||
}
|
||||
|
||||
public WrapperPlayServerEntityDestroy(PacketContainer packet) {
|
||||
super(packet, TYPE);
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return this.handle.getIntegerArrays().read(0).length;
|
||||
}
|
||||
|
||||
public int[] getEntityIds() {
|
||||
return this.handle.getIntegerArrays().read(0);
|
||||
}
|
||||
|
||||
public void setEntityIds(int[] value) {
|
||||
this.handle.getIntegerArrays().write(0, value);
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package me.konsolas.aac.internal.packetwrapper;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class WrapperPlayServerEntityEquipment extends AbstractPacket {
|
||||
public static final PacketType TYPE = PacketType.Play.Server.ENTITY_EQUIPMENT;
|
||||
|
||||
public WrapperPlayServerEntityEquipment() {
|
||||
super(new PacketContainer(TYPE), TYPE);
|
||||
this.handle.getModifier().writeDefaults();
|
||||
}
|
||||
|
||||
public WrapperPlayServerEntityEquipment(PacketContainer packet) {
|
||||
super(packet, TYPE);
|
||||
}
|
||||
|
||||
public int getEntityID() {
|
||||
return this.handle.getIntegers().read(0);
|
||||
}
|
||||
|
||||
public void setEntityID(int value) {
|
||||
this.handle.getIntegers().write(0, value);
|
||||
}
|
||||
|
||||
public int getSlot() {
|
||||
return this.handle.getIntegers().read(1);
|
||||
}
|
||||
|
||||
public void setSlot(int value) {
|
||||
this.handle.getIntegers().write(1, value);
|
||||
}
|
||||
|
||||
public ItemStack getItem() {
|
||||
return this.handle.getItemModifier().read(0);
|
||||
}
|
||||
|
||||
public void setItem(ItemStack value) {
|
||||
this.handle.getItemModifier().write(0, value);
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package me.konsolas.aac.internal.packetwrapper;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||
import java.util.List;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
public class WrapperPlayServerEntityMetadata extends AbstractPacket {
|
||||
public static final PacketType TYPE = PacketType.Play.Server.ENTITY_METADATA;
|
||||
|
||||
public WrapperPlayServerEntityMetadata() {
|
||||
super(new PacketContainer(TYPE), TYPE);
|
||||
this.handle.getModifier().writeDefaults();
|
||||
}
|
||||
|
||||
public WrapperPlayServerEntityMetadata(PacketContainer packet) {
|
||||
super(packet, TYPE);
|
||||
}
|
||||
|
||||
public int getEntityID() {
|
||||
return this.handle.getIntegers().read(0);
|
||||
}
|
||||
|
||||
public void setEntityID(int value) {
|
||||
this.handle.getIntegers().write(0, value);
|
||||
}
|
||||
|
||||
public Entity getEntity(World world) {
|
||||
return this.handle.getEntityModifier(world).read(0);
|
||||
}
|
||||
|
||||
public Entity getEntity(PacketEvent event) {
|
||||
return this.getEntity(event.getPlayer().getWorld());
|
||||
}
|
||||
|
||||
public List<WrappedWatchableObject> getMetadata() {
|
||||
return this.handle.getWatchableCollectionModifier().read(0);
|
||||
}
|
||||
|
||||
public void setMetadata(List<WrappedWatchableObject> value) {
|
||||
this.handle.getWatchableCollectionModifier().write(0, value);
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
package me.konsolas.aac.internal.packetwrapper;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
|
||||
public class WrapperPlayServerEntityMoveLook extends AbstractPacket {
|
||||
public static final PacketType TYPE = PacketType.Play.Server.ENTITY_MOVE_LOOK;
|
||||
|
||||
public WrapperPlayServerEntityMoveLook() {
|
||||
super(new PacketContainer(TYPE), TYPE);
|
||||
this.handle.getModifier().writeDefaults();
|
||||
}
|
||||
|
||||
public WrapperPlayServerEntityMoveLook(PacketContainer packet) {
|
||||
super(packet, TYPE);
|
||||
}
|
||||
|
||||
public int getEntityID() {
|
||||
return this.handle.getIntegers().read(0);
|
||||
}
|
||||
|
||||
public void setEntityID(int value) {
|
||||
this.handle.getIntegers().write(0, value);
|
||||
}
|
||||
|
||||
public double getDx() {
|
||||
return this.handle.getBytes().read(0) / 32.0;
|
||||
}
|
||||
|
||||
public void setDx(double value) {
|
||||
this.handle.getBytes().write(0, (byte) (value * 32.0));
|
||||
}
|
||||
|
||||
public double getDy() {
|
||||
return this.handle.getBytes().read(0) / 32.0;
|
||||
}
|
||||
|
||||
public void setDy(double value) {
|
||||
this.handle.getBytes().write(0, (byte) (value * 32.0));
|
||||
}
|
||||
|
||||
public double getDz() {
|
||||
return this.handle.getBytes().read(0) / 32.0;
|
||||
}
|
||||
|
||||
public void setDz(double value) {
|
||||
this.handle.getBytes().write(0, (byte) (value * 32.0));
|
||||
}
|
||||
|
||||
public float getYaw() {
|
||||
return this.handle.getBytes().read(0) * 360.0F / 256.0F;
|
||||
}
|
||||
|
||||
public void setYaw(float value) {
|
||||
this.handle.getBytes().write(0, (byte) (value * 256.0F / 360.0F));
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return this.handle.getBytes().read(1) * 360.0F / 256.0F;
|
||||
}
|
||||
|
||||
public void setPitch(float value) {
|
||||
this.handle.getBytes().write(1, (byte) (value * 256.0F / 360.0F));
|
||||
}
|
||||
|
||||
public boolean getOnGround() {
|
||||
return this.handle.getSpecificModifier(boolean.class).read(0);
|
||||
}
|
||||
|
||||
public void setOnGround(boolean value) {
|
||||
this.handle.getSpecificModifier(boolean.class).write(0, value);
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package me.konsolas.aac.internal.packetwrapper;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
public class WrapperPlayServerEntityStatus extends AbstractPacket {
|
||||
public static final PacketType TYPE = PacketType.Play.Server.ENTITY_STATUS;
|
||||
|
||||
public WrapperPlayServerEntityStatus() {
|
||||
super(new PacketContainer(TYPE), TYPE);
|
||||
this.handle.getModifier().writeDefaults();
|
||||
}
|
||||
|
||||
public WrapperPlayServerEntityStatus(PacketContainer packet) {
|
||||
super(packet, TYPE);
|
||||
}
|
||||
|
||||
public int getEntityID() {
|
||||
return this.handle.getIntegers().read(0);
|
||||
}
|
||||
|
||||
public void setEntityID(int value) {
|
||||
this.handle.getIntegers().write(0, value);
|
||||
}
|
||||
|
||||
public Entity getEntity(World world) {
|
||||
return this.handle.getEntityModifier(world).read(0);
|
||||
}
|
||||
|
||||
public Entity getEntity(PacketEvent event) {
|
||||
return this.getEntity(event.getPlayer().getWorld());
|
||||
}
|
||||
|
||||
public byte getEntityStatus() {
|
||||
return this.handle.getBytes().read(0);
|
||||
}
|
||||
|
||||
public void setEntityStatus(byte value) {
|
||||
this.handle.getBytes().write(0, value);
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
package me.konsolas.aac.internal.packetwrapper;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
public class WrapperPlayServerEntityTeleport extends AbstractPacket {
|
||||
public static final PacketType TYPE = PacketType.Play.Server.ENTITY_TELEPORT;
|
||||
|
||||
public WrapperPlayServerEntityTeleport() {
|
||||
super(new PacketContainer(TYPE), TYPE);
|
||||
this.handle.getModifier().writeDefaults();
|
||||
}
|
||||
|
||||
public WrapperPlayServerEntityTeleport(PacketContainer packet) {
|
||||
super(packet, TYPE);
|
||||
}
|
||||
|
||||
public int getEntityID() {
|
||||
return this.handle.getIntegers().read(0);
|
||||
}
|
||||
|
||||
public void setEntityID(int value) {
|
||||
this.handle.getIntegers().write(0, value);
|
||||
}
|
||||
|
||||
public Entity getEntity(World world) {
|
||||
return this.handle.getEntityModifier(world).read(0);
|
||||
}
|
||||
|
||||
public Entity getEntity(PacketEvent event) {
|
||||
return this.getEntity(event.getPlayer().getWorld());
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return this.handle.getDoubles().read(0);
|
||||
}
|
||||
|
||||
public void setX(double value) {
|
||||
this.handle.getDoubles().write(0, value);
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return this.handle.getDoubles().read(1);
|
||||
}
|
||||
|
||||
public void setY(double value) {
|
||||
this.handle.getDoubles().write(1, value);
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return this.handle.getDoubles().read(2);
|
||||
}
|
||||
|
||||
public void setZ(double value) {
|
||||
this.handle.getDoubles().write(2, value);
|
||||
}
|
||||
|
||||
public float getYaw() {
|
||||
return this.handle.getBytes().read(0) * 360.0F / 256.0F;
|
||||
}
|
||||
|
||||
public void setYaw(float value) {
|
||||
this.handle.getBytes().write(0, (byte) (value * 256.0F / 360.0F));
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return this.handle.getBytes().read(1) * 360.0F / 256.0F;
|
||||
}
|
||||
|
||||
public void setPitch(float value) {
|
||||
this.handle.getBytes().write(1, (byte) (value * 256.0F / 360.0F));
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
package me.konsolas.aac.internal.packetwrapper;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class WrapperPlayServerEntityVelocity extends AbstractPacket {
|
||||
public static final PacketType TYPE = PacketType.Play.Server.ENTITY_VELOCITY;
|
||||
|
||||
public WrapperPlayServerEntityVelocity() {
|
||||
super(new PacketContainer(TYPE), TYPE);
|
||||
this.handle.getModifier().writeDefaults();
|
||||
}
|
||||
|
||||
public WrapperPlayServerEntityVelocity(PacketContainer packet) {
|
||||
super(packet, TYPE);
|
||||
}
|
||||
|
||||
public int getEntityID() {
|
||||
return this.handle.getIntegers().read(0);
|
||||
}
|
||||
|
||||
public void setEntityID(int value) {
|
||||
this.handle.getIntegers().write(0, value);
|
||||
}
|
||||
|
||||
public Entity getEntity(World world) {
|
||||
return this.handle.getEntityModifier(world).read(0);
|
||||
}
|
||||
|
||||
public Entity getEntity(PacketEvent event) {
|
||||
return this.getEntity(event.getPlayer().getWorld());
|
||||
}
|
||||
|
||||
public double getVelocityX() {
|
||||
return this.handle.getIntegers().read(1) / 8000.0;
|
||||
}
|
||||
|
||||
public void setVelocityX(double value) {
|
||||
this.handle.getIntegers().write(1, (int) (value * 8000.0));
|
||||
}
|
||||
|
||||
public double getVelocityY() {
|
||||
return this.handle.getIntegers().read(2) / 8000.0;
|
||||
}
|
||||
|
||||
public void setVelocityY(double value) {
|
||||
this.handle.getIntegers().write(2, (int) (value * 8000.0));
|
||||
}
|
||||
|
||||
public double getVelocityZ() {
|
||||
return this.handle.getIntegers().read(3) / 8000.0;
|
||||
}
|
||||
|
||||
public void setVelocityZ(double value) {
|
||||
this.handle.getIntegers().write(3, (int) (value * 8000.0));
|
||||
}
|
||||
|
||||
public Vector getVelocity() {
|
||||
return new Vector(this.getVelocityX(), this.getVelocityY(), this.getVelocityZ());
|
||||
}
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
package me.konsolas.aac.internal.packetwrapper;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class WrapperPlayServerNamedEntitySpawn extends AbstractPacket {
|
||||
public static final PacketType TYPE = PacketType.Play.Server.NAMED_ENTITY_SPAWN;
|
||||
|
||||
public WrapperPlayServerNamedEntitySpawn() {
|
||||
super(new PacketContainer(TYPE), TYPE);
|
||||
this.handle.getModifier().writeDefaults();
|
||||
}
|
||||
|
||||
public WrapperPlayServerNamedEntitySpawn(PacketContainer packet) {
|
||||
super(packet, TYPE);
|
||||
}
|
||||
|
||||
public int getEntityID() {
|
||||
return this.handle.getIntegers().read(0);
|
||||
}
|
||||
|
||||
public void setEntityID(int value) {
|
||||
this.handle.getIntegers().write(0, value);
|
||||
}
|
||||
|
||||
public UUID getPlayerUUID() {
|
||||
return this.handle.getSpecificModifier(UUID.class).read(0);
|
||||
}
|
||||
|
||||
public void setPlayerUUID(UUID value) {
|
||||
this.handle.getSpecificModifier(UUID.class).write(0, value);
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
return new Vector(this.getX(), this.getY(), this.getZ());
|
||||
}
|
||||
|
||||
public void setPosition(Vector position) {
|
||||
this.setX(position.getX());
|
||||
this.setY(position.getY());
|
||||
this.setZ(position.getZ());
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return this.handle.getDoubles().read(0);
|
||||
}
|
||||
|
||||
public void setX(double value) {
|
||||
this.handle.getDoubles().write(0, value);
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return this.handle.getDoubles().read(1);
|
||||
}
|
||||
|
||||
public void setY(double value) {
|
||||
this.handle.getDoubles().write(1, value);
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return this.handle.getDoubles().read(2);
|
||||
}
|
||||
|
||||
public void setZ(double value) {
|
||||
this.handle.getDoubles().write(2, value);
|
||||
}
|
||||
|
||||
public float getYaw() {
|
||||
return this.handle.getBytes().read(0) * 360.0F / 256.0F;
|
||||
}
|
||||
|
||||
public void setYaw(float value) {
|
||||
this.handle.getBytes().write(0, (byte) (value * 256.0F / 360.0F));
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return this.handle.getBytes().read(1) * 360.0F / 256.0F;
|
||||
}
|
||||
|
||||
public void setPitch(float value) {
|
||||
this.handle.getBytes().write(1, (byte) (value * 256.0F / 360.0F));
|
||||
}
|
||||
|
||||
public WrappedDataWatcher getMetadata() {
|
||||
return this.handle.getDataWatcherModifier().read(0);
|
||||
}
|
||||
|
||||
public void setMetadata(WrappedDataWatcher value) {
|
||||
this.handle.getDataWatcherModifier().write(0, value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package me.konsolas.aac.internal.packetwrapper;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
|
||||
import com.comphenix.protocol.wrappers.PlayerInfoData;
|
||||
import java.util.List;
|
||||
|
||||
public class WrapperPlayServerPlayerInfo extends AbstractPacket {
|
||||
public static final PacketType TYPE = PacketType.Play.Server.PLAYER_INFO;
|
||||
|
||||
public WrapperPlayServerPlayerInfo() {
|
||||
super(new PacketContainer(TYPE), TYPE);
|
||||
this.handle.getModifier().writeDefaults();
|
||||
}
|
||||
|
||||
public WrapperPlayServerPlayerInfo(PacketContainer packet) {
|
||||
super(packet, TYPE);
|
||||
}
|
||||
|
||||
public PlayerInfoAction getAction() {
|
||||
return this.handle.getPlayerInfoAction().read(0);
|
||||
}
|
||||
|
||||
public void setAction(PlayerInfoAction value) {
|
||||
this.handle.getPlayerInfoAction().write(0, value);
|
||||
}
|
||||
|
||||
public List<PlayerInfoData> getData() {
|
||||
return this.handle.getPlayerInfoDataLists().read(0);
|
||||
}
|
||||
|
||||
public void setData(List<PlayerInfoData> value) {
|
||||
this.handle.getPlayerInfoDataLists().write(0, value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package me.konsolas.aac.internal.packetwrapper;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.wrappers.BukkitConverters;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import java.util.Set;
|
||||
|
||||
public class WrapperPlayServerPosition extends AbstractPacket {
|
||||
public static final PacketType TYPE = PacketType.Play.Server.POSITION;
|
||||
private static final Class<?> FLAGS_CLASS = MinecraftReflection.getMinecraftClass(
|
||||
"EnumPlayerTeleportFlags", "PacketPlayOutPosition$EnumPlayerTeleportFlags"
|
||||
);
|
||||
|
||||
public WrapperPlayServerPosition() {
|
||||
super(new PacketContainer(TYPE), TYPE);
|
||||
this.handle.getModifier().writeDefaults();
|
||||
}
|
||||
|
||||
public WrapperPlayServerPosition(PacketContainer packet) {
|
||||
super(packet, TYPE);
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return this.handle.getDoubles().read(0);
|
||||
}
|
||||
|
||||
public void setX(double value) {
|
||||
this.handle.getDoubles().write(0, value);
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return this.handle.getDoubles().read(1);
|
||||
}
|
||||
|
||||
public void setY(double value) {
|
||||
this.handle.getDoubles().write(1, value);
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return this.handle.getDoubles().read(2);
|
||||
}
|
||||
|
||||
public void setZ(double value) {
|
||||
this.handle.getDoubles().write(2, value);
|
||||
}
|
||||
|
||||
public float getYaw() {
|
||||
return this.handle.getFloat().read(0);
|
||||
}
|
||||
|
||||
public void setYaw(float value) {
|
||||
this.handle.getFloat().write(0, value);
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return this.handle.getFloat().read(1);
|
||||
}
|
||||
|
||||
public void setPitch(float value) {
|
||||
this.handle.getFloat().write(1, value);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private StructureModifier<Set<PlayerTeleportFlag>> getFlagsModifier() {
|
||||
return this.handle.getModifier().withType(
|
||||
Set.class,
|
||||
BukkitConverters.getSetConverter(FLAGS_CLASS, EnumWrappers.getGenericConverter(PlayerTeleportFlag.class))
|
||||
);
|
||||
}
|
||||
|
||||
public Set<PlayerTeleportFlag> getFlags() {
|
||||
return this.getFlagsModifier().read(0);
|
||||
}
|
||||
|
||||
public void setFlags(Set<PlayerTeleportFlag> value) {
|
||||
this.getFlagsModifier().write(0, value);
|
||||
}
|
||||
|
||||
public enum PlayerTeleportFlag {
|
||||
X,
|
||||
Y,
|
||||
Z,
|
||||
Y_ROT,
|
||||
X_ROT
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package me.konsolas.aac.internal.packetwrapper;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
|
||||
public class WrapperPlayServerRelEntityMove extends AbstractPacket {
|
||||
public static final PacketType TYPE = PacketType.Play.Server.REL_ENTITY_MOVE;
|
||||
|
||||
public WrapperPlayServerRelEntityMove() {
|
||||
super(new PacketContainer(TYPE), TYPE);
|
||||
this.handle.getModifier().writeDefaults();
|
||||
}
|
||||
|
||||
public WrapperPlayServerRelEntityMove(PacketContainer packet) {
|
||||
super(packet, TYPE);
|
||||
}
|
||||
|
||||
public int getEntityID() {
|
||||
return this.handle.getIntegers().read(0);
|
||||
}
|
||||
|
||||
public void setEntityID(int value) {
|
||||
this.handle.getIntegers().write(0, value);
|
||||
}
|
||||
|
||||
public double getDx() {
|
||||
return this.handle.getShorts().read(0) / 4096.0;
|
||||
}
|
||||
|
||||
public void setDx(double value) {
|
||||
this.handle.getShorts().write(0, (short) (value * 32.0 * 128.0));
|
||||
}
|
||||
|
||||
public double getDy() {
|
||||
return this.handle.getShorts().read(1) / 4096.0;
|
||||
}
|
||||
|
||||
public void setDy(double value) {
|
||||
this.handle.getShorts().write(1, (short) (value * 32.0 * 128.0));
|
||||
}
|
||||
|
||||
public double getDz() {
|
||||
return this.handle.getShorts().read(2) / 4096.0;
|
||||
}
|
||||
|
||||
public void setDz(double value) {
|
||||
this.handle.getShorts().write(2, (short) (value * 32.0 * 128.0));
|
||||
}
|
||||
|
||||
public boolean getOnGround() {
|
||||
return this.handle.getSpecificModifier(boolean.class).read(0);
|
||||
}
|
||||
|
||||
public void setOnGround(boolean value) {
|
||||
this.handle.getSpecificModifier(boolean.class).write(0, value);
|
||||
}
|
||||
}
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
package me.konsolas.aac.internal.packetwrapper;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.injector.PacketConstructor;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
public class WrapperPlayServerSpawnEntityLiving extends AbstractPacket {
|
||||
public static final PacketType TYPE = PacketType.Play.Server.SPAWN_ENTITY_LIVING;
|
||||
private static PacketConstructor entityConstructor;
|
||||
|
||||
public WrapperPlayServerSpawnEntityLiving() {
|
||||
super(new PacketContainer(TYPE), TYPE);
|
||||
this.handle.getModifier().writeDefaults();
|
||||
}
|
||||
|
||||
public WrapperPlayServerSpawnEntityLiving(PacketContainer packet) {
|
||||
super(packet, TYPE);
|
||||
}
|
||||
|
||||
public WrapperPlayServerSpawnEntityLiving(Entity entity) {
|
||||
super(fromEntity(entity), TYPE);
|
||||
}
|
||||
|
||||
private static PacketContainer fromEntity(Entity entity) {
|
||||
if (entityConstructor == null) {
|
||||
entityConstructor = ProtocolLibrary.getProtocolManager().createPacketConstructor(TYPE, entity);
|
||||
}
|
||||
|
||||
return entityConstructor.createPacket(entity);
|
||||
}
|
||||
|
||||
public int getEntityID() {
|
||||
return this.handle.getIntegers().read(0);
|
||||
}
|
||||
|
||||
public Entity getEntity(World world) {
|
||||
return this.handle.getEntityModifier(world).read(0);
|
||||
}
|
||||
|
||||
public Entity getEntity(PacketEvent event) {
|
||||
return this.getEntity(event.getPlayer().getWorld());
|
||||
}
|
||||
|
||||
public void setEntityID(int value) {
|
||||
this.handle.getIntegers().write(0, value);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public EntityType getType() {
|
||||
return EntityType.fromId(this.handle.getIntegers().read(1));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void setType(EntityType value) {
|
||||
this.handle.getIntegers().write(1, (int) value.getTypeId());
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return this.handle.getDoubles().read(0);
|
||||
}
|
||||
|
||||
public void setX(double value) {
|
||||
this.handle.getDoubles().write(0, value);
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return this.handle.getDoubles().read(1);
|
||||
}
|
||||
|
||||
public void setY(double value) {
|
||||
this.handle.getDoubles().write(1, value);
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return this.handle.getDoubles().read(2);
|
||||
}
|
||||
|
||||
public void setZ(double value) {
|
||||
this.handle.getDoubles().write(2, value);
|
||||
}
|
||||
|
||||
public float getYaw() {
|
||||
return this.handle.getBytes().read(0) * 360.0F / 256.0F;
|
||||
}
|
||||
|
||||
public void setYaw(float value) {
|
||||
this.handle.getBytes().write(0, (byte) (value * 256.0F / 360.0F));
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return this.handle.getBytes().read(1) * 360.0F / 256.0F;
|
||||
}
|
||||
|
||||
public void setPitch(float value) {
|
||||
this.handle.getBytes().write(1, (byte) (value * 256.0F / 360.0F));
|
||||
}
|
||||
|
||||
public float getHeadPitch() {
|
||||
return this.handle.getBytes().read(2) * 360.0F / 256.0F;
|
||||
}
|
||||
|
||||
public void setHeadPitch(float value) {
|
||||
this.handle.getBytes().write(2, (byte) (value * 256.0F / 360.0F));
|
||||
}
|
||||
|
||||
public double getVelocityX() {
|
||||
return this.handle.getIntegers().read(5) / 8000.0;
|
||||
}
|
||||
|
||||
public void setVelocityX(double value) {
|
||||
this.handle.getIntegers().write(5, (int) (value * 8000.0));
|
||||
}
|
||||
|
||||
public double getVelocityY() {
|
||||
return this.handle.getIntegers().read(6) / 8000.0;
|
||||
}
|
||||
|
||||
public void setVelocityY(double value) {
|
||||
this.handle.getIntegers().write(6, (int) (value * 8000.0));
|
||||
}
|
||||
|
||||
public double getVelocityZ() {
|
||||
return this.handle.getIntegers().read(7) / 8000.0;
|
||||
}
|
||||
|
||||
public void setVelocityZ(double value) {
|
||||
this.handle.getIntegers().write(7, (int) (value * 8000.0));
|
||||
}
|
||||
|
||||
public WrappedDataWatcher getMetadata() {
|
||||
return this.handle.getDataWatcherModifier().read(0);
|
||||
}
|
||||
|
||||
public void setMetadata(WrappedDataWatcher value) {
|
||||
this.handle.getDataWatcherModifier().write(0, value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package me.konsolas.aac.lang;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import me.konsolas.aac.AAC;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public class Messages {
|
||||
private final AAC plugin;
|
||||
private FileConfiguration configuration = null;
|
||||
private File configurationFile = null;
|
||||
|
||||
public Messages(AAC plugin) {
|
||||
this.plugin = plugin;
|
||||
this.saveDefaultConfig();
|
||||
}
|
||||
|
||||
public String getMessage(String key) {
|
||||
return this.getConfig().getString(key);
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
if (this.configuration == null) {
|
||||
this.reloadConfig();
|
||||
}
|
||||
|
||||
return this.configuration;
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
if (this.configurationFile == null) {
|
||||
this.configurationFile = new File(this.plugin.getDataFolder(), "language.yml");
|
||||
}
|
||||
|
||||
this.configuration = YamlConfiguration.loadConfiguration(this.configurationFile);
|
||||
InputStream defaultStream = this.plugin.getResource("language.yml");
|
||||
if (defaultStream != null) {
|
||||
InputStreamReader reader = new InputStreamReader(defaultStream, StandardCharsets.UTF_8);
|
||||
YamlConfiguration defaultConfig = YamlConfiguration.loadConfiguration(reader);
|
||||
this.configuration.setDefaults(defaultConfig);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveDefaultConfig() {
|
||||
if (this.configurationFile == null) {
|
||||
this.configurationFile = new File(this.plugin.getDataFolder(), "language.yml");
|
||||
}
|
||||
|
||||
if (!this.configurationFile.exists()) {
|
||||
this.plugin.saveResource("language.yml", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package me.konsolas.aac.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
public class BlockCache {
|
||||
private final double originX;
|
||||
private final double originY;
|
||||
private final double originZ;
|
||||
private final World world;
|
||||
private final Map<BlockPosition, Block> cachedBlocks = new HashMap<>();
|
||||
|
||||
public BlockCache(Location location) {
|
||||
this.originX = location.getX();
|
||||
this.originY = location.getY();
|
||||
this.originZ = location.getZ();
|
||||
this.world = location.getWorld();
|
||||
}
|
||||
|
||||
public Block getOffsetBlock(double dx, double dy, double dz) {
|
||||
return this.getBlockAt(
|
||||
(int) Math.floor(this.originX + dx),
|
||||
(int) Math.floor(this.originY + dy),
|
||||
(int) Math.floor(this.originZ + dz)
|
||||
);
|
||||
}
|
||||
|
||||
public Block getNegativeOffsetBlock(double dx, double dy, double dz) {
|
||||
return this.getBlockAt(
|
||||
(int) Math.floor(this.originX - dx),
|
||||
(int) Math.floor(this.originY - dy),
|
||||
(int) Math.floor(this.originZ - dz)
|
||||
);
|
||||
}
|
||||
|
||||
public Material getOffsetMaterial(double dx, double dy, double dz) {
|
||||
return this.getOffsetBlock(dx, dy, dz).getType();
|
||||
}
|
||||
|
||||
public Material getNegativeOffsetMaterial(double dx, double dy, double dz) {
|
||||
return this.getNegativeOffsetBlock(dx, dy, dz).getType();
|
||||
}
|
||||
|
||||
private Block getBlockAt(int x, int y, int z) {
|
||||
BlockPosition position = new BlockPosition(x, y, z);
|
||||
Block cached = this.cachedBlocks.get(position);
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
Block block = this.world.getBlockAt(x, y, z);
|
||||
this.cachedBlocks.put(position, block);
|
||||
return block;
|
||||
}
|
||||
|
||||
public Block getOriginBlock() {
|
||||
return this.getBlockAt((int) this.originX, (int) this.originY, (int) this.originZ);
|
||||
}
|
||||
|
||||
private static final class BlockPosition {
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
|
||||
private BlockPosition(int x, int y, int z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other == this) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(other instanceof BlockPosition)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BlockPosition position = (BlockPosition) other;
|
||||
return position.x == this.x && position.y == this.y && position.z == this.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = 17;
|
||||
result = 31 * result + this.x;
|
||||
result = 31 * result + this.y;
|
||||
return 31 * result + this.z;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,378 @@
|
||||
package me.konsolas.aac.util;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.events.PacketListener;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.EntityUseAction;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
|
||||
import com.comphenix.protocol.wrappers.PlayerInfoData;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.detectors.combat.Angle;
|
||||
import me.konsolas.aac.internal.packetwrapper.WrapperPlayClientUseEntity;
|
||||
import me.konsolas.aac.internal.packetwrapper.WrapperPlayServerEntityDestroy;
|
||||
import me.konsolas.aac.internal.packetwrapper.WrapperPlayServerEntityTeleport;
|
||||
import me.konsolas.aac.internal.packetwrapper.WrapperPlayServerNamedEntitySpawn;
|
||||
import me.konsolas.aac.internal.packetwrapper.WrapperPlayServerPlayerInfo;
|
||||
import me.konsolas.aac.internal.packetwrapper.WrapperPlayServerSpawnEntityLiving;
|
||||
import me.konsolas.aac.util.general.NumberUtil;
|
||||
import me.konsolas.aac.util.general.RandomPlayerNameGenerator;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class CombatDecoyPair {
|
||||
private static int ticksSpawned = 5;
|
||||
private static double maxDiff = 0.1;
|
||||
private static double maxReach = 5.0;
|
||||
private static int percentDistance = 80;
|
||||
private static double minDist = 2.7;
|
||||
private static int listenDelay = 2;
|
||||
private PlayerIdentity leftIdentity;
|
||||
private PlayerIdentity rightIdentity;
|
||||
private boolean callbackNotified = false;
|
||||
private final UUID playerId;
|
||||
private final Entity target;
|
||||
private final AAC plugin;
|
||||
private final DecoyResultCallback callback;
|
||||
private final PacketListener packetListener;
|
||||
private int decoyHits = 0;
|
||||
private int targetHits = 0;
|
||||
private BukkitTask tickTask;
|
||||
private int registerListenerTaskId;
|
||||
private int ticksElapsed;
|
||||
private int leftEntityId;
|
||||
private int rightEntityId;
|
||||
|
||||
public CombatDecoyPair(AAC plugin, Player player, Entity target, DecoyResultCallback callback) {
|
||||
this.callback = callback;
|
||||
this.plugin = plugin;
|
||||
this.playerId = player.getUniqueId();
|
||||
this.target = target;
|
||||
this.packetListener = new DecoyUseEntityListener(plugin, WrapperPlayClientUseEntity.TYPE);
|
||||
}
|
||||
|
||||
public static void loadConfig(AAC plugin) {
|
||||
ticksSpawned = plugin.getConfig().getInt("killaura.npc.ticks_spawned", ticksSpawned);
|
||||
maxDiff = plugin.getConfig().getDouble("killaura.npc.max_diff", maxDiff);
|
||||
maxReach = plugin.getConfig().getDouble("killaura.npc.max_reach", maxReach);
|
||||
percentDistance = plugin.getConfig().getInt("killaura.npc.percent_distance", percentDistance);
|
||||
minDist = plugin.getConfig().getDouble("killaura.npc.min_dist", minDist);
|
||||
listenDelay = plugin.getConfig().getInt("killaura.npc.listen_delay", listenDelay);
|
||||
}
|
||||
|
||||
public void spawn(EntityType entityType) {
|
||||
if (entityType == EntityType.PLAYER) {
|
||||
this.spawnPlayerDecoys();
|
||||
} else {
|
||||
this.spawnMobDecoys(entityType);
|
||||
}
|
||||
}
|
||||
|
||||
private void spawnPlayerDecoys() {
|
||||
Player player = this.getPlayer();
|
||||
if (player != null) {
|
||||
this.leftIdentity = PlayerIdentityPool.getInstance().createRandomIdentity();
|
||||
Vector leftPos = this.calculateDecoyPosition(
|
||||
player.getLocation().toVector(),
|
||||
this.getTarget().getLocation().toVector(),
|
||||
percentDistance,
|
||||
DecoySide.LEFT
|
||||
);
|
||||
leftPos.setY(leftPos.getY() + 0.15);
|
||||
WrapperPlayServerNamedEntitySpawn leftSpawn = this.createPlayerSpawnPacket(leftPos, true, this.leftIdentity);
|
||||
this.createPlayerInfoPacket(PlayerInfoAction.ADD_PLAYER, false, this.leftIdentity).sendPacket(player);
|
||||
leftSpawn.sendPacket(player);
|
||||
this.leftEntityId = leftSpawn.getEntityID();
|
||||
this.createPlayerInfoPacket(PlayerInfoAction.REMOVE_PLAYER, false, this.leftIdentity).sendPacket(player);
|
||||
|
||||
this.rightIdentity = PlayerIdentityPool.getInstance().createRandomIdentity();
|
||||
Vector rightPos = this.calculateDecoyPosition(
|
||||
player.getLocation().toVector(),
|
||||
this.getTarget().getLocation().toVector(),
|
||||
percentDistance,
|
||||
DecoySide.RIGHT
|
||||
);
|
||||
rightPos.setY(rightPos.getY() + 0.15);
|
||||
WrapperPlayServerNamedEntitySpawn rightSpawn = this.createPlayerSpawnPacket(rightPos, true, this.rightIdentity);
|
||||
this.createPlayerInfoPacket(PlayerInfoAction.ADD_PLAYER, false, this.rightIdentity).sendPacket(player);
|
||||
rightSpawn.sendPacket(player);
|
||||
this.rightEntityId = rightSpawn.getEntityID();
|
||||
this.createPlayerInfoPacket(PlayerInfoAction.REMOVE_PLAYER, false, this.rightIdentity).sendPacket(player);
|
||||
|
||||
this.registerListenerTaskId = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new RegisterListenerTask(), listenDelay);
|
||||
this.scheduleNextTick();
|
||||
}
|
||||
}
|
||||
|
||||
private void spawnMobDecoys(EntityType entityType) {
|
||||
Player player = this.getPlayer();
|
||||
if (player != null) {
|
||||
Vector leftPos = this.calculateDecoyPosition(
|
||||
player.getLocation().toVector(),
|
||||
this.getTarget().getLocation().toVector(),
|
||||
percentDistance,
|
||||
DecoySide.LEFT
|
||||
);
|
||||
leftPos.setY(leftPos.getY() + 0.15);
|
||||
WrapperPlayServerSpawnEntityLiving leftSpawn = new WrapperPlayServerSpawnEntityLiving();
|
||||
leftSpawn.setType(entityType);
|
||||
leftSpawn.setEntityID(this.generateEntityId(player));
|
||||
leftSpawn.setX(leftPos.getX());
|
||||
leftSpawn.setY(leftPos.getY());
|
||||
leftSpawn.setZ(leftPos.getZ());
|
||||
WrappedDataWatcher leftWatcher = new WrappedDataWatcher();
|
||||
leftWatcher.setObject(new WrappedDataWatcherObject(0, Registry.get(Byte.class)), (byte) 32);
|
||||
leftWatcher.setObject(new WrappedDataWatcherObject(7, Registry.get(Float.class)), ThreadLocalRandom.current().nextInt(19) + 1.0F);
|
||||
leftSpawn.setMetadata(leftWatcher);
|
||||
this.leftEntityId = leftSpawn.getEntityID();
|
||||
leftSpawn.sendPacket(player);
|
||||
|
||||
Vector rightPos = this.calculateDecoyPosition(
|
||||
player.getLocation().toVector(),
|
||||
this.getTarget().getLocation().toVector(),
|
||||
percentDistance,
|
||||
DecoySide.RIGHT
|
||||
);
|
||||
rightPos.setY(rightPos.getY() + 0.15);
|
||||
WrapperPlayServerSpawnEntityLiving rightSpawn = new WrapperPlayServerSpawnEntityLiving();
|
||||
rightSpawn.setType(entityType);
|
||||
rightSpawn.setEntityID(this.generateEntityId(player));
|
||||
rightSpawn.setX(rightPos.getX());
|
||||
rightSpawn.setY(rightPos.getY());
|
||||
rightSpawn.setZ(rightPos.getZ());
|
||||
WrappedDataWatcher rightWatcher = new WrappedDataWatcher();
|
||||
rightWatcher.setObject(new WrappedDataWatcherObject(0, Registry.get(Byte.class)), (byte) 32);
|
||||
rightWatcher.setObject(new WrappedDataWatcherObject(7, Registry.get(Float.class)), ThreadLocalRandom.current().nextInt(19) + 1.0F);
|
||||
rightSpawn.setMetadata(rightWatcher);
|
||||
this.rightEntityId = rightSpawn.getEntityID();
|
||||
rightSpawn.sendPacket(player);
|
||||
|
||||
this.registerListenerTaskId = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new RegisterListenerTask(), listenDelay);
|
||||
this.scheduleNextTick();
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePositions() {
|
||||
Player player = this.getPlayer();
|
||||
Entity targetEntity = this.getTarget();
|
||||
if (player != null && targetEntity != null) {
|
||||
try {
|
||||
if (player.getLocation().distance(targetEntity.getLocation()) < minDist) {
|
||||
this.destroy();
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
this.destroy();
|
||||
}
|
||||
|
||||
WrapperPlayServerEntityTeleport leftTeleport = new WrapperPlayServerEntityTeleport();
|
||||
leftTeleport.setPitch(AAC.random.nextFloat() * 80.0F);
|
||||
leftTeleport.setYaw(AAC.random.nextFloat() * 359.0F);
|
||||
Vector leftPos = this.calculateDecoyPosition(
|
||||
player.getLocation().toVector(),
|
||||
targetEntity.getLocation().toVector(),
|
||||
percentDistance,
|
||||
DecoySide.LEFT
|
||||
);
|
||||
leftTeleport.setX(leftPos.getX());
|
||||
leftTeleport.setY(leftPos.getY() + 0.1);
|
||||
leftTeleport.setZ(leftPos.getZ());
|
||||
leftTeleport.setEntityID(this.leftEntityId);
|
||||
leftTeleport.sendPacket(player);
|
||||
|
||||
WrapperPlayServerEntityTeleport rightTeleport = new WrapperPlayServerEntityTeleport();
|
||||
rightTeleport.setPitch(AAC.random.nextFloat() * 80.0F);
|
||||
rightTeleport.setYaw(AAC.random.nextFloat() * 359.0F);
|
||||
Vector rightPos = this.calculateDecoyPosition(
|
||||
player.getLocation().toVector(),
|
||||
targetEntity.getLocation().toVector(),
|
||||
percentDistance,
|
||||
DecoySide.RIGHT
|
||||
);
|
||||
rightTeleport.setX(rightPos.getX());
|
||||
rightTeleport.setY(rightPos.getY() + 0.1);
|
||||
rightTeleport.setZ(rightPos.getZ());
|
||||
rightTeleport.setEntityID(this.rightEntityId);
|
||||
rightTeleport.sendPacket(player);
|
||||
}
|
||||
}
|
||||
|
||||
private void scheduleNextTick() {
|
||||
this.tickTask = Bukkit.getScheduler().runTaskLaterAsynchronously(this.plugin, new DecoyTickTask(), 1L);
|
||||
}
|
||||
|
||||
private Vector calculateDecoyPosition(Vector playerPos, Vector targetPos, double distancePercent, DecoySide side) {
|
||||
Vector direction = targetPos.clone().subtract(playerPos);
|
||||
double distance = direction.length();
|
||||
direction = direction.normalize().multiply(distance * (distancePercent / 100.0));
|
||||
Vector midpoint = playerPos.clone().add(direction);
|
||||
Vector perpendicular = playerPos.clone().subtract(targetPos);
|
||||
Vector original = perpendicular.clone();
|
||||
if (side == DecoySide.LEFT) {
|
||||
perpendicular.setX(-original.getZ());
|
||||
perpendicular.setZ(original.getX());
|
||||
} else {
|
||||
perpendicular.setZ(-original.getX());
|
||||
perpendicular.setX(original.getZ());
|
||||
}
|
||||
|
||||
perpendicular.normalize();
|
||||
return midpoint.add(perpendicular.multiply(0.3));
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
Player player = this.getPlayer();
|
||||
if (player == null) {
|
||||
this.tickTask.cancel();
|
||||
Bukkit.getServer().getScheduler().cancelTask(this.registerListenerTaskId);
|
||||
ProtocolLibrary.getProtocolManager().removePacketListener(this.packetListener);
|
||||
this.finishCallback();
|
||||
} else {
|
||||
this.createDestroyPacket(this.leftEntityId).sendPacket(player);
|
||||
this.createDestroyPacket(this.rightEntityId).sendPacket(player);
|
||||
this.tickTask.cancel();
|
||||
Bukkit.getServer().getScheduler().cancelTask(this.registerListenerTaskId);
|
||||
ProtocolLibrary.getProtocolManager().removePacketListener(this.packetListener);
|
||||
this.finishCallback();
|
||||
}
|
||||
}
|
||||
|
||||
private void finishCallback() {
|
||||
if (!this.callbackNotified) {
|
||||
this.callback.onDecoyResult(this.decoyHits, this.targetHits);
|
||||
this.callbackNotified = true;
|
||||
}
|
||||
}
|
||||
|
||||
private WrapperPlayServerNamedEntitySpawn createPlayerSpawnPacket(Vector position, boolean invisible, PlayerIdentity identity) {
|
||||
int entityId = this.generateEntityId(this.getPlayer());
|
||||
WrapperPlayServerNamedEntitySpawn packet = new WrapperPlayServerNamedEntitySpawn();
|
||||
packet.setEntityID(entityId);
|
||||
packet.setPosition(position);
|
||||
packet.setPlayerUUID(identity.getUniqueId());
|
||||
packet.setYaw(AAC.random.nextInt() % 360);
|
||||
packet.setPitch(AAC.random.nextInt() % 100 - 50.0F);
|
||||
WrappedDataWatcher watcher = new WrappedDataWatcher();
|
||||
watcher.setObject(new WrappedDataWatcherObject(0, Registry.get(Byte.class)), (byte) (invisible ? 32 : 0));
|
||||
watcher.setObject(new WrappedDataWatcherObject(7, Registry.get(Float.class)), ThreadLocalRandom.current().nextInt(19) + 1.0F);
|
||||
packet.setMetadata(watcher);
|
||||
return packet;
|
||||
}
|
||||
|
||||
private WrapperPlayServerPlayerInfo createPlayerInfoPacket(PlayerInfoAction action, boolean useIdentityName, PlayerIdentity identity) {
|
||||
WrapperPlayServerPlayerInfo packet = new WrapperPlayServerPlayerInfo();
|
||||
packet.setAction(action);
|
||||
WrappedGameProfile profile = new WrappedGameProfile(
|
||||
identity.getUniqueId(),
|
||||
useIdentityName ? identity.getName() : RandomPlayerNameGenerator.generateName()
|
||||
);
|
||||
PlayerInfoData data = new PlayerInfoData(
|
||||
profile,
|
||||
1,
|
||||
NativeGameMode.SURVIVAL,
|
||||
WrappedChatComponent.fromText(useIdentityName ? identity.getName() : RandomPlayerNameGenerator.generateName())
|
||||
);
|
||||
List<PlayerInfoData> entries = new ArrayList<>();
|
||||
entries.add(data);
|
||||
packet.setData(entries);
|
||||
return packet;
|
||||
}
|
||||
|
||||
private WrapperPlayServerEntityDestroy createDestroyPacket(int entityId) {
|
||||
WrapperPlayServerEntityDestroy packet = new WrapperPlayServerEntityDestroy();
|
||||
packet.setEntityIds(new int[]{entityId});
|
||||
return packet;
|
||||
}
|
||||
|
||||
private int generateEntityId(Player player) {
|
||||
return player.getEntityId() + 1073741823 + AAC.random.nextInt(100000);
|
||||
}
|
||||
|
||||
private Player getPlayer() {
|
||||
return Bukkit.getPlayer(this.playerId);
|
||||
}
|
||||
|
||||
private Entity getTarget() {
|
||||
return this.target;
|
||||
}
|
||||
|
||||
private enum DecoySide {
|
||||
LEFT,
|
||||
RIGHT
|
||||
}
|
||||
|
||||
private final class DecoyUseEntityListener extends PacketAdapter {
|
||||
private DecoyUseEntityListener(Plugin plugin, PacketType... types) {
|
||||
super(plugin, types);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
try {
|
||||
if (event.getPacketType() == WrapperPlayClientUseEntity.TYPE) {
|
||||
WrapperPlayClientUseEntity packet = new WrapperPlayClientUseEntity(event.getPacket());
|
||||
Player player = CombatDecoyPair.this.getPlayer();
|
||||
if (packet.getAction() == EntityUseAction.ATTACK && event.getPlayer().getUniqueId().equals(player.getUniqueId())) {
|
||||
int targetId = packet.getTargetID();
|
||||
Entity targetEntity = CombatDecoyPair.this.getTarget();
|
||||
if (targetId == CombatDecoyPair.this.leftEntityId || targetId == CombatDecoyPair.this.rightEntityId) {
|
||||
CombatDecoyPair.this.decoyHits++;
|
||||
double dotProduct = Angle.getLookDotProduct(player.getLocation(), targetEntity.getLocation());
|
||||
|
||||
try {
|
||||
if (NumberUtil.approximatelyEqual(dotProduct, 1.0, maxDiff)
|
||||
&& player.getLocation().add(0.0, 1.0, 0.0).distance(targetEntity.getLocation()) < maxReach) {
|
||||
packet.setTargetID(targetEntity.getEntityId());
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
CombatDecoyPair.this.destroy();
|
||||
}
|
||||
} else if (targetId == targetEntity.getEntityId()) {
|
||||
CombatDecoyPair.this.targetHits++;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
CombatDecoyPair.this.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class RegisterListenerTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(CombatDecoyPair.this.packetListener);
|
||||
}
|
||||
}
|
||||
|
||||
private final class DecoyTickTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
CombatDecoyPair.this.updatePositions();
|
||||
CombatDecoyPair.this.ticksElapsed++;
|
||||
if (CombatDecoyPair.this.ticksElapsed < ticksSpawned) {
|
||||
CombatDecoyPair.this.scheduleNextTick();
|
||||
} else {
|
||||
CombatDecoyPair.this.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package me.konsolas.aac.util;
|
||||
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import me.konsolas.aac.AAC;
|
||||
import me.konsolas.aac.internal.packetwrapper.WrapperPlayServerNamedEntitySpawn;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public final class CrashUtil {
|
||||
private CrashUtil() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static void crashPlayer(Player target, CommandSender sender) {
|
||||
new Thread(new ClientCrashTask(sender, target)).start();
|
||||
}
|
||||
|
||||
private static final class ClientCrashTask implements Runnable {
|
||||
private final CommandSender sender;
|
||||
private final Player target;
|
||||
|
||||
private ClientCrashTask(CommandSender sender, Player target) {
|
||||
this.sender = sender;
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
this.sender.sendMessage(AAC.messagePrefix + "Sending 100,000 entity spawn packets to " + this.target.getName());
|
||||
|
||||
for (int i = 0; i < 100000; i++) {
|
||||
PlayerIdentity identity = PlayerIdentityPool.getInstance().randomOfflineIdentity(this.target.getUniqueId());
|
||||
Vector position = this.target
|
||||
.getLocation()
|
||||
.add(
|
||||
ThreadLocalRandom.current().nextInt(-10, 10),
|
||||
ThreadLocalRandom.current().nextInt(-10, 10),
|
||||
ThreadLocalRandom.current().nextInt(-10, 10)
|
||||
)
|
||||
.toVector();
|
||||
WrapperPlayServerNamedEntitySpawn spawnPacket = ForcefieldDecoyManager.createSpawnPacket(position, true, identity, this.target);
|
||||
ForcefieldDecoyManager.createPlayerInfoPacket(PlayerInfoAction.ADD_PLAYER, true, identity).sendPacket(this.target);
|
||||
spawnPacket.sendPacket(this.target);
|
||||
}
|
||||
|
||||
this.sender.sendMessage(AAC.messagePrefix + "Finished sending packets. Player may still be online.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package me.konsolas.aac.util;
|
||||
|
||||
public interface DecoyResultCallback {
|
||||
void onDecoyResult(int decoyHits, int targetHits);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package me.konsolas.aac.util;
|
||||
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
public class EntityTargetCategories {
|
||||
public static boolean isReachTarget(EntityType type) {
|
||||
switch (type) {
|
||||
case PLAYER:
|
||||
case VILLAGER:
|
||||
case ZOMBIE:
|
||||
case PIG_ZOMBIE:
|
||||
case SKELETON:
|
||||
case WITCH:
|
||||
case SNOWMAN:
|
||||
case BLAZE:
|
||||
case CREEPER:
|
||||
case CHICKEN:
|
||||
case ENDERMAN:
|
||||
case SILVERFISH:
|
||||
case ENDERMITE:
|
||||
case RABBIT:
|
||||
case BAT:
|
||||
case WOLF:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isKillauraTarget(EntityType type) {
|
||||
switch (type) {
|
||||
case PLAYER:
|
||||
case VILLAGER:
|
||||
case ZOMBIE:
|
||||
case PIG_ZOMBIE:
|
||||
case SKELETON:
|
||||
case WITCH:
|
||||
case SNOWMAN:
|
||||
case BLAZE:
|
||||
case CREEPER:
|
||||
case CHICKEN:
|
||||
case ENDERMAN:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isPrimaryCombatTarget(EntityType type) {
|
||||
switch (type) {
|
||||
case PLAYER:
|
||||
case VILLAGER:
|
||||
case ZOMBIE:
|
||||
case PIG_ZOMBIE:
|
||||
case SKELETON:
|
||||
case WITCH:
|
||||
case SNOWMAN:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isKnockbackSource(EntityType type) {
|
||||
switch (type) {
|
||||
case PRIMED_TNT:
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loaded 100 of 124 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user