From c13b024f93effabfb2e45c66858258e1d924e098 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 4 Jul 2020 10:49:49 +0200 Subject: [PATCH 01/30] First sections of a record system Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/FightSystem.java | 1 + .../listener/EventRecordListener.java | 27 +++++++++++++++++++ .../fightsystem/record/RecordSystem.java | 4 +++ 3 files changed, 32 insertions(+) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index feb9395..d21ac17 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -71,6 +71,7 @@ public class FightSystem extends JavaPlugin { new InFightInventoryListener(); new FreezeWorldStateListener(); new EventJoinListener(); + new EventRecordListener(); new CheckListener(); new TestListener(); new NormalJoinListener(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java new file mode 100644 index 0000000..720dbe0 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java @@ -0,0 +1,27 @@ +package de.steamwar.fightsystem.listener; + +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightPlayer; +import de.steamwar.fightsystem.states.FightState; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerJoinEvent; + +import java.util.EnumSet; + +public class EventRecordListener extends BasicListener { + + public EventRecordListener() { + super(Config.event() ? EnumSet.allOf(FightState.class) : EnumSet.noneOf(FightState.class)); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onPlayerJoin(PlayerJoinEvent e){ + FightPlayer fp = Fight.getFightPlayer(e.getPlayer()); + if(fp == null || !fp.isLiving()) + return; + + //TODO: Send Change + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java new file mode 100644 index 0000000..a373160 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -0,0 +1,4 @@ +package de.steamwar.fightsystem.record; + +public class RecordSystem { +} -- 2.39.2 From 7af46a1f13ca0d1dce1dbc92a7befc0b6490e70a Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 11 Jul 2020 07:17:10 +0200 Subject: [PATCH 02/30] More WIP RecordSystem Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/FightSystem.java | 2 + .../listener/EventRecordListener.java | 13 +++- .../fightsystem/record/RecordSystem.java | 74 +++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index d21ac17..5498d67 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -9,6 +9,7 @@ import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.kit.KitManager; import de.steamwar.fightsystem.listener.*; +import de.steamwar.fightsystem.record.RecordSystem; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.utils.*; @@ -107,6 +108,7 @@ public class FightSystem extends JavaPlugin { Objects.requireNonNull(getCommand("ready")).setExecutor(new EventDummyCommand()); Objects.requireNonNull(getCommand("ak")).setExecutor(new EventDummyCommand()); Objects.requireNonNull(getCommand("leader")).setExecutor(new EventDummyCommand()); + RecordSystem.init(); setPreSchemState(); }else if(Config.test()){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java index 720dbe0..bfea12e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java @@ -3,10 +3,12 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; +import de.steamwar.fightsystem.record.RecordSystem; import de.steamwar.fightsystem.states.FightState; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerMoveEvent; import java.util.EnumSet; @@ -22,6 +24,15 @@ public class EventRecordListener extends BasicListener { if(fp == null || !fp.isLiving()) return; - //TODO: Send Change + RecordSystem.playerJoins(e.getPlayer()); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onPlayerMove(PlayerMoveEvent e){ + FightPlayer fp = Fight.getFightPlayer(e.getPlayer()); + if(fp == null || !fp.isLiving()) + return; + + RecordSystem.entityMoves(e.getPlayer()); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java index a373160..1e228c2 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -1,4 +1,78 @@ package de.steamwar.fightsystem.record; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.sql.SteamwarUser; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufAllocator; +import io.netty.buffer.UnpooledUnsafeDirectByteBuf; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + public class RecordSystem { + + public static void init(){ + if(!Config.event()) + return; + + Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), RecordSystem::checkWorldState, 1, 1); + } + + /* + * PlayerJoinPacket (0x00) + int SWUserId + int EntityId + * EntityMovePacket (0x01) + int EntityId + double x, y, z + float pitch, yaw + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * */ + + public static void playerJoins(Player p){ + SteamwarUser user = SteamwarUser.get(p.getUniqueId()); + + ByteBuf buf = new UnpooledUnsafeDirectByteBuf(ByteBufAllocator.DEFAULT, 8, 8); //TODO size + buf.writeByte(0x00); + buf.writeInt(user.getId()); + buf.writeInt(p.getEntityId()); + send(buf); + + entityMoves(p); + } + + public static void entityMoves(Entity e){ + Location location = e.getLocation(); + + ByteBuf buf = new UnpooledUnsafeDirectByteBuf(ByteBufAllocator.DEFAULT, 8, 8); //TODO size + buf.writeByte(0x01); + buf.writeInt(e.getEntityId()); + buf.writeDouble(location.getX()); + buf.writeDouble(location.getY()); + buf.writeDouble(location.getZ()); + buf.writeFloat(location.getPitch()); + buf.writeFloat(location.getYaw()); + send(buf); + } + + private static void send(ByteBuf buf){ + + } + + private static void checkWorldState(){ + //TODO: TNT Entity position check + } } -- 2.39.2 From 10c9cf3ae58cc1b903280fafdbee48a32ca4a209 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 25 Jul 2020 09:55:05 +0200 Subject: [PATCH 03/30] More RecordSystem Signed-off-by: Lixfel --- .../listener/EventRecordListener.java | 2 ++ .../fightsystem/record/RecordSystem.java | 34 +++++++++++++------ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java index bfea12e..af677e9 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java @@ -35,4 +35,6 @@ public class EventRecordListener extends BasicListener { RecordSystem.entityMoves(e.getPlayer()); } + + //TODO: Listener, if player gets out (leaves, dies or starts to spectate), alternatively: track sent players } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java index 1e228c2..632048f 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -21,16 +21,16 @@ public class RecordSystem { } /* - * PlayerJoinPacket (0x00) + int SWUserId + int EntityId + * PlayerJoinPacket (0x00) + int EntityId + int SWUserId * EntityMovePacket (0x01) + int EntityId + double x, y, z + float pitch, yaw + * EntityDespawnsPacket (0x02) + int EntityId TODO Implementation * + * TODO (Player-Oriented): + * ItemInHandPacket (0x03) + int EntityId + * LeftClickPacket (0x04) + int EntityId + * RightClickPacket (0x05) + int EntityId TODO Bow spanning * - * - * - * - * - * - * + * TODO: Block Change Recordings * * * @@ -45,10 +45,10 @@ public class RecordSystem { public static void playerJoins(Player p){ SteamwarUser user = SteamwarUser.get(p.getUniqueId()); - ByteBuf buf = new UnpooledUnsafeDirectByteBuf(ByteBufAllocator.DEFAULT, 8, 8); //TODO size + ByteBuf buf = getByteBuf(); buf.writeByte(0x00); - buf.writeInt(user.getId()); buf.writeInt(p.getEntityId()); + buf.writeInt(user.getId()); send(buf); entityMoves(p); @@ -57,7 +57,7 @@ public class RecordSystem { public static void entityMoves(Entity e){ Location location = e.getLocation(); - ByteBuf buf = new UnpooledUnsafeDirectByteBuf(ByteBufAllocator.DEFAULT, 8, 8); //TODO size + ByteBuf buf = getByteBuf(); buf.writeByte(0x01); buf.writeInt(e.getEntityId()); buf.writeDouble(location.getX()); @@ -68,11 +68,23 @@ public class RecordSystem { send(buf); } + public static void playerLeaves(Player p){ + SteamwarUser user = SteamwarUser.get(p.getUniqueId()); + + ByteBuf buf = getByteBuf(); + buf.writeByte(0x02); + buf.writeInt(p.getEntityId()); + } + + private static ByteBuf getByteBuf(){ + return new UnpooledUnsafeDirectByteBuf(ByteBufAllocator.DEFAULT, 8, 8); //TODO size + } + private static void send(ByteBuf buf){ } private static void checkWorldState(){ - //TODO: TNT Entity position check + //TODO: Entity position transmissions } } -- 2.39.2 From 19d7d719e857c9726b1e0dd1ce98eee141ee92e5 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 15 Aug 2020 23:31:18 +0200 Subject: [PATCH 04/30] Add SpectateConnection --- .../record/SpectateConnection.java | 131 ++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java new file mode 100644 index 0000000..97754bd --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java @@ -0,0 +1,131 @@ +package de.steamwar.fightsystem.record; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; + +public class SpectateConnection { + + public static SpectateConnection getInstance() { + return spectateConnection; + } + + public static SpectateConnection build(String ip, int port) { + spectateConnection = new SpectateConnection(ip, port); + return spectateConnection; + } + + public static void cleanUp() { + if (spectateConnection == null) { + return; + } + spectateConnection.internalCleanUp(); + spectateConnection = null; + } + + private static SpectateConnection spectateConnection = null; + + private void internalCleanUp() { + try { + socket.close(); + inputStream.close(); + outputStream.close(); + } catch (IOException e) { + errorCode = 2; + } + } + + /** + * 0 - OK + * 1 - No Connect + * 2 - Error while cleanup + * 3 - Error while reading + * 4 - Error while writing + * 5 - Error while flushing + */ + private int errorCode = 0; + + private Socket socket; + private InputStream inputStream; + private OutputStream outputStream; + + private SpectateConnection(String ip, int port) { + try { + this.socket = new Socket(ip, port); + this.inputStream = socket.getInputStream(); + this.outputStream = socket.getOutputStream(); + } catch (IOException e) { + errorCode = 1; + } + } + + public int getErrorCode() { + return errorCode; + } + + public InputStream getInputStream() { + return inputStream; + } + + public OutputStream getOutputStream() { + return outputStream; + } + + public int read() { + try { + return inputStream.read(); + } catch (IOException e) { + errorCode = 3; + return -2; + } + } + + public byte[] lazyRead(int length) { + try { + byte[] bytes = new byte[length]; + inputStream.read(bytes); + return bytes; + } catch (IOException e) { + errorCode = 3; + return new byte[length]; + } + } + + public byte[] read(int length) { + byte[] bytes = new byte[length]; + for (int i = 0; i < length; i++) { + bytes[i] = (byte) read(); + if (errorCode != 0) { + break; + } + } + return bytes; + } + + public void write(byte b) { + try { + outputStream.write(b); + } catch (IOException e) { + errorCode = 4; + } + } + + public void write(byte... bytes) { + try { + outputStream.write(bytes); + } catch (IOException e) { + errorCode = 4; + } + flush(); + } + + public void flush() { + try { + outputStream.flush(); + } catch (IOException e) { + errorCode = 5; + } + } + +} -- 2.39.2 From 0f3943cd73201d6f1bd38a5b6994ffddab069127 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 22 Aug 2020 10:01:57 +0200 Subject: [PATCH 05/30] First player movement implementation Signed-off-by: Lixfel --- .../listener/EventRecordListener.java | 18 +++ .../fightsystem/record/RecordSystem.java | 76 ++++++---- .../record/SpectateConnection.java | 141 ++++++------------ 3 files changed, 107 insertions(+), 128 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java index af677e9..41b5d11 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java @@ -4,9 +4,11 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.record.RecordSystem; +import de.steamwar.fightsystem.record.SpectateConnection; import de.steamwar.fightsystem.states.FightState; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerMoveEvent; @@ -18,6 +20,13 @@ public class EventRecordListener extends BasicListener { super(Config.event() ? EnumSet.allOf(FightState.class) : EnumSet.noneOf(FightState.class)); } + @Override + public void enable() { + RecordSystem.init(); + SpectateConnection.init("127.0.0.1", 2222); + super.enable(); + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPlayerJoin(PlayerJoinEvent e){ FightPlayer fp = Fight.getFightPlayer(e.getPlayer()); @@ -36,5 +45,14 @@ public class EventRecordListener extends BasicListener { RecordSystem.entityMoves(e.getPlayer()); } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onPlayerDeath(PlayerDeathEvent e){ + FightPlayer fp = Fight.getFightPlayer(e.getEntity()); + if(fp == null || fp.isLiving()) + return; + + RecordSystem.entityDespawns(e.getEntity()); + } + //TODO: Listener, if player gets out (leaves, dies or starts to spectate), alternatively: track sent players } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java index 632048f..dd194f9 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -3,14 +3,16 @@ package de.steamwar.fightsystem.record; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.sql.SteamwarUser; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufAllocator; -import io.netty.buffer.UnpooledUnsafeDirectByteBuf; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import java.io.DataOutputStream; +import java.io.IOException; +import java.net.SocketException; +import java.util.logging.Level; + public class RecordSystem { public static void init(){ @@ -23,7 +25,7 @@ public class RecordSystem { /* * PlayerJoinPacket (0x00) + int EntityId + int SWUserId * EntityMovePacket (0x01) + int EntityId + double x, y, z + float pitch, yaw - * EntityDespawnsPacket (0x02) + int EntityId TODO Implementation + * EntityDespawnsPacket (0x02) + int EntityId * * TODO (Player-Oriented): * ItemInHandPacket (0x03) + int EntityId @@ -45,43 +47,57 @@ public class RecordSystem { public static void playerJoins(Player p){ SteamwarUser user = SteamwarUser.get(p.getUniqueId()); - ByteBuf buf = getByteBuf(); - buf.writeByte(0x00); - buf.writeInt(p.getEntityId()); - buf.writeInt(user.getId()); - send(buf); - - entityMoves(p); + DataOutputStream out = getOutput(); + try { + out.writeByte(0x00); + out.writeInt(p.getEntityId()); + out.writeInt(user.getId()); + entityMoves(p); + } catch (IOException ex) { + exceptionHandling(ex); + } } public static void entityMoves(Entity e){ Location location = e.getLocation(); - ByteBuf buf = getByteBuf(); - buf.writeByte(0x01); - buf.writeInt(e.getEntityId()); - buf.writeDouble(location.getX()); - buf.writeDouble(location.getY()); - buf.writeDouble(location.getZ()); - buf.writeFloat(location.getPitch()); - buf.writeFloat(location.getYaw()); - send(buf); + DataOutputStream out = getOutput(); + try { + out.writeByte(0x01); + out.writeInt(e.getEntityId()); + out.writeDouble(location.getX()); + out.writeDouble(location.getY()); + out.writeDouble(location.getZ()); + out.writeFloat(location.getPitch()); + out.writeFloat(location.getYaw()); + out.flush(); + } catch (IOException ex) { + exceptionHandling(ex); + } } - public static void playerLeaves(Player p){ - SteamwarUser user = SteamwarUser.get(p.getUniqueId()); - - ByteBuf buf = getByteBuf(); - buf.writeByte(0x02); - buf.writeInt(p.getEntityId()); + public static void entityDespawns(Entity e){ + DataOutputStream out = getOutput(); + try { + out.writeByte(0x02); + out.writeInt(e.getEntityId()); + out.flush(); + } catch (IOException ex) { + exceptionHandling(ex); + } } - private static ByteBuf getByteBuf(){ - return new UnpooledUnsafeDirectByteBuf(ByteBufAllocator.DEFAULT, 8, 8); //TODO size + private static DataOutputStream getOutput(){ + return SpectateConnection.get().getOutput(); } - private static void send(ByteBuf buf){ - + private static void exceptionHandling(IOException e){ + if(e instanceof SocketException){ + Bukkit.getLogger().log(Level.SEVERE, "SocketException", e); + SpectateConnection.get().close(); + }else{ + throw new SecurityException("Unknown Exception", e); + } } private static void checkWorldState(){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java index 97754bd..2f85f89 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java @@ -1,131 +1,76 @@ package de.steamwar.fightsystem.record; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; +import org.bukkit.Bukkit; + +import java.io.*; import java.net.Socket; +import java.util.logging.Level; public class SpectateConnection { - public static SpectateConnection getInstance() { + private static SpectateConnection spectateConnection = new SpectateConnection(); + + public static SpectateConnection get() { return spectateConnection; } - public static SpectateConnection build(String ip, int port) { - spectateConnection = new SpectateConnection(ip, port); - return spectateConnection; - } - - public static void cleanUp() { - if (spectateConnection == null) { - return; - } - spectateConnection.internalCleanUp(); - spectateConnection = null; - } - - private static SpectateConnection spectateConnection = null; - - private void internalCleanUp() { + public static void init(String ip, int port){ try { - socket.close(); - inputStream.close(); - outputStream.close(); + spectateConnection = new SpectateConnection(ip, port); } catch (IOException e) { - errorCode = 2; + Bukkit.getLogger().log(Level.SEVERE, "Could not init spectateconnection", e); } } - /** - * 0 - OK - * 1 - No Connect - * 2 - Error while cleanup - * 3 - Error while reading - * 4 - Error while writing - * 5 - Error while flushing - */ - private int errorCode = 0; + private final Socket socket; + private final DataInputStream inputStream; + private final DataOutputStream outputStream; - private Socket socket; - private InputStream inputStream; - private OutputStream outputStream; - - private SpectateConnection(String ip, int port) { - try { - this.socket = new Socket(ip, port); - this.inputStream = socket.getInputStream(); - this.outputStream = socket.getOutputStream(); - } catch (IOException e) { - errorCode = 1; - } + private SpectateConnection(String ip, int port) throws IOException{ + this.socket = new Socket(ip, port); + this.inputStream = new DataInputStream(socket.getInputStream()); + this.outputStream = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream())); } - public int getErrorCode() { - return errorCode; + private SpectateConnection(){ + socket = null; + this.inputStream = new DataInputStream(new NullInputStream()); + this.outputStream = new DataOutputStream(new NullOutputStream()); } - public InputStream getInputStream() { + public InputStream getInput() { return inputStream; } - public OutputStream getOutputStream() { + public DataOutputStream getOutput() { return outputStream; } - public int read() { + public void close() { try { - return inputStream.read(); + if(socket != null) + socket.close(); + inputStream.close(); + outputStream.close(); } catch (IOException e) { - errorCode = 3; - return -2; + Bukkit.getLogger().log(Level.SEVERE, "IOException on close", e); + } + spectateConnection = new SpectateConnection(); + } + + private static class NullOutputStream extends OutputStream { + + @Override + public void write(int b) throws IOException { + //ignored } } - public byte[] lazyRead(int length) { - try { - byte[] bytes = new byte[length]; - inputStream.read(bytes); - return bytes; - } catch (IOException e) { - errorCode = 3; - return new byte[length]; + private static class NullInputStream extends InputStream { + + @Override + public int read() throws IOException { + throw new IOException("NullInputStreamReadAttempt"); } } - - public byte[] read(int length) { - byte[] bytes = new byte[length]; - for (int i = 0; i < length; i++) { - bytes[i] = (byte) read(); - if (errorCode != 0) { - break; - } - } - return bytes; - } - - public void write(byte b) { - try { - outputStream.write(b); - } catch (IOException e) { - errorCode = 4; - } - } - - public void write(byte... bytes) { - try { - outputStream.write(bytes); - } catch (IOException e) { - errorCode = 4; - } - flush(); - } - - public void flush() { - try { - outputStream.flush(); - } catch (IOException e) { - errorCode = 5; - } - } - } -- 2.39.2 From ce39b0a27627b07dd12f8018a6699a16f00c767c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 22 Aug 2020 10:45:40 +0200 Subject: [PATCH 06/30] Rework recorder Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/Config.java | 4 + .../listener/EventRecordListener.java | 2 - .../fightsystem/record/RecordSystem.java | 64 +++------ .../steamwar/fightsystem/record/Recorder.java | 65 +++++++++ .../record/SpectateConnection.java | 136 +++++++++++------- 5 files changed, 173 insertions(+), 98 deletions(-) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index f5da638..68d512d 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -125,6 +125,10 @@ public class Config { //check parameter public static final int CheckSchemID; + //live recorder parameter + public static final String spectateIP = "127.0.0.1"; + public static final int spectatePort = 2222; + static{ File worldConfigFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "config.yml"); if(!worldConfigFile.exists()) { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java index 41b5d11..d3949f2 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java @@ -4,7 +4,6 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.record.RecordSystem; -import de.steamwar.fightsystem.record.SpectateConnection; import de.steamwar.fightsystem.states.FightState; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -23,7 +22,6 @@ public class EventRecordListener extends BasicListener { @Override public void enable() { RecordSystem.init(); - SpectateConnection.init("127.0.0.1", 2222); super.enable(); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java index dd194f9..a863899 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -8,11 +8,6 @@ import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import java.io.DataOutputStream; -import java.io.IOException; -import java.net.SocketException; -import java.util.logging.Level; - public class RecordSystem { public static void init(){ @@ -20,6 +15,7 @@ public class RecordSystem { return; Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), RecordSystem::checkWorldState, 1, 1); + new SpectateConnection(); } /* @@ -47,57 +43,29 @@ public class RecordSystem { public static void playerJoins(Player p){ SteamwarUser user = SteamwarUser.get(p.getUniqueId()); - DataOutputStream out = getOutput(); - try { - out.writeByte(0x00); - out.writeInt(p.getEntityId()); - out.writeInt(user.getId()); - entityMoves(p); - } catch (IOException ex) { - exceptionHandling(ex); - } + Recorder.rByte(0x00); + Recorder.rInt(p.getEntityId()); + Recorder.rInt(user.getId()); + entityMoves(p); } public static void entityMoves(Entity e){ Location location = e.getLocation(); - DataOutputStream out = getOutput(); - try { - out.writeByte(0x01); - out.writeInt(e.getEntityId()); - out.writeDouble(location.getX()); - out.writeDouble(location.getY()); - out.writeDouble(location.getZ()); - out.writeFloat(location.getPitch()); - out.writeFloat(location.getYaw()); - out.flush(); - } catch (IOException ex) { - exceptionHandling(ex); - } + Recorder.rByte(0x01); + Recorder.rInt(e.getEntityId()); + Recorder.rDouble(location.getX()); + Recorder.rDouble(location.getY()); + Recorder.rDouble(location.getZ()); + Recorder.rFloat(location.getPitch()); + Recorder.rFloat(location.getYaw()); + Recorder.flush(); } public static void entityDespawns(Entity e){ - DataOutputStream out = getOutput(); - try { - out.writeByte(0x02); - out.writeInt(e.getEntityId()); - out.flush(); - } catch (IOException ex) { - exceptionHandling(ex); - } - } - - private static DataOutputStream getOutput(){ - return SpectateConnection.get().getOutput(); - } - - private static void exceptionHandling(IOException e){ - if(e instanceof SocketException){ - Bukkit.getLogger().log(Level.SEVERE, "SocketException", e); - SpectateConnection.get().close(); - }else{ - throw new SecurityException("Unknown Exception", e); - } + Recorder.rByte(0x02); + Recorder.rInt(e.getEntityId()); + Recorder.flush(); } private static void checkWorldState(){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java new file mode 100644 index 0000000..998e143 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java @@ -0,0 +1,65 @@ +package de.steamwar.fightsystem.record; + +import java.util.ArrayList; +import java.util.List; + +public abstract class Recorder { + + private static List recorders = new ArrayList<>(); + + public static void rByte(int b){ + recorders.forEach((recorder) -> recorder.writeByte(b)); + } + + public static void rShort(short s){ + recorders.forEach((recorder) -> recorder.writeShort(s)); + } + + public static void rInt(int i){ + recorders.forEach((recorder) -> recorder.writeInt(i)); + } + + public static void rLong(long l){ + recorders.forEach((recorder) -> recorder.writeLong(l)); + } + + public static void rFloat(float f){ + recorders.forEach((recorder) -> recorder.writeFloat(f)); + } + + public static void rDouble(double d){ + recorders.forEach((recorder) -> recorder.writeDouble(d)); + } + + public static void rString(String s){ + recorders.forEach((recorder) -> recorder.writeString(s)); + } + + public static void flush(){ + recorders.forEach(Recorder::doFlush); + } + + public static void closeAll(){ + recorders.forEach(Recorder::close); + } + + protected Recorder(){ + recorders.add(this); + } + + protected void close(){ + closeRecorder(); + recorders.remove(this); + } + + protected abstract void writeByte(int b); + protected abstract void writeShort(short s); + protected abstract void writeInt(int i); + protected abstract void writeLong(long l); + protected abstract void writeFloat(float f); + protected abstract void writeDouble(double d); + protected abstract void writeString(String s); + protected abstract void doFlush(); + + protected abstract void closeRecorder(); +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java index 2f85f89..7f50851 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java @@ -1,76 +1,116 @@ package de.steamwar.fightsystem.record; +import de.steamwar.fightsystem.Config; import org.bukkit.Bukkit; -import java.io.*; +import java.io.BufferedOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; import java.net.Socket; import java.util.logging.Level; -public class SpectateConnection { +public class SpectateConnection extends Recorder{ - private static SpectateConnection spectateConnection = new SpectateConnection(); + private Socket socket; + private DataOutputStream outputStream; - public static SpectateConnection get() { - return spectateConnection; - } - - public static void init(String ip, int port){ + SpectateConnection(){ + super(); try { - spectateConnection = new SpectateConnection(ip, port); + this.socket = new Socket(Config.spectateIP, Config.spectatePort); + this.outputStream = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream())); } catch (IOException e) { - Bukkit.getLogger().log(Level.SEVERE, "Could not init spectateconnection", e); + Bukkit.getLogger().log(Level.SEVERE, "Could not init connection", e); } } - private final Socket socket; - private final DataInputStream inputStream; - private final DataOutputStream outputStream; - - private SpectateConnection(String ip, int port) throws IOException{ - this.socket = new Socket(ip, port); - this.inputStream = new DataInputStream(socket.getInputStream()); - this.outputStream = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream())); + @Override + protected void writeByte(int b) { + try{ + outputStream.writeByte(b); + } catch (IOException e) { + close(); + Bukkit.getLogger().log(Level.SEVERE, "Could not send", e); + } } - private SpectateConnection(){ - socket = null; - this.inputStream = new DataInputStream(new NullInputStream()); - this.outputStream = new DataOutputStream(new NullOutputStream()); + @Override + protected void writeShort(short s) { + try{ + outputStream.writeShort(s); + } catch (IOException e) { + close(); + Bukkit.getLogger().log(Level.SEVERE, "Could not send", e); + } } - public InputStream getInput() { - return inputStream; + @Override + protected void writeInt(int i) { + try{ + outputStream.writeInt(i); + } catch (IOException e) { + close(); + Bukkit.getLogger().log(Level.SEVERE, "Could not send", e); + } } - public DataOutputStream getOutput() { - return outputStream; + @Override + protected void writeLong(long l) { + try{ + outputStream.writeLong(l); + } catch (IOException e) { + close(); + Bukkit.getLogger().log(Level.SEVERE, "Could not send", e); + } } - public void close() { + @Override + protected void writeFloat(float f) { + try{ + outputStream.writeFloat(f); + } catch (IOException e) { + close(); + Bukkit.getLogger().log(Level.SEVERE, "Could not send", e); + } + } + + @Override + protected void writeDouble(double d) { + try{ + outputStream.writeDouble(d); + } catch (IOException e) { + close(); + Bukkit.getLogger().log(Level.SEVERE, "Could not send", e); + } + } + + @Override + protected void writeString(String s) { + try{ + outputStream.writeChars(s); + } catch (IOException e) { + close(); + Bukkit.getLogger().log(Level.SEVERE, "Could not send", e); + } + } + + @Override + protected void doFlush() { + try{ + outputStream.flush(); + } catch (IOException e) { + close(); + Bukkit.getLogger().log(Level.SEVERE, "Could not flush", e); + } + } + + @Override + protected void closeRecorder() { try { - if(socket != null) - socket.close(); - inputStream.close(); + socket.close(); outputStream.close(); } catch (IOException e) { - Bukkit.getLogger().log(Level.SEVERE, "IOException on close", e); - } - spectateConnection = new SpectateConnection(); - } - - private static class NullOutputStream extends OutputStream { - - @Override - public void write(int b) throws IOException { - //ignored - } - } - - private static class NullInputStream extends InputStream { - - @Override - public int read() throws IOException { - throw new IOException("NullInputStreamReadAttempt"); + Bukkit.getLogger().log(Level.SEVERE, "IOException on socket close", e); } } } -- 2.39.2 From ab15562e06b9891a6a64a93ce9b1777138fb9418 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 22 Aug 2020 11:05:31 +0200 Subject: [PATCH 07/30] Merge to writeUTF Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/record/SpectateConnection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java index 7f50851..092f0ce 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java @@ -87,7 +87,7 @@ public class SpectateConnection extends Recorder{ @Override protected void writeString(String s) { try{ - outputStream.writeChars(s); + outputStream.writeUTF(s); } catch (IOException e) { close(); Bukkit.getLogger().log(Level.SEVERE, "Could not send", e); -- 2.39.2 From 626dbe96605268b1f2af7eb562ef07b6b1c0bd84 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 22 Aug 2020 15:08:35 +0200 Subject: [PATCH 08/30] Add SpectateConnection chat --- .../src/de/steamwar/fightsystem/Config.java | 3 +++ .../listener/EventRecordListener.java | 1 + .../listener/PlayerChatListener.java | 5 +++- .../fightsystem/record/RecordSystem.java | 24 ++++++++++++++++--- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 68d512d..ce965e9 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -128,6 +128,7 @@ public class Config { //live recorder parameter public static final String spectateIP = "127.0.0.1"; public static final int spectatePort = 2222; + public static final boolean recording; static{ File worldConfigFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "config.yml"); @@ -379,6 +380,8 @@ public class Config { CheckSchemID = Integer.parseInt(System.getProperty("checkSchemID", "0")); Ranked = Boolean.parseBoolean(System.getProperty("ranked", "false")); + + recording = event(); } public static boolean event(){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java index d3949f2..9b52a0f 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java @@ -8,6 +8,7 @@ import de.steamwar.fightsystem.states.FightState; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerMoveEvent; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerChatListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerChatListener.java index 44ad9bd..3688609 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerChatListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerChatListener.java @@ -4,6 +4,7 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.record.RecordSystem; import de.steamwar.fightsystem.states.FightState; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; @@ -42,7 +43,9 @@ public class PlayerChatListener extends BasicListener { event.setCancelled(true); } - private void broadcastChat(String message){ + private void broadcastChat(String message) { + if (Config.recording) + RecordSystem.chat(message); BaseComponent[] msg = TextComponent.fromLegacyText(message); for(Player p : Bukkit.getOnlinePlayers()) toChat(p, msg); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java index a863899..e3e066a 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -40,7 +40,7 @@ public class RecordSystem { * * */ - public static void playerJoins(Player p){ + public static synchronized void playerJoins(Player p){ SteamwarUser user = SteamwarUser.get(p.getUniqueId()); Recorder.rByte(0x00); @@ -49,7 +49,7 @@ public class RecordSystem { entityMoves(p); } - public static void entityMoves(Entity e){ + public static synchronized void entityMoves(Entity e){ Location location = e.getLocation(); Recorder.rByte(0x01); @@ -62,12 +62,30 @@ public class RecordSystem { Recorder.flush(); } - public static void entityDespawns(Entity e){ + public static synchronized void entityDespawns(Entity e){ Recorder.rByte(0x02); Recorder.rInt(e.getEntityId()); Recorder.flush(); } + public static synchronized void chat(String s) { + Recorder.rByte(0xA0); + Recorder.rString(s); + Recorder.flush(); + } + + public static synchronized void actionBar(String s) { + Recorder.rByte(0xA1); + Recorder.rString(s); + Recorder.flush(); + } + + public static synchronized void systemChat(String s) { + Recorder.rByte(0xA2); + Recorder.rString(s); + Recorder.flush(); + } + private static void checkWorldState(){ //TODO: Entity position transmissions } -- 2.39.2 From 7e6e4f0312eaa688b75b5dcf855013ee2c6ae676 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 22 Aug 2020 19:18:11 +0200 Subject: [PATCH 09/30] Working prototype (missing player details & schematic pasting) Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/Config.java | 6 +- .../de/steamwar/fightsystem/FightSystem.java | 7 + .../fightsystem/countdown/Countdown.java | 4 + .../listener/EventRecordListener.java | 102 +++++++++++--- .../listener/PlayerChatListener.java | 2 +- .../fightsystem/record/FileRecorder.java | 126 ++++++++++++++++++ .../fightsystem/record/RecordSystem.java | 117 ++++++++++++++-- .../steamwar/fightsystem/record/Recorder.java | 5 + .../record/SpectateConnection.java | 10 ++ 9 files changed, 345 insertions(+), 34 deletions(-) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index ce965e9..cadb5c3 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -128,7 +128,6 @@ public class Config { //live recorder parameter public static final String spectateIP = "127.0.0.1"; public static final int spectatePort = 2222; - public static final boolean recording; static{ File worldConfigFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "config.yml"); @@ -380,8 +379,6 @@ public class Config { CheckSchemID = Integer.parseInt(System.getProperty("checkSchemID", "0")); Ranked = Boolean.parseBoolean(System.getProperty("ranked", "false")); - - recording = event(); } public static boolean event(){ @@ -393,4 +390,7 @@ public class Config { public static boolean check(){ return CheckSchemID != 0; } + public static boolean recording(){ + return event(); + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index 766e05a..5a6dec8 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -10,6 +10,7 @@ import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.kit.KitManager; import de.steamwar.fightsystem.listener.*; import de.steamwar.fightsystem.record.RecordSystem; +import de.steamwar.fightsystem.record.Recorder; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.utils.*; @@ -128,6 +129,12 @@ public class FightSystem extends JavaPlugin { } } + @Override + public void onDisable() { + + Recorder.closeAll(); + } + public static void setPreSchemState() { if(fightState != FightState.PRE_LEADER_SETUP) throw new SecurityException(fightState.name()); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/Countdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/Countdown.java index d330b6c..e8766fd 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/Countdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/Countdown.java @@ -1,9 +1,11 @@ package de.steamwar.fightsystem.countdown; import de.steamwar.core.Core; +import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.listener.BasicListener; +import de.steamwar.fightsystem.record.RecordSystem; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; @@ -54,6 +56,8 @@ public abstract class Countdown { } private void broadcast(String message){ + if(Config.recording()) + RecordSystem.actionBar(message); BaseComponent[] msg = TextComponent.fromLegacyText(message); for(Player p : Bukkit.getOnlinePlayers()) BasicListener.toActionbar(p, msg); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java index 9b52a0f..db21a2a 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java @@ -1,35 +1,40 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; +import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.record.RecordSystem; import de.steamwar.fightsystem.states.FightState; +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.Sound; +import org.bukkit.SoundCategory; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockPhysicsEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.*; +import org.bukkit.event.server.BroadcastMessageEvent; import java.util.EnumSet; public class EventRecordListener extends BasicListener { + private static final int AIR = 0; + public EventRecordListener() { super(Config.event() ? EnumSet.allOf(FightState.class) : EnumSet.noneOf(FightState.class)); } - @Override - public void enable() { - RecordSystem.init(); - super.enable(); - } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPlayerJoin(PlayerJoinEvent e){ - FightPlayer fp = Fight.getFightPlayer(e.getPlayer()); - if(fp == null || !fp.isLiving()) + if(isNotSent(e.getPlayer())) return; RecordSystem.playerJoins(e.getPlayer()); @@ -37,21 +42,84 @@ public class EventRecordListener extends BasicListener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPlayerMove(PlayerMoveEvent e){ - FightPlayer fp = Fight.getFightPlayer(e.getPlayer()); - if(fp == null || !fp.isLiving()) + if(isNotSent(e.getPlayer())) return; RecordSystem.entityMoves(e.getPlayer()); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerDeath(PlayerDeathEvent e){ - FightPlayer fp = Fight.getFightPlayer(e.getEntity()); - if(fp == null || fp.isLiving()) + if(isNotSent(e.getEntity())) return; RecordSystem.entityDespawns(e.getEntity()); } - //TODO: Listener, if player gets out (leaves, dies or starts to spectate), alternatively: track sent players + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onBroadcast(BroadcastMessageEvent e){ + RecordSystem.systemChat(e.getMessage()); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onSneak(PlayerToggleSneakEvent e){ + if(isNotSent(e.getPlayer())) + return; + + RecordSystem.playerSneak(e.getPlayer(), e.isSneaking()); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onAnimation(PlayerAnimationEvent e){ + if(isNotSent(e.getPlayer())) + return; + + if(e.getAnimationType() == PlayerAnimationType.ARM_SWING) + RecordSystem.entityAnimation(e.getPlayer(), AIR); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onTNTSpawn(EntitySpawnEvent e){ + //TODO: Falling block + if(e.getEntityType() != EntityType.PRIMED_TNT) + return; + + RecordSystem.tntSpawn(e.getEntity()); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onBlockPhysics(BlockPhysicsEvent e){ + RecordSystem.blockChange(e.getBlock()); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onExplosion(EntityExplodeEvent e){ + if(e.getEntityType() != EntityType.PRIMED_TNT) + return; + + Location loc = e.getLocation(); + RecordSystem.entityDespawns(e.getEntity()); + RecordSystem.particle(loc.getX(), loc.getY(), loc.getZ(), Particle.EXPLOSION_LARGE.name()); + RecordSystem.sound(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), Sound.ENTITY_GENERIC_EXPLODE.name(), SoundCategory.BLOCKS.name(), 255.0f, 1.0f); + } + + @Override + public void stateChange(FightState state) { + if(state == FightState.SPECTATE){ + despawnTeam(Fight.getRedTeam()); + despawnTeam(Fight.getBlueTeam()); + } + } + + private void despawnTeam(FightTeam team){ + for(FightPlayer player : team.getPlayers()){ + if(player.isLiving()) + RecordSystem.entityDespawns(player.getPlayer()); + } + } + + private boolean isNotSent(Player p){ + FightPlayer fp = Fight.getFightPlayer(p); + return fp == null || !fp.isLiving() || FightSystem.getFightState() == FightState.SPECTATE; + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerChatListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerChatListener.java index 3688609..debdf3f 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerChatListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerChatListener.java @@ -44,7 +44,7 @@ public class PlayerChatListener extends BasicListener { } private void broadcastChat(String message) { - if (Config.recording) + if (Config.recording()) RecordSystem.chat(message); BaseComponent[] msg = TextComponent.fromLegacyText(message); for(Player p : Bukkit.getOnlinePlayers()) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java new file mode 100644 index 0000000..182a2bd --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java @@ -0,0 +1,126 @@ +package de.steamwar.fightsystem.record; + +import de.steamwar.fightsystem.FightSystem; +import org.bukkit.Bukkit; + +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.logging.Level; +import java.util.zip.GZIPOutputStream; + +public class FileRecorder extends Recorder { + + private final DataOutputStream outputStream; + + public FileRecorder(){ + super(); + File file = new File(FightSystem.getPlugin().getDataFolder(), "recording"); + try{ + file.createNewFile(); + outputStream = new DataOutputStream(new GZIPOutputStream(new FileOutputStream(file))); + }catch(IOException e){ + throw new SecurityException("Could not open file", e); + } + } + + @Override + protected void writeBoolean(boolean b) { + try { + outputStream.writeBoolean(b); + } catch (IOException e) { + Bukkit.getLogger().log(Level.SEVERE, "Could not write", e); + close(); + } + } + + @Override + protected void writeByte(int b) { + try { + outputStream.writeByte(b); + } catch (IOException e) { + Bukkit.getLogger().log(Level.SEVERE, "Could not write", e); + close(); + } + } + + @Override + protected void writeShort(short s) { + try { + outputStream.writeShort(s); + } catch (IOException e) { + Bukkit.getLogger().log(Level.SEVERE, "Could not write", e); + close(); + } + } + + @Override + protected void writeInt(int i) { + try { + outputStream.writeInt(i); + } catch (IOException e) { + Bukkit.getLogger().log(Level.SEVERE, "Could not write", e); + close(); + } + } + + @Override + protected void writeLong(long l) { + try { + outputStream.writeLong(l); + } catch (IOException e) { + Bukkit.getLogger().log(Level.SEVERE, "Could not write", e); + close(); + } + } + + @Override + protected void writeFloat(float f) { + try { + outputStream.writeFloat(f); + } catch (IOException e) { + Bukkit.getLogger().log(Level.SEVERE, "Could not write", e); + close(); + } + } + + @Override + protected void writeDouble(double d) { + try { + outputStream.writeDouble(d); + } catch (IOException e) { + Bukkit.getLogger().log(Level.SEVERE, "Could not write", e); + close(); + } + } + + @Override + protected void writeString(String s) { + try { + outputStream.writeUTF(s); + } catch (IOException e) { + Bukkit.getLogger().log(Level.SEVERE, "Could not write", e); + close(); + } + } + + @Override + protected void doFlush() { + try { + outputStream.flush(); + } catch (IOException e) { + Bukkit.getLogger().log(Level.SEVERE, "Could not flush", e); + close(); + } + } + + @Override + protected void closeRecorder() { + try { + outputStream.close(); + } catch (IOException e) { + Bukkit.getLogger().log(Level.SEVERE, "Could not close OutputStream", e); + } + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java index e3e066a..f2f14ee 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -3,41 +3,57 @@ package de.steamwar.fightsystem.record; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.sql.SteamwarUser; +import net.minecraft.server.v1_15_R1.BlockPosition; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v1_15_R1.block.CraftBlock; +import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.util.Vector; public class RecordSystem { + private RecordSystem(){} + + private static final World WORLD = Bukkit.getWorlds().get(0); public static void init(){ - if(!Config.event()) + if(!Config.recording()) return; Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), RecordSystem::checkWorldState, 1, 1); new SpectateConnection(); + new FileRecorder(); } /* * PlayerJoinPacket (0x00) + int EntityId + int SWUserId - * EntityMovePacket (0x01) + int EntityId + double x, y, z + float pitch, yaw + * EntityMovePacket (0x01) + int EntityId + double x, y, z + float pitch, yaw + byte headyaw * EntityDespawnsPacket (0x02) + int EntityId + * PlayerSneakPacket (0x03) + int EntityId + boolean sneaks + * EntityAnimationPacket (0x04) + int EntityId + byte animation + * TNTSpawnPacket (0x05) + int EntityId + * EntitySpeedPacket (0x06) + int EntityId + double dx, dy, dz * * TODO (Player-Oriented): * ItemInHandPacket (0x03) + int EntityId - * LeftClickPacket (0x04) + int EntityId - * RightClickPacket (0x05) + int EntityId TODO Bow spanning - * - * TODO: Block Change Recordings - * - * - * + * TODO Bow spanning * * * + * BlockPacket (0x30) + pos int, byte, int + int BlockState + * ParticlePacket (0x31) + double x, y, z + string particleType + * SoundPacket (0x32) + int x, y, z + string soundType + string soundType + float volume, pitch * * + * ChatPacket (0xa0) + String message + * ActionBarPacket (0xa1) + String message + * SystemPacket (0xa2) + String message * + * TickPacket (0xff) * */ public static synchronized void playerJoins(Player p){ @@ -59,6 +75,7 @@ public class RecordSystem { Recorder.rDouble(location.getZ()); Recorder.rFloat(location.getPitch()); Recorder.rFloat(location.getYaw()); + Recorder.rByte((int)(((CraftEntity)e).getHandle().getHeadRotation() * 256 / 360)); Recorder.flush(); } @@ -68,25 +85,99 @@ public class RecordSystem { Recorder.flush(); } + public static synchronized void playerSneak(Player p, boolean sneaks){ + Recorder.rByte(0x03); + Recorder.rInt(p.getEntityId()); + Recorder.rBoolean(sneaks); + Recorder.flush(); + } + + public static synchronized void entityAnimation(Entity e, int animation){ + Recorder.rByte(0x04); + Recorder.rInt(e.getEntityId()); + Recorder.rByte(animation); + Recorder.flush(); + } + + public static synchronized void tntSpawn(Entity e){ + Recorder.rByte(0x05); + Recorder.rInt(e.getEntityId()); + entityMoves(e); + entitySpeed(e); + } + + public static synchronized void entitySpeed(Entity e){ + Vector velocity = e.getVelocity(); + Recorder.rByte(0x06); + Recorder.rInt(e.getEntityId()); + Recorder.rDouble(velocity.getX()); + Recorder.rDouble(velocity.getY()); + Recorder.rDouble(velocity.getZ()); + Recorder.flush(); + } + + public static synchronized void blockChange(BlockPosition pos, int blockState){ + Recorder.rByte(0x30); + Recorder.rInt(pos.getX()); + Recorder.rByte(pos.getY()); + Recorder.rInt(pos.getZ()); + Recorder.rInt(blockState); + Recorder.flush(); + } + + public static synchronized void particle(double x, double y, double z, String particleType){ + Recorder.rByte(0x31); + Recorder.rDouble(x); + Recorder.rDouble(y); + Recorder.rDouble(z); + Recorder.rString(particleType); + Recorder.flush(); + } + + public static synchronized void sound(int x, int y, int z, String soundType, String soundCategory, float volume, float pitch){ + Recorder.rByte(0x32); + Recorder.rInt(x); + Recorder.rInt(y); + Recorder.rInt(z); + Recorder.rString(soundType); + Recorder.rString(soundCategory); + Recorder.rFloat(volume); + Recorder.rFloat(pitch); + Recorder.flush(); + } + public static synchronized void chat(String s) { - Recorder.rByte(0xA0); + Recorder.rByte(0xa0); Recorder.rString(s); Recorder.flush(); } public static synchronized void actionBar(String s) { - Recorder.rByte(0xA1); + Recorder.rByte(0xa1); Recorder.rString(s); Recorder.flush(); } public static synchronized void systemChat(String s) { - Recorder.rByte(0xA2); + Recorder.rByte(0xa2); Recorder.rString(s); Recorder.flush(); } + public static synchronized void tick(){ + Recorder.rByte(0xff); + Recorder.flush(); + } + + public static synchronized void blockChange(Block block){ + blockChange(((CraftBlock)block).getPosition(), net.minecraft.server.v1_15_R1.Block.REGISTRY_ID.getId(((CraftBlock)block).getNMS())); + } + private static void checkWorldState(){ - //TODO: Entity position transmissions + tick(); + for(TNTPrimed tnt : WORLD.getEntitiesByClass(TNTPrimed.class)){ + entityMoves(tnt); + entitySpeed(tnt); + } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java index 998e143..5072b9d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java @@ -7,6 +7,10 @@ public abstract class Recorder { private static List recorders = new ArrayList<>(); + public static void rBoolean(boolean b){ + recorders.forEach((recorder) -> recorder.writeBoolean(b)); + } + public static void rByte(int b){ recorders.forEach((recorder) -> recorder.writeByte(b)); } @@ -52,6 +56,7 @@ public abstract class Recorder { recorders.remove(this); } + protected abstract void writeBoolean(boolean b); protected abstract void writeByte(int b); protected abstract void writeShort(short s); protected abstract void writeInt(int i); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java index 092f0ce..df1d7ea 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java @@ -24,6 +24,16 @@ public class SpectateConnection extends Recorder{ } } + @Override + protected void writeBoolean(boolean b) { + try{ + outputStream.writeBoolean(b); + } catch (IOException e) { + close(); + Bukkit.getLogger().log(Level.SEVERE, "Could not send", e); + } + } + @Override protected void writeByte(int b) { try{ -- 2.39.2 From 6ed7ae0180e1608179c8ef75d823d823ca17bf1f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 1 Sep 2020 19:41:30 +0200 Subject: [PATCH 10/30] Implementing scoreboard, schematics, items Signed-off-by: Lixfel --- .../steamwar/fightsystem/fight/FightTeam.java | 8 ++ .../listener/EventRecordListener.java | 82 +++++++++++++++++-- .../fightsystem/record/RecordSystem.java | 54 ++++++++++-- .../fightsystem/utils/FightScoreboard.java | 39 +++++---- 4 files changed, 155 insertions(+), 28 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index 9903ce2..0a226d3 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -6,6 +6,7 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.IFightSystem; import de.steamwar.fightsystem.kit.KitManager; +import de.steamwar.fightsystem.record.RecordSystem; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.utils.*; import de.steamwar.fightsystem.winconditions.RankedPlayerLeftWincondition; @@ -236,6 +237,13 @@ public class FightTeam implements IFightTeam{ } public void pasteSchematic(){ + if(Config.recording()){ + if(blue) + RecordSystem.blueSchem(schematic.getSchemID()); + else + RecordSystem.redSchem(schematic.getSchemID()); + } + FreezeWorld freezer = new FreezeWorld(); DyeColor c = ColorConverter.chat2dye(color); EditSession e; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java index db21a2a..742e18b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java @@ -7,10 +7,7 @@ import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.record.RecordSystem; import de.steamwar.fightsystem.states.FightState; -import org.bukkit.Location; -import org.bukkit.Particle; -import org.bukkit.Sound; -import org.bukkit.SoundCategory; +import org.bukkit.*; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -19,8 +16,11 @@ import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.player.*; import org.bukkit.event.server.BroadcastMessageEvent; +import org.bukkit.inventory.ItemStack; import java.util.EnumSet; @@ -103,14 +103,86 @@ public class EventRecordListener extends BasicListener { RecordSystem.sound(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), Sound.ENTITY_GENERIC_EXPLODE.name(), SoundCategory.BLOCKS.name(), 255.0f, 1.0f); } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onItem(PlayerItemHeldEvent e){ + if(isNotSent(e.getPlayer())) + return; + + RecordSystem.item(e.getPlayer(), disarmNull(e.getPlayer().getInventory().getItem(e.getNewSlot())), "MAINHAND"); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onItemSwap(PlayerSwapHandItemsEvent e){ + if(isNotSent(e.getPlayer())) + return; + + Player player = e.getPlayer(); + RecordSystem.item(player, disarmNull(e.getMainHandItem()), "MAINHAND"); + RecordSystem.item(player, disarmNull(e.getOffHandItem()), "OFFHAND"); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onInventoryClick(InventoryClickEvent e){ + Player player = (Player) e.getWhoClicked(); + if(isNotSent(player)) + return; + + if(e.getSlotType() != InventoryType.SlotType.ARMOR) + return; + + switch(e.getSlot()){ + case 103: + RecordSystem.item(player, disarmNull(e.getCurrentItem()), "HEAD"); + break; + case 102: + RecordSystem.item(player, disarmNull(e.getCurrentItem()), "CHEST"); + break; + case 101: + RecordSystem.item(player, disarmNull(e.getCurrentItem()), "LEGS"); + break; + case 100: + default: + RecordSystem.item(player, disarmNull(e.getCurrentItem()), "FEET"); + } + } + @Override public void stateChange(FightState state) { - if(state == FightState.SPECTATE){ + if(state == FightState.PRE_RUNNING) { + Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { + setKitItems(Fight.getBlueTeam()); + setKitItems(Fight.getRedTeam()); + }, 1); + }else if(state == FightState.SPECTATE){ despawnTeam(Fight.getRedTeam()); despawnTeam(Fight.getBlueTeam()); } } + private void setKitItems(FightTeam team){ + if(FightSystem.getFightState() != FightState.PRE_RUNNING) + return; + + for(FightPlayer fp : team.getPlayers()){ + if(!fp.isLiving()) + continue; + + Player player = fp.getPlayer(); + RecordSystem.item(player, disarmNull(player.getInventory().getItemInMainHand()), "MAINHAND"); + RecordSystem.item(player, disarmNull(player.getInventory().getItemInOffHand()), "OFFHAND"); + RecordSystem.item(player, disarmNull(player.getInventory().getHelmet()), "HEAD"); + RecordSystem.item(player, disarmNull(player.getInventory().getChestplate()), "CHEST"); + RecordSystem.item(player, disarmNull(player.getInventory().getLeggings()), "LEGS"); + RecordSystem.item(player, disarmNull(player.getInventory().getBoots()), "FEET"); + } + } + + private ItemStack disarmNull(ItemStack stack){ + if(stack == null) + return new ItemStack(Material.AIR); + return stack; + } + private void despawnTeam(FightTeam team){ for(FightPlayer player : team.getPlayers()){ if(player.isLiving()) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java index f2f14ee..ad210d9 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -13,6 +13,7 @@ import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; +import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; public class RecordSystem { @@ -37,9 +38,7 @@ public class RecordSystem { * EntityAnimationPacket (0x04) + int EntityId + byte animation * TNTSpawnPacket (0x05) + int EntityId * EntitySpeedPacket (0x06) + int EntityId + double dx, dy, dz - * - * TODO (Player-Oriented): - * ItemInHandPacket (0x03) + int EntityId + * PlayerItemPacket (0x07) + int EntityId + String item + boolean enchanted + String slot * TODO Bow spanning * * @@ -49,9 +48,13 @@ public class RecordSystem { * SoundPacket (0x32) + int x, y, z + string soundType + string soundType + float volume, pitch * * - * ChatPacket (0xa0) + String message - * ActionBarPacket (0xa1) + String message - * SystemPacket (0xa2) + String message + * ChatPacket (0xA0) + String message + * ActionBarPacket (0xA1) + String message + * SystemPacket (0xA2) + String message + * BlueSchemPacket (0xB0) + int blueSchemId + * RedSchemPacket (0xB1) + int redSchemId + * ScoreboardTitlePacket (0xC0) + String scoreboardTitle + * ScoreboardDataPacket (0xC1) + String key + int value * * TickPacket (0xff) * */ @@ -116,6 +119,14 @@ public class RecordSystem { Recorder.flush(); } + public static synchronized void item(Player p, ItemStack item, String slot){ + Recorder.rByte(p.getEntityId()); + Recorder.rString(item.getType().getKey().toString()); + Recorder.rBoolean(!item.getEnchantments().isEmpty()); + Recorder.rString(slot); + Recorder.flush(); + } + public static synchronized void blockChange(BlockPosition pos, int blockState){ Recorder.rByte(0x30); Recorder.rInt(pos.getX()); @@ -147,23 +158,48 @@ public class RecordSystem { } public static synchronized void chat(String s) { - Recorder.rByte(0xa0); + Recorder.rByte(0xA0); Recorder.rString(s); Recorder.flush(); } public static synchronized void actionBar(String s) { - Recorder.rByte(0xa1); + Recorder.rByte(0xA1); Recorder.rString(s); Recorder.flush(); } public static synchronized void systemChat(String s) { - Recorder.rByte(0xa2); + Recorder.rByte(0xA2); Recorder.rString(s); Recorder.flush(); } + public static synchronized void blueSchem(int schemId) { + Recorder.rByte(0xB0); + Recorder.rInt(schemId); + Recorder.flush(); + } + + public static synchronized void redSchem(int schemId) { + Recorder.rByte(0xB1); + Recorder.rInt(schemId); + Recorder.flush(); + } + + public static synchronized void scoreboardTitle(String title){ + Recorder.rByte(0xC0); + Recorder.rString(title); + Recorder.flush(); + } + + public static synchronized void scoreboardData(String key, int value){ + Recorder.rByte(0xC1); + Recorder.rString(key); + Recorder.rInt(value); + Recorder.flush(); + } + public static synchronized void tick(){ Recorder.rByte(0xff); Recorder.flush(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java index 4e1b7a0..a51dc53 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java @@ -4,6 +4,7 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.record.RecordSystem; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.winconditions.*; import org.bukkit.Bukkit; @@ -55,42 +56,52 @@ public class FightScoreboard { private static void teamScoreboard(FightTeam fightTeam){ objective.setDisplayName(fightTeam.getColoredName()); + if(Config.recording()) + RecordSystem.scoreboardTitle(fightTeam.getColoredName()); fightTeam.getPlayers().forEach(fp -> { if(fp.isLiving()) - objective.getScore(fightTeam.getPrefix() + fp.getPlayer().getName()).setScore((int) fp.getPlayer().getHealth()); + setScore(fightTeam.getPrefix() + fp.getPlayer().getName(), (int) fp.getPlayer().getHealth()); }); } private static void generalScoreboard(){ - objective.setDisplayName("§6Kampf"); + objective.setDisplayName("§eKampf"); + if(Config.recording()) + RecordSystem.scoreboardTitle("§eKampf"); if (Config.Timeout || Config.Points || Config.HeartRatioTimeout) { int fightTime = FightSystem.getFightTime(); if (fightTime >= 60) - objective.getScore("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s").setScore(3); + setScore("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s", 3); else - objective.getScore("§7Zeit: §a" + fightTime + "s").setScore(3); + setScore("§7Zeit: §a" + fightTime + "s", 3); } if(fullScoreboard.contains(FightSystem.getFightState())){ if (Config.PercentSystem){ - objective.getScore(Fight.getRedTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getRedPercent()) / 100.0) + "%").setScore(1); - objective.getScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getBluePercent()) / 100.0) + "%").setScore(0); + setScore(Fight.getRedTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getRedPercent()) / 100.0) + "%", 1); + setScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getBluePercent()) / 100.0) + "%", 0); }else if(Config.WaterTechKO){ - objective.getScore(Fight.getRedTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamRedWater()).setScore(1); - objective.getScore(Fight.getBlueTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamBlueWater()).setScore(0); + setScore(Fight.getRedTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamRedWater(),1); + setScore(Fight.getBlueTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamBlueWater(), 0); }else if(Config.RelativePercent){ - objective.getScore(Fight.getRedTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getRed().getPrintablePercent() + "%").setScore(1); - objective.getScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getBlue().getPrintablePercent() + "%").setScore(0); + setScore(Fight.getRedTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getRed().getPrintablePercent() + "%", 1); + setScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getBlue().getPrintablePercent() + "%", 0); }else if(Config.Points){ - objective.getScore(Fight.getRedTeam().getPrefix() + "Punkte: " + WinconditionPoints.getRed().getPoints()).setScore(1); - objective.getScore(Fight.getBlueTeam().getPrefix() + "Punkte: " + WinconditionPoints.getBlue().getPoints()).setScore(0); + setScore(Fight.getRedTeam().getPrefix() + "Punkte: " + WinconditionPoints.getRed().getPoints(), 1); + setScore(Fight.getBlueTeam().getPrefix() + "Punkte: " + WinconditionPoints.getBlue().getPoints(), 0); }else if(Config.PumpkinTechKO){ - objective.getScore(Fight.getRedTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamRedPumpkins()).setScore(1); - objective.getScore(Fight.getBlueTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamBluePumpkins()).setScore(0); + setScore(Fight.getRedTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamRedPumpkins(), 1); + setScore(Fight.getBlueTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamBluePumpkins(), 0); } } } + private static void setScore(String key, int value){ + objective.getScore(key).setScore(value); + if(Config.recording()) + RecordSystem.scoreboardData(key, value); + } + private static FightTeam getIndexDisplay() { index++; if(index == 1) -- 2.39.2 From 80416f3cdb20e1111e3c8f5df6d958490b3c514c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 5 Sep 2020 21:43:14 +0200 Subject: [PATCH 11/30] Additional work Signed-off-by: Lixfel --- .../listener/EventRecordListener.java | 9 ++++ .../fightsystem/record/RecordSystem.java | 51 +++++++++++++++---- 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java index 742e18b..1b4b304 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java @@ -16,6 +16,7 @@ import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.player.*; @@ -121,6 +122,14 @@ public class EventRecordListener extends BasicListener { RecordSystem.item(player, disarmNull(e.getOffHandItem()), "OFFHAND"); } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onProjectileSpawn(ProjectileLaunchEvent e){ + if(e.getEntityType() == EntityType.FIREBALL) + RecordSystem.fireballSpawn(e.getEntity()); + else if(e.getEntityType() == EntityType.ARROW) + RecordSystem.arrowSpawn(e.getEntity()); + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onInventoryClick(InventoryClickEvent e){ Player player = (Player) e.getWhoClicked(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java index ad210d9..ec29b5b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -39,6 +39,8 @@ public class RecordSystem { * TNTSpawnPacket (0x05) + int EntityId * EntitySpeedPacket (0x06) + int EntityId + double dx, dy, dz * PlayerItemPacket (0x07) + int EntityId + String item + boolean enchanted + String slot + * ArrowSpawnPacket (0x08) + int EntityId + * FireballSpawnPacket (0x09) + int EntityId * TODO Bow spanning * * @@ -46,6 +48,7 @@ public class RecordSystem { * BlockPacket (0x30) + pos int, byte, int + int BlockState * ParticlePacket (0x31) + double x, y, z + string particleType * SoundPacket (0x32) + int x, y, z + string soundType + string soundType + float volume, pitch + * ShortBlockPacket (0x33) + pos relative to ArenaMinX,ArenaMinZ byte, byte, byte + short BlockState * * * ChatPacket (0xA0) + String message @@ -104,9 +107,7 @@ public class RecordSystem { public static synchronized void tntSpawn(Entity e){ Recorder.rByte(0x05); - Recorder.rInt(e.getEntityId()); - entityMoves(e); - entitySpeed(e); + spawnEntity(e); } public static synchronized void entitySpeed(Entity e){ @@ -120,20 +121,44 @@ public class RecordSystem { } public static synchronized void item(Player p, ItemStack item, String slot){ - Recorder.rByte(p.getEntityId()); + Recorder.rByte(0x07); + Recorder.rInt(p.getEntityId()); Recorder.rString(item.getType().getKey().toString()); Recorder.rBoolean(!item.getEnchantments().isEmpty()); Recorder.rString(slot); Recorder.flush(); } + public static synchronized void arrowSpawn(Entity e){ + Recorder.rByte(0x08); + spawnEntity(e); + } + + public static synchronized void fireballSpawn(Entity e){ + Recorder.rByte(0x09); + spawnEntity(e); + } + public static synchronized void blockChange(BlockPosition pos, int blockState){ - Recorder.rByte(0x30); - Recorder.rInt(pos.getX()); - Recorder.rByte(pos.getY()); - Recorder.rInt(pos.getZ()); - Recorder.rInt(blockState); - Recorder.flush(); + int shortX = pos.getX() - Config.ArenaMinX; + int shortZ = pos.getZ() - Config.ArenaMinZ; + if((short)blockState == blockState && shortX > 0 && shortX < 256 && shortZ > 0 && shortZ < 256){ + //Short block packet + Recorder.rByte(0x33); + Recorder.rByte(pos.getX()); + Recorder.rByte(pos.getY()); + Recorder.rByte(pos.getZ()); + Recorder.rShort((short)blockState); + Recorder.flush(); + }else{ + //Block packet + Recorder.rByte(0x30); + Recorder.rInt(pos.getX()); + Recorder.rByte(pos.getY()); + Recorder.rInt(pos.getZ()); + Recorder.rInt(blockState); + Recorder.flush(); + } } public static synchronized void particle(double x, double y, double z, String particleType){ @@ -216,4 +241,10 @@ public class RecordSystem { entitySpeed(tnt); } } + + private static void spawnEntity(Entity e){ + Recorder.rInt(e.getEntityId()); + entityMoves(e); + entitySpeed(e); + } } -- 2.39.2 From d6a897443993a91cffa4758b7fb8a25484c0a9be Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 5 Sep 2020 21:46:43 +0200 Subject: [PATCH 12/30] Add GZIPOutputStream improvement --- .../src/de/steamwar/fightsystem/record/FileRecorder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java index 182a2bd..978ae8b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java @@ -19,7 +19,7 @@ public class FileRecorder extends Recorder { File file = new File(FightSystem.getPlugin().getDataFolder(), "recording"); try{ file.createNewFile(); - outputStream = new DataOutputStream(new GZIPOutputStream(new FileOutputStream(file))); + outputStream = new DataOutputStream(new GZIPOutputStream(new FileOutputStream(file), 4096)); }catch(IOException e){ throw new SecurityException("Could not open file", e); } -- 2.39.2 From 88f6bed639331a4110e3251644f5186a40660725 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 5 Sep 2020 22:22:20 +0200 Subject: [PATCH 13/30] Open source release merge Signed-off-by: Lixfel --- .../listener/EventRecordListener.java | 19 +++++++++++++++++++ .../fightsystem/record/FileRecorder.java | 19 +++++++++++++++++++ .../fightsystem/record/RecordSystem.java | 19 +++++++++++++++++++ .../steamwar/fightsystem/record/Recorder.java | 19 +++++++++++++++++++ .../record/SpectateConnection.java | 19 +++++++++++++++++++ 5 files changed, 95 insertions(+) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java index 1b4b304..1f5a84b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java @@ -1,3 +1,22 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.Config; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java index 978ae8b..1cea31f 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java @@ -1,3 +1,22 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.fightsystem.record; import de.steamwar.fightsystem.FightSystem; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java index ec29b5b..b68042e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -1,3 +1,22 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.fightsystem.record; import de.steamwar.fightsystem.Config; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java index 5072b9d..3646a5c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java @@ -1,3 +1,22 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.fightsystem.record; import java.util.ArrayList; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java index df1d7ea..298758e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java @@ -1,3 +1,22 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.fightsystem.record; import de.steamwar.fightsystem.Config; -- 2.39.2 From c68d967a826724554c6771ea310e0cb17a9f089c Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 5 Sep 2020 22:53:09 +0200 Subject: [PATCH 14/30] Add onLeaveEvent --- .../fightsystem/listener/EventRecordListener.java | 8 ++++++++ .../src/de/steamwar/fightsystem/record/RecordSystem.java | 3 +-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java index 1f5a84b..9e25bce 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java @@ -60,6 +60,14 @@ public class EventRecordListener extends BasicListener { RecordSystem.playerJoins(e.getPlayer()); } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onPlayerLeave(PlayerQuitEvent e) { + if(isNotSent(e.getPlayer())) + return; + + RecordSystem.entityDespawns(e.getPlayer()); + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPlayerMove(PlayerMoveEvent e){ if(isNotSent(e.getPlayer())) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java index b68042e..f6cfefe 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -168,7 +168,6 @@ public class RecordSystem { Recorder.rByte(pos.getY()); Recorder.rByte(pos.getZ()); Recorder.rShort((short)blockState); - Recorder.flush(); }else{ //Block packet Recorder.rByte(0x30); @@ -176,8 +175,8 @@ public class RecordSystem { Recorder.rByte(pos.getY()); Recorder.rInt(pos.getZ()); Recorder.rInt(blockState); - Recorder.flush(); } + Recorder.flush(); } public static synchronized void particle(double x, double y, double z, String particleType){ -- 2.39.2 From 90737ca915ea9efa3bdd566185c3f0265c3a6026 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 6 Sep 2020 11:39:16 +0200 Subject: [PATCH 15/30] Implementing sound at player Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/Fight.java | 8 ++++---- .../fightsystem/record/RecordSystem.java | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java index 4f4d4ca..76e98af 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java @@ -20,11 +20,9 @@ package de.steamwar.fightsystem.fight; import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.record.RecordSystem; import de.steamwar.sql.Schematic; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Material; -import org.bukkit.Sound; +import org.bukkit.*; import org.bukkit.entity.Player; import java.util.List; @@ -84,6 +82,8 @@ public class Fight { } public static void playSound(Sound sound, float volume, float pitch) { + if(Config.recording()) + RecordSystem.soundAtPlayer(sound.name(), SoundCategory.AMBIENT.name(), volume, pitch); //volume: max. 100, pitch: max. 2 Bukkit.getServer().getOnlinePlayers().forEach(player -> player.playSound(player.getLocation(), sound, volume, pitch)); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java index f6cfefe..1bb8af2 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -66,8 +66,9 @@ public class RecordSystem { * * BlockPacket (0x30) + pos int, byte, int + int BlockState * ParticlePacket (0x31) + double x, y, z + string particleType - * SoundPacket (0x32) + int x, y, z + string soundType + string soundType + float volume, pitch + * SoundPacket (0x32) + int x, y, z + string soundType + string soundCategory + float volume, pitch * ShortBlockPacket (0x33) + pos relative to ArenaMinX,ArenaMinZ byte, byte, byte + short BlockState + * SoundAtPlayerPacket (0x34) + string soundType, soundCategory + float volume, pitch * * * ChatPacket (0xA0) + String message @@ -164,9 +165,9 @@ public class RecordSystem { if((short)blockState == blockState && shortX > 0 && shortX < 256 && shortZ > 0 && shortZ < 256){ //Short block packet Recorder.rByte(0x33); - Recorder.rByte(pos.getX()); + Recorder.rByte(shortX); Recorder.rByte(pos.getY()); - Recorder.rByte(pos.getZ()); + Recorder.rByte(shortZ); Recorder.rShort((short)blockState); }else{ //Block packet @@ -200,6 +201,15 @@ public class RecordSystem { Recorder.flush(); } + public static synchronized void soundAtPlayer(String soundType, String soundCategory, float volume, float pitch){ + Recorder.rByte(0x34); + Recorder.rString(soundType); + Recorder.rString(soundCategory); + Recorder.rFloat(volume); + Recorder.rFloat(pitch); + Recorder.flush(); + } + public static synchronized void chat(String s) { Recorder.rByte(0xA0); Recorder.rString(s); -- 2.39.2 From 859e40453615fe2112b0e60003676df4fb6c9bc6 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 6 Sep 2020 11:43:09 +0200 Subject: [PATCH 16/30] Implementing sound at player Signed-off-by: Lixfel --- FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java | 2 +- .../src/de/steamwar/fightsystem/record/RecordSystem.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java index 76e98af..a802be6 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java @@ -83,7 +83,7 @@ public class Fight { public static void playSound(Sound sound, float volume, float pitch) { if(Config.recording()) - RecordSystem.soundAtPlayer(sound.name(), SoundCategory.AMBIENT.name(), volume, pitch); + RecordSystem.soundAtPlayer(sound.name(), volume, pitch); //volume: max. 100, pitch: max. 2 Bukkit.getServer().getOnlinePlayers().forEach(player -> player.playSound(player.getLocation(), sound, volume, pitch)); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java index 1bb8af2..dac507c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -201,10 +201,9 @@ public class RecordSystem { Recorder.flush(); } - public static synchronized void soundAtPlayer(String soundType, String soundCategory, float volume, float pitch){ + public static synchronized void soundAtPlayer(String soundType, float volume, float pitch){ Recorder.rByte(0x34); Recorder.rString(soundType); - Recorder.rString(soundCategory); Recorder.rFloat(volume); Recorder.rFloat(pitch); Recorder.flush(); -- 2.39.2 From 38b95a144b23d5fc1c6828cbb7674c97e746a0ff Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 6 Sep 2020 21:34:46 +0200 Subject: [PATCH 17/30] Fixing ConcurrentModificationException Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/record/Recorder.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java index 3646a5c..a332331 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/Recorder.java @@ -24,7 +24,7 @@ import java.util.List; public abstract class Recorder { - private static List recorders = new ArrayList<>(); + private static final List recorders = new ArrayList<>(); public static void rBoolean(boolean b){ recorders.forEach((recorder) -> recorder.writeBoolean(b)); @@ -63,7 +63,8 @@ public abstract class Recorder { } public static void closeAll(){ - recorders.forEach(Recorder::close); + while(!recorders.isEmpty()) + recorders.get(0).close(); } protected Recorder(){ -- 2.39.2 From 6aa99d2d4cfbc81d6a46100327311eea81fad0e9 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 7 Sep 2020 18:24:28 +0200 Subject: [PATCH 18/30] Implementing sending teams Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/record/RecordSystem.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java index dac507c..a285331 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -47,6 +47,8 @@ public class RecordSystem { Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), RecordSystem::checkWorldState, 1, 1); new SpectateConnection(); new FileRecorder(); + if(Config.event()) + teamIds(Config.EventTeamBlueID, Config.EventTeamRedID); } /* @@ -76,6 +78,7 @@ public class RecordSystem { * SystemPacket (0xA2) + String message * BlueSchemPacket (0xB0) + int blueSchemId * RedSchemPacket (0xB1) + int redSchemId + * TeamIDPacket (0xB2) + int blueTeamId, redTeamId * ScoreboardTitlePacket (0xC0) + String scoreboardTitle * ScoreboardDataPacket (0xC1) + String key + int value * @@ -239,6 +242,13 @@ public class RecordSystem { Recorder.flush(); } + public static synchronized void teamIds(int blueTeamId, int redTeamId) { + Recorder.rByte(0xB2); + Recorder.rInt(blueTeamId); + Recorder.rInt(redTeamId); + Recorder.flush(); + } + public static synchronized void scoreboardTitle(String title){ Recorder.rByte(0xC0); Recorder.rString(title); -- 2.39.2 From 7028bfbd98b173f3dfa53caa2da4c3f06bff4a8f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 8 Sep 2020 16:25:14 +0200 Subject: [PATCH 19/30] SchemID Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/FightTeam.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index 8671985..85e713e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -258,9 +258,9 @@ public class FightTeam implements IFightTeam{ public void pasteSchematic(){ if(Config.recording()){ if(blue) - RecordSystem.blueSchem(schematic.getSchemID()); + RecordSystem.blueSchem(schematic); else - RecordSystem.redSchem(schematic.getSchemID()); + RecordSystem.redSchem(schematic); } FreezeWorld freezer = new FreezeWorld(); -- 2.39.2 From ac1af7ffebf285e58555a6dba0cda4ebb2ee5987 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 10 Oct 2020 21:45:09 +0200 Subject: [PATCH 20/30] Add CommentPacket --- .../src/de/steamwar/fightsystem/record/RecordSystem.java | 1 + 1 file changed, 1 insertion(+) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java index a285331..0ab4e3e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -82,6 +82,7 @@ public class RecordSystem { * ScoreboardTitlePacket (0xC0) + String scoreboardTitle * ScoreboardDataPacket (0xC1) + String key + int value * + * CommentPacket (0xfe) + String comment * TickPacket (0xff) * */ -- 2.39.2 From 66b6e5a6ddb913680762376a6664c0ab9f2422ef Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 15 Oct 2020 10:52:06 +0200 Subject: [PATCH 21/30] Reduce blocking on spectatesystem-blackout Signed-off-by: Lixfel --- .../steamwar/fightsystem/record/SpectateConnection.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java index 298758e..2ccf537 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java @@ -22,9 +22,7 @@ package de.steamwar.fightsystem.record; import de.steamwar.fightsystem.Config; import org.bukkit.Bukkit; -import java.io.BufferedOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; +import java.io.*; import java.net.Socket; import java.util.logging.Level; @@ -32,11 +30,15 @@ public class SpectateConnection extends Recorder{ private Socket socket; private DataOutputStream outputStream; + private PipedInputStream inputStream; SpectateConnection(){ super(); try { this.socket = new Socket(Config.spectateIP, Config.spectatePort); + socket.setSoTimeout(1); // Wait a maximum of 1ms on a blocking operation (flush) + socket.setSoLinger(true, 1); // Wait a maximum of 1ms on close + socket.setTcpNoDelay(true); // Don't wait always on ack this.outputStream = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream())); } catch (IOException e) { Bukkit.getLogger().log(Level.SEVERE, "Could not init connection", e); -- 2.39.2 From cc8b7bd96eb6652d02207ada0bae77c465e75013 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 15 Oct 2020 18:42:31 +0200 Subject: [PATCH 22/30] Reduce block change packets Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/listener/EventRecordListener.java | 2 ++ .../src/de/steamwar/fightsystem/record/SpectateConnection.java | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java index 9e25bce..c50a3be 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java @@ -117,6 +117,8 @@ public class EventRecordListener extends BasicListener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockPhysics(BlockPhysicsEvent e){ + if(e.getBlock() != e.getSourceBlock()) + return; RecordSystem.blockChange(e.getBlock()); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java index 2ccf537..8db7f20 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java @@ -30,7 +30,6 @@ public class SpectateConnection extends Recorder{ private Socket socket; private DataOutputStream outputStream; - private PipedInputStream inputStream; SpectateConnection(){ super(); -- 2.39.2 From c04029fb92315a6e526820c677b5d700932e1336 Mon Sep 17 00:00:00 2001 From: jojo Date: Thu, 15 Oct 2020 18:55:43 +0200 Subject: [PATCH 23/30] Add clearity into RecordSystem comment --- .../src/de/steamwar/fightsystem/record/RecordSystem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java index 0ab4e3e..15d3f00 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -70,7 +70,7 @@ public class RecordSystem { * ParticlePacket (0x31) + double x, y, z + string particleType * SoundPacket (0x32) + int x, y, z + string soundType + string soundCategory + float volume, pitch * ShortBlockPacket (0x33) + pos relative to ArenaMinX,ArenaMinZ byte, byte, byte + short BlockState - * SoundAtPlayerPacket (0x34) + string soundType, soundCategory + float volume, pitch + * SoundAtPlayerPacket (0x34) + string (soundType, soundCategory) + float volume, pitch * * * ChatPacket (0xA0) + String message -- 2.39.2 From 20f14670dff0a43423e46e16cf9ad93a9f04c757 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 15 Oct 2020 22:10:08 +0200 Subject: [PATCH 24/30] Despawn all tnt at end of fight Signed-off-by: Lixfel --- .../steamwar/fightsystem/listener/EventRecordListener.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java index c50a3be..3249c75 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java @@ -29,6 +29,7 @@ import de.steamwar.fightsystem.states.FightState; import org.bukkit.*; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; +import org.bukkit.entity.TNTPrimed; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockPhysicsEvent; @@ -194,6 +195,7 @@ public class EventRecordListener extends BasicListener { }else if(state == FightState.SPECTATE){ despawnTeam(Fight.getRedTeam()); despawnTeam(Fight.getBlueTeam()); + despawnTNT(); } } @@ -228,6 +230,11 @@ public class EventRecordListener extends BasicListener { } } + private void despawnTNT(){ + for(TNTPrimed tnt : Bukkit.getWorlds().get(0).getEntitiesByClass(TNTPrimed.class)) + RecordSystem.entityDespawns(tnt); + } + private boolean isNotSent(Player p){ FightPlayer fp = Fight.getFightPlayer(p); return fp == null || !fp.isLiving() || FightSystem.getFightState() == FightState.SPECTATE; -- 2.39.2 From 8d33e25bec5025b7251cc590c9a42b9e9e45094a Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 16 Oct 2020 09:11:10 +0200 Subject: [PATCH 25/30] Fix exceptions Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/record/RecordSystem.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java index 15d3f00..a969de8 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -21,6 +21,7 @@ package de.steamwar.fightsystem.record; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.states.FightState; import de.steamwar.sql.SteamwarUser; import net.minecraft.server.v1_15_R1.BlockPosition; import org.bukkit.Bukkit; @@ -274,6 +275,10 @@ public class RecordSystem { private static void checkWorldState(){ tick(); + + if(FightSystem.getFightState() == FightState.SPECTATE) + return; + for(TNTPrimed tnt : WORLD.getEntitiesByClass(TNTPrimed.class)){ entityMoves(tnt); entitySpeed(tnt); -- 2.39.2 From 6db5d46af37d714e335d6dcebd200acdb8e53247 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 21 Oct 2020 18:32:20 +0200 Subject: [PATCH 26/30] Add fileSuffix `.recording` --- .../src/de/steamwar/fightsystem/record/FileRecorder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java index 1cea31f..92d19a9 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java @@ -35,7 +35,7 @@ public class FileRecorder extends Recorder { public FileRecorder(){ super(); - File file = new File(FightSystem.getPlugin().getDataFolder(), "recording"); + File file = new File(FightSystem.getPlugin().getDataFolder(), "recording.recording"); try{ file.createNewFile(); outputStream = new DataOutputStream(new GZIPOutputStream(new FileOutputStream(file), 4096)); -- 2.39.2 From bef28a99b25ac70d1205df815ff37f555e8d6ae1 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 27 Oct 2020 15:33:44 +0100 Subject: [PATCH 27/30] Commit recent changes Signed-off-by: Lixfel --- .../fightsystem/record/RecordSystem_15.java | 31 ++++++++++++++++ .../fightsystem/record/RecordSystem_8.java | 31 ++++++++++++++++ .../fightsystem/record/RecordSystem.java | 36 ++++++++++++------- 3 files changed, 85 insertions(+), 13 deletions(-) create mode 100644 FightSystem_15/src/de/steamwar/fightsystem/record/RecordSystem_15.java create mode 100644 FightSystem_8/src/de/steamwar/fightsystem/record/RecordSystem_8.java diff --git a/FightSystem_15/src/de/steamwar/fightsystem/record/RecordSystem_15.java b/FightSystem_15/src/de/steamwar/fightsystem/record/RecordSystem_15.java new file mode 100644 index 0000000..6d1a1e3 --- /dev/null +++ b/FightSystem_15/src/de/steamwar/fightsystem/record/RecordSystem_15.java @@ -0,0 +1,31 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.fightsystem.record; + +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v1_15_R1.block.CraftBlock; + +class RecordSystem_15 { + private RecordSystem_15(){} + + static int blockToId(Block block){ + return net.minecraft.server.v1_15_R1.Block.REGISTRY_ID.getId(((CraftBlock)block).getNMS()); + } +} diff --git a/FightSystem_8/src/de/steamwar/fightsystem/record/RecordSystem_8.java b/FightSystem_8/src/de/steamwar/fightsystem/record/RecordSystem_8.java new file mode 100644 index 0000000..207a3fd --- /dev/null +++ b/FightSystem_8/src/de/steamwar/fightsystem/record/RecordSystem_8.java @@ -0,0 +1,31 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.fightsystem.record; + +import org.bukkit.block.Block; + +class RecordSystem_8 { + private RecordSystem_8(){} + + @SuppressWarnings("deprecation") + static int blockToId(Block block){ + return block.getTypeId() << 4 + block.getData(); + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java index a969de8..84660b4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -19,16 +19,15 @@ package de.steamwar.fightsystem.record; +import de.steamwar.core.Core; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.states.FightState; import de.steamwar.sql.SteamwarUser; -import net.minecraft.server.v1_15_R1.BlockPosition; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.craftbukkit.v1_15_R1.block.CraftBlock; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -164,22 +163,24 @@ public class RecordSystem { spawnEntity(e); } - public static synchronized void blockChange(BlockPosition pos, int blockState){ - int shortX = pos.getX() - Config.ArenaMinX; - int shortZ = pos.getZ() - Config.ArenaMinZ; + public static synchronized void blockChange(Block block){ + int blockState = blockToId(block); + + int shortX = block.getX() - Config.ArenaMinX; + int shortZ = block.getZ() - Config.ArenaMinZ; if((short)blockState == blockState && shortX > 0 && shortX < 256 && shortZ > 0 && shortZ < 256){ //Short block packet Recorder.rByte(0x33); Recorder.rByte(shortX); - Recorder.rByte(pos.getY()); + Recorder.rByte(block.getY()); Recorder.rByte(shortZ); Recorder.rShort((short)blockState); }else{ //Block packet Recorder.rByte(0x30); - Recorder.rInt(pos.getX()); - Recorder.rByte(pos.getY()); - Recorder.rInt(pos.getZ()); + Recorder.rInt(block.getX()); + Recorder.rByte(block.getY()); + Recorder.rInt(block.getZ()); Recorder.rInt(blockState); } Recorder.flush(); @@ -269,10 +270,6 @@ public class RecordSystem { Recorder.flush(); } - public static synchronized void blockChange(Block block){ - blockChange(((CraftBlock)block).getPosition(), net.minecraft.server.v1_15_R1.Block.REGISTRY_ID.getId(((CraftBlock)block).getNMS())); - } - private static void checkWorldState(){ tick(); @@ -290,4 +287,17 @@ public class RecordSystem { entityMoves(e); entitySpeed(e); } + + private static int blockToId(Block block){ + switch(Core.getVersion()){ + case 8: + case 9: + case 10: + case 12: + return RecordSystem_8.blockToId(block); + case 15: + default: + return RecordSystem_15.blockToId(block); + } + } } -- 2.39.2 From f04a9edb411f336638684db68c43900e615eedef Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 29 Oct 2020 12:24:43 +0100 Subject: [PATCH 28/30] Fix sound strength Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/listener/EventRecordListener.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java index 3249c75..7fa5902 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java @@ -44,10 +44,12 @@ import org.bukkit.event.server.BroadcastMessageEvent; import org.bukkit.inventory.ItemStack; import java.util.EnumSet; +import java.util.Random; public class EventRecordListener extends BasicListener { private static final int AIR = 0; + private static final Random random = new Random(); public EventRecordListener() { super(Config.event() ? EnumSet.allOf(FightState.class) : EnumSet.noneOf(FightState.class)); @@ -131,7 +133,7 @@ public class EventRecordListener extends BasicListener { Location loc = e.getLocation(); RecordSystem.entityDespawns(e.getEntity()); RecordSystem.particle(loc.getX(), loc.getY(), loc.getZ(), Particle.EXPLOSION_LARGE.name()); - RecordSystem.sound(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), Sound.ENTITY_GENERIC_EXPLODE.name(), SoundCategory.BLOCKS.name(), 255.0f, 1.0f); + RecordSystem.sound(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), Sound.ENTITY_GENERIC_EXPLODE.name(), SoundCategory.BLOCKS.name(), 4.0F, (1.0F + (random.nextFloat() - random.nextFloat()) * 0.2F) * 0.7F); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) -- 2.39.2 From 32814697729df2508bd9ade4b9e627e1615a0eed Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 29 Oct 2020 21:40:28 +0100 Subject: [PATCH 29/30] Adjust explosion size Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/listener/EventRecordListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java index 7fa5902..5539cb6 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java @@ -132,7 +132,7 @@ public class EventRecordListener extends BasicListener { Location loc = e.getLocation(); RecordSystem.entityDespawns(e.getEntity()); - RecordSystem.particle(loc.getX(), loc.getY(), loc.getZ(), Particle.EXPLOSION_LARGE.name()); + RecordSystem.particle(loc.getX(), loc.getY(), loc.getZ(), Particle.EXPLOSION_HUGE.name()); RecordSystem.sound(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), Sound.ENTITY_GENERIC_EXPLODE.name(), SoundCategory.BLOCKS.name(), 4.0F, (1.0F + (random.nextFloat() - random.nextFloat()) * 0.2F) * 0.7F); } -- 2.39.2 From 014cee20a8e69970cc11d618d85194ee7ad5a09b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 1 Nov 2020 16:17:00 +0100 Subject: [PATCH 30/30] Temporary only record if recording Signed-off-by: Lixfel --- FightSystem_API/src/de/steamwar/fightsystem/Config.java | 2 +- .../steamwar/fightsystem/listener/EventRecordListener.java | 2 +- .../src/de/steamwar/fightsystem/record/FileRecorder.java | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 524da67..1469700 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -413,6 +413,6 @@ public class Config { return CheckSchemID != 0; } public static boolean recording(){ - return event(); + return event() && SpectateSystem; } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java index 5539cb6..8dcc023 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java @@ -52,7 +52,7 @@ public class EventRecordListener extends BasicListener { private static final Random random = new Random(); public EventRecordListener() { - super(Config.event() ? EnumSet.allOf(FightState.class) : EnumSet.noneOf(FightState.class)); + super(Config.recording() ? EnumSet.allOf(FightState.class) : EnumSet.noneOf(FightState.class)); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java index 92d19a9..3a0c616 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/FileRecorder.java @@ -19,8 +19,8 @@ package de.steamwar.fightsystem.record; -import de.steamwar.fightsystem.FightSystem; import org.bukkit.Bukkit; +import org.bukkit.World; import java.io.DataOutputStream; import java.io.File; @@ -35,7 +35,8 @@ public class FileRecorder extends Recorder { public FileRecorder(){ super(); - File file = new File(FightSystem.getPlugin().getDataFolder(), "recording.recording"); + World world = Bukkit.getWorlds().get(0); + File file = new File(world.getWorldFolder(), world.getName() + ".recording"); try{ file.createNewFile(); outputStream = new DataOutputStream(new GZIPOutputStream(new FileOutputStream(file), 4096)); -- 2.39.2