9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-19 15:09:19 +00:00

Merge pull request #155 from Craftinators/remapped

`HMCCosmeticsAPI` Javadoc Changes
This commit is contained in:
LoJoSho
2025-01-21 23:35:02 -06:00
committed by GitHub

View File

@@ -17,122 +17,152 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
public class HMCCosmeticsAPI { /**
* The main API class for HMCCosmetics. This class provides methods to interact with the plugin.
/** */
* Attempts to get a cosmetic from HMCCosmetics public final class HMCCosmeticsAPI {
* private HMCCosmeticsAPI() {
* @param cosmetic Cosmetic Id throw new UnsupportedOperationException("This class cannot be instantiated.");
* @return A {@link Cosmetic} if exists or null if it does not
*/
@Nullable
public static Cosmetic getCosmetic(@NotNull String cosmetic) {
return Cosmetics.getCosmetic(cosmetic);
} }
/** /**
* Attempts to get the CosmeticUser from an online user. If a player is offline it will return null. * Retrieves a {@link Cosmetic} associated with the specified id.
* A player maybe online but not have a CosmeticUser attached to them, either from delay specified in the config * <p>
* or from a /reload. Always check if it's null! * This method attempts to fetch a {@link Cosmetic} using the given id. If no {@link Cosmetic} exists
* * with the specified id, it will return {@code null}.
* @param uuid Player Unique ID * </p>
* @return A {@link CosmeticUser} if exists or null if it does not * @param id the id of the {@link Cosmetic} to retrieve; must not be {@code null}
* @return the {@link Cosmetic} if it exists, or {@code null} if no cosmetic is associated with the given id
*/ */
@Nullable public static @Nullable Cosmetic getCosmetic(@NotNull String id) {
public static CosmeticUser getUser(@NotNull UUID uuid) { return Cosmetics.getCosmetic(id);
}
/**
* Retrieves the {@link CosmeticUser} associated with the specified player's {@link UUID}.
* <p>
* This method attempts to fetch a {@link CosmeticUser} for an online player. If the player is offline,
* or if no {@link CosmeticUser} is currently associated with them, it will return {@code null}.
* </p>
* Note that a player may be online but not have a {@link CosmeticUser} attached due to:
* <ul>
* <li>A delay specified in the configuration</li>
* <li>A recent server reload (e.g., via the {@code /reload} command)</li>
* </ul>
* Always perform a {@code null} check before using the returned object to ensure safe operation.
*
* @param uuid the {@link UUID} of the player whose {@link CosmeticUser} is being retrieved; must not be {@code null}
* @return the {@link CosmeticUser} if it exists, or {@code null} if the player is offline or unassociated
*/
public static @Nullable CosmeticUser getUser(@NotNull UUID uuid) {
return CosmeticUsers.getUser(uuid); return CosmeticUsers.getUser(uuid);
} }
/** /**
* Attempts to get a HMCCosmetics Menu. Returns null if no menu exists under that id. * Retrieves a {@link Menu} associated with the specified id, or {@code null} if no menu exists with the given id.
* *
* @param id Menu ID * @param id the id of the menu to retrieve; must not be {@code null}
* @return A {@link Menu} if exists or null if it does not * @return the {@link Menu} if it exists, or {@code null} if no menu is associated with the given id
*/ */
@Nullable public static @Nullable Menu getMenu(@NotNull String id) {
public static Menu getMenu(@NotNull String id) {
return Menus.getMenu(id); return Menus.getMenu(id);
} }
/** /**
* Equips a cosmetic to a player. You can use getUser and getCosmetic to get the CosmeticUser and Cosmetic to equip. * Equips a {@link Cosmetic} to a player. To retrieve the necessary {@code CosmeticUser} and {@code Cosmetic}, use the {@link #getUser}
* @param user CosmeticUser to equip cosmetic to * and {@link #getCosmetic} methods respectively.
* @param cosmetic Cosmetic to equip *
* @param user the {@link CosmeticUser} to equip the cosmetic to
* @param cosmetic the {@link Cosmetic} to equip
*/ */
public static void equipCosmetic(@NotNull CosmeticUser user, @NotNull Cosmetic cosmetic) { public static void equipCosmetic(@NotNull CosmeticUser user, @NotNull Cosmetic cosmetic) {
equipCosmetic(user, cosmetic, null); equipCosmetic(user, cosmetic, null);
} }
/** /**
* Equips a cosmetic to a player with a color. You can use getUser and getCosmetic to get the CosmeticUser and Cosmetic to equip. * Equips a {@link Cosmetic} to a player with an optional color customization. To retrieve the necessary
* @param user CosmeticUser to equip cosmetic to * {@code CosmeticUser} and {@code Cosmetic}, use the {@link #getUser} and {@link #getCosmetic} methods
* @param cosmetic Cosmetic to equip * respectively.
* @param color Color to apply to cosmetic *
* @param user the {@link CosmeticUser} to equip the cosmetic to
* @param cosmetic the {@link Cosmetic} to equip
* @param color the color to apply to the cosmetic, or {@code null} if the cosmetic does not support color
* customization
*/ */
public static void equipCosmetic(@NotNull CosmeticUser user, @NotNull Cosmetic cosmetic, @Nullable Color color) { public static void equipCosmetic(@NotNull CosmeticUser user, @NotNull Cosmetic cosmetic, @Nullable Color color) {
user.addPlayerCosmetic(cosmetic, color); user.addPlayerCosmetic(cosmetic, color);
} }
/** /**
* Removes a cosmetic in cosmeticslot. * Removes a cosmetic from a specified slot for the given user.
* @param user The user to remove the cosmetic from *
* @param slot The slot to remove the cosmetic from * @param user the {@link CosmeticUser} from whom the cosmetic will be removed
* @param slot the {@link CosmeticSlot} from which the cosmetic will be removed
*/ */
public static void unequipCosmetic(@NotNull CosmeticUser user, @NotNull CosmeticSlot slot) { public static void unequipCosmetic(@NotNull CosmeticUser user, @NotNull CosmeticSlot slot) {
user.removeCosmeticSlot(slot); user.removeCosmeticSlot(slot);
} }
/** /**
* Gets all Cosmetics that are currently registered with HMCC. This list is immutable! * Retrieves a list of all cosmetics currently registered with HMCC.
* @return A list of all registered cosmetics *
* @return an {@code immutable} list containing all registered {@link Cosmetic} object
*/ */
@NotNull public static @NotNull List<Cosmetic> getAllCosmetics() {
public static List<Cosmetic> getAllCosmetics() {
return List.copyOf(Cosmetics.values()); return List.copyOf(Cosmetics.values());
} }
/** /**
* Gets all CosmeticUsers that are currently registered with HMCC. This list is immutable! * Retrieves a list of all cosmetic users currently registered with HMCC.
* @return A list of all registered CosmeticUsers *
* @return an immutable list containing all registered {@link CosmeticUser} objects
*/ */
@NotNull public static @NotNull List<CosmeticUser> getAllCosmeticUsers() {
public static List<CosmeticUser> getAllCosmeticUsers() {
return List.copyOf(CosmeticUsers.values()); return List.copyOf(CosmeticUsers.values());
} }
/** /**
* Gets all the cosmetic slots that are registered with HMCC. This map is immutable! * Retrieves a map of all cosmetic slots currently registered with HMCC.
* @return A map of all registered cosmetic slots *
* @return an immutable {@link Map} containing all registered cosmetic slots
*/ */
@NotNull public static @NotNull Map<String, CosmeticSlot> getAllCosmeticSlots() {
public static Map<String, CosmeticSlot> getAllCosmeticSlots() {
return Map.copyOf(CosmeticSlot.values()); return Map.copyOf(CosmeticSlot.values());
} }
/** /**
* Registers a new cosmetic slot with the given id. If a slot with the given id already exists, it will be returned. * Registers a new cosmetic slot with the specified id. If a slot with the same id already exists,
* @param id The id of the slot, this will automatically be converted to all UPPERCASE when registering the slot * the existing slot will be returned.
*
* <p>
* The provided id will automatically be converted to uppercase when registering the slot.
* </p>
*
* @param id the id for the cosmetic slot
* @return the {@link CosmeticSlot} associated with the given ID
*/ */
@NotNull public static @NotNull CosmeticSlot registerCosmeticSlot(@NotNull String id) {
public static CosmeticSlot registerCosmeticSlot(@NotNull String id) {
return CosmeticSlot.register(id); return CosmeticSlot.register(id);
} }
/** /**
* This returns the NMS version of the server as recognized by HMCCosmetics. This will be null until HMCC setup has been completed. * Retrieves the NMS version of the server as recognized by HMCCosmetics.
* @return The NMS version of the server in String format *
* <p>This value will be {@code null} until the HMCC setup has been completed. Ensure setup is finished
* before attempting to access this version.</p>
*
* @return the NMS version of the server in string format, or {@code null} if setup is not complete.
*/ */
@Nullable public static @Nullable String getNMSVersion() {
public static String getNMSVersion() {
return NMSHandlers.getVersion(); return NMSHandlers.getVersion();
} }
/** /**
* This returns the HMCCosmetics version. * Retrieves the version of HMCCosmetics currently in use.
* @return The HMCCosmetics version in String format *
* @return the HMCCosmetics version in string format
*/ */
@NotNull public static @NotNull String getHMCCVersion() {
public static String getHMCCVersion() {
return HMCCosmeticsPlugin.getInstance().getDescription().getVersion(); return HMCCosmeticsPlugin.getInstance().getDescription().getVersion();
} }
} }