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);
}
}
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);
}
}
}
Aggregations