Remove more reflection calls

This commit is contained in:
2026-05-16 21:41:50 +02:00
parent ba4ee08489
commit cfa650bcf4
5 changed files with 18 additions and 59 deletions
@@ -23,7 +23,6 @@ import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.techhider.TechHiderCommand;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.utils.PlayerMovementWrapper;
import de.steamwar.bausystem.utils.ScoreboardElement;
import de.steamwar.command.SWCommand;
import de.steamwar.core.CraftbukkitWrapper;
@@ -32,8 +31,10 @@ import de.steamwar.linkage.LinkedInstance;
import de.steamwar.techhider.TechHider;
import net.md_5.bungee.api.ChatMessageType;
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
import net.minecraft.server.level.ServerPlayer;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@@ -96,19 +97,26 @@ public class XrayCommand extends SWCommand implements Listener, ScoreboardElemen
}
{
BiFunction<Player, Object, Object> positionSetter = (player, o) -> {
BiFunction<Player, ServerboundMovePlayerPacket, Object> positionSetter = (player, packet) -> {
Region region = Region.getRegion(player.getLocation());
if (hidden.containsKey(region) && hidden.get(region).contains(player)) {
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
PlayerMovementWrapper.impl.setPosition(player, o);
ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
if (packet.hasPos) {
serverPlayer.setPosRaw(packet.x, packet.y, packet.z);
}
if (packet.hasRot) {
serverPlayer.setXRot(packet.xRot);
serverPlayer.setYRot(packet.yRot);
}
}, 0);
return null;
}
return o;
return packet;
};
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.Pos.class, positionSetter);
TinyProtocol.instance.addFilter(ServerboundMovePlayerPacket.PosRot.class, positionSetter);
TinyProtocol.instance.addTypedFilter(ServerboundMovePlayerPacket.Pos.class, positionSetter);
TinyProtocol.instance.addTypedFilter(ServerboundMovePlayerPacket.PosRot.class, positionSetter);
}
@EventHandler
@@ -1,42 +0,0 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2025 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.utils;
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
import net.minecraft.server.level.ServerPlayer;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
public class PlayerMovementWrapper {
public static final PlayerMovementWrapper impl = new PlayerMovementWrapper();
public void setPosition(Player player, Object object) {
ServerboundMovePlayerPacket packetPlayInFlying = ((ServerboundMovePlayerPacket) object);
ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
if (packetPlayInFlying.hasPos) {
serverPlayer.setPosRaw(packetPlayInFlying.x, packetPlayInFlying.y, packetPlayInFlying.z);
}
if (packetPlayInFlying.hasRot) {
serverPlayer.setXRot(packetPlayInFlying.xRot);
serverPlayer.setYRot(packetPlayInFlying.yRot);
}
}
}
@@ -243,7 +243,7 @@ public class TinyProtocol {
}
}
public <T> void addTypedFilter(Class<T> packetType, BiFunction<Player, T, Object> filter) {
public <T> void addTypedFilter(Class<T> packetType, BiFunction<Player, ? super T, Object> filter) {
packetFilters.computeIfAbsent(packetType, c -> new CopyOnWriteArrayList<>()).add((BiFunction) filter);
}
@@ -41,9 +41,7 @@ public class BountifulWrapper {
}
public void sendMessage(Player player, ChatMessageType type, BaseComponent... msg) {
if(type == ChatMessageType.CHAT)
type = ChatMessageType.SYSTEM;
if(type == ChatMessageType.CHAT) type = ChatMessageType.SYSTEM;
player.spigot().sendMessage(type, msg);
}
@@ -62,9 +60,7 @@ public class BountifulWrapper {
Reflection.Field<PositionMoveRotation> field = Reflection.getField(packetClass, PositionMoveRotation.class, 0);
return (packet, x, y, z, pitch, yaw) -> {
PositionMoveRotation pos = field.get(packet);
field.set(packet, new PositionMoveRotation(new Vec3(x, y, z), pos.deltaMovement(), yaw, pitch));
field.set(packet, new PositionMoveRotation(new Vec3(x, y, z), field.get(packet).deltaMovement(), yaw, pitch));
};
} catch (IllegalArgumentException e) {
Reflection.Field<Double> posX = Reflection.getField(packetClass, double.class, fieldOffset);
@@ -82,6 +82,7 @@ public class REntity {
private boolean bowDrawn;
@Getter
private boolean noGravity;
@Getter
private boolean isGlowing;
private int fireTick;
@@ -245,10 +246,6 @@ public class REntity {
server.updateEntity(this,getDataWatcherPacket(entityStatusWatcher,getEntityStatus()));
}
public boolean isGlowing() {
return isGlowing;
}
private static final Function<REntity, Object> spawnPacketGenerator = entitySpawnPacketGenerator(ProtocolWrapper.spawnPacket, 2);
private static final Reflection.Field<Integer> additionalData = Reflection.getField(ProtocolWrapper.spawnPacket, int.class, 4);