Search in sources :

Example 16 with PrettyPrinter

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

Example 17 with PrettyPrinter

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;
}
Also used : IMixinItem(org.spongepowered.common.interfaces.item.IMixinItem) Item(net.minecraft.item.Item) IMixinItem(org.spongepowered.common.interfaces.item.IMixinItem) PrettyPrinter(org.spongepowered.asm.util.PrettyPrinter) DataManipulator(org.spongepowered.api.data.manipulator.DataManipulator) InvalidDataException(org.spongepowered.api.data.persistence.InvalidDataException)

Example 18 with PrettyPrinter

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;
    }
}
Also used : PrettyPrinter(org.spongepowered.asm.util.PrettyPrinter) ReportedException(net.minecraft.util.ReportedException)

Example 19 with PrettyPrinter

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);
    }
}
Also used : PrettyPrinter(org.spongepowered.asm.util.PrettyPrinter)

Example 20 with PrettyPrinter

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);
}
Also used : PrettyPrinter(org.spongepowered.asm.util.PrettyPrinter)

Aggregations

PrettyPrinter (org.spongepowered.asm.util.PrettyPrinter)27 Map (java.util.Map)9 Collection (java.util.Collection)7 ReportedException (net.minecraft.util.ReportedException)7 CauseStackManager (org.spongepowered.api.event.CauseStackManager)7 UUID (java.util.UUID)6 Entity (org.spongepowered.api.entity.Entity)6 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 SpawnEntityEvent (org.spongepowered.api.event.entity.SpawnEntityEvent)5 DropItemEvent (org.spongepowered.api.event.item.inventory.DropItemEvent)5 ItemDropData (org.spongepowered.common.event.tracking.context.ItemDropData)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 EntityItem (net.minecraft.entity.item.EntityItem)4 Sponge (org.spongepowered.api.Sponge)4 World (org.spongepowered.api.world.World)4 SpongeImpl (org.spongepowered.common.SpongeImpl)4 IOException (java.io.IOException)3 Collectors (java.util.stream.Collectors)3 Nullable (javax.annotation.Nullable)3