From aef57c490ea15d799f0da57d31f99d4ba835d88a Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 15 Oct 2020 22:23:11 +0200 Subject: [PATCH] Push current changes --- .../spectatesystem/PacketProcessor.java | 8 +++---- .../spectatesystem/elements/REntity.java | 10 +++++++- .../spectatesystem/util/BlockTextCreator.java | 23 ++++++++++++------- .../steamwar/spectatesystem/util/Paster.java | 6 ++++- .../spectatesystem/util/WorldLoader.java | 12 ++++------ 5 files changed, 37 insertions(+), 22 deletions(-) diff --git a/src/de/steamwar/spectatesystem/PacketProcessor.java b/src/de/steamwar/spectatesystem/PacketProcessor.java index d2a4a41..7171194 100644 --- a/src/de/steamwar/spectatesystem/PacketProcessor.java +++ b/src/de/steamwar/spectatesystem/PacketProcessor.java @@ -62,7 +62,7 @@ class PacketProcessor { if(user == null) throw new IOException("Unknown user " + userId); - new RPlayer(user.getUUID(), user.getUserName(), entityId); + Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> new RPlayer(user.getUUID(), user.getUserName(), entityId)); } private void entityMoves() throws IOException{ @@ -74,13 +74,13 @@ class PacketProcessor { float yaw = source.rFloat(); byte headYaw = source.rByte(); - REntity.getEntity(entityId).move(locX, locY, locZ, yaw, pitch, headYaw); + Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> REntity.getEntity(entityId).move(locX, locY, locZ, yaw, pitch, headYaw)); } private void entityDespawns() throws IOException{ int entityId = source.rInt(); - REntity.getEntity(entityId).remove(); + Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> REntity.getEntity(entityId).remove()); } private void entitySneak() throws IOException { @@ -123,7 +123,7 @@ class PacketProcessor { boolean enchanted = source.rBoolean(); String slot = source.rString(); - ((RPlayer)REntity.getEntity(entityId)).setItem(item, enchanted, slot); + Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> ((RPlayer)REntity.getEntity(entityId)).setItem(item, enchanted, slot)); } private void arrowSpawn() throws IOException { diff --git a/src/de/steamwar/spectatesystem/elements/REntity.java b/src/de/steamwar/spectatesystem/elements/REntity.java index fc29bbc..8dd5e23 100644 --- a/src/de/steamwar/spectatesystem/elements/REntity.java +++ b/src/de/steamwar/spectatesystem/elements/REntity.java @@ -33,7 +33,7 @@ public abstract class REntity { protected static final WorldServer world = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle(); - private static Map entities = new HashMap<>(); + private static final Map entities = new HashMap<>(); private final int internalId; protected final Entity entity; @@ -67,6 +67,14 @@ public abstract class REntity { return entities.get(internalId); } + public static void removeAll(){ + while(!entities.isEmpty()){ + REntity entity = entities.values().iterator().next(); + System.out.println("Has to remove manually entity " + entity.internalId); + entity.remove(); + } + } + public void move(double x, double y, double z, float yaw, float pitch, byte headYaw){ entity.setLocation(x, y, z, yaw, pitch); entity.setHeadRotation(headYaw); diff --git a/src/de/steamwar/spectatesystem/util/BlockTextCreator.java b/src/de/steamwar/spectatesystem/util/BlockTextCreator.java index 9b922d8..12a148f 100644 --- a/src/de/steamwar/spectatesystem/util/BlockTextCreator.java +++ b/src/de/steamwar/spectatesystem/util/BlockTextCreator.java @@ -15,6 +15,8 @@ import de.steamwar.spectatesystem.Config; import de.steamwar.spectatesystem.SpectateSystem; import de.steamwar.sql.Team; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.DyeColor; import java.io.File; import java.io.FileInputStream; @@ -70,9 +72,9 @@ public class BlockTextCreator { return lengthes[lengthes.length - 1] + offsets[offsets.length - 1]; } - private static void pasteChar(BlockArrayClipboard character, int charOffset, int length, int x, int y, int z, AffineTransform transform){ + private static void pasteChar(BlockArrayClipboard character, int charOffset, int length, int x, int y, int z, AffineTransform transform, DyeColor c){ BlockVector3 offset = character.getRegion().getMinimumPoint().subtract(character.getOrigin()); - BlockVector3 v = BlockVector3.ZERO.subtract(- charOffset - length / 2, 0, 0).subtract(offset); + BlockVector3 v = BlockVector3.ZERO.subtract(- charOffset + length / 2, 0, 0).subtract(offset); v = transform.apply(v.toVector3()).toBlockPoint(); v = v.add(x, y, z); @@ -83,17 +85,21 @@ public class BlockTextCreator { e.flushSession(); } - private static void pasteText(String text, int x, int y, int z, AffineTransform transform){ + private static void pasteText(String text, int x, int y, int z, AffineTransform transform, DyeColor c){ BlockArrayClipboard[] characters = createText(text); int[] lengthes = characterSize(characters); int[] offsets = textOffsets(lengthes); int length = textLength(lengthes, offsets); for(int i = 0; i < characters.length; i++) - pasteChar(characters[i], offsets[i], length, x, y, z, transform); + pasteChar(characters[i], offsets[i], length, x, y, z, transform, c); + Paster.replaceTeamColor( + WorldEdit.getInstance().getEditSessionFactory().getEditSession(WORLD, -1), + c, + x, y, z, length, 6, 0); } - private static void pasteForTeam(int teamId, int x, int z, boolean rotate){ + private static void pasteForTeam(int teamId, int x, int z, boolean rotate, String color){ Team team = Team.get(teamId); AffineTransform aT = new AffineTransform(); if(rotate){ @@ -101,11 +107,12 @@ public class BlockTextCreator { z += Config.SchemsizeZ / 2; }else z -= Config.SchemsizeZ / 2; - pasteText(team.getTeamKuerzel(), x, Config.upperArenaBorder, z, aT); + DyeColor c = ColorConverter.chat2dye(ChatColor.getByChar(ChatColor.getLastColors(color).replace("ยง", ""))); + pasteText(team.getTeamKuerzel(), x, Config.upperArenaBorder, z, aT, c); } public static void pasteTeamNames(int teamBlueId, int teamRedId){ - pasteForTeam(teamBlueId, Config.TeamBluePasteX, Config.TeamBluePasteZ, Config.TeamBlueRotate); - pasteForTeam(teamRedId, Config.TeamRedPasteX, Config.TeamRedPasteZ, Config.TeamRedRotate); + pasteForTeam(teamBlueId, Config.TeamBluePasteX, Config.TeamBluePasteZ, Config.TeamBlueRotate, Config.TeamBluePrefix); + pasteForTeam(teamRedId, Config.TeamRedPasteX, Config.TeamRedPasteZ, Config.TeamRedRotate, Config.TeamRedPrefix); } } diff --git a/src/de/steamwar/spectatesystem/util/Paster.java b/src/de/steamwar/spectatesystem/util/Paster.java index 689f074..63bf309 100644 --- a/src/de/steamwar/spectatesystem/util/Paster.java +++ b/src/de/steamwar/spectatesystem/util/Paster.java @@ -59,8 +59,12 @@ public class Paster { private static final Set CARPET_SET = Collections.singleton(Objects.requireNonNull(BlockTypes.PINK_CARPET).getDefaultState().toBaseBlock()); public static void replaceTeamColor(EditSession e, DyeColor c, int cornerX, int cornerY, int cornerZ){ + replaceTeamColor(e, c, cornerX, cornerY, cornerZ, Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ); + } + + public static void replaceTeamColor(EditSession e, DyeColor c, int cornerX, int cornerY, int cornerZ, int sizeX, int sizeY, int sizeZ){ BlockVector3 corner3 = BlockVector3.at(cornerX, cornerY, cornerZ); - BlockVector3 schemsize3 = BlockVector3.at(Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ); + BlockVector3 schemsize3 = BlockVector3.at(sizeX, sizeY, sizeZ); CuboidRegion region = new CuboidRegion(corner3, corner3.add(schemsize3)); try { e.replaceBlocks(region, WOOL_SET, Objects.requireNonNull(BlockTypes.get(c.name().toLowerCase() + "_wool")).getDefaultState().toBaseBlock()); diff --git a/src/de/steamwar/spectatesystem/util/WorldLoader.java b/src/de/steamwar/spectatesystem/util/WorldLoader.java index 99b4633..f46e93d 100644 --- a/src/de/steamwar/spectatesystem/util/WorldLoader.java +++ b/src/de/steamwar/spectatesystem/util/WorldLoader.java @@ -20,15 +20,9 @@ package de.steamwar.spectatesystem.util; import de.steamwar.spectatesystem.SpectateSystem; -import net.minecraft.server.v1_15_R1.PacketPlayOutMapChunk; -import net.minecraft.server.v1_15_R1.PlayerChunkMap; +import de.steamwar.spectatesystem.elements.REntity; import org.bukkit.Bukkit; -import org.bukkit.Chunk; import org.bukkit.World; -import org.bukkit.craftbukkit.v1_15_R1.CraftChunk; -import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; public class WorldLoader { private WorldLoader(){} @@ -37,6 +31,8 @@ public class WorldLoader { public static void reloadWorld(){ Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> { + REntity.removeAll(); + /* Chunk[] chunks = world.getLoadedChunks(); PlayerChunkMap playerChunkMap = ((CraftWorld)world).getHandle().getChunkProvider().playerChunkMap; for(long l : playerChunkMap.updatingChunks.keySet()) @@ -46,7 +42,7 @@ public class WorldLoader { //world.getChunkAt(chunk.getX(), chunk.getZ()); for(Player player : Bukkit.getOnlinePlayers()) ((CraftPlayer)player).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)chunk).getHandle(), 65535)); - } + }*/ }); } }