From 2c0addaaac667916b30d5464e0c80b05f641cabd Mon Sep 17 00:00:00 2001 From: mathias Date: Fri, 13 Aug 2021 11:28:58 +0200 Subject: [PATCH 01/10] Updated the plugin version to 1.4 --- pom.xml | 2 +- src/main/resources/plugin.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index df81a4a7..5e620280 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ de.gnmyt MCDash - 1.0.3 + 1.0.4 8 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 9cc083cc..d778a60d 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: MinecraftDashboard main: de.gnmyt.mcdash.MinecraftDashboard -version: 1.0-SNAPSHOT +version: 1.4 description: This is the official plugin (wrapper) for MCDash, a free and open-source minecraft dashboard. author: GNMYT \ No newline at end of file From 330429664d3c000a594a81aaa60cafe630ee8447 Mon Sep 17 00:00:00 2001 From: mathias Date: Fri, 13 Aug 2021 11:31:19 +0200 Subject: [PATCH 02/10] Updated a value in the .gitignore file --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c07eaf28..85b3ddee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ .idea -MinecraftDashboard.iml +MCDash.iml.iml /target/ \ No newline at end of file From 4bae0142f940465c476a7de018a5eb259b568258 Mon Sep 17 00:00:00 2001 From: mathias Date: Fri, 13 Aug 2021 13:23:23 +0200 Subject: [PATCH 03/10] Fixed typo in .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 85b3ddee..b9388916 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ .idea -MCDash.iml.iml +MCDash.iml /target/ \ No newline at end of file From b2fd97f2017d7c2a3d0d642419c12d4f2cd7c708 Mon Sep 17 00:00:00 2001 From: mathias Date: Fri, 13 Aug 2021 13:44:48 +0200 Subject: [PATCH 04/10] Added the TPSRunnable --- .../gnmyt/mcdash/api/tasks/TPSRunnable.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/main/java/de/gnmyt/mcdash/api/tasks/TPSRunnable.java diff --git a/src/main/java/de/gnmyt/mcdash/api/tasks/TPSRunnable.java b/src/main/java/de/gnmyt/mcdash/api/tasks/TPSRunnable.java new file mode 100644 index 00000000..ecb241d2 --- /dev/null +++ b/src/main/java/de/gnmyt/mcdash/api/tasks/TPSRunnable.java @@ -0,0 +1,47 @@ +package de.gnmyt.mcdash.api.tasks; + +public class TPSRunnable implements Runnable { + + public int tick_count = 0; + public long[] ticks = new long[600]; + + /** + * Updates the tick variables + */ + @Override + public void run() { + ticks[(tick_count % ticks.length)] = System.currentTimeMillis(); + tick_count++; + } + + /** + * Gets the current tps of the server + * @return the current tps of the server + */ + public double getCurrentTPS() { + return getCurrentTPS(100); + } + + /** + * Gets the current tps of the server + * @param ticks The amount of ticks + * @return the current tps of the server + */ + public double getCurrentTPS(int ticks) { + if (tick_count< ticks) return 20.0D; + + int target = (tick_count-ticks-1) % this.ticks.length; + long elapsed = System.currentTimeMillis() - this.ticks[target]; + + return ticks / (elapsed / 1000.0D); + } + + /** + * Gets the tps of the server (rounded) + * @return the tps of the server (rounded) + */ + public long getCurrentRoundedTPS() { + return Math.round(getCurrentTPS()); + } + +} From d52a9dbe377356f0d8fa54c45594a4ebf8ee35df Mon Sep 17 00:00:00 2001 From: mathias Date: Fri, 13 Aug 2021 13:48:29 +0200 Subject: [PATCH 05/10] Created the StatsController & integrated the TPSRunnable into the StatsController --- .../api/controller/StatsController.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/main/java/de/gnmyt/mcdash/api/controller/StatsController.java diff --git a/src/main/java/de/gnmyt/mcdash/api/controller/StatsController.java b/src/main/java/de/gnmyt/mcdash/api/controller/StatsController.java new file mode 100644 index 00000000..84a852d5 --- /dev/null +++ b/src/main/java/de/gnmyt/mcdash/api/controller/StatsController.java @@ -0,0 +1,41 @@ +package de.gnmyt.mcdash.api.controller; + +import de.gnmyt.mcdash.MinecraftDashboard; +import de.gnmyt.mcdash.api.tasks.TPSRunnable; +import org.bukkit.Bukkit; + +import java.io.File; + +public class StatsController { + + private final File SERVER_FOLDER = new File("."); + private final TPSRunnable TPS_RUNNABLE = new TPSRunnable(); + + private MinecraftDashboard instance; + + /** + * Basic constructor of the {@link StatsController} + * @param instance The main instance of the plugin + */ + public StatsController(MinecraftDashboard instance) { + this.instance = instance; + startTPSRunnable(); + } + + /** + * Starts the {@link TPSRunnable} + * The runnable gets the current tps from the server + */ + private void startTPSRunnable() { + Bukkit.getScheduler().scheduleSyncRepeatingTask(instance, TPS_RUNNABLE, 0, 1); + } + + /** + * Gets the current tps + * @return the current tps + */ + public long getTPS() { + return TPS_RUNNABLE.getCurrentRoundedTPS(); + } + +} From a54b06140ce7f73bb2ca60e9d48220afa5dc7760 Mon Sep 17 00:00:00 2001 From: mathias Date: Fri, 13 Aug 2021 13:53:04 +0200 Subject: [PATCH 06/10] Added memory related methods to the StatsController --- .../api/controller/StatsController.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/de/gnmyt/mcdash/api/controller/StatsController.java b/src/main/java/de/gnmyt/mcdash/api/controller/StatsController.java index 84a852d5..fd8cea46 100644 --- a/src/main/java/de/gnmyt/mcdash/api/controller/StatsController.java +++ b/src/main/java/de/gnmyt/mcdash/api/controller/StatsController.java @@ -38,4 +38,28 @@ public long getTPS() { return TPS_RUNNABLE.getCurrentRoundedTPS(); } + /** + * Gets the amount of free memory in the jvm + * @return the amount of free memory in the jvm + */ + public long getFreeMemory() { + return Runtime.getRuntime().freeMemory(); + } + + /** + * Gets the maximum amount of memory that the jvm will use + * @return the maximum amount of memory that the jvm will use + */ + public long getTotalMemory() { + return Runtime.getRuntime().totalMemory(); + } + + /** + * Gets the used amount of memory from the jvm + * @return the used amount of memory from the jvm + */ + public long getUsedMemory() { + return getTotalMemory() - getFreeMemory(); + } + } From 3a317c39de008d9a7d864488a564e8c32563d5ef Mon Sep 17 00:00:00 2001 From: mathias Date: Fri, 13 Aug 2021 13:56:07 +0200 Subject: [PATCH 07/10] Added storage related methods to the StatsController --- .../api/controller/StatsController.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/de/gnmyt/mcdash/api/controller/StatsController.java b/src/main/java/de/gnmyt/mcdash/api/controller/StatsController.java index fd8cea46..2350b643 100644 --- a/src/main/java/de/gnmyt/mcdash/api/controller/StatsController.java +++ b/src/main/java/de/gnmyt/mcdash/api/controller/StatsController.java @@ -62,4 +62,28 @@ public long getUsedMemory() { return getTotalMemory() - getFreeMemory(); } + /** + * Gets the total amount of space from the server + * @return the total amount space from the server + */ + public long getTotalSpace() { + return SERVER_FOLDER.getTotalSpace(); + } + + /** + * Gets the free amount of space from the server + * @return the free amount of space from the server + */ + public long getFreeSpace() { + return SERVER_FOLDER.getFreeSpace(); + } + + /** + * Gets the used amount of space from the server + * @return the used amount of space from the server + */ + public long getUsedSpace() { + return getTotalSpace() - getFreeSpace(); + } + } From 8ee26ed034ab2a94bc8ea775004339c25a898698 Mon Sep 17 00:00:00 2001 From: mathias Date: Fri, 13 Aug 2021 14:01:44 +0200 Subject: [PATCH 08/10] Added processor related methods to the StatsController --- .../de/gnmyt/mcdash/api/controller/StatsController.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/de/gnmyt/mcdash/api/controller/StatsController.java b/src/main/java/de/gnmyt/mcdash/api/controller/StatsController.java index 2350b643..55c91ccc 100644 --- a/src/main/java/de/gnmyt/mcdash/api/controller/StatsController.java +++ b/src/main/java/de/gnmyt/mcdash/api/controller/StatsController.java @@ -86,4 +86,12 @@ public long getUsedSpace() { return getTotalSpace() - getFreeSpace(); } + /** + * Gets the total amount of processors available to the server + * @return the total amount of processors available to the server + */ + public long getAvailableProcessors() { + return Runtime.getRuntime().availableProcessors(); + } + } From 76c2e77455730f2028e1e4613b1a97247f5e8a0f Mon Sep 17 00:00:00 2001 From: mathias Date: Fri, 13 Aug 2021 14:11:44 +0200 Subject: [PATCH 09/10] Added the stats route --- .../mcdash/panel/routes/stats/StatsRoute.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/main/java/de/gnmyt/mcdash/panel/routes/stats/StatsRoute.java diff --git a/src/main/java/de/gnmyt/mcdash/panel/routes/stats/StatsRoute.java b/src/main/java/de/gnmyt/mcdash/panel/routes/stats/StatsRoute.java new file mode 100644 index 00000000..fafccc49 --- /dev/null +++ b/src/main/java/de/gnmyt/mcdash/panel/routes/stats/StatsRoute.java @@ -0,0 +1,19 @@ +package de.gnmyt.mcdash.panel.routes.stats; + +import de.gnmyt.mcdash.MinecraftDashboard; +import de.gnmyt.mcdash.api.controller.StatsController; +import de.gnmyt.mcdash.api.handler.DefaultHandler; +import de.gnmyt.mcdash.api.http.Request; +import de.gnmyt.mcdash.api.http.ResponseController; + +public class StatsRoute extends DefaultHandler { + + private final StatsController STATS = new StatsController(MinecraftDashboard.getInstance()); + + @Override + public void get(Request request, ResponseController response) throws Exception { + response.json("tps="+STATS.getTPS(), "processors="+STATS.getAvailableProcessors(), + "free_memory="+STATS.getFreeMemory(), "total_memory="+STATS.getTotalMemory(), "used_memory="+STATS.getUsedMemory(), + "free_space="+STATS.getFreeSpace(), "total_space="+STATS.getTotalSpace(), "used_space="+STATS.getUsedSpace()); + } +} From 308347b395b920aae9ba7ae2d71d0c395e491b89 Mon Sep 17 00:00:00 2001 From: mathias Date: Fri, 13 Aug 2021 20:57:03 +0200 Subject: [PATCH 10/10] Added a comment to the stats route --- .../de/gnmyt/mcdash/panel/routes/stats/StatsRoute.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/gnmyt/mcdash/panel/routes/stats/StatsRoute.java b/src/main/java/de/gnmyt/mcdash/panel/routes/stats/StatsRoute.java index fafccc49..fc1d9979 100644 --- a/src/main/java/de/gnmyt/mcdash/panel/routes/stats/StatsRoute.java +++ b/src/main/java/de/gnmyt/mcdash/panel/routes/stats/StatsRoute.java @@ -10,8 +10,13 @@ public class StatsRoute extends DefaultHandler { private final StatsController STATS = new StatsController(MinecraftDashboard.getInstance()); + /** + * Gets the current server statistics such as the tps, processors, memory and the space + * @param request The request object from the HttpExchange + * @param response The response controller from the HttpExchange + */ @Override - public void get(Request request, ResponseController response) throws Exception { + public void get(Request request, ResponseController response) { response.json("tps="+STATS.getTPS(), "processors="+STATS.getAvailableProcessors(), "free_memory="+STATS.getFreeMemory(), "total_memory="+STATS.getTotalMemory(), "used_memory="+STATS.getUsedMemory(), "free_space="+STATS.getFreeSpace(), "total_space="+STATS.getTotalSpace(), "used_space="+STATS.getUsedSpace());