Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
addb077133 | ||
|
|
1fcbd33a62 | ||
|
|
be88498fe5 | ||
|
|
9b14df0881 | ||
|
|
11b2c3ff41 | ||
|
|
b842426448 | ||
|
|
3f789ecd25 |
No files matched your search
@@ -204,7 +204,7 @@ jobs:
|
||||
purpur
|
||||
|
||||
game-versions: |
|
||||
>=1.16.5
|
||||
>=1.14.4
|
||||
|
||||
retry-attempts: 2
|
||||
retry-delay: 10000
|
||||
|
||||
@@ -29,7 +29,7 @@ tasks.named<JavaCompile>("compileTestJava") {
|
||||
dependencies {
|
||||
implementation(project(":common"))
|
||||
|
||||
compileOnly("org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT")
|
||||
compileOnly("org.spigotmc:spigot-api:1.14.4-R0.1-SNAPSHOT")
|
||||
compileOnly("org.geysermc.floodgate:api:2.0-SNAPSHOT")
|
||||
|
||||
compileOnly("org.projectlombok:lombok:1.18.34")
|
||||
@@ -42,6 +42,9 @@ dependencies {
|
||||
// shadeThisThing(implementation("net.kyori:adventure-platform-bukkit:4.3.4")!!)
|
||||
shadeThisThing(implementation("org.incendo:cloud-paper:2.0.0-beta.10")!!)
|
||||
shadeThisThing(implementation("org.incendo:cloud-core:2.0.0")!!)
|
||||
|
||||
// Required for 1.14.4 support because gson is too old to have JosnParser.parseString()
|
||||
shadeThisThing(implementation("com.google.code.gson:gson:2.11.0")!!)
|
||||
}
|
||||
|
||||
tasks.withType<ShadowJar> {
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package me.caseload.knockbacksync.player;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.PacketEventsAPI;
|
||||
import com.github.retrooper.packetevents.util.Vector3d;
|
||||
import me.caseload.knockbacksync.world.PlatformWorld;
|
||||
import me.caseload.knockbacksync.world.SpigotWorld;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -10,11 +13,34 @@ import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BukkitPlayer implements PlatformPlayer {
|
||||
public final Player bukkitPlayer;
|
||||
|
||||
// Reflection variables
|
||||
private static Class<?> craftPlayerClass;
|
||||
private static Method getHandleMethod;
|
||||
private static Method getAttackStrengthScaleMethod;
|
||||
|
||||
static {
|
||||
try {
|
||||
String bukkitversion = Bukkit.getServer().getClass().getPackage()
|
||||
.getName();
|
||||
// Step 1: Load the CraftPlayer class
|
||||
craftPlayerClass = Class.forName(bukkitversion + ".entity.CraftPlayer");
|
||||
// Step 2: Get the getHandle method
|
||||
getHandleMethod = craftPlayerClass.getMethod("getHandle");
|
||||
// Step 3: Get the getAttackStrengthScale method from the EntityPlayer class
|
||||
Class<?> entityPlayerClass = Class.forName("net.minecraft.server." + bukkitversion + ".EntityPlayer");
|
||||
getAttackStrengthScaleMethod = entityPlayerClass.getDeclaredMethod("getAttackStrengthScale", float.class);
|
||||
getAttackStrengthScaleMethod.setAccessible(true);
|
||||
} catch (ClassNotFoundException | NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public BukkitPlayer(Player player) {
|
||||
this.bukkitPlayer = player;
|
||||
}
|
||||
@@ -67,7 +93,7 @@ public class BukkitPlayer implements PlatformPlayer {
|
||||
|
||||
@Override
|
||||
public int getPing() {
|
||||
return bukkitPlayer.getPing();
|
||||
return PacketEvents.getAPI().getPlayerManager().getPing(bukkitPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -93,7 +119,17 @@ public class BukkitPlayer implements PlatformPlayer {
|
||||
|
||||
@Override
|
||||
public double getAttackCooldown() {
|
||||
return bukkitPlayer.getAttackCooldown();
|
||||
try {
|
||||
// Step 1: Get the CraftPlayer instance
|
||||
Object craftPlayer = craftPlayerClass.cast(bukkitPlayer);
|
||||
// Step 2: Get the handle (NMS EntityPlayer)
|
||||
Object entityPlayer = getHandleMethod.invoke(craftPlayer);
|
||||
// Step 3: Invoke the getAttackStrengthScale method
|
||||
return (float) getAttackStrengthScaleMethod.invoke(entityPlayer, 0.5f);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return -1; // Return -1 if an error occurs
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
name: KnockbackSync
|
||||
version: ${version}
|
||||
main: me.caseload.knockbacksync.KBSyncBukkitLoaderPlugin
|
||||
api-version: '1.16'
|
||||
api-version: '1.14'
|
||||
authors: [ Caseload ]
|
||||
description: Synchronizes player knockback for smoother gameplay.
|
||||
folia-supported: true
|
||||
|
||||
@@ -24,38 +24,6 @@ dependencies {
|
||||
exclude(group = "org.apache.commons", module = "commons-lang3")
|
||||
}
|
||||
|
||||
api("net.kyori:adventure-api:4.11.0") {
|
||||
exclude(module = "adventure-bom")
|
||||
exclude(module = "checker-qual")
|
||||
exclude(module = "annotations")
|
||||
}
|
||||
|
||||
api("net.kyori:adventure-text-serializer-gson:4.11.0") {
|
||||
exclude(module = "adventure-bom")
|
||||
exclude(module = "adventure-api")
|
||||
exclude(module = "gson")
|
||||
}
|
||||
|
||||
api("net.kyori:adventure-text-serializer-legacy:4.11.0") {
|
||||
exclude(module = "adventure-bom")
|
||||
exclude(module = "adventure-api")
|
||||
}
|
||||
|
||||
api("net.kyori:adventure-text-serializer-plain:4.11.0") {
|
||||
exclude(module = "adventure-bom")
|
||||
exclude(module = "adventure-api")
|
||||
}
|
||||
|
||||
api("net.kyori:adventure-text-minimessage:4.11.0") {
|
||||
exclude(module = "adventure-bom")
|
||||
exclude(module = "adventure-api")
|
||||
}
|
||||
|
||||
api("net.kyori:event-api:3.0.0") {
|
||||
exclude(module = "checker-qual")
|
||||
exclude(module = "guava")
|
||||
}
|
||||
|
||||
implementation("org.incendo:cloud-core:2.0.0")
|
||||
implementation("org.incendo:cloud-minecraft-extras:2.0.0-beta.10")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user