From 2733f10e898a753fa206ca31a51e54f9286b7495 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 7 Jun 2022 19:30:10 +0200 Subject: [PATCH] FightSystem 1.19 untested Signed-off-by: Lixfel --- .../fightsystem/utils/TechHider18.java | 10 +- FightSystem_19/pom.xml | 89 +++++++++++++ .../fightsystem/utils/BlockIdWrapper19.java | 87 +++++++++++++ .../utils/CraftbukkitWrapper19.java | 71 +++++++++++ .../fightsystem/utils/ProtocolWrapper19.java | 120 ++++++++++++++++++ .../fightsystem/utils/TechHider19.java | 31 +++++ FightSystem_Core/pom.xml | 2 +- .../steamwar/fightsystem/utils/TechHider.java | 2 +- FightSystem_Main/pom.xml | 6 + pom.xml | 1 + 10 files changed, 413 insertions(+), 6 deletions(-) create mode 100644 FightSystem_19/pom.xml create mode 100644 FightSystem_19/src/de/steamwar/fightsystem/utils/BlockIdWrapper19.java create mode 100644 FightSystem_19/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper19.java create mode 100644 FightSystem_19/src/de/steamwar/fightsystem/utils/ProtocolWrapper19.java create mode 100644 FightSystem_19/src/de/steamwar/fightsystem/utils/TechHider19.java diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/TechHider18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/TechHider18.java index b22f4a2..98c1a28 100644 --- a/FightSystem_18/src/de/steamwar/fightsystem/utils/TechHider18.java +++ b/FightSystem_18/src/de/steamwar/fightsystem/utils/TechHider18.java @@ -55,7 +55,7 @@ public class TechHider18 implements TechHider.ChunkHider { private static final Reflection.FieldAccessor dataField = Reflection.getField(ClientboundLevelChunkPacketData.class, byte[].class, 0); private static final Reflection.FieldAccessor tileEntities = Reflection.getField(ClientboundLevelChunkPacketData.class, List.class, 0); public static final Class tileEntity = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData$a"); - private static final Reflection.FieldAccessor entityType = Reflection.getField(tileEntity, TileEntityTypes.class, 0); + protected static final Reflection.FieldAccessor entityType = Reflection.getField(tileEntity, TileEntityTypes.class, 0); private final Set hiddenBlockIds = BlockIdWrapper.impl.getHiddenBlockIds(); private final int obfuscateWith = BlockIdWrapper.impl.getObfuscateWith(); @@ -68,9 +68,7 @@ public class TechHider18 implements TechHider.ChunkHider { packet = chunkPacketCloner.apply(packet); Object data = chunkDataCloner.apply(chunkData.get(packet)); - tileEntities.set(data, ((List)tileEntities.get(data)).stream().filter( - tile -> Config.HiddenBlockEntities.contains(IRegistry.aa.b(entityType.get(tile)).a()) - ).collect(Collectors.toList())); + tileEntities.set(data, ((List)tileEntities.get(data)).stream().filter(this::tileEntityVisible).collect(Collectors.toList())); World world = p.getWorld(); int sections = (world.getMaxHeight() - world.getMinHeight()) / 16; @@ -80,6 +78,10 @@ public class TechHider18 implements TechHider.ChunkHider { return packet; } + protected boolean tileEntityVisible(Object tile) { + return !Config.HiddenBlockEntities.contains(IRegistry.aa.b(entityType.get(tile)).a()); + } + private byte[] dataHider(byte[] data, int sections) { ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100); int i = 0; diff --git a/FightSystem_19/pom.xml b/FightSystem_19/pom.xml new file mode 100644 index 0000000..5eac264 --- /dev/null +++ b/FightSystem_19/pom.xml @@ -0,0 +1,89 @@ + + + + + 4.0.0 + + + steamwar + FightSystem + 1.0 + + + + ${project.basedir}/.. + + + FightSystem_19 + 1.0 + + + + org.spigotmc + spigot-api + 1.19-R0.1-SNAPSHOT + provided + + + com.mojang + datafixerupper + 4.0.26 + provided + + + io.netty + netty-all + 4.1.68.Final + provided + + + com.mojang + authlib + 1.5.25 + provided + + + steamwar + Spigot + 1.19 + system + ${main.basedir}/lib/Spigot-1.19.jar + + + steamwar + WorldEdit + 1.0 + system + ${main.basedir}/lib/WorldEdit-1.15.jar + + + steamwar + FightSystem_Core + 1.0 + + + steamwar + FightSystem_18 + 1.0 + + + \ No newline at end of file diff --git a/FightSystem_19/src/de/steamwar/fightsystem/utils/BlockIdWrapper19.java b/FightSystem_19/src/de/steamwar/fightsystem/utils/BlockIdWrapper19.java new file mode 100644 index 0000000..e7b861f --- /dev/null +++ b/FightSystem_19/src/de/steamwar/fightsystem/utils/BlockIdWrapper19.java @@ -0,0 +1,87 @@ +/* + 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.fightsystem.utils; + +import de.steamwar.fightsystem.Config; +import net.minecraft.core.BlockPosition; +import net.minecraft.core.IRegistry; +import net.minecraft.resources.MinecraftKey; +import net.minecraft.server.level.WorldServer; +import net.minecraft.world.entity.EntityPose; +import net.minecraft.world.level.block.state.IBlockData; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.level.material.FluidTypes; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_19_R1.block.CraftBlock; + +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; + +public class BlockIdWrapper19 implements BlockIdWrapper { + + @Override + public int blockToId(Block block) { + return net.minecraft.world.level.block.Block.i(((CraftBlock)block).getNMS()); + } + + @Override + public void setBlock(World world, int x, int y, int z, int blockState) { + IBlockData blockData = Objects.requireNonNull(net.minecraft.world.level.block.Block.a(blockState)); + WorldServer cworld = ((CraftWorld)world).getHandle(); + BlockPosition pos = new BlockPosition(x, y, z); + cworld.m(pos); + cworld.a(pos, blockData, 1042); + cworld.k().a(pos); + } + + @Override + public Set getHiddenBlockIds() { + Set hiddenBlockIds = new HashSet<>(); + for(String tag : Config.HiddenBlocks){ + for(IBlockData data : IRegistry.V.a(new MinecraftKey(tag)).k().a()){ + hiddenBlockIds.add(net.minecraft.world.level.block.Block.i(data)); + } + } + + if(Config.HiddenBlocks.contains("water")){ + Fluid water = FluidTypes.c.h(); + for(IBlockData data : net.minecraft.world.level.block.Block.o) { + if(data.p() == water) { + hiddenBlockIds.add(net.minecraft.world.level.block.Block.i(data)); + } + } + } + + return hiddenBlockIds; + } + + @Override + public int getObfuscateWith() { //ResourceLocation, DefaultedRegistry + return net.minecraft.world.level.block.Block.i(IRegistry.V.a(new MinecraftKey(Config.ObfuscateWith)).m()); + } + + @Override + public Object getPose(boolean sneaking) { + return sneaking ? EntityPose.f : EntityPose.a; + } +} diff --git a/FightSystem_19/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper19.java b/FightSystem_19/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper19.java new file mode 100644 index 0000000..5193f15 --- /dev/null +++ b/FightSystem_19/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper19.java @@ -0,0 +1,71 @@ +/* + 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.fightsystem.utils; + +import de.steamwar.fightsystem.Config; +import net.minecraft.world.level.chunk.Chunk; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; + +public class CraftbukkitWrapper19 implements CraftbukkitWrapper { + + @Override + public void resetChunk(World world, World backup, int x, int z) { + net.minecraft.world.level.World w = ((CraftWorld) world).getHandle(); + Chunk chunk = w.d(x, z); + Chunk backupChunk = ((CraftWorld) backup).getHandle().d(x, z); + + System.arraycopy(backupChunk.d(), 0, chunk.d(), 0, chunk.d().length); + } + + @Override + public void sendResourcePack(Player player, String pack, String sha1) { + ((CraftPlayer)player).getHandle().a(pack, sha1, true, null); + } + + @Override + public float headRotation(Entity e) { + return ((CraftEntity)e).getHandle().ch(); + } + + @Override + public boolean hasItems(ItemStack stack) { + Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).u().d()); + keys.remove("Enchantments"); + keys.remove("Damage"); + return !keys.isEmpty(); + } + + @Override + public Stream entityIterator() { + return StreamSupport.stream(((CraftWorld) Config.world).getHandle().F().a().spliterator(), false); + } +} diff --git a/FightSystem_19/src/de/steamwar/fightsystem/utils/ProtocolWrapper19.java b/FightSystem_19/src/de/steamwar/fightsystem/utils/ProtocolWrapper19.java new file mode 100644 index 0000000..d0d0ba8 --- /dev/null +++ b/FightSystem_19/src/de/steamwar/fightsystem/utils/ProtocolWrapper19.java @@ -0,0 +1,120 @@ +/* + 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.fightsystem.utils; + +import com.comphenix.tinyprotocol.Reflection; +import com.mojang.authlib.GameProfile; +import com.mojang.datafixers.util.Pair; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.record.REntity; +import net.minecraft.core.IRegistry; +import net.minecraft.core.SectionPosition; +import net.minecraft.world.entity.EntityTypes; +import net.minecraft.world.level.block.entity.TileEntityTypes; +import net.minecraft.world.level.block.state.IBlockData; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; + +import java.util.Collections; +import java.util.List; +import java.util.function.BiFunction; +import java.util.function.UnaryOperator; + +public class ProtocolWrapper19 implements ProtocolWrapper { + + private static final Reflection.FieldAccessor equipmentStack = Reflection.getField(REntity.equipmentPacket, List.class, 0); + @Override + public void setEquipmentPacketStack(Object packet, String slot, Object stack) { + equipmentStack.set(packet, Collections.singletonList(new Pair<>(getSlot(slot), stack))); + } + + private static final Reflection.FieldAccessor spawnType = Reflection.getField(REntity.spawnPacket, EntityTypes.class, 0); + @Override + public void setSpawnPacketType(Object packet, EntityType type) { + switch(type) { + case PRIMED_TNT: + spawnType.set(packet, EntityTypes.as); + break; + case ARROW: + spawnType.set(packet, EntityTypes.d); + break; + case FIREBALL: + spawnType.set(packet, EntityTypes.S); + break; + } + } + + private static final Class enumItemSlot = Reflection.getClass("{nms.world.entity}.EnumItemSlot"); + private static final Object[] itemSlots = enumItemSlot.getEnumConstants(); + private static Object getSlot(String slot) { + switch(slot){ + case "HEAD": + return itemSlots[5]; + case "CHEST": + return itemSlots[4]; + case "LEGS": + return itemSlots[3]; + case "FEET": + return itemSlots[2]; + case "OFFHAND": + return itemSlots[1]; + case "MAINHAND": + default: + return itemSlots[0]; + } + } + + private static final Reflection.FieldAccessor multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, SectionPosition.class, 0); + private static final Reflection.FieldAccessor multiBlockChangeBlocks = Reflection.getField(TechHider.multiBlockChangePacket, IBlockData[].class, 0); + private static final BiFunction, Object> iBlockDataArrayCloner = ProtocolAPI.arrayCloneGenerator(TechHider.iBlockData); + @Override + public Object multiBlockChangeHider(Player p, Object packet) { + Object chunkCoords = multiBlockChangeChunk.get(packet); + if(TechHider.bypass(p, TechHider.blockPositionX.get(chunkCoords), TechHider.blockPositionZ.get(chunkCoords))) + return packet; + + packet = TechHider.multiBlockChangeCloner.apply(packet); + multiBlockChangeBlocks.set(packet, iBlockDataArrayCloner.apply(multiBlockChangeBlocks.get(packet), block -> ProtocolWrapper.impl.iBlockDataHidden(block) ? TechHider.obfuscateIBlockData : block)); + return packet; + } + + private static final Reflection.FieldAccessor tileEntityType = Reflection.getField(TechHider.tileEntityDataPacket, TileEntityTypes.class, 0); + @Override + public boolean unfilteredTileEntityDataAction(Object packet) { + return tileEntityType.get(packet) != TileEntityTypes.h; + } + + @Override + public BiFunction blockBreakHiderGenerator(Class blockBreakPacket) { + return null; + } + + private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor(Fight.playerInfoDataClass, GameProfile.class, int.class, Fight.enumGamemode, Fight.iChatBaseComponent); + @Override + public Object playerInfoDataConstructor(Object packet, GameProfile profile, Object mode) { + return playerInfoDataConstructor.invoke(profile, 0, mode, null); + } + + @Override + public boolean iBlockDataHidden(Object iBlockData) { + return Config.HiddenBlocks.contains(IRegistry.V.b(((IBlockData) iBlockData).b()).a()); + } +} diff --git a/FightSystem_19/src/de/steamwar/fightsystem/utils/TechHider19.java b/FightSystem_19/src/de/steamwar/fightsystem/utils/TechHider19.java new file mode 100644 index 0000000..eb61b75 --- /dev/null +++ b/FightSystem_19/src/de/steamwar/fightsystem/utils/TechHider19.java @@ -0,0 +1,31 @@ +/* + 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.fightsystem.utils; + +import de.steamwar.fightsystem.Config; +import net.minecraft.core.IRegistry; + +public class TechHider19 extends TechHider18 { + + @Override + protected boolean tileEntityVisible(Object tile) { + return !Config.HiddenBlockEntities.contains(IRegistry.ab.b(entityType.get(tile)).a()); + } +} diff --git a/FightSystem_Core/pom.xml b/FightSystem_Core/pom.xml index 2ce9c10..7e022e6 100644 --- a/FightSystem_Core/pom.xml +++ b/FightSystem_Core/pom.xml @@ -21,7 +21,7 @@ org.spigotmc spigot-api - 1.18-R0.1-SNAPSHOT + 1.19-R0.1-SNAPSHOT provided diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java index 5e308a2..0cdb6fa 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java @@ -75,7 +75,7 @@ public class TechHider extends StateDependent { ChunkHider chunkHider = VersionDependent.getVersionImpl(FightSystem.getPlugin()); techhiders.put(chunkHider.mapChunkPacket(), chunkHider::mapChunkHider); - if(Core.getVersion() > 12) { + if(Core.getVersion() > 12 && Core.getVersion() < 19) { Class blockBreakClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutBlockBreak"); techhiders.put(blockBreakClass, ProtocolWrapper.impl.blockBreakHiderGenerator(blockBreakClass)); } diff --git a/FightSystem_Main/pom.xml b/FightSystem_Main/pom.xml index a42f01d..04f6fca 100644 --- a/FightSystem_Main/pom.xml +++ b/FightSystem_Main/pom.xml @@ -98,6 +98,12 @@ 1.0 compile + + steamwar + FightSystem_19 + 1.0 + compile + steamwar FightSystem_Core diff --git a/pom.xml b/pom.xml index 4c536b1..055ee93 100644 --- a/pom.xml +++ b/pom.xml @@ -58,6 +58,7 @@ FightSystem_14 FightSystem_15 FightSystem_18 + FightSystem_19 FightSystem_Core FightSystem_Main FightSystem_Standalone