aboutsummaryrefslogtreecommitdiff
path: root/spark-sponge8/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'spark-sponge8/src/main/java')
-rw-r--r--spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8CommandSender.java40
-rw-r--r--spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8SparkPlugin.java20
-rw-r--r--spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8TickHook.java4
3 files changed, 38 insertions, 26 deletions
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 cc0778c..60a4b8f 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
@@ -22,43 +22,61 @@ package me.lucko.spark.sponge;
import me.lucko.spark.common.command.sender.AbstractCommandSender;
import net.kyori.adventure.audience.Audience;
+import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component;
-import org.spongepowered.api.service.permission.Subject;
+import org.spongepowered.api.command.CommandCause;
+import org.spongepowered.api.service.permission.Subject;
+import org.spongepowered.api.util.Identifiable;
import java.util.UUID;
import static java.nio.charset.StandardCharsets.UTF_8;
-public class Sponge8CommandSender extends AbstractCommandSender<Audience> {
- private final Subject subject;
+public class Sponge8CommandSender extends AbstractCommandSender<Subject> {
+ private final CommandCause cause;
+ private final Audience audience;
+
+ public Sponge8CommandSender(CommandCause cause) {
+ super(cause);
+ this.cause = cause;
+ this.audience = cause.audience();
+ }
- public Sponge8CommandSender(Subject subject, Audience audience) {
- super(audience);
- this.subject = subject;
+ public <T extends Subject & Audience> Sponge8CommandSender(T cause) {
+ super(cause);
+ this.cause = null;
+ this.audience = cause;
}
@Override
public String getName() {
- return subject.friendlyIdentifier().orElse(subject.identifier());
+ return super.delegate.friendlyIdentifier().orElse(super.delegate.identifier());
}
@Override
public UUID getUniqueId() {
+ if (this.cause != null) {
+ Identifiable identifiable = this.cause.first(Identifiable.class).orElse(null);
+ if (identifiable != null) {
+ return identifiable.uniqueId();
+ }
+ }
+
try {
- return UUID.fromString(subject.identifier());
+ return UUID.fromString(super.delegate.identifier());
} catch (Exception e) {
- return UUID.nameUUIDFromBytes(subject.identifier().getBytes(UTF_8));
+ return UUID.nameUUIDFromBytes(super.delegate.identifier().getBytes(UTF_8));
}
}
@Override
public void sendMessage(Component message) {
- delegate.sendMessage(message);
+ this.audience.sendMessage(Identity.nil(), message);
}
@Override
public boolean hasPermission(String permission) {
- return subject.hasPermission(permission);
+ return super.delegate.hasPermission(permission);
}
}
diff --git a/spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8SparkPlugin.java b/spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8SparkPlugin.java
index aa05153..ff44c93 100644
--- a/spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8SparkPlugin.java
+++ b/spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8SparkPlugin.java
@@ -30,13 +30,13 @@ import me.lucko.spark.common.sampler.ThreadDumper;
import me.lucko.spark.common.tick.TickHook;
import net.kyori.adventure.text.Component;
+
import org.checkerframework.checker.nullness.qual.NonNull;
import org.spongepowered.api.Game;
import org.spongepowered.api.Server;
import org.spongepowered.api.command.Command;
import org.spongepowered.api.command.CommandCause;
import org.spongepowered.api.command.CommandResult;
-import org.spongepowered.api.command.exception.CommandException;
import org.spongepowered.api.command.parameter.ArgumentReader;
import org.spongepowered.api.command.registrar.tree.CommandTreeNode;
import org.spongepowered.api.config.ConfigDir;
@@ -66,7 +66,6 @@ public class Sponge8SparkPlugin implements SparkPlugin {
@Inject
public Sponge8SparkPlugin(PluginContainer pluginContainer, Game game, @ConfigDir(sharedRoot = false) Path configDirectory) {
-
this.pluginContainer = pluginContainer;
this.game = game;
this.configDirectory = configDirectory;
@@ -76,7 +75,7 @@ public class Sponge8SparkPlugin implements SparkPlugin {
@Listener
public void onRegisterCommands(final RegisterCommandEvent<Command.Raw> event) {
- event.register(this.pluginContainer, new SparkCommand(this), pluginContainer.getMetadata().getId());
+ event.register(this.pluginContainer, new SparkCommand(this), this.pluginContainer.getMetadata().getId());
}
@Listener
@@ -110,7 +109,7 @@ public class Sponge8SparkPlugin implements SparkPlugin {
return Stream.concat(
this.game.server().onlinePlayers().stream(),
Stream.of(this.game.systemSubject())
- ).map(s -> new Sponge8CommandSender(s, s));
+ ).map(Sponge8CommandSender::new);
}
@Override
@@ -134,8 +133,7 @@ public class Sponge8SparkPlugin implements SparkPlugin {
}
private static final class SparkCommand implements Command.Raw {
-
- private Sponge8SparkPlugin plugin;
+ private final Sponge8SparkPlugin plugin;
public SparkCommand(Sponge8SparkPlugin plugin) {
this.plugin = plugin;
@@ -144,22 +142,18 @@ public class Sponge8SparkPlugin implements SparkPlugin {
@Override
public CommandResult process(CommandCause cause, ArgumentReader.Mutable arguments) {
this.plugin.threadDumper.ensureSetup();
- this.plugin.platform.executeCommand(getSenderFromCause(cause), arguments.input().split(" "));
+ this.plugin.platform.executeCommand(new Sponge8CommandSender(cause), arguments.input().split(" "));
return CommandResult.empty();
}
@Override
public List<String> suggestions(CommandCause cause, ArgumentReader.Mutable arguments) {
- return this.plugin.platform.tabCompleteCommand(getSenderFromCause(cause), arguments.input().split(" "));
- }
-
- private static CommandSender getSenderFromCause(CommandCause cause) {
- return new Sponge8CommandSender(cause.subject(), cause.audience());
+ return this.plugin.platform.tabCompleteCommand(new Sponge8CommandSender(cause), arguments.input().split(" "));
}
@Override
public boolean canExecute(CommandCause cause) {
- return this.plugin.platform.hasPermissionForAnyCommand(getSenderFromCause(cause));
+ return this.plugin.platform.hasPermissionForAnyCommand(new Sponge8CommandSender(cause));
}
@Override
diff --git a/spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8TickHook.java b/spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8TickHook.java
index 29698c9..f6918db 100644
--- a/spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8TickHook.java
+++ b/spark-sponge8/src/main/java/me/lucko/spark/sponge/Sponge8TickHook.java
@@ -49,10 +49,10 @@ public class Sponge8TickHook extends AbstractTickHook implements TickHook, Runna
Task task = Task.builder()
.interval(Ticks.of(1))
.name("spark-ticker")
- .plugin(plugin)
+ .plugin(this.plugin)
.execute(this)
.build();
- this.task = game.server().scheduler().submit(task);
+ this.task = this.game.server().scheduler().submit(task);
}
@Override