* An exception from that rule is when the country is unknown or the retrieval of the country failed in any way, - * if that happens, the phrase for unknown country set in the config will be returned. + * if that happens, "Not Known" will be returned. * @see #getUncachedCountry(String) */ public static String getCountry(String ipAddress) { @@ -64,7 +65,7 @@ public class GeolocationCacheHandler { * @return The name of the country in full length. *
* An exception from that rule is when the country is unknown or the retrieval of the country failed in any way,
- * if that happens, the phrase for unknown country set in the config will be returned.
+ * if that happens, "Not Known" will be returned.
* @see http://freegeoip.net
* @see #getCountry(String)
*/
diff --git a/Plan/src/main/java/com/djrapitops/plan/data/cache/InspectCacheHandler.java b/Plan/src/main/java/com/djrapitops/plan/data/cache/InspectCacheHandler.java
index 6a3d3c384..e1c454255 100644
--- a/Plan/src/main/java/com/djrapitops/plan/data/cache/InspectCacheHandler.java
+++ b/Plan/src/main/java/com/djrapitops/plan/data/cache/InspectCacheHandler.java
@@ -55,6 +55,7 @@ public class InspectCacheHandler {
}
}
};
+
handler.getUserDataForProcessing(cacher, uuid, false);
}
@@ -103,10 +104,7 @@ public class InspectCacheHandler {
* @return -1 when not cached or Epoch millisecond.
*/
public long getCacheTime(UUID uuid) {
- if (cacheTimes.containsKey(uuid)) {
- return cacheTimes.get(uuid);
- }
- return -1;
+ return cacheTimes.getOrDefault(uuid, -1L);
}
/**
diff --git a/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanCommandPreprocessListener.java b/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanCommandPreprocessListener.java
index 855d7f8a2..143997743 100644
--- a/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanCommandPreprocessListener.java
+++ b/Plan/src/main/java/com/djrapitops/plan/data/listeners/PlanCommandPreprocessListener.java
@@ -5,12 +5,12 @@ import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
+import org.bukkit.command.Command;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
-import org.bukkit.help.HelpMap;
/**
* Event Listener for PlayerCommandPreprocessEvents.
@@ -43,13 +43,20 @@ public class PlanCommandPreprocessListener implements Listener {
return;
}
- String cmd = event.getMessage().split(" ")[0].toLowerCase();
+ String commandName = event.getMessage().split(" ")[0].toLowerCase();
- if (Settings.DO_NOT_LOG_UNKNOWN_COMMANDS.isTrue()) {
- HelpMap helpMap = plugin.getServer().getHelpMap();
- if (helpMap.getHelpTopic(cmd) == null) {
- Log.debug("Ignored command, command is unknown");
- return;
+ boolean doNotLogUnknownCommands = Settings.DO_NOT_LOG_UNKNOWN_COMMANDS.isTrue();
+ boolean combineCommandAliasesToMainCommand = Settings.COMBINE_COMMAND_ALIASES_TO_MAIN_COMMAND.isTrue();
+
+ if (doNotLogUnknownCommands || combineCommandAliasesToMainCommand) {
+ Command command = plugin.getServer().getPluginCommand(commandName);
+ if (command == null) {
+ if (doNotLogUnknownCommands) {
+ Log.debug("Ignored command, command is unknown");
+ return;
+ }
+ } else if (combineCommandAliasesToMainCommand) {
+ commandName = command.getName();
}
}
@@ -59,6 +66,6 @@ public class PlanCommandPreprocessListener implements Listener {
Log.debug("Ignored command, player had ignore permission.");
return;
}
- handler.handleCommand(cmd);
+ handler.handleCommand(commandName);
}
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/data/listeners/TPSCountTimer.java b/Plan/src/main/java/com/djrapitops/plan/data/listeners/TPSCountTimer.java
index 6bb384504..ce848b8d2 100644
--- a/Plan/src/main/java/com/djrapitops/plan/data/listeners/TPSCountTimer.java
+++ b/Plan/src/main/java/com/djrapitops/plan/data/listeners/TPSCountTimer.java
@@ -7,7 +7,10 @@ import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.TPS;
import main.java.com.djrapitops.plan.data.cache.DataCacheHandler;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
+import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
+import java.lang.management.ManagementFactory;
+import java.lang.management.OperatingSystemMXBean;
import java.util.ArrayList;
import java.util.List;
@@ -36,32 +39,87 @@ public class TPSCountTimer extends AbsRunnable {
long nanoTime = System.nanoTime();
long now = MiscUtils.getTime();
long diff = nanoTime - lastCheckNano;
+
lastCheckNano = nanoTime;
+
if (diff > nanoTime) { // First run's diff = nanoTime + 1, no calc possible.
Log.debug("First run of TPSCountTimer Task.");
return;
}
- diff -= TimeAmount.MILLISECOND.ns() * 40L; // 40ms removed because the run appears to take 40-50ms, screwing the tps.
+
TPS tps = calculateTPS(diff, now);
history.add(tps);
+
if (history.size() >= 60) {
handler.addTPSLastMinute(history);
history.clear();
}
}
- public TPS calculateTPS(long diff, long now) {
+ /**
+ * Calculates the TPS
+ *
+ * @param diff The time difference between the last run and the new run
+ * @param now The time right now
+ * @return the TPS
+ */
+ private TPS calculateTPS(long diff, long now) {
+ OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
+ int availableProcessors = ManagementFactory.getOperatingSystemMXBean().getAvailableProcessors();
+ final double averageCPUUsage = MathUtils.round(operatingSystemMXBean.getSystemLoadAverage() / availableProcessors * 100.0);
+
+ int playersOnline = plugin.getServer().getOnlinePlayers().size();
+
+ if (plugin.getVariable().isUsingPaper()) {
+ return getTPSPaper(now, averageCPUUsage, playersOnline);
+ } else {
+ diff -= TimeAmount.MILLISECOND.ns() * 40L; // 40ms removed because the run appears to take 40-50ms, screwing the tps.
+ return getTPS(diff, now, averageCPUUsage, playersOnline);
+ }
+ }
+
+ /**
+ * Gets the TPS for Paper
+ *
+ * @param now The time right now
+ * @param cpuUsage The usage of the CPU
+ * @param playersOnline The amount of players that are online
+ * @return the TPS
+ */
+ private TPS getTPSPaper(long now, double cpuUsage, int playersOnline) {
+ double tps = plugin.getServer().getTPS()[0];
+
+ if (tps > 20) {
+ tps = 20;
+ }
+
+ tps = MathUtils.round(tps);
+
+ return new TPS(now, tps, playersOnline, cpuUsage);
+ }
+
+ /**
+ * Gets the TPS for a Spigot / Bukkit
+ *
+ * @param diff The difference between the last run and this run
+ * @param now The time right now
+ * @param cpuUsage The usage of the CPU
+ * @param playersOnline The amount of players that are online
+ * @return the TPS
+ */
+ private TPS getTPS(long diff, long now, double cpuUsage, int playersOnline) {
if (diff < TimeAmount.SECOND.ns()) { // No tick count above 20
diff = TimeAmount.SECOND.ns();
}
- int playersOnline = plugin.getServer().getOnlinePlayers().size();
+
long twentySeconds = 20L * TimeAmount.SECOND.ns();
while (diff > twentySeconds) {
- history.add(new TPS(now, 0, playersOnline));
+ history.add(new TPS(now, 0, playersOnline, cpuUsage));
diff -= twentySeconds;
}
+
double tpsN = twentySeconds / diff;
- return new TPS(now, tpsN, playersOnline);
+ return new TPS(now, tpsN, playersOnline, cpuUsage);
}
}
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 2bcfa3fe5..e387c26bc 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
@@ -1,11 +1,6 @@
package main.java.com.djrapitops.plan.database.tables;
import com.djrapitops.plugin.api.TimeAmount;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.data.TPS;
import main.java.com.djrapitops.plan.database.DBUtils;
@@ -13,6 +8,12 @@ import main.java.com.djrapitops.plan.database.databases.SQLDB;
import main.java.com.djrapitops.plan.utilities.Benchmark;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Class representing database table plan_tps
*
@@ -24,6 +25,7 @@ public class TPSTable extends Table {
private final String columnDate;
private final String columnTPS;
private final String columnPlayers;
+ private final String columnCPUUsage;
/**
*
@@ -35,6 +37,7 @@ public class TPSTable extends Table {
columnDate = "date";
columnTPS = "tps";
columnPlayers = "players_online";
+ columnCPUUsage = "cpu_usage";
}
@Override
@@ -43,7 +46,8 @@ public class TPSTable extends Table {
execute("CREATE TABLE IF NOT EXISTS " + tableName + " ("
+ columnDate + " bigint NOT NULL, "
+ columnTPS + " double NOT NULL, "
- + columnPlayers + " integer NOT NULL"
+ + columnPlayers + " integer NOT NULL, "
+ + columnCPUUsage + " double NOT NULL"
+ ")"
);
return true;
@@ -69,7 +73,8 @@ public class TPSTable extends Table {
long date = set.getLong(columnDate);
double tps = set.getDouble(columnTPS);
int players = set.getInt(columnPlayers);
- data.add(new TPS(date, tps, players));
+ double cpuUsage = set.getDouble(columnCPUUsage);
+ data.add(new TPS(date, tps, players, cpuUsage));
}
return data;
} finally {
@@ -97,8 +102,9 @@ public class TPSTable extends Table {
statement = prepareStatement("INSERT INTO " + tableName + " ("
+ columnDate + ", "
+ columnTPS + ", "
- + columnPlayers
- + ") VALUES (?, ?, ?)");
+ + columnPlayers + ", "
+ + columnCPUUsage
+ + ") VALUES (?, ?, ?, ?)");
boolean commitRequired = false;
int i = 0;
@@ -106,6 +112,7 @@ public class TPSTable extends Table {
statement.setLong(1, tps.getDate());
statement.setDouble(2, tps.getTps());
statement.setInt(3, tps.getPlayers());
+ statement.setDouble(4, tps.getCPUUsage());
statement.addBatch();
commitRequired = true;
i++;
diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/PunchCardGraphCreator.java b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/PunchCardGraphCreator.java
index c64d64887..07ac32a9a 100644
--- a/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/PunchCardGraphCreator.java
+++ b/Plan/src/main/java/com/djrapitops/plan/ui/html/graphs/PunchCardGraphCreator.java
@@ -47,7 +47,7 @@ public class PunchCardGraphCreator {
continue;
}
arrayBuilder.append("{").append("x:").append(j).append(", y:").append(i).append(", r:").append(value).append("}");
- if (!(i == 6 && j == 23)) {
+ if (i != 6 || j != 23) {
arrayBuilder.append(",");
}
}
diff --git a/Plan/src/main/java/com/djrapitops/plan/ui/text/TextUI.java b/Plan/src/main/java/com/djrapitops/plan/ui/text/TextUI.java
index c3d8667a7..d6b37c168 100644
--- a/Plan/src/main/java/com/djrapitops/plan/ui/text/TextUI.java
+++ b/Plan/src/main/java/com/djrapitops/plan/ui/text/TextUI.java
@@ -1,16 +1,10 @@
package main.java.com.djrapitops.plan.ui.text;
-import java.util.UUID;
import main.java.com.djrapitops.plan.Phrase;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.data.AnalysisData;
import main.java.com.djrapitops.plan.data.UserData;
-import main.java.com.djrapitops.plan.data.analysis.ActivityPart;
-import main.java.com.djrapitops.plan.data.analysis.JoinInfoPart;
-import main.java.com.djrapitops.plan.data.analysis.KillPart;
-import main.java.com.djrapitops.plan.data.analysis.PlayerCountPart;
-import main.java.com.djrapitops.plan.data.analysis.PlaytimePart;
-import main.java.com.djrapitops.plan.data.analysis.TPSPart;
+import main.java.com.djrapitops.plan.data.analysis.*;
import main.java.com.djrapitops.plan.data.cache.AnalysisCacheHandler;
import main.java.com.djrapitops.plan.data.cache.InspectCacheHandler;
import main.java.com.djrapitops.plan.utilities.FormatUtils;
@@ -19,6 +13,8 @@ import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils;
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
import org.bukkit.ChatColor;
+import java.util.UUID;
+
/**
*
* @author Rsl1122
@@ -68,7 +64,6 @@ public class TextUI {
AnalysisData d = analysisCache.getData();
ChatColor main = Phrase.COLOR_MAIN.color();
ChatColor sec = Phrase.COLOR_SEC.color();
- ChatColor ter = Phrase.COLOR_TER.color();
String ball = sec + " " + Phrase.BALL + main;
final ActivityPart activity = d.getActivityPart();
final JoinInfoPart join = d.getJoinInfoPart();
diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/AnalysisUtils.java b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/AnalysisUtils.java
index ff26d3894..b745e775b 100644
--- a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/AnalysisUtils.java
+++ b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/AnalysisUtils.java
@@ -247,10 +247,10 @@ public class AnalysisUtils {
continue;
}
}
+
int day = getDayOfYear(session);
- if (!uniqueJoins.containsKey(day)) {
- uniqueJoins.put(day, new HashSet<>());
- }
+
+ uniqueJoins.computeIfAbsent(day, computedDay -> new HashSet<>());
uniqueJoins.get(day).add(uuid);
}
});
diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/MathUtils.java b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/MathUtils.java
index 7a37ba76e..1381e7551 100644
--- a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/MathUtils.java
+++ b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/MathUtils.java
@@ -8,89 +8,104 @@ import java.util.OptionalLong;
import java.util.stream.Stream;
/**
- *
* @author Rsl1122
*/
public class MathUtils {
/**
+ * Gets the average of a Stream of Integers.
+ * If there are no components in the Stream, it will return 0.
*
- * @param values
- * @return
+ * @param values The Stream of Integers.
+ * @return The average
*/
public static double averageInt(Stream