From e42c701ac7b1ad36f304216d2b4a84867b22ffb3 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 11 Jun 2022 21:12:24 +0200 Subject: [PATCH] Hotfix NoClipCommand Signed-off-by: yoyosource --- .../bausystem/utils/ProtocolWrapper15.java | 33 ++++++++++++++++++ .../bausystem/utils/ProtocolWrapper18.java | 34 +++++++++++++++++++ .../features/util/NoClipCommand.java | 13 ++++--- .../bausystem/utils/ProtocolWrapper.java | 30 ++++++++++++++++ 4 files changed, 103 insertions(+), 7 deletions(-) create mode 100644 BauSystem_15/src/de/steamwar/bausystem/utils/ProtocolWrapper15.java create mode 100644 BauSystem_18/src/de/steamwar/bausystem/utils/ProtocolWrapper18.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolWrapper.java diff --git a/BauSystem_15/src/de/steamwar/bausystem/utils/ProtocolWrapper15.java b/BauSystem_15/src/de/steamwar/bausystem/utils/ProtocolWrapper15.java new file mode 100644 index 00000000..57ba7259 --- /dev/null +++ b/BauSystem_15/src/de/steamwar/bausystem/utils/ProtocolWrapper15.java @@ -0,0 +1,33 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 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 com.comphenix.tinyprotocol.Reflection; +import com.mojang.authlib.GameProfile; +import de.steamwar.bausystem.features.util.NoClipCommand; + +public class ProtocolWrapper15 implements ProtocolWrapper { + + private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(NoClipCommand.playerInfoDataClass, NoClipCommand.playerInfoPacket, GameProfile.class, int.class, NoClipCommand.enumGamemode, NoClipCommand.iChatBaseComponent); + @Override + public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) { + return playerInfoDataConstructor.invoke(packet, profile, 0, mode, null); + } +} diff --git a/BauSystem_18/src/de/steamwar/bausystem/utils/ProtocolWrapper18.java b/BauSystem_18/src/de/steamwar/bausystem/utils/ProtocolWrapper18.java new file mode 100644 index 00000000..c82f70f2 --- /dev/null +++ b/BauSystem_18/src/de/steamwar/bausystem/utils/ProtocolWrapper18.java @@ -0,0 +1,34 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 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 com.comphenix.tinyprotocol.Reflection; +import com.mojang.authlib.GameProfile; +import de.steamwar.bausystem.features.util.NoClipCommand; +import de.steamwar.sql.Fight; + +public class ProtocolWrapper18 implements ProtocolWrapper { + + private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(NoClipCommand.playerInfoDataClass, GameProfile.class, int.class, NoClipCommand.enumGamemode, NoClipCommand.iChatBaseComponent); + @Override + public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) { + return playerInfoDataConstructor.invoke(profile, 0, mode, null); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java index f605f828..700eb64f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java @@ -28,6 +28,7 @@ import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.utils.NMSWrapper; import de.steamwar.bausystem.utils.ProtocolAPI; +import de.steamwar.bausystem.utils.ProtocolWrapper; import de.steamwar.command.SWCommand; import de.steamwar.core.Core; import lombok.Getter; @@ -47,17 +48,15 @@ import java.util.function.BiFunction; @Linked(LinkageType.LISTENER) public class NoClipCommand extends SWCommand implements Listener { - private static final Class playerInfoPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo"); + public static final Class playerInfoPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo"); private static final Class playerInfoActionClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$EnumPlayerInfoAction"); private static final Reflection.FieldAccessor playerInfoAction = Reflection.getField(playerInfoPacket, playerInfoActionClass, 0); private static final Object updateGamemode = playerInfoActionClass.getEnumConstants()[1]; private static final Reflection.FieldAccessor playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0); - private static final Class playerInfoDataClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$PlayerInfoData"); - private static final Class enumGamemode = Reflection.getClass("{nms.world.level}.EnumGamemode"); + public static final Class playerInfoDataClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$PlayerInfoData"); + public static final Class enumGamemode = Reflection.getClass("{nms.world.level}.EnumGamemode"); private static final Object spectator = enumGamemode.getEnumConstants()[Core.getVersion() > 15 ? 3 : 4]; - private static final Class iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent"); - - private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Core.getVersion() > 15 ? Reflection.getConstructor(playerInfoDataClass, GameProfile.class, int.class, enumGamemode, iChatBaseComponent) : Reflection.getConstructor(playerInfoDataClass, playerInfoPacket, GameProfile.class, int.class, enumGamemode, iChatBaseComponent); + public static final Class iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent"); public static final Class gameStateChange = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutGameStateChange"); private static final Reflection.FieldAccessor floatFieldAccessor = Reflection.getField(gameStateChange, float.class, 0); @@ -158,7 +157,7 @@ public class NoClipCommand extends SWCommand implements Listener { private static Object playerInfoPacket(Object action, GameProfile profile, Object mode) { Object packet = Reflection.newInstance(playerInfoPacket); playerInfoAction.set(packet, action); - playerInfoData.set(packet, Collections.singletonList(Core.getVersion() > 15 ? playerInfoDataConstructor.invoke(profile, 0, mode, null) : playerInfoDataConstructor.invoke(packet, profile, 0, mode, null))); + playerInfoData.set(packet, Collections.singletonList(ProtocolWrapper.impl.playerInfoDataConstructor(packet, profile, mode))); return packet; } } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolWrapper.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolWrapper.java new file mode 100644 index 00000000..536dec51 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/ProtocolWrapper.java @@ -0,0 +1,30 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 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 com.mojang.authlib.GameProfile; +import de.steamwar.bausystem.BauSystem; +import de.steamwar.core.VersionDependent; + +public interface ProtocolWrapper { + ProtocolWrapper impl = VersionDependent.getVersionImpl(BauSystem.getInstance()); + + Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode); +}