diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 41f6cd7..6c45bfd 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -231,13 +231,6 @@ public class FightSystem extends JavaPlugin { return plugin; } - public static void shutdown(String reason){ - if(reason != null) - FightSystem.broadcast(reason); - //Staggered kick to prevent lobby overloading - kickNext(); - } - public static void broadcast(String message) { Bukkit.broadcastMessage(PREFIX + message); GlobalRecorder.getInstance().systemChat(PREFIX + message); @@ -247,13 +240,14 @@ public class FightSystem extends JavaPlugin { return plugin.message; } - private static void kickNext(){ + public static void shutdown() { + //Staggered kick to prevent lobby overloading if(Bukkit.getOnlinePlayers().isEmpty()){ Bukkit.shutdown(); return; } Bukkit.getOnlinePlayers().iterator().next().kickPlayer(null); - Bukkit.getScheduler().runTaskLater(plugin, FightSystem::kickNext, 10); + Bukkit.getScheduler().runTaskLater(plugin, FightSystem::shutdown, 10); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties index f646e38..81bc2f7 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties @@ -151,6 +151,10 @@ RESOURCEPACK_REQUIRED= NO_ENTERN=§cDu darfst nicht entern NO_TEAMAREA=§cDu darfst nicht zu den Teams TEST_BECOME_LEADER=§7Werde zum Teamleader mit §8/§eleader +PREPARE_SCHEM_DELETED=§cAnscheinend wurde die auszufahrende Schematic gelöscht, Einsenden wird abgebrochen. +PREPARE_ACTIVE_PISTON=§cIm Teambereich wurden sich noch bewegende Pistons gefunden, Einsenden wird abgebrochen. +PREPARE_FAILED_SAVING=§cDie Schematic konnte nicht gespeichert werden, Einsenden wird abgebrochen. +PREPARE_SENT_IN=§aDie Schematic wird nun zeitnah von einem Teammitglied überprüft # Replay diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EventSpectateCountdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EventSpectateCountdown.java index 61be26c..485db37 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EventSpectateCountdown.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EventSpectateCountdown.java @@ -40,6 +40,6 @@ public class EventSpectateCountdown extends Countdown { @Override public void countdownFinished() { - FightSystem.shutdown(null); + FightSystem.shutdown(); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java index f20057f..8efd4ad 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java @@ -53,14 +53,16 @@ public class PrepareSchem implements Listener { try{ schem = Schematic.getSchemFromDB(Config.PrepareSchemID); }catch(SecurityException e){ - FightSystem.shutdown(FightSystem.PREFIX + "§cAnscheinend wurde die auszufahrende Schematic gelöscht, Einsenden wird abgebrochen."); + FightSystem.getMessage().broadcast("PREPARE_SCHEM_DELETED"); + Bukkit.shutdown(); return; } try{ region.forEach((x, y, z) -> { if(FlatteningWrapper.impl.checkPistonMoving(world.getBlockAt(x, y, z))){ - FightSystem.shutdown(FightSystem.PREFIX + "§cIm Teambereich wurden sich noch bewegende Pistons gefunden, Einsenden wird abgebrochen."); + FightSystem.getMessage().broadcast("PREPARE_ACTIVE_PISTON"); + Bukkit.shutdown(); throw new IllegalStateException(); } }); @@ -71,12 +73,14 @@ public class PrepareSchem implements Listener { try{ WorldeditWrapper.impl.saveSchem(schem, region, minY); }catch(WorldEditException e){ - FightSystem.shutdown(FightSystem.PREFIX + "§cDie Schematic konnte nicht gespeichert werden, Einsenden wird abgebrochen."); + FightSystem.getMessage().broadcast("PREPARE_FAILED_SAVING"); + Bukkit.shutdown(); throw new SecurityException("Could not save schem", e); } schem.setSchemType(Config.SchematicType.checkType()); - FightSystem.shutdown(FightSystem.PREFIX + "§aDie Schematic wird nun zeitnah von einem Teammitglied überprüft"); + FightSystem.getMessage().broadcast("PREPARE_SENT_IN"); + Bukkit.shutdown(); } }; } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index 5fbddf3..ba988e9 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -45,7 +45,9 @@ import org.bukkit.scheduler.BukkitTask; import java.io.EOFException; import java.io.IOException; +import java.util.ArrayList; import java.util.LinkedList; +import java.util.List; import java.util.Set; import java.util.logging.Level; @@ -458,6 +460,44 @@ public class PacketProcessor { } } + private Object[] readMessageParams() throws IOException { + List params = new ArrayList<>(); + + int type; + do { + type = Byte.toUnsignedInt(source.readByte()); + switch(type) { + case 0x00: + break; + case 0x01: + params.add(source.readBoolean()); + break; + case 0x02: + params.add(source.readByte()); + break; + case 0x03: + params.add(source.readShort()); + break; + case 0x04: + params.add(source.readInt()); + break; + case 0x05: + params.add(source.readFloat()); + break; + case 0x06: + params.add(source.readDouble()); + break; + case 0x07: + params.add(source.readUTF()); + break; + default: + throw new IOException("Unknown message param type " + type); + } + } while(type != 0x00); + + return params.toArray(); + } + private interface PacketParser{ void process() throws IOException; } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java index 903ddcf..936f74e 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java @@ -126,6 +126,17 @@ public interface Recorder { * * CommentPacket (0xfe) + String comment * TickPacket (0xff) + * + * Message-Format + * String message + byte prefixed Object-Params + byte 0x00 + * 0x00: End of message + * 0x01: boolean following + * 0x02: byte following + * 0x03: short following + * 0x04: int following + * 0x05: float following + * 0x06: double following + * 0x07: String following * */ default void playerJoins(Player p){ @@ -289,25 +300,8 @@ public interface Recorder { DataOutputStream stream = getStream(); try { stream.writeByte(id); - for(Object o : objects){ - if(o instanceof Boolean) - stream.writeBoolean((Boolean)o); - else if(o instanceof Byte) - stream.writeByte((Byte)o); - else if(o instanceof Short) - stream.writeShort((Short)o); - else if(o instanceof Integer) - stream.writeInt((Integer)o); - else if(o instanceof Float) - stream.writeFloat((Float)o); - else if(o instanceof Double) - stream.writeDouble((Double)o); - else if(o instanceof String) - stream.writeUTF((String)o); - else if(o instanceof byte[]) - stream.write((byte[])o); - else - throw new SecurityException("Undefined write for: " + o.getClass().getName()); + for(Object o : objects) { + writeObject(stream, o); } stream.flush(); } catch (IOException e) { @@ -316,6 +310,51 @@ public interface Recorder { } } + default void writeObject(DataOutputStream stream, Object o) throws IOException { + if(o instanceof Boolean) + stream.writeBoolean((Boolean)o); + else if(o instanceof Byte) + stream.writeByte((Byte)o); + else if(o instanceof Short) + stream.writeShort((Short)o); + else if(o instanceof Integer) + stream.writeInt((Integer)o); + else if(o instanceof Float) + stream.writeFloat((Float)o); + else if(o instanceof Double) + stream.writeDouble((Double)o); + else if(o instanceof String) + stream.writeUTF((String)o); + else if(o instanceof byte[]) + stream.write((byte[])o); + else + throw new SecurityException("Undefined write for: " + o.getClass().getName()); + } + + default void writeMessage(DataOutputStream stream, String message, Object... params) throws IOException { + stream.writeUTF(message); + for(Object o : params) { + if(o instanceof Boolean) + stream.writeByte(0x01); + else if(o instanceof Byte) + stream.writeByte(0x02); + else if(o instanceof Short) + stream.writeByte(0x03); + else if(o instanceof Integer) + stream.writeByte(0x04); + else if(o instanceof Float) + stream.writeByte(0x05); + else if(o instanceof Double) + stream.writeByte(0x06); + else if(o instanceof String) + stream.writeByte(0x07); + else + throw new SecurityException("Undefined message serialization for: " + o.getClass().getName()); + writeObject(stream, o); + } + stream.writeByte(0x00); + } + static void copy(InputStream var0, OutputStream var1) throws IOException { int var5; for(byte[] var4 = new byte[8192]; (var5 = var0.read(var4)) > 0;) { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightUI.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightUI.java index 73605cb..cf8f3fe 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightUI.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightUI.java @@ -144,7 +144,7 @@ public class FightUI { BLUE_LEFT(345, 165), RED_LEFT(165, 345); - private static final boolean blueNegZ = Config.blueNegZ(); + private static final boolean BLUE_NEG_Z = Config.blueNegZ(); private final double minAngle; private final double maxAngle; @@ -155,7 +155,7 @@ public class FightUI { } private static BossBarType byAngle(double angle) { - if(blueNegZ) + if(BLUE_NEG_Z) angle += 180; angle = ((angle % 360) + 360) % 360;