diff options
author | Luck <git@lucko.me> | 2021-04-05 10:46:22 +0100 |
---|---|---|
committer | Luck <git@lucko.me> | 2021-04-05 10:46:22 +0100 |
commit | bb981b509d65f80a88d5a0310cabde4041337236 (patch) | |
tree | 8a30bdd6191c5c3a3987d2fb7a04be41347b99a8 /spark-sponge8 | |
parent | 75f1e4d0c20c38e7d65a7c558d96213145b682e6 (diff) | |
download | spark-bb981b509d65f80a88d5a0310cabde4041337236.tar.gz spark-bb981b509d65f80a88d5a0310cabde4041337236.tar.bz2 spark-bb981b509d65f80a88d5a0310cabde4041337236.zip |
Tidy up
Diffstat (limited to 'spark-sponge8')
5 files changed, 61 insertions, 44 deletions
diff --git a/spark-sponge8/build.gradle b/spark-sponge8/build.gradle index e4ee48c..89b2ac3 100644 --- a/spark-sponge8/build.gradle +++ b/spark-sponge8/build.gradle @@ -1,6 +1,5 @@ plugins { - id("java-library") - id('com.github.johnrengelman.shadow') version '4.0.1' + id 'com.github.johnrengelman.shadow' version '4.0.1' } dependencies { @@ -9,29 +8,35 @@ dependencies { } repositories { - maven { - url "https://repo.spongepowered.org/repository/maven-public/" - name "sponge" + maven { 'https://repo.spongepowered.org/repository/maven-public/' } +} + +processResources { + from(sourceSets.main.resources.srcDirs) { + include 'META-INF/plugins.json' + expand ( + version: project.version, + description: project.pluginDescription + ) } } shadowJar { archiveFileName = 'spark-sponge8.jar' + + relocate 'okio', 'me.lucko.spark.lib.okio' + relocate 'okhttp3', 'me.lucko.spark.lib.okhttp3' + 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 } - -processResources { - from(sourceSets.main.resources.srcDirs) { - include 'META-INF/plugins.json' - - expand ( - version: project.version, - description: project.pluginDescription - ) - } -} - 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 diff --git a/spark-sponge8/src/main/resources/META-INF/plugins.json b/spark-sponge8/src/main/resources/META-INF/plugins.json index 1cf2eaa..ac4e3cf 100644 --- a/spark-sponge8/src/main/resources/META-INF/plugins.json +++ b/spark-sponge8/src/main/resources/META-INF/plugins.json @@ -15,7 +15,7 @@ "contributors": [ { "name": "Luck", - "description": "Lead Developer" + "description": "Developer" } ], "dependencies": [ |