From f9966c3377983cb21158f067bb637f66ca11ad97 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 14 Nov 2020 20:32:47 +0100 Subject: [PATCH 01/15] Fix Seat problem --- .../spectatesystem/listener/PlayerSeatListener.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/spectatesystem/listener/PlayerSeatListener.java b/src/de/steamwar/spectatesystem/listener/PlayerSeatListener.java index 8b9183d..212e1a4 100644 --- a/src/de/steamwar/spectatesystem/listener/PlayerSeatListener.java +++ b/src/de/steamwar/spectatesystem/listener/PlayerSeatListener.java @@ -20,6 +20,8 @@ package de.steamwar.spectatesystem.listener; import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.block.data.Bisected; import org.bukkit.block.data.type.Stairs; import org.bukkit.entity.AbstractArrow; @@ -49,7 +51,11 @@ public class PlayerSeatListener extends BasicListener { if(event.getPlayer().isInsideVehicle()) event.getPlayer().getVehicle().remove(); - Arrow arrow = (Arrow) event.getPlayer().getWorld().spawnEntity(event.getClickedBlock().getLocation().add(0.5, 0, 0.5), EntityType.ARROW); + Location location = event.getClickedBlock().getLocation(); + if (location.getWorld().getBlockAt(location.getBlockX(), location.getBlockY() + 1, location.getBlockZ()).getType() == Material.AIR) + return; + + Arrow arrow = (Arrow) event.getPlayer().getWorld().spawnEntity(location.add(0.5, 0, 0.5), EntityType.ARROW); arrow.setGravity(false); arrow.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED); arrow.addPassenger(event.getPlayer()); From be105ac77055efaf4917e93ac34077961203c820 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 15 Nov 2020 08:40:01 +0100 Subject: [PATCH 02/15] Fix Air Problem --- src/de/steamwar/spectatesystem/listener/PlayerSeatListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/spectatesystem/listener/PlayerSeatListener.java b/src/de/steamwar/spectatesystem/listener/PlayerSeatListener.java index 212e1a4..35389fb 100644 --- a/src/de/steamwar/spectatesystem/listener/PlayerSeatListener.java +++ b/src/de/steamwar/spectatesystem/listener/PlayerSeatListener.java @@ -52,7 +52,7 @@ public class PlayerSeatListener extends BasicListener { event.getPlayer().getVehicle().remove(); Location location = event.getClickedBlock().getLocation(); - if (location.getWorld().getBlockAt(location.getBlockX(), location.getBlockY() + 1, location.getBlockZ()).getType() == Material.AIR) + if (location.getWorld().getBlockAt(location.getBlockX(), location.getBlockY() + 1, location.getBlockZ()).getType() != Material.AIR) return; Arrow arrow = (Arrow) event.getPlayer().getWorld().spawnEntity(location.add(0.5, 0, 0.5), EntityType.ARROW); From a3d7376d546555673548beed5cbf49b9372f01a4 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 15 Nov 2020 08:41:29 +0100 Subject: [PATCH 03/15] Simplify PlayerSeatListener --- .../spectatesystem/listener/PlayerSeatListener.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/spectatesystem/listener/PlayerSeatListener.java b/src/de/steamwar/spectatesystem/listener/PlayerSeatListener.java index 35389fb..0e84497 100644 --- a/src/de/steamwar/spectatesystem/listener/PlayerSeatListener.java +++ b/src/de/steamwar/spectatesystem/listener/PlayerSeatListener.java @@ -50,12 +50,11 @@ public class PlayerSeatListener extends BasicListener { if(event.getPlayer().isInsideVehicle()) event.getPlayer().getVehicle().remove(); - - Location location = event.getClickedBlock().getLocation(); - if (location.getWorld().getBlockAt(location.getBlockX(), location.getBlockY() + 1, location.getBlockZ()).getType() != Material.AIR) + + if (event.getClickedBlock().getRelative(0, 1, 0).getType() != Material.AIR) return; - Arrow arrow = (Arrow) event.getPlayer().getWorld().spawnEntity(location.add(0.5, 0, 0.5), EntityType.ARROW); + Arrow arrow = (Arrow) event.getPlayer().getWorld().spawnEntity(event.getClickedBlock().getLocation().add(0.5, 0, 0.5), EntityType.ARROW); arrow.setGravity(false); arrow.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED); arrow.addPassenger(event.getPlayer()); From 1c1b55efac951353b3198ee1b86cda8e0fe90f54 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 15 Nov 2020 11:22:18 +0100 Subject: [PATCH 04/15] Fix dependency messages --- src/plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugin.yml b/src/plugin.yml index 8cd1a66..cb71967 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -5,7 +5,7 @@ version: "1.0" api-version: "1.13" main: de.steamwar.spectatesystem.SpectateSystem load: POSTWORLD -depends: +depend: - SpigotCore - WorldEdit - ProtocolLib From 4fa02d12962db8191eee9e54a428cf6fdc2d8d93 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 15 Nov 2020 12:08:58 +0100 Subject: [PATCH 05/15] Fix CME --- .../spectatesystem/elements/REntity.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/de/steamwar/spectatesystem/elements/REntity.java b/src/de/steamwar/spectatesystem/elements/REntity.java index 7225343..ff5dedc 100644 --- a/src/de/steamwar/spectatesystem/elements/REntity.java +++ b/src/de/steamwar/spectatesystem/elements/REntity.java @@ -41,7 +41,9 @@ public abstract class REntity { protected REntity(int internalId, Entity entity){ this.internalId = internalId; this.entity = entity; - entities.put(internalId, this); + synchronized(entities){ + entities.put(internalId, this); + } for(Player player : Bukkit.getOnlinePlayers()){ sendToPlayer(player); @@ -49,17 +51,15 @@ public abstract class REntity { } public static void playerJoins(Player player){ - for(REntity entity : entities.values()){ - entity.sendToPlayer(player); - entity.sendLocation(player); + synchronized(entities){ + for(REntity entity : entities.values()){ + entity.sendToPlayer(player); + entity.sendLocation(player); + } } } protected static EntityLiving getShooter(){ - for(REntity entity : entities.values()){ - if(entity.entity instanceof EntityLiving) - return (EntityLiving) entity.entity; - } return ((CraftPlayer)Bukkit.getOnlinePlayers().iterator().next()).getHandle(); } @@ -69,10 +69,12 @@ public abstract class REntity { public static void removeAll(){ int entity_counter = 0; - while(!entities.isEmpty()){ - entity_counter++; - REntity entity = entities.values().iterator().next(); - entity.remove(); + synchronized (entities){ + while(!entities.isEmpty()){ + entity_counter++; + REntity entity = entities.values().iterator().next(); + entity.remove(); + } } System.out.println("Has to remove manually " + entity_counter + " entities!"); } @@ -96,7 +98,9 @@ public abstract class REntity { connection.sendPacket(packet); } Bukkit.getScheduler().runTask(SpectateSystem.get(), entity::die); - entities.remove(internalId); + synchronized (entities){ + entities.remove(internalId); + } } public void sneak(boolean sneaking) { From d71cb738c72f9bc8699113d8a56268a8dbd8b4ec Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 18 Nov 2020 09:22:29 +0100 Subject: [PATCH 06/15] Change to info --- src/de/steamwar/spectatesystem/ConnectionAcceptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/spectatesystem/ConnectionAcceptor.java b/src/de/steamwar/spectatesystem/ConnectionAcceptor.java index 97d00c2..66e62c0 100644 --- a/src/de/steamwar/spectatesystem/ConnectionAcceptor.java +++ b/src/de/steamwar/spectatesystem/ConnectionAcceptor.java @@ -48,7 +48,7 @@ public class ConnectionAcceptor { new FightserverConnection(socket.accept()); } } catch (IOException e) { - Bukkit.getLogger().log(Level.WARNING, "Stopping accepting connections", e); + Bukkit.getLogger().log(Level.INFO, "Stopping accepting connections", e); } } } From b73052c5e068ef70be102d0a4edf7e0d3e28a9f5 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 20 Mar 2021 12:01:27 +0100 Subject: [PATCH 07/15] Fast WorldReset, reduce spawned tasks, fix schemcoloring --- .../spectatesystem/PacketProcessor.java | 113 +++++++++++------- .../spectatesystem/util/WorldLoader.java | 58 ++++----- 2 files changed, 92 insertions(+), 79 deletions(-) diff --git a/src/de/steamwar/spectatesystem/PacketProcessor.java b/src/de/steamwar/spectatesystem/PacketProcessor.java index 737bb7a..cbcb9d0 100644 --- a/src/de/steamwar/spectatesystem/PacketProcessor.java +++ b/src/de/steamwar/spectatesystem/PacketProcessor.java @@ -43,6 +43,7 @@ import org.bukkit.scheduler.BukkitTask; import java.io.EOFException; import java.io.IOException; import java.util.HashMap; +import java.util.LinkedList; import java.util.Map; import java.util.Objects; import java.util.logging.Level; @@ -54,26 +55,49 @@ class PacketProcessor { private final PacketSource source; private final BukkitTask task; + private final LinkedList syncList = new LinkedList<>(); + public PacketProcessor(PacketSource source){ this.source = source; - if(source.async()) - task = Bukkit.getScheduler().runTaskAsynchronously(SpectateSystem.get(), this::process); - else + if(source.async()) { + Bukkit.getScheduler().runTaskAsynchronously(SpectateSystem.get(), this::process); + task = Bukkit.getScheduler().runTaskTimer(SpectateSystem.get(), this::runSync, 1, 1); + }else task = Bukkit.getScheduler().runTaskTimer(SpectateSystem.get(), this::process, 1, 1); } - private void playerJoins() throws IOException{ + private void runSync() { + synchronized (syncList) { + for(Runnable runnable : syncList) { + runnable.run(); + } + syncList.clear(); + } + } + + private void execSync(Runnable runnable){ + if (!source.async()) { + runnable.run(); + return; + } + + synchronized (syncList) { + syncList.add(runnable); + } + } + + private void playerJoins() throws IOException { int entityId = source.rInt(); int userId = source.rInt(); SteamwarUser user = SteamwarUser.get(userId); if(user == null) throw new IOException("Unknown user " + userId); - Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> new RPlayer(user.getUUID(), user.getUserName(), entityId)); + execSync(() -> new RPlayer(user.getUUID(), user.getUserName(), entityId)); } - private void entityMoves() throws IOException{ + private void entityMoves() throws IOException { int entityId = source.rInt(); double locX = source.rDouble(); double locY = source.rDouble(); @@ -82,33 +106,33 @@ class PacketProcessor { float yaw = source.rFloat(); byte headYaw = source.rByte(); - Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> REntity.getEntity(entityId).move(locX, locY, locZ, yaw, pitch, headYaw)); + execSync(() -> REntity.getEntity(entityId).move(locX, locY, locZ, yaw, pitch, headYaw)); } - private void entityDespawns() throws IOException{ + private void entityDespawns() throws IOException { int entityId = source.rInt(); - Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> REntity.getEntity(entityId).remove()); + execSync(() -> REntity.getEntity(entityId).remove()); } private void entitySneak() throws IOException { int entityId = source.rInt(); boolean sneaking = source.rBoolean(); - Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> REntity.getEntity(entityId).sneak(sneaking)); + execSync(() -> REntity.getEntity(entityId).sneak(sneaking)); } private void entityAnimation() throws IOException { int entityId = source.rInt(); byte animation = source.rByte(); - Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> REntity.getEntity(entityId).animation(animation)); + execSync(() -> REntity.getEntity(entityId).animation(animation)); } private void tntSpawn() throws IOException { int entityId = source.rInt(); - new RTnT(entityId); + execSync(() -> new RTnT(entityId)); } private void entityVelocity() throws IOException { @@ -118,7 +142,7 @@ class PacketProcessor { double dY = source.rDouble(); double dZ = source.rDouble(); - Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> { + execSync(() -> { REntity entity = REntity.getEntity(entityId); if(entity != null) entity.setMotion(dX, dY, dZ); @@ -131,19 +155,19 @@ class PacketProcessor { boolean enchanted = source.rBoolean(); String slot = source.rString(); - Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> ((RPlayer)REntity.getEntity(entityId)).setItem(item, enchanted, slot)); + execSync(() -> ((RPlayer)REntity.getEntity(entityId)).setItem(item, enchanted, slot)); } private void arrowSpawn() throws IOException { int entityId = source.rInt(); - new RArrow(entityId); + execSync(() -> new RArrow(entityId)); } private void fireballSpawn() throws IOException { int entityId = source.rInt(); - new RFireball(entityId); + execSync(() -> new RFireball(entityId)); } private void send(ChatMessageType type) throws IOException { @@ -171,6 +195,23 @@ class PacketProcessor { setBlock(x, y, z, blockState); } + private void setBlock(int x, int y, int z, int blockState){ + if(Config.ArenaMinX > x || Config.ArenaMaxX < x || Config.ArenaMinZ > z || Config.ArenaMaxZ < z) + return; //Outside of the arena + + if (Config.TechhiderActive && Config.HiddenBlocks.contains(blockState)) { + blockState = Config.ObfuscateWith; + } + IBlockData blockData = Objects.requireNonNull(Block.REGISTRY_ID.fromId(blockState)); + execSync(() -> { + WorldServer cworld = ((CraftWorld)world).getHandle(); + BlockPosition pos = new BlockPosition(x, y, z); + cworld.removeTileEntity(pos); + cworld.setTypeAndData(pos, blockData, 1042); + cworld.getChunkProvider().flagDirty(pos); + }); + } + private void particle() throws IOException { double x = source.rDouble(); double y = source.rDouble(); @@ -178,7 +219,7 @@ class PacketProcessor { String particleName = source.rString(); - Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> world.spawnParticle(Particle.valueOf(particleName), x, y, z, 1)); + execSync(() -> world.spawnParticle(Particle.valueOf(particleName), x, y, z, 1)); } private void sound() throws IOException { @@ -195,7 +236,7 @@ class PacketProcessor { Sound sound = Sound.valueOf(soundName); SoundCategory sCategory = SoundCategory.valueOf(soundCategory); - Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> world.playSound(new Location(world, x, y, z), sound, sCategory, volume, pitch)); + execSync(() -> world.playSound(new Location(world, x, y, z), sound, sCategory, volume, pitch)); } private void soundAtPlayer() throws IOException { @@ -206,21 +247,21 @@ class PacketProcessor { Sound sound = Sound.valueOf(soundName); - Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> { + execSync(() -> { for(Player player : Bukkit.getOnlinePlayers()){ player.playSound(player.getLocation(), sound, volume, pitch); } }); } - private void pasteSchem(int cornerX, int cornerY, int cornerZ, boolean rotate, String prefix) throws IOException { + private void pasteSchem(int pasteX, int cornerY, int pasteZ, int cornerX, int cornerZ, boolean rotate, String prefix) throws IOException { int schemId = source.rInt(); Schematic schem = Schematic.getSchemFromDB(schemId); DyeColor c = ColorConverter.chat2dye(ChatColor.getByChar(ChatColor.getLastColors(prefix).replace("§", ""))); - Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> { + execSync(() -> { try { - EditSession e = Paster.pasteSchematic(schem, cornerX, cornerY, cornerZ, rotate); + EditSession e = Paster.pasteSchematic(schem, pasteX, cornerY, pasteZ, rotate); Paster.replaceTeamColor(e, c, cornerX, cornerY, cornerZ); } catch (NoClipboardException | IOException e) { throw new SecurityException("Could not load Clipboard", e); @@ -232,7 +273,7 @@ class PacketProcessor { int blueId = source.rInt(); int redId = source.rInt(); - Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> BlockTextCreator.pasteTeamNames(blueId, redId)); + execSync(() -> BlockTextCreator.pasteTeamNames(blueId, redId)); } private void scoreboardTitle() throws IOException { @@ -248,23 +289,6 @@ class PacketProcessor { SpectateSystem.getScoreboard().addValue(key, value); } - private void setBlock(int x, int y, int z, int blockState){ - if(Config.ArenaMinX > x || Config.ArenaMaxX < x || Config.ArenaMinZ > z || Config.ArenaMaxZ < z) - return; //Outside of the arena - - if (Config.TechhiderActive && Config.HiddenBlocks.contains(blockState)) { - blockState = Config.ObfuscateWith; - } - IBlockData blockData = Objects.requireNonNull(Block.REGISTRY_ID.fromId(blockState)); - Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> { - WorldServer cworld = ((CraftWorld)world).getHandle(); - BlockPosition pos = new BlockPosition(x, y, z); - cworld.removeTileEntity(pos); - cworld.setTypeAndData(pos, blockData, 1042); - cworld.getChunkProvider().flagDirty(pos); - }); - } - private void endSpectating(){ WorldLoader.reloadWorld(); SpectateSystem.getScoreboard().setTitle("§eKein Kampf"); @@ -339,10 +363,10 @@ class PacketProcessor { send(ChatMessageType.SYSTEM); break; case (byte) 0xB0: - pasteSchem(Config.TeamBluePasteX, Config.TeamBlueCornerY, Config.TeamBluePasteZ, Config.TeamBlueRotate, Config.TeamBluePrefix); + pasteSchem(Config.TeamBluePasteX, Config.TeamBlueCornerY, Config.TeamBluePasteZ, Config.TeamBlueCornerX, Config.TeamBlueCornerZ, Config.TeamBlueRotate, Config.TeamBluePrefix); break; case (byte) 0xB1: - pasteSchem(Config.TeamRedPasteX, Config.TeamRedCornerY, Config.TeamRedPasteZ, Config.TeamRedRotate, Config.TeamRedPrefix); + pasteSchem(Config.TeamRedPasteX, Config.TeamRedCornerY, Config.TeamRedPasteZ, Config.TeamRedCornerX, Config.TeamRedCornerZ, Config.TeamRedRotate, Config.TeamRedPrefix); break; case (byte) 0xB2: teams(); @@ -376,9 +400,8 @@ class PacketProcessor { } if(source.isClosed()){ - endSpectating(); - if(!source.async()) - task.cancel(); + execSync(() -> endSpectating()); + task.cancel(); } } } diff --git a/src/de/steamwar/spectatesystem/util/WorldLoader.java b/src/de/steamwar/spectatesystem/util/WorldLoader.java index 8228d61..2dc3d64 100644 --- a/src/de/steamwar/spectatesystem/util/WorldLoader.java +++ b/src/de/steamwar/spectatesystem/util/WorldLoader.java @@ -19,18 +19,19 @@ package de.steamwar.spectatesystem.util; +import de.steamwar.core.events.ChunkListener; import de.steamwar.spectatesystem.Config; import de.steamwar.spectatesystem.SpectateSystem; import de.steamwar.spectatesystem.elements.REntity; import net.minecraft.server.v1_15_R1.BlockPosition; import net.minecraft.server.v1_15_R1.Blocks; -import net.minecraft.server.v1_15_R1.IBlockData; +import net.minecraft.server.v1_15_R1.Chunk; import net.minecraft.server.v1_15_R1.WorldServer; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.WorldCreator; -import org.bukkit.craftbukkit.v1_15_R1.CraftChunk; import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; +import org.bukkit.entity.Player; public class WorldLoader { private WorldLoader(){} @@ -48,25 +49,21 @@ public class WorldLoader { world.setKeepSpawnInMemory(true); } - public static void reloadWorld(){ - Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> { - REntity.removeAll(); - World backupWorld = new WorldCreator(world.getName() + "-backup").createWorld(); + public static void reloadWorld() { + REntity.removeAll(); + World backupWorld = new WorldCreator(world.getName() + "-backup").createWorld(); - int delay = 1; - Bukkit.getScheduler().runTaskLater(SpectateSystem.get(), () -> fillTeamArea(Config.TeamBlueCornerX, Config.TeamBlueCornerY, Config.TeamBlueCornerZ, Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ), delay++); - Bukkit.getScheduler().runTaskLater(SpectateSystem.get(), () -> fillTeamArea(Config.TeamRedCornerX, Config.TeamRedCornerY, Config.TeamRedCornerZ, Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ), delay++); + fillTeamArea(Config.TeamBlueCornerX, Config.TeamBlueCornerY, Config.TeamBlueCornerZ, Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ); + fillTeamArea(Config.TeamRedCornerX, Config.TeamRedCornerY, Config.TeamRedCornerZ, Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ); - for(int cX = (int) Math.floor(Config.ArenaMinX / 16.0); cX <= (int) Math.floor(Config.ArenaMaxX / 16.0); cX++){ - for(int cZ = (int) Math.floor(Config.ArenaMinZ / 16.0); cZ <= (int) Math.floor(Config.ArenaMaxZ / 16.0); cZ++){ - int finalCX = cX; - int finalCZ = cZ; - Bukkit.getScheduler().runTaskLater(SpectateSystem.get(), () -> reloadChunk(backupWorld, finalCX, finalCZ), delay++); + Bukkit.getScheduler().runTaskLater(SpectateSystem.get(), () -> { + for(int cZ = (int) Math.floor(Config.ArenaMinZ / 16.0); cZ <= (int) Math.floor(Config.ArenaMaxZ / 16.0); cZ++){ + for(int cX = (int) Math.floor(Config.ArenaMinX / 16.0); cX <= (int) Math.floor(Config.ArenaMaxX / 16.0); cX++){ + reloadChunk(backupWorld, cX, cZ); } } - - Bukkit.getScheduler().runTaskLater(SpectateSystem.get(), () -> Bukkit.unloadWorld(world.getName() + "-backup", false), delay); - }); + Bukkit.unloadWorld(world.getName() + "-backup", false); + }, 10); } public static void fillTeamArea(int teamX, int teamY, int teamZ, int sizeX, int sizeY, int sizeZ){ @@ -83,24 +80,17 @@ public class WorldLoader { } } - public static void reloadChunk(World backupWorld, int cX, int cZ){ - WorldServer cworld = ((CraftWorld)world).getHandle(); - WorldServer backup = ((CraftWorld) backupWorld).getHandle(); + public static void reloadChunk(World backup, int x, int z){ + Chunk chunk = ((CraftWorld) world).getHandle().getChunkAt(x, z); + Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z); - net.minecraft.server.v1_15_R1.Chunk cchunk = ((CraftChunk) world.getChunkAt(cX, cZ)).getHandle(); - for(int y = 255; y >= 0; y--){ // y top down to reduce lightning calculations - for(int x = cX * 16; x < (cX + 1) * 16; x++){ - for(int z = cZ * 16; z < (cZ + 1) * 16; z++){ - BlockPosition blockPos = new BlockPosition(x, y, z); - IBlockData backupBlock = backup.getType(blockPos); - if(backupBlock == cworld.getType(blockPos)) - continue; - - cchunk.removeTileEntity(blockPos); - cworld.setTypeAndData(blockPos, backupBlock, 1042); - cworld.getChunkProvider().flagDirty(blockPos); - } - } + System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length); + chunk.tileEntities.clear(); + chunk.tileEntities.putAll(backupChunk.tileEntities); + chunk.heightMap.clear(); + chunk.heightMap.putAll(backupChunk.heightMap); + for(Player p : Bukkit.getOnlinePlayers()){ + ChunkListener.sendChunk(p, x, z); } } } From fccd3ff142ebf24002de506510a93c1a928f6488 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 20 Mar 2021 12:04:36 +0100 Subject: [PATCH 08/15] Try catch --- src/de/steamwar/spectatesystem/PacketProcessor.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/spectatesystem/PacketProcessor.java b/src/de/steamwar/spectatesystem/PacketProcessor.java index cbcb9d0..824e321 100644 --- a/src/de/steamwar/spectatesystem/PacketProcessor.java +++ b/src/de/steamwar/spectatesystem/PacketProcessor.java @@ -70,7 +70,11 @@ class PacketProcessor { private void runSync() { synchronized (syncList) { for(Runnable runnable : syncList) { - runnable.run(); + try{ + runnable.run(); + }catch (Exception e) { + Bukkit.getLogger().log(Level.WARNING, "Failed to execute packet", e); + } } syncList.clear(); } From 9419f1223e717d46799f8a083533f65f4dc9e617 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 20 Mar 2021 12:24:53 +0100 Subject: [PATCH 09/15] Wait longer --- src/de/steamwar/spectatesystem/util/WorldLoader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/spectatesystem/util/WorldLoader.java b/src/de/steamwar/spectatesystem/util/WorldLoader.java index 2dc3d64..c0240d8 100644 --- a/src/de/steamwar/spectatesystem/util/WorldLoader.java +++ b/src/de/steamwar/spectatesystem/util/WorldLoader.java @@ -63,7 +63,7 @@ public class WorldLoader { } } Bukkit.unloadWorld(world.getName() + "-backup", false); - }, 10); + }, 20); } public static void fillTeamArea(int teamX, int teamY, int teamZ, int sizeX, int sizeY, int sizeZ){ From 682cb3e284151c6c824ebb1e80c317318f359a00 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 20 Mar 2021 13:00:00 +0100 Subject: [PATCH 10/15] Wait longer --- src/de/steamwar/spectatesystem/util/WorldLoader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/spectatesystem/util/WorldLoader.java b/src/de/steamwar/spectatesystem/util/WorldLoader.java index c0240d8..6e9a67b 100644 --- a/src/de/steamwar/spectatesystem/util/WorldLoader.java +++ b/src/de/steamwar/spectatesystem/util/WorldLoader.java @@ -63,7 +63,7 @@ public class WorldLoader { } } Bukkit.unloadWorld(world.getName() + "-backup", false); - }, 20); + }, 40); } public static void fillTeamArea(int teamX, int teamY, int teamZ, int sizeX, int sizeY, int sizeZ){ From fc193aff83c1bd4114866bd65d346ed4d3c117a9 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 20 Mar 2021 13:00:09 +0100 Subject: [PATCH 11/15] Wait longer --- src/de/steamwar/spectatesystem/util/WorldLoader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/spectatesystem/util/WorldLoader.java b/src/de/steamwar/spectatesystem/util/WorldLoader.java index 6e9a67b..236ee2a 100644 --- a/src/de/steamwar/spectatesystem/util/WorldLoader.java +++ b/src/de/steamwar/spectatesystem/util/WorldLoader.java @@ -63,7 +63,7 @@ public class WorldLoader { } } Bukkit.unloadWorld(world.getName() + "-backup", false); - }, 40); + }, 80); } public static void fillTeamArea(int teamX, int teamY, int teamZ, int sizeX, int sizeY, int sizeZ){ From 5e5f7ee874041f8b1de0c7d35d715f8d505835df Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 20 Mar 2021 13:29:09 +0100 Subject: [PATCH 12/15] fix cleanup --- src/de/steamwar/spectatesystem/PacketProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/spectatesystem/PacketProcessor.java b/src/de/steamwar/spectatesystem/PacketProcessor.java index 824e321..b372e7b 100644 --- a/src/de/steamwar/spectatesystem/PacketProcessor.java +++ b/src/de/steamwar/spectatesystem/PacketProcessor.java @@ -404,7 +404,7 @@ class PacketProcessor { } if(source.isClosed()){ - execSync(() -> endSpectating()); + Bukkit.getScheduler().runTask(SpectateSystem.get(), this::endSpectating); task.cancel(); } } From 6cbdb837d029d3e4b932e453639e8b5d55ffdb90 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 21 Mar 2021 11:22:03 +0100 Subject: [PATCH 13/15] Add inspection option --- .../spectatesystem/PacketProcessor.java | 3 +- .../steamwar/spectatesystem/PlayerSetup.java | 4 +++ .../spectatesystem/SpectateSystem.java | 7 +++++ .../commands/InspectCommand.java | 29 +++++++++++++++++++ .../commands/ReplayCommand.java | 8 ++--- .../spectatesystem/listener/JoinListener.java | 12 ++++++++ .../listener/PlayerListener.java | 4 +++ .../steamwar/spectatesystem/util/Paster.java | 3 +- src/plugin.yml | 3 +- 9 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 src/de/steamwar/spectatesystem/commands/InspectCommand.java diff --git a/src/de/steamwar/spectatesystem/PacketProcessor.java b/src/de/steamwar/spectatesystem/PacketProcessor.java index b372e7b..f2a53ec 100644 --- a/src/de/steamwar/spectatesystem/PacketProcessor.java +++ b/src/de/steamwar/spectatesystem/PacketProcessor.java @@ -20,6 +20,7 @@ package de.steamwar.spectatesystem; import com.sk89q.worldedit.EditSession; +import de.steamwar.spectatesystem.commands.InspectCommand; import de.steamwar.spectatesystem.elements.*; import de.steamwar.spectatesystem.util.BlockTextCreator; import de.steamwar.spectatesystem.util.ColorConverter; @@ -203,7 +204,7 @@ class PacketProcessor { if(Config.ArenaMinX > x || Config.ArenaMaxX < x || Config.ArenaMinZ > z || Config.ArenaMaxZ < z) return; //Outside of the arena - if (Config.TechhiderActive && Config.HiddenBlocks.contains(blockState)) { + if (!InspectCommand.inspecting && Config.TechhiderActive && Config.HiddenBlocks.contains(blockState)) { blockState = Config.ObfuscateWith; } IBlockData blockData = Objects.requireNonNull(Block.REGISTRY_ID.fromId(blockState)); diff --git a/src/de/steamwar/spectatesystem/PlayerSetup.java b/src/de/steamwar/spectatesystem/PlayerSetup.java index 02d6a84..5c6a451 100644 --- a/src/de/steamwar/spectatesystem/PlayerSetup.java +++ b/src/de/steamwar/spectatesystem/PlayerSetup.java @@ -26,6 +26,7 @@ import com.comphenix.protocol.wrappers.EnumWrappers; import com.comphenix.protocol.wrappers.PlayerInfoData; import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedGameProfile; +import de.steamwar.spectatesystem.commands.InspectCommand; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; @@ -102,6 +103,9 @@ public class PlayerSetup { } } Bukkit.getScheduler().runTaskLater(SpectateSystem.get(), () -> { + if(InspectCommand.inspecting) + return; + PacketContainer gm1packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO); gm1packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE); List playerInfoActions = new ArrayList<>(); diff --git a/src/de/steamwar/spectatesystem/SpectateSystem.java b/src/de/steamwar/spectatesystem/SpectateSystem.java index 76bc293..fbd45b2 100644 --- a/src/de/steamwar/spectatesystem/SpectateSystem.java +++ b/src/de/steamwar/spectatesystem/SpectateSystem.java @@ -19,6 +19,7 @@ package de.steamwar.spectatesystem; +import de.steamwar.spectatesystem.commands.InspectCommand; import de.steamwar.spectatesystem.commands.ReplayCommand; import de.steamwar.spectatesystem.elements.RScoreboard; import de.steamwar.spectatesystem.listener.PlayerListener; @@ -26,14 +27,19 @@ import de.steamwar.spectatesystem.listener.CancelListener; import de.steamwar.spectatesystem.listener.JoinListener; import de.steamwar.spectatesystem.listener.PlayerSeatListener; import de.steamwar.spectatesystem.util.WorldLoader; +import de.steamwar.sql.UserGroup; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; import java.io.IOException; +import java.util.EnumSet; +import java.util.Set; import java.util.logging.Level; public class SpectateSystem extends JavaPlugin { + public static final Set allowedGroups = EnumSet.of(UserGroup.Admin, UserGroup.Developer, UserGroup.Moderator); + private static SpectateSystem instance; private static RScoreboard scoreboard; private ConnectionAcceptor acceptor; @@ -53,6 +59,7 @@ public class SpectateSystem extends JavaPlugin { } Bukkit.getPluginCommand("replay").setExecutor(new ReplayCommand()); + Bukkit.getPluginCommand("inspect").setExecutor(new InspectCommand()); WorldLoader.configureForceLoad(); } diff --git a/src/de/steamwar/spectatesystem/commands/InspectCommand.java b/src/de/steamwar/spectatesystem/commands/InspectCommand.java new file mode 100644 index 0000000..fc88afc --- /dev/null +++ b/src/de/steamwar/spectatesystem/commands/InspectCommand.java @@ -0,0 +1,29 @@ +package de.steamwar.spectatesystem.commands; + +import de.steamwar.spectatesystem.SpectateSystem; +import de.steamwar.sql.SteamwarUser; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class InspectCommand implements CommandExecutor { + + public static boolean inspecting = false; + + @Override + public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) { + if(sender instanceof Player){ + Player player = (Player) sender; + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if(!SpectateSystem.allowedGroups.contains(user.getUserGroup())){ + player.sendMessage("§eSteam§8War» §cUnbekannter Befehl."); + return false; + } + } + + inspecting = !inspecting; + sender.sendMessage("Inspection: " + inspecting); + return false; + } +} diff --git a/src/de/steamwar/spectatesystem/commands/ReplayCommand.java b/src/de/steamwar/spectatesystem/commands/ReplayCommand.java index a0b6ed0..b0e4ed0 100644 --- a/src/de/steamwar/spectatesystem/commands/ReplayCommand.java +++ b/src/de/steamwar/spectatesystem/commands/ReplayCommand.java @@ -20,8 +20,8 @@ package de.steamwar.spectatesystem.commands; import de.steamwar.spectatesystem.FightfileConnection; +import de.steamwar.spectatesystem.SpectateSystem; import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.UserGroup; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -30,20 +30,16 @@ import org.bukkit.entity.Player; import java.io.File; import java.io.IOException; -import java.util.EnumSet; -import java.util.Set; import java.util.logging.Level; public class ReplayCommand implements CommandExecutor { - private static final Set allowedGroups = EnumSet.of(UserGroup.Admin, UserGroup.Developer, UserGroup.Moderator); - @Override public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) { if(sender instanceof Player){ Player player = (Player) sender; SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - if(!allowedGroups.contains(user.getUserGroup())){ + if(!SpectateSystem.allowedGroups.contains(user.getUserGroup())){ player.sendMessage("§eSteam§8War» §cUnbekannter Befehl."); return false; } diff --git a/src/de/steamwar/spectatesystem/listener/JoinListener.java b/src/de/steamwar/spectatesystem/listener/JoinListener.java index a29e611..5ecef40 100644 --- a/src/de/steamwar/spectatesystem/listener/JoinListener.java +++ b/src/de/steamwar/spectatesystem/listener/JoinListener.java @@ -23,7 +23,9 @@ import de.steamwar.scoreboard.SWScoreboard; import de.steamwar.spectatesystem.Config; import de.steamwar.spectatesystem.PlayerSetup; import de.steamwar.spectatesystem.SpectateSystem; +import de.steamwar.spectatesystem.commands.InspectCommand; import de.steamwar.spectatesystem.elements.REntity; +import de.steamwar.sql.SteamwarUser; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerJoinEvent; @@ -35,6 +37,16 @@ public class JoinListener extends BasicListener { public void onJoin(PlayerJoinEvent e){ e.setJoinMessage(null); Player player = e.getPlayer(); + + if(InspectCommand.inspecting){ + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if(!SpectateSystem.allowedGroups.contains(user.getUserGroup())){ + player.sendMessage("§eSteam§8War» §cDerzeit ist das Zuschauen nicht gestattet."); + player.kickPlayer(null); + return; + } + } + player.teleport(Config.SpecSpawn); REntity.playerJoins(player); PlayerSetup.playerJoins(player); diff --git a/src/de/steamwar/spectatesystem/listener/PlayerListener.java b/src/de/steamwar/spectatesystem/listener/PlayerListener.java index c63b5cd..baf82e6 100644 --- a/src/de/steamwar/spectatesystem/listener/PlayerListener.java +++ b/src/de/steamwar/spectatesystem/listener/PlayerListener.java @@ -22,6 +22,7 @@ package de.steamwar.spectatesystem.listener; import de.steamwar.spectatesystem.Config; import de.steamwar.spectatesystem.PlayerSetup; import de.steamwar.spectatesystem.SpectateSystem; +import de.steamwar.spectatesystem.commands.InspectCommand; import de.steamwar.spectatesystem.util.Region; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.BaseComponent; @@ -53,6 +54,9 @@ public class PlayerListener extends BasicListener { } private void checkMovementInArena(PlayerMoveEvent event, Location to){ + if(InspectCommand.inspecting) + return; + boolean inArenaY = to.getY() + 1.8 <= Config.upperArenaBorder; boolean inBlueArea = inArenaY && Region.isIn2DRange(to, Config.TeamBlueCornerX, Config.TeamBlueCornerZ, Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic); boolean inRedArea = inArenaY && Region.isIn2DRange(to, Config.TeamRedCornerX, Config.TeamRedCornerZ, Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic); diff --git a/src/de/steamwar/spectatesystem/util/Paster.java b/src/de/steamwar/spectatesystem/util/Paster.java index 06da440..350e76e 100644 --- a/src/de/steamwar/spectatesystem/util/Paster.java +++ b/src/de/steamwar/spectatesystem/util/Paster.java @@ -35,6 +35,7 @@ import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockTypes; import de.steamwar.spectatesystem.Config; +import de.steamwar.spectatesystem.commands.InspectCommand; import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; @@ -90,7 +91,7 @@ public class Paster { for(int y = 0; y < clipboard.getDimensions().getY(); y++){ for(int z = 0; z < clipboard.getDimensions().getZ(); z++){ BlockVector3 blockPos = minimum.add(x, y, z); - if(Config.HiddenBlockTags.contains(BukkitAdapter.adapt(clipboard.getFullBlock(blockPos).getBlockType()).name())){ + if(!InspectCommand.inspecting && Config.HiddenBlockTags.contains(BukkitAdapter.adapt(clipboard.getFullBlock(blockPos).getBlockType()).name())){ try { clipboard.setBlock(blockPos, obfuscateWith); } catch (WorldEditException e) { diff --git a/src/plugin.yml b/src/plugin.yml index cb71967..10295c1 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -10,4 +10,5 @@ depend: - WorldEdit - ProtocolLib commands: - replay: \ No newline at end of file + replay: + inspect: From ccc1388cc3b7f8ef80bf74c8b986b4861e681ddc Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 21 Mar 2021 11:27:01 +0100 Subject: [PATCH 14/15] Fix to login event --- .../spectatesystem/listener/JoinListener.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/de/steamwar/spectatesystem/listener/JoinListener.java b/src/de/steamwar/spectatesystem/listener/JoinListener.java index 5ecef40..64715d6 100644 --- a/src/de/steamwar/spectatesystem/listener/JoinListener.java +++ b/src/de/steamwar/spectatesystem/listener/JoinListener.java @@ -29,23 +29,27 @@ import de.steamwar.sql.SteamwarUser; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerQuitEvent; public class JoinListener extends BasicListener { @EventHandler - public void onJoin(PlayerJoinEvent e){ - e.setJoinMessage(null); + public void onLogin(PlayerLoginEvent e){ Player player = e.getPlayer(); if(InspectCommand.inspecting){ SteamwarUser user = SteamwarUser.get(player.getUniqueId()); if(!SpectateSystem.allowedGroups.contains(user.getUserGroup())){ - player.sendMessage("§eSteam§8War» §cDerzeit ist das Zuschauen nicht gestattet."); - player.kickPlayer(null); - return; + e.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, "§eSteam§8War» §cDerzeit ist das Zuschauen nicht gestattet."); } } + } + + @EventHandler + public void onJoin(PlayerJoinEvent e){ + e.setJoinMessage(null); + Player player = e.getPlayer(); player.teleport(Config.SpecSpawn); REntity.playerJoins(player); From c208fab359f6883f94f4dc20d84c8fc3d2b1a200 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 21 Mar 2021 12:17:49 +0100 Subject: [PATCH 15/15] Force resourcepack --- .../spectatesystem/listener/JoinListener.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/de/steamwar/spectatesystem/listener/JoinListener.java b/src/de/steamwar/spectatesystem/listener/JoinListener.java index 64715d6..bd76dc2 100644 --- a/src/de/steamwar/spectatesystem/listener/JoinListener.java +++ b/src/de/steamwar/spectatesystem/listener/JoinListener.java @@ -31,6 +31,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerResourcePackStatusEvent; public class JoinListener extends BasicListener { @@ -51,6 +52,7 @@ public class JoinListener extends BasicListener { e.setJoinMessage(null); Player player = e.getPlayer(); + player.setResourcePack("https://steamwar.de/antixray.zip"); player.teleport(Config.SpecSpawn); REntity.playerJoins(player); PlayerSetup.playerJoins(player); @@ -65,4 +67,14 @@ public class JoinListener extends BasicListener { PlayerSetup.playerLeaves(e.getPlayer()); e.setQuitMessage(null); } + + @EventHandler + public void onResourcepack(PlayerResourcePackStatusEvent e){ + if(e.getStatus() == PlayerResourcePackStatusEvent.Status.ACCEPTED || e.getStatus() == PlayerResourcePackStatusEvent.Status.SUCCESSFULLY_LOADED) + return; + + Player player = e.getPlayer(); + player.sendMessage("§eSteam§8War» §cAuf Eventserver kann nur mit dem SteamWar-Resourcepack beigetreten werden"); + player.kickPlayer(null); + } }