From 1a63993de13a02d87647a9b0485516372f8eacc1 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 15 Oct 2020 18:16:34 +0200 Subject: [PATCH] Push current changes --- .../spectatesystem/FightfileConnection.java | 15 +++++ .../spectatesystem/FightserverConnection.java | 48 +------------- .../steamwar/spectatesystem/PacketSource.java | 63 +++++++++++++++---- .../listener/ArenaListener.java | 2 - .../spectatesystem/util/BlockTextCreator.java | 6 +- .../spectatesystem/util/WorldLoader.java | 12 +++- 6 files changed, 82 insertions(+), 64 deletions(-) create mode 100644 src/de/steamwar/spectatesystem/FightfileConnection.java diff --git a/src/de/steamwar/spectatesystem/FightfileConnection.java b/src/de/steamwar/spectatesystem/FightfileConnection.java new file mode 100644 index 0000000..801cea5 --- /dev/null +++ b/src/de/steamwar/spectatesystem/FightfileConnection.java @@ -0,0 +1,15 @@ +package de.steamwar.spectatesystem; + +import java.io.*; + +public class FightfileConnection extends PacketSource { + + public FightfileConnection(File fightFile) throws IOException { + super(new DataInputStream(new FileInputStream(fightFile))); + } + + @Override + boolean isClosed() { + return false; + } +} diff --git a/src/de/steamwar/spectatesystem/FightserverConnection.java b/src/de/steamwar/spectatesystem/FightserverConnection.java index 6a5dd0d..c7065e9 100644 --- a/src/de/steamwar/spectatesystem/FightserverConnection.java +++ b/src/de/steamwar/spectatesystem/FightserverConnection.java @@ -26,61 +26,19 @@ import java.io.IOException; import java.net.Socket; import java.util.logging.Level; -public class FightserverConnection implements PacketSource { +public class FightserverConnection extends PacketSource { private final Socket socket; - private final DataInputStream inputStream; FightserverConnection(Socket socket) throws IOException{ + super(new DataInputStream(socket.getInputStream())); this.socket = socket; - this.inputStream = new DataInputStream(socket.getInputStream()); - new PacketProcessor(this); - } - - @Override - public byte rByte() throws IOException { - return inputStream.readByte(); - } - - @Override - public boolean rBoolean() throws IOException { - return inputStream.readBoolean(); - } - - @Override - public short rShort() throws IOException { - return inputStream.readShort(); - } - - @Override - public int rInt() throws IOException { - return inputStream.readInt(); - } - - @Override - public long rLong() throws IOException { - return inputStream.readLong(); - } - - @Override - public float rFloat() throws IOException { - return inputStream.readFloat(); - } - - @Override - public double rDouble() throws IOException { - return inputStream.readDouble(); - } - - @Override - public String rString() throws IOException { - return inputStream.readUTF(); } @Override public void close() { + super.close(); try { socket.close(); - inputStream.close(); } catch (IOException e) { Bukkit.getLogger().log(Level.SEVERE, "IOException on close", e); } diff --git a/src/de/steamwar/spectatesystem/PacketSource.java b/src/de/steamwar/spectatesystem/PacketSource.java index 71e90b5..4ac291a 100644 --- a/src/de/steamwar/spectatesystem/PacketSource.java +++ b/src/de/steamwar/spectatesystem/PacketSource.java @@ -19,19 +19,60 @@ package de.steamwar.spectatesystem; +import org.bukkit.Bukkit; + +import java.io.DataInputStream; import java.io.IOException; +import java.util.logging.Level; -public interface PacketSource { +public abstract class PacketSource { - byte rByte() throws IOException; - boolean rBoolean() throws IOException; - short rShort() throws IOException; - int rInt() throws IOException; - long rLong() throws IOException; - float rFloat() throws IOException; - double rDouble() throws IOException; - String rString() throws IOException; + private final DataInputStream inputStream; - void close(); - boolean isClosed(); + protected PacketSource(DataInputStream inputStream){ + this.inputStream = inputStream; + new PacketProcessor(this); + } + + public byte rByte() throws IOException { + return inputStream.readByte(); + } + + public boolean rBoolean() throws IOException { + return inputStream.readBoolean(); + } + + public short rShort() throws IOException { + return inputStream.readShort(); + } + + public int rInt() throws IOException { + return inputStream.readInt(); + } + + public long rLong() throws IOException { + return inputStream.readLong(); + } + + public float rFloat() throws IOException { + return inputStream.readFloat(); + } + + public double rDouble() throws IOException { + return inputStream.readDouble(); + } + + public String rString() throws IOException { + return inputStream.readUTF(); + } + + public void close(){ + try { + inputStream.close(); + } catch (IOException e) { + Bukkit.getLogger().log(Level.SEVERE, "IOException on close", e); + } + } + + abstract boolean isClosed(); } diff --git a/src/de/steamwar/spectatesystem/listener/ArenaListener.java b/src/de/steamwar/spectatesystem/listener/ArenaListener.java index 625c041..1fb4249 100644 --- a/src/de/steamwar/spectatesystem/listener/ArenaListener.java +++ b/src/de/steamwar/spectatesystem/listener/ArenaListener.java @@ -29,7 +29,6 @@ import org.bukkit.BanList; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_15_R1.CraftChunk; -import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockExplodeEvent; @@ -104,7 +103,6 @@ public class ArenaListener extends BasicListener { @EventHandler public void onWorldLoad(WorldLoadEvent e){ e.getWorld().setAutoSave(false); - ((CraftWorld)e.getWorld()).getHandle().savingDisabled = true; } @EventHandler diff --git a/src/de/steamwar/spectatesystem/util/BlockTextCreator.java b/src/de/steamwar/spectatesystem/util/BlockTextCreator.java index 8c22ad0..9b922d8 100644 --- a/src/de/steamwar/spectatesystem/util/BlockTextCreator.java +++ b/src/de/steamwar/spectatesystem/util/BlockTextCreator.java @@ -28,7 +28,7 @@ import java.util.zip.GZIPInputStream; public class BlockTextCreator { private BlockTextCreator(){} - private final static int BETWEEN_CHARACTERS_WIDTH = 1; + private static final int BETWEEN_CHARACTERS_WIDTH = 1; private static final World WORLD = new BukkitWorld(Bukkit.getWorlds().get(0)); @@ -70,9 +70,9 @@ public class BlockTextCreator { return lengthes[lengthes.length - 1] + offsets[offsets.length - 1]; } - private static void pasteChar(BlockArrayClipboard character, int char_offset, 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){ BlockVector3 offset = character.getRegion().getMinimumPoint().subtract(character.getOrigin()); - BlockVector3 v = BlockVector3.ZERO.subtract(char_offset - 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); diff --git a/src/de/steamwar/spectatesystem/util/WorldLoader.java b/src/de/steamwar/spectatesystem/util/WorldLoader.java index 3dbafd4..99b4633 100644 --- a/src/de/steamwar/spectatesystem/util/WorldLoader.java +++ b/src/de/steamwar/spectatesystem/util/WorldLoader.java @@ -21,10 +21,12 @@ 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 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; @@ -35,9 +37,13 @@ public class WorldLoader { public static void reloadWorld(){ Bukkit.getScheduler().runTask(SpectateSystem.get(), () -> { - for(Chunk chunk: world.getLoadedChunks()){ - world.unloadChunk(chunk.getX(), chunk.getZ(), false); - world.getChunkAt(chunk.getX(), chunk.getZ()); + Chunk[] chunks = world.getLoadedChunks(); + PlayerChunkMap playerChunkMap = ((CraftWorld)world).getHandle().getChunkProvider().playerChunkMap; + for(long l : playerChunkMap.updatingChunks.keySet()) + playerChunkMap.unloadQueue.add(l); + System.out.println(world.getLoadedChunks().length); + for(Chunk chunk: chunks){ + //world.getChunkAt(chunk.getX(), chunk.getZ()); for(Player player : Bukkit.getOnlinePlayers()) ((CraftPlayer)player).getHandle().playerConnection.sendPacket(new PacketPlayOutMapChunk(((CraftChunk)chunk).getHandle(), 65535)); }