Merge pull request 'Add TPSWatcher' (#62) from TPS into master
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Commit
1088e3e037
32
SpigotCore_10/src/de/steamwar/core/SpigotTPS_10.java
Normale Datei
32
SpigotCore_10/src/de/steamwar/core/SpigotTPS_10.java
Normale Datei
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
32
SpigotCore_12/src/de/steamwar/core/SpigotTPS_12.java
Normale Datei
32
SpigotCore_12/src/de/steamwar/core/SpigotTPS_12.java
Normale Datei
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
32
SpigotCore_14/src/de/steamwar/core/SpigotTPS_14.java
Normale Datei
32
SpigotCore_14/src/de/steamwar/core/SpigotTPS_14.java
Normale Datei
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
32
SpigotCore_15/src/de/steamwar/core/SpigotTPS_15.java
Normale Datei
32
SpigotCore_15/src/de/steamwar/core/SpigotTPS_15.java
Normale Datei
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
32
SpigotCore_8/src/de/steamwar/core/SpigotTPS_8.java
Normale Datei
32
SpigotCore_8/src/de/steamwar/core/SpigotTPS_8.java
Normale Datei
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
32
SpigotCore_9/src/de/steamwar/core/SpigotTPS_9.java
Normale Datei
32
SpigotCore_9/src/de/steamwar/core/SpigotTPS_9.java
Normale Datei
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -64,6 +64,7 @@ public class Core extends JavaPlugin{
|
|||||||
ErrorLogger.init();
|
ErrorLogger.init();
|
||||||
getServer().getMessenger().registerIncomingPluginChannel(this, "sw:bridge", new BungeeReceiver());
|
getServer().getMessenger().registerIncomingPluginChannel(this, "sw:bridge", new BungeeReceiver());
|
||||||
getServer().getMessenger().registerOutgoingPluginChannel(this, "sw:bridge");
|
getServer().getMessenger().registerOutgoingPluginChannel(this, "sw:bridge");
|
||||||
|
TPSWatcher.init();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,11 +76,11 @@ public class Core extends JavaPlugin{
|
|||||||
public static Core getInstance() {
|
public static Core getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getVersion(){
|
public static int getVersion(){
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void setInstance(Core instance) {
|
private static void setInstance(Core instance) {
|
||||||
Core.instance = instance;
|
Core.instance = instance;
|
||||||
}
|
}
|
||||||
|
134
SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java
Normale Datei
134
SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java
Normale Datei
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren