From f29bf025e6aa125b5e05b0a7e9b618992a080a1b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 3 Feb 2023 11:59:39 +0100 Subject: [PATCH 1/2] Multiversion simplification & 1.19.3 compatibility Signed-off-by: Lixfel --- .../utils/CraftbukkitWrapper10.java | 19 ------- .../utils/CraftbukkitWrapper12.java | 19 ------- .../fightsystem/utils/BlockIdWrapper14.java | 41 ++++++++------ .../utils/CraftbukkitWrapper14.java | 19 ------- .../fightsystem/utils/BlockIdWrapper15.java | 50 ----------------- .../utils/CraftbukkitWrapper15.java | 19 ------- .../fightsystem/utils/BlockIdWrapper18.java | 54 ------------------- .../utils/CraftbukkitWrapper18.java | 48 ++++++++--------- .../fightsystem/utils/BlockIdWrapper19.java | 54 ------------------- .../utils/CraftbukkitWrapper19.java | 45 +--------------- .../fightsystem/utils/BlockIdWrapper8.java | 5 -- .../utils/CraftbukkitWrapper8.java | 19 ------- .../utils/CraftbukkitWrapper9.java | 19 ------- .../de/steamwar/fightsystem/fight/Fight.java | 20 +------ .../de/steamwar/fightsystem/fight/Kit.java | 16 +++++- .../fightsystem/utils/BlockIdWrapper.java | 2 - .../fightsystem/utils/CraftbukkitWrapper.java | 4 -- 17 files changed, 63 insertions(+), 390 deletions(-) delete mode 100644 FightSystem_15/src/de/steamwar/fightsystem/utils/BlockIdWrapper15.java delete mode 100644 FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java delete mode 100644 FightSystem_19/src/de/steamwar/fightsystem/utils/BlockIdWrapper19.java diff --git a/FightSystem_10/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper10.java b/FightSystem_10/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper10.java index d43e00c..e6b9dc8 100644 --- a/FightSystem_10/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper10.java +++ b/FightSystem_10/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper10.java @@ -25,14 +25,8 @@ import net.minecraft.server.v1_10_R1.Chunk; import org.bukkit.World; import org.bukkit.craftbukkit.v1_10_R1.CraftWorld; import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_10_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; public class CraftbukkitWrapper10 implements CraftbukkitWrapper { @@ -52,24 +46,11 @@ public class CraftbukkitWrapper10 implements CraftbukkitWrapper { chunk.tileEntities.putAll(backupChunk.tileEntities); } - @Override - public void sendResourcePack(Player player, String pack, String sha1) { - ((CraftPlayer)player).getHandle().setResourcePack(pack, sha1); - } - @Override public float headRotation(Entity e) { return ((CraftEntity)e).getHandle().getHeadRotation(); } - @Override - public boolean hasItems(ItemStack stack) { - Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c()); - keys.remove("Enchantments"); - keys.remove("Damage"); - return !keys.isEmpty(); - } - @Override public Stream entityIterator() { return ((CraftWorld) Config.world).getHandle().entityList.stream(); diff --git a/FightSystem_12/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper12.java index a637867..36fd0ab 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper12.java @@ -25,14 +25,8 @@ import net.minecraft.server.v1_12_R1.Chunk; import org.bukkit.World; import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_12_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; public class CraftbukkitWrapper12 implements CraftbukkitWrapper { @@ -52,24 +46,11 @@ public class CraftbukkitWrapper12 implements CraftbukkitWrapper { chunk.tileEntities.putAll(backupChunk.tileEntities); } - @Override - public void sendResourcePack(Player player, String pack, String sha1) { - ((CraftPlayer)player).getHandle().setResourcePack(pack, sha1); - } - @Override public float headRotation(Entity e) { return ((CraftEntity)e).getHandle().getHeadRotation(); } - @Override - public boolean hasItems(ItemStack stack) { - Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c()); - keys.remove("Enchantments"); - keys.remove("Damage"); - return !keys.isEmpty(); - } - @Override public Stream entityIterator() { return ((CraftWorld) Config.world).getHandle().entityList.stream(); diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java index 3fdc6db..916bfb6 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java @@ -19,32 +19,41 @@ package de.steamwar.fightsystem.utils; -import net.minecraft.server.v1_14_R1.*; +import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.core.Core; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_14_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_14_R1.block.CraftBlock; - -import java.util.Objects; public class BlockIdWrapper14 implements BlockIdWrapper { + + private static final Class worldServer = Reflection.getClass("{nms.server.level}.WorldServer"); + private static final Class chunkProviderServer = Reflection.getClass("{nms.server.level}.ChunkProviderServer"); + private static final Class block = Reflection.getClass("{nms.world.level.block}.Block"); + private static final Class iBlockData = Reflection.getClass("{nms.world.level.block.state}.IBlockData"); + private static final Class blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); + + private static final Reflection.MethodInvoker getCombinedId = Reflection.getTypedMethod(block, null, int.class, iBlockData); + private static final Reflection.MethodInvoker getNMS = Reflection.getTypedMethod(Reflection.getClass("{obc}.block.CraftBlock"), "getNMS", iBlockData); @Override public int blockToId(Block block) { - return net.minecraft.server.v1_14_R1.Block.REGISTRY_ID.getId(((CraftBlock)block).getNMS()); + return (int) getCombinedId.invoke(null, getNMS.invoke(block)); } + private static final Reflection.MethodInvoker getByCombinedId = Reflection.getTypedMethod(block, null, iBlockData, int.class); + private static final Reflection.MethodInvoker getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle", worldServer); + private static final Reflection.ConstructorInvoker newBlockPosition = Reflection.getConstructor(blockPosition, int.class, int.class, int.class); + private static final Reflection.MethodInvoker getTypeAndData = Reflection.getMethod(worldServer, null, blockPosition, iBlockData, int.class); + private static final Reflection.MethodInvoker removeTileEntity = Reflection.getMethod(worldServer, Core.getVersion() > 15 ? "m" : "removeTileEntity", blockPosition); + private static final Reflection.MethodInvoker getChunkProvider = Reflection.getTypedMethod(worldServer, null, chunkProviderServer); + private static final Reflection.MethodInvoker flagDirty = Reflection.getMethod(chunkProviderServer, null, blockPosition); @Override public void setBlock(World world, int x, int y, int z, int blockState) { - IBlockData blockData = Objects.requireNonNull(net.minecraft.server.v1_14_R1.Block.REGISTRY_ID.fromId(blockState)); - WorldServer cworld = ((CraftWorld)world).getHandle(); - BlockPosition pos = new BlockPosition(x, y, z); - cworld.removeTileEntity(pos); - cworld.setTypeAndData(pos, blockData, 1042); - cworld.getChunkProvider().flagDirty(pos); - } + Object blockData = getByCombinedId.invoke(null, blockState); + Object nworld = getWorldHandle.invoke(world); + Object pos = newBlockPosition.invoke(x, y, z); - @Override - public Object getPose(boolean sneaking) { - return sneaking ? EntityPose.SNEAKING : EntityPose.STANDING; + removeTileEntity.invoke(nworld, pos); + getTypeAndData.invoke(nworld, pos, blockData, 1042); + flagDirty.invoke(getChunkProvider.invoke(nworld), pos); } } diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper14.java index 54e5ff9..7528fcf 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper14.java @@ -25,14 +25,8 @@ import net.minecraft.server.v1_14_R1.Chunk; import org.bukkit.World; import org.bukkit.craftbukkit.v1_14_R1.CraftWorld; import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_14_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; public class CraftbukkitWrapper14 implements CraftbukkitWrapper { @@ -53,24 +47,11 @@ public class CraftbukkitWrapper14 implements CraftbukkitWrapper { chunk.heightMap.putAll(backupChunk.heightMap); } - @Override - public void sendResourcePack(Player player, String pack, String sha1) { - ((CraftPlayer)player).getHandle().setResourcePack(pack, sha1); - } - @Override public float headRotation(Entity e) { return ((CraftEntity)e).getHandle().getHeadRotation(); } - @Override - public boolean hasItems(ItemStack stack) { - Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().getKeys()); - keys.remove("Enchantments"); - keys.remove("Damage"); - return !keys.isEmpty(); - } - @Override public Stream entityIterator() { return ((CraftWorld) Config.world).getHandle().entitiesById.values().stream(); diff --git a/FightSystem_15/src/de/steamwar/fightsystem/utils/BlockIdWrapper15.java b/FightSystem_15/src/de/steamwar/fightsystem/utils/BlockIdWrapper15.java deleted file mode 100644 index 3a5452e..0000000 --- a/FightSystem_15/src/de/steamwar/fightsystem/utils/BlockIdWrapper15.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - 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 net.minecraft.server.v1_15_R1.*; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_15_R1.block.CraftBlock; - -import java.util.Objects; - -public class BlockIdWrapper15 implements BlockIdWrapper { - @Override - public int blockToId(Block block) { - return net.minecraft.server.v1_15_R1.Block.REGISTRY_ID.getId(((CraftBlock)block).getNMS()); - } - - @Override - public void setBlock(World world, int x, int y, int z, int blockState) { - IBlockData blockData = Objects.requireNonNull(net.minecraft.server.v1_15_R1.Block.REGISTRY_ID.fromId(blockState)); - WorldServer cworld = ((CraftWorld)world).getHandle(); - BlockPosition pos = new BlockPosition(x, y, z); - cworld.removeTileEntity(pos); - cworld.setTypeAndData(pos, blockData, 1042); - cworld.getChunkProvider().flagDirty(pos); - } - - @Override - public Object getPose(boolean sneaking) { - return sneaking ? EntityPose.CROUCHING : EntityPose.STANDING; - } -} diff --git a/FightSystem_15/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper15.java b/FightSystem_15/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper15.java index 2fe700e..f06902b 100644 --- a/FightSystem_15/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper15.java +++ b/FightSystem_15/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper15.java @@ -25,14 +25,8 @@ import net.minecraft.server.v1_15_R1.Chunk; import org.bukkit.World; import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_15_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; public class CraftbukkitWrapper15 implements CraftbukkitWrapper { @@ -53,24 +47,11 @@ public class CraftbukkitWrapper15 implements CraftbukkitWrapper { chunk.heightMap.putAll(backupChunk.heightMap); } - @Override - public void sendResourcePack(Player player, String pack, String sha1) { - ((CraftPlayer)player).getHandle().setResourcePack(pack, sha1); - } - @Override public float headRotation(Entity e) { return ((CraftEntity)e).getHandle().getHeadRotation(); } - @Override - public boolean hasItems(ItemStack stack) { - Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().getKeys()); - keys.remove("Enchantments"); - keys.remove("Damage"); - return !keys.isEmpty(); - } - @Override public Stream entityIterator() { return ((CraftWorld) Config.world).getHandle().entitiesById.values().stream(); diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java deleted file mode 100644 index 23366db..0000000 --- a/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - 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 net.minecraft.core.BlockPosition; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.entity.EntityPose; -import net.minecraft.world.level.block.state.IBlockData; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_18_R2.block.CraftBlock; - -import java.util.Objects; - -public class BlockIdWrapper18 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 Object getPose(boolean sneaking) { - return sneaking ? EntityPose.f : EntityPose.a; - } -} diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java index de77d54..3a05921 100644 --- a/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java +++ b/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java @@ -19,53 +19,47 @@ package de.steamwar.fightsystem.utils; +import com.comphenix.tinyprotocol.Reflection; import de.steamwar.fightsystem.Config; +import net.minecraft.server.level.WorldServer; import net.minecraft.world.level.chunk.Chunk; +import net.minecraft.world.level.chunk.ChunkSection; +import net.minecraft.world.level.entity.LevelEntityGetter; import org.bukkit.World; -import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_18_R2.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 CraftbukkitWrapper18 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); + private static final Reflection.MethodInvoker getWorld = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle", net.minecraft.world.level.World.class); + private static final Reflection.MethodInvoker getChunk = Reflection.getTypedMethod(net.minecraft.world.level.World.class, null, Chunk.class, int.class, int.class); + private static final Reflection.MethodInvoker getChunkSections = Reflection.getTypedMethod(Chunk.class, null, ChunkSection[].class); + private ChunkSection[] getChunkSections(World world, int x, int z) { + return (ChunkSection[]) getChunkSections.invoke(getChunk.invoke(getWorld.invoke(world), x, z)); } @Override - public void sendResourcePack(Player player, String pack, String sha1) { - ((CraftPlayer)player).getHandle().a(pack, sha1, true, null); + public void resetChunk(World world, World backup, int x, int z) { + ChunkSection[] sections = getChunkSections(world, x, z); + System.arraycopy(getChunkSections(backup, x, z), 0, sections, 0, sections.length); + } + + private static final Reflection.MethodInvoker getEntity = Reflection.getTypedMethod(Reflection.getClass("{obc}.entity.CraftEntity"), "getHandle", net.minecraft.world.entity.Entity.class); + protected net.minecraft.world.entity.Entity getEntity(Entity e) { + return (net.minecraft.world.entity.Entity) getEntity.invoke(e); } @Override public float headRotation(Entity e) { - return ((CraftEntity)e).getHandle().ce(); - } - - @Override - public boolean hasItems(ItemStack stack) { - Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).t().d()); - keys.remove("Enchantments"); - keys.remove("Damage"); - return !keys.isEmpty(); + return getEntity(e).ce(); } + private static final Reflection.MethodInvoker getWorldEntities = Reflection.getTypedMethod(WorldServer.class, null, LevelEntityGetter.class); + private static final Reflection.MethodInvoker getIterable = Reflection.getTypedMethod(LevelEntityGetter.class, null, Iterable.class); @Override public Stream entityIterator() { - return StreamSupport.stream(((CraftWorld) Config.world).getHandle().H().a().spliterator(), false); + return StreamSupport.stream(((Iterable) getIterable.invoke(getWorldEntities.invoke(getWorld.invoke(Config.world)))).spliterator(), false); } } diff --git a/FightSystem_19/src/de/steamwar/fightsystem/utils/BlockIdWrapper19.java b/FightSystem_19/src/de/steamwar/fightsystem/utils/BlockIdWrapper19.java deleted file mode 100644 index dd251ac..0000000 --- a/FightSystem_19/src/de/steamwar/fightsystem/utils/BlockIdWrapper19.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - 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 net.minecraft.core.BlockPosition; -import net.minecraft.server.level.WorldServer; -import net.minecraft.world.entity.EntityPose; -import net.minecraft.world.level.block.state.IBlockData; -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.Objects; - -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 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 index 8c87581..1a18a2a 100644 --- a/FightSystem_19/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper19.java +++ b/FightSystem_19/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper19.java @@ -19,53 +19,12 @@ 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); - } +public class CraftbukkitWrapper19 extends CraftbukkitWrapper18 { @Override public float headRotation(Entity e) { - return ((CraftEntity)e).getHandle().cg(); - } - - @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); + return getEntity(e).ck(); } } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java index 06956c8..aedd2e8 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java @@ -37,9 +37,4 @@ public class BlockIdWrapper8 implements BlockIdWrapper { world.getBlockAt(x, y, z).setTypeIdAndData(blockState >> 4, (byte)(blockState & 0b1111), false); } - - @Override - public Object getPose(boolean sneaking) { - return Byte.valueOf((byte)(sneaking ? 2 : 0)); - } } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper8.java index 07d75e9..8d743ae 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper8.java @@ -24,14 +24,8 @@ import net.minecraft.server.v1_8_R3.Chunk; import org.bukkit.World; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_8_R3.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; public class CraftbukkitWrapper8 implements CraftbukkitWrapper { @@ -49,24 +43,11 @@ public class CraftbukkitWrapper8 implements CraftbukkitWrapper { chunk.tileEntities.putAll(backupChunk.tileEntities); } - @Override - public void sendResourcePack(Player player, String pack, String sha1) { - ((CraftPlayer)player).getHandle().setResourcePack(pack, sha1); - } - @Override public float headRotation(Entity e) { return ((CraftEntity)e).getHandle().getHeadRotation(); } - @Override - public boolean hasItems(ItemStack stack) { - Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c()); - keys.remove("Enchantments"); - keys.remove("Damage"); - return !keys.isEmpty(); - } - @Override public Stream entityIterator() { return ((CraftWorld) Config.world).getHandle().entityList.stream(); diff --git a/FightSystem_9/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper9.java b/FightSystem_9/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper9.java index 0873f8a..a0ddcd9 100644 --- a/FightSystem_9/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper9.java +++ b/FightSystem_9/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper9.java @@ -25,14 +25,8 @@ import net.minecraft.server.v1_9_R2.Chunk; import org.bukkit.World; import org.bukkit.craftbukkit.v1_9_R2.CraftWorld; import org.bukkit.craftbukkit.v1_9_R2.entity.CraftEntity; -import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_9_R2.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; public class CraftbukkitWrapper9 implements CraftbukkitWrapper { @@ -52,24 +46,11 @@ public class CraftbukkitWrapper9 implements CraftbukkitWrapper { chunk.tileEntities.putAll(backupChunk.tileEntities); } - @Override - public void sendResourcePack(Player player, String pack, String sha1) { - ((CraftPlayer)player).getHandle().setResourcePack(pack, sha1); - } - @Override public float headRotation(Entity e) { return ((CraftEntity)e).getHandle().getHeadRotation(); } - @Override - public boolean hasItems(ItemStack stack) { - Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c()); - keys.remove("Enchantments"); - keys.remove("Damage"); - return !keys.isEmpty(); - } - @Override public Stream entityIterator() { return ((CraftWorld) Config.world).getHandle().entityList.stream(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java index b8d2650..750941e 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java @@ -19,10 +19,8 @@ package de.steamwar.fightsystem.fight; -import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import com.mojang.authlib.GameProfile; -import de.steamwar.core.Core; import de.steamwar.core.ProtocolWrapper; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; @@ -34,9 +32,7 @@ import org.bukkit.Sound; import org.bukkit.entity.Player; import java.util.Collection; -import java.util.Collections; import java.util.HashSet; -import java.util.List; public class Fight { private Fight(){} @@ -146,22 +142,8 @@ public class Fight { } } - private static final Class playerInfoActionClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$EnumPlayerInfoAction"); - private static final Reflection.FieldAccessor playerInfoAction = Reflection.getField(ProtocolWrapper.playerInfoPacket, playerInfoActionClass, 0); - private static final Object updateGamemode = playerInfoActionClass.getEnumConstants()[1]; - private static final Reflection.FieldAccessor playerInfoData = Reflection.getField(ProtocolWrapper.playerInfoPacket, List.class, 0); - public static final Object creative = ProtocolWrapper.enumGamemode.getEnumConstants()[Core.getVersion() > 15 ? 1 : 2]; - private static final Object spectator = ProtocolWrapper.enumGamemode.getEnumConstants()[Core.getVersion() > 15 ? 3 : 4]; - public static void pseudoSpectator(Player player, boolean enable) { - TinyProtocol.instance.sendPacket(player, playerInfoPacket(updateGamemode, new GameProfile(player.getUniqueId(), player.getName()), enable ? creative : spectator)); - } - - public static Object playerInfoPacket(Object action, GameProfile profile, Object mode) { - Object packet = Reflection.newInstance(ProtocolWrapper.playerInfoPacket); - playerInfoAction.set(packet, action); - playerInfoData.set(packet, Collections.singletonList(ProtocolWrapper.impl.playerInfoDataConstructor(packet, profile, mode))); - return packet; + TinyProtocol.instance.sendPacket(player, ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.GAMEMODE, new GameProfile(player.getUniqueId(), player.getName()), enable ? GameMode.CREATIVE : GameMode.SPECTATOR)); } public static int getMaxRank(){ diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java index 4f0f60c..6c99696 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java @@ -19,12 +19,12 @@ package de.steamwar.fightsystem.fight; +import com.comphenix.tinyprotocol.Reflection; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.commands.Commands; import de.steamwar.fightsystem.commands.GUI; import de.steamwar.fightsystem.listener.PersonalKitCreator; -import de.steamwar.fightsystem.utils.CraftbukkitWrapper; import de.steamwar.fightsystem.utils.FlatteningWrapper; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; @@ -211,7 +211,7 @@ public class Kit { if(FlatteningWrapper.impl.containsBlockMeta(meta)) return true; //Blocks always upwards slabs etc. - if(CraftbukkitWrapper.impl.hasItems(stack)) + if(hasItems(stack)) return true; //Blocks prefilled inventories } @@ -220,6 +220,18 @@ public class Kit { return !normal.isEnchantmentInKit(stack) && !stack.getEnchantments().isEmpty(); } + private static final Class itemStack = Reflection.getClass("{nms.world.item}.ItemStack"); + private static final Reflection.MethodInvoker asNMSCopy = Reflection.getTypedMethod(Reflection.getClass("{obc}.inventory.CraftItemStack"), "asNMSCopy", itemStack, ItemStack.class); + private static final Class nbtTagCompound = Reflection.getClass("{nms.nbt}.NBTTagCompound"); + private static final Reflection.MethodInvoker getTag = Reflection.getTypedMethod(itemStack, null, nbtTagCompound); + private static final Reflection.MethodInvoker getKeys = Reflection.getTypedMethod(nbtTagCompound, null, Set.class); + public static boolean hasItems(ItemStack stack) { + Set keys = new HashSet<>((Set) getKeys.invoke(getTag.invoke(asNMSCopy.invoke(null, stack)))); + keys.remove("Enchantments"); + keys.remove("Damage"); + return !keys.isEmpty(); + } + private boolean isEnchantmentInKit(ItemStack stack){ for(ItemStack is : inventory){ if(similar(stack, is)) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java index 74f7a46..6cda218 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java @@ -29,6 +29,4 @@ public interface BlockIdWrapper { int blockToId(Block block); void setBlock(World world, int x, int y, int z, int blockState); - - Object getPose(boolean sneaking); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper.java index 1771d79..242119f 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper.java @@ -23,8 +23,6 @@ import de.steamwar.core.VersionDependent; import de.steamwar.fightsystem.FightSystem; import org.bukkit.World; import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; import java.util.stream.Stream; @@ -32,9 +30,7 @@ public interface CraftbukkitWrapper { CraftbukkitWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); void resetChunk(World world, World backup, int x, int z); - void sendResourcePack(Player player, String pack, String sha1); float headRotation(Entity e); - boolean hasItems(ItemStack stack); Stream entityIterator(); } -- 2.39.2 From 410c9fd3d06056097528afd2fe03c91e3754b502 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 1 Mar 2023 22:17:12 +0100 Subject: [PATCH 2/2] Fix getHandle Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java index 3a05921..72c14f8 100644 --- a/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java +++ b/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java @@ -33,7 +33,7 @@ import java.util.stream.StreamSupport; public class CraftbukkitWrapper18 implements CraftbukkitWrapper { - private static final Reflection.MethodInvoker getWorld = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle", net.minecraft.world.level.World.class); + private static final Reflection.MethodInvoker getWorld = Reflection.getMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle"); private static final Reflection.MethodInvoker getChunk = Reflection.getTypedMethod(net.minecraft.world.level.World.class, null, Chunk.class, int.class, int.class); private static final Reflection.MethodInvoker getChunkSections = Reflection.getTypedMethod(Chunk.class, null, ChunkSection[].class); private ChunkSection[] getChunkSections(World world, int x, int z) { -- 2.39.2