3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

Wrap exceptions in remappers to InformativeEx

Dieser Commit ist enthalten in:
KennyTV 2020-07-02 11:08:59 +02:00
Ursprung 67c5e78e7b
Commit 61fb1c249c
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
2 geänderte Dateien mit 18 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -8,6 +8,7 @@ import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.platform.providers.ViaProviders;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.exception.CancelException;
import us.myles.ViaVersion.exception.InformativeException;
import us.myles.ViaVersion.packets.Direction;
import us.myles.ViaVersion.packets.State;
@ -417,9 +418,9 @@ public abstract class Protocol<C1 extends ClientboundPacketType, C2 extends Clie
// Remap
try {
protocolPacket.getRemapper().remap(packetWrapper);
} catch (Exception e) {
// Don't print cancelled packets or the handshake
if (e instanceof CancelException || state == State.HANDSHAKE) {
} catch (InformativeException e) { // Catch InformativeExceptions, pass through CancelExceptions
// Don't print errors during handshake
if (state == State.HANDSHAKE) {
throw e;
}

Datei anzeigen

@ -3,6 +3,7 @@ package us.myles.ViaVersion.api.remapper;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Pair;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.exception.CancelException;
import us.myles.ViaVersion.exception.InformativeException;
import java.util.ArrayList;
@ -62,7 +63,9 @@ public abstract class PacketRemapper {
* @param <T2> The new return type.
*/
public <T1, T2> void map(ValueTransformer<T1, T2> transformer) {
if (transformer.getInputType() == null) throw new IllegalArgumentException("Use map(Type<T1>, ValueTransformer<T1, T2>) for value transformers without specified input type!");
if (transformer.getInputType() == null) {
throw new IllegalArgumentException("Use map(Type<T1>, ValueTransformer<T1, T2>) for value transformers without specified input type!");
}
map(transformer.getInputType(), transformer);
}
@ -116,7 +119,8 @@ public abstract class PacketRemapper {
* Remap a packet wrapper
*
* @param packetWrapper The wrapper to remap
* @throws Exception Throws if it fails to write / read to the packet.
* @throws InformativeException if it fails to write / read to the packet
* @throws CancelException if the packet should be cancelled
*/
public void remap(PacketWrapper packetWrapper) throws Exception {
try {
@ -130,6 +134,14 @@ public abstract class PacketRemapper {
} catch (InformativeException e) {
e.addSource(this.getClass());
throw e;
} catch (CancelException e) {
// Pass through CancelExceptions
throw e;
} catch (Exception e) {
// Wrap other exceptions during packet handling
InformativeException ex = new InformativeException(e);
ex.addSource(this.getClass());
throw ex;
}
}
}