From 75dcb3dbea0135607c68273c32c760fd3ef5182f Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 5 Aug 2022 15:29:32 +0200 Subject: [PATCH 1/2] Fix TPSLimit Movement --- .../features/tpslimit/TPSLimitUtils.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java index 8fde0980..4b7aa4ce 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java @@ -19,13 +19,19 @@ package de.steamwar.bausystem.features.tpslimit; +import com.comphenix.tinyprotocol.Reflection; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.xray.XrayWrapper; import de.steamwar.bausystem.utils.NMSWrapper; +import de.steamwar.bausystem.utils.ProtocolAPI; import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; import org.bukkit.World; +import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; +import java.util.function.BiFunction; + @UtilityClass public class TPSLimitUtils { @@ -86,4 +92,20 @@ public class TPSLimitUtils { currentTPSLimit = d; tpsLimiter(); } + + private static final Class position = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPosition"); + private static final Class positionLook = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPositionLook"); + static { + BiFunction positionSetter = (player, o) -> { + if (currentTPSLimit < 20) { + Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { + XrayWrapper.impl.setPosition(player, o); + }, 1L); + return null; + } + return o; + }; + ProtocolAPI.setIncomingHandler(position, positionSetter); + ProtocolAPI.setIncomingHandler(positionLook, positionSetter); + } } \ No newline at end of file -- 2.39.5 From f323c043b207af78df5a179b9d86ccfda7c47652 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 6 Aug 2022 11:15:30 +0200 Subject: [PATCH 2/2] Refactor --- .../PlayerMovementWrapper15.java} | 4 ++-- .../PlayerMovementWrapper18.java} | 4 ++-- .../PlayerMovementWrapper19.java} | 4 ++-- .../steamwar/bausystem/features/tpslimit/TPSLimitUtils.java | 4 ++-- .../de/steamwar/bausystem/features/xray/XrayCommand.java | 3 ++- .../XrayWrapper.java => shared/PlayerMovementWrapper.java} | 6 +++--- 6 files changed, 13 insertions(+), 12 deletions(-) rename BauSystem_15/src/de/steamwar/bausystem/{features/xray/XrayWrapper15.java => shared/PlayerMovementWrapper15.java} (93%) rename BauSystem_18/src/de/steamwar/bausystem/{features/xray/XrayWrapper18.java => shared/PlayerMovementWrapper18.java} (93%) rename BauSystem_19/src/de/steamwar/bausystem/{features/xray/XrayWrapper19.java => shared/PlayerMovementWrapper19.java} (93%) rename BauSystem_Main/src/de/steamwar/bausystem/{features/xray/XrayWrapper.java => shared/PlayerMovementWrapper.java} (84%) diff --git a/BauSystem_15/src/de/steamwar/bausystem/features/xray/XrayWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/shared/PlayerMovementWrapper15.java similarity index 93% rename from BauSystem_15/src/de/steamwar/bausystem/features/xray/XrayWrapper15.java rename to BauSystem_15/src/de/steamwar/bausystem/shared/PlayerMovementWrapper15.java index b48e4de5..67243ebb 100644 --- a/BauSystem_15/src/de/steamwar/bausystem/features/xray/XrayWrapper15.java +++ b/BauSystem_15/src/de/steamwar/bausystem/shared/PlayerMovementWrapper15.java @@ -17,14 +17,14 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.xray; +package de.steamwar.bausystem.shared; import net.minecraft.server.v1_15_R1.EntityPlayer; import net.minecraft.server.v1_15_R1.PacketPlayInFlying; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -public class XrayWrapper15 implements XrayWrapper { +public class PlayerMovementWrapper15 implements PlayerMovementWrapper { @Override public void setPosition(Player player, Object object) { diff --git a/BauSystem_18/src/de/steamwar/bausystem/features/xray/XrayWrapper18.java b/BauSystem_18/src/de/steamwar/bausystem/shared/PlayerMovementWrapper18.java similarity index 93% rename from BauSystem_18/src/de/steamwar/bausystem/features/xray/XrayWrapper18.java rename to BauSystem_18/src/de/steamwar/bausystem/shared/PlayerMovementWrapper18.java index 3acc74b3..ce1a99fc 100644 --- a/BauSystem_18/src/de/steamwar/bausystem/features/xray/XrayWrapper18.java +++ b/BauSystem_18/src/de/steamwar/bausystem/shared/PlayerMovementWrapper18.java @@ -17,14 +17,14 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.xray; +package de.steamwar.bausystem.shared; import net.minecraft.network.protocol.game.PacketPlayInFlying; import net.minecraft.server.level.EntityPlayer; import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; import org.bukkit.entity.Player; -public class XrayWrapper18 implements XrayWrapper { +public class PlayerMovementWrapper18 implements PlayerMovementWrapper { @Override public void setPosition(Player player, Object object) { diff --git a/BauSystem_19/src/de/steamwar/bausystem/features/xray/XrayWrapper19.java b/BauSystem_19/src/de/steamwar/bausystem/shared/PlayerMovementWrapper19.java similarity index 93% rename from BauSystem_19/src/de/steamwar/bausystem/features/xray/XrayWrapper19.java rename to BauSystem_19/src/de/steamwar/bausystem/shared/PlayerMovementWrapper19.java index 83f5f61c..06f482a3 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/features/xray/XrayWrapper19.java +++ b/BauSystem_19/src/de/steamwar/bausystem/shared/PlayerMovementWrapper19.java @@ -17,14 +17,14 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.xray; +package de.steamwar.bausystem.shared; import net.minecraft.network.protocol.game.PacketPlayInFlying; import net.minecraft.server.level.EntityPlayer; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -public class XrayWrapper19 implements XrayWrapper { +public class PlayerMovementWrapper19 implements PlayerMovementWrapper { @Override public void setPosition(Player player, Object object) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java index 4b7aa4ce..8cbced1b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java @@ -21,7 +21,7 @@ package de.steamwar.bausystem.features.tpslimit; import com.comphenix.tinyprotocol.Reflection; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.features.xray.XrayWrapper; +import de.steamwar.bausystem.shared.PlayerMovementWrapper; import de.steamwar.bausystem.utils.NMSWrapper; import de.steamwar.bausystem.utils.ProtocolAPI; import lombok.experimental.UtilityClass; @@ -99,7 +99,7 @@ public class TPSLimitUtils { BiFunction positionSetter = (player, o) -> { if (currentTPSLimit < 20) { Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { - XrayWrapper.impl.setPosition(player, o); + PlayerMovementWrapper.impl.setPosition(player, o); }, 1L); return null; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java index 2d3f9503..ec135654 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java @@ -26,6 +26,7 @@ import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.linkage.LinkedInstance; import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.shared.PlayerMovementWrapper; import de.steamwar.bausystem.utils.ProtocolAPI; import de.steamwar.command.SWCommand; import de.steamwar.core.CraftbukkitWrapper; @@ -115,7 +116,7 @@ public class XrayCommand extends SWCommand implements Listener { Region region = Region.getRegion(player.getLocation()); if (hidden.containsKey(region) && hidden.get(region).contains(player)) { Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { - XrayWrapper.impl.setPosition(player, o); + PlayerMovementWrapper.impl.setPosition(player, o); }, 1L); return null; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayWrapper.java b/BauSystem_Main/src/de/steamwar/bausystem/shared/PlayerMovementWrapper.java similarity index 84% rename from BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayWrapper.java rename to BauSystem_Main/src/de/steamwar/bausystem/shared/PlayerMovementWrapper.java index 243b42e1..66e858af 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayWrapper.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/shared/PlayerMovementWrapper.java @@ -17,14 +17,14 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.features.xray; +package de.steamwar.bausystem.shared; import de.steamwar.bausystem.BauSystem; import de.steamwar.core.VersionDependent; import org.bukkit.entity.Player; -public interface XrayWrapper { - XrayWrapper impl = VersionDependent.getVersionImpl(BauSystem.getInstance()); +public interface PlayerMovementWrapper { + PlayerMovementWrapper impl = VersionDependent.getVersionImpl(BauSystem.getInstance()); void setPosition(Player player, Object object); } -- 2.39.5