Search in sources :

Example 1 with QueryRegenerateEvent

use of cn.nukkit.event.server.QueryRegenerateEvent in project Nukkit by Nukkit.

the class RakNetInterface method setName.

@Override
public void setName(String name) {
    QueryRegenerateEvent info = this.server.getQueryInformation();
    // Split double names within the program
    String[] names = name.split("!@#");
    this.handler.sendOption("name", "MCPE;" + Utils.rtrim(names[0].replace(";", "\\;"), '\\') + ";" + ProtocolInfo.CURRENT_PROTOCOL + ";;" + info.getPlayerCount() + ";" + info.getMaxPlayerCount() + ";" + this.server.getServerUniqueId().toString() + ";" + (names.length > 1 ? Utils.rtrim(names[1].replace(";", "\\;"), '\\') : "") + ";" + Server.getGamemodeString(this.server.getDefaultGamemode(), true) + ";");
}
Also used : QueryRegenerateEvent(cn.nukkit.event.server.QueryRegenerateEvent)

Example 2 with QueryRegenerateEvent

use of cn.nukkit.event.server.QueryRegenerateEvent in project Nukkit by Nukkit.

the class QueryHandler method regenerateInfo.

public void regenerateInfo() {
    QueryRegenerateEvent ev = this.server.getQueryInformation();
    this.longData = ev.getLongQuery(this.longData);
    this.shortData = ev.getShortQuery(this.shortData);
    this.timeout = System.currentTimeMillis() + ev.getTimeout();
}
Also used : QueryRegenerateEvent(cn.nukkit.event.server.QueryRegenerateEvent)

Example 3 with QueryRegenerateEvent

use of cn.nukkit.event.server.QueryRegenerateEvent in project Nukkit by Nukkit.

the class Server method tick.

private boolean tick() {
    long tickTime = System.currentTimeMillis();
    // TODO
    long sleepTime = tickTime - this.nextTick;
    if (sleepTime < -25) {
        try {
            Thread.sleep(Math.max(5, -sleepTime - 25));
        } catch (InterruptedException e) {
            Server.getInstance().getLogger().logException(e);
        }
    }
    long tickTimeNano = System.nanoTime();
    if ((tickTime - this.nextTick) < -25) {
        return false;
    }
    Timings.fullServerTickTimer.startTiming();
    ++this.tickCounter;
    Timings.connectionTimer.startTiming();
    this.network.processInterfaces();
    if (this.rcon != null) {
        this.rcon.check();
    }
    Timings.connectionTimer.stopTiming();
    Timings.schedulerTimer.startTiming();
    this.scheduler.mainThreadHeartbeat(this.tickCounter);
    Timings.schedulerTimer.stopTiming();
    this.checkTickUpdates(this.tickCounter, tickTime);
    for (Player player : new ArrayList<>(this.players.values())) {
        player.checkNetwork();
    }
    if ((this.tickCounter & 0b1111) == 0) {
        this.titleTick();
        this.network.resetStatistics();
        this.maxTick = 20;
        this.maxUse = 0;
        if ((this.tickCounter & 0b111111111) == 0) {
            try {
                this.getPluginManager().callEvent(this.queryRegenerateEvent = new QueryRegenerateEvent(this, 5));
                if (this.queryHandler != null) {
                    this.queryHandler.regenerateInfo();
                }
            } catch (Exception e) {
                this.logger.logException(e);
            }
        }
        this.getNetwork().updateName();
    }
    if (this.autoSave && ++this.autoSaveTicker >= this.autoSaveTicks) {
        this.autoSaveTicker = 0;
        this.doAutoSave();
    }
    if (this.sendUsageTicker > 0 && --this.sendUsageTicker == 0) {
        this.sendUsageTicker = 6000;
    // todo sendUsage
    }
    if (this.tickCounter % 100 == 0) {
        for (Level level : this.levelArray) {
            level.doChunkGarbageCollection();
        }
    }
    Timings.fullServerTickTimer.stopTiming();
    // long now = System.currentTimeMillis();
    long nowNano = System.nanoTime();
    // float tick = Math.min(20, 1000 / Math.max(1, now - tickTime));
    // float use = Math.min(1, (now - tickTime) / 50);
    float tick = (float) Math.min(20, 1000000000 / Math.max(1000000, ((double) nowNano - tickTimeNano)));
    float use = (float) Math.min(1, ((double) (nowNano - tickTimeNano)) / 50000000);
    if (this.maxTick > tick) {
        this.maxTick = tick;
    }
    if (this.maxUse < use) {
        this.maxUse = use;
    }
    System.arraycopy(this.tickAverage, 1, this.tickAverage, 0, this.tickAverage.length - 1);
    this.tickAverage[this.tickAverage.length - 1] = tick;
    System.arraycopy(this.useAverage, 1, this.useAverage, 0, this.useAverage.length - 1);
    this.useAverage[this.useAverage.length - 1] = use;
    if ((this.nextTick - tickTime) < -1000) {
        this.nextTick = tickTime;
    } else {
        this.nextTick += 50;
    }
    return true;
}
Also used : QueryRegenerateEvent(cn.nukkit.event.server.QueryRegenerateEvent) Level(cn.nukkit.level.Level)

Aggregations

QueryRegenerateEvent (cn.nukkit.event.server.QueryRegenerateEvent)3 Level (cn.nukkit.level.Level)1