From f29bf025e6aa125b5e05b0a7e9b618992a080a1b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 3 Feb 2023 11:59:39 +0100 Subject: [PATCH 01/16] 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(); } From ded764002f5ef73ecf1488a317a15f51c7989277 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 1 Mar 2023 17:03:43 +0100 Subject: [PATCH 02/16] Fix modifying other inventories in PersonalKitCreator Signed-off-by: Lixfel --- .../fightsystem/listener/PersonalKitCreator.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java index c9c2dd4..f9a3b2d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java @@ -37,6 +37,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryAction; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; @@ -108,6 +109,15 @@ public class PersonalKitCreator implements Listener { backup.close(); } + @EventHandler + public void onOpenEvent(InventoryOpenEvent e){ + InventoryBackup backup = openKitCreators.get(e.getPlayer()); + if(backup == null) + return; + + backup.close(); + } + @EventHandler public void onInventoryClose(InventoryCloseEvent e) { InventoryBackup backup = openKitCreators.get(e.getPlayer()); From 704f79a166f368e0cf3a98ac0182814d209a6795 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 1 Mar 2023 20:00:32 +0100 Subject: [PATCH 03/16] Fix arena border, piston border, and y-Damage Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/Config.java | 10 ++--- .../fightsystem/listener/ArenaBorder.java | 39 ++++++++++--------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index 8d28cfa..423a9c3 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -61,6 +61,7 @@ public class Config { public static final Region BlueExtendRegion; public static final Region RedExtendRegion; public static final Region ArenaRegion; + public static final Region PlayerRegion; public static final Location TeamBlueSpawn; public static final Location TeamRedSpawn; @@ -300,14 +301,13 @@ public class Config { RedRotate = teamRedRotate; BlueRotate = teamBlueRotate; - int arenaYSize = blueCornerY - underBorder + schemsizeY + PreperationArea; - RedPasteRegion = new Region(teamRedCornerX, teamRedCornerY, teamRedCornerZ, schemsizeX, schemsizeY, schemsizeZ); BluePasteRegion = new Region(blueCornerX, blueCornerY, blueCornerZ, schemsizeX, schemsizeY, schemsizeZ); - RedExtendRegion = new Region(teamRedCornerX, teamRedCornerY, teamRedCornerZ, schemsizeX, arenaYSize, schemsizeZ, PreperationArea, PreperationArea, PreperationArea); - BlueExtendRegion = new Region(blueCornerX, blueCornerY, blueCornerZ, schemsizeX, arenaYSize, schemsizeZ, PreperationArea, PreperationArea, PreperationArea); - ArenaRegion = new Region(arenaMinX, underBorder, arenaMinZ, arenaMaxX - arenaMinX, arenaYSize, arenaMaxZ - arenaMinZ); + RedExtendRegion = new Region(teamRedCornerX, teamRedCornerY, teamRedCornerZ, schemsizeX, schemsizeY, schemsizeZ, PreperationArea, PreperationArea, PreperationArea); + BlueExtendRegion = new Region(blueCornerX, blueCornerY, blueCornerZ, schemsizeX, schemsizeY, schemsizeZ, PreperationArea, PreperationArea, PreperationArea); + ArenaRegion = new Region(arenaMinX, blueCornerY, arenaMinZ, arenaMaxX - arenaMinX, schemsizeY, arenaMaxZ - arenaMinZ, 0, PreperationArea, 0); + PlayerRegion = new Region(arenaMinX, underBorder, arenaMinZ, arenaMaxX - arenaMinX, world.getMaxHeight() - underBorder, arenaMaxZ - arenaMinZ); EventKampfID = Integer.parseInt(System.getProperty("fightID", "0")); if(EventKampfID >= 1){ diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArenaBorder.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArenaBorder.java index 600a798..9eab82d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArenaBorder.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArenaBorder.java @@ -26,7 +26,9 @@ import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; +import de.steamwar.fightsystem.states.StateDependentTask; import net.md_5.bungee.api.ChatMessageType; +import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -38,40 +40,39 @@ public class ArenaBorder implements Listener { public ArenaBorder() { new StateDependentListener(ArenaMode.All, FightState.All, this); + new StateDependentTask(ArenaMode.All, FightState.Running, this::damage, 2, 2); } @EventHandler public void arenaBorder(PlayerMoveEvent event){ Player player = event.getPlayer(); - if(Config.ArenaLeaveable && !Fight.fighting(player)) + FightTeam team = Fight.getPlayerTeam(player); + + if(Config.ArenaLeaveable && team == null) return; Location to = event.getTo(); assert to != null; - if(!Config.ArenaRegion.in2dRegion(to)){ - reset(event); + if(Config.PlayerRegion.inRegion(to)) return; - } - FightTeam team = Fight.getPlayerTeam(player); - if(team == null || player.getGameMode() == GameMode.SPECTATOR){ - if(to.getY() <= Config.ArenaRegion.getMinY()) - reset(event); - return; - } - - if(to.getY() <= Config.ArenaRegion.getMinY()) { - if(FightState.infight()) - player.damage(2); - else if(!Config.GroundWalkable) + if(to.getY() <= Config.PlayerRegion.getMinY() && player.getGameMode() != GameMode.SPECTATOR && team != null) { + if(!Config.GroundWalkable && !FightState.infight()) player.teleport(team.getSpawn()); - } - } - private void reset(PlayerMoveEvent event){ - Player player = event.getPlayer(); + return; + } + player.teleport(event.getFrom()); FightSystem.getMessage().sendPrefixless("NO_ARENA_LEAVING", player, ChatMessageType.ACTION_BAR); } + + private void damage() { + for(Player player : Bukkit.getServer().getOnlinePlayers()) { + FightTeam team = Fight.getPlayerTeam(player); + if(team != null && player.getLocation().getY() <= Config.PlayerRegion.getMinY()) + player.damage(1); + } + } } From 410c9fd3d06056097528afd2fe03c91e3754b502 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 1 Mar 2023 22:17:12 +0100 Subject: [PATCH 04/16] 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) { From 10f8e597f886fda2df23217134389caaa127eb3e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 4 Mar 2023 07:32:03 +0100 Subject: [PATCH 05/16] Add spectate team to hide nametags Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/FightTeam.java | 9 ++++----- .../steamwar/fightsystem/listener/FightScoreboard.java | 10 ++++++++-- .../de/steamwar/fightsystem/listener/Permanent.java | 7 +++++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 47ba81f..dac4135 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -26,6 +26,7 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.commands.GUI; import de.steamwar.fightsystem.countdown.Countdown; import de.steamwar.fightsystem.listener.FightScoreboard; +import de.steamwar.fightsystem.listener.Permanent; import de.steamwar.fightsystem.listener.PersonalKitCreator; import de.steamwar.fightsystem.record.GlobalRecorder; import de.steamwar.fightsystem.states.FightState; @@ -121,11 +122,7 @@ public class FightTeam { new KitLoader(); new SpectateHandler(); - if(FightScoreboard.getBukkit().getTeam(name) == null) - team = FightScoreboard.getBukkit().registerNewTeam(name); - else - team = FightScoreboard.getBukkit().getTeam(name); - assert team != null; + team = FightScoreboard.getBukkitTeam(name); WorldOfColorWrapper.impl.setTeamColor(team, color); BountifulWrapper.impl.setNametagVisibility(team); team.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OTHER_TEAMS); @@ -252,6 +249,7 @@ public class FightTeam { FightPlayer fightPlayer = new FightPlayer(player, this); players.put(player, fightPlayer); invited.remove(player); + Permanent.getSpectatorTeam().removeEntry(player.getName()); team.addEntry(player.getName()); Fight.setPlayerGamemode(player, GameMode.SURVIVAL); @@ -277,6 +275,7 @@ public class FightTeam { List chunksToReload = FightSystem.getTechHider().prepareChunkReload(player, true); players.remove(player); team.removeEntry(player.getName()); + Permanent.getSpectatorTeam().addEntry(player.getName()); FightUI.addSubtitle("UI_PLAYER_LEAVES", prefix, player.getName()); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/FightScoreboard.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/FightScoreboard.java index 957f085..63ca402 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/FightScoreboard.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/FightScoreboard.java @@ -30,14 +30,20 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.scoreboard.Scoreboard; +import org.bukkit.scoreboard.Team; import java.util.HashMap; import java.util.Objects; public class FightScoreboard implements Listener, ScoreboardCallback { - public static Scoreboard getBukkit() { - return Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard(); + public static Team getBukkitTeam(String name) { + Scoreboard scoreboard = Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard(); + Team team = scoreboard.getTeam(name); + if(team != null) + return team; + + return scoreboard.registerNewTeam(name); } private static FightScoreboard scoreboard; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java index d10c7c8..64aa91a 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java @@ -46,9 +46,15 @@ import org.bukkit.event.inventory.InventoryPickupItemEvent; import org.bukkit.event.player.*; import org.bukkit.event.weather.WeatherChangeEvent; import org.bukkit.event.world.WorldLoadEvent; +import org.bukkit.scoreboard.Team; public class Permanent implements Listener { + private static final Team spectatorTeam = FightScoreboard.getBukkitTeam("Spectator"); + public static Team getSpectatorTeam() { + return spectatorTeam; + } + public Permanent() { new StateDependentListener(ArenaMode.All, FightState.All, this); } @@ -81,6 +87,7 @@ public class Permanent implements Listener { if (!Config.ArenaLeaveable && !Fight.fighting(player)) { Fight.setPlayerGamemode(player, GameMode.SPECTATOR); + spectatorTeam.addEntry(player.getName()); player.teleport(Config.SpecSpawn); } } From d7348befbc54852874c44b43f218bdcd3f6e0b5d Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 4 Mar 2023 11:36:03 +0100 Subject: [PATCH 06/16] Fix Nametags in Replay spectate mode Signed-off-by: Lixfel --- .../fightsystem/record/PacketProcessor.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index e1a73ac..11632ee 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -56,6 +56,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitTask; +import org.bukkit.scoreboard.NameTagVisibility; import java.io.EOFException; import java.io.FilterInputStream; @@ -66,16 +67,11 @@ import java.util.stream.Collectors; public class PacketProcessor implements Listener { - /*private static final String SCOREBOARD_TEAMNAME = "Replay"; - private static final Team team; - + private static final org.bukkit.scoreboard.Team team = FightScoreboard.getBukkitTeam("Replay"); static { - if(FightScoreboard.getBukkit().getTeam(SCOREBOARD_TEAMNAME) == null) - team = FightScoreboard.getBukkit().registerNewTeam(SCOREBOARD_TEAMNAME); - else - team = FightScoreboard.getBukkit().getTeam(SCOREBOARD_TEAMNAME); + BountifulWrapper.impl.setNametagVisibility(team); team.setNameTagVisibility(NameTagVisibility.NEVER); - }*/ + } private static PacketProcessor currentProcessor = null; @@ -239,6 +235,7 @@ public class PacketProcessor implements Listener { execSync(() -> { SteamwarUser user = SteamwarUser.get(userId); entities.put(entityId, new RPlayer(entityServer, user.getUUID(), user.getUserName(), Config.SpecSpawn)); + team.addEntry(user.getUserName()); }); } From b8199eb04d67b10aaef60f6a752603a70c1e1d36 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 4 Mar 2023 12:10:33 +0100 Subject: [PATCH 07/16] Fix ConcurrentModificationException Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/record/PacketProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index 11632ee..2ca450d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -612,7 +612,7 @@ public class PacketProcessor implements Listener { } private void tick(){ - entityServer.tick(); + execSync(entityServer::tick); if(!source.async() && !skipToSubtitle) tickFinished = true; From e2e677c7890f442ae9a2b24bfedfe4487f7da665 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 4 Mar 2023 13:10:30 +0100 Subject: [PATCH 08/16] Fix Arenas below 0 in Replays Signed-off-by: Lixfel --- .../steamwar/fightsystem/record/PacketProcessor.java | 12 ++++++++++-- .../src/de/steamwar/fightsystem/record/Recorder.java | 6 +++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index 2ca450d..d7c31fd 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -121,7 +121,8 @@ public class PacketProcessor implements Listener { packetDecoder[0x0a] = this::bow; packetDecoder[0x0b] = this::damage; packetDecoder[0x0c] = this::fireTick; - packetDecoder[0x20] = this::arenaInfo; + packetDecoder[0x20] = this::oldArenaInfo; + packetDecoder[0x21] = this::arenaInfo; packetDecoder[0x30] = this::byteWorldHeightBlock; packetDecoder[0x31] = this::particle; packetDecoder[0x32] = this::sound; @@ -367,13 +368,20 @@ public class PacketProcessor implements Listener { Bukkit.getOnlinePlayers().forEach(p -> Countdown.sendCountdownMessage(p, message, displaytime, appendix)); } - private void arenaInfo() throws IOException { + private void oldArenaInfo() throws IOException { rotateZ = source.readBoolean() != Config.blueNegZ(); arenaMinY = Byte.toUnsignedInt(source.readByte()); arenaMinX = source.readInt(); arenaMinZ = source.readInt(); } + private void arenaInfo() throws IOException { + rotateZ = source.readBoolean() != Config.blueNegZ(); + arenaMinX = source.readInt(); + arenaMinY = source.readInt(); + arenaMinZ = source.readInt(); + } + private void shortBlock() throws IOException { int x = Byte.toUnsignedInt(source.readByte()) + Config.ArenaRegion.getMinX(); int y = Byte.toUnsignedInt(source.readByte()); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java index 39cc43f..2b5f3c7 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java @@ -98,7 +98,8 @@ public interface Recorder { * PlayerDamagePacket (0x0b) + int EntityId * SetOnFire (0x0c) + int EntityId + boolean perma * - * ArenaInfo (0x20) + bool blueNegZ + byte arenaY + int arenaMinX + int arenaMinZ + * DEPRECATED ArenaInfo (0x20) + bool blueNegZ + byte arenaY + int arenaMinX + int arenaMinZ + * ArenaInfo (0x21) + bool blueNegZ + int arenaMinX + int arenaMinY + int arenaMinZ * * DEPRECATED BlockPacket (0x30) + pos int, byte, int + int BlockState * ParticlePacket (0x31) + double x, y, z + string particleType @@ -213,8 +214,7 @@ public interface Recorder { } default void arenaInfo(){ - write(0x20, Config.blueNegZ(), (byte)Config.BluePasteRegion.getMinY(), - Config.ArenaRegion.getMinX(), Config.ArenaRegion.getMinZ()); + write(0x21, Config.blueNegZ(), Config.ArenaRegion.getMinX(), Config.BluePasteRegion.getMinY(), Config.ArenaRegion.getMinZ()); } default void blockChange(Block block){ From cb9b757369d53dd340abf5345555d12b4ff11517 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 4 Mar 2023 13:18:49 +0100 Subject: [PATCH 09/16] Fix Spectate Nametags Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/record/PacketProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index d7c31fd..5d61268 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -70,7 +70,7 @@ public class PacketProcessor implements Listener { private static final org.bukkit.scoreboard.Team team = FightScoreboard.getBukkitTeam("Replay"); static { BountifulWrapper.impl.setNametagVisibility(team); - team.setNameTagVisibility(NameTagVisibility.NEVER); + team.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OTHER_TEAMS); } private static PacketProcessor currentProcessor = null; From 5f7faabbff9985b5eb19a0aabc2d69cce9cf8e2f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 11 Mar 2023 19:49:02 +0100 Subject: [PATCH 10/16] Hotfix click recording Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/listener/ClickAnalyzer.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java index bf0ea32..9aea4b2 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java @@ -43,7 +43,9 @@ public class ClickAnalyzer { } public Object onBlockPlace(Player player, Object packet) { - output.println(player.getName() + "," + System.nanoTime() + "," + CraftbukkitWrapper.impl.headRotation(player) + "," + player.getLocation().getPitch()); + synchronized(output) { + output.println(player.getName() + "," + System.nanoTime() + "," + CraftbukkitWrapper.impl.headRotation(player) + "," + player.getLocation().getPitch()); + } return packet; } From b9e87de241c7735909726fcf69641c51471ae148 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 11 Mar 2023 19:56:44 +0100 Subject: [PATCH 11/16] Hotfix click recording Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/listener/ClickAnalyzer.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java index 9aea4b2..73e2afa 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java @@ -19,7 +19,9 @@ package de.steamwar.fightsystem.listener; +import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; +import de.steamwar.core.Core; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.utils.CraftbukkitWrapper; import org.bukkit.entity.Player; @@ -40,6 +42,8 @@ public class ClickAnalyzer { public ClickAnalyzer() { TinyProtocol.instance.addFilter(Recording.blockPlacePacket, this::onBlockPlace); + if(Core.getVersion() > 8) + TinyProtocol.instance.addFilter(Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem"), this::onBlockPlace); } public Object onBlockPlace(Player player, Object packet) { From 301a51bcd9a7357287d4ef26bf563e89d1f00660 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 11 Mar 2023 20:43:47 +0100 Subject: [PATCH 12/16] Delay Team adding Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/FightTeam.java | 2 +- .../src/de/steamwar/fightsystem/listener/Permanent.java | 3 ++- .../src/de/steamwar/fightsystem/record/PacketProcessor.java | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index dac4135..c870054 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -250,7 +250,7 @@ public class FightTeam { players.put(player, fightPlayer); invited.remove(player); Permanent.getSpectatorTeam().removeEntry(player.getName()); - team.addEntry(player.getName()); + Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> team.addEntry(player.getName()), 2); Fight.setPlayerGamemode(player, GameMode.SURVIVAL); player.setHealth(20); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java index 64aa91a..1ce0c82 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java @@ -28,6 +28,7 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.utils.FlatteningWrapper; import net.md_5.bungee.api.ChatMessageType; +import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.block.Block; @@ -87,7 +88,7 @@ public class Permanent implements Listener { if (!Config.ArenaLeaveable && !Fight.fighting(player)) { Fight.setPlayerGamemode(player, GameMode.SPECTATOR); - spectatorTeam.addEntry(player.getName()); + Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> spectatorTeam.addEntry(player.getName()), 2); player.teleport(Config.SpecSpawn); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index 5d61268..893d2b3 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -236,7 +236,7 @@ public class PacketProcessor implements Listener { execSync(() -> { SteamwarUser user = SteamwarUser.get(userId); entities.put(entityId, new RPlayer(entityServer, user.getUUID(), user.getUserName(), Config.SpecSpawn)); - team.addEntry(user.getUserName()); + Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> team.addEntry(user.getUserName()), 2); }); } From bdb708a7a871d8e6bba8355d81c75dc9988bd95b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 11 Mar 2023 21:05:58 +0100 Subject: [PATCH 13/16] Fix ReplayServer race condition Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/record/FileSource.java | 1 + .../src/de/steamwar/fightsystem/record/LiveSource.java | 1 + .../src/de/steamwar/fightsystem/record/PacketSource.java | 1 - 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/FileSource.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/FileSource.java index 0536b01..2fcaa59 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/FileSource.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/FileSource.java @@ -50,6 +50,7 @@ public class FileSource extends PacketSource { public FileSource(File fightFile) throws IOException { super(new GZIPInputStream(new FileInputStream(fightFile))); + new PacketProcessor(this); } @Override diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/LiveSource.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/LiveSource.java index 3a1fad5..313ff85 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/LiveSource.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/LiveSource.java @@ -31,6 +31,7 @@ public class LiveSource extends PacketSource { protected LiveSource(Socket socket) throws IOException { super(socket.getInputStream()); this.socket = socket; + new PacketProcessor(this); } @Override diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketSource.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketSource.java index 855959f..e3d994c 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketSource.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketSource.java @@ -30,7 +30,6 @@ public abstract class PacketSource extends DataInputStream { protected PacketSource(InputStream inputStream){ super(inputStream); - new PacketProcessor(this); } @Override From 896665a405034937832c896581f7de3ba58f36a5 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 11 Mar 2023 21:14:19 +0100 Subject: [PATCH 14/16] Fix NametagVisibility Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/listener/Permanent.java | 7 +++++++ .../de/steamwar/fightsystem/record/PacketProcessor.java | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java index 1ce0c82..a9e961d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java @@ -26,6 +26,7 @@ import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; +import de.steamwar.fightsystem.utils.BountifulWrapper; import de.steamwar.fightsystem.utils.FlatteningWrapper; import net.md_5.bungee.api.ChatMessageType; import org.bukkit.Bukkit; @@ -47,11 +48,17 @@ import org.bukkit.event.inventory.InventoryPickupItemEvent; import org.bukkit.event.player.*; import org.bukkit.event.weather.WeatherChangeEvent; import org.bukkit.event.world.WorldLoadEvent; +import org.bukkit.scoreboard.NameTagVisibility; import org.bukkit.scoreboard.Team; public class Permanent implements Listener { private static final Team spectatorTeam = FightScoreboard.getBukkitTeam("Spectator"); + static { + BountifulWrapper.impl.setNametagVisibility(spectatorTeam); + spectatorTeam.setNameTagVisibility(NameTagVisibility.NEVER); + } + public static Team getSpectatorTeam() { return spectatorTeam; } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index 893d2b3..c26b0c9 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -70,7 +70,7 @@ public class PacketProcessor implements Listener { private static final org.bukkit.scoreboard.Team team = FightScoreboard.getBukkitTeam("Replay"); static { BountifulWrapper.impl.setNametagVisibility(team); - team.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OTHER_TEAMS); + team.setNameTagVisibility(NameTagVisibility.NEVER); } private static PacketProcessor currentProcessor = null; From 98cd6f5b259e0560254bf98dc1e9842919808008 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 11 Mar 2023 21:46:33 +0100 Subject: [PATCH 15/16] Remove delay Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/FightTeam.java | 2 +- .../src/de/steamwar/fightsystem/listener/Permanent.java | 3 +-- .../src/de/steamwar/fightsystem/record/PacketProcessor.java | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index c870054..dac4135 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -250,7 +250,7 @@ public class FightTeam { players.put(player, fightPlayer); invited.remove(player); Permanent.getSpectatorTeam().removeEntry(player.getName()); - Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> team.addEntry(player.getName()), 2); + team.addEntry(player.getName()); Fight.setPlayerGamemode(player, GameMode.SURVIVAL); player.setHealth(20); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java index a9e961d..6e60e48 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java @@ -29,7 +29,6 @@ import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.utils.BountifulWrapper; import de.steamwar.fightsystem.utils.FlatteningWrapper; import net.md_5.bungee.api.ChatMessageType; -import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.block.Block; @@ -95,7 +94,7 @@ public class Permanent implements Listener { if (!Config.ArenaLeaveable && !Fight.fighting(player)) { Fight.setPlayerGamemode(player, GameMode.SPECTATOR); - Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> spectatorTeam.addEntry(player.getName()), 2); + spectatorTeam.addEntry(player.getName()); player.teleport(Config.SpecSpawn); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index c26b0c9..d7c31fd 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -236,7 +236,7 @@ public class PacketProcessor implements Listener { execSync(() -> { SteamwarUser user = SteamwarUser.get(userId); entities.put(entityId, new RPlayer(entityServer, user.getUUID(), user.getUserName(), Config.SpecSpawn)); - Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> team.addEntry(user.getUserName()), 2); + team.addEntry(user.getUserName()); }); } From 70d4f96999c7d0b0177fe27a4acdebbf723d0421 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 11 Apr 2023 11:00:24 +0200 Subject: [PATCH 16/16] Unlimited preparation phase option Signed-off-by: Lixfel --- FightSystem_Core/src/config.yml | 2 ++ FightSystem_Core/src/de/steamwar/fightsystem/Config.java | 2 ++ .../de/steamwar/fightsystem/countdown/PostSchemCountdown.java | 3 +++ 3 files changed, 7 insertions(+) diff --git a/FightSystem_Core/src/config.yml b/FightSystem_Core/src/config.yml index 14a9fed..350f6df 100644 --- a/FightSystem_Core/src/config.yml +++ b/FightSystem_Core/src/config.yml @@ -72,6 +72,8 @@ Schematic: ReplaceObsidianBedrock: false # defaults to false if missing # If the replacement should happen with block updates ReplaceWithBlockupdates: false # defaults to false if missing + # If the schematic perparation arena mode is time limited + UnlimitedPrepare: false # defaults to false if missing # Maximal amount of blocks allowed in the schematic MaxBlocks: 0 # defaults to 0 (ignored) if missing # Maximal amount of items per dispenser diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index 423a9c3..2632f0b 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -88,6 +88,7 @@ public class Config { public static final boolean PasteAligned; public static final boolean ReplaceObsidianBedrock; public static final boolean ReplaceWithBlockupdates; + public static final boolean UnlimitedPrepare; //team parameter public static final String TeamRedName; @@ -185,6 +186,7 @@ public class Config { PasteAligned = config.getBoolean("Schematic.PasteAligned", false); ReplaceObsidianBedrock = config.getBoolean("Schematic.ReplaceObsidianBedrock", false); ReplaceWithBlockupdates = config.getBoolean("Schematic.ReplaceWithBlockupdates", false); + UnlimitedPrepare = config.getBoolean("Schematic.UnlimitedPrepare", false); GameName = config.getString("GameName", "WarGear"); TeamChatDetection = config.getString("TeamChatPrefix", "+"); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java index 877dfe0..cb5f2db 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java @@ -29,6 +29,9 @@ public class PostSchemCountdown extends Countdown { public PostSchemCountdown() { super(Config.SetupDuration, new Message("POST_SCHEM_COUNTDOWN"), null, false); + if(Config.mode == ArenaMode.PREPARE && Config.UnlimitedPrepare) + return; + new StateDependentCountdown(ArenaMode.SeriousFight, FightState.PostSchemSetup, this); }