Add TPSWarpUtils #245
@ -22,6 +22,7 @@ package de.steamwar.core;
|
||||
import com.comphenix.tinyprotocol.Reflection;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.SystemUtils;
|
||||
import net.minecraft.network.protocol.game.ClientboundPlayerInfoRemovePacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket;
|
||||
import net.minecraft.world.level.EnumGamemode;
|
||||
@ -30,6 +31,7 @@ import org.bukkit.GameMode;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.function.LongSupplier;
|
||||
|
||||
public class ProtocolWrapper19 implements ProtocolWrapper {
|
||||
|
||||
@ -54,4 +56,9 @@ public class ProtocolWrapper19 implements ProtocolWrapper {
|
||||
updatePlayers.set(packet, Collections.singletonList(new ClientboundPlayerInfoUpdatePacket.b(profile.getId(), profile, false, 0, EnumGamemode.a(mode.getValue()), null, null)));
|
||||
return packet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initTPSWarp(LongSupplier longSupplier) {
|
||||
SystemUtils.a = () -> System.nanoTime() + longSupplier.getAsLong();
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ import com.comphenix.tinyprotocol.Reflection;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import org.bukkit.GameMode;
|
||||
|
||||
import java.util.function.LongSupplier;
|
||||
|
||||
public interface ProtocolWrapper {
|
||||
|
||||
Class<?> itemStack = Reflection.getClass("{nms.world.item}.ItemStack");
|
||||
@ -42,6 +44,9 @@ public interface ProtocolWrapper {
|
||||
|
||||
Object playerInfoPacketConstructor(PlayerInfoAction action, GameProfile profile, GameMode mode);
|
||||
|
||||
default void initTPSWarp(LongSupplier longSupplier) {
|
||||
}
|
||||
|
||||
enum PlayerInfoAction {
|
||||
ADD,
|
||||
GAMEMODE,
|
||||
|
@ -35,9 +35,13 @@ public class TPSWarpUtils {
|
||||
private static BukkitTask bukkitTask = null;
|
||||
|
||||
static {
|
||||
Class clazz = Reflection.getClass(Core.getVersion() <= 15 ? "{nms}.SystemUtils" : "net.minecraft.SystemUtils");
|
||||
Reflection.FieldAccessor<LongSupplier> fieldAccessor = Reflection.getField(clazz, LongSupplier.class, 0);
|
||||
fieldAccessor.set(clazz, (LongSupplier) () -> System.nanoTime() + nanoDOffset);
|
||||
if (Core.getVersion() <= 18) {
|
||||
Class clazz = Reflection.getClass("{nms}.SystemUtils");
|
||||
Reflection.FieldAccessor fieldAccessor = Reflection.getField(clazz, LongSupplier.class, 0);
|
||||
fieldAccessor.set(clazz, (LongSupplier) () -> System.nanoTime() + nanoDOffset);
|
||||
} else {
|
||||
ProtocolWrapper.impl.initTPSWarp(() -> nanoDOffset);
|
||||
}
|
||||
}
|
||||
|
||||
public static void warp(double tps) {
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren