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