Optimize TPSWarpUtils
Dieser Commit ist enthalten in:
Ursprung
b0dda7ec42
Commit
9e8372a318
@ -67,8 +67,8 @@ public class TPSLimitCommand extends SWCommand implements Enable {
|
|||||||
public void defaultCommand(Player p) {
|
public void defaultCommand(Player p) {
|
||||||
if (!permissionCheck(p)) return;
|
if (!permissionCheck(p)) return;
|
||||||
TPSLimitUtils.currentTPSLimit = 20;
|
TPSLimitUtils.currentTPSLimit = 20;
|
||||||
sendNewTPSLimitMessage();
|
|
||||||
TPSLimitUtils.tpsLimiter();
|
TPSLimitUtils.tpsLimiter();
|
||||||
|
sendNewTPSLimitMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register
|
@Register
|
||||||
@ -79,8 +79,8 @@ public class TPSLimitCommand extends SWCommand implements Enable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
TPSLimitUtils.currentTPSLimit = tpsLimitDouble;
|
TPSLimitUtils.currentTPSLimit = tpsLimitDouble;
|
||||||
sendNewTPSLimitMessage();
|
|
||||||
TPSLimitUtils.tpsLimiter();
|
TPSLimitUtils.tpsLimiter();
|
||||||
|
sendNewTPSLimitMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ClassMapper(value = double.class, local = true)
|
@ClassMapper(value = double.class, local = true)
|
||||||
|
@ -20,10 +20,12 @@
|
|||||||
package de.steamwar.bausystem.features.tpslimit;
|
package de.steamwar.bausystem.features.tpslimit;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.core.Core;
|
||||||
import de.steamwar.core.TPSWatcher;
|
import de.steamwar.core.TPSWatcher;
|
||||||
import de.steamwar.core.VersionedRunnable;
|
import de.steamwar.core.VersionedRunnable;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.experimental.UtilityClass;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class TPSWarpUtils {
|
public class TPSWarpUtils {
|
||||||
@ -31,11 +33,11 @@ public class TPSWarpUtils {
|
|||||||
private static boolean warp = true;
|
private static boolean warp = true;
|
||||||
private static long nanoOffset = 0;
|
private static long nanoOffset = 0;
|
||||||
private static long nanoDOffset = 0;
|
private static long nanoDOffset = 0;
|
||||||
|
private static BukkitTask bukkitTask = null;
|
||||||
|
|
||||||
static void init() {
|
static void init() {
|
||||||
VersionedRunnable.call(new VersionedRunnable(() -> warp = false, 8),
|
VersionedRunnable.call(new VersionedRunnable(() -> warp = false, 8),
|
||||||
new VersionedRunnable(() -> {
|
new VersionedRunnable(() -> {
|
||||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> nanoOffset += nanoDOffset, 1, 1);
|
|
||||||
TPSUtils_15.init(() -> nanoOffset);
|
TPSUtils_15.init(() -> nanoOffset);
|
||||||
}, 15));
|
}, 15));
|
||||||
}
|
}
|
||||||
@ -43,6 +45,16 @@ public class TPSWarpUtils {
|
|||||||
public static void setTPS(double tps) {
|
public static void setTPS(double tps) {
|
||||||
double d = 50 - (50 / (tps / 20.0));
|
double d = 50 - (50 / (tps / 20.0));
|
||||||
nanoDOffset = Math.max(0, Math.min((long) (d * 1000000), 37500000));
|
nanoDOffset = Math.max(0, Math.min((long) (d * 1000000), 37500000));
|
||||||
|
if (Core.getVersion() != 15) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (nanoDOffset == 0) {
|
||||||
|
if (bukkitTask == null) return;
|
||||||
|
bukkitTask.cancel();
|
||||||
|
bukkitTask = null;
|
||||||
|
} else {
|
||||||
|
bukkitTask = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> nanoOffset += nanoDOffset, 1, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isWarpAllowed() {
|
public static boolean isWarpAllowed() {
|
||||||
@ -53,7 +65,6 @@ public class TPSWarpUtils {
|
|||||||
return nanoDOffset > 0;
|
return nanoDOffset > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public static double getTps(TPSWatcher.TPSType tpsType) {
|
public static double getTps(TPSWatcher.TPSType tpsType) {
|
||||||
if (TPSWarpUtils.isWarping())
|
if (TPSWarpUtils.isWarping())
|
||||||
return TPSWatcher.getTPS(tpsType, Math.max(TPSLimitUtils.getCurrentTPSLimit(), 20));
|
return TPSWatcher.getTPS(tpsType, Math.max(TPSLimitUtils.getCurrentTPSLimit(), 20));
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren