diff options
author | Luke <32024335+lukeeey@users.noreply.github.com> | 2021-02-04 18:22:51 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-04 18:22:51 +0000 |
commit | 7802172459179ce56419c6d3d2a9d43571e5c639 (patch) | |
tree | 4ba383b12a476e77c12668e5304172d4069f8578 /spark-nukkit/src/main/java/me/lucko/spark | |
parent | c8f4fe1c2d5832b495d1f815ebc1e60ce9949d8f (diff) | |
download | spark-7802172459179ce56419c6d3d2a9d43571e5c639.tar.gz spark-7802172459179ce56419c6d3d2a9d43571e5c639.tar.bz2 spark-7802172459179ce56419c6d3d2a9d43571e5c639.zip |
Add support for Cloudburst Nukkit (#95)
Diffstat (limited to 'spark-nukkit/src/main/java/me/lucko/spark')
3 files changed, 143 insertions, 0 deletions
diff --git a/spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitCommandSender.java b/spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitCommandSender.java new file mode 100644 index 0000000..5a40e16 --- /dev/null +++ b/spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitCommandSender.java @@ -0,0 +1,39 @@ +package me.lucko.spark.nukkit; + +import cn.nukkit.Player; +import cn.nukkit.command.CommandSender; +import me.lucko.spark.common.command.sender.AbstractCommandSender; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; + +import java.util.UUID; + +public class NukkitCommandSender extends AbstractCommandSender<CommandSender> { + + public NukkitCommandSender(CommandSender delegate) { + super(delegate); + } + + @Override + public String getName() { + return this.delegate.getName(); + } + + @Override + public UUID getUniqueId() { + if (this.delegate instanceof Player) { + return ((Player) this.delegate).getUniqueId(); + } + return null; + } + + @Override + public void sendMessage(Component message) { + this.delegate.sendMessage(LegacyComponentSerializer.legacySection().serialize(message)); + } + + @Override + public boolean hasPermission(String permission) { + return this.delegate.hasPermission(permission); + } +}
\ No newline at end of file diff --git a/spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitPlatformInfo.java b/spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitPlatformInfo.java new file mode 100644 index 0000000..7198719 --- /dev/null +++ b/spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitPlatformInfo.java @@ -0,0 +1,33 @@ +package me.lucko.spark.nukkit; + +import cn.nukkit.Server; +import cn.nukkit.network.protocol.ProtocolInfo; +import me.lucko.spark.common.platform.AbstractPlatformInfo; + +public class NukkitPlatformInfo extends AbstractPlatformInfo { + private final Server server; + + public NukkitPlatformInfo(Server server) { + this.server = server; + } + + @Override + public Type getType() { + return Type.SERVER; + } + + @Override + public String getName() { + return "Nukkit"; + } + + @Override + public String getVersion() { + return this.server.getNukkitVersion(); + } + + @Override + public String getMinecraftVersion() { + return this.server.getVersion(); + } +} diff --git a/spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitSparkPlugin.java b/spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitSparkPlugin.java new file mode 100644 index 0000000..6c16383 --- /dev/null +++ b/spark-nukkit/src/main/java/me/lucko/spark/nukkit/NukkitSparkPlugin.java @@ -0,0 +1,71 @@ +package me.lucko.spark.nukkit; + +import cn.nukkit.command.Command; +import cn.nukkit.command.CommandSender; +import cn.nukkit.plugin.PluginBase; +import cn.nukkit.scheduler.AsyncTask; +import me.lucko.spark.common.SparkPlatform; +import me.lucko.spark.common.SparkPlugin; +import me.lucko.spark.common.platform.PlatformInfo; + +import java.nio.file.Path; +import java.util.stream.Stream; + +public class NukkitSparkPlugin extends PluginBase implements SparkPlugin { + private SparkPlatform platform; + + @Override + public void onEnable() { + this.platform = new SparkPlatform(this); + this.platform.enable(); + } + + @Override + public void onDisable() { + this.platform.disable(); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + this.platform.executeCommand(new NukkitCommandSender(sender), args); + return true; + } + + @Override + public String getVersion() { + return getDescription().getVersion(); + } + + @Override + public Path getPluginDirectory() { + return getDataFolder().toPath(); + } + + @Override + public String getCommandName() { + return "spark"; + } + + @Override + public Stream<NukkitCommandSender> getSendersWithPermission(String permission) { + return Stream.concat( + getServer().getOnlinePlayers().values().stream().filter(player -> player.hasPermission(permission)), + Stream.of(getServer().getConsoleSender()) + ).map(NukkitCommandSender::new); + } + + @Override + public void executeAsync(Runnable task) { + getServer().getScheduler().scheduleAsyncTask(this, new AsyncTask() { + @Override + public void onRun() { + task.run(); + } + }); + } + + @Override + public PlatformInfo getPlatformInfo() { + return new NukkitPlatformInfo(getServer()); + } +} |