From 97320645783f21893a4a8dc3af0a29804f1cf6dd Mon Sep 17 00:00:00 2001 From: Luck Date: Thu, 23 Dec 2021 12:49:21 +0000 Subject: Remove Forge 1.12.2 module The current downloads for this version will remain on CurseForge, but it will no longer be updated with new features. --- settings.gradle | 1 - 1 file changed, 1 deletion(-) (limited to 'settings.gradle') diff --git a/settings.gradle b/settings.gradle index fc72d02..843c836 100644 --- a/settings.gradle +++ b/settings.gradle @@ -20,7 +20,6 @@ include ( 'spark-sponge', 'spark-sponge8', 'spark-forge', - 'spark-forge1122', 'spark-fabric', 'spark-nukkit', 'spark-waterdog', -- cgit From 5bbd0ebf0db436d4a764163618c577783f4a9e08 Mon Sep 17 00:00:00 2001 From: Luck Date: Sun, 2 Jan 2022 16:48:37 +0000 Subject: Separate Sponge API 7 build --- settings.gradle | 2 +- spark-sponge/build.gradle | 19 -- .../me/lucko/spark/sponge/SpongeCommandSender.java | 61 ------- .../me/lucko/spark/sponge/SpongePlatformInfo.java | 54 ------ .../me/lucko/spark/sponge/SpongeSparkPlugin.java | 201 --------------------- .../java/me/lucko/spark/sponge/SpongeTickHook.java | 51 ------ spark-sponge7/build.gradle | 43 +++++ .../lucko/spark/sponge/Sponge7CommandSender.java | 61 +++++++ .../me/lucko/spark/sponge/Sponge7PlatformInfo.java | 54 ++++++ .../me/lucko/spark/sponge/Sponge7SparkPlugin.java | 196 ++++++++++++++++++++ .../me/lucko/spark/sponge/Sponge7TickHook.java | 51 ++++++ spark-universal/build.gradle | 1 - 12 files changed, 406 insertions(+), 388 deletions(-) delete mode 100644 spark-sponge/build.gradle delete mode 100644 spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeCommandSender.java delete mode 100644 spark-sponge/src/main/java/me/lucko/spark/sponge/SpongePlatformInfo.java delete mode 100644 spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeSparkPlugin.java delete mode 100644 spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeTickHook.java create mode 100644 spark-sponge7/build.gradle create mode 100644 spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7CommandSender.java create mode 100644 spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7PlatformInfo.java create mode 100644 spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7SparkPlugin.java create mode 100644 spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7TickHook.java (limited to 'settings.gradle') diff --git a/settings.gradle b/settings.gradle index 843c836..09d0a60 100644 --- a/settings.gradle +++ b/settings.gradle @@ -17,7 +17,7 @@ include ( 'spark-bungeecord', 'spark-velocity', 'spark-velocity4', - 'spark-sponge', + 'spark-sponge7', 'spark-sponge8', 'spark-forge', 'spark-fabric', diff --git a/spark-sponge/build.gradle b/spark-sponge/build.gradle deleted file mode 100644 index b81008c..0000000 --- a/spark-sponge/build.gradle +++ /dev/null @@ -1,19 +0,0 @@ -plugins { - id 'net.kyori.blossom' version '1.3.0' -} - -dependencies { - implementation project(':spark-common') - compileOnly 'org.spongepowered:spongeapi:7.3.0' - annotationProcessor 'org.spongepowered:spongeapi:7.3.0' -} - -repositories { - maven { url "https://repo.spongepowered.org/maven" } -} - -blossom { - replaceTokenIn('src/main/java/me/lucko/spark/sponge/SpongeSparkPlugin.java') - replaceToken '@version@', project.pluginVersion - replaceToken '@desc@', project.pluginDescription -} 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 deleted file mode 100644 index b2c4b8c..0000000 --- a/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeCommandSender.java +++ /dev/null @@ -1,61 +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.sponge; - -import me.lucko.spark.common.command.sender.AbstractCommandSender; - -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; - -import org.spongepowered.api.command.CommandSource; -import org.spongepowered.api.entity.living.player.Player; -import org.spongepowered.api.text.serializer.TextSerializers; - -import java.util.UUID; - -public class SpongeCommandSender extends AbstractCommandSender { - public SpongeCommandSender(CommandSource source) { - super(source); - } - - @Override - public String getName() { - return super.delegate.getName(); - } - - @Override - public UUID getUniqueId() { - if (super.delegate instanceof Player) { - return ((Player) super.delegate).getUniqueId(); - } - return null; - } - - @Override - public void sendMessage(Component message) { - super.delegate.sendMessage(TextSerializers.JSON.deserialize(GsonComponentSerializer.gson().serialize(message))); - } - - @Override - public boolean hasPermission(String permission) { - return super.delegate.hasPermission(permission); - } -} 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 deleted file mode 100644 index 28f7513..0000000 --- a/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongePlatformInfo.java +++ /dev/null @@ -1,54 +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.sponge; - -import me.lucko.spark.common.platform.PlatformInfo; - -import org.spongepowered.api.Game; -import org.spongepowered.api.Platform; - -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 getVersion() { - return this.game.getPlatform().getContainer(Platform.Component.IMPLEMENTATION).getVersion().orElse("unknown"); - } - - @Override - public String getMinecraftVersion() { - return this.game.getPlatform().getMinecraftVersion().getName(); - } -} 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 deleted file mode 100644 index 45d8d80..0000000 --- a/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeSparkPlugin.java +++ /dev/null @@ -1,201 +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.sponge; - -import com.google.inject.Inject; - -import me.lucko.spark.api.Spark; -import me.lucko.spark.common.SparkPlatform; -import me.lucko.spark.common.SparkPlugin; -import me.lucko.spark.common.platform.PlatformInfo; -import me.lucko.spark.common.sampler.ThreadDumper; -import me.lucko.spark.common.tick.TickHook; - -import org.slf4j.Logger; -import org.spongepowered.api.Game; -import org.spongepowered.api.command.CommandCallable; -import org.spongepowered.api.command.CommandResult; -import org.spongepowered.api.command.CommandSource; -import org.spongepowered.api.config.ConfigDir; -import org.spongepowered.api.event.Listener; -import org.spongepowered.api.event.game.state.GameStartedServerEvent; -import org.spongepowered.api.event.game.state.GameStoppingServerEvent; -import org.spongepowered.api.plugin.Dependency; -import org.spongepowered.api.plugin.Plugin; -import org.spongepowered.api.plugin.PluginContainer; -import org.spongepowered.api.scheduler.AsynchronousExecutor; -import org.spongepowered.api.scheduler.SpongeExecutorService; -import org.spongepowered.api.text.Text; -import org.spongepowered.api.world.Location; -import org.spongepowered.api.world.World; - -import java.nio.file.Path; -import java.util.List; -import java.util.Optional; -import java.util.logging.Level; -import java.util.stream.Stream; - -import javax.annotation.Nullable; - -@Plugin( - id = "spark", - name = "spark", - version = "@version@", - description = "@desc@", - authors = {"Luck"}, - dependencies = { - // explicit dependency on spongeapi with no defined API version - @Dependency(id = "spongeapi") - } -) -public class SpongeSparkPlugin implements SparkPlugin { - - private final PluginContainer pluginContainer; - private final Logger logger; - private final Game game; - private final Path configDirectory; - private final SpongeExecutorService asyncExecutor; - - private SparkPlatform platform; - private final ThreadDumper.GameThread threadDumper = new ThreadDumper.GameThread(); - - @Inject - public SpongeSparkPlugin(PluginContainer pluginContainer, Logger logger, Game game, @ConfigDir(sharedRoot = false) Path configDirectory, @AsynchronousExecutor SpongeExecutorService asyncExecutor) { - this.pluginContainer = pluginContainer; - this.logger = logger; - this.game = game; - this.configDirectory = configDirectory; - this.asyncExecutor = asyncExecutor; - } - - @Listener - public void onEnable(GameStartedServerEvent event) { - this.platform = new SparkPlatform(this); - this.platform.enable(); - this.game.getCommandManager().register(this, new SparkCommand(this), "spark"); - } - - @Listener - public void onDisable(GameStoppingServerEvent event) { - this.platform.disable(); - } - - @Override - public String getVersion() { - return SpongeSparkPlugin.class.getAnnotation(Plugin.class).version(); - } - - @Override - public Path getPluginDirectory() { - return this.configDirectory; - } - - @Override - public String getCommandName() { - return "spark"; - } - - @Override - public Stream getCommandSenders() { - return Stream.concat( - this.game.getServer().getOnlinePlayers().stream(), - Stream.of(this.game.getServer().getConsole()) - ).map(SpongeCommandSender::new); - } - - @Override - public void executeAsync(Runnable task) { - this.asyncExecutor.execute(task); - } - - @Override - public void log(Level level, String msg) { - if (level == Level.INFO) { - this.logger.info(msg); - } else if (level == Level.WARNING) { - this.logger.warn(msg); - } else if (level == Level.SEVERE) { - this.logger.error(msg); - } else { - throw new IllegalArgumentException(level.getName()); - } - } - - @Override - public ThreadDumper getDefaultThreadDumper() { - return this.threadDumper.get(); - } - - @Override - public TickHook createTickHook() { - return new SpongeTickHook(this); - } - - @Override - public PlatformInfo getPlatformInfo() { - return new SpongePlatformInfo(this.game); - } - - @Override - public void registerApi(Spark api) { - this.game.getServiceManager().setProvider(this, Spark.class, api); - } - - private static final class SparkCommand implements CommandCallable { - private final SpongeSparkPlugin plugin; - - private SparkCommand(SpongeSparkPlugin plugin) { - this.plugin = plugin; - } - - @Override - public CommandResult process(CommandSource source, String arguments) { - this.plugin.threadDumper.ensureSetup(); - this.plugin.platform.executeCommand(new SpongeCommandSender(source), arguments.split(" ")); - return CommandResult.empty(); - } - - @Override - public List getSuggestions(CommandSource source, String arguments, @Nullable Location targetPosition) { - return this.plugin.platform.tabCompleteCommand(new SpongeCommandSender(source), arguments.split(" ")); - } - - @Override - public boolean testPermission(CommandSource source) { - return this.plugin.platform.hasPermissionForAnyCommand(new SpongeCommandSender(source)); - } - - @Override - public Optional getShortDescription(CommandSource source) { - return Optional.of(Text.of("Main spark plugin command")); - } - - @Override - public Optional getHelp(CommandSource source) { - return Optional.of(Text.of("Run '/spark' to view usage.")); - } - - @Override - public Text getUsage(CommandSource source) { - return Text.of("Run '/spark' to view usage."); - } - } -} diff --git a/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeTickHook.java b/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeTickHook.java deleted file mode 100644 index b6903de..0000000 --- a/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeTickHook.java +++ /dev/null @@ -1,51 +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.sponge; - -import me.lucko.spark.common.tick.AbstractTickHook; -import me.lucko.spark.common.tick.TickHook; - -import org.spongepowered.api.scheduler.Task; - -public class SpongeTickHook extends AbstractTickHook implements TickHook, Runnable { - private final SpongeSparkPlugin plugin; - private Task task; - - public SpongeTickHook(SpongeSparkPlugin plugin) { - this.plugin = plugin; - } - - @Override - public void run() { - onTick(); - } - - @Override - public void start() { - this.task = Task.builder().intervalTicks(1).name("spark-ticker").execute(this).submit(this.plugin); - } - - @Override - public void close() { - this.task.cancel(); - } - -} diff --git a/spark-sponge7/build.gradle b/spark-sponge7/build.gradle new file mode 100644 index 0000000..fe555b0 --- /dev/null +++ b/spark-sponge7/build.gradle @@ -0,0 +1,43 @@ +plugins { + id 'net.kyori.blossom' version '1.3.0' + id 'com.github.johnrengelman.shadow' version '7.0.0' +} + +dependencies { + implementation project(':spark-common') + compileOnly 'org.spongepowered:spongeapi:7.3.0' + annotationProcessor 'org.spongepowered:spongeapi:7.3.0' +} + +repositories { + maven { url "https://repo.spongepowered.org/maven" } +} + +blossom { + replaceTokenIn('src/main/java/me/lucko/spark/sponge/SpongeSparkPlugin.java') + replaceToken '@version@', project.pluginVersion + replaceToken '@desc@', project.pluginDescription +} + +shadowJar { + archiveFileName = 'spark-sponge7.jar' + + relocate 'okio', 'me.lucko.spark.lib.okio' + relocate 'okhttp3', 'me.lucko.spark.lib.okhttp3' + relocate 'net.kyori.adventure', 'me.lucko.spark.lib.adventure' + relocate 'net.kyori.examination', 'me.lucko.spark.lib.adventure.examination' + relocate 'net.bytebuddy', 'me.lucko.spark.lib.bytebuddy' + relocate 'org.tukaani.xz', 'me.lucko.spark.lib.xz' + 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' + + exclude 'module-info.class' + exclude 'META-INF/maven/**' + exclude 'META-INF/proguard/**' +} + +artifacts { + archives shadowJar + shadow shadowJar +} diff --git a/spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7CommandSender.java b/spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7CommandSender.java new file mode 100644 index 0000000..b0cfd3c --- /dev/null +++ b/spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7CommandSender.java @@ -0,0 +1,61 @@ +/* + * 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.text.Component; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; + +import org.spongepowered.api.command.CommandSource; +import org.spongepowered.api.entity.living.player.Player; +import org.spongepowered.api.text.serializer.TextSerializers; + +import java.util.UUID; + +public class Sponge7CommandSender extends AbstractCommandSender { + public Sponge7CommandSender(CommandSource source) { + super(source); + } + + @Override + public String getName() { + return super.delegate.getName(); + } + + @Override + public UUID getUniqueId() { + if (super.delegate instanceof Player) { + return ((Player) super.delegate).getUniqueId(); + } + return null; + } + + @Override + public void sendMessage(Component message) { + super.delegate.sendMessage(TextSerializers.JSON.deserialize(GsonComponentSerializer.gson().serialize(message))); + } + + @Override + public boolean hasPermission(String permission) { + return super.delegate.hasPermission(permission); + } +} diff --git a/spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7PlatformInfo.java b/spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7PlatformInfo.java new file mode 100644 index 0000000..91d7ea2 --- /dev/null +++ b/spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7PlatformInfo.java @@ -0,0 +1,54 @@ +/* + * 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; + +public class Sponge7PlatformInfo implements PlatformInfo { + private final Game game; + + public Sponge7PlatformInfo(Game game) { + this.game = game; + } + + @Override + public Type getType() { + return Type.SERVER; + } + + @Override + public String getName() { + return "Sponge"; + } + + @Override + public String getVersion() { + return this.game.getPlatform().getContainer(Platform.Component.IMPLEMENTATION).getVersion().orElse("unknown"); + } + + @Override + public String getMinecraftVersion() { + return this.game.getPlatform().getMinecraftVersion().getName(); + } +} diff --git a/spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7SparkPlugin.java b/spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7SparkPlugin.java new file mode 100644 index 0000000..7ac317b --- /dev/null +++ b/spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7SparkPlugin.java @@ -0,0 +1,196 @@ +/* + * 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.inject.Inject; + +import me.lucko.spark.api.Spark; +import me.lucko.spark.common.SparkPlatform; +import me.lucko.spark.common.SparkPlugin; +import me.lucko.spark.common.platform.PlatformInfo; +import me.lucko.spark.common.sampler.ThreadDumper; +import me.lucko.spark.common.tick.TickHook; + +import org.slf4j.Logger; +import org.spongepowered.api.Game; +import org.spongepowered.api.command.CommandCallable; +import org.spongepowered.api.command.CommandResult; +import org.spongepowered.api.command.CommandSource; +import org.spongepowered.api.config.ConfigDir; +import org.spongepowered.api.event.Listener; +import org.spongepowered.api.event.game.state.GameStartedServerEvent; +import org.spongepowered.api.event.game.state.GameStoppingServerEvent; +import org.spongepowered.api.plugin.Plugin; +import org.spongepowered.api.plugin.PluginContainer; +import org.spongepowered.api.scheduler.AsynchronousExecutor; +import org.spongepowered.api.scheduler.SpongeExecutorService; +import org.spongepowered.api.text.Text; +import org.spongepowered.api.world.Location; +import org.spongepowered.api.world.World; + +import java.nio.file.Path; +import java.util.List; +import java.util.Optional; +import java.util.logging.Level; +import java.util.stream.Stream; + +import javax.annotation.Nullable; + +@Plugin( + id = "spark", + name = "spark", + version = "@version@", + description = "@desc@", + authors = {"Luck"} +) +public class Sponge7SparkPlugin implements SparkPlugin { + + private final PluginContainer pluginContainer; + private final Logger logger; + private final Game game; + private final Path configDirectory; + private final SpongeExecutorService asyncExecutor; + + private SparkPlatform platform; + private final ThreadDumper.GameThread threadDumper = new ThreadDumper.GameThread(); + + @Inject + public Sponge7SparkPlugin(PluginContainer pluginContainer, Logger logger, Game game, @ConfigDir(sharedRoot = false) Path configDirectory, @AsynchronousExecutor SpongeExecutorService asyncExecutor) { + this.pluginContainer = pluginContainer; + this.logger = logger; + this.game = game; + this.configDirectory = configDirectory; + this.asyncExecutor = asyncExecutor; + } + + @Listener + public void onEnable(GameStartedServerEvent event) { + this.platform = new SparkPlatform(this); + this.platform.enable(); + this.game.getCommandManager().register(this, new SparkCommand(this), "spark"); + } + + @Listener + public void onDisable(GameStoppingServerEvent event) { + this.platform.disable(); + } + + @Override + public String getVersion() { + return Sponge7SparkPlugin.class.getAnnotation(Plugin.class).version(); + } + + @Override + public Path getPluginDirectory() { + return this.configDirectory; + } + + @Override + public String getCommandName() { + return "spark"; + } + + @Override + public Stream getCommandSenders() { + return Stream.concat( + this.game.getServer().getOnlinePlayers().stream(), + Stream.of(this.game.getServer().getConsole()) + ).map(Sponge7CommandSender::new); + } + + @Override + public void executeAsync(Runnable task) { + this.asyncExecutor.execute(task); + } + + @Override + public void log(Level level, String msg) { + if (level == Level.INFO) { + this.logger.info(msg); + } else if (level == Level.WARNING) { + this.logger.warn(msg); + } else if (level == Level.SEVERE) { + this.logger.error(msg); + } else { + throw new IllegalArgumentException(level.getName()); + } + } + + @Override + public ThreadDumper getDefaultThreadDumper() { + return this.threadDumper.get(); + } + + @Override + public TickHook createTickHook() { + return new Sponge7TickHook(this); + } + + @Override + public PlatformInfo getPlatformInfo() { + return new Sponge7PlatformInfo(this.game); + } + + @Override + public void registerApi(Spark api) { + this.game.getServiceManager().setProvider(this, Spark.class, api); + } + + private static final class SparkCommand implements CommandCallable { + private final Sponge7SparkPlugin plugin; + + private SparkCommand(Sponge7SparkPlugin plugin) { + this.plugin = plugin; + } + + @Override + public CommandResult process(CommandSource source, String arguments) { + this.plugin.threadDumper.ensureSetup(); + this.plugin.platform.executeCommand(new Sponge7CommandSender(source), arguments.split(" ")); + return CommandResult.empty(); + } + + @Override + public List getSuggestions(CommandSource source, String arguments, @Nullable Location targetPosition) { + return this.plugin.platform.tabCompleteCommand(new Sponge7CommandSender(source), arguments.split(" ")); + } + + @Override + public boolean testPermission(CommandSource source) { + return this.plugin.platform.hasPermissionForAnyCommand(new Sponge7CommandSender(source)); + } + + @Override + public Optional getShortDescription(CommandSource source) { + return Optional.of(Text.of("Main spark plugin command")); + } + + @Override + public Optional getHelp(CommandSource source) { + return Optional.of(Text.of("Run '/spark' to view usage.")); + } + + @Override + public Text getUsage(CommandSource source) { + return Text.of("Run '/spark' to view usage."); + } + } +} diff --git a/spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7TickHook.java b/spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7TickHook.java new file mode 100644 index 0000000..2618522 --- /dev/null +++ b/spark-sponge7/src/main/java/me/lucko/spark/sponge/Sponge7TickHook.java @@ -0,0 +1,51 @@ +/* + * 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.tick.AbstractTickHook; +import me.lucko.spark.common.tick.TickHook; + +import org.spongepowered.api.scheduler.Task; + +public class Sponge7TickHook extends AbstractTickHook implements TickHook, Runnable { + private final Sponge7SparkPlugin plugin; + private Task task; + + public Sponge7TickHook(Sponge7SparkPlugin plugin) { + this.plugin = plugin; + } + + @Override + public void run() { + onTick(); + } + + @Override + public void start() { + this.task = Task.builder().intervalTicks(1).name("spark-ticker").execute(this).submit(this.plugin); + } + + @Override + public void close() { + this.task.cancel(); + } + +} diff --git a/spark-universal/build.gradle b/spark-universal/build.gradle index 26dbd30..f784a9e 100644 --- a/spark-universal/build.gradle +++ b/spark-universal/build.gradle @@ -6,7 +6,6 @@ dependencies { implementation project(':spark-common') implementation project(':spark-bukkit') implementation project(':spark-bungeecord') - implementation project(':spark-sponge') } shadowJar { -- cgit From 25f46b649363d99f51b1b5262b5f7c0ce0c3251b Mon Sep 17 00:00:00 2001 From: Luck Date: Sun, 6 Feb 2022 20:25:07 +0000 Subject: Improve build tooling - add version to output file name - check license headers automatically --- HEADER.txt | 17 +++++++++++ build.gradle | 27 ++++++++++++++++-- settings.gradle | 4 +-- spark-api/HEADER.txt | 22 +++++++++++++++ spark-api/build.gradle | 4 +++ spark-bukkit/build.gradle | 29 ++++++++++++++++++- .../java/me/lucko/spark/bukkit/CommandMapUtil.java | 27 ++++++++---------- .../placeholder/SparkPlaceholderProvider.java | 2 +- spark-bungeecord/build.gradle | 29 ++++++++++++++++++- spark-common/build.gradle | 4 +++ .../command/tabcomplete/CompletionSupplier.java | 27 ++++++++---------- .../common/command/tabcomplete/TabCompleter.java | 27 ++++++++---------- .../spark/common/monitor/MonitoringExecutor.java | 20 +++++++++++++ .../lucko/spark/common/sampler/ThreadDumper.java | 1 - .../spark/common/sampler/java/JavaSampler.java | 1 - .../spark/common/sampler/node/AbstractNode.java | 1 - .../spark/common/sampler/node/StackTraceNode.java | 1 - .../me/lucko/spark/common/util/BytebinClient.java | 27 ++++++++---------- spark-fabric/build.gradle | 4 +-- .../placeholder/SparkFabricPlaceholderApi.java | 20 +++++++++++++ spark-forge/build.gradle | 2 +- spark-nukkit/build.gradle | 2 +- spark-sponge7/build.gradle | 2 +- spark-sponge8/build.gradle | 2 +- .../lucko/spark/sponge/Sponge8CommandSender.java | 1 + spark-universal/build.gradle | 33 ---------------------- spark-velocity/build.gradle | 2 +- spark-velocity4/build.gradle | 2 +- spark-waterdog/build.gradle | 2 +- 29 files changed, 224 insertions(+), 118 deletions(-) create mode 100644 HEADER.txt create mode 100644 spark-api/HEADER.txt delete mode 100644 spark-universal/build.gradle (limited to 'settings.gradle') diff --git a/HEADER.txt b/HEADER.txt new file mode 100644 index 0000000..3457e84 --- /dev/null +++ b/HEADER.txt @@ -0,0 +1,17 @@ +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 . \ No newline at end of file diff --git a/build.gradle b/build.gradle index 9e64e75..2780159 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,10 @@ +plugins { + id 'org.cadixdev.licenser' version '0.6.1' apply false +} + allprojects { group = 'me.lucko' - version = '1.6-SNAPSHOT' + version = '1.8-SNAPSHOT' configurations { compileClasspath // Fabric-loom needs this for remap jar for some reason @@ -11,9 +15,12 @@ subprojects { apply plugin: 'java' apply plugin: 'idea' apply plugin: 'java-library' + apply plugin: 'org.cadixdev.licenser' ext { - pluginVersion = '1.8.0' + baseVersion = '1.8' + patchVersion = determinePatchVersion() + pluginVersion = baseVersion + '.' + patchVersion pluginDescription = 'spark is a performance profiling plugin/mod for Minecraft clients, servers and proxies.' } @@ -26,6 +33,11 @@ subprojects { duplicatesStrategy = DuplicatesStrategy.INCLUDE } + license { + header = rootProject.file('HEADER.txt') + include '**/*.java' + } + repositories { mavenCentral() maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } @@ -34,3 +46,14 @@ subprojects { } } + +def determinePatchVersion() { + def tagInfo = new ByteArrayOutputStream() + exec { + commandLine 'git', 'describe', '--tags' + standardOutput = tagInfo + } + tagInfo = tagInfo.toString() + + return tagInfo.contains('-') ? tagInfo.split("-")[1] : 0 +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 09d0a60..8ec8a72 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,5 @@ pluginManagement { repositories { - jcenter() maven { name = 'Fabric' url = 'https://maven.fabricmc.net/' @@ -22,6 +21,5 @@ include ( 'spark-forge', 'spark-fabric', 'spark-nukkit', - 'spark-waterdog', - 'spark-universal' + 'spark-waterdog' ) diff --git a/spark-api/HEADER.txt b/spark-api/HEADER.txt new file mode 100644 index 0000000..63aafcb --- /dev/null +++ b/spark-api/HEADER.txt @@ -0,0 +1,22 @@ +This file is part of spark, licensed under the MIT License. + + Copyright (c) lucko (Luck) + 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: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + 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. \ No newline at end of file diff --git a/spark-api/build.gradle b/spark-api/build.gradle index 31458af..0fbe9e1 100644 --- a/spark-api/build.gradle +++ b/spark-api/build.gradle @@ -9,6 +9,10 @@ dependencies { compileOnly 'org.jetbrains:annotations:20.1.0' } +license { + header = project.file('HEADER.txt') +} + publishing { //repositories { // maven { diff --git a/spark-bukkit/build.gradle b/spark-bukkit/build.gradle index b66134d..8e111e8 100644 --- a/spark-bukkit/build.gradle +++ b/spark-bukkit/build.gradle @@ -1,3 +1,7 @@ +plugins { + id 'com.github.johnrengelman.shadow' version '7.0.0' +} + dependencies { implementation project(':spark-common') implementation('me.lucko:adventure-platform-bukkit:4.9.4') { @@ -28,4 +32,27 @@ processResources { ) include 'plugin.yml' } -} \ No newline at end of file +} + +shadowJar { + archiveName = "spark-${project.pluginVersion}-bukkit.jar" + + relocate 'okio', 'me.lucko.spark.lib.okio' + relocate 'okhttp3', 'me.lucko.spark.lib.okhttp3' + relocate 'net.kyori.adventure', 'me.lucko.spark.lib.adventure' + relocate 'net.kyori.examination', 'me.lucko.spark.lib.adventure.examination' + relocate 'net.bytebuddy', 'me.lucko.spark.lib.bytebuddy' + relocate 'org.tukaani.xz', 'me.lucko.spark.lib.xz' + 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' + + exclude 'module-info.class' + exclude 'META-INF/maven/**' + exclude 'META-INF/proguard/**' +} + +artifacts { + archives shadowJar + shadow shadowJar +} 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) * 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 . */ 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 96c9e93..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) * 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 diff --git a/spark-bungeecord/build.gradle b/spark-bungeecord/build.gradle index f1a6db5..ccea89d 100644 --- a/spark-bungeecord/build.gradle +++ b/spark-bungeecord/build.gradle @@ -1,3 +1,7 @@ +plugins { + id 'com.github.johnrengelman.shadow' version '7.0.0' +} + dependencies { implementation project(':spark-common') implementation('me.lucko:adventure-platform-bungeecord:4.9.4') { @@ -18,4 +22,27 @@ processResources { ) include 'bungee.yml' } -} \ No newline at end of file +} + +shadowJar { + archiveName = "spark-${project.pluginVersion}-bungeecord.jar" + + relocate 'okio', 'me.lucko.spark.lib.okio' + relocate 'okhttp3', 'me.lucko.spark.lib.okhttp3' + relocate 'net.kyori.adventure', 'me.lucko.spark.lib.adventure' + relocate 'net.kyori.examination', 'me.lucko.spark.lib.adventure.examination' + relocate 'net.bytebuddy', 'me.lucko.spark.lib.bytebuddy' + relocate 'org.tukaani.xz', 'me.lucko.spark.lib.xz' + 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' + + exclude 'module-info.class' + exclude 'META-INF/maven/**' + exclude 'META-INF/proguard/**' +} + +artifacts { + archives shadowJar + shadow shadowJar +} diff --git a/spark-common/build.gradle b/spark-common/build.gradle index c1ddafb..aa0f409 100644 --- a/spark-common/build.gradle +++ b/spark-common/build.gradle @@ -2,6 +2,10 @@ plugins { id 'com.google.protobuf' version '0.8.16' } +license { + exclude '**/sampler/async/jfr/**' +} + dependencies { api project(':spark-api') implementation 'com.github.jvm-profiling-tools:async-profiler:v2.5' diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/tabcomplete/CompletionSupplier.java b/spark-common/src/main/java/me/lucko/spark/common/command/tabcomplete/CompletionSupplier.java index f1a6d10..9975df5 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/tabcomplete/CompletionSupplier.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/tabcomplete/CompletionSupplier.java @@ -1,26 +1,21 @@ /* - * This file is part of LuckPerms, licensed under the MIT License. + * This file is part of spark. * * Copyright (c) lucko (Luck) * 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 . */ package me.lucko.spark.common.command.tabcomplete; diff --git a/spark-common/src/main/java/me/lucko/spark/common/command/tabcomplete/TabCompleter.java b/spark-common/src/main/java/me/lucko/spark/common/command/tabcomplete/TabCompleter.java index d2b2622..9707f55 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/command/tabcomplete/TabCompleter.java +++ b/spark-common/src/main/java/me/lucko/spark/common/command/tabcomplete/TabCompleter.java @@ -1,26 +1,21 @@ /* - * This file is part of LuckPerms, licensed under the MIT License. + * This file is part of spark. * * Copyright (c) lucko (Luck) * 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 . */ package me.lucko.spark.common.command.tabcomplete; diff --git a/spark-common/src/main/java/me/lucko/spark/common/monitor/MonitoringExecutor.java b/spark-common/src/main/java/me/lucko/spark/common/monitor/MonitoringExecutor.java index 779dbbf..635ae20 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/monitor/MonitoringExecutor.java +++ b/spark-common/src/main/java/me/lucko/spark/common/monitor/MonitoringExecutor.java @@ -1,3 +1,23 @@ +/* + * 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.common.monitor; import java.util.concurrent.Executors; diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java index 5cc41b9..9d54f50 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java +++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/ThreadDumper.java @@ -1,7 +1,6 @@ /* * This file is part of spark. * - * Copyright (C) Albert Pham * Copyright (c) lucko (Luck) * Copyright (c) contributors * diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/java/JavaSampler.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/java/JavaSampler.java index d2959bd..2bedae6 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/sampler/java/JavaSampler.java +++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/java/JavaSampler.java @@ -1,7 +1,6 @@ /* * This file is part of spark. * - * Copyright (C) Albert Pham * Copyright (c) lucko (Luck) * Copyright (c) contributors * diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/node/AbstractNode.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/node/AbstractNode.java index 18f67ba..fd2be8d 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/sampler/node/AbstractNode.java +++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/node/AbstractNode.java @@ -1,7 +1,6 @@ /* * This file is part of spark. * - * Copyright (C) Albert Pham * Copyright (c) lucko (Luck) * Copyright (c) contributors * diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/node/StackTraceNode.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/node/StackTraceNode.java index 54217be..b0d9237 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/sampler/node/StackTraceNode.java +++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/node/StackTraceNode.java @@ -1,7 +1,6 @@ /* * This file is part of spark. * - * Copyright (C) Albert Pham * Copyright (c) lucko (Luck) * Copyright (c) contributors * diff --git a/spark-common/src/main/java/me/lucko/spark/common/util/BytebinClient.java b/spark-common/src/main/java/me/lucko/spark/common/util/BytebinClient.java index 29ee5bb..c2ca1b1 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/util/BytebinClient.java +++ b/spark-common/src/main/java/me/lucko/spark/common/util/BytebinClient.java @@ -1,26 +1,21 @@ /* - * This file is part of bytebin, licensed under the MIT License. + * This file is part of spark. * * Copyright (c) lucko (Luck) * 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 . */ package me.lucko.spark.common.util; diff --git a/spark-fabric/build.gradle b/spark-fabric/build.gradle index d7e87cd..8cdf5fe 100644 --- a/spark-fabric/build.gradle +++ b/spark-fabric/build.gradle @@ -67,7 +67,7 @@ processResources { } shadowJar { - archiveFileName = 'spark-fabric-dev.jar' + archiveFileName = "spark-fabric-${project.pluginVersion}-dev.jar" configurations = [project.configurations.shade] relocate 'okio', 'me.lucko.spark.lib.okio' @@ -89,7 +89,7 @@ task remappedShadowJar(type: RemapJarTask) { dependsOn tasks.shadowJar input = tasks.shadowJar.archiveFile addNestedDependencies = true - archiveFileName = 'spark-fabric.jar' + archiveFileName = "spark-${project.pluginVersion}-fabric.jar" } tasks.assemble.dependsOn tasks.remappedShadowJar diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/placeholder/SparkFabricPlaceholderApi.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/placeholder/SparkFabricPlaceholderApi.java index b9cff691..dc2e7d9 100644 --- a/spark-fabric/src/main/java/me/lucko/spark/fabric/placeholder/SparkFabricPlaceholderApi.java +++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/placeholder/SparkFabricPlaceholderApi.java @@ -1,3 +1,23 @@ +/* + * 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.fabric.placeholder; import eu.pb4.placeholders.PlaceholderAPI; diff --git a/spark-forge/build.gradle b/spark-forge/build.gradle index e0fe0f8..25e51ef 100644 --- a/spark-forge/build.gradle +++ b/spark-forge/build.gradle @@ -49,7 +49,7 @@ processResources { } shadowJar { - archiveName = 'spark-forge.jar' + archiveName = "spark-${project.pluginVersion}-forge.jar" configurations = [project.configurations.shade] relocate 'okio', 'me.lucko.spark.lib.okio' diff --git a/spark-nukkit/build.gradle b/spark-nukkit/build.gradle index ff36091..2e1ad55 100644 --- a/spark-nukkit/build.gradle +++ b/spark-nukkit/build.gradle @@ -23,7 +23,7 @@ processResources { } shadowJar { - archiveName = 'spark-nukkit.jar' + archiveName = "spark-${project.pluginVersion}-nukkit.jar" relocate 'okio', 'me.lucko.spark.lib.okio' relocate 'okhttp3', 'me.lucko.spark.lib.okhttp3' diff --git a/spark-sponge7/build.gradle b/spark-sponge7/build.gradle index 5b26924..b18ffdb 100644 --- a/spark-sponge7/build.gradle +++ b/spark-sponge7/build.gradle @@ -20,7 +20,7 @@ blossom { } shadowJar { - archiveFileName = 'spark-sponge7.jar' + archiveFileName = "spark-${project.pluginVersion}-sponge7.jar" relocate 'okio', 'me.lucko.spark.lib.okio' relocate 'okhttp3', 'me.lucko.spark.lib.okhttp3' diff --git a/spark-sponge8/build.gradle b/spark-sponge8/build.gradle index 45f17b3..314ab18 100644 --- a/spark-sponge8/build.gradle +++ b/spark-sponge8/build.gradle @@ -22,7 +22,7 @@ processResources { } shadowJar { - archiveFileName = 'spark-sponge8.jar' + archiveFileName = "spark-${project.pluginVersion}-sponge8.jar" dependencies { exclude(dependency('net.kyori:^(?!adventure-text-feature-pagination).+$')) diff --git a/spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8CommandSender.java b/spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8CommandSender.java index 5e7a65a..e7878dc 100644 --- a/spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8CommandSender.java +++ b/spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8CommandSender.java @@ -17,6 +17,7 @@ * 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; diff --git a/spark-universal/build.gradle b/spark-universal/build.gradle deleted file mode 100644 index f784a9e..0000000 --- a/spark-universal/build.gradle +++ /dev/null @@ -1,33 +0,0 @@ -plugins { - id 'com.github.johnrengelman.shadow' version '7.0.0' -} - -dependencies { - implementation project(':spark-common') - implementation project(':spark-bukkit') - implementation project(':spark-bungeecord') -} - -shadowJar { - archiveName = 'spark.jar' - - relocate 'okio', 'me.lucko.spark.lib.okio' - relocate 'okhttp3', 'me.lucko.spark.lib.okhttp3' - relocate 'net.kyori.adventure', 'me.lucko.spark.lib.adventure' - relocate 'net.kyori.examination', 'me.lucko.spark.lib.adventure.examination' - relocate 'net.bytebuddy', 'me.lucko.spark.lib.bytebuddy' - relocate 'org.tukaani.xz', 'me.lucko.spark.lib.xz' - 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' - - exclude 'module-info.class' - exclude 'META-INF/maven/**' - exclude 'META-INF/proguard/**' -} - -artifacts { - archives shadowJar - shadow shadowJar -} - diff --git a/spark-velocity/build.gradle b/spark-velocity/build.gradle index 8a345f9..b2e938b 100644 --- a/spark-velocity/build.gradle +++ b/spark-velocity/build.gradle @@ -20,7 +20,7 @@ blossom { } shadowJar { - archiveName = 'spark-velocity.jar' + archiveName = "spark-${project.pluginVersion}-velocity.jar" dependencies { exclude(dependency('net.kyori:^(?!adventure-text-feature-pagination).+$')) diff --git a/spark-velocity4/build.gradle b/spark-velocity4/build.gradle index e2a0559..5bef80b 100644 --- a/spark-velocity4/build.gradle +++ b/spark-velocity4/build.gradle @@ -25,7 +25,7 @@ blossom { } shadowJar { - archiveName = 'spark-velocity4.jar' + archiveName = "spark-${project.pluginVersion}-velocity4.jar" dependencies { exclude(dependency('net.kyori:^(?!adventure-text-feature-pagination).+$')) diff --git a/spark-waterdog/build.gradle b/spark-waterdog/build.gradle index 07be15c..c11e3fb 100644 --- a/spark-waterdog/build.gradle +++ b/spark-waterdog/build.gradle @@ -28,7 +28,7 @@ processResources { } shadowJar { - archiveName = 'spark-waterdog.jar' + archiveName = "spark-${project.pluginVersion}-waterdog.jar" relocate 'okio', 'me.lucko.spark.lib.okio' relocate 'okhttp3', 'me.lucko.spark.lib.okhttp3' -- cgit From d3e6d73b6be762558a3c7ff991ba52d4d6cfb74d Mon Sep 17 00:00:00 2001 From: Huynh Tien Date: Fri, 20 May 2022 00:09:51 +0700 Subject: Minestom platform (#203) --- settings.gradle | 3 +- .../java/me/lucko/spark/common/SparkPlatform.java | 2 +- spark-minestom/build.gradle | 50 +++++++ .../spark/minestom/MinestomClassSourceLookup.java | 48 +++++++ .../spark/minestom/MinestomCommandSender.java | 64 +++++++++ .../lucko/spark/minestom/MinestomPlatformInfo.java | 46 +++++++ .../spark/minestom/MinestomPlayerPingProvider.java | 39 ++++++ .../spark/minestom/MinestomSparkExtension.java | 151 +++++++++++++++++++++ .../me/lucko/spark/minestom/MinestomTickHook.java | 46 +++++++ .../lucko/spark/minestom/MinestomTickReporter.java | 47 +++++++ spark-minestom/src/main/resources/extension.json | 5 + 11 files changed, 499 insertions(+), 2 deletions(-) create mode 100644 spark-minestom/build.gradle create mode 100644 spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomClassSourceLookup.java create mode 100644 spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomCommandSender.java create mode 100644 spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomPlatformInfo.java create mode 100644 spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomPlayerPingProvider.java create mode 100644 spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomSparkExtension.java create mode 100644 spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomTickHook.java create mode 100644 spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomTickReporter.java create mode 100644 spark-minestom/src/main/resources/extension.json (limited to 'settings.gradle') diff --git a/settings.gradle b/settings.gradle index 8ec8a72..5dd9582 100644 --- a/settings.gradle +++ b/settings.gradle @@ -21,5 +21,6 @@ include ( 'spark-forge', 'spark-fabric', 'spark-nukkit', - 'spark-waterdog' + 'spark-waterdog', + 'spark-minestom' ) diff --git a/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java b/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java index a961925..a79d110 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java +++ b/spark-common/src/main/java/me/lucko/spark/common/SparkPlatform.java @@ -142,7 +142,7 @@ public class SparkPlatform { this.tickHook = plugin.createTickHook(); this.tickReporter = plugin.createTickReporter(); - this.tickStatistics = this.tickHook != null ? new TickStatistics() : null; + this.tickStatistics = this.tickHook != null || this.tickReporter != null ? new TickStatistics() : null; PlayerPingProvider pingProvider = plugin.createPlayerPingProvider(); this.pingStatistics = pingProvider != null ? new PingStatistics(pingProvider) : null; diff --git a/spark-minestom/build.gradle b/spark-minestom/build.gradle new file mode 100644 index 0000000..26cdc2c --- /dev/null +++ b/spark-minestom/build.gradle @@ -0,0 +1,50 @@ +plugins { + id 'com.github.johnrengelman.shadow' version '7.0.0' +} + +tasks.withType(JavaCompile) { + // override, compile targeting J17 + options.release = 17 +} + +dependencies { + implementation project(':spark-common') + compileOnly 'com.github.Minestom:Minestom:367c389bc6' + implementation 'com.google.guava:guava:19.0' +} + +processResources { + from(sourceSets.main.resources.srcDirs) { + expand ( + 'pluginVersion': project.pluginVersion, + 'pluginDescription': project.pluginDescription + ) + include 'extension.json' + } +} + +shadowJar { + archiveName = "spark-${project.pluginVersion}-minestom.jar" + + dependencies { + exclude(dependency('net.kyori:^(?!adventure-text-feature-pagination).+$')) + } + + relocate 'okio', 'me.lucko.spark.lib.okio' + relocate 'okhttp3', 'me.lucko.spark.lib.okhttp3' + relocate 'net.kyori.adventure.text.feature.pagination', 'me.lucko.spark.lib.adventure.pagination' + relocate 'net.bytebuddy', 'me.lucko.spark.lib.bytebuddy' + relocate 'org.tukaani.xz', 'me.lucko.spark.lib.xz' + 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' + + exclude 'module-info.class' + exclude 'META-INF/maven/**' + exclude 'META-INF/proguard/**' +} + +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 new file mode 100644 index 0000000..a3cf04c --- /dev/null +++ b/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomClassSourceLookup.java @@ -0,0 +1,48 @@ +/* + * 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.util.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 new file mode 100644 index 0000000..3fc1a82 --- /dev/null +++ b/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomCommandSender.java @@ -0,0 +1,64 @@ +/* + * 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 (delegate instanceof Player player) { + return player.getUsername(); + } else if (delegate instanceof ConsoleSender) { + return "Console"; + }else { + return "unknown:" + delegate.getClass().getSimpleName(); + } + } + + @Override + public UUID getUniqueId() { + if (super.delegate instanceof Player player) { + return player.getUuid(); + } + return null; + } + + @Override + public void sendMessage(Component message) { + delegate.sendMessage(message); + } + + @Override + public boolean hasPermission(String permission) { + return 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 new file mode 100644 index 0000000..64dea89 --- /dev/null +++ b/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomPlatformInfo.java @@ -0,0 +1,46 @@ +/* + * 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 new file mode 100644 index 0000000..8fb42e0 --- /dev/null +++ b/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomPlayerPingProvider.java @@ -0,0 +1,39 @@ +/* + * 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/MinestomSparkExtension.java b/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomSparkExtension.java new file mode 100644 index 0000000..a99f49c --- /dev/null +++ b/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomSparkExtension.java @@ -0,0 +1,151 @@ +/* + * 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.command.sender.CommandSender; +import me.lucko.spark.common.monitor.ping.PlayerPingProvider; +import me.lucko.spark.common.platform.PlatformInfo; +import me.lucko.spark.common.tick.TickHook; +import me.lucko.spark.common.tick.TickReporter; +import me.lucko.spark.common.util.ClassSourceLookup; +import net.minestom.server.MinecraftServer; +import net.minestom.server.command.builder.Command; +import net.minestom.server.command.builder.arguments.ArgumentStringArray; +import net.minestom.server.command.builder.arguments.ArgumentType; +import net.minestom.server.command.builder.suggestion.SuggestionEntry; +import net.minestom.server.extensions.Extension; +import net.minestom.server.timer.ExecutionType; + +import java.nio.file.Path; +import java.util.logging.Level; +import java.util.stream.Stream; + +public class MinestomSparkExtension extends Extension implements SparkPlugin { + private SparkPlatform platform; + private MinestomSparkCommand 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 PlayerPingProvider createPlayerPingProvider() { + return new MinestomPlayerPingProvider(); + } + + @Override + public TickReporter createTickReporter() { + return new MinestomTickReporter(); + } + + @Override + public TickHook createTickHook() { + return new MinestomTickHook(); + } + + @Override + public void initialize() { + this.platform = new SparkPlatform(this); + this.platform.enable(); + this.command = new MinestomSparkCommand(this); + MinecraftServer.getCommandManager().register(command); + } + + @Override + public void terminate() { + this.platform.disable(); + MinecraftServer.getCommandManager().unregister(command); + } + + private static final class MinestomSparkCommand extends Command { + public MinestomSparkCommand(MinestomSparkExtension extension) { + super("spark", "sparkms"); + setDefaultExecutor((sender, context) -> extension.platform.executeCommand(new MinestomCommandSender(sender), new String[0])); + ArgumentStringArray arrayArgument = ArgumentType.StringArray("query"); + arrayArgument.setSuggestionCallback((sender, context, suggestion) -> { + String[] args = context.get(arrayArgument); + if (args == null) { + args = new String[0]; + } + Iterable suggestionEntries = extension.platform.tabCompleteCommand(new MinestomCommandSender(sender), args); + for (String suggestionEntry : suggestionEntries) { + suggestion.addEntry(new SuggestionEntry(suggestionEntry)); + } + }); + addSyntax((sender, context) -> { + String[] args = context.get(arrayArgument); + if (args == null) { + args = new String[0]; + } + extension.platform.executeCommand(new MinestomCommandSender(sender), args); + }, arrayArgument); + } + } +} 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 new file mode 100644 index 0000000..e5a1895 --- /dev/null +++ b/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomTickHook.java @@ -0,0 +1,46 @@ +/* + * 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() { + task = MinecraftServer.getSchedulerManager() + .buildTask(this::onTick) + .delay(TaskSchedule.tick(1)) + .repeat(TaskSchedule.tick(1)) + .schedule(); + } + + @Override + public void close() { + if (task != null) { + 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 new file mode 100644 index 0000000..dbb09ea --- /dev/null +++ b/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomTickReporter.java @@ -0,0 +1,47 @@ +/* + * 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() { + node.addListener(ServerTickMonitorEvent.class, event -> onTick(event.getTickMonitor().getTickTime())); + } + + @Override + public void start() { + MinecraftServer.getGlobalEventHandler().addChild(node); + } + + @Override + public void close() { + MinecraftServer.getGlobalEventHandler().removeChild(node); + } +} diff --git a/spark-minestom/src/main/resources/extension.json b/spark-minestom/src/main/resources/extension.json new file mode 100644 index 0000000..de58a69 --- /dev/null +++ b/spark-minestom/src/main/resources/extension.json @@ -0,0 +1,5 @@ +{ + "entrypoint": "me.lucko.spark.minestom.MinestomSparkExtension", + "name": "spark", + "version": "${pluginVersion}" +} \ No newline at end of file -- cgit