diff --git a/platform-bukkit/src/main/java/net/kyori/adventure/platform/bukkit/BukkitAudiencesImpl.java b/platform-bukkit/src/main/java/net/kyori/adventure/platform/bukkit/BukkitAudiencesImpl.java index 2e628660..5cf4593a 100644 --- a/platform-bukkit/src/main/java/net/kyori/adventure/platform/bukkit/BukkitAudiencesImpl.java +++ b/platform-bukkit/src/main/java/net/kyori/adventure/platform/bukkit/BukkitAudiencesImpl.java @@ -94,7 +94,6 @@ static BukkitAudiences instanceFor(final @NotNull Plugin plugin) { BukkitAudiencesImpl(final @NotNull Plugin plugin, final @NotNull ComponentRenderer componentRenderer) { super(componentRenderer); this.plugin = requireNonNull(plugin, "plugin"); - this.softDepend("ViaVersion"); final CommandSender console = this.plugin.getServer().getConsoleSender(); this.addViewer(console); @@ -171,44 +170,47 @@ static final class Builder implements BukkitAudiences.Builder { @Override public @NotNull BukkitAudiences build() { - return INSTANCES.computeIfAbsent(this.plugin.getName(), name -> new BukkitAudiencesImpl(this.plugin, this.componentRenderer)); + return INSTANCES.computeIfAbsent(this.plugin.getName(), name -> { + this.softDepend("ViaVersion"); + return new BukkitAudiencesImpl(this.plugin, this.componentRenderer); + }); } - } - /** - * Add the provided plugin as a soft-depend of ourselves. - * - *

This removes the PluginClassLoader warning added by Spigot without - * requiring every user to add ViaVersion to their own plugin.yml.

- * - *

We do assume here that each copy of Adventure belongs to a JavaPlugin. - * If that is not true, we will silently fail to inject.

- * - * @param pluginName a plugin name - */ - @SuppressWarnings("unchecked") - private void softDepend(final @NotNull String pluginName) { - final PluginDescriptionFile file = this.plugin.getDescription(); - if (file.getName().equals(pluginName)) return; + /** + * Add the provided plugin as a soft-depend of ourselves. + * + *

This removes the PluginClassLoader warning added by Spigot without + * requiring every user to add ViaVersion to their own plugin.yml.

+ * + *

We do assume here that each copy of Adventure belongs to a JavaPlugin. + * If that is not true, we will silently fail to inject.

+ * + * @param pluginName a plugin name + */ + @SuppressWarnings("unchecked") + private void softDepend(final @NotNull String pluginName) { + final PluginDescriptionFile file = this.plugin.getDescription(); + if (file.getName().equals(pluginName)) return; - try { - final Field softDepend = needField(file.getClass(), "softDepend"); - final List dependencies = (List) softDepend.get(file); - if (!dependencies.contains(pluginName)) { - final List newList = ImmutableList.builder().addAll(dependencies).add(pluginName).build(); - softDepend.set(file, newList); + try { + final Field softDepend = needField(file.getClass(), "softDepend"); + final List dependencies = (List) softDepend.get(file); + if (!dependencies.contains(pluginName)) { + final List newList = ImmutableList.builder().addAll(dependencies).add(pluginName).build(); + softDepend.set(file, newList); + } + } catch (final Throwable error) { + logError(error, "Failed to inject softDepend in plugin.yml: %s %s", this.plugin, pluginName); } - } catch (final Throwable error) { - logError(error, "Failed to inject softDepend in plugin.yml: %s %s", this.plugin, pluginName); - } - try { - final PluginManager manager = this.plugin.getServer().getPluginManager(); - final Field dependencyGraphField = needField(manager.getClass(), "dependencyGraph"); - final MutableGraph graph = (MutableGraph) dependencyGraphField.get(manager); - graph.putEdge(file.getName(), pluginName); - } catch (final Throwable error) { - // Fail silently, dependency graphs were added in 1.15, but the previous method still works + try { + final PluginManager manager = this.plugin.getServer().getPluginManager(); + final Field dependencyGraphField = needField(manager.getClass(), "dependencyGraph"); + final MutableGraph graph = (MutableGraph) dependencyGraphField.get(manager); + graph.putEdge(file.getName(), pluginName); + } catch (final Throwable error) { + // Fail silently, dependency graphs were added in 1.15, but the previous method still works + } } } diff --git a/platform-facet/src/main/java/net/kyori/adventure/platform/facet/FacetAudienceProvider.java b/platform-facet/src/main/java/net/kyori/adventure/platform/facet/FacetAudienceProvider.java index 3e0c5d9d..7fd3f34c 100644 --- a/platform-facet/src/main/java/net/kyori/adventure/platform/facet/FacetAudienceProvider.java +++ b/platform-facet/src/main/java/net/kyori/adventure/platform/facet/FacetAudienceProvider.java @@ -72,7 +72,7 @@ public abstract class FacetAudienceProvider> protected final Map viewers; private final Map players; private final Set consoles; - private final A empty; + private A empty; private volatile boolean closed; protected FacetAudienceProvider(final @NotNull ComponentRenderer componentRenderer) { @@ -96,7 +96,6 @@ protected FacetAudienceProvider(final @NotNull ComponentRenderer comp } }; this.player = Audience.audience(this.players.values()); - this.empty = this.createAudience(Collections.emptyList()); this.closed = false; } @@ -184,7 +183,14 @@ public void refreshViewer(final @NotNull V viewer) { @Override public @NotNull Audience player(final @NotNull UUID playerId) { - return this.players.getOrDefault(playerId, this.empty); + return this.players.getOrDefault(playerId, this.empty()); + } + + private @NotNull A empty() { + if (this.empty == null) { + this.empty = this.createAudience(Collections.emptyList()); + } + return this.empty; } /**