co.aikar.timings.Timing Java Examples

The following examples show how to use co.aikar.timings.Timing. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Player.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public boolean batchDataPacket(DataPacket packet) {
    if (!this.connected) {
        return false;
    }

    try (Timing timing = Timings.getSendDataPacketTiming(packet)) {
        DataPacketSendEvent event = new DataPacketSendEvent(this, packet);
        this.server.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return false;
        }

        if (!this.batchedPackets.containsKey(packet.getChannel())) {
            this.batchedPackets.put(packet.getChannel(), new ArrayList<>());
        }

        this.batchedPackets.get(packet.getChannel()).add(packet.clone());
    }
    return true;
}
 
Example #2
Source File: Player.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public int directDataPacket(DataPacket packet, boolean needACK) {
    if (!this.connected) {
        return -1;
    }

    try (Timing timing = Timings.getSendDataPacketTiming(packet)) {
        DataPacketSendEvent ev = new DataPacketSendEvent(this, packet);
        this.server.getPluginManager().callEvent(ev);
        if (ev.isCancelled()) {
            timing.stopTiming();
            return -1;
        }

        Integer identifier = this.interfaz.putPacket(this, packet, needACK, true);

        if (needACK && identifier != null) {
            this.needACK.put(identifier, Boolean.FALSE);
            timing.stopTiming();
            return identifier;
        }
    }
    return 0;
}
 
Example #3
Source File: Player.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public int dataPacket(DataPacket packet, boolean needACK) {
    if (!this.connected) {
        return -1;
    }

    try (Timing timing = Timings.getSendDataPacketTiming(packet)) {
        DataPacketSendEvent ev = new DataPacketSendEvent(this, packet);
        this.server.getPluginManager().callEvent(ev);
        if (ev.isCancelled()) {
            timing.stopTiming();
            return -1;
        }

        Integer identifier = this.interfaz.putPacket(this, packet, needACK, false);

        if (needACK && identifier != null) {
            this.needACK.put(identifier, Boolean.FALSE);
            timing.stopTiming();
            return identifier;
        }
    }
    return 0;
}
 
Example #4
Source File: Player.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public boolean batchDataPacket(DataPacket packet) {
    if (!this.connected) {
        return false;
    }

    try (Timing timing = Timings.getSendDataPacketTiming(packet)) {
        DataPacketSendEvent event = new DataPacketSendEvent(this, packet);
        this.server.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            timing.stopTiming();
            return false;
        }

        if (!this.batchedPackets.containsKey(packet.getChannel())) {
            this.batchedPackets.put(packet.getChannel(), new ArrayList<>());
        }

        this.batchedPackets.get(packet.getChannel()).add(packet.clone());
    }
    return true;
}
 
Example #5
Source File: SynapsePlayer.java    From SynapseAPI with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void handleDataPacket(DataPacket packet) {
    if (!this.isSynapseLogin) {
        super.handleDataPacket(packet);
        return;
    }
    Timing dataPacketTiming = handlePlayerDataPacketTimings.getOrDefault(packet.pid(), TimingsManager.getTiming("SynapseEntry - HandlePlayerDataPacket - " + packet.getClass().getSimpleName()));
    dataPacketTiming.startTiming();

    super.handleDataPacket(packet);

    dataPacketTiming.stopTiming();
    if (!handlePlayerDataPacketTimings.containsKey(packet.pid()))
        handlePlayerDataPacketTimings.put(packet.pid(), dataPacketTiming);

}
 
Example #6
Source File: Player.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public int directDataPacket(DataPacket packet, boolean needACK) {
    if (!this.connected) {
        return -1;
    }

    try (Timing timing = Timings.getSendDataPacketTiming(packet)) {
        DataPacketSendEvent ev = new DataPacketSendEvent(this, packet);
        this.server.getPluginManager().callEvent(ev);
        if (ev.isCancelled()) {
            return -1;
        }

        Integer identifier = this.interfaz.putPacket(this, packet, needACK, true);

        if (needACK && identifier != null) {
            this.needACK.put(identifier, Boolean.FALSE);
            return identifier;
        }
    }
    return 0;
}
 
Example #7
Source File: Player.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public int dataPacket(DataPacket packet, boolean needACK) {
    if (!this.connected) {
        return -1;
    }

    try (Timing timing = Timings.getSendDataPacketTiming(packet)) {
        DataPacketSendEvent ev = new DataPacketSendEvent(this, packet);
        this.server.getPluginManager().callEvent(ev);
        if (ev.isCancelled()) {
            return -1;
        }

        if (log.isTraceEnabled() && !(packet instanceof BatchPacket)) {
            log.trace("Outbound {}: {}", this.getName(), packet);
        }

        Integer identifier = this.interfaz.putPacket(this, packet, needACK, false);

        if (needACK && identifier != null) {
            this.needACK.put(identifier, Boolean.FALSE);
            return identifier;
        }
    }
    return 0;
}
 
Example #8
Source File: VirtualChestInventory.java    From VirtualChest with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Consumer<Inventory> getUpdaterFor(String name, Player player)
{
    return inventory ->
    {
        try (Timing ignored1 = VirtualChestTimings.updateAndRefreshMappings(name).startTiming())
        {
            int index = 0;
            for (Slot slot : inventory.<Slot>slots())
            {
                try (Timing ignored2 = VirtualChestTimings.updateAndRefreshMapping(name, index).startTiming())
                {
                    this.setItemInInventory(player, slot, index++, name);
                }
            }
        }
    };
}
 
Example #9
Source File: VirtualChestJavaScriptManager.java    From VirtualChest with GNU Lesser General Public License v3.0 6 votes vote down vote up
public boolean execute(Player player, Tuple<String, CompiledScript> tuple)
{
    String scriptLiteral = tuple.getFirst();
    ScriptContext context = this.getContext(player);
    try (Timing ignored = VirtualChestTimings.executeRequirementScript().startTiming())
    {
        return Boolean.valueOf(String.valueOf(tuple.getSecond().eval(context)));
    }
    catch (ScriptException e)
    {
        this.logger.error("Error found when executing script for player " + player.getName(), e);
        this.logger.debug("Literal: {}", scriptLiteral);
        this.logger.debug("Result: {}", Boolean.FALSE);
        return false;
    }
    finally
    {
        this.removeContextAttributes(context);
    }
}
 
Example #10
Source File: PluginManager.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin, boolean ignoreCancelled) throws PluginException {
    if (!plugin.isEnabled()) {
        throw new PluginException("Plugin attempted to register " + event + " while not enabled");
    }

    try {
        Timing timing = Timings.getPluginEventTiming(event, listener, executor, plugin);
        this.getEventListeners(event).register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled, timing));
    } catch (IllegalAccessException e) {
        Server.getInstance().getLogger().logException(e);
    }
}
 
Example #11
Source File: RegisteredListener.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public RegisteredListener(Listener listener, EventExecutor executor, EventPriority priority, Plugin plugin, boolean ignoreCancelled, Timing timing) {
    this.listener = listener;
    this.priority = priority;
    this.plugin = plugin;
    this.executor = executor;
    this.ignoreCancelled = ignoreCancelled;
    this.timing = timing;
}
 
Example #12
Source File: PluginManager.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin, boolean ignoreCancelled) throws PluginException {
    if (!plugin.isEnabled()) {
        throw new PluginException("Plugin attempted to register " + event + " while not enabled");
    }

    try {
        Timing timing = Timings.getPluginEventTiming(event, listener, executor, plugin);
        this.getEventListeners(event).register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled, timing));
    } catch (IllegalAccessException e) {
        Server.getInstance().getLogger().logException(e);
    }
}
 
Example #13
Source File: RegisteredListener.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public RegisteredListener(Listener listener, EventExecutor executor, EventPriority priority, Plugin plugin, boolean ignoreCancelled, Timing timing) {
    this.listener = listener;
    this.priority = priority;
    this.plugin = plugin;
    this.executor = executor;
    this.ignoreCancelled = ignoreCancelled;
    this.timing = timing;
}
 
Example #14
Source File: VirtualChestItem.java    From VirtualChest with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean matchRequirements(Player player, int index, String name)
{
    try (Timing ignored = VirtualChestTimings.checkRequirements(name, index).startTiming())
    {
        return this.plugin.getScriptManager().execute(player, this.requirements);
    }
}
 
Example #15
Source File: VirtualChestItem.java    From VirtualChest with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void fillInventory(Player player, Inventory inventory, int index, String name)
{
    try (Timing ignored = VirtualChestTimings.setItemInInventory(name, index).startTiming())
    {
        inventory.set(this.serializer.apply(player, this.serializedStack));
    }
    catch (InvalidDataException e)
    {
        String posString = VirtualChestInventory.slotIndexToKey(index);
        throw new InvalidDataException("Find error when generating item at " + posString, e);
    }
}
 
Example #16
Source File: RegisteredListener.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public RegisteredListener(Listener listener, EventExecutor executor, EventPriority priority, Plugin plugin, boolean ignoreCancelled, Timing timing) {
    this.listener = listener;
    this.priority = priority;
    this.plugin = plugin;
    this.executor = executor;
    this.ignoreCancelled = ignoreCancelled;
    this.timing = timing;
}
 
Example #17
Source File: PluginManager.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin, boolean ignoreCancelled) throws PluginException {
    if (!plugin.isEnabled()) {
        throw new PluginException("Plugin attempted to register " + event + " while not enabled");
    }

    try {
        Timing timing = Timings.getPluginEventTiming(event, listener, executor, plugin);
        this.getEventListeners(event).register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled, timing));
    } catch (IllegalAccessException e) {
        Server.getInstance().getLogger().logException(e);
    }
}
 
Example #18
Source File: VirtualChestJavaScriptManager.java    From VirtualChest with GNU Lesser General Public License v3.0 5 votes vote down vote up
private ScriptContext getContext(Player player)
{
    try (Timing ignored = VirtualChestTimings.prepareRequirementBindings().startTiming())
    {
        SimpleScriptContext context = this.tempContext;
        VirtualChestPlaceholderManager placeholderManager = this.plugin.getPlaceholderManager();
        Function<String, Object> papi = s -> Text.of(placeholderManager.replacePlaceholder(player, s)).toPlain();

        context.setAttribute("papi", papi, ScriptContext.ENGINE_SCOPE);
        context.setAttribute("player", player, ScriptContext.ENGINE_SCOPE);
        context.setAttribute("tick", this.getTickFromOpeningInventory(player), ScriptContext.ENGINE_SCOPE);

        return context;
    }
}
 
Example #19
Source File: VirtualChestTimings.java    From VirtualChest with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static Timing updateAndRefreshMappings(String name)
{
    return Timings.of(PLUGIN, "updateAndRefreshMappings - " + name);
}
 
Example #20
Source File: Timings.java    From EssentialCmds with MIT License 4 votes vote down vote up
public Timing teleportCooldown()
{
	return teleportCooldown;
}
 
Example #21
Source File: Timings.java    From EssentialCmds with MIT License 4 votes vote down vote up
public Timing teleportPlayer()
{
	return teleportPlayer;
}
 
Example #22
Source File: Timings.java    From EssentialCmds with MIT License 4 votes vote down vote up
public Timing afk()
{
	return afk;
}
 
Example #23
Source File: Timings.java    From EssentialCmds with MIT License 4 votes vote down vote up
public Timing loginMessage()
{
	return loginMessage;
}
 
Example #24
Source File: Timings.java    From EssentialCmds with MIT License 4 votes vote down vote up
public Timing saveInventory()
{
	return saveInventory;
}
 
Example #25
Source File: Timings.java    From EssentialCmds with MIT License 4 votes vote down vote up
public Timing getMail()
{
	return mail;
}
 
Example #26
Source File: Timings.java    From EssentialCmds with MIT License 4 votes vote down vote up
public Timing safeLogin()
{
	return safeLogin;
}
 
Example #27
Source File: Timings.java    From EssentialCmds with MIT License 4 votes vote down vote up
public Timing firstJoin()
{
	return firstJoin;
}
 
Example #28
Source File: Timings.java    From EssentialCmds with MIT License 4 votes vote down vote up
private Timing timing(String key)
{
	return co.aikar.timings.Timings.of(this.plugin, key);
}
 
Example #29
Source File: VirtualChestTimings.java    From VirtualChest with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static Timing executeRequirementScript()
{
    return EXECUTE_REQUIREMENT_SCRIPT;
}
 
Example #30
Source File: SkriptTimings.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
public static void stop(@Nullable Object timing) {
	if (timing == null) // Timings disabled...
		return;
	((Timing) timing).stopTimingIfSync();
}