Class CompatUtils

java.lang.Object
com.github.relativobr.supreme.util.CompatUtils

public final class CompatUtils extends Object
Version-safety helpers so Supreme loads + enables on legacy servers (1.8–1.13) without a NoSuchMethodError/NoSuchFieldError from post-1.13 (or otherwise newer-than-the- compileOnly-baseline) API.

Enchantment.getByKey(NamespacedKey.minecraft(name)) is 1.13+ only (legacy Bukkit only had Enchantment.getByName(String)); resolving by name through the fork's relocated XSeries XEnchantment wrapper works on every version and simply yields nothing for a name absent on the running server, instead of referencing methods that don't exist there.

  • Method Details

    • resolveEnchantment

      @Nullable public static org.bukkit.enchantments.Enchantment resolveEnchantment(@Nonnull String name)
    • applyEnchantment

      public static void applyEnchantment(@Nonnull io.github.thebusybiscuit.slimefun5.api.items.SlimefunItemStack item, @Nonnull String name, int level)
      Applies an enchantment resolved by name (see resolveEnchantment(String)). A no-op when the enchantment doesn't exist on the running server, so e.g. MENDING (1.9+) simply isn't added on 1.8.8 instead of triggering a NoSuchFieldError on the raw Enchantment.MENDING constant. name is the Bukkit enchantment field name.
    • playSound

      public static void playSound(@Nullable org.bukkit.Location location, @Nonnull String name, float volume, float pitch)
      Plays a sound resolved by name through XSeries XSound, which maps the name to whatever the running server actually supports (or no-ops if absent). Avoids referencing a raw Sound.X constant: the whole org.bukkit.Sound enum was renamed in 1.9, so every modern BLOCK_*/ENTITY_* name is a NoSuchFieldError on 1.8.8.
    • isEntityType

      public static boolean isEntityType(@Nonnull org.bukkit.entity.Entity entity, @Nonnull String typeName)
      Version-safe replacement for a raw entity.getType() == EntityType.X comparison (and for entity instanceof Bee-style subtype checks): compares the entity's own Enum.name() against the wanted name instead of referencing the enum constant or subtype class, so the class file never resolves a type/field absent on the running server (e.g. EntityType.BEE/GLOW_SQUID/WITHER_SKELETON, or org.bukkit.entity.Bee). Simply returns false for a name the running server doesn't know.
    • getItemDamage

      public static int getItemDamage(@Nonnull org.bukkit.inventory.ItemStack item)
      Implementation Note:
      Before 1.13 an item's damage lived on ItemStack#getDurability() directly; Damageable#getDamage() on ItemMeta is the 1.13+ replacement. Reflection avoids referencing the Damageable interface (and hence resolving it) on servers without it.
    • setItemDamage

      public static void setItemDamage(@Nonnull org.bukkit.inventory.meta.ItemMeta meta, @Nonnull org.bukkit.inventory.ItemStack item, int damage)
    • setUnbreakable

      public static void setUnbreakable(@Nonnull org.bukkit.inventory.meta.ItemMeta meta, boolean value)
      Sets an item's unbreakable flag across versions (paired with isUnbreakable(org.bukkit.inventory.meta.ItemMeta)).
      Implementation Note:
      ItemMeta#setUnbreakable(boolean) is 1.11+; before that the same method lived on ItemMeta.spigot(). Reflection avoids a direct 1.11 method reference (NoSuchMethodError on 1.8.8), and the Method is resolved off the PUBLIC interface (ItemMeta/ItemMeta.Spigot), never off the concrete non-public CraftMetaItem, so invoke() can't hit an IllegalAccessException.
    • isUnbreakable

      public static boolean isUnbreakable(@Nonnull org.bukkit.inventory.meta.ItemMeta meta)
    • getEntity

      @Nullable public static org.bukkit.entity.Entity getEntity(@Nonnull UUID uuid)
    • potionEffect

      @Nullable public static org.bukkit.potion.PotionEffect potionEffect(@Nonnull String typeName, int duration, int amplifier, boolean ambient, boolean particles, boolean icon)
      Builds a PotionEffect across versions, resolving the type by name.
      Implementation Note:
      The 6-arg (type,dur,amp,ambient,particles,icon) constructor is 1.13+ (the icon boolean). The type is resolved by name via XPotion so a modern-only effect name no-ops instead of NPEing, then built reflectively, falling back 6-arg → 5-arg → 4-arg.
    • isAir

      public static boolean isAir(@Nullable org.bukkit.Material material)
    • getNearbyEntities

      @Nonnull public static Collection<org.bukkit.entity.Entity> getNearbyEntities(@Nonnull org.bukkit.World world, @Nonnull org.bukkit.Location loc, double x, double y, double z, @Nullable Predicate<org.bukkit.entity.Entity> filter)
      Implementation Note:
      World#getNearbyEntities(Location, x, y, z, Predicate) is post-1.8; the 4-arg (no-predicate) overload exists on 1.8.8, so it is called here and the predicate applied in Java.
    • sendActionBar

      public static void sendActionBar(@Nonnull org.bukkit.entity.Player player, @Nonnull net.md_5.bungee.api.chat.BaseComponent[] components)
      Implementation Note:
      Player.Spigot#sendMessage(ChatMessageType, BaseComponent[]) needs the net.md_5.bungee.api.ChatMessageType class, which does NOT exist on 1.8.8. It is resolved entirely by reflection (Class.forName) so this class never references ChatMessageType directly, falling back to a plain spigot chat message where the action-bar overload is unavailable.
    • particlesSupported

      public static boolean particlesSupported()
      World#spawnParticle + org.bukkit.Particle are 1.9+.
    • spawnParticle

      public static void spawnParticle(@Nonnull org.bukkit.Location location, @Nonnull String name, int count)
      Implementation Note:
      The actual org.bukkit.Particle reference lives in ParticleCompat, loaded ONLY when particlesSupported() passes. Naming a post-1.8 Bukkit type anywhere in THIS class (even a guarded private method) would force its resolution when CompatUtils loads, so it must stay out entirely.
    • blockDataSupported

      public static boolean blockDataSupported()
    • isLightable

      public static boolean isLightable(@Nonnull org.bukkit.block.Block block)
      Whether a block can carry a lit visual (paired with setLit(org.bukkit.block.Block, boolean)).
      Implementation Note:
      org.bukkit.block.data.BlockData/Lightable are 1.13+, and a block's lit visual has no pre-1.13 equivalent API at all, so on legacy servers this assumes the block is valid (rather than failing the caller's validity check) and setLit(org.bukkit.block.Block, boolean) is a silent no-op. The BlockData/Lightable references live in ModernBlockCompat, loaded ONLY behind blockDataSupported().
    • setLit

      public static void setLit(@Nonnull org.bukkit.block.Block block, boolean lit)