Search in sources :

Example 21 with PrettyPrinter

use of org.spongepowered.common.util.PrettyPrinter in project SpongeCommon by SpongePowered.

the class PhasePrinter method printBlockTrackingException.

static void printBlockTrackingException(final PhaseTracker tracker, final PhaseContext<@NonNull ?> phaseData, final IPhaseState<@NonNull ?> phaseState, final Throwable e) {
    if (!SpongeConfigs.getCommon().get().phaseTracker.verbose && !PhasePrinter.printedExceptionsForBlocks.isEmpty()) {
        if (PhasePrinter.printedExceptionsForBlocks.contains(phaseState)) {
            return;
        }
    }
    final PrettyPrinter printer = new PrettyPrinter(60).add("Exception attempting to capture a block change!").centre().hr();
    PhasePrinter.printPhasestack(tracker, phaseData, e, printer);
    if (PhasePrinter.IN_DEVELOPMENT) {
        printer.print(System.err);
    } else {
        printer.log(SpongeCommon.logger(), Level.ERROR);
    }
    if (!SpongeConfigs.getCommon().get().phaseTracker.verbose) {
        PhasePrinter.printedExceptionsForBlocks.add(phaseState);
    }
}
Also used : PrettyPrinter(org.spongepowered.common.util.PrettyPrinter)

Example 22 with PrettyPrinter

use of org.spongepowered.common.util.PrettyPrinter in project SpongeCommon by SpongePowered.

the class PhasePrinter method printRunAwayPhaseCompletion.

static void printRunAwayPhaseCompletion(final PhaseStack stack, final IPhaseState<@NonNull ?> state) {
    if (!SpongeConfigs.getCommon().get().phaseTracker.verbose && !PhasePrinter.hasPrintedAboutRunnawayPhases) {
        // Avoiding spam logs.
        return;
    }
    final PrettyPrinter printer = new PrettyPrinter(60);
    printer.add("Completing Phase").centre().hr();
    printer.add("Detecting a runaway phase! Potentially a problem " + "where something isn't completing a phase!!! Sponge will stop printing" + "after three more times to avoid generating extra logs");
    printer.add();
    printer.add("%s : %s", "Completing phase", state);
    printer.add(" Phases Remaining:");
    PhasePrinter.printPhaseStackWithException(stack, printer, new Exception("RunawayPhase"));
    if (PhasePrinter.IN_DEVELOPMENT) {
        printer.print(System.err);
    } else {
        printer.log(SpongeCommon.logger(), Level.ERROR);
    }
    if (!SpongeConfigs.getCommon().get().phaseTracker.verbose && PhasePrinter.printRunawayCount++ > 3) {
        PhasePrinter.hasPrintedAboutRunnawayPhases = true;
    }
}
Also used : PrettyPrinter(org.spongepowered.common.util.PrettyPrinter)

Example 23 with PrettyPrinter

use of org.spongepowered.common.util.PrettyPrinter in project SpongeCommon by SpongePowered.

the class PhasePrinter method printNullSourceBlockNeighborNotificationWithNoTileSource.

static void printNullSourceBlockNeighborNotificationWithNoTileSource(final BlockPos pos, final Block blockIn, final BlockPos otherPos, final NullPointerException e) {
    final PhaseTracker instance = PhaseTracker.getInstance();
    final PrettyPrinter printer = new PrettyPrinter(60).add("Null Source Block on TileEntity!").centre().hr().addWrapped("Hey, Sponge is saving the game from crashing because a TileEntity " + "is sending out a 'null' Block as it's source (more likely) and " + "attempting to perform a neighbor notification with it. Because " + "this is guaranteed to lead to a crash or a spam of reports, " + "Sponge is going ahead and fixing the issue. The offending Tile " + "is unknown, so we don't have any way to configure a reporting for you").add().add("%s : %s", "Source position", pos).add("%s : %s", "Source TileEntity", "UNKNOWN").add("%s : %s", "Recovered using TileEntity as Source", "false").add("%s : %s", "Source Block Recovered", blockIn).add("%s : %s", "Notified Position", otherPos);
    PhasePrinter.printPhaseStackWithException(instance.stack, printer, e);
    printer.log(SpongeCommon.logger(), Level.WARN);
}
Also used : PrettyPrinter(org.spongepowered.common.util.PrettyPrinter)

Example 24 with PrettyPrinter

use of org.spongepowered.common.util.PrettyPrinter in project SpongeCommon by SpongePowered.

the class PhasePrinter method printAsyncEntitySpawn.

static void printAsyncEntitySpawn(final Entity entity) {
    // We will DEFINITELY be doing bad things otherwise. We need to artificially capture here.
    if (!SpongeConfigs.getCommon().get().phaseTracker.captureAsyncSpawningEntities) {
        // Print a pretty warning about not capturing an async spawned entity, but don't care about spawning.
        if (!SpongeConfigs.getCommon().get().phaseTracker.verbose) {
            return;
        }
        // If we have, we don't want to print any more times.
        if (!SpongeConfigs.getCommon().get().phaseTracker.verboseErrors && PhasePrinter.hasPrintedAsyncEntities) {
            return;
        }
        // Otherwise, let's print out either the first time, or several more times.
        final PrettyPrinter printer = new PrettyPrinter(60).add("Async Entity Spawn Warning").centre().hr().add("An entity was attempting to spawn off the \"main\" server thread").add().add("Details of the spawning are disabled according to the Sponge").add("configuration file. A stack trace of the attempted spawn should").add("provide information about how it was being spawned. Sponge is").add("currently configured to NOT attempt to capture this spawn and").add("spawn the entity at an appropriate time, while on the main server").add("thread.").add().add("Details of the spawn:").add("%s : %s", "Entity", entity).add("Stacktrace").add(new Exception("Async entity spawn attempt"));
        if (PhasePrinter.IN_DEVELOPMENT) {
            printer.print(System.err);
        } else {
            printer.log(SpongeCommon.logger(), Level.ERROR);
        }
        PhasePrinter.hasPrintedAsyncEntities = true;
        return;
    }
    PhaseTracker.ASYNC_CAPTURED_ENTITIES.add((net.minecraft.world.entity.Entity) entity);
    // Print a pretty warning about not capturing an async spawned entity, but don't care about spawning.
    if (!SpongeConfigs.getCommon().get().phaseTracker.verbose) {
        return;
    }
    // If we have, we don't want to print any more times.
    if (!SpongeConfigs.getCommon().get().phaseTracker.verboseErrors && PhasePrinter.hasPrintedAsyncEntities) {
        return;
    }
    // Otherwise, let's print out either the first time, or several more times.
    final PrettyPrinter printer = new PrettyPrinter(60).add("Async Entity Spawn Warning").centre().hr().add("An entity was attempting to spawn off the \"main\" server thread").add().add("Delayed spawning is ENABLED for Sponge.").add("The entity is safely captured by Sponge while off the main").add("server thread, and therefore will be spawned the next tick.").add("Some cases where a mod is expecting the entity back while").add("async can cause issues with said mod.").add().add("Details of the spawn:").add("%s : %s", "Entity", entity).add("Stacktrace").add(new Exception("Async entity spawn attempt"));
    if (PhasePrinter.IN_DEVELOPMENT) {
        printer.print(System.err);
    } else {
        printer.log(SpongeCommon.logger(), Level.ERROR);
    }
    PhasePrinter.hasPrintedAsyncEntities = true;
}
Also used : PrettyPrinter(org.spongepowered.common.util.PrettyPrinter)

Example 25 with PrettyPrinter

use of org.spongepowered.common.util.PrettyPrinter in project SpongeCommon by SpongePowered.

the class SpongeGameProfileManager method close.

public void close() {
    // Shut down the executor
    this.gameLookupExecutorService.shutdown();
    try {
        if (!this.gameLookupExecutorService.awaitTermination(5, TimeUnit.SECONDS)) {
            final List<Runnable> remaining = this.gameLookupExecutorService.shutdownNow();
            new PrettyPrinter().add("Sponge game profile resolver failed to shut down in 5 seconds!").add("Remaining tasks:").addWithIndices(remaining).add("These tasks have been cancelled.").log(SpongeGameProfileManager.LOGGER, Level.WARN);
        }
    } catch (final InterruptedException e) {
        SpongeGameProfileManager.LOGGER.error("The async scheduler was interrupted while awaiting shutdown!");
    }
}
Also used : PrettyPrinter(org.spongepowered.common.util.PrettyPrinter)

Aggregations

PrettyPrinter (org.spongepowered.common.util.PrettyPrinter)28 Nullable (org.checkerframework.checker.nullness.qual.Nullable)5 Map (java.util.Map)4 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Collectors (java.util.stream.Collectors)3 ServerLevel (net.minecraft.server.level.ServerLevel)3 Level (org.apache.logging.log4j.Level)3 PluginContainer (org.spongepowered.plugin.PluginContainer)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 IdentityHashMap (java.util.IdentityHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Player (net.minecraft.world.entity.player.Player)2 NonNull (org.checkerframework.checker.nullness.qual.NonNull)2