SteamWar/BauSystem2.0
Archiviert
12
0

Fix TPSLimit Movement #101

Zusammengeführt
YoyoNow hat 2 Commits von tps_limit_movement_fix nach master 2022-08-06 14:10:40 +02:00 zusammengeführt
6 geänderte Dateien mit 33 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -17,14 +17,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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) {

Datei anzeigen

@ -17,14 +17,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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) {

Datei anzeigen

@ -17,14 +17,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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) {

Datei anzeigen

@ -19,13 +19,19 @@
package de.steamwar.bausystem.features.tpslimit;
import com.comphenix.tinyprotocol.Reflection;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.shared.PlayerMovementWrapper;
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<Player, Object, Object> positionSetter = (player, o) -> {
if (currentTPSLimit < 20) {
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
PlayerMovementWrapper.impl.setPosition(player, o);
}, 1L);
return null;
}
return o;
};
ProtocolAPI.setIncomingHandler(position, positionSetter);
ProtocolAPI.setIncomingHandler(positionLook, positionSetter);
}
}

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -17,14 +17,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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);
}