From c13b024f93effabfb2e45c66858258e1d924e098 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 4 Jul 2020 10:49:49 +0200 Subject: [PATCH 01/55] 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 { +} From 7af46a1f13ca0d1dce1dbc92a7befc0b6490e70a Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 11 Jul 2020 07:17:10 +0200 Subject: [PATCH 02/55] 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 + } } From 10c9cf3ae58cc1b903280fafdbee48a32ca4a209 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 25 Jul 2020 09:55:05 +0200 Subject: [PATCH 03/55] 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 } } From 19d7d719e857c9726b1e0dd1ce98eee141ee92e5 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 15 Aug 2020 23:31:18 +0200 Subject: [PATCH 04/55] 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; + } + } + +} From 0f3943cd73201d6f1bd38a5b6994ffddab069127 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 22 Aug 2020 10:01:57 +0200 Subject: [PATCH 05/55] 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; - } - } - } From ce39b0a27627b07dd12f8018a6699a16f00c767c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 22 Aug 2020 10:45:40 +0200 Subject: [PATCH 06/55] 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); } } } From ab15562e06b9891a6a64a93ce9b1777138fb9418 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 22 Aug 2020 11:05:31 +0200 Subject: [PATCH 07/55] 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); From 626dbe96605268b1f2af7eb562ef07b6b1c0bd84 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 22 Aug 2020 15:08:35 +0200 Subject: [PATCH 08/55] 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 } From 7e6e4f0312eaa688b75b5dcf855013ee2c6ae676 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 22 Aug 2020 19:18:11 +0200 Subject: [PATCH 09/55] 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{ From 6ed7ae0180e1608179c8ef75d823d823ca17bf1f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 1 Sep 2020 19:41:30 +0200 Subject: [PATCH 10/55] 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) From 80416f3cdb20e1111e3c8f5df6d958490b3c514c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 5 Sep 2020 21:43:14 +0200 Subject: [PATCH 11/55] 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); + } } From d6a897443993a91cffa4758b7fb8a25484c0a9be Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 5 Sep 2020 21:46:43 +0200 Subject: [PATCH 12/55] 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); } From 88f6bed639331a4110e3251644f5186a40660725 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 5 Sep 2020 22:22:20 +0200 Subject: [PATCH 13/55] 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; From c68d967a826724554c6771ea310e0cb17a9f089c Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 5 Sep 2020 22:53:09 +0200 Subject: [PATCH 14/55] 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){ From 90737ca915ea9efa3bdd566185c3f0265c3a6026 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 6 Sep 2020 11:39:16 +0200 Subject: [PATCH 15/55] 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); From 859e40453615fe2112b0e60003676df4fb6c9bc6 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 6 Sep 2020 11:43:09 +0200 Subject: [PATCH 16/55] 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(); From 38b95a144b23d5fc1c6828cbb7674c97e746a0ff Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 6 Sep 2020 21:34:46 +0200 Subject: [PATCH 17/55] 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(){ From 6aa99d2d4cfbc81d6a46100327311eea81fad0e9 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 7 Sep 2020 18:24:28 +0200 Subject: [PATCH 18/55] 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); From 7028bfbd98b173f3dfa53caa2da4c3f06bff4a8f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 8 Sep 2020 16:25:14 +0200 Subject: [PATCH 19/55] 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(); From de0d7d734006d26335fc128fb03eed6b384e047b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 9 Sep 2020 20:47:50 +0200 Subject: [PATCH 20/55] Gamemode 1 packet Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/Fight.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java index 4f4d4ca..ecdf408 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java @@ -19,6 +19,9 @@ package de.steamwar.fightsystem.fight; +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.events.PacketContainer; import de.steamwar.fightsystem.Config; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; @@ -27,7 +30,9 @@ import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.Player; +import java.lang.reflect.InvocationTargetException; import java.util.List; +import java.util.logging.Level; public class Fight { private Fight(){} @@ -36,8 +41,12 @@ public class Fight { public static final FightTeam blueTeam = new FightTeam(Config.TeamBlueName, Config.TeamBluePrefix, Config.TeamBlueSpawn, Config.TeamBlueCornerX, Config.TeamBlueCornerY, Config.TeamBlueCornerZ, Config.TeamBlueRotate, true, Config.BlueLeader); private static int schemRank; + private static final PacketContainer gm_1_packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.GAME_STATE_CHANGE); + public static void init(){ IFight.init(redTeam, blueTeam); + gm_1_packet.getBytes().write(0, (byte)3); + gm_1_packet.getFloat().write(0, 1f); } public static FightTeam getPlayerTeam(Player player) { @@ -112,6 +121,11 @@ public class Fight { player.setGameMode(gameMode); if(gameMode == GameMode.SPECTATOR) { + try { + ProtocolLibrary.getProtocolManager().sendServerPacket(player, gm_1_packet); + } catch (InvocationTargetException e) { + Bukkit.getLogger().log(Level.SEVERE, "Invocation target exception", e); + } for(Player currentPlayer : Bukkit.getServer().getOnlinePlayers()) { if(currentPlayer.getUniqueId() != player.getUniqueId() && currentPlayer.getGameMode() == GameMode.SPECTATOR) { currentPlayer.hidePlayer(player); From 2b3f08aae242da3d62dd95cd36d53d77ae42b9a8 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 25 Sep 2020 16:35:16 +0200 Subject: [PATCH 21/55] Set spectators in halfcreative mode Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/fight/Fight.java | 45 ++++++++++++++----- .../listener/PlayerMoveListener.java | 19 ++++++++ 2 files changed, 54 insertions(+), 10 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java index ecdf408..a570be5 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java @@ -22,7 +22,13 @@ package de.steamwar.fightsystem.fight; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.reflect.StructureModifier; +import com.comphenix.protocol.wrappers.EnumWrappers; +import com.comphenix.protocol.wrappers.PlayerInfoData; +import com.comphenix.protocol.wrappers.WrappedChatComponent; +import com.comphenix.protocol.wrappers.WrappedGameProfile; import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -31,6 +37,7 @@ import org.bukkit.Sound; import org.bukkit.entity.Player; import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; import java.util.List; import java.util.logging.Level; @@ -41,12 +48,20 @@ public class Fight { public static final FightTeam blueTeam = new FightTeam(Config.TeamBlueName, Config.TeamBluePrefix, Config.TeamBlueSpawn, Config.TeamBlueCornerX, Config.TeamBlueCornerY, Config.TeamBlueCornerZ, Config.TeamBlueRotate, true, Config.BlueLeader); private static int schemRank; - private static final PacketContainer gm_1_packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.GAME_STATE_CHANGE); + private static final PacketContainer flying_packet = new PacketContainer(PacketType.Play.Server.ABILITIES); + + static { + flying_packet.getBytes().write(0, (byte)0x06); + StructureModifier booleans = flying_packet.getBooleans(); + booleans.write(0, false); + booleans.write(1, true); + booleans.write(2, true); + booleans.write(3, false); + flying_packet.getFloat().writeDefaults(); + } public static void init(){ IFight.init(redTeam, blueTeam); - gm_1_packet.getBytes().write(0, (byte)3); - gm_1_packet.getFloat().write(0, 1f); } public static FightTeam getPlayerTeam(Player player) { @@ -121,20 +136,30 @@ public class Fight { player.setGameMode(gameMode); if(gameMode == GameMode.SPECTATOR) { - try { - ProtocolLibrary.getProtocolManager().sendServerPacket(player, gm_1_packet); - } catch (InvocationTargetException e) { - Bukkit.getLogger().log(Level.SEVERE, "Invocation target exception", e); - } for(Player currentPlayer : Bukkit.getServer().getOnlinePlayers()) { if(currentPlayer.getUniqueId() != player.getUniqueId() && currentPlayer.getGameMode() == GameMode.SPECTATOR) { currentPlayer.hidePlayer(player); player.hidePlayer(currentPlayer); } } - } - if(gameMode == GameMode.SURVIVAL) { + if(FightSystem.getEventLeiter() == player) + return; + + Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { + PacketContainer gm_1_packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO); + gm_1_packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE); + List playerInfoActions = new ArrayList<>(); + playerInfoActions.add(new PlayerInfoData(WrappedGameProfile.fromPlayer(player), 1, EnumWrappers.NativeGameMode.CREATIVE, WrappedChatComponent.fromText(player.getDisplayName()))); + gm_1_packet.getPlayerInfoDataLists().write(0, playerInfoActions); + try { + ProtocolLibrary.getProtocolManager().sendServerPacket(player, gm_1_packet); + ProtocolLibrary.getProtocolManager().sendServerPacket(player, flying_packet); + } catch (InvocationTargetException e) { + Bukkit.getLogger().log(Level.SEVERE, "Invocation target exception", e); + } + }, 2); + }else if(gameMode == GameMode.SURVIVAL) { for(Player currentPlayer : Bukkit.getServer().getOnlinePlayers()) { if(currentPlayer.getUniqueId() != player.getUniqueId() && currentPlayer.getGameMode() == GameMode.SPECTATOR) { currentPlayer.showPlayer(player); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerMoveListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerMoveListener.java index d6b678e..54be27d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerMoveListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerMoveListener.java @@ -26,6 +26,8 @@ import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.utils.Region; import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.BanList; +import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -33,6 +35,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerMoveEvent; import java.util.EnumSet; +import java.util.logging.Level; public class PlayerMoveListener extends BasicListener { @@ -64,15 +67,31 @@ public class PlayerMoveListener extends BasicListener { reset(event, DENY_TEAM); else if(fightTeam == Fight.getRedTeam() && player.getGameMode() == GameMode.SPECTATOR) reset(event, DENY_ENTERN); + else + return; // Is allowed in area + checkInInnerArea(event.getPlayer(), to, Config.TeamBlueCornerX, Config.TeamBlueCornerZ); }else if(inRedArea){ if(fightTeam == null) reset(event, DENY_TEAM); else if(fightTeam == Fight.getBlueTeam() && player.getGameMode() == GameMode.SPECTATOR) reset(event, DENY_ENTERN); + else + return; // Is allowed in area + checkInInnerArea(event.getPlayer(), to, Config.TeamRedCornerX, Config.TeamRedCornerZ); }else if(fightTeam != null && player.getGameMode() != GameMode.SPECTATOR && !fightTeam.canPlayerEntern(player)) reset(event, DENY_ENTERN); } + private void checkInInnerArea(Player player, Location to, int teamCornerX, int teamCornerZ){ + boolean inArenaY = to.getY() + 1.8 <= Config.TeamBlueCornerY + Config.SchemsizeY; + boolean inArea = inArenaY && Region.isIn2DRange(to, teamCornerX, teamCornerZ, Config.SchemsizeX, Config.SchemsizeZ, 0); + if(inArea){ + player.kickPlayer(null); + Bukkit.getBanList(BanList.Type.NAME).addBan(player.getUniqueId().toString(), "§cVersuchtes Eindringen in einen Teambereich", null, null); + Bukkit.getLogger().log(Level.SEVERE, player.getName() + " ist in einen Teambereich eingedrungen."); + } + } + @EventHandler public void arenaBorder(PlayerMoveEvent event){ Player player = event.getPlayer(); From ac1af7ffebf285e58555a6dba0cda4ebb2ee5987 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 10 Oct 2020 21:45:09 +0200 Subject: [PATCH 22/55] 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) * */ From 66b6e5a6ddb913680762376a6664c0ab9f2422ef Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 15 Oct 2020 10:52:06 +0200 Subject: [PATCH 23/55] 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); From cc8b7bd96eb6652d02207ada0bae77c465e75013 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 15 Oct 2020 18:42:31 +0200 Subject: [PATCH 24/55] 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(); From c04029fb92315a6e526820c677b5d700932e1336 Mon Sep 17 00:00:00 2001 From: jojo Date: Thu, 15 Oct 2020 18:55:43 +0200 Subject: [PATCH 25/55] 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 From 20f14670dff0a43423e46e16cf9ad93a9f04c757 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 15 Oct 2020 22:10:08 +0200 Subject: [PATCH 26/55] 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; From 8d33e25bec5025b7251cc590c9a42b9e9e45094a Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 16 Oct 2020 09:11:10 +0200 Subject: [PATCH 27/55] 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); From 6db5d46af37d714e335d6dcebd200acdb8e53247 Mon Sep 17 00:00:00 2001 From: jojo Date: Wed, 21 Oct 2020 18:32:20 +0200 Subject: [PATCH 28/55] 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)); From bef28a99b25ac70d1205df815ff37f555e8d6ae1 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 27 Oct 2020 15:33:44 +0100 Subject: [PATCH 29/55] 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); + } + } } From 70b90b467b13459050c9a9c621947c583e046d2d Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 27 Oct 2020 15:50:24 +0100 Subject: [PATCH 30/55] This should fix the waterlogged waterremover problem Signed-off-by: Lixfel --- .../fightsystem/utils/WaterRemover_14.java | 20 +++++++++++++++++ .../fightsystem/utils/WaterRemover_8.java | 8 +++++++ .../fightsystem/utils/WaterRemover.java | 22 ++++++++++++++++--- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/WaterRemover_14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/WaterRemover_14.java index 265d2e3..17260c3 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/WaterRemover_14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/WaterRemover_14.java @@ -37,4 +37,24 @@ class WaterRemover_14 { return ((Waterlogged) data).isWaterlogged(); } + + static boolean removeWater(Block block){ + if(block.getType() == Material.WATER){ + block.setType(Material.AIR); + return true; + } + + BlockData data = block.getBlockData(); + if(!(data instanceof Waterlogged)) + return false; + + Waterlogged waterlogged = (Waterlogged) data; + if(waterlogged.isWaterlogged()){ + waterlogged.setWaterlogged(false); + block.setBlockData(waterlogged); + return true; + } + + return false; + } } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/WaterRemover_8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/WaterRemover_8.java index 0a544df..a510557 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/WaterRemover_8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/WaterRemover_8.java @@ -29,4 +29,12 @@ public class WaterRemover_8 { Material type = block.getType(); return type == Material.WATER || type == Material.STATIONARY_WATER; } + + static boolean removeWater(Block block){ + if(isWater(block)){ + block.setType(Material.AIR); + return true; + } + return false; + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java index 8506394..fcff47a 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java @@ -49,14 +49,15 @@ public class WaterRemover { } private static void checkBlock(Block b, int startX, int startY, int startZ) throws IsAnOcean { - if(!isWater(b)) + if(!removeWater(b)) return; // If distance to original block is greater than 20 - if(Math.abs(startX - b.getX()) + Math.abs(startY - b.getY() + Math.abs(startZ - b.getZ())) >= 20) + if(Math.abs(startX - b.getX()) + Math.abs(startY - b.getY() + Math.abs(startZ - b.getZ())) >= 20){ + b.setType(Material.WATER); throw new IsAnOcean(); + } - b.setType(Material.AIR); try{ checkBlock(b.getRelative(BlockFace.EAST), startX, startY, startZ); checkBlock(b.getRelative(BlockFace.WEST), startX, startY, startZ); @@ -84,4 +85,19 @@ public class WaterRemover { return WaterRemover_14.isWater(block); } } + + public static boolean removeWater(Block block){ + //checks for water and removes it, if present + switch(Core.getVersion()){ + case 8: + case 9: + case 10: + case 12: + return WaterRemover_8.removeWater(block); + case 14: + case 15: + default: + return WaterRemover_14.removeWater(block); + } + } } From 84fa4e8dd0481815e45e80004125098b29d0bb36 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 28 Oct 2020 10:21:13 +0100 Subject: [PATCH 31/55] Might fix #192 Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/FightTeam.java | 4 ++++ .../de/steamwar/fightsystem/listener/PersonalKitCreator.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index 6bd4a93..2dc3fdd 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -25,6 +25,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.listener.PersonalKitCreator; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.utils.*; import de.steamwar.fightsystem.winconditions.RankedPlayerLeftWincondition; @@ -222,6 +223,9 @@ public class FightTeam implements IFightTeam{ } return; } + if (!PersonalKitCreator.notInKitCreator(leader.getPlayer())) + leader.getPlayer().closeInventory(); + this.leader = leader; if(ready) setReady(false); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java index c593dae..104fa81 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java @@ -78,7 +78,7 @@ public class PersonalKitCreator extends BasicListener { player.setGameMode(GameMode.CREATIVE); } - static boolean notInKitCreator(HumanEntity player){ + public static boolean notInKitCreator(HumanEntity player){ return !openKitCreators.containsKey(player); } From 192602625be20d964dea93dc3044f64173cac8c8 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 28 Oct 2020 11:16:25 +0100 Subject: [PATCH 32/55] Blocked spectator mode Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/fight/Fight.java | 30 +++++-------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java index a570be5..4d944c1 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java @@ -22,7 +22,6 @@ package de.steamwar.fightsystem.fight; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketContainer; -import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.wrappers.EnumWrappers; import com.comphenix.protocol.wrappers.PlayerInfoData; import com.comphenix.protocol.wrappers.WrappedChatComponent; @@ -48,18 +47,6 @@ public class Fight { public static final FightTeam blueTeam = new FightTeam(Config.TeamBlueName, Config.TeamBluePrefix, Config.TeamBlueSpawn, Config.TeamBlueCornerX, Config.TeamBlueCornerY, Config.TeamBlueCornerZ, Config.TeamBlueRotate, true, Config.BlueLeader); private static int schemRank; - private static final PacketContainer flying_packet = new PacketContainer(PacketType.Play.Server.ABILITIES); - - static { - flying_packet.getBytes().write(0, (byte)0x06); - StructureModifier booleans = flying_packet.getBooleans(); - booleans.write(0, false); - booleans.write(1, true); - booleans.write(2, true); - booleans.write(3, false); - flying_packet.getFloat().writeDefaults(); - } - public static void init(){ IFight.init(redTeam, blueTeam); } @@ -138,8 +125,8 @@ public class Fight { if(gameMode == GameMode.SPECTATOR) { for(Player currentPlayer : Bukkit.getServer().getOnlinePlayers()) { if(currentPlayer.getUniqueId() != player.getUniqueId() && currentPlayer.getGameMode() == GameMode.SPECTATOR) { - currentPlayer.hidePlayer(player); - player.hidePlayer(currentPlayer); + currentPlayer.hidePlayer(FightSystem.getPlugin(), player); + player.hidePlayer(FightSystem.getPlugin(), currentPlayer); } } @@ -147,14 +134,13 @@ public class Fight { return; Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { - PacketContainer gm_1_packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO); - gm_1_packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE); + PacketContainer gm1packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO); + gm1packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE); List playerInfoActions = new ArrayList<>(); playerInfoActions.add(new PlayerInfoData(WrappedGameProfile.fromPlayer(player), 1, EnumWrappers.NativeGameMode.CREATIVE, WrappedChatComponent.fromText(player.getDisplayName()))); - gm_1_packet.getPlayerInfoDataLists().write(0, playerInfoActions); + gm1packet.getPlayerInfoDataLists().write(0, playerInfoActions); try { - ProtocolLibrary.getProtocolManager().sendServerPacket(player, gm_1_packet); - ProtocolLibrary.getProtocolManager().sendServerPacket(player, flying_packet); + ProtocolLibrary.getProtocolManager().sendServerPacket(player, gm1packet); } catch (InvocationTargetException e) { Bukkit.getLogger().log(Level.SEVERE, "Invocation target exception", e); } @@ -162,8 +148,8 @@ public class Fight { }else if(gameMode == GameMode.SURVIVAL) { for(Player currentPlayer : Bukkit.getServer().getOnlinePlayers()) { if(currentPlayer.getUniqueId() != player.getUniqueId() && currentPlayer.getGameMode() == GameMode.SPECTATOR) { - currentPlayer.showPlayer(player); - player.showPlayer(currentPlayer); + currentPlayer.showPlayer(FightSystem.getPlugin(), player); + player.showPlayer(FightSystem.getPlugin(), currentPlayer); } } } From 9b4744ae05bc230b0860c3af56acc2bb533f62ed Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 28 Oct 2020 11:18:06 +0100 Subject: [PATCH 33/55] Don't autoban Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/listener/PlayerMoveListener.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerMoveListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerMoveListener.java index 54be27d..bec0121 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerMoveListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerMoveListener.java @@ -26,7 +26,6 @@ import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.utils.Region; import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.BanList; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; @@ -87,7 +86,6 @@ public class PlayerMoveListener extends BasicListener { boolean inArea = inArenaY && Region.isIn2DRange(to, teamCornerX, teamCornerZ, Config.SchemsizeX, Config.SchemsizeZ, 0); if(inArea){ player.kickPlayer(null); - Bukkit.getBanList(BanList.Type.NAME).addBan(player.getUniqueId().toString(), "§cVersuchtes Eindringen in einen Teambereich", null, null); Bukkit.getLogger().log(Level.SEVERE, player.getName() + " ist in einen Teambereich eingedrungen."); } } From 259ca31f2b5b4d8a54562f059186253b0830b958 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 29 Oct 2020 12:19:23 +0100 Subject: [PATCH 34/55] Tablist name impl. as comments. Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/FightTeam.java | 2 ++ .../de/steamwar/fightsystem/listener/PlayerStateListener.java | 1 + 2 files changed, 3 insertions(+) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index 2dc3fdd..df53eb7 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -178,6 +178,7 @@ public class FightTeam implements IFightTeam{ if(KitManager.getKits(false).size() > 1 || Config.PersonalKits) player.getInventory().setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§eKit wählen").build()); player.getInventory().setItem(7, new ItemBuilder(Material.BEACON).removeAllAttributs().setDisplayName("§eRespawn").build()); + //new TablistNamePacket(SteamwarUser.get(player).getId(), prefix + player.name()).send(player); TechHider.reloadChunks(player, chunksToReload); return fightPlayer; } @@ -195,6 +196,7 @@ public class FightTeam implements IFightTeam{ Fight.setPlayerGamemode(player, GameMode.SPECTATOR); player.teleport(Config.SpecSpawn); + //new TablistNamePacket(SteamwarUser.get(player).getId(), "§7§o" + player.name()).send(player); TechHider.reloadChunks(player, chunksToReload); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java index 8f179e6..e75d51c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java @@ -61,6 +61,7 @@ public class PlayerStateListener extends BasicListener{ if (fightTeam == null) { Fight.setPlayerGamemode(player, GameMode.SPECTATOR); player.teleport(Config.SpecSpawn); + //new TablistNamePacket(SteamwarUser.get(player).getId(), "§7§o" + player.name()).send(player); } else { player.teleport(fightTeam.getSpawn()); if(FightSystem.getFightState().setup()) From f04a9edb411f336638684db68c43900e615eedef Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 29 Oct 2020 12:24:43 +0100 Subject: [PATCH 35/55] 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) From 886e624bacbf04de916991788b576961a1b7aeec Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 29 Oct 2020 20:51:45 +0100 Subject: [PATCH 36/55] Impl. tablist name capability Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/FightTeam.java | 10 +++++++--- .../fightsystem/listener/PlayerStateListener.java | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index df53eb7..aa7e00b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -20,6 +20,7 @@ package de.steamwar.fightsystem.fight; import com.sk89q.worldedit.EditSession; +import de.steamwar.comms.packets.TablistNamePacket; import de.steamwar.core.Core; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; @@ -27,7 +28,10 @@ import de.steamwar.fightsystem.IFightSystem; import de.steamwar.fightsystem.kit.KitManager; import de.steamwar.fightsystem.listener.PersonalKitCreator; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.utils.*; +import de.steamwar.fightsystem.utils.ColorConverter; +import de.steamwar.fightsystem.utils.FightScoreboard; +import de.steamwar.fightsystem.utils.ItemBuilder; +import de.steamwar.fightsystem.utils.TechHider; import de.steamwar.fightsystem.winconditions.RankedPlayerLeftWincondition; import de.steamwar.inventory.SWItem; import de.steamwar.sql.NoClipboardException; @@ -178,7 +182,7 @@ public class FightTeam implements IFightTeam{ if(KitManager.getKits(false).size() > 1 || Config.PersonalKits) player.getInventory().setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§eKit wählen").build()); player.getInventory().setItem(7, new ItemBuilder(Material.BEACON).removeAllAttributs().setDisplayName("§eRespawn").build()); - //new TablistNamePacket(SteamwarUser.get(player).getId(), prefix + player.name()).send(player); + new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), prefix + player.getName()).send(player); TechHider.reloadChunks(player, chunksToReload); return fightPlayer; } @@ -196,7 +200,7 @@ public class FightTeam implements IFightTeam{ Fight.setPlayerGamemode(player, GameMode.SPECTATOR); player.teleport(Config.SpecSpawn); - //new TablistNamePacket(SteamwarUser.get(player).getId(), "§7§o" + player.name()).send(player); + new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7§o" + player.getName()).send(player); TechHider.reloadChunks(player, chunksToReload); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java index e75d51c..721f523 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java @@ -19,6 +19,7 @@ package de.steamwar.fightsystem.listener; +import de.steamwar.comms.packets.TablistNamePacket; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.countdown.Countdown; @@ -27,6 +28,7 @@ import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -61,7 +63,7 @@ public class PlayerStateListener extends BasicListener{ if (fightTeam == null) { Fight.setPlayerGamemode(player, GameMode.SPECTATOR); player.teleport(Config.SpecSpawn); - //new TablistNamePacket(SteamwarUser.get(player).getId(), "§7§o" + player.name()).send(player); + new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7§o" + player.getName()).send(player); } else { player.teleport(fightTeam.getSpawn()); if(FightSystem.getFightState().setup()) From 32814697729df2508bd9ade4b9e627e1615a0eed Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 29 Oct 2020 21:40:28 +0100 Subject: [PATCH 37/55] 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); } From 924ed3b30aabfb6ed836acd142383d9c4b20b466 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 30 Oct 2020 07:31:21 +0100 Subject: [PATCH 38/55] Disable TablistPacket on test arenas Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/FightTeam.java | 6 ++++-- .../steamwar/fightsystem/listener/PlayerStateListener.java | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index aa7e00b..142568e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -182,7 +182,8 @@ public class FightTeam implements IFightTeam{ if(KitManager.getKits(false).size() > 1 || Config.PersonalKits) player.getInventory().setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§eKit wählen").build()); player.getInventory().setItem(7, new ItemBuilder(Material.BEACON).removeAllAttributs().setDisplayName("§eRespawn").build()); - new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), prefix + player.getName()).send(player); + if(!Config.test()) + new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), prefix + player.getName()).send(player); TechHider.reloadChunks(player, chunksToReload); return fightPlayer; } @@ -200,7 +201,8 @@ public class FightTeam implements IFightTeam{ Fight.setPlayerGamemode(player, GameMode.SPECTATOR); player.teleport(Config.SpecSpawn); - new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7§o" + player.getName()).send(player); + if(!Config.test()) + new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7§o" + player.getName()).send(player); TechHider.reloadChunks(player, chunksToReload); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java index 721f523..56d6c93 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java @@ -63,7 +63,8 @@ public class PlayerStateListener extends BasicListener{ if (fightTeam == null) { Fight.setPlayerGamemode(player, GameMode.SPECTATOR); player.teleport(Config.SpecSpawn); - new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7§o" + player.getName()).send(player); + if(!Config.test()) + new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7§o" + player.getName()).send(player); } else { player.teleport(fightTeam.getSpawn()); if(FightSystem.getFightState().setup()) From acb83e7fbb3c4eb5478f7bafbaf4760f40529017 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 30 Oct 2020 07:52:08 +0100 Subject: [PATCH 39/55] Hotfix Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/FightTeam.java | 2 +- .../de/steamwar/fightsystem/listener/PlayerStateListener.java | 2 +- 2 files 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 142568e..9114a71 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -183,7 +183,7 @@ public class FightTeam implements IFightTeam{ player.getInventory().setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§eKit wählen").build()); player.getInventory().setItem(7, new ItemBuilder(Material.BEACON).removeAllAttributs().setDisplayName("§eRespawn").build()); if(!Config.test()) - new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), prefix + player.getName()).send(player); + Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), prefix + player.getName()).send(player), 1); TechHider.reloadChunks(player, chunksToReload); return fightPlayer; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java index 56d6c93..a5b182d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java @@ -64,7 +64,7 @@ public class PlayerStateListener extends BasicListener{ Fight.setPlayerGamemode(player, GameMode.SPECTATOR); player.teleport(Config.SpecSpawn); if(!Config.test()) - new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7§o" + player.getName()).send(player); + Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7" + player.getName()).send(player), 1); } else { player.teleport(fightTeam.getSpawn()); if(FightSystem.getFightState().setup()) From 55b27082cbf3638a3781bb4c75208fa796d5ef55 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 30 Oct 2020 14:06:38 +0100 Subject: [PATCH 40/55] Kick all nonparticipants if Event with SpectateSystem Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/Config.java | 3 +++ .../fightsystem/listener/EventJoinListener.java | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 43db7ba..5510486 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -140,6 +140,7 @@ public class Config { public static final int EventTeamRedID; public static final boolean BothTeamsPublic; public static final int MaximumTeamMembers; + public static final boolean SpectateSystem; //check parameter public static final int CheckSchemID; @@ -370,6 +371,7 @@ public class Config { OnlyPublicSchematics = event.publicSchemsOnly(); MaximumTeamMembers = event.getMaximumTeamMembers(); } + SpectateSystem = event.spectateSystem(); }else{ //No event TeamRedName = config.getString("Output.TeamRedName"); @@ -379,6 +381,7 @@ public class Config { EventTeamRedID = 0; BothTeamsPublic = true; MaximumTeamMembers = Integer.MAX_VALUE; + SpectateSystem = false; } String blueLeader = System.getProperty("blueLeader", null); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoinListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoinListener.java index 23a4a31..73284cd 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoinListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoinListener.java @@ -29,6 +29,7 @@ import de.steamwar.sql.SteamwarUser; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerQuitEvent; import java.util.EnumSet; @@ -39,6 +40,21 @@ public class EventJoinListener extends BasicListener { super(Config.event() ? EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP) : EnumSet.noneOf(FightState.class)); } + @EventHandler + public void playerLogin(PlayerLoginEvent event) { + if(!Config.SpectateSystem) + return; + + Player player = event.getPlayer(); + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + if(user.getTeam() == Config.EventTeamBlueID || + user.getTeam() == Config.EventTeamRedID || + user.getId() == FightSystem.getEventFight().getKampfleiter()) + return; + + event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "§cDu bist kein Kampfteilnehmer"); + } + @EventHandler public void handlePlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); From 6189b7278a2c0336941ee99e4be334a4a4e21297 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 30 Oct 2020 22:04:04 +0100 Subject: [PATCH 41/55] Hotfix gm 31 in testarena & tablist Signed-off-by: Lixfel --- FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java | 2 +- .../src/de/steamwar/fightsystem/fight/FightTeam.java | 2 +- .../de/steamwar/fightsystem/listener/PlayerStateListener.java | 2 +- 3 files changed, 3 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 4d944c1..595e107 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java @@ -130,7 +130,7 @@ public class Fight { } } - if(FightSystem.getEventLeiter() == player) + if(FightSystem.getEventLeiter() == player || Config.test()) return; Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index 9114a71..cfaed39 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -183,7 +183,7 @@ public class FightTeam implements IFightTeam{ player.getInventory().setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§eKit wählen").build()); player.getInventory().setItem(7, new ItemBuilder(Material.BEACON).removeAllAttributs().setDisplayName("§eRespawn").build()); if(!Config.test()) - Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), prefix + player.getName()).send(player), 1); + Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), prefix + player.getName()).send(player), 5); TechHider.reloadChunks(player, chunksToReload); return fightPlayer; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java index a5b182d..d07ab37 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java @@ -64,7 +64,7 @@ public class PlayerStateListener extends BasicListener{ Fight.setPlayerGamemode(player, GameMode.SPECTATOR); player.teleport(Config.SpecSpawn); if(!Config.test()) - Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7" + player.getName()).send(player), 1); + Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7" + player.getName()).send(player), 5); } else { player.teleport(fightTeam.getSpawn()); if(FightSystem.getFightState().setup()) From 014cee20a8e69970cc11d618d85194ee7ad5a09b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 1 Nov 2020 16:17:00 +0100 Subject: [PATCH 42/55] 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)); From d9dede725b18715afdb117dd51ffcda50be71b37 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 2 Nov 2020 10:41:45 +0100 Subject: [PATCH 43/55] Fix fightscoreboard recording Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/utils/FightScoreboard.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java index 8be7cf7..69260b5 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java @@ -79,7 +79,7 @@ public class FightScoreboard { RecordSystem.scoreboardTitle(fightTeam.getColoredName()); fightTeam.getPlayers().forEach(fp -> { if(fp.isLiving()) - objective.getScore(fightTeam.getPrefix() + fp.getPlayer().getName()).setScore((int) Math.ceil(fp.getPlayer().getHealth())); + setScore(fightTeam.getPrefix() + fp.getPlayer().getName(), (int) Math.ceil(fp.getPlayer().getHealth())); }); } From 5b12e10b98598cbcd5188a9c924336a36d76c22f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 2 Nov 2020 12:13:57 +0100 Subject: [PATCH 44/55] Fix player despawn Signed-off-by: Lixfel --- .../listener/EventRecordListener.java | 16 ---------------- .../listener/PlayerStateListener.java | 9 +++++++++ 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java index 8dcc023..12ed538 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java @@ -55,22 +55,6 @@ public class EventRecordListener extends BasicListener { super(Config.recording() ? EnumSet.allOf(FightState.class) : EnumSet.noneOf(FightState.class)); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onPlayerJoin(PlayerJoinEvent e){ - if(isNotSent(e.getPlayer())) - return; - - 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/listener/PlayerStateListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java index d07ab37..3830c12 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java @@ -27,6 +27,7 @@ import de.steamwar.fightsystem.countdown.SWSound; 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 de.steamwar.sql.SteamwarUser; import net.md_5.bungee.api.chat.TextComponent; @@ -89,6 +90,8 @@ public class PlayerStateListener extends BasicListener{ Fight.setPlayerGamemode(player, GameMode.SPECTATOR); player.teleport(fightTeam.getSpawn()); Fight.playSound(Countdown.getSound(SWSound.ENTITY_WITHER_DEATH), 100.0F, 1.0F); + if(Config.recording()) + RecordSystem.entityDespawns(player); } @EventHandler(priority = EventPriority.HIGH) @@ -103,11 +106,17 @@ public class PlayerStateListener extends BasicListener{ FightState fightState = FightSystem.getFightState(); if(fightState.setup()){ fightTeam.removePlayer(player); + + if(Config.recording()) + RecordSystem.entityDespawns(player); }else if(fightState.ingame()){ FightPlayer fightPlayer = fightTeam.getFightPlayer(player); if(fightPlayer.isLiving()) { Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler " + fightTeam.getPrefix() + player.getName() + " §chat den Kampf verlassen!"); fightTeam.getFightPlayer(player).setOut(); + + if(Config.recording()) + RecordSystem.entityDespawns(player); } } From ea63704c384aa5d54f68b0344d982d5f56dd4b2b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 2 Nov 2020 17:11:18 +0100 Subject: [PATCH 45/55] Kick non players and record more blocks (to prevent ghost blocks) Signed-off-by: Lixfel --- .../steamwar/fightsystem/listener/EventJoinListener.java | 7 ++++++- .../steamwar/fightsystem/listener/EventRecordListener.java | 5 ++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoinListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoinListener.java index 73284cd..6e60e5c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoinListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoinListener.java @@ -82,10 +82,15 @@ public class EventJoinListener extends BasicListener { FightPlayer fp = team.addMember(player); if(!team.hasTeamLeader()) team.setLeader(fp); + return; } - if(user.getId() == FightSystem.getEventFight().getKampfleiter()) + if(user.getId() == FightSystem.getEventFight().getKampfleiter()){ FightSystem.setEventLeiter(player); + return; + } + if(Config.SpectateSystem) + player.kickPlayer("§cDu bist kein Kampfteilnehmer"); } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java index 12ed538..7b690a1 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java @@ -104,9 +104,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()); + if(e.getBlock() == e.getSourceBlock() || e.getChangedType() == Material.AIR) + RecordSystem.blockChange(e.getBlock()); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) From c0887a87d01a7e3ac8bf565be19aa980f875696f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 2 Nov 2020 17:23:15 +0100 Subject: [PATCH 46/55] Start recording all event fights Signed-off-by: Lixfel --- FightSystem_API/src/de/steamwar/fightsystem/Config.java | 2 +- .../de/steamwar/fightsystem/record/SpectateConnection.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 1469700..524da67 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() && SpectateSystem; + return event(); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java index 8db7f20..9951321 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/SpectateConnection.java @@ -40,7 +40,8 @@ public class SpectateConnection extends Recorder{ 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); + Bukkit.getLogger().log(Level.WARNING, "Could not init connection to spectate server", e); + close(); } } @@ -140,7 +141,7 @@ public class SpectateConnection extends Recorder{ socket.close(); outputStream.close(); } catch (IOException e) { - Bukkit.getLogger().log(Level.SEVERE, "IOException on socket close", e); + Bukkit.getLogger().log(Level.WARNING, "IOException on socket close", e); } } } From 247396bffda8a0e84aeca0ecc74c094a06c4458a Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 2 Nov 2020 17:37:28 +0100 Subject: [PATCH 47/55] Hotfix player join not recognized Signed-off-by: Lixfel --- .../fightsystem/listener/EventRecordListener.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java index 7b690a1..755eb19 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java @@ -55,6 +55,14 @@ public class EventRecordListener extends BasicListener { super(Config.recording() ? EnumSet.allOf(FightState.class) : EnumSet.noneOf(FightState.class)); } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onPlayerJoin(PlayerJoinEvent e){ + if(isNotSent(e.getPlayer())) + return; + + RecordSystem.playerJoins(e.getPlayer()); + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPlayerMove(PlayerMoveEvent e){ if(isNotSent(e.getPlayer())) From 3147783ef8c65bbb33efff3526d64a14e1a49305 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 2 Nov 2020 17:53:57 +0100 Subject: [PATCH 48/55] Hotfix player join not recognized Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/FightTeam.java | 4 ++++ .../fightsystem/listener/EventRecordListener.java | 8 -------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index 66cf9ae..57380a2 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -185,6 +185,8 @@ public class FightTeam implements IFightTeam{ player.getInventory().setItem(7, new ItemBuilder(Material.BEACON).removeAllAttributs().setDisplayName("§eRespawn").build()); if(!Config.test()) Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), prefix + player.getName()).send(player), 5); + if(Config.recording()) + RecordSystem.playerJoins(player); TechHider.reloadChunks(player, chunksToReload); return fightPlayer; } @@ -204,6 +206,8 @@ public class FightTeam implements IFightTeam{ player.teleport(Config.SpecSpawn); if(!Config.test()) new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7§o" + player.getName()).send(player); + if(Config.recording()) + RecordSystem.entityDespawns(player); TechHider.reloadChunks(player, chunksToReload); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java index 755eb19..7b690a1 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java @@ -55,14 +55,6 @@ public class EventRecordListener extends BasicListener { super(Config.recording() ? EnumSet.allOf(FightState.class) : EnumSet.noneOf(FightState.class)); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onPlayerJoin(PlayerJoinEvent e){ - if(isNotSent(e.getPlayer())) - return; - - RecordSystem.playerJoins(e.getPlayer()); - } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPlayerMove(PlayerMoveEvent e){ if(isNotSent(e.getPlayer())) From fc1400a73a203e1b389c7e434864380137a7cd93 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 2 Nov 2020 18:07:09 +0100 Subject: [PATCH 49/55] Hotfix player join not recognized Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/FightSystem.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index 7394a12..8ad4146 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -32,7 +32,10 @@ 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.*; +import de.steamwar.fightsystem.utils.EnterHandler; +import de.steamwar.fightsystem.utils.FightScoreboard; +import de.steamwar.fightsystem.utils.FightStatistics; +import de.steamwar.fightsystem.utils.TechHider; import de.steamwar.fightsystem.winconditions.*; import de.steamwar.sql.EventFight; import de.steamwar.sql.Schematic; @@ -68,6 +71,7 @@ public class FightSystem extends JavaPlugin { KitManager.loadAllKits(); TechHider.init(); FightScoreboard.init(); + RecordSystem.init(); try { CommandRemover.removeAll("gamemode"); @@ -132,7 +136,6 @@ 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()){ From 2317505494c57061042d10b700d940a0c6002285 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 2 Nov 2020 18:32:33 +0100 Subject: [PATCH 50/55] Double disconnect fix Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/FightTeam.java | 2 -- 1 file changed, 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 57380a2..61d5b64 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -185,8 +185,6 @@ public class FightTeam implements IFightTeam{ player.getInventory().setItem(7, new ItemBuilder(Material.BEACON).removeAllAttributs().setDisplayName("§eRespawn").build()); if(!Config.test()) Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), prefix + player.getName()).send(player), 5); - if(Config.recording()) - RecordSystem.playerJoins(player); TechHider.reloadChunks(player, chunksToReload); return fightPlayer; } From 1848622a50b6c74d3ca4a2c2cb18ce8a57e58a44 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 7 Nov 2020 11:40:01 +0100 Subject: [PATCH 51/55] Implementing tps scoreboard parameter Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/utils/FightScoreboard.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java index 69260b5..81f3935 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java @@ -19,6 +19,7 @@ package de.steamwar.fightsystem.utils; +import de.steamwar.core.TPSWatcher; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; @@ -90,11 +91,13 @@ public class FightScoreboard { if (Config.Timeout || Config.Points || Config.HeartRatioTimeout) { int fightTime = FightSystem.getFightTime(); if (fightTime >= 60) - setScore("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s", 3); + setScore("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s", 4); else - setScore("§7Zeit: §a" + fightTime + "s", 3); + setScore("§7Zeit: §a" + fightTime + "s", 4); } + setScore("§7TPS: §e" + TPSWatcher.getTPS(), 3); + if(fullScoreboard.contains(FightSystem.getFightState())){ if (Config.PercentSystem){ setScore(Fight.getRedTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getRedPercent()) / 100.0) + "%", 1); From c423d8ea2277a200ce8770b0f40600d4c9eeac6b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 9 Nov 2020 19:25:21 +0100 Subject: [PATCH 52/55] Hothotfix Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/FightTeam.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index 61d5b64..57380a2 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -185,6 +185,8 @@ public class FightTeam implements IFightTeam{ player.getInventory().setItem(7, new ItemBuilder(Material.BEACON).removeAllAttributs().setDisplayName("§eRespawn").build()); if(!Config.test()) Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), prefix + player.getName()).send(player), 5); + if(Config.recording()) + RecordSystem.playerJoins(player); TechHider.reloadChunks(player, chunksToReload); return fightPlayer; } From 680994aed9df8843928a3142dc39b8f30fccdc3b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 10 Nov 2020 09:59:19 +0100 Subject: [PATCH 53/55] Fix small fightstate bug Signed-off-by: Lixfel --- FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java index 7d598ba..fe567c3 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java @@ -153,7 +153,8 @@ public class GUI { FightTeam fightTeam = Fight.getPlayerTeam(p); if(fightTeam == null) return; - fightTeam.setSchematic(s); + if(FightSystem.getFightState() != FightState.POST_SCHEM_SETUP) + fightTeam.setSchematic(s); p.closeInventory(); }); inv.setCallback(-999, (ClickType click) -> p.closeInventory()); From aa3d9f4a8a97fb1fc4788f7601a7fb743e1535ca Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 12 Nov 2020 14:25:38 +0100 Subject: [PATCH 54/55] Fix NPE Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/utils/FightStatistics.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java index 0b948b3..23fcdf4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -47,6 +47,8 @@ public class FightStatistics { public static void saveStats(FightTeam winner, String windescription){ String gameMode = Config.SchematicType.toDB(); + if(!Fight.getBlueTeam().hasTeamLeader() || !Fight.getRedTeam().hasTeamLeader()) + return; SteamwarUser blueLeader = SteamwarUser.get(Fight.getBlueTeam().getLeader().getPlayer().getUniqueId()); SteamwarUser redLeader = SteamwarUser.get(Fight.getRedTeam().getLeader().getPlayer().getUniqueId()); int win = 0; From 59a000d3f2135cdf560059a2fb9ebffb9d844795 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 15 Nov 2020 11:24:57 +0100 Subject: [PATCH 55/55] Fix closed channel packets Signed-off-by: Lixfel --- FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java index 30d4087..e060c46 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java @@ -134,6 +134,8 @@ public class Fight { return; Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { + if(!player.isOnline()) + return; PacketContainer gm1packet = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.PLAYER_INFO); gm1packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE); List playerInfoActions = new ArrayList<>();