From cfa650bcf4d81b742d6a0dda7916f26545d3cbc4 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Sat, 16 May 2026 21:41:50 +0200 Subject: [PATCH] Remove more reflection calls --- .../bausystem/features/xray/XrayCommand.java | 20 ++++++--- .../utils/PlayerMovementWrapper.java | 42 ------------------- .../comphenix/tinyprotocol/TinyProtocol.java | 2 +- .../de/steamwar/core/BountifulWrapper.java | 8 +--- .../src/de/steamwar/entity/REntity.java | 5 +-- 5 files changed, 18 insertions(+), 59 deletions(-) delete mode 100644 BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlayerMovementWrapper.java diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java index 401f6066..b1d100f3 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java @@ -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 positionSetter = (player, o) -> { + BiFunction 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 diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlayerMovementWrapper.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlayerMovementWrapper.java deleted file mode 100644 index 65394390..00000000 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlayerMovementWrapper.java +++ /dev/null @@ -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 . - */ - -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); - } - } -} diff --git a/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java b/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java index 6ea85ccc..2aa64c77 100644 --- a/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java +++ b/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java @@ -243,7 +243,7 @@ public class TinyProtocol { } } - public void addTypedFilter(Class packetType, BiFunction filter) { + public void addTypedFilter(Class packetType, BiFunction filter) { packetFilters.computeIfAbsent(packetType, c -> new CopyOnWriteArrayList<>()).add((BiFunction) filter); } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/BountifulWrapper.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/BountifulWrapper.java index a8377e1e..4894a2ee 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/BountifulWrapper.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/BountifulWrapper.java @@ -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 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 posX = Reflection.getField(packetClass, double.class, fieldOffset); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java index eb075295..b5643eb2 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -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 spawnPacketGenerator = entitySpawnPacketGenerator(ProtocolWrapper.spawnPacket, 2); private static final Reflection.Field additionalData = Reflection.getField(ProtocolWrapper.spawnPacket, int.class, 4);