Search in sources :

Example 11 with Timing

use of co.aikar.timings.Timing in project DragonProxy by DragonetMC.

the class UpstreamSession method sendPacket.

// if sending a packer before spawn, you should set high_priority to true !
public void sendPacket(PEPacket packet, boolean high_priority) {
    if (packet == null)
        return;
    if (!proxy.getConfig().disable_packet_events) {
        PackettoPlayerEvent packetEvent = new PackettoPlayerEvent(this, packet);
        proxy.getEventManager().callEvent(packetEvent);
        packet = packetEvent.getPacket();
    }
    // cache in case of not spawned and no high priority
    if (!spawned && !high_priority) {
        putCachePacket(packet);
        return;
    }
    while (!cachedPackets.isEmpty()) // TODO sendAllPackets
    sendPacket(cachedPackets.poll(), true);
    try (Timing timing = Timings.getSendDataPacketTiming(packet)) {
        packet.encode();
        byte[] buffer;
        try {
            buffer = Zlib.deflate(Binary.appendBytes(Binary.writeUnsignedVarInt(packet.getBuffer().length), packet.getBuffer()), Deflater.BEST_COMPRESSION);
        } catch (Exception e) {
            timing.stopTiming();
            e.printStackTrace();
            return;
        }
        raknetClient.sendMessage(Reliability.RELIABLE_ORDERED, 0, new com.whirvis.jraknet.Packet(Binary.appendBytes((byte) 0xfe, buffer)));
    }
}
Also used : PackettoPlayerEvent(org.dragonet.proxy.events.defaults.packets.PackettoPlayerEvent) Timing(co.aikar.timings.Timing) RequestException(com.github.steveice10.mc.auth.exception.request.RequestException)

Example 12 with Timing

use of co.aikar.timings.Timing in project SpongeCommon by SpongePowered.

the class TrackingUtil method tickTileEntity.

@SuppressWarnings({ "unused", "try" })
public static void tickTileEntity(final TrackedWorldBridge mixinWorldServer, final TickableBlockEntity tile) {
    checkArgument(tile instanceof BlockEntity, "ITickable %s is not a TileEntity!", tile);
    checkNotNull(tile, "Cannot capture on a null ticking tile entity!");
    final net.minecraft.world.level.block.entity.BlockEntity tileEntity = (net.minecraft.world.level.block.entity.BlockEntity) tile;
    final BlockEntityBridge mixinTileEntity = (BlockEntityBridge) tile;
    final BlockPos pos = tileEntity.getBlockPos();
    final LevelChunkBridge chunk = ((ActiveChunkReferantBridge) tile).bridge$getActiveChunk();
    if (!((TrackableBridge) tileEntity).bridge$shouldTick()) {
        return;
    }
    if (chunk == null) {
        ((ActiveChunkReferantBridge) tile).bridge$setActiveChunk((TrackedLevelChunkBridge) tileEntity.getLevel().getChunkAt(tileEntity.getBlockPos()));
    }
    final TileEntityTickContext context = TickPhase.Tick.TILE_ENTITY.createPhaseContext(PhaseTracker.SERVER).source(mixinTileEntity);
    try (final PhaseContext<?> phaseContext = context) {
        if (tile instanceof CreatorTrackedBridge) {
            // Add notifier and owner so we don't have to perform lookups during the phases and other processing
            ((CreatorTrackedBridge) tile).tracker$getNotifierUUID().ifPresent(phaseContext::notifier);
            // Allow the tile entity to validate the owner of itself. As long as the tile entity
            // chunk is already loaded and activated, and the tile entity has already loaded
            // the owner of itself.
            ((CreatorTrackedBridge) tile).tracker$getCreatorUUID().ifPresent(phaseContext::creator);
        }
        // Finally, switch the context now that we have the owner and notifier
        phaseContext.buildAndSwitch();
        try (final Timing timing = ((TimingBridge) tileEntity.getType()).bridge$timings().startTiming()) {
            tile.tick();
        }
        // otherwise the viewing players update this during their ticking
        if (tileEntity instanceof ViewableInventoryBridge) {
            final Set<ServerPlayer> players = ((ViewableInventoryBridge) tileEntity).viewableBridge$getViewers();
            if (players.size() > 0) {
                players.forEach(player -> player.containerMenu.broadcastChanges());
            }
        }
    } catch (final Exception e) {
        PhasePrinter.printExceptionFromPhase(PhaseTracker.getInstance().stack, e, context);
    }
    // We delay clearing active chunk if TE is invalidated during tick so we must remove it after
    if (tileEntity.isRemoved()) {
        ((ActiveChunkReferantBridge) tileEntity).bridge$setActiveChunk(null);
    }
}
Also used : CreatorTrackedBridge(org.spongepowered.common.bridge.CreatorTrackedBridge) BlockEntityBridge(org.spongepowered.common.bridge.world.level.block.entity.BlockEntityBridge) ActiveChunkReferantBridge(org.spongepowered.common.bridge.world.level.chunk.ActiveChunkReferantBridge) ViewableInventoryBridge(org.spongepowered.common.bridge.world.inventory.ViewableInventoryBridge) ServerPlayer(net.minecraft.server.level.ServerPlayer) BlockPos(net.minecraft.core.BlockPos) LevelChunkBridge(org.spongepowered.common.bridge.world.level.chunk.LevelChunkBridge) TrackedLevelChunkBridge(org.spongepowered.common.bridge.world.level.chunk.TrackedLevelChunkBridge) Timing(co.aikar.timings.Timing) TileEntityTickContext(org.spongepowered.common.event.tracking.phase.tick.TileEntityTickContext) TickableBlockEntity(net.minecraft.world.level.block.entity.TickableBlockEntity) BlockEntity(org.spongepowered.api.block.entity.BlockEntity)

Example 13 with Timing

use of co.aikar.timings.Timing in project SpongeCommon by SpongePowered.

the class TrackingUtil method updateTickBlock.

@SuppressWarnings("rawtypes")
public static void updateTickBlock(final TrackedWorldBridge mixinWorld, final net.minecraft.world.level.block.state.BlockState block, final BlockPos pos, final Random random) {
    final ServerLevel world = (ServerLevel) mixinWorld;
    final org.spongepowered.api.world.server.ServerWorld apiWorld = (org.spongepowered.api.world.server.ServerWorld) world;
    if (ShouldFire.TICK_BLOCK_EVENT) {
        final BlockSnapshot snapshot = mixinWorld.bridge$createSnapshot(block, pos, BlockChangeFlags.NONE);
        final TickBlockEvent event = SpongeEventFactory.createTickBlockEventScheduled(PhaseTracker.getCauseStackManager().currentCause(), snapshot);
        SpongeCommon.post(event);
        if (event.isCancelled()) {
            return;
        }
    }
    final LocatableBlock locatable = new SpongeLocatableBlockBuilder().world(apiWorld).position(pos.getX(), pos.getY(), pos.getZ()).state((BlockState) block).build();
    final BlockTickContext phaseContext = TickPhase.Tick.BLOCK.createPhaseContext(PhaseTracker.SERVER).source(locatable);
    // We have to associate any notifiers in case of scheduled block updates from other sources
    final PhaseContext<@NonNull ?> currentContext = PhaseTracker.getInstance().getPhaseContext();
    currentContext.appendNotifierPreBlockTick(world, pos, phaseContext);
    try (final PhaseContext<@NonNull ?> context = phaseContext;
        final Timing timing = ((TimingBridge) block.getBlock()).bridge$timings()) {
        timing.startTiming();
        context.buildAndSwitch();
        PhaseTracker.LOGGER.trace(TrackingUtil.BLOCK_TICK, () -> "Wrapping Block Tick: " + block.toString());
        block.tick(world, pos, random);
    } catch (final Exception | NoClassDefFoundError e) {
        PhasePrinter.printExceptionFromPhase(PhaseTracker.getInstance().stack, e, phaseContext);
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) SpongeLocatableBlockBuilder(org.spongepowered.common.world.server.SpongeLocatableBlockBuilder) SpongeBlockSnapshot(org.spongepowered.common.block.SpongeBlockSnapshot) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) TickBlockEvent(org.spongepowered.api.event.block.TickBlockEvent) BlockState(org.spongepowered.api.block.BlockState) BlockTickContext(org.spongepowered.common.event.tracking.phase.tick.BlockTickContext) LocatableBlock(org.spongepowered.api.world.LocatableBlock) Timing(co.aikar.timings.Timing) TimingBridge(org.spongepowered.common.bridge.TimingBridge)

Example 14 with Timing

use of co.aikar.timings.Timing in project DragonProxy by DragonetMC.

the class PEPacketProcessor method onTick.

public void onTick() {
    int cnt = 0;
    Timings.playerNetworkReceiveTimer.startTiming();
    while (cnt < MAX_PACKETS_PER_CYCLE && !packets.isEmpty()) {
        cnt++;
        byte[] p = packets.pop();
        PEPacket[] packets;
        try {
            packets = Protocol.decode(p);
            if (packets == null || packets.length <= 0)
                continue;
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }
        for (PEPacket decoded : packets) try (Timing timing = Timings.getReceiveDataPacketTiming(decoded)) {
            handlePacket(decoded);
        }
    }
    Timings.playerNetworkReceiveTimer.stopTiming();
}
Also used : PEPacket(org.dragonet.protocol.PEPacket) Timing(co.aikar.timings.Timing) JsonParseException(com.google.gson.JsonParseException)

Example 15 with Timing

use of co.aikar.timings.Timing in project DragonProxy by DragonetMC.

the class CommandRegister method callCommand.

public void callCommand(String cmd) {
    String trimedCmd = cmd.trim();
    String label = null;
    String[] args = null;
    if (!cmd.trim().contains(" ")) {
        label = trimedCmd.toLowerCase();
        args = new String[0];
    } else {
        label = trimedCmd.substring(0, trimedCmd.indexOf(" ")).toLowerCase();
        String argLine = trimedCmd.substring(trimedCmd.indexOf(" ") + 1);
        args = argLine.contains(" ") ? argLine.split(" ") : new String[] { argLine };
    }
    if (label == null) {
        proxy.getLogger().warning(proxy.getLang().get(Lang.COMMAND_NOT_FOUND));
        return;
    }
    Command command = commandMap.get(label);
    if (command == null) {
        proxy.getLogger().warning(proxy.getLang().get(Lang.COMMAND_NOT_FOUND));
        return;
    }
    try (Timing timing = Timings.getCommandTiming(command)) {
        command.execute(proxy, args);
    }
}
Also used : Timing(co.aikar.timings.Timing)

Aggregations

Timing (co.aikar.timings.Timing)22 TileEntityTickContext (org.spongepowered.common.event.tracking.phase.tick.TileEntityTickContext)6 TimingBridge (org.spongepowered.common.bridge.TimingBridge)5 DataPacketSendEvent (cn.nukkit.event.server.DataPacketSendEvent)4 Entity (org.spongepowered.api.entity.Entity)4 EntityTickContext (org.spongepowered.common.event.tracking.phase.tick.EntityTickContext)4 BlockPos (net.minecraft.util.math.BlockPos)3 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)3 StackFrame (org.spongepowered.api.event.CauseStackManager.StackFrame)3 IMixinTileEntity (org.spongepowered.common.interfaces.block.tile.IMixinTileEntity)3 TickableBlockEntity (net.minecraft.world.level.block.entity.TickableBlockEntity)2 BlockEntity (org.spongepowered.api.block.entity.BlockEntity)2 User (org.spongepowered.api.entity.living.player.User)2 Redirect (org.spongepowered.asm.mixin.injection.Redirect)2 CreatorTrackedBridge (org.spongepowered.common.bridge.CreatorTrackedBridge)2 IMixinChunk (org.spongepowered.common.interfaces.IMixinChunk)2 IMixinEntity (org.spongepowered.common.interfaces.entity.IMixinEntity)2 Type (cn.nukkit.AdventureSettings.Type)1 cn.nukkit.block (cn.nukkit.block)1 BlockEntity (cn.nukkit.blockentity.BlockEntity)1