diff --git a/src/de/steamwar/spectatesystem/Config.java b/src/de/steamwar/spectatesystem/Config.java index be368d6..dcb4f2f 100644 --- a/src/de/steamwar/spectatesystem/Config.java +++ b/src/de/steamwar/spectatesystem/Config.java @@ -43,11 +43,13 @@ public class Config { public static final int TeamBlueCornerX; public static final int TeamBlueCornerY; public static final int TeamBlueCornerZ; - private static final int TeamBluePasteX; - private static final int TeamBluePasteZ; + public static final int TeamBluePasteX; + public static final int TeamBluePasteZ; public static final int TeamRedCornerX; public static final int TeamRedCornerY; public static final int TeamRedCornerZ; + public static final int TeamRedPasteX; + public static final int TeamRedPasteZ; private static final int TeamBluetoReddistanceX; private static final int TeamBluetoReddistanceY; public static final int TeamBluetoReddistanceZ; @@ -141,6 +143,8 @@ public class Config { TeamBluePasteX = TeamBlueCornerX + SchemsizeX / 2; TeamBluePasteZ = TeamBlueCornerZ + SchemsizeZ / 2; + TeamRedPasteX = TeamRedCornerX + SchemsizeX / 2; + TeamRedPasteZ = TeamRedCornerZ + SchemsizeZ / 2; SpecSpawn = new Location(world, TeamBluePasteX + TeamBluetoReddistanceX/2.0, diff --git a/src/de/steamwar/spectatesystem/PacketProcessor.java b/src/de/steamwar/spectatesystem/PacketProcessor.java index d83ac03..1023b7c 100644 --- a/src/de/steamwar/spectatesystem/PacketProcessor.java +++ b/src/de/steamwar/spectatesystem/PacketProcessor.java @@ -212,12 +212,14 @@ class PacketProcessor { Schematic schem = Schematic.getSchemFromDB(schemId); DyeColor c = ColorConverter.chat2dye(ChatColor.getByChar(ChatColor.getLastColors(prefix).replace("ยง", ""))); - try { - EditSession e = Paster.pasteSchematic(schem, cornerX, cornerY, cornerZ, rotate); - Paster.replaceTeamColor(e, c, cornerX, cornerY, cornerZ); - } catch (NoClipboardException e) { - throw new IOException("Could not load Clipboard", e); - } + Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> { + try { + EditSession e = Paster.pasteSchematic(schem, cornerX, cornerY, cornerZ, rotate); + Paster.replaceTeamColor(e, c, cornerX, cornerY, cornerZ); + } catch (NoClipboardException | IOException e) { + throw new SecurityException("Could not load Clipboard", e); + } + }); } private void scoreboardTitle() throws IOException { @@ -291,10 +293,10 @@ class PacketProcessor { send(ChatMessageType.SYSTEM); break; case (byte) 0xB0: - pasteSchem(Config.TeamBlueCornerX, Config.TeamBlueCornerY, Config.TeamBlueCornerZ, Config.TeamBlueRotate, Config.TeamBluePrefix); + pasteSchem(Config.TeamBluePasteX, Config.TeamBlueCornerY, Config.TeamBluePasteZ, Config.TeamBlueRotate, Config.TeamBluePrefix); break; case (byte) 0xB1: - pasteSchem(Config.TeamRedCornerX, Config.TeamRedCornerY, Config.TeamRedCornerZ, Config.TeamRedRotate, Config.TeamRedPrefix); + pasteSchem(Config.TeamRedPasteX, Config.TeamRedCornerY, Config.TeamRedPasteZ, Config.TeamRedRotate, Config.TeamRedPrefix); break; case (byte) 0xC0: scoreboardTitle(); diff --git a/src/de/steamwar/spectatesystem/elements/REntity.java b/src/de/steamwar/spectatesystem/elements/REntity.java index 2a221bc..8c5429b 100644 --- a/src/de/steamwar/spectatesystem/elements/REntity.java +++ b/src/de/steamwar/spectatesystem/elements/REntity.java @@ -84,6 +84,7 @@ public abstract class REntity { PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection; connection.sendPacket(packet); } + entity.killEntity(); entities.remove(internalId); } diff --git a/src/de/steamwar/spectatesystem/elements/RPlayer.java b/src/de/steamwar/spectatesystem/elements/RPlayer.java index c447ba2..49062c6 100644 --- a/src/de/steamwar/spectatesystem/elements/RPlayer.java +++ b/src/de/steamwar/spectatesystem/elements/RPlayer.java @@ -24,7 +24,6 @@ import com.mojang.authlib.properties.Property; import net.minecraft.server.v1_15_R1.*; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.v1_15_R1.CraftServer; -import org.bukkit.craftbukkit.v1_15_R1.enchantments.CraftEnchantment; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.entity.Player; @@ -90,7 +89,7 @@ public class RPlayer extends REntity { ItemStack stack = new ItemStack(IRegistry.ITEM.get(new MinecraftKey(item)), 1); if(enchanted) - stack.addEnchantment(((CraftEnchantment)org.bukkit.enchantments.Enchantment.KNOCKBACK).getHandle(), 1); + stack.addEnchantment(Enchantments.DURABILITY, 1); PlayerInventory inventory = ((EntityPlayer)entity).inventory; switch(slot){ diff --git a/src/de/steamwar/spectatesystem/util/Paster.java b/src/de/steamwar/spectatesystem/util/Paster.java index ccbfb0d..689f074 100644 --- a/src/de/steamwar/spectatesystem/util/Paster.java +++ b/src/de/steamwar/spectatesystem/util/Paster.java @@ -22,6 +22,8 @@ package de.steamwar.spectatesystem.util; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.function.operation.Operations; @@ -37,11 +39,13 @@ import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; import org.bukkit.DyeColor; +import org.bukkit.Material; import java.io.IOException; import java.util.Collections; import java.util.Objects; import java.util.Set; +import java.util.logging.Level; public class Paster { private Paster(){} @@ -76,6 +80,24 @@ public class Paster { BlockVector3 paste = BlockVector3.at(pX, pY, pZ); Clipboard clipboard = schematic.load(); + BlockVector3 minimum = clipboard.getRegion().getMinimumPoint(); + BaseBlock obfuscateWith = BukkitAdapter.adapt(Material.valueOf(Config.ObfuscateWithTag).createBlockData()).toBaseBlock(); + for(int x = 0; x < clipboard.getDimensions().getX(); x++){ + 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())){ + try { + clipboard.setBlock(blockPos, obfuscateWith); + } catch (WorldEditException e) { + Bukkit.getLogger().log(Level.SEVERE, "Could not hide block!", e); + } + } + + } + } + } + World w = new BukkitWorld(Bukkit.getWorlds().get(0)); BlockVector3 dimensions = clipboard.getDimensions(); BlockVector3 v; diff --git a/src/de/steamwar/spectatesystem/util/WorldLoader.java b/src/de/steamwar/spectatesystem/util/WorldLoader.java index 6aefdbe..2fdbcba 100644 --- a/src/de/steamwar/spectatesystem/util/WorldLoader.java +++ b/src/de/steamwar/spectatesystem/util/WorldLoader.java @@ -21,10 +21,14 @@ package de.steamwar.spectatesystem.util; import de.steamwar.spectatesystem.Config; import de.steamwar.spectatesystem.SpectateSystem; +import net.minecraft.server.v1_15_R1.PacketPlayOutMapChunk; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.craftbukkit.v1_15_R1.CraftChunk; +import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; public class WorldLoader { private WorldLoader(){} @@ -36,6 +40,8 @@ public class WorldLoader { for(Chunk chunk: world.getLoadedChunks()){ world.unloadChunk(chunk.getX(), chunk.getZ(), false); world.getChunkAt(chunk.getX(), chunk.getZ()); + for(Player player : Bukkit.getOnlinePlayers()) + ((CraftPlayer)player).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)chunk).getHandle(), 65535)); } }); Bukkit.getScheduler().runTaskLater(SpectateSystem.get(), () -> world.getBlockAt(Config.SpecSpawn).setType(Material.STONE), 100);