Reduce calls of System.currentTimeMillis() in TickLimiter, close #130
This commit is contained in:
parent
043978c113
commit
ac8700f8a6
@ -111,6 +111,7 @@ public class KCauldron {
|
|||||||
public static int lookupForgeRevision() {
|
public static int lookupForgeRevision() {
|
||||||
if (sForgeRevision != 0) return sForgeRevision;
|
if (sForgeRevision != 0) return sForgeRevision;
|
||||||
int revision = Integer.parseInt(System.getProperty("kcauldron.forgeRevision", "0"));
|
int revision = Integer.parseInt(System.getProperty("kcauldron.forgeRevision", "0"));
|
||||||
|
if (revision != 0) return sForgeRevision = revision;
|
||||||
try {
|
try {
|
||||||
Properties p = new Properties();
|
Properties p = new Properties();
|
||||||
p.load(KCauldron.class
|
p.load(KCauldron.class
|
||||||
|
@ -3,16 +3,23 @@ package org.spigotmc;
|
|||||||
public class TickLimiter {
|
public class TickLimiter {
|
||||||
private final int maxTime;
|
private final int maxTime;
|
||||||
private long startTime;
|
private long startTime;
|
||||||
|
private int tick;
|
||||||
|
private boolean shouldContinue;
|
||||||
public TickLimiter(int maxTime) {
|
public TickLimiter(int maxTime) {
|
||||||
this.maxTime = maxTime;
|
this.maxTime = maxTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initTick() {
|
public void initTick() {
|
||||||
startTime = System.currentTimeMillis();
|
startTime = System.currentTimeMillis();
|
||||||
|
tick = 0;
|
||||||
|
shouldContinue = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean shouldContinue() {
|
public boolean shouldContinue() {
|
||||||
return System.currentTimeMillis() - startTime < maxTime;
|
if (++tick >= 300 && !shouldContinue) {
|
||||||
|
tick = 0;
|
||||||
|
shouldContinue = System.currentTimeMillis() - startTime < maxTime;
|
||||||
|
}
|
||||||
|
return shouldContinue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user