Java Code Examples for cn.nukkit.level.Level#doTick()
The following examples show how to use
cn.nukkit.level.Level#doTick() .
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: Server.java From Jupiter with GNU General Public License v3.0 | 4 votes |
private void checkTickUpdates(int currentTick, long tickTime) { for (Player p : new ArrayList<>(this.players.values())) { /*if (!p.loggedIn && (tickTime - p.creationTime) >= 10000 && p.kick(PlayerKickEvent.Reason.LOGIN_TIMEOUT, "Login timeout")) { continue; } client freezes when applying resource packs todo: fix*/ if (this.alwaysTickPlayers) { p.onUpdate(currentTick); } } //Do level ticks for (Level level : this.getLevels().values()) { if (level.getTickRate() > this.baseTickRate && --level.tickRateCounter > 0) { continue; } try { long levelTime = System.currentTimeMillis(); level.doTick(currentTick); int tickMs = (int) (System.currentTimeMillis() - levelTime); level.tickRateTime = tickMs; if (this.autoTickRate) { if (tickMs < 50 && level.getTickRate() > this.baseTickRate) { int r; level.setTickRate(r = level.getTickRate() - 1); if (r > this.baseTickRate) { level.tickRateCounter = level.getTickRate(); } this.getLogger().debug("Raising level \"" + level.getName() + "\" tick rate to " + level.getTickRate() + " ticks"); } else if (tickMs >= 50) { if (level.getTickRate() == this.baseTickRate) { level.setTickRate((int) Math.max(this.baseTickRate + 1, Math.min(this.autoTickRateLimit, Math.floor(tickMs / 50)))); this.getLogger().debug("Level \"" + level.getName() + "\" took " + NukkitMath.round(tickMs, 2) + "ms, setting tick rate to " + level.getTickRate() + " ticks"); } else if ((tickMs / level.getTickRate()) >= 50 && level.getTickRate() < this.autoTickRateLimit) { level.setTickRate(level.getTickRate() + 1); this.getLogger().debug("Level \"" + level.getName() + "\" took " + NukkitMath.round(tickMs, 2) + "ms, setting tick rate to " + level.getTickRate() + " ticks"); } level.tickRateCounter = level.getTickRate(); } } } catch (Exception e) { if (Nukkit.DEBUG > 1 && this.logger != null) { this.logger.logException(e); } this.logger.critical(this.getLanguage().translateString("nukkit.level.tickError", new String[]{level.getName(), e.toString()})); this.logger.logException(e); } } }
Example 2
Source File: Server.java From Nukkit with GNU General Public License v3.0 | 4 votes |
private void checkTickUpdates(int currentTick, long tickTime) { for (Player p : new ArrayList<>(this.players.values())) { /*if (!p.loggedIn && (tickTime - p.creationTime) >= 10000 && p.kick(PlayerKickEvent.Reason.LOGIN_TIMEOUT, "Login timeout")) { continue; } client freezes when applying resource packs todo: fix*/ if (this.alwaysTickPlayers) { p.onUpdate(currentTick); } } //Do level ticks for (Level level : this.levelArray) { if (level.getTickRate() > this.baseTickRate && --level.tickRateCounter > 0) { continue; } try { long levelTime = System.currentTimeMillis(); level.doTick(currentTick); int tickMs = (int) (System.currentTimeMillis() - levelTime); level.tickRateTime = tickMs; if (this.autoTickRate) { if (tickMs < 50 && level.getTickRate() > this.baseTickRate) { int r; level.setTickRate(r = level.getTickRate() - 1); if (r > this.baseTickRate) { level.tickRateCounter = level.getTickRate(); } this.getLogger().debug("Raising level \"" + level.getName() + "\" tick rate to " + level.getTickRate() + " ticks"); } else if (tickMs >= 50) { if (level.getTickRate() == this.baseTickRate) { level.setTickRate(Math.max(this.baseTickRate + 1, Math.min(this.autoTickRateLimit, tickMs / 50))); this.getLogger().debug("Level \"" + level.getName() + "\" took " + NukkitMath.round(tickMs, 2) + "ms, setting tick rate to " + level.getTickRate() + " ticks"); } else if ((tickMs / level.getTickRate()) >= 50 && level.getTickRate() < this.autoTickRateLimit) { level.setTickRate(level.getTickRate() + 1); this.getLogger().debug("Level \"" + level.getName() + "\" took " + NukkitMath.round(tickMs, 2) + "ms, setting tick rate to " + level.getTickRate() + " ticks"); } level.tickRateCounter = level.getTickRate(); } } } catch (Exception e) { log.error(this.getLanguage().translateString("nukkit.level.tickError", new String[]{level.getFolderName(), Utils.getExceptionMessage(e)})); } } }
Example 3
Source File: Server.java From Nukkit with GNU General Public License v3.0 | 4 votes |
private void checkTickUpdates(int currentTick, long tickTime) { for (Player p : new ArrayList<>(this.players.values())) { /*if (!p.loggedIn && (tickTime - p.creationTime) >= 10000 && p.kick(PlayerKickEvent.Reason.LOGIN_TIMEOUT, "Login timeout")) { continue; } client freezes when applying resource packs todo: fix*/ if (this.alwaysTickPlayers) { p.onUpdate(currentTick); } } //Do level ticks for (Level level : this.levelArray) { if (level.getTickRate() > this.baseTickRate && --level.tickRateCounter > 0) { continue; } try { long levelTime = System.currentTimeMillis(); level.doTick(currentTick); int tickMs = (int) (System.currentTimeMillis() - levelTime); level.tickRateTime = tickMs; if (this.autoTickRate) { if (tickMs < 50 && level.getTickRate() > this.baseTickRate) { int r; level.setTickRate(r = level.getTickRate() - 1); if (r > this.baseTickRate) { level.tickRateCounter = level.getTickRate(); } this.getLogger().debug("Raising level \"" + level.getName() + "\" tick rate to " + level.getTickRate() + " ticks"); } else if (tickMs >= 50) { if (level.getTickRate() == this.baseTickRate) { level.setTickRate((int) Math.max(this.baseTickRate + 1, Math.min(this.autoTickRateLimit, Math.floor(tickMs / 50)))); this.getLogger().debug("Level \"" + level.getName() + "\" took " + NukkitMath.round(tickMs, 2) + "ms, setting tick rate to " + level.getTickRate() + " ticks"); } else if ((tickMs / level.getTickRate()) >= 50 && level.getTickRate() < this.autoTickRateLimit) { level.setTickRate(level.getTickRate() + 1); this.getLogger().debug("Level \"" + level.getName() + "\" took " + NukkitMath.round(tickMs, 2) + "ms, setting tick rate to " + level.getTickRate() + " ticks"); } level.tickRateCounter = level.getTickRate(); } } } catch (Exception e) { if (Nukkit.DEBUG > 1 && this.logger != null) { this.logger.logException(e); } this.logger.critical(this.getLanguage().translateString("nukkit.level.tickError", new String[]{level.getName(), e.toString()})); this.logger.logException(e); } } }