Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d31816ede | ||
|
|
ff35ca78dd |
No files matched your search
@@ -40,9 +40,9 @@ dependencies {
|
||||
|
||||
shadeThisThing(implementation("org.kohsuke:github-api:1.326")!!)
|
||||
if (shadePE) {
|
||||
shadeThisThing(implementation("com.github.retrooper:packetevents-spigot:2.11.2")!!)
|
||||
shadeThisThing(implementation("com.github.retrooper:packetevents-spigot:2.11.1+60a2c34-SNAPSHOT")!!)
|
||||
} else {
|
||||
compileOnly("com.github.retrooper:packetevents-spigot:2.11.2")
|
||||
compileOnly("com.github.retrooper:packetevents-spigot:2.11.1+60a2c34-SNAPSHOT")
|
||||
}
|
||||
shadeThisThing(implementation("org.incendo:cloud-paper:2.0.0-beta.14")!!)
|
||||
shadeThisThing(implementation("org.incendo:cloud-core:2.0.0")!!)
|
||||
|
||||
@@ -232,4 +232,19 @@ public class BukkitPlayer implements PlatformPlayer {
|
||||
public String getClientBrand() {
|
||||
return this.clientBrand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFlying() {
|
||||
return bukkitPlayer.isFlying();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getSpeed() {
|
||||
return bukkitPlayer.getWalkSpeed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFlyingSpeed() {
|
||||
return bukkitPlayer.getFlySpeed();
|
||||
}
|
||||
}
|
||||
-3
@@ -11,9 +11,6 @@ import me.caseload.knockbacksync.player.PlatformPlayer;
|
||||
import me.caseload.knockbacksync.player.PlayerData;
|
||||
import me.caseload.knockbacksync.util.ChatUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PacketPlayerJoinQuit extends PacketListenerAbstract {
|
||||
@Override
|
||||
|
||||
@@ -7,6 +7,7 @@ import me.caseload.knockbacksync.Base;
|
||||
import me.caseload.knockbacksync.Platform;
|
||||
import me.caseload.knockbacksync.config.YamlConfiguration;
|
||||
import me.caseload.knockbacksync.runnable.PingRunnable;
|
||||
import me.caseload.knockbacksync.runnable.TickRunnable;
|
||||
import me.caseload.knockbacksync.scheduler.AbstractTaskHandle;
|
||||
|
||||
import java.io.File;
|
||||
@@ -39,6 +40,7 @@ public class ConfigManager {
|
||||
private String playerDisconnectedWhileExecutingCommand;
|
||||
|
||||
private AbstractTaskHandle pingTask;
|
||||
private AbstractTaskHandle tickTask;
|
||||
|
||||
private Map<String, Object> config;
|
||||
private File configFile;
|
||||
@@ -114,6 +116,8 @@ public class ConfigManager {
|
||||
pingTask = Base.INSTANCE.getScheduler().runTaskTimerAsynchronously(new PingRunnable(), initialDelay, pingTaskRunnableInterval);
|
||||
}
|
||||
|
||||
tickTask = Base.INSTANCE.getScheduler().runTaskTimer(new TickRunnable(), 0L, 1L);
|
||||
|
||||
notifyUpdate = configWrapper.getBoolean("notify_updates", true);
|
||||
autoUpdate = configWrapper.getBoolean("auto_update", true);
|
||||
combatTimer = configWrapper.getLong("runnable.timer", 30L);
|
||||
|
||||
@@ -63,4 +63,10 @@ public interface PlatformPlayer {
|
||||
|
||||
String getClientBrand();
|
||||
// Add more methods as needed
|
||||
|
||||
boolean isFlying();
|
||||
|
||||
float getSpeed();
|
||||
|
||||
float getFlyingSpeed();
|
||||
}
|
||||
@@ -88,11 +88,14 @@ public class PlayerData {
|
||||
@Setter private double knockbackResistanceAttribute = 0.0;
|
||||
public PingStrategy pingStrategy; // this is currently shared between all instances, but can be made per-player later
|
||||
|
||||
@Getter private final SimulatedPlayer simulatedPlayer;
|
||||
|
||||
public PlayerData(User user, PlatformPlayer platformPlayer) {
|
||||
this.uuid = platformPlayer.getUUID();
|
||||
this.user = user;
|
||||
this.platformPlayer = platformPlayer;
|
||||
this.pingStrategy = loadPingStrategy(Base.INSTANCE.getConfigManager());
|
||||
this.simulatedPlayer = new SimulatedPlayer(this);
|
||||
}
|
||||
|
||||
public double getNotNullPing() {
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package me.caseload.knockbacksync.player;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.potion.PotionEffect;
|
||||
import com.github.retrooper.packetevents.protocol.world.BoundingBox;
|
||||
import com.github.retrooper.packetevents.util.Vector3d;
|
||||
import com.github.retrooper.packetevents.util.Vector3i;
|
||||
import lombok.Getter;
|
||||
import me.caseload.knockbacksync.Base;
|
||||
import me.caseload.knockbacksync.util.data.Vec2d;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public final class SimulatedPlayer {
|
||||
|
||||
private final PlayerData playerData;
|
||||
private final PlatformPlayer platformPlayer;
|
||||
private Vec2d position;
|
||||
@Getter private double yCoordinate;
|
||||
@Getter private double verticalVelocity;
|
||||
@Getter private BoundingBox boundingBox;
|
||||
@Getter private boolean isOnGround;
|
||||
|
||||
public SimulatedPlayer(PlayerData playerData) {
|
||||
this.playerData = playerData;
|
||||
this.platformPlayer = playerData.getPlatformPlayer();
|
||||
this.position = new Vec2d(platformPlayer.getX(), platformPlayer.getZ());
|
||||
this.yCoordinate = platformPlayer.getY();
|
||||
this.verticalVelocity = platformPlayer.getVelocity().y;
|
||||
this.boundingBox = platformPlayer.getBoundingBox();
|
||||
this.isOnGround = platformPlayer.isOnGround(); // not safe but its only for a single tick
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
Vector3d location = playerData.getPlatformPlayer().getLocation();
|
||||
Vec2d newPosition = new Vec2d(location.x, location.z);
|
||||
|
||||
if (!position.equals(newPosition)) {
|
||||
double dx = newPosition.x - position.x;
|
||||
double dz = newPosition.z - position.z;
|
||||
boundingBox.shift(dx, 0, dz);
|
||||
position = newPosition;
|
||||
}
|
||||
|
||||
if (platformPlayer.isFlying() || platformPlayer.isGliding()) {
|
||||
double newY = platformPlayer.getY();
|
||||
double shiftY = newY - yCoordinate;
|
||||
boundingBox.shift(0, shiftY, 0);
|
||||
yCoordinate = newY;
|
||||
verticalVelocity = platformPlayer.getVelocity().getY();
|
||||
return;
|
||||
}
|
||||
|
||||
verticalVelocity += playerData.getGravityAttribute();
|
||||
verticalVelocity = Math.min(verticalVelocity, 3.92);
|
||||
verticalVelocity *= 0.98;
|
||||
|
||||
double newY = yCoordinate -= verticalVelocity;
|
||||
double shiftY = newY - yCoordinate;
|
||||
boundingBox.shift(0, shiftY, 0);
|
||||
yCoordinate = newY;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package me.caseload.knockbacksync.runnable;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
import me.caseload.knockbacksync.Base;
|
||||
import me.caseload.knockbacksync.manager.PlayerDataManager;
|
||||
import me.caseload.knockbacksync.player.PlatformPlayer;
|
||||
import me.caseload.knockbacksync.player.PlayerData;
|
||||
import me.caseload.knockbacksync.player.SimulatedPlayer;
|
||||
|
||||
public class TickRunnable implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!Base.INSTANCE.getConfigManager().isToggled())
|
||||
return;
|
||||
|
||||
for (PlatformPlayer player : Base.INSTANCE.getPlatformServer().getOnlinePlayers()) {
|
||||
User user = player.getUser();
|
||||
if (user == null)
|
||||
continue;
|
||||
|
||||
PlayerData playerData = PlayerDataManager.getPlayerData(user);
|
||||
if (playerData == null)
|
||||
continue;
|
||||
|
||||
SimulatedPlayer simulatedPlayer = playerData.getSimulatedPlayer();
|
||||
if (simulatedPlayer == null)
|
||||
continue;
|
||||
|
||||
simulatedPlayer.tick();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package me.caseload.knockbacksync.util.data;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public final class Vec2d {
|
||||
|
||||
public final double x;
|
||||
public final double z;
|
||||
|
||||
public Vec2d(double x, double z) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (this == object)
|
||||
return true;
|
||||
|
||||
if (!(object instanceof Vec2d))
|
||||
return false;
|
||||
|
||||
Vec2d v = (Vec2d) object;
|
||||
return Double.compare(v.x, x) == 0 && Double.compare(v.z, z) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Vec2d(" + x + ", " + z + ")";
|
||||
}
|
||||
}
|
||||
@@ -171,4 +171,19 @@ public class FabricPlayer implements PlatformPlayer {
|
||||
public String getClientBrand() {
|
||||
return this.clientBrand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFlying() {
|
||||
return this.fabricPlayer.getAbilities().flying;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getSpeed() {
|
||||
return this.fabricPlayer.getAbilities().getWalkSpeed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFlyingSpeed() {
|
||||
return this.fabricPlayer.getAbilities().getFlySpeed();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user