mirror of
https://github.com/funkemunky/KauriV3.git
synced 2026-06-02 06:22:18 +00:00
Shit
This commit is contained in:
@@ -13,6 +13,7 @@ import dev.brighten.ac.utils.*;
|
||||
import dev.brighten.ac.utils.timer.Timer;
|
||||
import dev.brighten.ac.utils.timer.impl.MillisTimer;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.val;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
@@ -30,8 +31,11 @@ public class Check implements ECheck {
|
||||
@Getter
|
||||
private final CheckData checkData;
|
||||
@Getter
|
||||
private float vl;
|
||||
public float vl;
|
||||
private long lastFlagRun;
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean enabled, punishable;
|
||||
private final Timer lastAlert = new MillisTimer();
|
||||
|
||||
public static Set<UUID> alertsEnabled = new HashSet<>();
|
||||
@@ -60,6 +64,14 @@ public class Check implements ECheck {
|
||||
.replace("%info%", info));
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
|
||||
}
|
||||
|
||||
private String addPlaceHolders(String string) {
|
||||
return string.replace("%player%", player.getBukkitPlayer().getName())
|
||||
.replace("%check%", checkData.name())
|
||||
@@ -170,6 +182,8 @@ public class Check implements ECheck {
|
||||
}
|
||||
|
||||
public void punish() {
|
||||
if(!punishable) return;
|
||||
|
||||
PunishResult result = PunishResult.builder().cancelled(false).build();
|
||||
|
||||
List<String> commands = CheckConfig.punishmentCommands.stream().map(this::addPlaceHolders)
|
||||
|
||||
@@ -11,6 +11,9 @@ public @interface CheckData {
|
||||
String name();
|
||||
CheckType type();
|
||||
|
||||
boolean enabled() default true;
|
||||
|
||||
boolean punishable() default true;
|
||||
int punishVl() default 10;
|
||||
|
||||
ProtocolVersion minVersion() default ProtocolVersion.V1_7;
|
||||
|
||||
@@ -5,17 +5,19 @@ import dev.brighten.ac.utils.ClassScanner;
|
||||
import dev.brighten.ac.utils.reflections.types.WrappedClass;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
public class CheckManager {
|
||||
private final List<CheckStatic> checkClasses = new ArrayList<>();
|
||||
private final Map<String, CheckStatic> checkClasses = new HashMap<>();
|
||||
|
||||
public CheckManager() {
|
||||
for (WrappedClass aClass : ClassScanner.getClasses(CheckData.class,
|
||||
"dev.brighten.ac.check.impl")) {
|
||||
addCheck(aClass);
|
||||
synchronized (checkClasses) {
|
||||
for (WrappedClass aClass : ClassScanner.getClasses(CheckData.class,
|
||||
"dev.brighten.ac.check.impl")) {
|
||||
addCheck(aClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,12 +32,11 @@ public class CheckManager {
|
||||
|
||||
Anticheat.INSTANCE.alog(true, "&7Adding check to CheckManager: " + checkData.name());
|
||||
|
||||
checkClasses.add(check);
|
||||
checkClasses.put(checkData.name(), check);
|
||||
}
|
||||
|
||||
public boolean isCheck(String name) {
|
||||
final String formattedName = name.replace("_", " ");
|
||||
return checkClasses.stream().anyMatch(c -> c.getCheckClass().getAnnotation(CheckData.class).name()
|
||||
.equalsIgnoreCase(formattedName));
|
||||
return checkClasses.containsKey(formattedName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import co.aikar.commands.annotation.*;
|
||||
import co.aikar.commands.bukkit.contexts.OnlinePlayer;
|
||||
import dev.brighten.ac.Anticheat;
|
||||
import dev.brighten.ac.check.Check;
|
||||
import dev.brighten.ac.check.CheckData;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.messages.Messages;
|
||||
import dev.brighten.ac.packet.handler.HandlerAbstract;
|
||||
@@ -35,9 +34,9 @@ public class AnticheatCommand extends BaseCommand {
|
||||
BukkitCommandCompletions cc = (BukkitCommandCompletions) Anticheat.INSTANCE.getCommandManager()
|
||||
.getCommandCompletions();
|
||||
|
||||
cc.registerCompletion("checks", (c) -> Anticheat.INSTANCE.getCheckManager().getCheckClasses().stream()
|
||||
.map(cs -> cs.getCheckClass().getAnnotation(CheckData.class).name().replace(" ", "_"))
|
||||
.sorted(Comparator.naturalOrder()).collect(Collectors.toList()));
|
||||
cc.registerCompletion("checks", (c) -> Anticheat.INSTANCE.getCheckManager().getCheckClasses().keySet()
|
||||
.stream() .sorted(Comparator.naturalOrder())
|
||||
.map(name -> name.replace(" ", "_")).collect(Collectors.toList()));
|
||||
|
||||
BukkitCommandContexts contexts = (BukkitCommandContexts) Anticheat.INSTANCE.getCommandManager()
|
||||
.getCommandContexts();
|
||||
|
||||
@@ -6,8 +6,10 @@ import dev.brighten.ac.data.handlers.BlockInformation;
|
||||
import dev.brighten.ac.data.handlers.GeneralInformation;
|
||||
import dev.brighten.ac.data.handlers.LagInformation;
|
||||
import dev.brighten.ac.data.handlers.MovementHandler;
|
||||
import dev.brighten.ac.data.obj.ActionStore;
|
||||
import dev.brighten.ac.data.obj.InstantAction;
|
||||
import dev.brighten.ac.data.obj.NormalAction;
|
||||
import dev.brighten.ac.data.obj.TimedActionStore;
|
||||
import dev.brighten.ac.handler.EntityLocationHandler;
|
||||
import dev.brighten.ac.handler.PotionHandler;
|
||||
import dev.brighten.ac.handler.block.BlockUpdateHandler;
|
||||
@@ -82,8 +84,8 @@ public class APlayer {
|
||||
private final List<Consumer<Vector>> onVelocityTasks = new ArrayList<>();
|
||||
public final EvictingList<Tuple<KLocation, Double>> pastLocations = new EvictingList<>(20);
|
||||
|
||||
private final Map<Class<?>, WAction<?>[]> events = new HashMap<>();
|
||||
private final Map<Class<?>, TimedWAction<?>[]> eventsWithTimestamp = new HashMap<>();
|
||||
private final Map<Class<?>, ActionStore[]> events = new HashMap<>();
|
||||
private final Map<Class<?>, TimedActionStore[]> eventsWithTimestamp = new HashMap<>();
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@@ -111,7 +113,7 @@ public class APlayer {
|
||||
|
||||
private void load() {
|
||||
synchronized (checks) {
|
||||
for (CheckStatic check : Anticheat.INSTANCE.getCheckManager().getCheckClasses()) {
|
||||
for (CheckStatic check : Anticheat.INSTANCE.getCheckManager().getCheckClasses().values()) {
|
||||
checks.add(check.playerInit(this));
|
||||
}
|
||||
}
|
||||
@@ -128,7 +130,7 @@ public class APlayer {
|
||||
playerVersion = ProtocolVersion.getVersion(ProtocolAPI.INSTANCE.getPlayerVersion(getBukkitPlayer()));
|
||||
|
||||
// Enabling checks for players on join
|
||||
for (CheckStatic checkClass : Anticheat.INSTANCE.getCheckManager().getCheckClasses()) {
|
||||
for (CheckStatic checkClass : Anticheat.INSTANCE.getCheckManager().getCheckClasses().values()) {
|
||||
CheckData data = checkClass.getCheckClass().getAnnotation(CheckData.class);
|
||||
|
||||
//Version checks
|
||||
@@ -141,31 +143,35 @@ public class APlayer {
|
||||
|
||||
Check check = checkClass.playerInit(this);
|
||||
|
||||
for (Tuple<WrappedField, Class<?>> tuple : checkClass.getActions()) {
|
||||
WAction<?> action = tuple.one.get(check);
|
||||
synchronized (events) {
|
||||
for (Tuple<WrappedField, Class<?>> tuple : checkClass.getActions()) {
|
||||
WAction<?> action = tuple.one.get(check);
|
||||
|
||||
events.compute(tuple.two, (packetClass, array) -> {
|
||||
if (array == null) {
|
||||
return new WAction<?>[]{action};
|
||||
} else {
|
||||
WAction<?>[] newArray = Arrays.copyOf(array, array.length + 1);
|
||||
newArray[array.length] = action;
|
||||
return newArray;
|
||||
}
|
||||
});
|
||||
events.compute(tuple.two, (packetClass, array) -> {
|
||||
if (array == null) {
|
||||
return new ActionStore[] {new ActionStore(action, checkClass.getCheckClass().getParent())};
|
||||
} else {
|
||||
ActionStore[] newArray = Arrays.copyOf(array, array.length + 1);
|
||||
newArray[array.length] = new ActionStore(action, checkClass.getCheckClass().getParent());
|
||||
return newArray;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
for (Tuple<WrappedField, Class<?>> tuple : checkClass.getTimedActions()) {
|
||||
TimedWAction<?> action = tuple.one.get(check);
|
||||
synchronized (eventsWithTimestamp) {
|
||||
for (Tuple<WrappedField, Class<?>> tuple : checkClass.getTimedActions()) {
|
||||
TimedWAction<?> action = tuple.one.get(check);
|
||||
|
||||
eventsWithTimestamp.compute(tuple.two, (packetClass, array) -> {
|
||||
if (array == null) {
|
||||
return new TimedWAction<?>[]{action};
|
||||
} else {
|
||||
TimedWAction<?>[] newArray = Arrays.copyOf(array, array.length + 1);
|
||||
newArray[array.length] = action;
|
||||
return newArray;
|
||||
}
|
||||
});
|
||||
eventsWithTimestamp.compute(tuple.two, (packetClass, array) -> {
|
||||
if (array == null) {
|
||||
return new TimedActionStore[] {new TimedActionStore(action, checkClass.getCheckClass().getParent())};
|
||||
} else {
|
||||
TimedActionStore[] newArray = Arrays.copyOf(array, array.length + 1);
|
||||
newArray[array.length] = new TimedActionStore(action, checkClass.getCheckClass().getParent());
|
||||
return newArray;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -187,11 +193,15 @@ public class APlayer {
|
||||
this.movement = null;
|
||||
}
|
||||
|
||||
public void disableCheck(String checkName) {
|
||||
|
||||
}
|
||||
|
||||
public void callEvent(Event event) {
|
||||
if(events.containsKey(event.getClass())) {
|
||||
WAction<Event>[] actions = (WAction<Event>[]) events.get(event.getClass());
|
||||
for (WAction<Event> action : actions) {
|
||||
action.invoke(event);
|
||||
ActionStore<Event>[] actions = (ActionStore<Event>[]) events.get(event.getClass());
|
||||
for (ActionStore<Event> action : actions) {
|
||||
action.getAction().invoke(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -199,15 +209,19 @@ public class APlayer {
|
||||
//TODO When using WPacket wrappers only, make this strictly WPacket param based only
|
||||
public void callPacket(Object packet, long timestamp) {
|
||||
if(events.containsKey(packet.getClass())) {
|
||||
WAction<Object>[] actions = (WAction<Object>[]) events.get(packet.getClass());
|
||||
for (WAction<Object> action : actions) {
|
||||
action.invoke(packet);
|
||||
synchronized (events) {
|
||||
ActionStore<Object>[] actions = events.get(packet.getClass());
|
||||
for (ActionStore<Object> action : actions) {
|
||||
action.getAction().invoke(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(eventsWithTimestamp.containsKey(packet.getClass())) {
|
||||
TimedWAction<Object>[] actions = (TimedWAction<Object>[]) eventsWithTimestamp.get(packet.getClass());
|
||||
for (TimedWAction<Object> action : actions) {
|
||||
action.invoke(packet, timestamp);
|
||||
synchronized (events) {
|
||||
TimedActionStore<Object>[] actions = eventsWithTimestamp.get(packet.getClass());
|
||||
for (TimedActionStore<Object> action : actions) {
|
||||
action.getAction().invoke(packet, timestamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package dev.brighten.ac.data.obj;
|
||||
|
||||
import dev.brighten.ac.check.Check;
|
||||
import dev.brighten.ac.check.WAction;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class ActionStore<T> {
|
||||
private final WAction<T> action;
|
||||
private final Class<? extends Check> checkClass;
|
||||
//To ensure duplicate actions are not added to the list
|
||||
private final UUID uuid = UUID.randomUUID();
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ActionStore that = (ActionStore) o;
|
||||
return uuid.equals(that.uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(uuid);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package dev.brighten.ac.data.obj;
|
||||
|
||||
import dev.brighten.ac.check.Check;
|
||||
import dev.brighten.ac.check.TimedWAction;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class TimedActionStore<T> {
|
||||
private final TimedWAction<T> action;
|
||||
private final Class<? extends Check> checkClass;
|
||||
//To ensure duplicate actions are not added to the list
|
||||
private final UUID uuid = UUID.randomUUID();
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
TimedActionStore that = (TimedActionStore) o;
|
||||
return uuid.equals(that.uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(uuid);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.brighten.ac.handler;
|
||||
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.wrapper.out.WPacketPlayOutEntityVelocity;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@@ -8,7 +9,7 @@ public class VelocityHandler {
|
||||
|
||||
private APlayer player;
|
||||
|
||||
public void onPre( packet) {
|
||||
public void onPre(WPacketPlayOutEntityVelocity packet) {
|
||||
if(packet.getEntityId() != player.getBukkitPlayer().getEntityId()) return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class JoinListener implements Listener {
|
||||
case BLOCK_CHANGE:
|
||||
case MULTI_BLOCK_CHANGE:
|
||||
case MAP_CHUNK: {
|
||||
if(player.getLagInfo().getLastClientTransaction().isPassed(100L)) {
|
||||
if(player.getLagInfo().getLastClientTransaction().isPassed(100L) && player.getCreation().isPassed(2000L)) {
|
||||
synchronized (player.getPacketQueue()) {
|
||||
player.getPacketQueue().add(event.getPacket());
|
||||
}
|
||||
@@ -78,7 +78,10 @@ public class JoinListener implements Listener {
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
APlayer player = Anticheat.INSTANCE.getPlayerRegistry().generate(event.getPlayer());
|
||||
|
||||
RunUtils.taskLater(() -> HandlerAbstract.getHandler().add(event.getPlayer()), 6);
|
||||
RunUtils.taskLater(() -> {
|
||||
if(event.getPlayer() != null && event.getPlayer().isOnline())
|
||||
HandlerAbstract.getHandler().add(event.getPlayer());
|
||||
}, 6);
|
||||
|
||||
player.callEvent(event);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user