Search in sources :

Example 1 with PEBKACException

use of org.spongepowered.api.util.PEBKACException in project SpongeCommon by SpongePowered.

the class ManipulatorTest method testSerialization.

@SuppressWarnings("unchecked")
@Test
public void testSerialization() {
    try {
        final Constructor<?> ctor = this.manipulatorClass.getConstructor();
        final DataManipulator<?, ?> manipulator = (DataManipulator<?, ?>) ctor.newInstance();
        final DataContainer container = manipulator.toContainer();
        if (this.builder != null) {
            final Optional<DataManipulator<?, ?>> optional = (Optional<DataManipulator<?, ?>>) this.builder.build(container);
            if (!optional.isPresent()) {
                throw new IllegalArgumentException("[Serialization]: A builder did not translate the data manipulator: " + this.dataName + "\n[Serialization]: Providing the DataContainer: " + container.toString());
            }
            final DataManipulator<?, ?> deserialized = this.builder.build(container).get();
            assertThat(manipulator.equals(deserialized), is(true));
        }
    } catch (NoSuchMethodException | InstantiationException | InvocationTargetException e) {
        throw new PEBKACException("Exceptions thrown trying to construct: " + this.dataName, e);
    } catch (Exception e) {
        throw new RuntimeException("There was an unknown exception trying to test " + this.dataName + ". Probably because the DataManipulator relies on an implementation class.", e);
    }
}
Also used : Optional(java.util.Optional) ImmutableDataManipulator(org.spongepowered.api.data.manipulator.ImmutableDataManipulator) DataManipulator(org.spongepowered.api.data.manipulator.DataManipulator) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PEBKACException(org.spongepowered.api.util.PEBKACException) DataContainer(org.spongepowered.api.data.DataContainer) PEBKACException(org.spongepowered.api.util.PEBKACException) Test(org.junit.Test)

Example 2 with PEBKACException

use of org.spongepowered.api.util.PEBKACException in project SpongeForge by SpongePowered.

the class MixinNBTTagCompound method checkNullTag.

@Inject(method = "setTag(Ljava/lang/String;Lnet/minecraft/nbt/NBTBase;)V", at = @At("HEAD"))
private void checkNullTag(String key, NBTBase value, CallbackInfo callbackInfo) {
    if (value == null) {
        final PrettyPrinter printer = new PrettyPrinter(60);
        printer.add("Null being stored in NBT!!!").centre().hr();
        printer.addWrapped("Sponge is forcing a shutdown of the game because someone is storing nulls in an NBTTagCompound. " + "Our implementation and Minecraft's strictly prevents this from happening, however, certain mods are" + "not null checking. Please provide this report in a report to the associated mod!");
        printer.add("NBT Key: %s", key);
        printer.add("Exception!");
        final PEBKACException pebkacException = new PEBKACException("Someone is trying to store a null to an NBTTagCompound!");
        printer.add(pebkacException);
        printer.log(SpongeImpl.getLogger(), Level.ERROR);
        try {
            final Class<?> terminateVm = Class.forName("org.spongepowered.mixin.handler.TerminateVM");
            final Method terminate = terminateVm.getMethod("terminate");
            terminate.setAccessible(true);
            terminate.invoke(null, "net.minecraftforge.fml", -2);
        } catch (Exception e) {
            FMLCommonHandler.instance().exitJava(-2, true);
        }
    }
}
Also used : PrettyPrinter(org.spongepowered.asm.util.PrettyPrinter) PEBKACException(org.spongepowered.api.util.PEBKACException) Method(java.lang.reflect.Method) PEBKACException(org.spongepowered.api.util.PEBKACException) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

PEBKACException (org.spongepowered.api.util.PEBKACException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Optional (java.util.Optional)1 Test (org.junit.Test)1 DataContainer (org.spongepowered.api.data.DataContainer)1 DataManipulator (org.spongepowered.api.data.manipulator.DataManipulator)1 ImmutableDataManipulator (org.spongepowered.api.data.manipulator.ImmutableDataManipulator)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1 PrettyPrinter (org.spongepowered.asm.util.PrettyPrinter)1