From 90b9bcce2db2f49ca37dcba4610bac22eb249846 Mon Sep 17 00:00:00 2001
From: KyTDK <71435411+KyTDK@users.noreply.github.com>
Date: Thu, 29 Dec 2022 15:10:35 +1100
Subject: [PATCH] v1.14.4 - Plugin monitors current TPS and sends for analytics
---
LEGACY/pom.xml | 2 +-
LEGACY/target/maven-archiver/pom.properties | 4 +-
NONLEGACY/pom.xml | 2 +-
.../target/maven-archiver/pom.properties | 4 +-
abstraction/pom.xml | 2 +-
.../target/maven-archiver/pom.properties | 4 +-
api/pom.xml | 2 +-
.../neoperformance/NeoPerformance.java | 2 +
.../neoperformance/utils/Logger.java | 9 -
.../utils/config/ConfigUpdater.java | 246 ------------------
.../utils/resources/Memory.java | 8 -
api/target/classes/plugin.yml | 2 +-
pom.xml | 2 +-
13 files changed, 14 insertions(+), 275 deletions(-)
delete mode 100644 api/src/main/java/com/neomechanical/neoperformance/utils/config/ConfigUpdater.java
delete mode 100644 api/src/main/java/com/neomechanical/neoperformance/utils/resources/Memory.java
diff --git a/LEGACY/pom.xml b/LEGACY/pom.xml
index 3dd1f8c..7640b3a 100644
--- a/LEGACY/pom.xml
+++ b/LEGACY/pom.xml
@@ -5,7 +5,7 @@
com.neomechanical
NeoPerformance-parent
- 1.14.3
+ 1.14.4
4.0.0
NeoPerformance-LEGACY
diff --git a/LEGACY/target/maven-archiver/pom.properties b/LEGACY/target/maven-archiver/pom.properties
index b2d649e..63da028 100644
--- a/LEGACY/target/maven-archiver/pom.properties
+++ b/LEGACY/target/maven-archiver/pom.properties
@@ -1,5 +1,5 @@
#Generated by Maven
-#Wed Dec 28 15:54:53 AEDT 2022
-version=1.14.3
+#Thu Dec 29 15:07:15 AEDT 2022
+version=1.14.4
groupId=com.neomechanical
artifactId=NeoPerformance-LEGACY
diff --git a/NONLEGACY/pom.xml b/NONLEGACY/pom.xml
index fd9f92a..788ba91 100644
--- a/NONLEGACY/pom.xml
+++ b/NONLEGACY/pom.xml
@@ -5,7 +5,7 @@
com.neomechanical
NeoPerformance-parent
- 1.14.3
+ 1.14.4
4.0.0
NeoPerformance-NONLEGACY
diff --git a/NONLEGACY/target/maven-archiver/pom.properties b/NONLEGACY/target/maven-archiver/pom.properties
index ce76759..07d7a81 100644
--- a/NONLEGACY/target/maven-archiver/pom.properties
+++ b/NONLEGACY/target/maven-archiver/pom.properties
@@ -1,5 +1,5 @@
#Generated by Maven
-#Wed Dec 28 15:54:54 AEDT 2022
-version=1.14.3
+#Thu Dec 29 15:07:16 AEDT 2022
+version=1.14.4
groupId=com.neomechanical
artifactId=NeoPerformance-NONLEGACY
diff --git a/abstraction/pom.xml b/abstraction/pom.xml
index d237dc1..b4fa11f 100644
--- a/abstraction/pom.xml
+++ b/abstraction/pom.xml
@@ -15,7 +15,7 @@
com.neomechanical
NeoPerformance-parent
- 1.14.3
+ 1.14.4
NeoPerformance-abstraction
diff --git a/abstraction/target/maven-archiver/pom.properties b/abstraction/target/maven-archiver/pom.properties
index a0ff160..0e79c31 100644
--- a/abstraction/target/maven-archiver/pom.properties
+++ b/abstraction/target/maven-archiver/pom.properties
@@ -1,5 +1,5 @@
#Generated by Maven
-#Wed Dec 28 15:54:52 AEDT 2022
-version=1.14.3
+#Thu Dec 29 15:07:15 AEDT 2022
+version=1.14.4
groupId=com.neomechanical
artifactId=NeoPerformance-abstraction
diff --git a/api/pom.xml b/api/pom.xml
index b2f53c7..18fec4e 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -5,7 +5,7 @@
com.neomechanical
NeoPerformance-parent
- 1.14.3
+ 1.14.4
4.0.0
NeoPerformance
diff --git a/api/src/main/java/com/neomechanical/neoperformance/NeoPerformance.java b/api/src/main/java/com/neomechanical/neoperformance/NeoPerformance.java
index 0fc462a..4195cbe 100644
--- a/api/src/main/java/com/neomechanical/neoperformance/NeoPerformance.java
+++ b/api/src/main/java/com/neomechanical/neoperformance/NeoPerformance.java
@@ -18,6 +18,7 @@ import com.neomechanical.neoperformance.managers.DataHandler;
import com.neomechanical.neoperformance.performance.haltActions.RegisterHaltActions;
import com.neomechanical.neoperformance.performance.managers.DataManager;
import com.neomechanical.neoperformance.performance.performanceHeartBeat.HeartBeat;
+import com.neomechanical.neoperformance.performance.utils.TpsUtils;
import com.neomechanical.neoperformance.register.StartRegistering;
import com.neomechanical.neoperformance.utils.Logger;
import com.neomechanical.neoperformance.utils.updates.UpdateChecker;
@@ -123,6 +124,7 @@ public final class NeoPerformance extends JavaPlugin {
metrics = new Metrics(this, pluginId);
metrics.addCustomChart(new SimplePie("Language", () -> getLanguageManager().getLanguageCode()));
metrics.addCustomChart(new SimplePie("halt_at_tps", () -> String.valueOf(getDataManager().getTweakData().getTpsHaltAt())));
+ metrics.addCustomChart(new SimplePie("current_server_tps", () -> String.valueOf(TpsUtils.getTPS(this))));
}
@Override
diff --git a/api/src/main/java/com/neomechanical/neoperformance/utils/Logger.java b/api/src/main/java/com/neomechanical/neoperformance/utils/Logger.java
index 515f71f..7a46677 100644
--- a/api/src/main/java/com/neomechanical/neoperformance/utils/Logger.java
+++ b/api/src/main/java/com/neomechanical/neoperformance/utils/Logger.java
@@ -7,16 +7,7 @@ public class Logger {
public static void warn(String message) {
Bukkit.getLogger().warning(prefix + message);
}
-
public static void info(String message) {
Bukkit.getLogger().info(prefix + message);
}
-
- public static void severe(String message) {
- Bukkit.getLogger().severe(prefix + message);
- }
-
- public static void outdated() {
- Bukkit.getLogger().warning("[NeoPerformance] WARNING, PLUGIN IS EITHER OUTDATED OR NOT SUPPORTED ON THIS VERSION OF MINECRAFT");
- }
}
diff --git a/api/src/main/java/com/neomechanical/neoperformance/utils/config/ConfigUpdater.java b/api/src/main/java/com/neomechanical/neoperformance/utils/config/ConfigUpdater.java
deleted file mode 100644
index e6a6b95..0000000
--- a/api/src/main/java/com/neomechanical/neoperformance/utils/config/ConfigUpdater.java
+++ /dev/null
@@ -1,246 +0,0 @@
-package com.neomechanical.neoperformance.utils.config;
-
-import com.google.common.base.Preconditions;
-import com.neomechanical.neoconfig.neoutils.config.KeyBuilder;
-import com.neomechanical.neoperformance.utils.Logger;
-import org.bukkit.configuration.ConfigurationSection;
-import org.bukkit.configuration.file.FileConfiguration;
-import org.bukkit.configuration.file.YamlConfiguration;
-import org.bukkit.plugin.Plugin;
-
-import java.io.*;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.*;
-
-public class ConfigUpdater {
-
- //Used for separating keys in the keyBuilder inside parseComments method
- private static final char SEPARATOR = '.';
-
- public static void update(Plugin plugin, String resourceName, File toUpdate, String... ignoredSections) throws IOException {
- update(plugin, resourceName, toUpdate, Arrays.asList(ignoredSections));
- }
-
- public static void update(Plugin plugin, String resourceName, File toUpdate, List ignoredSections) throws IOException {
- Preconditions.checkArgument(toUpdate.exists(), "The toUpdate file doesn't exist!");
- if (plugin.getResource(resourceName) == null) {
- Logger.warn("The resource " + resourceName + " doesn't exist!");
- return;
- }
- FileConfiguration defaultConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(Objects.requireNonNull(plugin.getResource(resourceName)), StandardCharsets.UTF_8));
- FileConfiguration currentConfig = YamlConfiguration.loadConfiguration(toUpdate);
- Map comments = parseComments(plugin, resourceName, defaultConfig);
- Map ignoredSectionsValues = parseIgnoredSections(toUpdate, currentConfig, comments, ignoredSections == null ? Collections.emptyList() : ignoredSections);
-
- // will write updated config file "contents" to a string
- StringWriter writer = new StringWriter();
- write(defaultConfig, currentConfig, new BufferedWriter(writer), comments, ignoredSectionsValues);
- String value = writer.toString(); // config contents
-
- Path toUpdatePath = toUpdate.toPath();
- if (!value.equals(new String(Files.readAllBytes(toUpdatePath), StandardCharsets.UTF_8))) { // if updated contents are not the same as current file contents, update
- Files.write(toUpdatePath, value.getBytes(StandardCharsets.UTF_8));
- }
- }
-
- private static void write(FileConfiguration defaultConfig, FileConfiguration currentConfig, BufferedWriter writer, Map comments, Map ignoredSectionsValues) throws IOException {
- //Used for converting objects to yaml, then cleared
- FileConfiguration parserConfig = new YamlConfiguration();
-
- keyLoop: for (String fullKey : defaultConfig.getKeys(true)) {
- String indents = KeyBuilder.getIndents(fullKey, SEPARATOR);
-
- if (ignoredSectionsValues.isEmpty()) {
- writeCommentIfExists(comments, writer, fullKey, indents);
- } else {
- for (Map.Entry entry : ignoredSectionsValues.entrySet()) {
- if (entry.getKey().equals(fullKey)) {
- writer.write(ignoredSectionsValues.get(fullKey) + "\n");
- continue keyLoop;
- } else if (KeyBuilder.isSubKeyOf(entry.getKey(), fullKey, SEPARATOR)) {
- continue keyLoop;
- }
- }
-
- writeCommentIfExists(comments, writer, fullKey, indents);
- }
-
- Object currentValue = currentConfig.get(fullKey);
-
- if (currentValue == null)
- currentValue = defaultConfig.get(fullKey);
-
- String[] splitFullKey = fullKey.split("[" + SEPARATOR + "]");
- String trailingKey = splitFullKey[splitFullKey.length - 1];
-
- if (currentValue instanceof ConfigurationSection) {
- writer.write(indents + trailingKey + ":");
-
- if (!((ConfigurationSection) currentValue).getKeys(false).isEmpty())
- writer.write("\n");
- else
- writer.write(" {}\n");
-
- continue;
- }
-
- parserConfig.set(trailingKey, currentValue);
- String yaml = parserConfig.saveToString();
- yaml = yaml.substring(0, yaml.length() - 1).replace("\n", "\n" + indents);
- String toWrite = indents + yaml + "\n";
- parserConfig.set(trailingKey, null);
- writer.write(toWrite);
- }
-
- String danglingComments = comments.get(null);
-
- if (danglingComments != null)
- writer.write(danglingComments);
-
- writer.close();
- }
-
- //Returns a map of key comment pairs. If a key doesn't have any comments it won't be included in the map.
- private static Map parseComments(Plugin plugin, String resourceName, FileConfiguration defaultConfig) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(plugin.getResource(resourceName)));
- Map comments = new LinkedHashMap<>();
- StringBuilder commentBuilder = new StringBuilder();
- KeyBuilder keyBuilder = new KeyBuilder(defaultConfig, SEPARATOR);
-
- String line;
- while ((line = reader.readLine()) != null) {
- String trimmedLine = line.trim();
-
- //Only getting comments for keys. A list/array element comment(s) not supported
- if (trimmedLine.startsWith("-")) {
- continue;
- }
-
- if (trimmedLine.isEmpty() || trimmedLine.startsWith("#")) {//Is blank line or is comment
- commentBuilder.append(trimmedLine).append("\n");
- } else {//is a valid yaml key
- keyBuilder.parseLine(trimmedLine);
- String key = keyBuilder.toString();
-
- //If there is a comment associated with the key it is added to comments map and the commentBuilder is reset
- if (commentBuilder.length() > 0) {
- comments.put(key, commentBuilder.toString());
- commentBuilder.setLength(0);
- }
-
- //Remove the last key from keyBuilder if current path isn't a config section or if it is empty to prepare for the next key
- if (!keyBuilder.isConfigSectionWithKeys()) {
- keyBuilder.removeLastKey();
- }
- }
- }
-
- reader.close();
-
- if (commentBuilder.length() > 0)
- comments.put(null, commentBuilder.toString());
-
- return comments;
- }
-
- private static Map parseIgnoredSections(File toUpdate, FileConfiguration currentConfig, Map comments, List ignoredSections) throws IOException {
- BufferedReader reader = new BufferedReader(new FileReader(toUpdate));
- Map ignoredSectionsValues = new LinkedHashMap<>(ignoredSections.size());
- KeyBuilder keyBuilder = new KeyBuilder(currentConfig, SEPARATOR);
- StringBuilder valueBuilder = new StringBuilder();
-
- String currentIgnoredSection = null;
- String line;
- lineLoop : while ((line = reader.readLine()) != null) {
- String trimmedLine = line.trim();
-
- if (trimmedLine.isEmpty() || trimmedLine.startsWith("#"))
- continue;
-
- if (trimmedLine.startsWith("-")) {
- for (String ignoredSection : ignoredSections) {
- boolean isIgnoredParent = ignoredSection.equals(keyBuilder.toString());
-
- if (isIgnoredParent || keyBuilder.isSubKeyOf(ignoredSection)) {
- valueBuilder.append("\n").append(line);
- continue lineLoop;
- }
- }
- }
-
- keyBuilder.parseLine(trimmedLine);
- String fullKey = keyBuilder.toString();
-
- //If building the value for an ignored section and this line is no longer a part of the ignored section,
- // write the valueBuilder, reset it, and set the current ignored section to null
- if (currentIgnoredSection != null && !KeyBuilder.isSubKeyOf(currentIgnoredSection, fullKey, SEPARATOR)) {
- ignoredSectionsValues.put(currentIgnoredSection, valueBuilder.toString());
- valueBuilder.setLength(0);
- currentIgnoredSection = null;
- }
-
- for (String ignoredSection : ignoredSections) {
- boolean isIgnoredParent = ignoredSection.equals(fullKey);
-
- if (isIgnoredParent || keyBuilder.isSubKeyOf(ignoredSection)) {
- if (valueBuilder.length() > 0)
- valueBuilder.append("\n");
-
- String comment = comments.get(fullKey);
-
- if (comment != null) {
- String indents = KeyBuilder.getIndents(fullKey, SEPARATOR);
- valueBuilder.append(indents).append(comment.replace("\n", "\n" + indents));//Should end with new line (\n)
- valueBuilder.setLength(valueBuilder.length() - indents.length());//Get rid of trailing \n and spaces
- }
-
- valueBuilder.append(line);
-
- //Set the current ignored section for future iterations of while loop
- //Don't set currentIgnoredSection to any ignoredSection sub-keys
- if (isIgnoredParent)
- currentIgnoredSection = fullKey;
-
- break;
- }
- }
- }
-
- reader.close();
-
- if (valueBuilder.length() > 0)
- ignoredSectionsValues.put(currentIgnoredSection, valueBuilder.toString());
-
- return ignoredSectionsValues;
- }
-
- private static void writeCommentIfExists(Map comments, BufferedWriter writer, String fullKey, String indents) throws IOException {
- String comment = comments.get(fullKey);
-
- //Comments always end with new line (\n)
- if (comment != null)
- //Replaces all '\n' with '\n' + indents except for the last one
- writer.write(indents + comment.substring(0, comment.length() - 1).replace("\n", "\n" + indents) + "\n");
- }
-
- //Input: 'key1.key2' Result: 'key1'
- private static void removeLastKey(StringBuilder keyBuilder) {
- if (keyBuilder.length() == 0)
- return;
-
- String keyString = keyBuilder.toString();
- //Must be enclosed in brackets in case a regex special character is the separator
- String[] split = keyString.split("[" + SEPARATOR + "]");
- //Makes sure begin index isn't < 0 (error). Occurs when there is only one key in the path
- int minIndex = Math.max(0, keyBuilder.length() - split[split.length - 1].length() - 1);
- keyBuilder.replace(minIndex, keyBuilder.length(), "");
- }
-
- private static void appendNewLine(StringBuilder builder) {
- if (builder.length() > 0)
- builder.append("\n");
- }
-
-}
\ No newline at end of file
diff --git a/api/src/main/java/com/neomechanical/neoperformance/utils/resources/Memory.java b/api/src/main/java/com/neomechanical/neoperformance/utils/resources/Memory.java
deleted file mode 100644
index 89e6da3..0000000
--- a/api/src/main/java/com/neomechanical/neoperformance/utils/resources/Memory.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.neomechanical.neoperformance.utils.resources;
-
-public class Memory {
- public static long getMemory() {
- Runtime r = Runtime.getRuntime();
- return (r.totalMemory() - r.freeMemory()) / 1048576;
- }
-}
diff --git a/api/target/classes/plugin.yml b/api/target/classes/plugin.yml
index f35c3fc..49f93d6 100644
--- a/api/target/classes/plugin.yml
+++ b/api/target/classes/plugin.yml
@@ -1,5 +1,5 @@
name: NeoPerformance
-version: '1.14.3'
+version: '1.14.4'
main: com.neomechanical.neoperformance.NeoPerformance
load: POSTWORLD
authors:
diff --git a/pom.xml b/pom.xml
index c05c1dd..db3cc35 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
4.0.0
com.neomechanical
NeoPerformance-parent
- 1.14.3
+ 1.14.4
pom
NeoPerformance