use of org.spongepowered.asm.util.PrettyPrinter in project SpongeCommon by SpongePowered.
the class PhaseTracker method printRunnawayPhaseCompletion.
private void printRunnawayPhaseCompletion(IPhaseState<?> state) {
if (!SpongeImpl.getGlobalConfig().getConfig().getPhaseTracker().isVerbose() && !this.hasPrintedAboutRunnawayPhases) {
// Avoiding spam logs.
return;
}
final PrettyPrinter printer = new PrettyPrinter(60);
printer.add("Completing Phase").centre().hr();
printer.addWrapped(60, "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.addWrapped(60, "%s : %s", "Completing phase", state);
printer.add(" Phases Remaining:");
this.stack.forEach(data -> PHASE_PRINTER.accept(printer, data));
printer.add();
printer.add("Stacktrace:");
printer.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++ > 3) {
this.hasPrintedAboutRunnawayPhases = true;
}
}
use of org.spongepowered.asm.util.PrettyPrinter in project SpongeCommon by SpongePowered.
the class DeathUpdateState method unwind.
@Override
public void unwind(BasicEntityContext context) {
final Entity dyingEntity = context.getSource(Entity.class).orElseThrow(TrackingUtil.throwWithContext("Dying entity not found!", context));
context.getCapturedItemsSupplier().acceptAndClearIfNotEmpty(items -> {
final DamageSource damageSource = context.getDamageSource();
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().pushCause(dyingEntity);
Sponge.getCauseStackManager().pushCause(damageSource);
Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.DROPPED_ITEM);
final ArrayList<Entity> entities = new ArrayList<>();
for (EntityItem item : items) {
entities.add(EntityUtil.fromNative(item));
}
final DropItemEvent.Destruct destruct = SpongeEventFactory.createDropItemEventDestruct(Sponge.getCauseStackManager().getCurrentCause(), entities);
SpongeImpl.postEvent(destruct);
if (!destruct.isCancelled()) {
for (Entity entity : destruct.getEntities()) {
EntityUtil.getMixinWorld(entity).forceSpawnEntity(entity);
}
}
}
});
context.getCapturedEntitySupplier().acceptAndClearIfNotEmpty(entities -> {
final List<Entity> experience = entities.stream().filter(entity -> entity instanceof ExperienceOrb).collect(Collectors.toList());
if (!experience.isEmpty()) {
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().pushCause(dyingEntity);
Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.EXPERIENCE);
final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), experience);
SpongeImpl.postEvent(event);
if (!event.isCancelled()) {
for (Entity entity : event.getEntities()) {
EntityUtil.getMixinWorld(entity).forceSpawnEntity(entity);
}
}
}
}
final List<Entity> other = entities.stream().filter(entity -> !(entity instanceof ExperienceOrb)).collect(Collectors.toList());
if (!other.isEmpty()) {
try (StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().pushCause(dyingEntity);
Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.ENTITY_DEATH);
final SpawnEntityEvent event1 = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), other);
SpongeImpl.postEvent(event1);
if (!event1.isCancelled()) {
for (Entity entity : event1.getEntities()) {
EntityUtil.getMixinWorld(entity).forceSpawnEntity(entity);
}
}
}
}
});
context.getCapturedEntityDropSupplier().acceptIfNotEmpty(map -> {
if (map.isEmpty()) {
return;
}
final PrettyPrinter printer = new PrettyPrinter(80);
printer.add("Processing Entity Death Updates Spawning").centre().hr();
printer.add("Entity Dying: " + dyingEntity);
printer.add("The item stacks captured are: ");
for (Map.Entry<UUID, Collection<ItemDropData>> entry : map.asMap().entrySet()) {
printer.add(" - Entity with UUID: %s", entry.getKey());
for (ItemDropData stack : entry.getValue()) {
printer.add(" - %s", stack);
}
}
printer.trace(System.err);
});
context.getCapturedBlockSupplier().acceptAndClearIfNotEmpty(blocks -> TrackingUtil.processBlockCaptures(blocks, this, context));
}
use of org.spongepowered.asm.util.PrettyPrinter in project SpongeCommon by SpongePowered.
the class AttackEntityPacketState method unwind.
@Override
public void unwind(BasicPacketContext context) {
final EntityPlayerMP player = context.getPacketPlayer();
final CPacketUseEntity useEntityPacket = context.getPacket();
final net.minecraft.entity.Entity entity = useEntityPacket.getEntityFromWorld(player.world);
if (entity == null) {
// Something happened?
return;
}
final World spongeWorld = EntityUtil.getSpongeWorld(player);
EntityUtil.toMixin(entity).setNotifier(player.getUniqueID());
context.getCapturedItemsSupplier().acceptAndClearIfNotEmpty(items -> {
// For destruction, this should be empty, however, some
// times,
// it may not be?
final PrettyPrinter printer = new PrettyPrinter(60);
printer.add("Processing Attack Entity").centre().hr();
printer.add("There are some captured items after the entity was destructed!");
printer.addWrapped(60, "%s : %s", "Items captured", items);
printer.add("Stacktrace:");
printer.add(new Exception("Stack trace"));
printer.trace(System.err, SpongeImpl.getLogger(), Level.TRACE);
});
context.getCapturedBlockSupplier().acceptAndClearIfNotEmpty(blocks -> TrackingUtil.processBlockCaptures(blocks, this, context));
context.getCapturedEntityDropSupplier().acceptIfNotEmpty(map -> {
for (Map.Entry<UUID, Collection<ItemDropData>> entry : map.asMap().entrySet()) {
final UUID key = entry.getKey();
final Optional<Entity> affectedEntity = spongeWorld.getEntity(key);
if (!affectedEntity.isPresent()) {
continue;
}
final Collection<ItemDropData> itemStacks = entry.getValue();
if (itemStacks.isEmpty()) {
return;
}
final List<ItemDropData> items = new ArrayList<>(itemStacks);
if (!items.isEmpty()) {
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
final List<Entity> itemEntities = items.stream().map(data -> data.create(((WorldServer) player.world))).map(EntityUtil::fromNative).collect(Collectors.toList());
Sponge.getCauseStackManager().pushCause(player);
Sponge.getCauseStackManager().pushCause(affectedEntity.get());
Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.DROPPED_ITEM);
final DropItemEvent.Destruct destruct = SpongeEventFactory.createDropItemEventDestruct(Sponge.getCauseStackManager().getCurrentCause(), itemEntities);
SpongeImpl.postEvent(destruct);
if (!destruct.isCancelled()) {
processSpawnedEntities(player, destruct);
}
}
}
}
});
context.getCapturedEntityItemDropSupplier().acceptIfNotEmpty(map -> {
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().pushCause(player);
Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.DROPPED_ITEM);
for (Map.Entry<UUID, Collection<EntityItem>> entry : map.asMap().entrySet()) {
final UUID key = entry.getKey();
final Optional<Entity> attackedEntities = spongeWorld.getEntity(key);
if (!attackedEntities.isPresent()) {
continue;
}
final List<Entity> items = entry.getValue().stream().map(EntityUtil::fromNative).collect(Collectors.toList());
final DropItemEvent.Destruct destruct = SpongeEventFactory.createDropItemEventDestruct(Sponge.getCauseStackManager().getCurrentCause(), items);
SpongeImpl.postEvent(destruct);
if (!destruct.isCancelled()) {
processSpawnedEntities(player, destruct);
}
}
}
});
}
use of org.spongepowered.asm.util.PrettyPrinter in project SpongeCommon by SpongePowered.
the class InteractAtEntityPacketState method unwind.
@Override
public void unwind(BasicPacketContext context) {
final EntityPlayerMP player = context.getPacketPlayer();
final CPacketUseEntity useEntityPacket = context.getPacket();
final net.minecraft.entity.Entity entity = useEntityPacket.getEntityFromWorld(player.world);
if (entity == null) {
// Something happened?
return;
}
final World spongeWorld = EntityUtil.getSpongeWorld(player);
EntityUtil.toMixin(entity).setNotifier(player.getUniqueID());
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().pushCause(player);
Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.PLACEMENT);
context.getCapturedEntitySupplier().acceptAndClearIfNotEmpty(entities -> {
SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), entities);
SpongeImpl.postEvent(event);
if (!event.isCancelled()) {
processSpawnedEntities(player, event);
}
});
context.getCapturedItemsSupplier().acceptAndClearIfNotEmpty(entities -> {
final List<Entity> items = entities.stream().map(EntityUtil::fromNative).collect(Collectors.toList());
SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), items);
SpongeImpl.postEvent(event);
if (!event.isCancelled()) {
processSpawnedEntities(player, event);
}
});
context.getCapturedEntityDropSupplier().acceptIfNotEmpty(map -> {
final PrettyPrinter printer = new PrettyPrinter(80);
printer.add("Processing Interact At Entity").centre().hr();
printer.add("The item stacks captured are: ");
for (Map.Entry<UUID, Collection<ItemDropData>> entry : map.asMap().entrySet()) {
printer.add(" - Entity with UUID: %s", entry.getKey());
for (ItemDropData stack : entry.getValue()) {
printer.add(" - %s", stack);
}
}
printer.trace(System.err);
});
context.getCapturedEntityItemDropSupplier().acceptIfNotEmpty(map -> {
for (Map.Entry<UUID, Collection<EntityItem>> entry : map.asMap().entrySet()) {
final UUID entityUuid = entry.getKey();
final net.minecraft.entity.Entity entityFromUuid = player.getServerWorld().getEntityFromUuid(entityUuid);
if (entityFromUuid != null) {
final List<Entity> entities = entry.getValue().stream().map(EntityUtil::fromNative).collect(Collectors.toList());
if (!entities.isEmpty()) {
DropItemEvent.Custom event = SpongeEventFactory.createDropItemEventCustom(Sponge.getCauseStackManager().getCurrentCause(), entities);
SpongeImpl.postEvent(event);
if (!event.isCancelled()) {
processSpawnedEntities(player, event);
}
}
}
}
});
context.getCapturedItemStackSupplier().acceptAndClearIfNotEmpty(drops -> {
final List<EntityItem> items = drops.stream().map(drop -> drop.create(player.getServerWorld())).collect(Collectors.toList());
final List<Entity> entities = items.stream().map(EntityUtil::fromNative).collect(Collectors.toList());
if (!entities.isEmpty()) {
DropItemEvent.Custom event = SpongeEventFactory.createDropItemEventCustom(Sponge.getCauseStackManager().getCurrentCause(), entities);
SpongeImpl.postEvent(event);
if (!event.isCancelled()) {
processSpawnedEntities(player, event);
}
}
});
}
context.getCapturedBlockSupplier().acceptAndClearIfNotEmpty(snapshots -> TrackingUtil.processBlockCaptures(snapshots, this, context));
}
use of org.spongepowered.asm.util.PrettyPrinter in project SpongeCommon by SpongePowered.
the class InteractionPacketState method unwind.
@Override
public void unwind(BasicPacketContext phaseContext) {
final EntityPlayerMP player = phaseContext.getPacketPlayer();
final ItemStack usedStack = phaseContext.getItemUsed();
final ItemStackSnapshot usedSnapshot = ItemStackUtil.snapshotOf(usedStack);
final Entity spongePlayer = EntityUtil.fromNative(player);
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().pushCause(spongePlayer);
Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.DROPPED_ITEM);
final boolean hasBlocks = !phaseContext.getCapturedBlockSupplier().isEmpty();
final List<BlockSnapshot> capturedBlcoks = phaseContext.getCapturedBlocks();
@Nullable final BlockSnapshot firstBlockChange = hasBlocks ? capturedBlcoks.get(0) : null;
if (hasBlocks) {
if (!TrackingUtil.processBlockCaptures(capturedBlcoks, this, phaseContext)) {
// Stop entities like XP from being spawned
return;
}
} else {
phaseContext.getBlockItemDropSupplier().acceptIfNotEmpty(map -> {
if (ShouldFire.DROP_ITEM_EVENT_DESTRUCT) {
for (BlockSnapshot blockChange : capturedBlcoks) {
final Location<World> location = blockChange.getLocation().get();
final Vector3d position = location.getPosition();
final BlockPos blockPos = VecHelper.toBlockPos(position);
final Collection<EntityItem> entityItems = map.get(blockPos);
if (!entityItems.isEmpty()) {
final List<Entity> items = entityItems.stream().map(EntityUtil::fromNative).collect(Collectors.toList());
final DropItemEvent.Destruct event = SpongeEventFactory.createDropItemEventDestruct(Sponge.getCauseStackManager().getCurrentCause(), items);
SpongeImpl.postEvent(event);
if (!event.isCancelled()) {
processSpawnedEntities(player, event);
}
}
}
} else {
for (BlockSnapshot blockChange : capturedBlcoks) {
final Location<World> location = blockChange.getLocation().get();
final Vector3d position = location.getPosition();
final BlockPos blockPos = VecHelper.toBlockPos(position);
final Collection<EntityItem> entityItems = map.get(blockPos);
if (!entityItems.isEmpty()) {
processEntities(player, (Collection<Entity>) (Collection<?>) entityItems);
}
}
}
});
}
phaseContext.getCapturedItemsSupplier().acceptAndClearIfNotEmpty(items -> {
final ArrayList<Entity> entities = new ArrayList<>();
for (EntityItem item : items) {
entities.add(EntityUtil.fromNative(item));
}
final DropItemEvent.Dispense dispense = SpongeEventFactory.createDropItemEventDispense(Sponge.getCauseStackManager().getCurrentCause(), entities);
SpongeImpl.postEvent(dispense);
if (!dispense.isCancelled()) {
processSpawnedEntities(player, dispense);
}
});
phaseContext.getCapturedEntityDropSupplier().acceptIfNotEmpty(map -> {
if (map.isEmpty()) {
return;
}
final PrettyPrinter printer = new PrettyPrinter(80);
printer.add("Processing Interaction").centre().hr();
printer.add("The item stacks captured are: ");
for (Map.Entry<UUID, Collection<ItemDropData>> entry : map.asMap().entrySet()) {
printer.add(" - Entity with UUID: %s", entry.getKey());
for (ItemDropData stack : entry.getValue()) {
printer.add(" - %s", stack);
}
}
printer.trace(System.err);
});
phaseContext.getCapturedEntitySupplier().acceptAndClearIfNotEmpty(entities -> {
final List<Entity> projectiles = new ArrayList<>(entities.size());
final List<Entity> spawnEggs = new ArrayList<>(entities.size());
final List<Entity> xpOrbs = new ArrayList<>(entities.size());
final List<Entity> normalPlacement = new ArrayList<>(entities.size());
final List<Entity> items = new ArrayList<>(entities.size());
for (Entity entity : entities) {
if (entity instanceof Projectile || entity instanceof EntityThrowable) {
projectiles.add(entity);
} else if (usedSnapshot.getType() == ItemTypes.SPAWN_EGG) {
spawnEggs.add(entity);
} else if (entity instanceof EntityItem) {
items.add(entity);
} else if (entity instanceof EntityXPOrb) {
xpOrbs.add(entity);
} else {
normalPlacement.add(entity);
}
}
if (!projectiles.isEmpty()) {
if (ShouldFire.SPAWN_ENTITY_EVENT) {
try (CauseStackManager.StackFrame frame2 = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.PROJECTILE);
Sponge.getCauseStackManager().pushCause(usedSnapshot);
final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), projectiles);
if (!SpongeImpl.postEvent(event)) {
processSpawnedEntities(player, event);
}
}
} else {
processEntities(player, projectiles);
}
}
if (!spawnEggs.isEmpty()) {
if (ShouldFire.SPAWN_ENTITY_EVENT) {
try (CauseStackManager.StackFrame frame2 = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.PROJECTILE);
Sponge.getCauseStackManager().pushCause(usedSnapshot);
final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), spawnEggs);
if (!SpongeImpl.postEvent(event)) {
processSpawnedEntities(player, event);
}
}
} else {
processEntities(player, spawnEggs);
}
}
if (!items.isEmpty()) {
if (ShouldFire.DROP_ITEM_EVENT_DISPENSE) {
final DropItemEvent.Dispense dispense = SpongeEventFactory.createDropItemEventDispense(Sponge.getCauseStackManager().getCurrentCause(), items);
if (!SpongeImpl.postEvent(dispense)) {
processSpawnedEntities(player, dispense);
}
} else {
processEntities(player, items);
}
}
if (!xpOrbs.isEmpty()) {
if (ShouldFire.SPAWN_ENTITY_EVENT) {
try (final CauseStackManager.StackFrame stackFrame = Sponge.getCauseStackManager().pushCauseFrame()) {
if (firstBlockChange != null) {
stackFrame.pushCause(firstBlockChange);
}
stackFrame.addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.EXPERIENCE);
final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), xpOrbs);
if (!SpongeImpl.postEvent(event)) {
processSpawnedEntities(player, event);
}
}
} else {
processEntities(player, xpOrbs);
}
}
if (!normalPlacement.isEmpty()) {
if (ShouldFire.SPAWN_ENTITY_EVENT) {
try (final CauseStackManager.StackFrame stackFrame = Sponge.getCauseStackManager().pushCauseFrame()) {
if (firstBlockChange != null) {
stackFrame.pushCause(firstBlockChange);
}
final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), normalPlacement);
if (!SpongeImpl.postEvent(event)) {
processSpawnedEntities(player, event);
}
}
} else {
processEntities(player, normalPlacement);
}
}
});
final IMixinContainer mixinContainer = ContainerUtil.toMixin(player.openContainer);
mixinContainer.setCaptureInventory(false);
mixinContainer.getCapturedTransactions().clear();
}
}
Aggregations