Class Attributes

java.lang.Object
valorless.rarespawns.utils.Attributes

public class Attributes extends Object
Utility class for handling Bukkit Attributes with version compatibility.

This class provides a method to retrieve Bukkit Attributes by name, accommodating differences in how attributes are referenced across different Minecraft server versions.

  • Constructor Details

    • Attributes

      public Attributes()
  • Method Details

    • getAttributeByName

      public static org.bukkit.attribute.Attribute getAttributeByName(String name)
      Retrieves a Bukkit Attribute by its name, handling version differences.

      For versions 1.21.3 and earlier, it attempts to find the attribute directly by name, falling back to "GENERIC_" prefix if not found. For versions 1.21.4 and later, it uses NamespacedKey to look up the attribute, converting underscores to dots for names that contain them.

      Parameters:
      name - The name of the attribute (e.g., "GENERIC_MAX_HEALTH" or "generic.max_health").
      Returns:
      The corresponding Attribute, or null if not found or if the server version is unrecognized.
      Throws:
      IllegalStateException - If the server version is unrecognized.