diff options
Diffstat (limited to 'spark-minestom')
-rw-r--r-- | spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomClassSourceLookup.java | 1 | ||||
-rw-r--r-- | spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomCommandSender.java | 11 | ||||
-rw-r--r-- | spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomPlatformInfo.java | 1 | ||||
-rw-r--r-- | spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomPlayerPingProvider.java | 2 | ||||
-rw-r--r-- | spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomSparkPlugin.java (renamed from spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomSparkExtension.java) | 106 | ||||
-rw-r--r-- | spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomTickHook.java | 7 | ||||
-rw-r--r-- | spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomTickReporter.java | 7 | ||||
-rw-r--r-- | spark-minestom/src/main/resources/extension.json | 2 |
8 files changed, 88 insertions, 49 deletions
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 index a3cf04c..252060e 100644 --- a/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomClassSourceLookup.java +++ b/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomClassSourceLookup.java @@ -21,6 +21,7 @@ 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; 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 index 3fc1a82..da46224 100644 --- a/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomCommandSender.java +++ b/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomCommandSender.java @@ -21,6 +21,7 @@ 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; @@ -35,12 +36,12 @@ public class MinestomCommandSender extends AbstractCommandSender<CommandSender> @Override public String getName() { - if (delegate instanceof Player player) { + if (this.delegate instanceof Player player) { return player.getUsername(); - } else if (delegate instanceof ConsoleSender) { + } else if (this.delegate instanceof ConsoleSender) { return "Console"; }else { - return "unknown:" + delegate.getClass().getSimpleName(); + return "unknown:" + this.delegate.getClass().getSimpleName(); } } @@ -54,11 +55,11 @@ public class MinestomCommandSender extends AbstractCommandSender<CommandSender> @Override public void sendMessage(Component message) { - delegate.sendMessage(message); + this.delegate.sendMessage(message); } @Override public boolean hasPermission(String permission) { - return delegate.hasPermission(permission); + 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 index 64dea89..add258a 100644 --- a/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomPlatformInfo.java +++ b/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomPlatformInfo.java @@ -21,6 +21,7 @@ package me.lucko.spark.minestom; import me.lucko.spark.common.platform.PlatformInfo; + import net.minestom.server.MinecraftServer; public class MinestomPlatformInfo implements PlatformInfo { 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 index 8fb42e0..0b50c0a 100644 --- a/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomPlayerPingProvider.java +++ b/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomPlayerPingProvider.java @@ -21,7 +21,9 @@ 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; diff --git a/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomSparkExtension.java b/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomSparkPlugin.java index a99f49c..2b43cae 100644 --- a/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomSparkExtension.java +++ b/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomSparkPlugin.java @@ -22,29 +22,51 @@ 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.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.logging.Level; import java.util.stream.Stream; -public class MinestomSparkExtension extends Extension implements SparkPlugin { +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(); } @@ -60,7 +82,7 @@ public class MinestomSparkExtension extends Extension implements SparkPlugin { } @Override - public Stream<? extends CommandSender> getCommandSenders() { + public Stream<MinestomCommandSender> getCommandSenders() { return Stream.concat( MinecraftServer.getConnectionManager().getOnlinePlayers().stream(), Stream.of(MinecraftServer.getCommandManager().getConsoleSender()) @@ -110,42 +132,52 @@ public class MinestomSparkExtension extends Extension implements SparkPlugin { return new MinestomTickHook(); } - @Override - public void initialize() { - this.platform = new SparkPlatform(this); - this.platform.enable(); - this.command = new MinestomSparkCommand(this); - MinecraftServer.getCommandManager().register(command); - } + private static final class MinestomSparkCommand extends Command implements CommandExecutor, SuggestionCallback { + private final SparkPlatform platform; - @Override - public void terminate() { - this.platform.disable(); - MinecraftServer.getCommandManager().unregister(command); - } + 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<String> 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; + } - 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<String> 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); + 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 index e5a1895..44c1c2d 100644 --- a/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomTickHook.java +++ b/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomTickHook.java @@ -21,6 +21,7 @@ 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; @@ -30,7 +31,7 @@ public class MinestomTickHook extends AbstractTickHook { @Override public void start() { - task = MinecraftServer.getSchedulerManager() + this.task = MinecraftServer.getSchedulerManager() .buildTask(this::onTick) .delay(TaskSchedule.tick(1)) .repeat(TaskSchedule.tick(1)) @@ -39,8 +40,8 @@ public class MinestomTickHook extends AbstractTickHook { @Override public void close() { - if (task != null) { - task.cancel(); + 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 index dbb09ea..ae25f92 100644 --- a/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomTickReporter.java +++ b/spark-minestom/src/main/java/me/lucko/spark/minestom/MinestomTickReporter.java @@ -21,6 +21,7 @@ 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; @@ -32,16 +33,16 @@ public class MinestomTickReporter extends AbstractTickReporter { private final EventNode<Event> node = EventNode.all("sparkTickReporter-" + UUID.randomUUID()); public MinestomTickReporter() { - node.addListener(ServerTickMonitorEvent.class, event -> onTick(event.getTickMonitor().getTickTime())); + this.node.addListener(ServerTickMonitorEvent.class, event -> onTick(event.getTickMonitor().getTickTime())); } @Override public void start() { - MinecraftServer.getGlobalEventHandler().addChild(node); + MinecraftServer.getGlobalEventHandler().addChild(this.node); } @Override public void close() { - MinecraftServer.getGlobalEventHandler().removeChild(node); + MinecraftServer.getGlobalEventHandler().removeChild(this.node); } } diff --git a/spark-minestom/src/main/resources/extension.json b/spark-minestom/src/main/resources/extension.json index de58a69..bea56bb 100644 --- a/spark-minestom/src/main/resources/extension.json +++ b/spark-minestom/src/main/resources/extension.json @@ -1,5 +1,5 @@ { - "entrypoint": "me.lucko.spark.minestom.MinestomSparkExtension", + "entrypoint": "me.lucko.spark.minestom.MinestomSparkPlugin", "name": "spark", "version": "${pluginVersion}" }
\ No newline at end of file |