diff --git a/bukkit/build.gradle b/bukkit/build.gradle index 9bce6045..291dc3f4 100644 --- a/bukkit/build.gradle +++ b/bukkit/build.gradle @@ -36,7 +36,6 @@ shadowJar { relocate 'org.json', 'net.william278.husksync.libraries.json' relocate 'com.fatboyindustrial', 'net.william278.husksync.libraries' relocate 'de.themoep', 'net.william278.husksync.libraries' - relocate 'net.kyori', 'net.william278.husksync.libraries' relocate 'org.jetbrains', 'net.william278.husksync.libraries' relocate 'org.intellij', 'net.william278.husksync.libraries' relocate 'com.zaxxer', 'net.william278.husksync.libraries' diff --git a/bukkit/src/main/java/net/william278/husksync/BukkitHuskSync.java b/bukkit/src/main/java/net/william278/husksync/BukkitHuskSync.java index 37b93097..b50a236f 100644 --- a/bukkit/src/main/java/net/william278/husksync/BukkitHuskSync.java +++ b/bukkit/src/main/java/net/william278/husksync/BukkitHuskSync.java @@ -46,7 +46,6 @@ import net.william278.husksync.migrator.MpdbMigrator; import net.william278.husksync.redis.RedisManager; import net.william278.husksync.sync.DataSyncer; import net.william278.husksync.user.BukkitUser; -import net.william278.husksync.user.ConsoleUser; import net.william278.husksync.user.OnlineUser; import net.william278.husksync.util.BukkitLegacyConverter; import net.william278.husksync.util.BukkitMapPersister; @@ -346,12 +345,6 @@ public class BukkitHuskSync extends JavaPlugin implements HuskSync, BukkitTask.S } } - @NotNull - @Override - public ConsoleUser getConsole() { - return new ConsoleUser(audiences.console()); - } - @NotNull @Override public Version getPluginVersion() { diff --git a/common/build.gradle b/common/build.gradle index 6734ba7b..62facd92 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -6,7 +6,6 @@ dependencies { api 'commons-io:commons-io:2.15.1' api 'org.apache.commons:commons-text:1.11.0' api 'de.themoep:minedown-adventure:1.7.2-SNAPSHOT' - api 'net.kyori:adventure-api:4.14.0' api 'org.json:json:20231013' api 'com.google.code.gson:gson:2.10.1' api 'com.fatboyindustrial.gson-javatime-serialisers:gson-javatime-serialisers:1.1.2' @@ -18,6 +17,8 @@ dependencies { exclude module: 'slf4j-api' } + compileOnly 'net.kyori:adventure-api:4.15.0' + compileOnly 'net.kyori:adventure-platform-api:4.3.1' compileOnly 'org.jetbrains:annotations:24.1.0' compileOnly 'com.github.plan-player-analytics:Plan:5.5.2272' compileOnly "redis.clients:jedis:$jedis_version" diff --git a/common/src/main/java/net/william278/husksync/HuskSync.java b/common/src/main/java/net/william278/husksync/HuskSync.java index fc7b8b10..101cb6a3 100644 --- a/common/src/main/java/net/william278/husksync/HuskSync.java +++ b/common/src/main/java/net/william278/husksync/HuskSync.java @@ -22,6 +22,8 @@ package net.william278.husksync; import com.fatboyindustrial.gsonjavatime.Converters; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.platform.AudienceProvider; import net.william278.annotaml.Annotaml; import net.william278.desertwell.util.ThrowingConsumer; import net.william278.desertwell.util.UpdateChecker; @@ -250,12 +252,35 @@ public interface HuskSync extends Task.Supplier, EventDispatcher { } /** - * Get the console user + * Get the {@link AudienceProvider} instance * - * @return the {@link ConsoleUser} + * @return the {@link AudienceProvider} instance + * @since 1.0 */ @NotNull - ConsoleUser getConsole(); + AudienceProvider getAudiences(); + + /** + * Get the {@link Audience} instance for the given {@link OnlineUser} + * + * @param user the {@link OnlineUser} to get the {@link Audience} for + * @return the {@link Audience} instance + */ + @NotNull + default Audience getAudience(@NotNull UUID user) { + return getAudiences().player(user); + } + + /** + * Get the {@link ConsoleUser} instance + * + * @return the {@link ConsoleUser} instance + * @since 1.0 + */ + @NotNull + default ConsoleUser getConsole() { + return new ConsoleUser(getAudiences()); + } /** * Returns the plugin version diff --git a/common/src/main/java/net/william278/husksync/user/ConsoleUser.java b/common/src/main/java/net/william278/husksync/user/ConsoleUser.java index fe89c93b..306e799c 100644 --- a/common/src/main/java/net/william278/husksync/user/ConsoleUser.java +++ b/common/src/main/java/net/william278/husksync/user/ConsoleUser.java @@ -20,6 +20,7 @@ package net.william278.husksync.user; import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.platform.AudienceProvider; import org.jetbrains.annotations.NotNull; public final class ConsoleUser implements CommandUser { @@ -27,8 +28,8 @@ public final class ConsoleUser implements CommandUser { @NotNull private final Audience audience; - public ConsoleUser(@NotNull Audience console) { - this.audience = console; + public ConsoleUser(@NotNull AudienceProvider audiences) { + this.audience = audiences.console(); } @Override diff --git a/paper/build.gradle b/paper/build.gradle index 829628ce..95ab01d9 100644 --- a/paper/build.gradle +++ b/paper/build.gradle @@ -17,7 +17,6 @@ shadowJar { relocate 'org.json', 'net.william278.husksync.libraries.json' relocate 'com.fatboyindustrial', 'net.william278.husksync.libraries' relocate 'de.themoep', 'net.william278.husksync.libraries' - relocate 'net.kyori', 'net.william278.husksync.libraries' relocate 'org.jetbrains', 'net.william278.husksync.libraries' relocate 'org.intellij', 'net.william278.husksync.libraries' relocate 'com.zaxxer', 'net.william278.husksync.libraries' diff --git a/paper/src/main/java/net/william278/husksync/PaperHuskSync.java b/paper/src/main/java/net/william278/husksync/PaperHuskSync.java index 77ede88a..3024cc0b 100644 --- a/paper/src/main/java/net/william278/husksync/PaperHuskSync.java +++ b/paper/src/main/java/net/william278/husksync/PaperHuskSync.java @@ -19,10 +19,14 @@ package net.william278.husksync; +import net.kyori.adventure.audience.Audience; import net.william278.husksync.listener.BukkitEventListener; import net.william278.husksync.listener.PaperEventListener; +import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +import java.util.UUID; + @SuppressWarnings("unused") public class PaperHuskSync extends BukkitHuskSync { @@ -32,4 +36,11 @@ public class PaperHuskSync extends BukkitHuskSync { return new PaperEventListener(this); } + @NotNull + @Override + public Audience getAudience(@NotNull UUID user) { + final Player player = getServer().getPlayer(user); + return player == null || !player.isOnline() ? Audience.empty() : player; + } + }