API Methods¶
This page documents the NickedAPI interface and the NickedAPIProvider accessor class.
All methods are thread-safe for reading (isNicked, getNickInfo, getDisplayName, getRealName). Methods that mutate state (nickPlayer, unnickPlayer) must be called from the main server thread, as they fire Bukkit events and modify player state.
NickedAPI¶
Package: com.nicked.api
Type: Interface
Obtain an instance via NickedAPIProvider.getAPI().
getDisplayName¶
Returns the display name for the given player UUID.
- If the player is currently nicked, returns their nick name.
- If the player is not nicked, returns their real name.
- Fires
NickResolveEventbefore returning, allowing other plugins to override the resolved value.
Parameters
| Name | Type | Description |
|---|---|---|
uuid |
UUID |
The player's UUID. May belong to an offline player. |
Returns: String — the resolved display name, never null.
Example
isNicked¶
Returns true if the player is currently nicked.
Note
This returns true as soon as nickPlayer is called, even before the asynchronous skin fetch completes. The NickInfo snapshot obtained via getNickInfo may have a null nickedSkin field during this window.
Parameters
| Name | Type | Description |
|---|---|---|
uuid |
UUID |
The player's UUID. |
Returns: boolean
Example
getNickInfo¶
Returns an immutable snapshot of the player's current nick state, or an empty Optional if the player is not nicked.
The returned NickInfo captures the state at the moment of the call. It will not update if the player's nick changes afterwards — call getNickInfo again to get a fresh snapshot.
Parameters
| Name | Type | Description |
|---|---|---|
uuid |
UUID |
The player's UUID. |
Returns: Optional<NickInfo> — present if the player is nicked, empty otherwise.
Example
nicked.getNickInfo(player.getUniqueId()).ifPresent(info -> {
getLogger().info(
info.realName() + " is nicked as " + info.nickedName()
+ " (cause: " + info.cause() + ")"
);
});
nickPlayer¶
Applies a nick to the specified player.
Behaviour:
- Validates that the player is online. If not, logs a warning and returns immediately without storing any data.
- Fires
NickChangeEventsynchronously. If the event is cancelled, the call is a no-op. - Stores a
NickDataentry immediately, soisNicked(uuid)returnstrueright away. - Sets the Bukkit display name and tab-list name.
- Fetches the Mojang skin for
newNameasynchronously. - Once the skin fetch completes (or fails):
- Updates the nick entry with the skin.
- Saves to
nicks.ymlif persistence is enabled. - Applies the server-side
GameProfilemodification ifinternal_name_changeis enabled. - Sends
PLAYER_INFO_UPDATEpackets to all viewers. - Sends a
RESPAWNpacket to the nicked player (ifskin_change_for_selfis enabled). - Fires
NickApplyEventon the main thread.
If the Mojang API request fails, the nick remains active without a skin change, and the player receives the skin_fetch_failed message.
Parameters
| Name | Type | Description |
|---|---|---|
uuid |
UUID |
The UUID of the player to nick. The player must be online. |
newName |
String |
The nick name to apply. |
cause |
NickCause |
The reason for the nick change. Use NickCause.PLUGIN for API-driven changes. |
Returns: void
Main thread only
This method fires Bukkit events and modifies player state. Call it from the main server thread. If you need to call it from an async context, use Bukkit.getScheduler().runTask(plugin, () -> nicked.nickPlayer(...)).
Example
import com.nicked.nick.NickCause;
// Nick the player as "Notch" via your plugin
nicked.nickPlayer(player.getUniqueId(), "Notch", NickCause.PLUGIN);
unnickPlayer¶
Removes the active nick from the specified player.
Behaviour:
- Does nothing if the player is not currently nicked.
- Fires
NickRemoveEventsynchronously. If the event is cancelled, the nick is left in place. - Removes the nick from the in-memory store.
- Removes the entry from
nicks.ymlif persistence is enabled. - Restores the Bukkit display name to the real name.
- Restores the server-side
GameProfileifinternal_name_changewas active. - Refreshes packets for all viewers (restoring the original skin).
Parameters
| Name | Type | Description |
|---|---|---|
uuid |
UUID |
The UUID of the player to unnick. |
cause |
NickCause |
The reason for the removal. Use NickCause.PLUGIN for API-driven removals. |
Returns: void
Main thread only
Same threading constraint as nickPlayer.
Example
getRealName¶
Returns the real username for the given UUID, regardless of nick state.
- For online players, returns
Player#getName(). - For offline players, resolves from persistent storage, falling back to a UUID-derived string if the player is completely unknown.
Parameters
| Name | Type | Description |
|---|---|---|
uuid |
UUID |
The player's UUID. |
Returns: String — the real name, never null.
Example
String real = nicked.getRealName(player.getUniqueId());
// Even if the player is nicked as "Dream", this returns "Steve"
NickedAPIProvider¶
Package: com.nicked.api
Type: Class (static utility)
getAPI¶
Returns the active NickedAPI instance.
Returns: NickedAPI
Throws: IllegalStateException if called before the Nicked plugin has finished enabling.
getAPIOrNull¶
Returns the active NickedAPI instance, or null if the Nicked plugin is not enabled.
Returns: NickedAPI or null
setInstance (internal)¶
Registers or clears the API singleton. Called exclusively by the Nicked plugin internals during onEnable() and onDisable(). Do not call this from external plugins.