diff --git a/SpigotCore_10/src/de/steamwar/core/SpigotTPS_10.java b/SpigotCore_10/src/de/steamwar/core/SpigotTPS_10.java new file mode 100644 index 0000000..2cc2d26 --- /dev/null +++ b/SpigotCore_10/src/de/steamwar/core/SpigotTPS_10.java @@ -0,0 +1,32 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.core; + +import net.minecraft.server.v1_10_R1.MinecraftServer; + +public class SpigotTPS_10 { + + private SpigotTPS_10(){} + + static double[] getTps(){ + return MinecraftServer.getServer().recentTps; + } + +} diff --git a/SpigotCore_12/src/de/steamwar/core/SpigotTPS_12.java b/SpigotCore_12/src/de/steamwar/core/SpigotTPS_12.java new file mode 100644 index 0000000..17541c7 --- /dev/null +++ b/SpigotCore_12/src/de/steamwar/core/SpigotTPS_12.java @@ -0,0 +1,32 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.core; + +import net.minecraft.server.v1_12_R1.MinecraftServer; + +public class SpigotTPS_12 { + + private SpigotTPS_12(){} + + static double[] getTps(){ + return MinecraftServer.getServer().recentTps; + } + +} diff --git a/SpigotCore_14/src/de/steamwar/core/SpigotTPS_14.java b/SpigotCore_14/src/de/steamwar/core/SpigotTPS_14.java new file mode 100644 index 0000000..d00aba8 --- /dev/null +++ b/SpigotCore_14/src/de/steamwar/core/SpigotTPS_14.java @@ -0,0 +1,32 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.core; + +import net.minecraft.server.v1_14_R1.MinecraftServer; + +public class SpigotTPS_14 { + + private SpigotTPS_14(){} + + static double[] getTps(){ + return MinecraftServer.getServer().recentTps; + } + +} diff --git a/SpigotCore_15/src/de/steamwar/core/SpigotTPS_15.java b/SpigotCore_15/src/de/steamwar/core/SpigotTPS_15.java new file mode 100644 index 0000000..46c1186 --- /dev/null +++ b/SpigotCore_15/src/de/steamwar/core/SpigotTPS_15.java @@ -0,0 +1,32 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.core; + +import net.minecraft.server.v1_15_R1.MinecraftServer; + +public class SpigotTPS_15 { + + private SpigotTPS_15(){} + + static double[] getTps(){ + return MinecraftServer.getServer().recentTps; + } + +} diff --git a/SpigotCore_8/src/de/steamwar/core/SpigotTPS_8.java b/SpigotCore_8/src/de/steamwar/core/SpigotTPS_8.java new file mode 100644 index 0000000..aeb94d1 --- /dev/null +++ b/SpigotCore_8/src/de/steamwar/core/SpigotTPS_8.java @@ -0,0 +1,32 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.core; + +import net.minecraft.server.v1_8_R3.MinecraftServer; + +public class SpigotTPS_8 { + + private SpigotTPS_8(){} + + static double[] getTps(){ + return MinecraftServer.getServer().recentTps; + } + +} diff --git a/SpigotCore_9/src/de/steamwar/core/SpigotTPS_9.java b/SpigotCore_9/src/de/steamwar/core/SpigotTPS_9.java new file mode 100644 index 0000000..6a0ba28 --- /dev/null +++ b/SpigotCore_9/src/de/steamwar/core/SpigotTPS_9.java @@ -0,0 +1,32 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.core; + +import net.minecraft.server.v1_9_R2.MinecraftServer; + +public class SpigotTPS_9 { + + private SpigotTPS_9(){} + + static double[] getTps(){ + return MinecraftServer.getServer().recentTps; + } + +} diff --git a/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore_Main/src/de/steamwar/core/Core.java index 893e53a..a7e1cab 100644 --- a/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -64,6 +64,7 @@ public class Core extends JavaPlugin{ ErrorLogger.init(); getServer().getMessenger().registerIncomingPluginChannel(this, "sw:bridge", new BungeeReceiver()); getServer().getMessenger().registerOutgoingPluginChannel(this, "sw:bridge"); + TPSWatcher.init(); } @@ -75,11 +76,11 @@ public class Core extends JavaPlugin{ public static Core getInstance() { return instance; } + public static int getVersion(){ return version; } - private static void setInstance(Core instance) { Core.instance = instance; } diff --git a/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java new file mode 100644 index 0000000..9b36d29 --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java @@ -0,0 +1,134 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.core; + +import org.bukkit.Bukkit; + +public class TPSWatcher { + + private static final double tickDefault = 20.0; + + private static TPSWatcher tps_OneSecond; + private static TPSWatcher tps_TenSecond; + + public static void init() { + tps_OneSecond = new TPSWatcher(1000); + tps_TenSecond = new TPSWatcher(10000); + } + + private long lastTime = System.currentTimeMillis(); + + private double tps = 20.0; + + private TPSWatcher(long timeInterval) { + Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> { + long tickTime = System.currentTimeMillis() - lastTime; + lastTime = System.currentTimeMillis(); + + double now = 0; + if (tickTime != 0) { + now = (timeInterval / (double) tickTime) * tickDefault; + } + if (now < 0) { + now = 0; + } + tps = now; + }, timeInterval / 50, timeInterval / 50); + } + + public enum TPSType { + + // With own implementation + ONE_SECOND, + TEN_SECONDS, + // With getting the values from Spigot itself + ONE_MINUTE, + FIVE_MINUTES, + TEN_MINUTES + + } + + public double getTPS() { + return getTPS(TPSType.ONE_SECOND); + } + + public double getTPSUnlimited() { + return getTPSUnlimited(TPSType.ONE_SECOND); + } + + public double getTPS(TPSType tpsType) { + switch (tpsType) { + case TEN_SECONDS: + return round(tps_TenSecond.tps); + case ONE_MINUTE: + return round(getSpigotTPS()[0]); + case FIVE_MINUTES: + return round(getSpigotTPS()[1]); + case TEN_MINUTES: + return round(getSpigotTPS()[2]); + + default: + return round(tps_OneSecond.tps); + } + } + + public double getTPSUnlimited(TPSType tpsType) { + switch (tpsType) { + case TEN_SECONDS: + return roundUnlimited(tps_TenSecond.tps); + case ONE_MINUTE: + return roundUnlimited(getSpigotTPS()[0]); + case FIVE_MINUTES: + return roundUnlimited(getSpigotTPS()[1]); + case TEN_MINUTES: + return roundUnlimited(getSpigotTPS()[2]); + + default: + return roundUnlimited(tps_OneSecond.tps); + } + } + + private double[] getSpigotTPS() { + switch (Core.getVersion()) { + case 8: + return SpigotTPS_8.getTps(); + case 9: + return SpigotTPS_9.getTps(); + case 10: + return SpigotTPS_10.getTps(); + case 14: + return SpigotTPS_14.getTps(); + case 15: + return SpigotTPS_15.getTps(); + + default: + return SpigotTPS_12.getTps(); + } + } + + private double round(double d) { + return Math.max(Math.round(d * 10) / 10.0, 20.0); + } + + private double roundUnlimited(double d) { + return Math.round(d * 10) / 10.0; + } + +}