aboutsummaryrefslogtreecommitdiff
path: root/spark-sponge/src/main
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2020-11-07 17:41:39 +0000
committerLuck <git@lucko.me>2020-11-07 17:41:39 +0000
commit8cc92ff83634dffacfe1f25a135bc9ac665ff68b (patch)
tree35efc9d9131c7ceb1db3822fbb6a0707535f7c18 /spark-sponge/src/main
parent70a468e114316a98f6d7f7e91afa8d50639762c9 (diff)
downloadspark-8cc92ff83634dffacfe1f25a135bc9ac665ff68b.tar.gz
spark-8cc92ff83634dffacfe1f25a135bc9ac665ff68b.tar.bz2
spark-8cc92ff83634dffacfe1f25a135bc9ac665ff68b.zip
Update from text to adventure
Diffstat (limited to 'spark-sponge/src/main')
-rw-r--r--spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeCommandSender.java12
-rw-r--r--spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeSparkPlugin.java14
2 files changed, 18 insertions, 8 deletions
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
index ba0e5df..03766d2 100644
--- a/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeCommandSender.java
+++ b/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeCommandSender.java
@@ -21,16 +21,20 @@
package me.lucko.spark.sponge;
import me.lucko.spark.common.command.sender.AbstractCommandSender;
-import net.kyori.text.Component;
-import net.kyori.text.adapter.spongeapi.TextAdapter;
+import net.kyori.adventure.audience.Audience;
+import net.kyori.adventure.platform.spongeapi.SpongeAudiences;
+import net.kyori.adventure.text.Component;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.entity.living.player.Player;
import java.util.UUID;
public class SpongeCommandSender extends AbstractCommandSender<CommandSource> {
- public SpongeCommandSender(CommandSource source) {
+ private final Audience audience;
+
+ public SpongeCommandSender(CommandSource source, SpongeAudiences audienceFactory) {
super(source);
+ this.audience = audienceFactory.receiver(source);
}
@Override
@@ -48,7 +52,7 @@ public class SpongeCommandSender extends AbstractCommandSender<CommandSource> {
@Override
public void sendMessage(Component message) {
- TextAdapter.sendMessage(super.delegate, message);
+ this.audience.sendMessage(message);
}
@Override
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
index d2c842a..5f9a3ef 100644
--- a/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeSparkPlugin.java
+++ b/spark-sponge/src/main/java/me/lucko/spark/sponge/SpongeSparkPlugin.java
@@ -26,6 +26,7 @@ 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.sampler.tick.TickHook;
+import net.kyori.adventure.platform.spongeapi.SpongeAudiences;
import org.spongepowered.api.Game;
import org.spongepowered.api.command.CommandCallable;
import org.spongepowered.api.command.CommandResult;
@@ -36,6 +37,7 @@ 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;
@@ -62,14 +64,17 @@ import javax.annotation.Nullable;
)
public class SpongeSparkPlugin implements SparkPlugin {
+ private final PluginContainer pluginContainer;
private final Game game;
private final Path configDirectory;
private final SpongeExecutorService asyncExecutor;
+ private SpongeAudiences audienceFactory;
private SparkPlatform platform;
@Inject
- public SpongeSparkPlugin(Game game, @ConfigDir(sharedRoot = false) Path configDirectory, @AsynchronousExecutor SpongeExecutorService asyncExecutor) {
+ public SpongeSparkPlugin(PluginContainer pluginContainer, Game game, @ConfigDir(sharedRoot = false) Path configDirectory, @AsynchronousExecutor SpongeExecutorService asyncExecutor) {
+ this.pluginContainer = pluginContainer;
this.game = game;
this.configDirectory = configDirectory;
this.asyncExecutor = asyncExecutor;
@@ -77,6 +82,7 @@ public class SpongeSparkPlugin implements SparkPlugin {
@Listener
public void onEnable(GameStartedServerEvent event) {
+ this.audienceFactory = SpongeAudiences.create(this.pluginContainer, this.game);
this.platform = new SparkPlatform(this);
this.platform.enable();
this.game.getCommandManager().register(this, new SparkCommand(this), "spark");
@@ -107,7 +113,7 @@ public class SpongeSparkPlugin implements SparkPlugin {
return Stream.concat(
this.game.getServer().getOnlinePlayers().stream().filter(player -> player.hasPermission(permission)),
Stream.of(this.game.getServer().getConsole())
- ).map(SpongeCommandSender::new);
+ ).map((CommandSource source) -> new SpongeCommandSender(source, this.audienceFactory));
}
@Override
@@ -139,13 +145,13 @@ public class SpongeSparkPlugin implements SparkPlugin {
@Override
public CommandResult process(CommandSource source, String arguments) {
- this.plugin.platform.executeCommand(new SpongeCommandSender(source), arguments.split(" "));
+ this.plugin.platform.executeCommand(new SpongeCommandSender(source, this.plugin.audienceFactory), arguments.split(" "));
return CommandResult.empty();
}
@Override
public List<String> getSuggestions(CommandSource source, String arguments, @Nullable Location<World> targetPosition) {
- return this.plugin.platform.tabCompleteCommand(new SpongeCommandSender(source), arguments.split(" "));
+ return this.plugin.platform.tabCompleteCommand(new SpongeCommandSender(source, this.plugin.audienceFactory), arguments.split(" "));
}
@Override