mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-02 08:39:59 +01:00
Wrap exceptions in remappers to InformativeEx
This commit is contained in:
parent
f16ff65933
commit
dae83d0e36
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user