SteamWar/BauSystem
Archiviert
13
0

Optimize TPSLimit_15

Optimize CommandInfo
Optimize CommandTPSLimiter
Optimize CommandTPSLimiterTabComplete
Optimize BauScoreboard
Optimize TPSUtils
Dieser Commit ist enthalten in:
jojo 2021-02-09 21:14:52 +01:00
Ursprung 5372f84409
Commit 97926c08d5
6 geänderte Dateien mit 18 neuen und 28 gelöschten Zeilen

Datei anzeigen

@ -16,7 +16,6 @@
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
* /
*/ */
package de.steamwar.bausystem.world; package de.steamwar.bausystem.world;

Datei anzeigen

@ -32,6 +32,8 @@ import org.bukkit.entity.Player;
import java.util.List; import java.util.List;
import static de.steamwar.bausystem.world.TPSUtils.getTps;
public class CommandInfo implements CommandExecutor { public class CommandInfo implements CommandExecutor {
@Override @Override
@ -69,11 +71,4 @@ public class CommandInfo implements CommandExecutor {
return false; return false;
} }
private double getTps(TPSWatcher.TPSType tpsType) {
if (TPSUtils.isWarping()) {
return TPSWatcher.getTPS(tpsType, Math.max(CommandTPSLimiter.getCurrentTPSLimit(), 20));
}
return TPSWatcher.getTPS(tpsType);
}
} }

Datei anzeigen

@ -98,7 +98,7 @@ public class CommandTPSLimiter implements CommandExecutor {
} }
private void sendInvalidArgumentMessage(Player player) { private void sendInvalidArgumentMessage(Player player) {
player.sendMessage(BauSystem.PREFIX + "§cNur Zahlen zwischen 0,5 und 20, und 'default' erlaubt."); player.sendMessage(BauSystem.PREFIX + "§cNur Zahlen zwischen 0,5 und " + (TPSUtils.isWarpAllowed() ? 40 : 20) + ", und 'default' erlaubt.");
} }
private void tpsLimiter() { private void tpsLimiter() {

Datei anzeigen

@ -31,7 +31,9 @@ import java.util.List;
public class CommandTPSLimiterTabComplete implements TabCompleter { public class CommandTPSLimiterTabComplete implements TabCompleter {
private List<String> arguments = Arrays.asList("default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"); private List<String> arguments = Arrays.asList("default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20");
private List<String> argumentsWarped = Arrays.asList("default", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40"); public CommandTPSLimiterTabComplete() {
if (TPSUtils.isWarpAllowed()) arguments.addAll(Arrays.asList("21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40"));
}
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) { public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
@ -39,7 +41,7 @@ public class CommandTPSLimiterTabComplete implements TabCompleter {
return new ArrayList<>(); return new ArrayList<>();
} }
List<String> validArguments = new ArrayList<>(arguments.size()); List<String> validArguments = new ArrayList<>(arguments.size());
for (String s : TPSUtils.isWarpAllowed() ? argumentsWarped : arguments) { for (String s : arguments) {
if (s.startsWith(args[0])) { if (s.startsWith(args[0])) {
validArguments.add(s); validArguments.add(s);
} }

Datei anzeigen

@ -73,7 +73,7 @@ public class BauScoreboard implements Listener {
} }
strings.add("§4"); strings.add("§4");
strings.add("§eTPS§8: " + tpsColor() + getTps() + tpsLimit()); strings.add("§eTPS§8: " + tpsColor() + TPSUtils.getTps(TPSWatcher.TPSType.ONE_SECOND) + tpsLimit());
int i = strings.size(); int i = strings.size();
HashMap<String, Integer> result = new HashMap<>(); HashMap<String, Integer> result = new HashMap<>();
@ -87,7 +87,7 @@ public class BauScoreboard implements Listener {
} }
private String tpsColor() { private String tpsColor() {
double tps = getTps(); double tps = TPSUtils.getTps(TPSWatcher.TPSType.ONE_SECOND);
if (tps > CommandTPSLimiter.getCurrentTPSLimit() * 0.9) { if (tps > CommandTPSLimiter.getCurrentTPSLimit() * 0.9) {
return "§a"; return "§a";
} }
@ -104,11 +104,4 @@ public class BauScoreboard implements Listener {
return "§8/§7" + CommandTPSLimiter.getCurrentTPSLimit(); return "§8/§7" + CommandTPSLimiter.getCurrentTPSLimit();
} }
private double getTps() {
if (TPSUtils.isWarping()) {
return TPSWatcher.getTPS(Math.max(CommandTPSLimiter.getCurrentTPSLimit(), 20));
}
return TPSWatcher.getTPS();
}
} }

Datei anzeigen

@ -16,12 +16,13 @@
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
* /
*/ */
package de.steamwar.bausystem.world; package de.steamwar.bausystem.world;
import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.commands.CommandTPSLimiter;
import de.steamwar.core.TPSWatcher;
import de.steamwar.core.VersionedRunnable; import de.steamwar.core.VersionedRunnable;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -36,19 +37,14 @@ public class TPSUtils {
private static long nanoDOffset = 0; private static long nanoDOffset = 0;
public static void init() { public static void init() {
Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> { Bukkit.getScheduler().runTaskTimer(BauSystem.getPlugin(), () -> nanoOffset += nanoDOffset, 1, 1);
nanoOffset += nanoDOffset;
}, 1, 1);
VersionedRunnable.call(new VersionedRunnable(() -> warp = false, 8), VersionedRunnable.call(new VersionedRunnable(() -> warp = false, 8),
new VersionedRunnable(() -> TPSLimit_15.init(() -> nanoOffset), 15)); new VersionedRunnable(() -> TPSLimit_15.init(() -> nanoOffset), 15));
} }
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));
long nanos = (long) (d * 1000000); nanoDOffset = Math.max(0, Math.min((long) (d * 1000000), 25000000));
if (nanos < 0) nanos = 0;
if (nanos > 25000000) nanos = 25000000;
nanoDOffset = nanos;
} }
public static boolean isWarpAllowed() { public static boolean isWarpAllowed() {
@ -59,4 +55,9 @@ public class TPSUtils {
return nanoDOffset > 0; return nanoDOffset > 0;
} }
public static double getTps(TPSWatcher.TPSType tpsType) {
if (TPSUtils.isWarping()) return TPSWatcher.getTPS(tpsType, Math.max(CommandTPSLimiter.getCurrentTPSLimit(), 20));
return TPSWatcher.getTPS(tpsType);
}
} }