From 4116f32256ca7828ea3c51779594e6718d33c66f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 11 Nov 2020 08:39:44 +0100 Subject: [PATCH] Better WorldReset and faster blockplacement --- .../spectatesystem/PacketProcessor.java | 15 +++++++++++--- .../spectatesystem/util/WorldLoader.java | 20 ++++++++++++++++++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/spectatesystem/PacketProcessor.java b/src/de/steamwar/spectatesystem/PacketProcessor.java index b14e386..737bb7a 100644 --- a/src/de/steamwar/spectatesystem/PacketProcessor.java +++ b/src/de/steamwar/spectatesystem/PacketProcessor.java @@ -32,8 +32,11 @@ import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; import net.minecraft.server.v1_15_R1.Block; +import net.minecraft.server.v1_15_R1.BlockPosition; +import net.minecraft.server.v1_15_R1.IBlockData; +import net.minecraft.server.v1_15_R1.WorldServer; import org.bukkit.*; -import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData; +import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; @@ -252,8 +255,14 @@ class PacketProcessor { if (Config.TechhiderActive && Config.HiddenBlocks.contains(blockState)) { blockState = Config.ObfuscateWith; } - CraftBlockData craftBlockData = CraftBlockData.fromData(Objects.requireNonNull(Block.REGISTRY_ID.fromId(blockState))); - Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> world.getBlockAt(x, y, z).setBlockData(craftBlockData)); + 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(){ diff --git a/src/de/steamwar/spectatesystem/util/WorldLoader.java b/src/de/steamwar/spectatesystem/util/WorldLoader.java index 0bfa364..63766b1 100644 --- a/src/de/steamwar/spectatesystem/util/WorldLoader.java +++ b/src/de/steamwar/spectatesystem/util/WorldLoader.java @@ -23,6 +23,7 @@ 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.WorldServer; import org.bukkit.Bukkit; @@ -52,7 +53,10 @@ public class WorldLoader { REntity.removeAll(); World backupWorld = new WorldCreator(world.getName() + "-backup").createWorld(); - int delay = 0; + 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++); + 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; @@ -65,6 +69,20 @@ public class WorldLoader { }); } + public static void fillTeamArea(int teamX, int teamY, int teamZ, int sizeX, int sizeY, int sizeZ){ + WorldServer cworld = ((CraftWorld)world).getHandle(); + for(int x = teamX; x < teamX + sizeX; x++){ + for(int y = teamY; y < teamY + sizeY; y++){ + for(int z = teamZ; z < teamZ + sizeZ; z++){ + BlockPosition pos = new BlockPosition(x, y, z); + cworld.removeTileEntity(pos); + cworld.setTypeAndData(pos, Blocks.AIR.getBlockData(), 1042); + cworld.getChunkProvider().flagDirty(pos); + } + } + } + } + public static void reloadChunk(World backupWorld, int cX, int cZ){ WorldServer cworld = ((CraftWorld)world).getHandle(); WorldServer backup = ((CraftWorld) backupWorld).getHandle();