Class AudienceResolver
java.lang.Object
dev.ua.theroer.magicutils.platform.AudienceResolver
Normalizes "any sender-like object" into an
Audience.
Plugins receive different sender types from different code paths
(Bukkit Player, Velocity CommandSource, raw
CommandSender, an existing Audience, or null).
This utility unifies that decoding so callers can write
Messages.send(player, key) without re-implementing the type
branching dance every time.
Resolution order:
null→null.Audienceinstance → returned as is.- Each registered factory is tried in registration order; the first non-null result wins.
- Reflective fallback: if the object exposes a
getUniqueId()returningUUID, a syntheticAudiencecarrying just that id is returned.
Platform bootstraps (Bukkit/Velocity/Bungee/Fabric/NeoForge)
register a factory at start-up that knows how to wrap their native
types into proper Audience implementations. Callers should
never need to know which platform they are on.
-
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable UUIDextractUuid(@Nullable Object who) static voidregisterFactory(Function<Object, Audience> factory) Registers a factory that wraps platform-specific objects (e.g.static @Nullable AudienceResolves any object into anAudience.static voidunregisterFactory(Function<Object, Audience> factory) Removes a previously registered factory.
-
Method Details
-
registerFactory
Registers a factory that wraps platform-specific objects (e.g. BukkitPlayer, VelocityCommandSource) into anAudience.Factories receive the raw object and may return
nullwhen they cannot handle it. Resolution stops at the first non-null result.- Parameters:
factory- non-null factory
-
unregisterFactory
-
resolve
-
extractUuid
-