use of org.spongepowered.asm.util.PrettyPrinter 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);
}
}
}
use of org.spongepowered.asm.util.PrettyPrinter in project SpongeCommon by SpongePowered.
the class MixinItemStack method getContainers.
@Override
public Collection<DataManipulator<?, ?>> getContainers() {
final List<DataManipulator<?, ?>> manipulators = Lists.newArrayList();
final Item item = this.shadow$getItem();
// Null items should be impossible to create
if (item == null) {
final PrettyPrinter printer = new PrettyPrinter(60);
printer.add("Null Item found!").centre().hr();
printer.add("An ItemStack has a null ItemType! This is usually not supported as it will likely have issues elsewhere.");
printer.add("Please ask help for seeing if this is an issue with a mod and report it!");
printer.add("Printing a Stacktrace:");
printer.add(new Exception());
printer.log(SpongeImpl.getLogger(), Level.WARN);
return manipulators;
}
((IMixinItem) item).getManipulatorsFor((net.minecraft.item.ItemStack) (Object) this, manipulators);
if (hasManipulators()) {
final List<DataManipulator<?, ?>> customManipulators = this.getCustomManipulators();
manipulators.addAll(customManipulators);
}
return manipulators;
}
use of org.spongepowered.asm.util.PrettyPrinter in project SpongeCommon by SpongePowered.
the class PhaseTracker method printRunawayPhase.
private void printRunawayPhase(IPhaseState<?> state, PhaseContext<?> context) {
if (!SpongeImpl.getGlobalConfig().getConfig().getPhaseTracker().isVerbose() && !this.hasPrintedAboutRunnawayPhases) {
// Avoiding spam logs.
return;
}
final PrettyPrinter printer = new PrettyPrinter(60);
printer.add("Switching Phase").centre().hr();
printer.addWrapped(60, "Detecting a runaway phase! Potentially a problem where something isn't completing a phase!!!");
printer.add(" %s : %s", "Entering Phase", state.getPhase());
printer.add(" %s : %s", "Entering State", state);
CONTEXT_PRINTER.accept(printer, context);
printer.addWrapped(60, "%s :", "Phases remaining");
this.stack.forEach(data -> PHASE_PRINTER.accept(printer, data));
printer.add();
printer.add(" %s :", "Printing stack trace").add(new Exception("Stack trace"));
printer.add();
this.generateVersionInfo(printer);
printer.trace(System.err, SpongeImpl.getLogger(), Level.ERROR);
if (!SpongeImpl.getGlobalConfig().getConfig().getPhaseTracker().isVerbose() && this.printRunawayCount++ > SpongeImpl.getGlobalConfig().getConfig().getPhaseTracker().getMaximumRunawayCount()) {
this.hasPrintedAboutRunnawayPhases = true;
}
}
use of org.spongepowered.asm.util.PrettyPrinter in project SpongeCommon by SpongePowered.
the class PhaseTracker method printExceptionFromPhase.
public void printExceptionFromPhase(Throwable e, PhaseContext<?> context) {
if (!SpongeImpl.getGlobalConfig().getConfig().getPhaseTracker().isVerbose() && !this.printedExceptionsForState.isEmpty()) {
for (IPhaseState<?> iPhaseState : this.printedExceptionsForState) {
if (context.state == iPhaseState) {
return;
}
}
}
final PrettyPrinter printer = new PrettyPrinter(60).add("Exception occurred during a PhaseState").centre().hr().addWrapped("Sponge's tracking system makes a best effort to not throw exceptions randomly but sometimes it is inevitable. In most " + "cases, something else triggered this exception and Sponge prevented a crash by catching it. The following stacktrace can be " + "used to help pinpoint the cause.").hr().add("The PhaseState having an exception: %s", context.state).add("The PhaseContext:");
printer.add(context.printCustom(printer));
printer.hr().add("StackTrace:").add(e);
printer.add(" Phases Remaining:");
this.stack.forEach(data -> PHASE_PRINTER.accept(printer, data));
printer.add();
this.generateVersionInfo(printer);
printer.trace(System.err, SpongeImpl.getLogger(), Level.ERROR);
if (!SpongeImpl.getGlobalConfig().getConfig().getPhaseTracker().isVerbose()) {
this.printedExceptionsForState.add(context.state);
}
}
use of org.spongepowered.asm.util.PrettyPrinter in project SpongeCommon by SpongePowered.
the class PhaseTracker method printMessageWithCaughtException.
private void printMessageWithCaughtException(String header, String subHeader, IPhaseState<?> state, PhaseContext<?> context, Throwable t) {
final PrettyPrinter printer = new PrettyPrinter(60);
printer.add(header).centre().hr().add("%s %s", subHeader, state).addWrapped(60, "%s :", "PhaseContext");
CONTEXT_PRINTER.accept(printer, context);
printer.addWrapped(60, "%s :", "Phases remaining");
this.stack.forEach(data -> PHASE_PRINTER.accept(printer, data));
printer.add("Stacktrace:").add(t);
printer.add();
this.generateVersionInfo(printer);
printer.trace(System.err, SpongeImpl.getLogger(), Level.ERROR);
}
Aggregations