From 4face768621e459335f2e8e23f8db2fac017b834 Mon Sep 17 00:00:00 2001 From: Luck Date: Sun, 20 Oct 2024 09:17:06 +0100 Subject: Move some platform implementations to new repo --- settings.gradle | 15 +- spark-common/build.gradle | 32 ++- spark-minestom/build.gradle | 51 ---- .../spark/minestom/MinestomClassSourceLookup.java | 49 ---- .../spark/minestom/MinestomCommandSender.java | 68 ------ .../lucko/spark/minestom/MinestomPlatformInfo.java | 47 ---- .../spark/minestom/MinestomPlayerPingProvider.java | 41 ---- .../lucko/spark/minestom/MinestomSparkPlugin.java | 195 --------------- .../me/lucko/spark/minestom/MinestomTickHook.java | 47 ---- .../lucko/spark/minestom/MinestomTickReporter.java | 48 ---- spark-minestom/src/main/resources/extension.json | 5 - spark-nukkit/build.gradle | 47 ---- .../spark/nukkit/NukkitClassSourceLookup.java | 38 --- .../me/lucko/spark/nukkit/NukkitCommandSender.java | 59 ----- .../me/lucko/spark/nukkit/NukkitPlatformInfo.java | 57 ----- .../spark/nukkit/NukkitPlayerPingProvider.java | 45 ---- .../me/lucko/spark/nukkit/NukkitSparkPlugin.java | 118 --------- spark-nukkit/src/main/resources/plugin.yml | 10 - spark-sponge/build.gradle | 49 ++++ .../spark/sponge/SpongeClassSourceLookup.java | 82 +++++++ .../me/lucko/spark/sponge/SpongeCommandSender.java | 94 ++++++++ .../me/lucko/spark/sponge/SpongePlatformInfo.java | 60 +++++ .../spark/sponge/SpongePlayerPingProvider.java | 45 ++++ .../me/lucko/spark/sponge/SpongeSparkPlugin.java | 267 +++++++++++++++++++++ .../java/me/lucko/spark/sponge/SpongeTickHook.java | 61 +++++ .../spark/sponge/SpongeWorldInfoProvider.java | 134 +++++++++++ .../main/resources/META-INF/sponge_plugins.json | 33 +++ spark-sponge7/build.gradle | 46 ---- .../spark/sponge/Sponge7ClassSourceLookup.java | 43 ---- .../lucko/spark/sponge/Sponge7CommandSender.java | 59 ----- .../me/lucko/spark/sponge/Sponge7PlatformInfo.java | 58 ----- .../spark/sponge/Sponge7PlayerPingProvider.java | 45 ---- .../me/lucko/spark/sponge/Sponge7SparkPlugin.java | 232 ------------------ .../me/lucko/spark/sponge/Sponge7TickHook.java | 50 ---- .../spark/sponge/Sponge7WorldInfoProvider.java | 123 ---------- spark-sponge8/build.gradle | 49 ---- .../spark/sponge/Sponge8ClassSourceLookup.java | 82 ------- .../lucko/spark/sponge/Sponge8CommandSender.java | 94 -------- .../me/lucko/spark/sponge/Sponge8PlatformInfo.java | 60 ----- .../spark/sponge/Sponge8PlayerPingProvider.java | 45 ---- .../me/lucko/spark/sponge/Sponge8SparkPlugin.java | 267 --------------------- .../me/lucko/spark/sponge/Sponge8TickHook.java | 61 ----- .../spark/sponge/Sponge8WorldInfoProvider.java | 134 ----------- .../main/resources/META-INF/sponge_plugins.json | 33 --- spark-velocity4/build.gradle | 52 ---- .../spark/velocity/Velocity4ClassSourceLookup.java | 61 ----- .../spark/velocity/Velocity4CommandSender.java | 64 ----- .../spark/velocity/Velocity4PlatformInfo.java | 57 ----- .../velocity/Velocity4PlayerPingProvider.java | 45 ---- .../lucko/spark/velocity/Velocity4SparkPlugin.java | 161 ------------- spark-waterdog/build.gradle | 56 ----- .../spark/waterdog/WaterdogClassSourceLookup.java | 61 ----- .../spark/waterdog/WaterdogCommandSender.java | 59 ----- .../lucko/spark/waterdog/WaterdogPlatformInfo.java | 52 ---- .../spark/waterdog/WaterdogPlayerPingProvider.java | 45 ---- .../lucko/spark/waterdog/WaterdogSparkPlugin.java | 139 ----------- spark-waterdog/src/main/resources/plugin.yml | 6 - 57 files changed, 860 insertions(+), 3276 deletions(-) delete mode 100644 spark-minestom/build.gradle delete mode 100644 spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomClassSourceLookup.java delete mode 100644 spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomCommandSender.java delete mode 100644 spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomPlatformInfo.java delete mode 100644 spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomPlayerPingProvider.java delete mode 100644 spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomSparkPlugin.java delete mode 100644 spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomTickHook.java delete mode 100644 spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomTickReporter.java delete mode 100644 spark-minestom/src/main/resources/extension.json delete mode 100644 spark-nukkit/build.gradle delete mode 100644 spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitClassSourceLookup.java delete mode 100644 spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitCommandSender.java delete mode 100644 spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitPlatformInfo.java delete mode 100644 spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitPlayerPingProvider.java delete mode 100644 spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitSparkPlugin.java delete mode 100644 spark-nukkit/src/main/resources/plugin.yml create mode 100644 spark-sponge/build.gradle create mode 100644 spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeClassSourceLookup.java create mode 100644 spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeCommandSender.java create mode 100644 spark-sponge/src/main/java/me/lucko/spark/sponge/SpongePlatformInfo.java create mode 100644 spark-sponge/src/main/java/me/lucko/spark/sponge/SpongePlayerPingProvider.java create mode 100644 spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeSparkPlugin.java create mode 100644 spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeTickHook.java create mode 100644 spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeWorldInfoProvider.java create mode 100644 spark-sponge/src/main/resources/META-INF/sponge_plugins.json delete mode 100644 spark-sponge7/build.gradle delete mode 100644 spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7ClassSourceLookup.java delete mode 100644 spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7CommandSender.java delete mode 100644 spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7PlatformInfo.java delete mode 100644 spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7PlayerPingProvider.java delete mode 100644 spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7SparkPlugin.java delete mode 100644 spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7TickHook.java delete mode 100644 spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7WorldInfoProvider.java delete mode 100644 spark-sponge8/build.gradle delete mode 100644 spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8ClassSourceLookup.java delete mode 100644 spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8CommandSender.java delete mode 100644 spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8PlatformInfo.java delete mode 100644 spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8PlayerPingProvider.java delete mode 100644 spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8SparkPlugin.java delete mode 100644 spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8TickHook.java delete mode 100644 spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8WorldInfoProvider.java delete mode 100644 spark-sponge8/src/main/resources/META-INF/sponge_plugins.json delete mode 100644 spark-velocity4/build.gradle delete mode 100644 spark-velocity4/src/main/java/me/lucko/spark/velocity/Velocity4ClassSourceLookup.java delete mode 100644 spark-velocity4/src/main/java/me/lucko/spark/velocity/Velocity4CommandSender.java delete mode 100644 spark-velocity4/src/main/java/me/lucko/spark/velocity/Velocity4PlatformInfo.java delete mode 100644 spark-velocity4/src/main/java/me/lucko/spark/velocity/Velocity4PlayerPingProvider.java delete mode 100644 spark-velocity4/src/main/java/me/lucko/spark/velocity/Velocity4SparkPlugin.java delete mode 100644 spark-waterdog/build.gradle delete mode 100644 spark-waterdog/src/main/java/me/lucko/spark/waterdog/WaterdogClassSourceLookup.java delete mode 100644 spark-waterdog/src/main/java/me/lucko/spark/waterdog/WaterdogCommandSender.java delete mode 100644 spark-waterdog/src/main/java/me/lucko/spark/waterdog/WaterdogPlatformInfo.java delete mode 100644 spark-waterdog/src/main/java/me/lucko/spark/waterdog/WaterdogPlayerPingProvider.java delete mode 100644 spark-waterdog/src/main/java/me/lucko/spark/waterdog/WaterdogSparkPlugin.java delete mode 100644 spark-waterdog/src/main/resources/plugin.yml diff --git a/settings.gradle b/settings.gradle index 6931c9f..d3e1b45 100644 --- a/settings.gradle +++ b/settings.gradle @@ -23,18 +23,13 @@ plugins { rootProject.name = 'spark' include ( 'spark-api', - 'spark-common', 'spark-bukkit', - 'spark-paper', 'spark-bungeecord', - 'spark-velocity', - 'spark-velocity4', - 'spark-sponge7', - 'spark-sponge8', + 'spark-common', + 'spark-fabric', 'spark-forge', 'spark-neoforge', - 'spark-fabric', - 'spark-nukkit', - 'spark-waterdog', - //'spark-minestom', // disabled until minestom publish their maven artifacts to a proper repo + 'spark-paper', + 'spark-sponge', + 'spark-velocity', ) diff --git a/spark-common/build.gradle b/spark-common/build.gradle index 5bc4bda..ba3d2b4 100644 --- a/spark-common/build.gradle +++ b/spark-common/build.gradle @@ -1,5 +1,6 @@ plugins { id 'com.google.protobuf' version '0.9.4' + id 'maven-publish' } license { @@ -14,7 +15,7 @@ dependencies { implementation 'com.github.jvm-profiling-tools:async-profiler:v2.8.3' implementation 'org.ow2.asm:asm:9.7' implementation 'net.bytebuddy:byte-buddy-agent:1.14.17' - implementation 'com.google.protobuf:protobuf-javalite:4.27.1' + implementation 'com.google.protobuf:protobuf-javalite:4.28.2' implementation('me.lucko:bytesocks-java-client:1.0-20230828.145440-5') { exclude(module: 'slf4j-api') @@ -60,7 +61,7 @@ dependencies { protobuf { protoc { - artifact = 'com.google.protobuf:protoc:4.27.1' + artifact = 'com.google.protobuf:protoc:4.28.2' } generateProtoTasks { all().each { task -> @@ -77,3 +78,30 @@ test { useJUnitPlatform {} systemProperty('net.kyori.ansi.colorLevel', 'indexed16') } + +publishing { + //repositories { + // maven { + // url = 'https://oss.sonatype.org/content/repositories/snapshots' + // credentials { + // username = sonatypeUsername + // password = sonatypePassword + // } + // } + //} + //repositories { + // maven { + // url = 'https://nexus.lucko.me/repository/maven-snapshots/' + // credentials { + // username = luckoNexusUsername + // password = luckoNexusPassword + // } + // } + //} + publications { + maven(MavenPublication) { + from components.java + version = "${project.pluginVersion}-SNAPSHOT" + } + } +} diff --git a/spark-minestom/build.gradle b/spark-minestom/build.gradle deleted file mode 100644 index 6e0d7e6..0000000 --- a/spark-minestom/build.gradle +++ /dev/null @@ -1,51 +0,0 @@ -plugins { - id 'com.gradleup.shadow' version '8.3.0' -} - -tasks.withType(JavaCompile) { - // override, compile targeting J17 - options.release = 17 -} - -dependencies { - implementation project(':spark-common') - compileOnly 'com.github.Minestom.Minestom:Minestom:master-SNAPSHOT' - implementation 'com.google.guava:guava:19.0' -} - -processResources { - from(sourceSets.main.resources.srcDirs) { - expand ( - 'pluginVersion': project.pluginVersion, - 'pluginDescription': project.pluginDescription - ) - include 'extension.json' - } -} - -shadowJar { - archiveFileName = "spark-${project.pluginVersion}-minestom.jar" - - dependencies { - exclude(dependency('net.kyori:^(?!adventure-text-feature-pagination).+$')) - } - - relocate 'net.kyori.adventure.text.feature.pagination', 'me.lucko.spark.lib.adventure.pagination' - relocate 'net.bytebuddy', 'me.lucko.spark.lib.bytebuddy' - relocate 'com.google.protobuf', 'me.lucko.spark.lib.protobuf' - relocate 'org.objectweb.asm', 'me.lucko.spark.lib.asm' - relocate 'one.profiler', 'me.lucko.spark.lib.asyncprofiler' - relocate 'me.lucko.bytesocks.client', 'me.lucko.spark.lib.bytesocks' - relocate 'org.java_websocket', 'me.lucko.spark.lib.bytesocks.ws' - - exclude 'module-info.class' - exclude 'META-INF/maven/**' - exclude 'META-INF/proguard/**' - exclude '**/*.proto' - exclude '**/*.proto.bin' -} - -artifacts { - archives shadowJar - shadow shadowJar -} diff --git a/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomClassSourceLookup.java b/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomClassSourceLookup.java deleted file mode 100644 index ca44eea..0000000 --- a/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomClassSourceLookup.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is part of spark. - * - * Copyright (c) lucko (Luck) - * 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 . - */ - -package me.lucko.spark.minestom; - -import me.lucko.spark.common.sampler.source.ClassSourceLookup; - -import net.minestom.server.MinecraftServer; -import net.minestom.server.extensions.Extension; -import net.minestom.server.extensions.ExtensionClassLoader; - -import java.util.HashMap; -import java.util.Map; - -public class MinestomClassSourceLookup extends ClassSourceLookup.ByClassLoader { - private final Map classLoaderToExtensions; - - public MinestomClassSourceLookup() { - this.classLoaderToExtensions = new HashMap<>(); - for (Extension extension : MinecraftServer.getExtensionManager().getExtensions()) { - this.classLoaderToExtensions.put(extension.getClass().getClassLoader(), extension.getOrigin().getName()); - } - } - - @Override - public String identify(ClassLoader loader) { - if (loader instanceof ExtensionClassLoader) { - return this.classLoaderToExtensions.get(loader); - } - return null; - } -} diff --git a/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomCommandSender.java b/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomCommandSender.java deleted file mode 100644 index e4323e6..0000000 --- a/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomCommandSender.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * This file is part of spark. - * - * Copyright (c) lucko (Luck) - * 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 . - */ - -package me.lucko.spark.minestom; - -import me.lucko.spark.common.command.sender.AbstractCommandSender; - -import net.kyori.adventure.text.Component; -import net.minestom.server.command.CommandSender; -import net.minestom.server.command.ConsoleSender; -import net.minestom.server.entity.Player; - -import java.util.UUID; - -public class MinestomCommandSender extends AbstractCommandSender { - public MinestomCommandSender(CommandSender delegate) { - super(delegate); - } - - @Override - public String getName() { - if (this.delegate instanceof Player player) { - return player.getUsername(); - } else if (this.delegate instanceof ConsoleSender) { - return "Console"; - }else { - return "unknown:" + this.delegate.getClass().getSimpleName(); - } - } - - @Override - public UUID getUniqueId() { - if (super.delegate instanceof Player player) { - return player.getUuid(); - } - return null; - } - - @Override - public void sendMessage(Component message) { - this.delegate.sendMessage(message); - } - - @Override - public boolean hasPermission(String permission) { - if (this.delegate instanceof ConsoleSender) { - return true; - } - return this.delegate.hasPermission(permission); - } -} diff --git a/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomPlatformInfo.java b/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomPlatformInfo.java deleted file mode 100644 index add258a..0000000 --- a/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomPlatformInfo.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * This file is part of spark. - * - * Copyright (c) lucko (Luck) - * 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 . - */ - -package me.lucko.spark.minestom; - -import me.lucko.spark.common.platform.PlatformInfo; - -import net.minestom.server.MinecraftServer; - -public class MinestomPlatformInfo implements PlatformInfo { - @Override - public Type getType() { - return Type.SERVER; - } - - @Override - public String getName() { - return "Minestom"; - } - - @Override - public String getVersion() { - return MinecraftServer.VERSION_NAME + "-" + MinecraftServer.getBrandName(); - } - - @Override - public String getMinecraftVersion() { - return MinecraftServer.VERSION_NAME; - } -} diff --git a/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomPlayerPingProvider.java b/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomPlayerPingProvider.java deleted file mode 100644 index 0b50c0a..0000000 --- a/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomPlayerPingProvider.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file is part of spark. - * - * Copyright (c) lucko (Luck) - * 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 . - */ - -package me.lucko.spark.minestom; - -import com.google.common.collect.ImmutableMap; - -import me.lucko.spark.common.monitor.ping.PlayerPingProvider; - -import net.minestom.server.MinecraftServer; -import net.minestom.server.entity.Player; - -import java.util.Map; - -public class MinestomPlayerPingProvider implements PlayerPingProvider { - @Override - public Map poll() { - ImmutableMap.Builder builder = ImmutableMap.builder(); - for (Player player : MinecraftServer.getConnectionManager().getOnlinePlayers()) { - builder.put(player.getUsername(), player.getLatency()); - } - return builder.build(); - } -} diff --git a/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomSparkPlugin.java b/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomSparkPlugin.java deleted file mode 100644 index 9014476..0000000 --- a/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomSparkPlugin.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * This file is part of spark. - * - * Copyright (c) lucko (Luck) - * 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 . - */ - -package me.lucko.spark.minestom; - -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.sampler.source.ClassSourceLookup; -import me.lucko.spark.common.sampler.source.SourceMetadata; -import me.lucko.spark.common.tick.TickHook; -import me.lucko.spark.common.tick.TickReporter; - -import net.minestom.server.MinecraftServer; -import net.minestom.server.command.CommandSender; -import net.minestom.server.command.builder.Command; -import net.minestom.server.command.builder.CommandContext; -import net.minestom.server.command.builder.CommandExecutor; -import net.minestom.server.command.builder.arguments.ArgumentStringArray; -import net.minestom.server.command.builder.arguments.ArgumentType; -import net.minestom.server.command.builder.suggestion.Suggestion; -import net.minestom.server.command.builder.suggestion.SuggestionCallback; -import net.minestom.server.command.builder.suggestion.SuggestionEntry; -import net.minestom.server.extensions.Extension; -import net.minestom.server.timer.ExecutionType; - -import org.jetbrains.annotations.NotNull; - -import java.nio.file.Path; -import java.util.Arrays; -import java.util.Collection; -import java.util.logging.Level; -import java.util.stream.Stream; - -public class MinestomSparkPlugin extends Extension implements SparkPlugin { - private SparkPlatform platform; - private MinestomSparkCommand command; - - @Override - public void initialize() { - this.platform = new SparkPlatform(this); - this.platform.enable(); - this.command = new MinestomSparkCommand(this.platform); - MinecraftServer.getCommandManager().register(this.command); - } - - @Override - public void terminate() { - this.platform.disable(); - MinecraftServer.getCommandManager().unregister(this.command); - } - - @Override - public String getVersion() { - return getOrigin().getVersion(); - } - - @Override - public Path getPluginDirectory() { - return getDataDirectory(); - } - - @Override - public String getCommandName() { - return "spark"; - } - - @Override - public Stream getCommandSenders() { - return Stream.concat( - MinecraftServer.getConnectionManager().getOnlinePlayers().stream(), - Stream.of(MinecraftServer.getCommandManager().getConsoleSender()) - ).map(MinestomCommandSender::new); - } - - @Override - public void executeAsync(Runnable task) { - MinecraftServer.getSchedulerManager().scheduleNextTick(task, ExecutionType.ASYNC); - } - - @Override - public void log(Level level, String msg) { - if (level == Level.INFO) { - this.getLogger().info(msg); - } else if (level == Level.WARNING) { - this.getLogger().warn(msg); - } else if (level == Level.SEVERE) { - this.getLogger().error(msg); - } else { - throw new IllegalArgumentException(level.getName()); - } - } - - @Override - public PlatformInfo getPlatformInfo() { - return new MinestomPlatformInfo(); - } - - @Override - public ClassSourceLookup createClassSourceLookup() { - return new MinestomClassSourceLookup(); - } - - @Override - public Collection getKnownSources() { - return SourceMetadata.gather( - MinecraftServer.getExtensionManager().getExtensions(), - extension -> extension.getOrigin().getName(), - extension -> extension.getOrigin().getVersion(), - extension -> String.join(", ", extension.getOrigin().getAuthors()) - ); - } - - @Override - public PlayerPingProvider createPlayerPingProvider() { - return new MinestomPlayerPingProvider(); - } - - @Override - public TickReporter createTickReporter() { - return new MinestomTickReporter(); - } - - @Override - public TickHook createTickHook() { - return new MinestomTickHook(); - } - - private static final class MinestomSparkCommand extends Command implements CommandExecutor, SuggestionCallback { - private final SparkPlatform platform; - - public MinestomSparkCommand(SparkPlatform platform) { - super("spark"); - this.platform = platform; - - ArgumentStringArray arrayArgument = ArgumentType.StringArray("args"); - arrayArgument.setSuggestionCallback(this); - - addSyntax(this, arrayArgument); - setDefaultExecutor((sender, context) -> platform.executeCommand(new MinestomCommandSender(sender), new String[0])); - } - - // execute - @Override - public void apply(@NotNull CommandSender sender, @NotNull CommandContext context) { - String[] args = processArgs(context, false); - if (args == null) { - return; - } - - this.platform.executeCommand(new MinestomCommandSender(sender), args); - } - - // tab complete - @Override - public void apply(@NotNull CommandSender sender, @NotNull CommandContext context, @NotNull Suggestion suggestion) { - String[] args = processArgs(context, true); - if (args == null) { - return; - } - - Iterable suggestionEntries = this.platform.tabCompleteCommand(new MinestomCommandSender(sender), args); - for (String suggestionEntry : suggestionEntries) { - suggestion.addEntry(new SuggestionEntry(suggestionEntry)); - } - } - - private static String [] processArgs(CommandContext context, boolean tabComplete) { - String[] split = context.getInput().split(" ", tabComplete ? -1 : 0); - if (split.length == 0 || !split[0].equals("/spark") && !split[0].equals("spark")) { - return null; - } - - return Arrays.copyOfRange(split, 1, split.length); - } - } -} diff --git a/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomTickHook.java b/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomTickHook.java deleted file mode 100644 index 44c1c2d..0000000 --- a/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomTickHook.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * This file is part of spark. - * - * Copyright (c) lucko (Luck) - * 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 . - */ - -package me.lucko.spark.minestom; - -import me.lucko.spark.common.tick.AbstractTickHook; - -import net.minestom.server.MinecraftServer; -import net.minestom.server.timer.Task; -import net.minestom.server.timer.TaskSchedule; - -public class MinestomTickHook extends AbstractTickHook { - private Task task; - - @Override - public void start() { - this.task = MinecraftServer.getSchedulerManager() - .buildTask(this::onTick) - .delay(TaskSchedule.tick(1)) - .repeat(TaskSchedule.tick(1)) - .schedule(); - } - - @Override - public void close() { - if (this.task != null) { - this.task.cancel(); - } - } -} diff --git a/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomTickReporter.java b/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomTickReporter.java deleted file mode 100644 index ae25f92..0000000 --- a/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomTickReporter.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of spark. - * - * Copyright (c) lucko (Luck) - * 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 . - */ - -package me.lucko.spark.minestom; - -import me.lucko.spark.common.tick.AbstractTickReporter; - -import net.minestom.server.MinecraftServer; -import net.minestom.server.event.Event; -import net.minestom.server.event.EventNode; -import net.minestom.server.event.server.ServerTickMonitorEvent; - -import java.util.UUID; - -public class MinestomTickReporter extends AbstractTickReporter { - private final EventNode node = EventNode.all("sparkTickReporter-" + UUID.randomUUID()); - - public MinestomTickReporter() { - this.node.addListener(ServerTickMonitorEvent.class, event -> onTick(event.getTickMonitor().getTickTime())); - } - - @Override - public void start() { - MinecraftServer.getGlobalEventHandler().addChild(this.node); - } - - @Override - public void close() { - MinecraftServer.getGlobalEventHandler().removeChild(this.node); - } -} diff --git a/spark-minestom/src/main/resources/extension.json b/spark-minestom/src/main/resources/extension.json deleted file mode 100644 index bea56bb..0000000 --- a/spark-minestom/src/main/resources/extension.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "entrypoint": "me.lucko.spark.minestom.MinestomSparkPlugin", - "name": "spark", - "version": "${pluginVersion}" -} \ No newline at end of file diff --git a/spark-nukkit/build.gradle b/spark-nukkit/build.gradle deleted file mode 100644 index c11e02e..0000000 --- a/spark-nukkit/build.gradle +++ /dev/null @@ -1,47 +0,0 @@ -plugins { - id 'com.gradleup.shadow' version '8.3.0' -} - -dependencies { - implementation project(':spark-common') - compileOnly 'cn.nukkit:nukkit:1.0-SNAPSHOT' -} - -repositories { - maven { url 'https://repo.opencollab.dev/main/' } -} - -processResources { - from(sourceSets.main.resources.srcDirs) { - expand ( - 'pluginVersion': project.pluginVersion, - 'pluginDescription': project.pluginDescription - ) - include 'plugin.yml' - } -} - -shadowJar { - archiveFileName = "spark-${project.pluginVersion}-nukkit.jar" - - relocate 'net.kyori.adventure', 'me.lucko.spark.lib.adventure' - relocate 'net.kyori.examination', 'me.lucko.spark.lib.adventure.examination' - relocate 'net.kyori.option', 'me.lucko.spark.lib.adventure.option' - relocate 'net.bytebuddy', 'me.lucko.spark.lib.bytebuddy' - relocate 'com.google.protobuf', 'me.lucko.spark.lib.protobuf' - relocate 'org.objectweb.asm', 'me.lucko.spark.lib.asm' - relocate 'one.profiler', 'me.lucko.spark.lib.asyncprofiler' - relocate 'me.lucko.bytesocks.client', 'me.lucko.spark.lib.bytesocks' - relocate 'org.java_websocket', 'me.lucko.spark.lib.bytesocks.ws' - - exclude 'module-info.class' - exclude 'META-INF/maven/**' - exclude 'META-INF/proguard/**' - exclude '**/*.proto' - exclude '**/*.proto.bin' -} - -artifacts { - archives shadowJar - shadow shadowJar -} diff --git a/spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitClassSourceLookup.java b/spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitClassSourceLookup.java deleted file mode 100644 index e815b6c..0000000 --- a/spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitClassSourceLookup.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This file is part of spark. - * - * Copyright (c) lucko (Luck) - * 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 . - */ - -package me.lucko.spark.nukkit; - -import cn.nukkit.plugin.PluginClassLoader; -import me.lucko.spark.common.sampler.source.ClassSourceLookup; - -import java.io.IOException; -import java.net.URISyntaxException; - -public class NukkitClassSourceLookup extends ClassSourceLookup.ByFirstUrlSource { - - @Override - public String identify(ClassLoader loader) throws IOException, URISyntaxException { - if (loader instanceof PluginClassLoader) { - return super.identify(loader); - } - return null; - } -} diff --git a/spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitCommandSender.java b/spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitCommandSender.java deleted file mode 100644 index 3d6de22..0000000 --- a/spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitCommandSender.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of spark. - * - * Copyright (c) lucko (Luck) - * 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 . - */ - -package me.lucko.spark.nukkit; - -import cn.nukkit.Player; -import cn.nukkit.command.CommandSender; -import me.lucko.spark.common.command.sender.AbstractCommandSender; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; - -import java.util.UUID; - -public class NukkitCommandSender extends AbstractCommandSender { - - public NukkitCommandSender(CommandSender delegate) { - super(delegate); - } - - @Override - public String getName() { - return this.delegate.getName(); - } - - @Override - public UUID getUniqueId() { - if (this.delegate instanceof Player) { - return ((Player) this.delegate).getUniqueId(); - } - return null; - } - - @Override - public void sendMessage(Component message) { - this.delegate.sendMessage(LegacyComponentSerializer.legacySection().serialize(message)); - } - - @Override - public boolean hasPermission(String permission) { - return this.delegate.hasPermission(permission); - } -} diff --git a/spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitPlatformInfo.java b/spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitPlatformInfo.java deleted file mode 100644 index a1c9c5b..0000000 --- a/spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitPlatformInfo.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This file is part of spark. - * - * Copyright (c) lucko (Luck) - * 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 . - */ - -package me.lucko.spark.nukkit; - -import cn.nukkit.Server; -import me.lucko.spark.common.platform.PlatformInfo; - -public class NukkitPlatformInfo implements PlatformInfo { - private final Server server; - - public NukkitPlatformInfo(Server server) { - this.server = server; - } - - @Override - public Type getType() { - return Type.SERVER; - } - - @Override - public String getName() { - return "Nukkit"; - } - - @Override - public String getBrand() { - return this.server.getName(); - } - - @Override - public String getVersion() { - return this.server.getNukkitVersion(); - } - - @Override - public String getMinecraftVersion() { - return this.server.getVersion(); - } -} diff --git a/spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitPlayerPingProvider.java b/spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitPlayerPingProvider.java deleted file mode 100644 index b2e5100..0000000 --- a/spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitPlayerPingProvider.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * This file is part of spark. - * - * Copyright (c) lucko (Luck) - * 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 . - */ - -package me.lucko.spark.nukkit; - -import cn.nukkit.Player; -import cn.nukkit.Server; -import com.google.common.collect.ImmutableMap; -import me.lucko.spark.common.monitor.ping.PlayerPingProvider; - -import java.util.Map; - -public class NukkitPlayerPingProvider implements PlayerPingProvider { - private final Server server; - - public NukkitPlayerPingProvider(Server server) { - this.server = server; - } - - @Override - public Map poll() { - ImmutableMap.Builder builder = ImmutableMap.builder(); - for (Player player : this.server.getOnlinePlayers().values()) { - builder.put(player.getName(), player.getPing()); - } - return builder.build(); - } -} diff --git a/spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitSparkPlugin.java b/spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitSparkPlugin.java deleted file mode 100644 index 39be28d..0000000 --- a/spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitSparkPlugin.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * This file is part of spark. - * - * Copyright (c) lucko (Luck) - * 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 . - */ - -package me.lucko.spark.nukkit; - -import cn.nukkit.command.Command; -import cn.nukkit.command.CommandSender; -import cn.nukkit.plugin.PluginBase; -import cn.nukkit.plugin.service.ServicePriority; -import me.lucko.spark.api.Spark; -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.sampler.source.ClassSourceLookup; - -import java.nio.file.Path; -import java.util.logging.Level; -import java.util.stream.Stream; - -public class NukkitSparkPlugin extends PluginBase implements SparkPlugin { - private SparkPlatform platform; - - @Override - public void onEnable() { - this.platform = new SparkPlatform(this); - this.platform.enable(); - } - - @Override - public void onDisable() { - this.platform.disable(); - } - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - this.platform.executeCommand(new NukkitCommandSender(sender), args); - return true; - } - - @Override - public String getVersion() { - return getDescription().getVersion(); - } - - @Override - public Path getPluginDirectory() { - return getDataFolder().toPath(); - } - - @Override - public String getCommandName() { - return "spark"; - } - - @Override - public Stream getCommandSenders() { - return Stream.concat( - getServer().getOnlinePlayers().values().stream(), - Stream.of(getServer().getConsoleSender()) - ).map(NukkitCommandSender::new); - } - - @Override - public void executeAsync(Runnable task) { - getServer().getScheduler().scheduleTask(this, task, true); - } - - @Override - public void log(Level level, String msg) { - if (level == Level.INFO) { - getLogger().info(msg); - } else if (level == Level.WARNING) { - getLogger().warning(msg); - } else if (level == Level.SEVERE) { - getLogger().error(msg); - } else { - throw new IllegalArgumentException(level.getName()); - } - } - - @Override - public ClassSourceLookup createClassSourceLookup() { - return new NukkitClassSourceLookup(); - } - - @Override - public PlayerPingProvider createPlayerPingProvider() { - return new NukkitPlayerPingProvider(getServer()); - } - - @Override - public PlatformInfo getPlatformInfo() { - return new NukkitPlatformInfo(getServer()); - } - - @Override - public void registerApi(Spark api) { - getServer().getServiceManager().register(Spark.class, api, this, ServicePriority.NORMAL); - } -} diff --git a/spark-nukkit/src/main/resources/plugin.yml b/spark-nukkit/src/main/resources/plugin.yml deleted file mode 100644 index cab74b5..0000000 --- a/spark-nukkit/src/main/resources/plugin.yml +++ /dev/null @@ -1,10 +0,0 @@ -name: spark -version: ${pluginVersion} -description: ${pluginDescription} -author: Luck -website: https://spark.lucko.me/ -main: me.lucko.spark.nukkit.NukkitSparkPlugin -api: [1.0.5] -commands: - spark: - description: Main plugin command \ No newline at end of file diff --git a/spark-sponge/build.gradle b/spark-sponge/build.gradle new file mode 100644 index 0000000..efb3321 --- /dev/null +++ b/spark-sponge/build.gradle @@ -0,0 +1,49 @@ +plugins { + id 'com.gradleup.shadow' version '8.3.0' +} + +dependencies { + implementation project(':spark-common') + compileOnly "org.spongepowered:spongeapi:8.0.0-SNAPSHOT" +} + +repositories { + maven { url 'https://repo.spongepowered.org/repository/maven-public/' } +} + +processResources { + from(sourceSets.main.resources.srcDirs) { + include 'META-INF/sponge_plugins.json' + expand ( + version: project.pluginVersion, + description: project.pluginDescription + ) + } +} + +shadowJar { + archiveFileName = "spark-${project.pluginVersion}-sponge.jar" + + dependencies { + exclude(dependency('net.kyori:^(?!adventure-text-feature-pagination).+$')) + } + + relocate 'net.kyori.adventure.text.feature.pagination', 'me.lucko.spark.lib.adventure.pagination' + relocate 'net.bytebuddy', 'me.lucko.spark.lib.bytebuddy' + relocate 'com.google.protobuf', 'me.lucko.spark.lib.protobuf' + relocate 'org.objectweb.asm', 'me.lucko.spark.lib.asm' + relocate 'one.profiler', 'me.lucko.spark.lib.asyncprofiler' + relocate 'me.lucko.bytesocks.client', 'me.lucko.spark.lib.bytesocks' + relocate 'org.java_websocket', 'me.lucko.spark.lib.bytesocks.ws' + + exclude 'module-info.class' + exclude 'META-INF/maven/**' + exclude 'META-INF/proguard/**' + exclude '**/*.proto' + exclude '**/*.proto.bin' +} + +artifacts { + archives shadowJar + shadow shadowJar +} diff --git a/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeClassSourceLookup.java b/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeClassSourceLookup.java new file mode 100644 index 0000000..0820ae3 --- /dev/null +++ b/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeClassSourceLookup.java @@ -0,0 +1,82 @@ +/* + * This file is part of spark. + * + * Copyright (c) lucko (Luck) + * 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 . + */ + +package me.lucko.spark.sponge; + +import com.google.common.collect.ImmutableMap; +import me.lucko.spark.common.sampler.source.ClassSourceLookup; +import org.spongepowered.api.Game; +import org.spongepowered.plugin.PluginCandidate; +import org.spongepowered.plugin.PluginContainer; +import org.spongepowered.plugin.builtin.jvm.JVMPluginContainer; +import org.spongepowered.plugin.builtin.jvm.locator.JVMPluginResource; + +import java.lang.reflect.Field; +import java.nio.file.Path; +import java.util.Collection; +import java.util.Map; + +public class SpongeClassSourceLookup extends ClassSourceLookup.ByCodeSource { + private final Path modsDirectory; + private final Map pathToPluginMap; + + public SpongeClassSourceLookup(Game game) { + this.modsDirectory = game.gameDirectory().resolve("mods").toAbsolutePath().normalize(); + this.pathToPluginMap = constructPathToPluginIdMap(game.pluginManager().plugins()); + } + + @Override + public String identifyFile(Path path) { + String id = this.pathToPluginMap.get(path); + if (id != null) { + return id; + } + + if (!path.startsWith(this.modsDirectory)) { + return null; + } + + return super.identifyFileName(this.modsDirectory.relativize(path).toString()); + } + + // pretty nasty, but if it fails it doesn't really matter + @SuppressWarnings("unchecked") + private static Map constructPathToPluginIdMap(Collection plugins) { + ImmutableMap.Builder builder = ImmutableMap.builder(); + + try { + Field candidateField = JVMPluginContainer.class.getDeclaredField("candidate"); + candidateField.setAccessible(true); + + for (PluginContainer plugin : plugins) { + if (plugin instanceof JVMPluginContainer) { + PluginCandidate candidate = (PluginCandidate) candidateField.get(plugin); + Path path = candidate.resource().path().toAbsolutePath().normalize(); + builder.put(path, plugin.metadata().id()); + } + } + } catch (Exception e) { + // ignore + } + + return builder.build(); + } + +} diff --git a/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeCommandSender.java b/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeCommandSender.java new file mode 100644 index 0000000..aa634cc --- /dev/null +++ b/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeCommandSender.java @@ -0,0 +1,94 @@ +/* + * This file is part of spark. + * + * Copyright (c) lucko (Luck) + * 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 . + */ + +package me.lucko.spark.sponge; + +import me.lucko.spark.common.command.sender.AbstractCommandSender; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.identity.Identity; +import net.kyori.adventure.text.Component; +import org.spongepowered.api.command.CommandCause; +import org.spongepowered.api.service.permission.Subject; +import org.spongepowered.api.util.Identifiable; + +import java.util.UUID; + +import static java.nio.charset.StandardCharsets.UTF_8; + +public class SpongeCommandSender extends AbstractCommandSender { + private final CommandCause cause; + private final Audience audience; + + public SpongeCommandSender(CommandCause cause) { + super(cause); + this.cause = cause; + this.audience = cause.audience(); + } + + public SpongeCommandSender(T cause) { + super(cause); + this.cause = null; + this.audience = cause; + } + + @Override + public String getName() { + return super.delegate.friendlyIdentifier().orElse(super.delegate.identifier()); + } + + @Override + public UUID getUniqueId() { + if (this.cause != null) { + Identifiable identifiable = this.cause.first(Identifiable.class).orElse(null); + if (identifiable != null) { + return identifiable.uniqueId(); + } + } + + try { + return UUID.fromString(super.delegate.identifier()); + } catch (Exception e) { + return UUID.nameUUIDFromBytes(super.delegate.identifier().getBytes(UTF_8)); + } + } + + @Override + public void sendMessage(Component message) { + this.audience.sendMessage(Identity.nil(), message); + } + + @Override + public boolean hasPermission(String permission) { + return super.delegate.hasPermission(permission); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SpongeCommandSender that = (SpongeCommandSender) o; + return this.getUniqueId().equals(that.getUniqueId()); + } + + @Override + public int hashCode() { + return getUniqueId().hashCode(); + } +} diff --git a/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongePlatformInfo.java b/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongePlatformInfo.java new file mode 100644 index 0000000..e5811cd --- /dev/null +++ b/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongePlatformInfo.java @@ -0,0 +1,60 @@ +/* + * This file is part of spark. + * + * Copyright (c) lucko (Luck) + * 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 . + */ + +package me.lucko.spark.sponge; + +import me.lucko.spark.common.platform.PlatformInfo; +import org.spongepowered.api.Game; +import org.spongepowered.api.Platform; +import org.spongepowered.plugin.metadata.PluginMetadata; + +public class SpongePlatformInfo implements PlatformInfo { + private final Game game; + + public SpongePlatformInfo(Game game) { + this.game = game; + } + + @Override + public Type getType() { + return Type.SERVER; + } + + @Override + public String getName() { + return "Sponge"; + } + + @Override + public String getBrand() { + PluginMetadata brandMetadata = this.game.platform().container(Platform.Component.IMPLEMENTATION).metadata(); + return brandMetadata.name().orElseGet(brandMetadata::id); + } + + @Override + public String getVersion() { + return this.game.platform().container(Platform.Component.IMPLEMENTATION).metadata().version().toString(); + } + + @Override + public String getMinecraftVersion() { + return this.game.platform().minecraftVersion().name(); + } +} diff --git a/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongePlayerPingProvider.java b/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongePlayerPingProvider.java new file mode 100644 index 0000000..b327a0a --- /dev/null +++ b/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongePlayerPingProvider.java @@ -0,0 +1,45 @@ +/* + * This file is part of spark. + * + * Copyright (c) lucko (Luck) + * 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 . + */ + +package me.lucko.spark.sponge; + +import com.google.common.collect.ImmutableMap; +import me.lucko.spark.common.monitor.ping.PlayerPingProvider; +import org.spongepowered.api.Server; +import org.spongepowered.api.entity.living.player.server.ServerPlayer; + +import java.util.Map; + +public class SpongePlayerPingProvider implements PlayerPingProvider { + private final Server server; + + public SpongePlayerPingProvider(Server server) { + this.server = server; + } + + @Override + public Map poll() { + ImmutableMap.Builder builder = ImmutableMap.builder(); + for (ServerPlayer player : this.server.onlinePlayers()) { + builder.put(player.name(), player.connection().latency()); + } + return builder.build(); + } +} diff --git a/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeSparkPlugin.java b/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeSparkPlugin.java new file mode 100644 index 0000000..3542dae --- /dev/null +++ b/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeSparkPlugin.java @@ -0,0 +1,267 @@ +/* + * This file is part of spark. + * + * Copyright (c) lucko (Luck) + * 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 . + */ + +package me.lucko.spark.sponge; + +import com.google.common.base.Suppliers; +import com.google.inject.Inject; +import me.lucko.spark.common.SparkPlatform; +import me.lucko.spark.common.SparkPlugin; +import me.lucko.spark.common.command.sender.CommandSender; +import me.lucko.spark.common.monitor.ping.PlayerPingProvider; +import me.lucko.spark.common.platform.PlatformInfo; +import me.lucko.spark.common.platform.world.WorldInfoProvider; +import me.lucko.spark.common.sampler.ThreadDumper; +import me.lucko.spark.common.sampler.source.ClassSourceLookup; +import me.lucko.spark.common.sampler.source.SourceMetadata; +import me.lucko.spark.common.tick.TickHook; +import net.kyori.adventure.text.Component; +import org.apache.logging.log4j.Logger; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.spongepowered.api.Game; +import org.spongepowered.api.Server; +import org.spongepowered.api.command.Command; +import org.spongepowered.api.command.CommandCause; +import org.spongepowered.api.command.CommandCompletion; +import org.spongepowered.api.command.CommandResult; +import org.spongepowered.api.command.parameter.ArgumentReader; +import org.spongepowered.api.command.registrar.tree.CommandTreeNode; +import org.spongepowered.api.config.ConfigDir; +import org.spongepowered.api.event.Listener; +import org.spongepowered.api.event.lifecycle.RegisterCommandEvent; +import org.spongepowered.api.event.lifecycle.StartedEngineEvent; +import org.spongepowered.api.event.lifecycle.StoppingEngineEvent; +import org.spongepowered.plugin.PluginContainer; +import org.spongepowered.plugin.builtin.jvm.Plugin; +import org.spongepowered.plugin.metadata.model.PluginContributor; + +import java.nio.file.Path; +import java.util.Collection; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.ExecutorService; +import java.util.function.Supplier; +import java.util.logging.Level; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@Plugin("spark") +public class SpongeSparkPlugin implements SparkPlugin { + + private final PluginContainer pluginContainer; + private final Logger logger; + private final Game game; + private final Path configDirectory; + private final ExecutorService asyncExecutor; + private final Supplier syncExecutor; + private final ThreadDumper.GameThread gameThreadDumper = new ThreadDumper.GameThread(); + + private SparkPlatform platform; + + @Inject + public SpongeSparkPlugin(PluginContainer pluginContainer, Logger logger, Game game, @ConfigDir(sharedRoot = false) Path configDirectory) { + this.pluginContainer = pluginContainer; + this.logger = logger; + this.game = game; + this.configDirectory = configDirectory; + this.asyncExecutor = game.asyncScheduler().executor(pluginContainer); + this.syncExecutor = Suppliers.memoize(() -> { + if (this.game.isServerAvailable()) { + return this.game.server().scheduler().executor(this.pluginContainer); + } else if (this.game.isClientAvailable()) { + return this.game.client().scheduler().executor(this.pluginContainer); + } else { + throw new IllegalStateException("Server and client both unavailable"); + } + }); + } + + + @Listener + public void onRegisterCommands(final RegisterCommandEvent event) { + event.register(this.pluginContainer, new SparkCommand(this), this.pluginContainer.metadata().id()); + } + + @Listener + public void onEnable(StartedEngineEvent event) { + this.gameThreadDumper.setThread(Thread.currentThread()); + + this.platform = new SparkPlatform(this); + this.platform.enable(); + } + + @Listener + public void onDisable(StoppingEngineEvent event) { + this.platform.disable(); + } + + @Override + public String getVersion() { + return this.pluginContainer.metadata().version().toString(); + } + + @Override + public Path getPluginDirectory() { + return this.configDirectory; + } + + @Override + public String getCommandName() { + return "spark"; + } + + @Override + public Stream getCommandSenders() { + if (this.game.isServerAvailable()) { + return Stream.concat( + this.game.server().onlinePlayers().stream(), + Stream.of(this.game.systemSubject()) + ).map(SpongeCommandSender::new); + } else { + return Stream.of