🎨 Update Exceptions
Dieser Commit ist enthalten in:
Ursprung
75c03f79c5
Commit
fed8a5f830
@ -20,21 +20,19 @@
|
|||||||
package de.steamwar.network.packets;
|
package de.steamwar.network.packets;
|
||||||
|
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
@EqualsAndHashCode
|
@EqualsAndHashCode
|
||||||
public abstract class NetworkPacket implements Serializable {
|
public abstract class NetworkPacket implements Serializable {
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
public byte[] serialize() {
|
public byte[] serialize() {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
try {
|
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
oos.writeObject(this);
|
||||||
oos.writeObject(this);
|
oos.flush();
|
||||||
oos.flush();
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
return baos.toByteArray();
|
return baos.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,13 +40,10 @@ public abstract class NetworkPacket implements Serializable {
|
|||||||
PacketHandler.handlePacket(deserialize(data));
|
PacketHandler.handlePacket(deserialize(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
public static NetworkPacket deserialize(byte[] data) {
|
public static NetworkPacket deserialize(byte[] data) {
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(data);
|
ByteArrayInputStream bais = new ByteArrayInputStream(data);
|
||||||
try {
|
ObjectInputStream ois = new ObjectInputStream(bais);
|
||||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
return (NetworkPacket) ois.readObject();
|
||||||
return (NetworkPacket) ois.readObject();
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren