diff --git a/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java b/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java index bcb2a32f3..732aa7102 100644 --- a/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java +++ b/Plan/src/main/java/com/djrapitops/plan/PlanBungee.java @@ -20,6 +20,7 @@ import main.java.com.djrapitops.plan.systems.info.server.BungeeServerInfoManager import main.java.com.djrapitops.plan.systems.listeners.BungeePlayerListener; import main.java.com.djrapitops.plan.systems.processing.Processor; import main.java.com.djrapitops.plan.systems.queue.ProcessingQueue; +import main.java.com.djrapitops.plan.systems.tasks.TPSCountTimer; import main.java.com.djrapitops.plan.systems.webserver.WebServer; import main.java.com.djrapitops.plan.utilities.Benchmark; import net.md_5.bungee.api.ChatColor; @@ -67,7 +68,7 @@ public class PlanBungee extends BungeePlugin implements IPlan { registerCommand(new ReloadCommand(this)); String ip = variableHolder.getIp(); - if ("0.0.0.0".equals(ip)) { + if ("0.0.0.0" .equals(ip)) { Log.error("IP setting still 0.0.0.0 - Configure AlternativeIP/IP that connects to the Proxy server."); Log.info("Player Analytics partially enabled (Use /planbungee to reload config)"); return; @@ -94,6 +95,7 @@ public class PlanBungee extends BungeePlugin implements IPlan { infoManager.sendConfigSettings(); } }).runTaskAsynchronously(); + getRunnableFactory().createNew("Player Count task", new TPSCountTimer(this)); // getProxy().registerChannel("Plan"); // registerListener(new BungeePluginChannelListener(this)); diff --git a/Plan/src/main/java/com/djrapitops/plan/database/tables/TPSTable.java b/Plan/src/main/java/com/djrapitops/plan/database/tables/TPSTable.java index fe81c2fe8..25ea21197 100644 --- a/Plan/src/main/java/com/djrapitops/plan/database/tables/TPSTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/database/tables/TPSTable.java @@ -2,7 +2,6 @@ package main.java.com.djrapitops.plan.database.tables; import com.djrapitops.plugin.api.TimeAmount; import com.djrapitops.plugin.utilities.Verify; -import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.api.exceptions.DBCreateTableException; import main.java.com.djrapitops.plan.data.TPS; import main.java.com.djrapitops.plan.database.databases.SQLDB; @@ -12,6 +11,7 @@ import main.java.com.djrapitops.plan.database.processing.QueryStatement; import main.java.com.djrapitops.plan.database.sql.Select; import main.java.com.djrapitops.plan.database.sql.Sql; import main.java.com.djrapitops.plan.database.sql.TableSqlParser; +import main.java.com.djrapitops.plan.systems.info.server.ServerInfo; import main.java.com.djrapitops.plan.utilities.MiscUtils; import java.sql.PreparedStatement; @@ -108,7 +108,7 @@ public class TPSTable extends Table { execute(new ExecStatement(insertStatement) { @Override public void prepare(PreparedStatement statement) throws SQLException { - statement.setString(1, Plan.getServerUUID().toString()); + statement.setString(1, MiscUtils.getIPlan().getServerUuid().toString()); statement.setLong(2, tps.getDate()); statement.setDouble(3, tps.getTicksPerSecond()); statement.setInt(4, tps.getPlayers()); @@ -262,15 +262,22 @@ public class TPSTable extends Table { } public List getNetworkOnlineData() throws SQLException { + Optional bungeeInfo = serverTable.getBungeeInfo(); + if (!bungeeInfo.isPresent()) { + return new ArrayList<>(); + } + UUID bungeeUUID = bungeeInfo.get().getUuid(); + String sql = "SELECT " + columnDate + ", " + - "SUM(" + columnPlayers + ") as players" + + columnPlayers + " FROM " + tableName + - " GROUP BY " + columnDate; + " WHERE " + columnServerID + "=" + serverTable.statementSelectServerID; return query(new QueryStatement>(sql, 50000) { @Override public void prepare(PreparedStatement statement) throws SQLException { + statement.setString(1, bungeeUUID.toString()); } @Override @@ -278,7 +285,7 @@ public class TPSTable extends Table { List tpsList = new ArrayList<>(); while (set.next()) { long date = set.getLong(columnDate); - int players = set.getInt("players"); + int players = set.getInt(columnPlayers); tpsList.add(new TPS(date, 0, players, 0, 0, 0, 0)); } diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/NetworkPageParser.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/NetworkPageParser.java index 0f5592259..687ffe362 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/NetworkPageParser.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/parsing/NetworkPageParser.java @@ -48,7 +48,7 @@ public class NetworkPageParser extends PageParser { addValue("playersOnlineSeries", PlayerActivityGraphCreator.buildSeriesDataString(networkOnlineData)); addValue("playersGraphColor", Colors.PLAYERS_ONLINE.getColor()); addValue("playersOnline", plugin.getProxy().getOnlineCount()); - addValue("playersMax", db.getServerTable().getMaxPlayers()); + addValue("playersMax", plugin.getProxy().getConfig().getPlayerLimit()); addValue("playersTotal", db.getUsersTable().getPlayerCount()); diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/processing/TPSInsertProcessor.java b/Plan/src/main/java/com/djrapitops/plan/systems/processing/TPSInsertProcessor.java index a4e8ac9e8..595ae2ebc 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/processing/TPSInsertProcessor.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/processing/TPSInsertProcessor.java @@ -5,8 +5,8 @@ package main.java.com.djrapitops.plan.systems.processing; import main.java.com.djrapitops.plan.Log; -import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.data.TPS; +import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.analysis.MathUtils; import java.sql.SQLException; @@ -36,7 +36,7 @@ public class TPSInsertProcessor extends Processor> { TPS tps = new TPS(lastDate, averageTPS, averagePlayersOnline, averageCPUUsage, averageUsedMemory, averageEntityCount, averageChunksLoaded); try { - Plan.getInstance().getDB().getTpsTable().insertTPS(tps); + MiscUtils.getIPlan().getDB().getTpsTable().insertTPS(tps); } catch (SQLException e) { Log.toLog(this.getClass().getName(), e); } diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/tasks/TPSCountTimer.java b/Plan/src/main/java/com/djrapitops/plan/systems/tasks/TPSCountTimer.java index 057fc4e51..631a35044 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/tasks/TPSCountTimer.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/tasks/TPSCountTimer.java @@ -2,8 +2,11 @@ package main.java.com.djrapitops.plan.systems.tasks; import com.djrapitops.plugin.api.TimeAmount; import com.djrapitops.plugin.task.AbsRunnable; +import com.djrapitops.plugin.utilities.Compatibility; import main.java.com.djrapitops.plan.Log; import main.java.com.djrapitops.plan.Plan; +import main.java.com.djrapitops.plan.PlanBungee; +import main.java.com.djrapitops.plan.api.IPlan; import main.java.com.djrapitops.plan.data.TPS; import main.java.com.djrapitops.plan.systems.processing.TPSInsertProcessor; import main.java.com.djrapitops.plan.utilities.MiscUtils; @@ -22,35 +25,41 @@ import java.util.List; */ public class TPSCountTimer extends AbsRunnable { - private final Plan plugin; + private final IPlan plugin; private final List history; private long lastCheckNano; + private final boolean usingBungee; + private int latestPlayersOnline = 0; - public TPSCountTimer(Plan plugin) { + public TPSCountTimer(IPlan plugin) { super("TPSCountTimer"); lastCheckNano = -1; this.plugin = plugin; history = new ArrayList<>(); + usingBungee = Compatibility.isBungeeAvailable(); } @Override public void run() { long nanoTime = System.nanoTime(); long now = MiscUtils.getTime(); - long diff = nanoTime - lastCheckNano; - lastCheckNano = nanoTime; + if (usingBungee) { + history.add(new TPS(now, -1, ((PlanBungee) plugin).getProxy().getOnlineCount(), -1, -1, -1, -1)); + } else { + long diff = nanoTime - lastCheckNano; - if (diff > nanoTime) { // First run's diff = nanoTime + 1, no calc possible. - Log.debug("First run of TPSCountTimer Task."); - return; + lastCheckNano = nanoTime; + + if (diff > nanoTime) { // First run's diff = nanoTime + 1, no calc possible. + Log.debug("First run of TPSCountTimer Task."); + return; + } + + history.add(calculateTPS(diff, now)); } - - TPS tps = calculateTPS(diff, now); - history.add(tps); - if (history.size() >= 60) { plugin.addToProcessQueue(new TPSInsertProcessor(new ArrayList<>(history))); history.clear(); @@ -78,7 +87,7 @@ public class TPSCountTimer extends AbsRunnable { long totalMemory = runtime.totalMemory(); long usedMemory = (totalMemory - runtime.freeMemory()) / 1000000; - int playersOnline = plugin.getServer().getOnlinePlayers().size(); + int playersOnline = ((Plan) plugin).getServer().getOnlinePlayers().size(); latestPlayersOnline = playersOnline; int loadedChunks = getLoadedChunks(); int entityCount; @@ -131,7 +140,7 @@ public class TPSCountTimer extends AbsRunnable { * @return the TPS */ private TPS getTPSPaper(long now, double cpuUsage, long usedMemory, int entityCount, int chunksLoaded, int playersOnline) { - double tps = plugin.getServer().getTPS()[0]; + double tps = ((Plan) plugin).getServer().getTPS()[0]; if (tps > 20) { tps = 20; @@ -148,7 +157,7 @@ public class TPSCountTimer extends AbsRunnable { * @return amount of loaded chunks */ private int getLoadedChunks() { - return plugin.getServer().getWorlds().stream().mapToInt(world -> world.getLoadedChunks().length).sum(); + return ((Plan) plugin).getServer().getWorlds().stream().mapToInt(world -> world.getLoadedChunks().length).sum(); } /** @@ -157,7 +166,7 @@ public class TPSCountTimer extends AbsRunnable { * @return amount of entities */ private int getEntityCount() { - return plugin.getServer().getWorlds().stream().mapToInt(world -> world.getEntities().size()).sum(); + return ((Plan) plugin).getServer().getWorlds().stream().mapToInt(world -> world.getEntities().size()).sum(); } /** @@ -166,7 +175,7 @@ public class TPSCountTimer extends AbsRunnable { * @return amount of entities */ private int getEntityCountPaper() { - return plugin.getServer().getWorlds().stream().mapToInt(World::getEntityCount).sum(); + return ((Plan) plugin).getServer().getWorlds().stream().mapToInt(World::getEntityCount).sum(); } public int getLatestPlayersOnline() {