SteamWar/FightSystem
Archiviert
13
1
Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2021-10-13 08:50:49 +02:00
Ursprung 4fc9a6cd8e
Commit 4bf27107c6
7 geänderte Dateien mit 116 neuen und 35 gelöschten Zeilen

Datei anzeigen

@ -231,13 +231,6 @@ public class FightSystem extends JavaPlugin {
return plugin; 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) { public static void broadcast(String message) {
Bukkit.broadcastMessage(PREFIX + message); Bukkit.broadcastMessage(PREFIX + message);
GlobalRecorder.getInstance().systemChat(PREFIX + message); GlobalRecorder.getInstance().systemChat(PREFIX + message);
@ -247,13 +240,14 @@ public class FightSystem extends JavaPlugin {
return plugin.message; return plugin.message;
} }
private static void kickNext(){ public static void shutdown() {
//Staggered kick to prevent lobby overloading
if(Bukkit.getOnlinePlayers().isEmpty()){ if(Bukkit.getOnlinePlayers().isEmpty()){
Bukkit.shutdown(); Bukkit.shutdown();
return; return;
} }
Bukkit.getOnlinePlayers().iterator().next().kickPlayer(null); Bukkit.getOnlinePlayers().iterator().next().kickPlayer(null);
Bukkit.getScheduler().runTaskLater(plugin, FightSystem::kickNext, 10); Bukkit.getScheduler().runTaskLater(plugin, FightSystem::shutdown, 10);
} }
} }

Datei anzeigen

@ -151,6 +151,10 @@ RESOURCEPACK_REQUIRED=
NO_ENTERN=§cDu darfst nicht entern NO_ENTERN=§cDu darfst nicht entern
NO_TEAMAREA=§cDu darfst nicht zu den Teams NO_TEAMAREA=§cDu darfst nicht zu den Teams
TEST_BECOME_LEADER=§7Werde zum Teamleader mit §8/§eleader 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 # Replay

Datei anzeigen

@ -40,6 +40,6 @@ public class EventSpectateCountdown extends Countdown {
@Override @Override
public void countdownFinished() { public void countdownFinished() {
FightSystem.shutdown(null); FightSystem.shutdown();
} }
} }

Datei anzeigen

@ -53,14 +53,16 @@ public class PrepareSchem implements Listener {
try{ try{
schem = Schematic.getSchemFromDB(Config.PrepareSchemID); schem = Schematic.getSchemFromDB(Config.PrepareSchemID);
}catch(SecurityException e){ }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; return;
} }
try{ try{
region.forEach((x, y, z) -> { region.forEach((x, y, z) -> {
if(FlatteningWrapper.impl.checkPistonMoving(world.getBlockAt(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(); throw new IllegalStateException();
} }
}); });
@ -71,12 +73,14 @@ public class PrepareSchem implements Listener {
try{ try{
WorldeditWrapper.impl.saveSchem(schem, region, minY); WorldeditWrapper.impl.saveSchem(schem, region, minY);
}catch(WorldEditException e){ }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); throw new SecurityException("Could not save schem", e);
} }
schem.setSchemType(Config.SchematicType.checkType()); 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();
} }
}; };
} }

Datei anzeigen

@ -45,7 +45,9 @@ import org.bukkit.scheduler.BukkitTask;
import java.io.EOFException; import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
@ -458,6 +460,44 @@ public class PacketProcessor {
} }
} }
private Object[] readMessageParams() throws IOException {
List<Object> 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{ private interface PacketParser{
void process() throws IOException; void process() throws IOException;
} }

Datei anzeigen

@ -126,6 +126,17 @@ public interface Recorder {
* *
* CommentPacket (0xfe) + String comment * CommentPacket (0xfe) + String comment
* TickPacket (0xff) * 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){ default void playerJoins(Player p){
@ -289,25 +300,8 @@ public interface Recorder {
DataOutputStream stream = getStream(); DataOutputStream stream = getStream();
try { try {
stream.writeByte(id); stream.writeByte(id);
for(Object o : objects){ for(Object o : objects) {
if(o instanceof Boolean) writeObject(stream, o);
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());
} }
stream.flush(); stream.flush();
} catch (IOException e) { } 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 { static void copy(InputStream var0, OutputStream var1) throws IOException {
int var5; int var5;
for(byte[] var4 = new byte[8192]; (var5 = var0.read(var4)) > 0;) { for(byte[] var4 = new byte[8192]; (var5 = var0.read(var4)) > 0;) {

Datei anzeigen

@ -144,7 +144,7 @@ public class FightUI {
BLUE_LEFT(345, 165), BLUE_LEFT(345, 165),
RED_LEFT(165, 345); 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 minAngle;
private final double maxAngle; private final double maxAngle;
@ -155,7 +155,7 @@ public class FightUI {
} }
private static BossBarType byAngle(double angle) { private static BossBarType byAngle(double angle) {
if(blueNegZ) if(BLUE_NEG_Z)
angle += 180; angle += 180;
angle = ((angle % 360) + 360) % 360; angle = ((angle % 360) + 360) % 360;