forked from SteamWar/SteamWar
Remove more Reflection stuff
This commit is contained in:
@@ -21,7 +21,6 @@ package de.steamwar.fightsystem.utils;
|
|||||||
|
|
||||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||||
import de.steamwar.Reflection;
|
import de.steamwar.Reflection;
|
||||||
import de.steamwar.core.Core;
|
|
||||||
import de.steamwar.entity.REntity;
|
import de.steamwar.entity.REntity;
|
||||||
import de.steamwar.fightsystem.Config;
|
import de.steamwar.fightsystem.Config;
|
||||||
import de.steamwar.fightsystem.fight.Fight;
|
import de.steamwar.fightsystem.fight.Fight;
|
||||||
@@ -37,6 +36,8 @@ import lombok.Getter;
|
|||||||
import net.minecraft.core.Vec3i;
|
import net.minecraft.core.Vec3i;
|
||||||
import net.minecraft.network.protocol.game.ClientboundExplodePacket;
|
import net.minecraft.network.protocol.game.ClientboundExplodePacket;
|
||||||
import net.minecraft.network.protocol.game.ClientboundLevelEventPacket;
|
import net.minecraft.network.protocol.game.ClientboundLevelEventPacket;
|
||||||
|
import net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket;
|
||||||
|
import net.minecraft.network.protocol.game.ClientboundSoundPacket;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -76,10 +77,8 @@ public class HullHider implements Listener {
|
|||||||
|
|
||||||
packetHiders.put(packetPlayOutWorldEvent, this::worldEventHider);
|
packetHiders.put(packetPlayOutWorldEvent, this::worldEventHider);
|
||||||
packetHiders.put(packetPlayOutExplosion, this::explosionHider);
|
packetHiders.put(packetPlayOutExplosion, this::explosionHider);
|
||||||
posHiderGenerator("net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket", Core.getVersion() >= 18 ? double.class : float.class, 1.0);
|
posHiderGenerator(ClientboundLevelParticlesPacket.class, double.class, 1.0);
|
||||||
posHiderGenerator("net.minecraft.network.protocol.game.ClientboundSoundPacket", int.class, 8.0);
|
posHiderGenerator(ClientboundSoundPacket.class, int.class, 8.0);
|
||||||
if(Core.getVersion() >= 9 && Core.getVersion() < 18)
|
|
||||||
posHiderGenerator("net.minecraft.network.protocol.game.PacketPlayOutCustomSoundEffect", int.class, 8.0);
|
|
||||||
|
|
||||||
new StateDependentListener(TechHiderWrapper.ENABLED, FightState.Schem, this);
|
new StateDependentListener(TechHiderWrapper.ENABLED, FightState.Schem, this);
|
||||||
new StateDependent(TechHiderWrapper.ENABLED, FightState.Schem) {
|
new StateDependent(TechHiderWrapper.ENABLED, FightState.Schem) {
|
||||||
@@ -215,8 +214,7 @@ public class HullHider implements Listener {
|
|||||||
return ReflectionWrapper.impl.explosionHider(player, packet, this::packetHider);
|
return ReflectionWrapper.impl.explosionHider(player, packet, this::packetHider);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void posHiderGenerator(String typeName, Class<? extends Number> posType, double factor) {
|
private void posHiderGenerator(Class<?> type, Class<? extends Number> posType, double factor) {
|
||||||
Class<?> type = Reflection.getClass(typeName);
|
|
||||||
Function<Object, Location> location = posPacketToLocation(type, posType, factor);
|
Function<Object, Location> location = posPacketToLocation(type, posType, factor);
|
||||||
packetHiders.put(type, (player, packet) -> packetHider(player, packet, location.apply(packet)));
|
packetHiders.put(type, (player, packet) -> packetHider(player, packet, location.apply(packet)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,6 @@ dependencies {
|
|||||||
|
|
||||||
compileOnly(libs.spigotapi)
|
compileOnly(libs.spigotapi)
|
||||||
|
|
||||||
compileOnly(libs.nms20)
|
compileOnly(libs.nms21)
|
||||||
compileOnly(libs.fawe21)
|
compileOnly(libs.fawe21)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,10 @@
|
|||||||
|
|
||||||
package de.steamwar.misslewars.slowmo;
|
package de.steamwar.misslewars.slowmo;
|
||||||
|
|
||||||
import de.steamwar.Reflection;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.craftbukkit.CraftWorld;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
@@ -30,7 +31,6 @@ public class SlowMoUtils {
|
|||||||
private static final Field field;
|
private static final Field field;
|
||||||
public static final boolean freezeEnabled;
|
public static final boolean freezeEnabled;
|
||||||
|
|
||||||
private static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"), "getHandle", null);
|
|
||||||
private static boolean frozen = false;
|
private static boolean frozen = false;
|
||||||
|
|
||||||
private static final World world;
|
private static final World world;
|
||||||
@@ -38,7 +38,7 @@ public class SlowMoUtils {
|
|||||||
static {
|
static {
|
||||||
Field temp;
|
Field temp;
|
||||||
try {
|
try {
|
||||||
temp = Reflection.getClass("net.minecraft.server.level.ServerLevel").getField("freezed");
|
temp = ServerLevel.class.getField("freezed");
|
||||||
} catch (NoSuchFieldException e) {
|
} catch (NoSuchFieldException e) {
|
||||||
temp = null;
|
temp = null;
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,7 @@ public class SlowMoUtils {
|
|||||||
if (freezeEnabled) {
|
if (freezeEnabled) {
|
||||||
if (frozen == state) return;
|
if (frozen == state) return;
|
||||||
try {
|
try {
|
||||||
field.set(getWorldHandle.invoke(world), state);
|
field.set(((CraftWorld) world).getHandle(), state);
|
||||||
frozen = state;
|
frozen = state;
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
// Ignored;
|
// Ignored;
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ package de.steamwar.core;
|
|||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.datafixers.util.Pair;
|
import com.mojang.datafixers.util.Pair;
|
||||||
import de.steamwar.Reflection;
|
|
||||||
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
|
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
|
||||||
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;
|
||||||
@@ -42,7 +41,7 @@ public class ProtocolWrapper {
|
|||||||
public static final Class<?> equipmentPacket = ClientboundSetEquipmentPacket.class;
|
public static final Class<?> equipmentPacket = ClientboundSetEquipmentPacket.class;
|
||||||
|
|
||||||
// 0: hand, 1: offhand, 2: feet, 3: legs, 4: chest, 5: head
|
// 0: hand, 1: offhand, 2: feet, 3: legs, 4: chest, 5: head
|
||||||
public static final Object[] itemSlots = Core.getVersion() > 8 ? Reflection.getClass("net.minecraft.world.entity.EnumItemSlot").getEnumConstants() : new Integer[]{0, 0, 1, 2, 3, 4};
|
public static final EquipmentSlot[] itemSlots = EquipmentSlot.values();
|
||||||
|
|
||||||
public static final ProtocolWrapper impl = new ProtocolWrapper();
|
public static final ProtocolWrapper impl = new ProtocolWrapper();
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import de.steamwar.linkage.Linked;
|
|||||||
import net.minecraft.network.protocol.game.ClientboundLoginPacket;
|
import net.minecraft.network.protocol.game.ClientboundLoginPacket;
|
||||||
import net.minecraft.network.protocol.game.CommonPlayerSpawnInfo;
|
import net.minecraft.network.protocol.game.CommonPlayerSpawnInfo;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
@@ -33,7 +34,7 @@ public class WorldIdentifier {
|
|||||||
private static ResourceKey<Level> resourceKey = null;
|
private static ResourceKey<Level> resourceKey = null;
|
||||||
|
|
||||||
private static final Class<?> resourceKeyClass = ResourceKey.class;
|
private static final Class<?> resourceKeyClass = ResourceKey.class;
|
||||||
private static final Class<?> minecraftKeyClass = Reflection.getClass("net.minecraft.resources.MinecraftKey");
|
private static final Class<?> minecraftKeyClass = ResourceLocation.class;
|
||||||
private static final Reflection.Constructor resourceKeyConstructor = Reflection.getConstructor(resourceKeyClass, minecraftKeyClass, minecraftKeyClass);
|
private static final Reflection.Constructor resourceKeyConstructor = Reflection.getConstructor(resourceKeyClass, minecraftKeyClass, minecraftKeyClass);
|
||||||
private static final Reflection.Constructor minecraftKeyConstructor = Reflection.getConstructor(minecraftKeyClass, String.class, String.class);
|
private static final Reflection.Constructor minecraftKeyConstructor = Reflection.getConstructor(minecraftKeyClass, String.class, String.class);
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,10 @@ package de.steamwar.entity;
|
|||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.properties.Property;
|
import com.mojang.authlib.properties.Property;
|
||||||
import de.steamwar.Reflection;
|
import de.steamwar.core.BountifulWrapper;
|
||||||
import de.steamwar.core.*;
|
import de.steamwar.core.Core;
|
||||||
|
import de.steamwar.core.ProtocolWrapper;
|
||||||
|
import de.steamwar.core.TrickyTrialsWrapper;
|
||||||
import de.steamwar.network.CoreNetworkHandler;
|
import de.steamwar.network.CoreNetworkHandler;
|
||||||
import de.steamwar.network.NetworkSender;
|
import de.steamwar.network.NetworkSender;
|
||||||
import de.steamwar.network.packets.common.PlayerSkinRequestPacket;
|
import de.steamwar.network.packets.common.PlayerSkinRequestPacket;
|
||||||
@@ -36,7 +38,6 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public class RPlayer extends REntity {
|
public class RPlayer extends REntity {
|
||||||
|
|
||||||
@@ -114,24 +115,7 @@ public class RPlayer extends REntity {
|
|||||||
packetSink.accept(ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.REMOVE, saved, GameMode.CREATIVE));
|
packetSink.accept(ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.REMOVE, saved, GameMode.CREATIVE));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Class<?> namedSpawnPacket = null;
|
|
||||||
private static Function<REntity, Object> namedSpawnPacketGenerator = null;
|
|
||||||
private static Reflection.Field<UUID> namedSpawnUUID = null;
|
|
||||||
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
namedSpawnPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundAddPlayerPacket");
|
|
||||||
namedSpawnPacketGenerator = spawnPacketGenerator(namedSpawnPacket, Core.getVersion() == 8 ? 1 : 0);
|
|
||||||
namedSpawnUUID = Reflection.getField(namedSpawnPacket, UUID.class, 0);
|
|
||||||
} catch (IllegalArgumentException e) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object getNamedSpawnPacket() {
|
private Object getNamedSpawnPacket() {
|
||||||
if (Core.getVersion() >= 21) return PacketConstructor.impl.createRPlayerSpawn(this);
|
return PacketConstructor.impl.createRPlayerSpawn(this);
|
||||||
|
|
||||||
Object packet = namedSpawnPacketGenerator.apply(this);
|
|
||||||
namedSpawnUUID.set(packet, uuid);
|
|
||||||
FlatteningWrapper.impl.setNamedSpawnPacketDataWatcher(packet);
|
|
||||||
return packet;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user