12
0

Add TPSWarpUtils
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2023-10-10 18:07:21 +02:00
Ursprung 019a3ba2a6
Commit e202adeb86
3 geänderte Dateien mit 19 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -22,6 +22,7 @@ package de.steamwar.core;
import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.Reflection;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.util.Pair;
import net.minecraft.SystemUtils;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoRemovePacket; import net.minecraft.network.protocol.game.ClientboundPlayerInfoRemovePacket;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket; import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket;
import net.minecraft.world.level.EnumGamemode; import net.minecraft.world.level.EnumGamemode;
@ -30,6 +31,7 @@ import org.bukkit.GameMode;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.function.LongSupplier;
public class ProtocolWrapper19 implements ProtocolWrapper { 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))); updatePlayers.set(packet, Collections.singletonList(new ClientboundPlayerInfoUpdatePacket.b(profile.getId(), profile, false, 0, EnumGamemode.a(mode.getValue()), null, null)));
return packet; return packet;
} }
@Override
public void initTPSWarp(LongSupplier longSupplier) {
SystemUtils.a = () -> System.nanoTime() + longSupplier.getAsLong();
}
} }

Datei anzeigen

@ -23,6 +23,8 @@ import com.comphenix.tinyprotocol.Reflection;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import java.util.function.LongSupplier;
public interface ProtocolWrapper { public interface ProtocolWrapper {
Class<?> itemStack = Reflection.getClass("{nms.world.item}.ItemStack"); Class<?> itemStack = Reflection.getClass("{nms.world.item}.ItemStack");
@ -42,6 +44,9 @@ public interface ProtocolWrapper {
Object playerInfoPacketConstructor(PlayerInfoAction action, GameProfile profile, GameMode mode); Object playerInfoPacketConstructor(PlayerInfoAction action, GameProfile profile, GameMode mode);
default void initTPSWarp(LongSupplier longSupplier) {
}
enum PlayerInfoAction { enum PlayerInfoAction {
ADD, ADD,
GAMEMODE, GAMEMODE,

Datei anzeigen

@ -35,9 +35,13 @@ public class TPSWarpUtils {
private static BukkitTask bukkitTask = null; private static BukkitTask bukkitTask = null;
static { static {
Class clazz = Reflection.getClass(Core.getVersion() <= 15 ? "{nms}.SystemUtils" : "net.minecraft.SystemUtils"); if (Core.getVersion() <= 18) {
Reflection.FieldAccessor<LongSupplier> fieldAccessor = Reflection.getField(clazz, LongSupplier.class, 0); Class clazz = Reflection.getClass("{nms}.SystemUtils");
fieldAccessor.set(clazz, (LongSupplier) () -> System.nanoTime() + nanoDOffset); 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) { public static void warp(double tps) {