mirror of
https://github.com/funkemunky/KauriV3.git
synced 2026-07-01 02:08:27 +00:00
New bug fixes and code features
- Fixed WPacketPlayOutMultiBlockChange bug where the x and z where incorrect. I didn't shift the value based on the chunk location like the vanilla packet does. - Added BukkitRunnable which passes through the BukkitTask so tasks can be cancelled when using RunUtils, without having to use the Bukkit implementation instead. - Fixed signs returning as collidable blocks in Materials, causing false positives. - Fixed NullPointerException in the CHEST wrapper enum inside BlockData. Needed to use the BlockUtils#getRelative method instead, incase the APlayer object pass-through was null. - Optimized Horizontal a bit more, reducing iterations.
This commit is contained in:
@@ -245,7 +245,7 @@ public class Anticheat extends LoaderPlugin {
|
||||
lastTickLag = new TickTimer();
|
||||
AtomicInteger ticks = new AtomicInteger();
|
||||
AtomicLong lastTimeStamp = new AtomicLong(0);
|
||||
RunUtils.taskTimer(() -> {
|
||||
RunUtils.taskTimer(task -> {
|
||||
ticks.getAndIncrement();
|
||||
currentTick++;
|
||||
long currentTime = System.currentTimeMillis();
|
||||
|
||||
@@ -525,11 +525,11 @@ public class Horizontal extends Check {
|
||||
MathHelper.floor_double(lastUnderBlockLoc.z))).getType();
|
||||
for (int f = -1; f < 2; f++) {
|
||||
for (int s = -1; s < 2; s++) {
|
||||
for (boolean sprinting : getSprintIteration(f)) {
|
||||
for (boolean sneaking : getSneakingIteration()) {
|
||||
for (boolean sprinting : getSprintIteration(f, sneaking)) {
|
||||
for (int fastMath = 0; fastMath <= 2; fastMath++) {
|
||||
for (boolean attack : TRUE_FALSE) {
|
||||
for (boolean using : TRUE_FALSE) {
|
||||
for (boolean sneaking : getSneakingIteration()) {
|
||||
for (boolean jumped : getJumpingIteration(player.getMovement().getFrom().isOnGround())) {
|
||||
iterations.add(new Iteration(underMaterial, lastUnderMaterial, f, s,
|
||||
fastMath, sprinting, attack, using, sneaking, jumped));
|
||||
@@ -553,8 +553,8 @@ public class Horizontal extends Check {
|
||||
public boolean sprinting, attack, using, sneaking, jumped;
|
||||
}
|
||||
|
||||
private static boolean[] getSprintIteration(int f) {
|
||||
if(f > 0) {
|
||||
private static boolean[] getSprintIteration(int f, boolean sneaking) {
|
||||
if(f > 0 && !sneaking) {
|
||||
return new boolean[] {true, false};
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public class BlockUpdateHandler {
|
||||
/**
|
||||
* Keep track of block placements since the Bukkit API will be a bit behind
|
||||
*
|
||||
* @param place
|
||||
* @param place wrapped PacketPlayInBlockPlace
|
||||
*/
|
||||
public void onPlace(WPacketPlayInBlockPlace place) {
|
||||
player.getInfo().lastBlockUpdate.reset();
|
||||
@@ -70,7 +70,7 @@ public class BlockUpdateHandler {
|
||||
/**
|
||||
* Keep track of block breaking since the Bukkit API will be a bit behind.
|
||||
*
|
||||
* @param dig
|
||||
* @param dig Wrapped PacketPlayInBlockDig
|
||||
*/
|
||||
public void onDig(WPacketPlayInBlockDig dig) {
|
||||
player.getInfo().lastBlockUpdate.reset();
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.google.common.cache.CacheBuilder;
|
||||
import dev.brighten.ac.Anticheat;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.handler.HandlerAbstract;
|
||||
import dev.brighten.ac.utils.BukkitRunnable;
|
||||
import dev.brighten.ac.utils.RunUtils;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
|
||||
@@ -15,7 +16,7 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class KeepaliveProcessor implements Runnable {
|
||||
public class KeepaliveProcessor implements BukkitRunnable {
|
||||
|
||||
private BukkitTask task;
|
||||
|
||||
@@ -32,7 +33,7 @@ public class KeepaliveProcessor implements Runnable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
public void run(BukkitTask task) {
|
||||
tick++;
|
||||
synchronized (keepAlives) {
|
||||
short id = (short) (tick > Short.MAX_VALUE ? tick % Short.MAX_VALUE : tick);
|
||||
|
||||
@@ -100,10 +100,17 @@ public class JoinListener implements Listener {
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
APlayer player = Anticheat.INSTANCE.getPlayerRegistry().generate(event.getPlayer());
|
||||
|
||||
RunUtils.taskLater(() -> {
|
||||
if(event.getPlayer() != null && event.getPlayer().isOnline())
|
||||
HandlerAbstract.getHandler().add(event.getPlayer());
|
||||
}, 6);
|
||||
RunUtils.taskTimer(task -> {
|
||||
if(Anticheat.INSTANCE.getPlayerRegistry().aplayerMap.containsKey(event.getPlayer().getUniqueId().hashCode())) {
|
||||
if(task != null
|
||||
&& Anticheat.INSTANCE.getPlayerRegistry().aplayerMap
|
||||
.containsKey(event.getPlayer().getUniqueId().hashCode())
|
||||
&& event.getPlayer() != null && event.getPlayer().isOnline()) {
|
||||
HandlerAbstract.getHandler().add(event.getPlayer());
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
}, 6, 1);
|
||||
|
||||
player.getCheckHandler().callEvent(event);
|
||||
}
|
||||
|
||||
@@ -403,7 +403,8 @@ public class Processor_18 implements PacketConverter {
|
||||
for (int i = 0; i < blockChanges.length; i++) {
|
||||
short encodedloc = serial.readShort();
|
||||
|
||||
IntVector loc = new IntVector(encodedloc >> 12 & 15, encodedloc & 255, encodedloc >> 8 & 15);
|
||||
IntVector loc = new IntVector((chunkLoc[0] << 4) + (encodedloc >> 12 & 15),
|
||||
encodedloc & 255, (chunkLoc[1] << 4) + (encodedloc >> 8 & 15));
|
||||
IBlockData blockData = Block.d.a(serial.e());
|
||||
Material blockType = CraftMagicNumbers.getMaterial(blockData.getBlock());
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package dev.brighten.ac.utils;
|
||||
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface BukkitRunnable {
|
||||
void run(BukkitTask task);
|
||||
}
|
||||
@@ -56,6 +56,8 @@ public class Materials {
|
||||
if(mat.name().contains("BED") && !mat.name().contains("ROCK")) MATERIAL_FLAGS[mat.ordinal()] |= SLABS;
|
||||
if(mat.name().contains("ICE")) MATERIAL_FLAGS[mat.ordinal()] |= ICE;
|
||||
if(mat.name().contains("CARPET")) MATERIAL_FLAGS[mat.ordinal()] |= SOLID;
|
||||
//Signs get set as collidable when they shouldn't
|
||||
if(mat.name().contains("SIGN")) MATERIAL_FLAGS[mat.ordinal()] = 0;
|
||||
}
|
||||
|
||||
// fix some types where isSolid() returns the wrong value
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.bukkit.scheduler.BukkitTask;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/*
|
||||
@@ -15,12 +16,22 @@ import java.util.function.Consumer;
|
||||
*/
|
||||
public class RunUtils {
|
||||
|
||||
public static BukkitTask taskTimer(Runnable runnable, long delay, long interval) {
|
||||
return Bukkit.getScheduler().runTaskTimer(Anticheat.INSTANCE.getPluginInstance(), runnable, delay, interval);
|
||||
public static BukkitTask taskTimer(BukkitRunnable runnable, long delay, long interval) {
|
||||
AtomicReference<BukkitTask> task = new AtomicReference<>(null);
|
||||
|
||||
task.set(Bukkit.getScheduler().runTaskTimer(Anticheat.INSTANCE.getPluginInstance(),
|
||||
() -> runnable.run(task.get()), delay, interval));
|
||||
|
||||
return task.get();
|
||||
}
|
||||
|
||||
public static BukkitTask taskTimerAsync(Runnable runnable, long delay, long interval) {
|
||||
return Bukkit.getScheduler().runTaskTimerAsynchronously(Anticheat.INSTANCE.getPluginInstance(), runnable, delay, interval);
|
||||
public static BukkitTask taskTimerAsync(BukkitRunnable runnable, long delay, long interval) {
|
||||
AtomicReference<BukkitTask> task = new AtomicReference<>(null);
|
||||
|
||||
task.set(Bukkit.getScheduler().runTaskTimerAsynchronously(Anticheat.INSTANCE.getPluginInstance(),
|
||||
() -> runnable.run(task.get()), delay, interval));
|
||||
|
||||
return task.get();
|
||||
}
|
||||
|
||||
public static BukkitTask task(Runnable runnable) {
|
||||
|
||||
@@ -37,7 +37,7 @@ public class UpdatingButton extends Button {
|
||||
public void startUpdate() {
|
||||
if(updateTask != null) return;
|
||||
|
||||
updateTask = RunUtils.taskTimer(() -> {
|
||||
updateTask = RunUtils.taskTimer(task -> {
|
||||
if(menu == null) {
|
||||
updateTask.cancel();
|
||||
updateTask = null;
|
||||
|
||||
@@ -172,20 +172,24 @@ public enum BlockData {
|
||||
.toArray(Material[]::new)),
|
||||
|
||||
_CHEST((protocol, player, b) -> {
|
||||
if (player.getBlockUpdateHandler().getRelative(new IntVector(b.getLocation()), BlockFace.NORTH)
|
||||
.getType().name().contains("CHEST")) {
|
||||
if(BlockUtils.getRelative(player, b.getLocation(), BlockFace.NORTH)
|
||||
.map(block -> block.getType().name().contains("CHEST"))
|
||||
.orElse(false)) {
|
||||
return new SimpleCollisionBox(0.0625F, 0.0F, 0.0F,
|
||||
0.9375F, 0.875F, 0.9375F);
|
||||
} else if (player.getBlockUpdateHandler().getRelative(new IntVector(b.getLocation()), BlockFace.SOUTH)
|
||||
.getType().name().contains("CHEST")) {
|
||||
} else if(BlockUtils.getRelative(player, b.getLocation(), BlockFace.SOUTH)
|
||||
.map(block -> block.getType().name().contains("CHEST"))
|
||||
.orElse(false)) {
|
||||
return new SimpleCollisionBox(0.0625F, 0.0F, 0.0625F,
|
||||
0.9375F, 0.875F, 1.0F);
|
||||
} else if (player.getBlockUpdateHandler().getRelative(new IntVector(b.getLocation()), BlockFace.WEST)
|
||||
.getType().name().contains("CHEST")) {
|
||||
} else if(BlockUtils.getRelative(player, b.getLocation(), BlockFace.WEST)
|
||||
.map(block -> block.getType().name().contains("CHEST"))
|
||||
.orElse(false)) {
|
||||
return new SimpleCollisionBox(0.0F, 0.0F, 0.0625F,
|
||||
0.9375F, 0.875F, 0.9375F);
|
||||
} else if (player.getBlockUpdateHandler().getRelative(new IntVector(b.getLocation()), BlockFace.EAST)
|
||||
.getType().name().contains("CHEST")) {
|
||||
} else if(BlockUtils.getRelative(player, b.getLocation(), BlockFace.EAST)
|
||||
.map(block -> block.getType().name().contains("CHEST"))
|
||||
.orElse(false)) {
|
||||
return new SimpleCollisionBox(0.0625F, 0.0F, 0.0625F,
|
||||
1.0F, 0.875F, 0.9375F);
|
||||
} else {
|
||||
|
||||
@@ -27,7 +27,7 @@ public class WorldInfo {
|
||||
|
||||
public WorldInfo(World world) {
|
||||
this.worldId = world.getUID();
|
||||
task = RunUtils.taskTimer(() -> {
|
||||
task = RunUtils.taskTimer(task -> {
|
||||
synchronized (entityMap) {
|
||||
entityMap.clear();
|
||||
for (Entity entity : world.getEntities()) {
|
||||
|
||||
Reference in New Issue
Block a user