aboutsummaryrefslogtreecommitdiff
path: root/spark-bukkit/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'spark-bukkit/src/main')
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitPlatformInfo.java4
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitPlayerPingProvider.java57
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitServerConfigProvider.java138
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitSparkPlugin.java16
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/CommandMapUtil.java27
-rw-r--r--spark-bukkit/src/main/java/me/lucko/spark/bukkit/placeholder/SparkPlaceholderProvider.java56
6 files changed, 252 insertions, 46 deletions
diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitPlatformInfo.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitPlatformInfo.java
index 3f0c155..2bf17ac 100644
--- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitPlatformInfo.java
+++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitPlatformInfo.java
@@ -20,14 +20,14 @@
package me.lucko.spark.bukkit;
-import me.lucko.spark.common.platform.AbstractPlatformInfo;
+import me.lucko.spark.common.platform.PlatformInfo;
import org.bukkit.Server;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
-public class BukkitPlatformInfo extends AbstractPlatformInfo {
+public class BukkitPlatformInfo implements PlatformInfo {
private final Server server;
public BukkitPlatformInfo(Server server) {
diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitPlayerPingProvider.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitPlayerPingProvider.java
new file mode 100644
index 0000000..2cf58cf
--- /dev/null
+++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitPlayerPingProvider.java
@@ -0,0 +1,57 @@
+/*
+ * 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;
+
+import com.google.common.collect.ImmutableMap;
+
+import me.lucko.spark.common.monitor.ping.PlayerPingProvider;
+
+import org.bukkit.Server;
+import org.bukkit.entity.Player;
+
+import java.util.Map;
+
+public class BukkitPlayerPingProvider implements PlayerPingProvider {
+
+ public static boolean isSupported() {
+ try {
+ Player.Spigot.class.getMethod("getPing");
+ return true;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ private final Server server;
+
+ public BukkitPlayerPingProvider(Server server) {
+ this.server = server;
+ }
+
+ @Override
+ public Map<String, Integer> poll() {
+ ImmutableMap.Builder<String, Integer> builder = ImmutableMap.builder();
+ for (Player player : this.server.getOnlinePlayers()) {
+ builder.put(player.getName(), player.spigot().getPing());
+ }
+ return builder.build();
+ }
+}
diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitServerConfigProvider.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitServerConfigProvider.java
new file mode 100644
index 0000000..953e171
--- /dev/null
+++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitServerConfigProvider.java
@@ -0,0 +1,138 @@
+/*
+ * 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;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonSerializer;
+
+import me.lucko.spark.common.platform.serverconfig.AbstractServerConfigProvider;
+import me.lucko.spark.common.platform.serverconfig.PropertiesFileReader;
+
+import org.bukkit.configuration.MemorySection;
+import org.bukkit.configuration.file.YamlConfiguration;
+
+import co.aikar.timings.TimingsManager;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+public class BukkitServerConfigProvider extends AbstractServerConfigProvider<BukkitServerConfigProvider.FileType> {
+ private static final Gson GSON = new GsonBuilder()
+ .registerTypeAdapter(MemorySection.class, (JsonSerializer<MemorySection>) (obj, type, ctx) -> ctx.serialize(obj.getValues(false)))
+ .create();
+
+ /** A map of provided files and their type */
+ private static final Map<String, FileType> FILES;
+ /** A collection of paths to be excluded from the files */
+ private static final Collection<String> HIDDEN_PATHS;
+
+ public BukkitServerConfigProvider() {
+ super(FILES, HIDDEN_PATHS);
+ }
+
+ @Override
+ protected JsonElement load(String path, FileType type) throws IOException {
+ Path filePath = Paths.get(path);
+ if (!Files.exists(filePath)) {
+ return null;
+ }
+
+ try (BufferedReader reader = Files.newBufferedReader(filePath, StandardCharsets.UTF_8)) {
+ Map<String, Object> values;
+
+ if (type == FileType.PROPERTIES) {
+ PropertiesFileReader propertiesReader = new PropertiesFileReader(reader);
+ values = propertiesReader.readProperties();
+ } else if (type == FileType.YAML) {
+ YamlConfiguration config = YamlConfiguration.loadConfiguration(reader);
+ values = config.getValues(false);
+ } else {
+ throw new IllegalArgumentException("Unknown file type: " + type);
+ }
+
+ return GSON.toJsonTree(values);
+ }
+ }
+
+ enum FileType {
+ PROPERTIES,
+ YAML
+ }
+
+ static {
+ ImmutableMap.Builder<String, FileType> files = ImmutableMap.<String, FileType>builder()
+ .put("server.properties", FileType.PROPERTIES)
+ .put("bukkit.yml", FileType.YAML)
+ .put("spigot.yml", FileType.YAML)
+ .put("paper.yml", FileType.YAML)
+ .put("purpur.yml", FileType.YAML);
+
+ for (String config : getSystemPropertyList("spark.serverconfigs.extra")) {
+ files.put(config, FileType.YAML);
+ }
+
+ ImmutableSet.Builder<String> hiddenPaths = ImmutableSet.<String>builder()
+ .add("database")
+ .add("settings.bungeecord-addresses")
+ .add("settings.velocity-support.secret")
+ .add("server-ip")
+ .add("motd")
+ .add("resource-pack")
+ .add("rcon<dot>password")
+ .add("level-seed")
+ .add("world-settings.*.feature-seeds")
+ .add("world-settings.*.seed-*")
+ .addAll(getTimingsHiddenConfigs())
+ .addAll(getSystemPropertyList("spark.serverconfigs.hiddenpaths"));
+
+ FILES = files.build();
+ HIDDEN_PATHS = hiddenPaths.build();
+ }
+
+ private static List<String> getSystemPropertyList(String property) {
+ String value = System.getProperty(property);
+ return value == null
+ ? Collections.emptyList()
+ : Arrays.asList(value.split(","));
+ }
+
+ private static List<String> getTimingsHiddenConfigs() {
+ try {
+ return TimingsManager.hiddenConfigs;
+ } catch (NoClassDefFoundError e) {
+ return Collections.emptyList();
+ }
+ }
+
+}
diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitSparkPlugin.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitSparkPlugin.java
index f81a176..9727277 100644
--- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitSparkPlugin.java
+++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/BukkitSparkPlugin.java
@@ -25,7 +25,9 @@ import me.lucko.spark.bukkit.placeholder.SparkMVdWPlaceholders;
import me.lucko.spark.bukkit.placeholder.SparkPlaceholderApi;
import me.lucko.spark.common.SparkPlatform;
import me.lucko.spark.common.SparkPlugin;
+import me.lucko.spark.common.monitor.ping.PlayerPingProvider;
import me.lucko.spark.common.platform.PlatformInfo;
+import me.lucko.spark.common.platform.serverconfig.ServerConfigProvider;
import me.lucko.spark.common.sampler.ThreadDumper;
import me.lucko.spark.common.tick.TickHook;
import me.lucko.spark.common.tick.TickReporter;
@@ -172,6 +174,20 @@ public class BukkitSparkPlugin extends JavaPlugin implements SparkPlugin {
}
@Override
+ public PlayerPingProvider createPlayerPingProvider() {
+ if (BukkitPlayerPingProvider.isSupported()) {
+ return new BukkitPlayerPingProvider(getServer());
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public ServerConfigProvider createServerConfigProvider() {
+ return new BukkitServerConfigProvider();
+ }
+
+ @Override
public PlatformInfo getPlatformInfo() {
return new BukkitPlatformInfo(getServer());
}
diff --git a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/CommandMapUtil.java b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/CommandMapUtil.java
index 5c4d0db..e604321 100644
--- a/spark-bukkit/src/main/java/me/lucko/spark/bukkit/CommandMapUtil.java
+++ b/spark-bukkit/src/main/java/me/lucko/spark/bukkit/CommandMapUtil.java
@@ -1,26 +1,21 @@
/*
- * This file is part of helper, licensed under the MIT License.
+ * This file is part of spark.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
+ * 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.
*
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
+ * 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.
*
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
+ * 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;
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
index 6e14bdb..5b57857 100644
--- 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
@@ -3,7 +3,7 @@
*
* 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
@@ -21,9 +21,9 @@
package me.lucko.spark.bukkit.placeholder;
import me.lucko.spark.common.SparkPlatform;
-import me.lucko.spark.common.command.modules.HealthModule;
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;
@@ -42,22 +42,22 @@ enum SparkPlaceholderProvider {
switch (placeholder) {
case "tps":
return Component.text()
- .append(HealthModule.formatTps(tickStatistics.tps5Sec())).append(Component.text(", "))
- .append(HealthModule.formatTps(tickStatistics.tps10Sec())).append(Component.text(", "))
- .append(HealthModule.formatTps(tickStatistics.tps1Min())).append(Component.text(", "))
- .append(HealthModule.formatTps(tickStatistics.tps5Min())).append(Component.text(", "))
- .append(HealthModule.formatTps(tickStatistics.tps15Min()))
+ .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 HealthModule.formatTps(tickStatistics.tps5Sec());
+ return StatisticFormatter.formatTps(tickStatistics.tps5Sec());
case "tps_10s":
- return HealthModule.formatTps(tickStatistics.tps10Sec());
+ return StatisticFormatter.formatTps(tickStatistics.tps10Sec());
case "tps_1m":
- return HealthModule.formatTps(tickStatistics.tps1Min());
+ return StatisticFormatter.formatTps(tickStatistics.tps1Min());
case "tps_5m":
- return HealthModule.formatTps(tickStatistics.tps5Min());
+ return StatisticFormatter.formatTps(tickStatistics.tps5Min());
case "tps_15m":
- return HealthModule.formatTps(tickStatistics.tps15Min());
+ return StatisticFormatter.formatTps(tickStatistics.tps15Min());
}
}
@@ -70,13 +70,13 @@ enum SparkPlaceholderProvider {
switch (placeholder) {
case "tickduration":
return Component.text()
- .append(HealthModule.formatTickDurations(tickStatistics.duration10Sec())).append(Component.text("; "))
- .append(HealthModule.formatTickDurations(tickStatistics.duration1Min()))
+ .append(StatisticFormatter.formatTickDurations(tickStatistics.duration10Sec())).append(Component.text("; "))
+ .append(StatisticFormatter.formatTickDurations(tickStatistics.duration1Min()))
.build();
case "tickduration_10s":
- return HealthModule.formatTickDurations(tickStatistics.duration10Sec());
+ return StatisticFormatter.formatTickDurations(tickStatistics.duration10Sec());
case "tickduration_1m":
- return HealthModule.formatTickDurations(tickStatistics.duration1Min());
+ return StatisticFormatter.formatTickDurations(tickStatistics.duration1Min());
}
}
@@ -84,28 +84,28 @@ enum SparkPlaceholderProvider {
switch (placeholder) {
case "cpu_system":
return Component.text()
- .append(HealthModule.formatCpuUsage(CpuMonitor.systemLoad10SecAvg())).append(Component.text(", "))
- .append(HealthModule.formatCpuUsage(CpuMonitor.systemLoad1MinAvg())).append(Component.text(", "))
- .append(HealthModule.formatCpuUsage(CpuMonitor.systemLoad15MinAvg()))
+ .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 HealthModule.formatCpuUsage(CpuMonitor.systemLoad10SecAvg());
+ return StatisticFormatter.formatCpuUsage(CpuMonitor.systemLoad10SecAvg());
case "cpu_system_1m":
- return HealthModule.formatCpuUsage(CpuMonitor.systemLoad1MinAvg());
+ return StatisticFormatter.formatCpuUsage(CpuMonitor.systemLoad1MinAvg());
case "cpu_system_15m":
- return HealthModule.formatCpuUsage(CpuMonitor.systemLoad15MinAvg());
+ return StatisticFormatter.formatCpuUsage(CpuMonitor.systemLoad15MinAvg());
case "cpu_process":
return Component.text()
- .append(HealthModule.formatCpuUsage(CpuMonitor.processLoad10SecAvg())).append(Component.text(", "))
- .append(HealthModule.formatCpuUsage(CpuMonitor.processLoad1MinAvg())).append(Component.text(", "))
- .append(HealthModule.formatCpuUsage(CpuMonitor.processLoad15MinAvg()))
+ .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 HealthModule.formatCpuUsage(CpuMonitor.processLoad10SecAvg());
+ return StatisticFormatter.formatCpuUsage(CpuMonitor.processLoad10SecAvg());
case "cpu_process_1m":
- return HealthModule.formatCpuUsage(CpuMonitor.processLoad1MinAvg());
+ return StatisticFormatter.formatCpuUsage(CpuMonitor.processLoad1MinAvg());
case "cpu_process_15m":
- return HealthModule.formatCpuUsage(CpuMonitor.processLoad15MinAvg());
+ return StatisticFormatter.formatCpuUsage(CpuMonitor.processLoad15MinAvg());
}
}