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..962b8181 --- /dev/null +++ b/BauSystem_18/src/de/steamwar/bausystem/utils/ProtocolWrapper18.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 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_19/src/de/steamwar/bausystem/shared/BaseEntity19.java b/BauSystem_19/src/de/steamwar/bausystem/shared/BaseEntity19.java index 7cf650c2..075d4987 100644 --- a/BauSystem_19/src/de/steamwar/bausystem/shared/BaseEntity19.java +++ b/BauSystem_19/src/de/steamwar/bausystem/shared/BaseEntity19.java @@ -79,7 +79,7 @@ public class BaseEntity19 extends EntityFallingBlock implements AbstractEntity { } public void sendEntity(Player player) { - PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(ae(), cp(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.C, Block.i(iBlockData), ZERO, 0.0); + PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(ae(), cp(), position.getX(), position.getY(), position.getZ(), 0, 0, EntityTypes.E, Block.i(iBlockData), ZERO, 0.0); PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().b; playerConnection.a(packetPlayOutSpawnEntity); diff --git a/BauSystem_19/src/de/steamwar/bausystem/utils/ProtocolWrapper19.java b/BauSystem_19/src/de/steamwar/bausystem/utils/ProtocolWrapper19.java new file mode 100644 index 00000000..3a21ab08 --- /dev/null +++ b/BauSystem_19/src/de/steamwar/bausystem/utils/ProtocolWrapper19.java @@ -0,0 +1,33 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2021 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 ProtocolWrapper19 implements ProtocolWrapper { + + private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(NoClipCommand.playerInfoDataClass, GameProfile.class, int.class, NoClipCommand.enumGamemode, NoClipCommand.iChatBaseComponent, Reflection.getClass("net.minecraft.world.entity.player.ProfilePublicKey$a")); + @Override + public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) { + return playerInfoDataConstructor.invoke(profile, 0, mode, null, 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); +} diff --git a/build.gradle b/build.gradle index 0d352184..7f44d482 100644 --- a/build.gradle +++ b/build.gradle @@ -94,6 +94,7 @@ dependencies { implementation project(":BauSystem_Main") implementation project(":BauSystem_15") implementation project(":BauSystem_18") + implementation project(":BauSystem_19") } task buildResources(type: Copy) {