aboutsummaryrefslogtreecommitdiff
path: root/spark-bukkit/src/main
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2022-06-11 21:05:08 +0100
committerLuck <git@lucko.me>2022-06-11 21:08:29 +0100
commita551317a0acc0f6ccb2d1bb66e8475b42387e59c (patch)
treed59ecc067c27a77b0662d5813051cbbb8e3b39a5 /spark-bukkit/src/main
parent0ac8713eaaefe7336db2e0369bbe547dc6c0da7d (diff)
downloadspark-a551317a0acc0f6ccb2d1bb66e8475b42387e59c.tar.gz
spark-a551317a0acc0f6ccb2d1bb66e8475b42387e59c.tar.bz2
spark-a551317a0acc0f6ccb2d1bb66e8475b42387e59c.zip
Tidy up placeholder handling
Co-authored-by: Caden Kriese <armrest.trimmer.00@icloud.com>
Diffstat (limited to 'spark-bukkit/src/main')
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkMVdWPlaceholders.java3
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderApi.java3
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderProvider.java123
3 files changed, 4 insertions, 125 deletions
diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkMVdWPlaceholders.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkMVdWPlaceholders.java
index 078d027..7fa6e02 100644
--- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkMVdWPlaceholders.java
+++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkMVdWPlaceholders.java
@@ -22,6 +22,7 @@ package me.lucko.spark.bukkit.placeholder;
import me.lucko.spark.bukkit.BukkitSparkPlugin;
import me.lucko.spark.common.SparkPlatform;
+import me.lucko.spark.common.util.SparkPlaceholder;
import be.maximvdw.placeholderapi.PlaceholderAPI;
import be.maximvdw.placeholderapi.PlaceholderReplaceEvent;
@@ -43,6 +44,6 @@ public class SparkMVdWPlaceholders implements PlaceholderReplacer {
}
String identifier = placeholder.substring("spark_".length());
- return SparkPlaceholderProvider.respond(this.platform, identifier);
+ return SparkPlaceholder.resolveFormattingCode(this.platform, identifier);
}
}
diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderApi.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderApi.java
index 69dca72..b3919dd 100644
--- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderApi.java
+++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderApi.java
@@ -23,6 +23,7 @@ package me.lucko.spark.bukkit.placeholder;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import me.lucko.spark.bukkit.BukkitSparkPlugin;
import me.lucko.spark.common.SparkPlatform;
+import me.lucko.spark.common.util.SparkPlaceholder;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
@@ -44,7 +45,7 @@ public class SparkPlaceholderApi extends PlaceholderExpansion {
@Override
public String onRequest(OfflinePlayer p, String params) {
- return SparkPlaceholderProvider.respond(this.platform, params);
+ return SparkPlaceholder.resolveFormattingCode(this.platform, params);
}
@Override
diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderProvider.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderProvider.java
deleted file mode 100644
index 5b57857..0000000
--- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderProvider.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * This file is part of spark.
- *
- * Copyright (c) lucko (Luck) <luck@lucko.me>
- * Copyright (c) contributors
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package me.lucko.spark.bukkit.placeholder;
-
-import me.lucko.spark.common.SparkPlatform;
-import me.lucko.spark.common.monitor.cpu.CpuMonitor;
-import me.lucko.spark.common.monitor.tick.TickStatistics;
-import me.lucko.spark.common.util.StatisticFormatter;
-
-import net.kyori.adventure.text.Component;
-import net.kyori.adventure.text.TextComponent;
-import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
-
-enum SparkPlaceholderProvider {
- ;
-
- public static TextComponent respondComponent(SparkPlatform platform, String placeholder) {
- if (placeholder.startsWith("tps")) {
- TickStatistics tickStatistics = platform.getTickStatistics();
- if (tickStatistics == null) {
- return null;
- }
-
- switch (placeholder) {
- case "tps":
- return Component.text()
- .append(StatisticFormatter.formatTps(tickStatistics.tps5Sec())).append(Component.text(", "))
- .append(StatisticFormatter.formatTps(tickStatistics.tps10Sec())).append(Component.text(", "))
- .append(StatisticFormatter.formatTps(tickStatistics.tps1Min())).append(Component.text(", "))
- .append(StatisticFormatter.formatTps(tickStatistics.tps5Min())).append(Component.text(", "))
- .append(StatisticFormatter.formatTps(tickStatistics.tps15Min()))
- .build();
- case "tps_5s":
- return StatisticFormatter.formatTps(tickStatistics.tps5Sec());
- case "tps_10s":
- return StatisticFormatter.formatTps(tickStatistics.tps10Sec());
- case "tps_1m":
- return StatisticFormatter.formatTps(tickStatistics.tps1Min());
- case "tps_5m":
- return StatisticFormatter.formatTps(tickStatistics.tps5Min());
- case "tps_15m":
- return StatisticFormatter.formatTps(tickStatistics.tps15Min());
- }
- }
-
- if (placeholder.startsWith("tickduration")) {
- TickStatistics tickStatistics = platform.getTickStatistics();
- if (tickStatistics == null || !tickStatistics.isDurationSupported()) {
- return null;
- }
-
- switch (placeholder) {
- case "tickduration":
- return Component.text()
- .append(StatisticFormatter.formatTickDurations(tickStatistics.duration10Sec())).append(Component.text("; "))
- .append(StatisticFormatter.formatTickDurations(tickStatistics.duration1Min()))
- .build();
- case "tickduration_10s":
- return StatisticFormatter.formatTickDurations(tickStatistics.duration10Sec());
- case "tickduration_1m":
- return StatisticFormatter.formatTickDurations(tickStatistics.duration1Min());
- }
- }
-
- if (placeholder.startsWith("cpu")) {
- switch (placeholder) {
- case "cpu_system":
- return Component.text()
- .append(StatisticFormatter.formatCpuUsage(CpuMonitor.systemLoad10SecAvg())).append(Component.text(", "))
- .append(StatisticFormatter.formatCpuUsage(CpuMonitor.systemLoad1MinAvg())).append(Component.text(", "))
- .append(StatisticFormatter.formatCpuUsage(CpuMonitor.systemLoad15MinAvg()))
- .build();
- case "cpu_system_10s":
- return StatisticFormatter.formatCpuUsage(CpuMonitor.systemLoad10SecAvg());
- case "cpu_system_1m":
- return StatisticFormatter.formatCpuUsage(CpuMonitor.systemLoad1MinAvg());
- case "cpu_system_15m":
- return StatisticFormatter.formatCpuUsage(CpuMonitor.systemLoad15MinAvg());
- case "cpu_process":
- return Component.text()
- .append(StatisticFormatter.formatCpuUsage(CpuMonitor.processLoad10SecAvg())).append(Component.text(", "))
- .append(StatisticFormatter.formatCpuUsage(CpuMonitor.processLoad1MinAvg())).append(Component.text(", "))
- .append(StatisticFormatter.formatCpuUsage(CpuMonitor.processLoad15MinAvg()))
- .build();
- case "cpu_process_10s":
- return StatisticFormatter.formatCpuUsage(CpuMonitor.processLoad10SecAvg());
- case "cpu_process_1m":
- return StatisticFormatter.formatCpuUsage(CpuMonitor.processLoad1MinAvg());
- case "cpu_process_15m":
- return StatisticFormatter.formatCpuUsage(CpuMonitor.processLoad15MinAvg());
- }
- }
-
- return null;
- }
-
- public static String respond(SparkPlatform platform, String placeholder) {
- TextComponent result = respondComponent(platform, placeholder);
- if (result == null) {
- return null;
- }
- return LegacyComponentSerializer.legacySection().serialize(result);
- }
-
-}