Class CompatUtils
java.lang.Object
com.github.relativobr.supreme.util.CompatUtils
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 Summary
Modifier and TypeMethodDescriptionstatic voidapplyEnchantment(io.github.thebusybiscuit.slimefun5.api.items.SlimefunItemStack item, String name, int level) Applies an enchantment resolved by name (seeresolveEnchantment(String)).static booleanstatic org.bukkit.entity.Entitystatic intgetItemDamage(org.bukkit.inventory.ItemStack item) Reads an item's damage across versions (paired withsetItemDamage(org.bukkit.inventory.meta.ItemMeta, org.bukkit.inventory.ItemStack, int)).static Collection<org.bukkit.entity.Entity> getNearbyEntities(org.bukkit.World world, org.bukkit.Location loc, double x, double y, double z, Predicate<org.bukkit.entity.Entity> filter) static booleanisAir(org.bukkit.Material material) static booleanisEntityType(org.bukkit.entity.Entity entity, String typeName) Version-safe replacement for a rawentity.getType() == EntityType.Xcomparison (and forentity instanceof Bee-style subtype checks): compares the entity's ownEnum.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.static booleanisLightable(org.bukkit.block.Block block) Whether a block can carry a lit visual (paired withsetLit(org.bukkit.block.Block, boolean)).static booleanisUnbreakable(org.bukkit.inventory.meta.ItemMeta meta) static booleanWorld#spawnParticle+org.bukkit.Particleare 1.9+.static voidPlays a sound resolved by name through XSeriesXSound, which maps the name to whatever the running server actually supports (or no-ops if absent).static org.bukkit.potion.PotionEffectpotionEffect(String typeName, int duration, int amplifier, boolean ambient, boolean particles, boolean icon) Builds aPotionEffectacross versions, resolving the type by name.static org.bukkit.enchantments.EnchantmentresolveEnchantment(String name) static voidsendActionBar(org.bukkit.entity.Player player, net.md_5.bungee.api.chat.BaseComponent[] components) static voidsetItemDamage(org.bukkit.inventory.meta.ItemMeta meta, org.bukkit.inventory.ItemStack item, int damage) static voidsetLit(org.bukkit.block.Block block, boolean lit) static voidsetUnbreakable(org.bukkit.inventory.meta.ItemMeta meta, boolean value) Sets an item's unbreakable flag across versions (paired withisUnbreakable(org.bukkit.inventory.meta.ItemMeta)).static voidspawnParticle(org.bukkit.Location location, String name, int count)
-
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 (seeresolveEnchantment(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 aNoSuchFieldErroron the rawEnchantment.MENDINGconstant.nameis 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 XSeriesXSound, which maps the name to whatever the running server actually supports (or no-ops if absent). Avoids referencing a rawSound.Xconstant: the wholeorg.bukkit.Soundenum was renamed in 1.9, so every modernBLOCK_*/ENTITY_*name is aNoSuchFieldErroron 1.8.8. -
isEntityType
public static boolean isEntityType(@Nonnull org.bukkit.entity.Entity entity, @Nonnull String typeName) Version-safe replacement for a rawentity.getType() == EntityType.Xcomparison (and forentity instanceof Bee-style subtype checks): compares the entity's ownEnum.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, ororg.bukkit.entity.Bee). Simply returnsfalsefor a name the running server doesn't know. -
getItemDamage
public static int getItemDamage(@Nonnull org.bukkit.inventory.ItemStack item) Reads an item's damage across versions (paired withsetItemDamage(org.bukkit.inventory.meta.ItemMeta, org.bukkit.inventory.ItemStack, int)).- Implementation Note:
- Before 1.13 an item's damage lived on
ItemStack#getDurability()directly;Damageable#getDamage()onItemMetais the 1.13+ replacement. Reflection avoids referencing theDamageableinterface (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 withisUnbreakable(org.bukkit.inventory.meta.ItemMeta)).- Implementation Note:
ItemMeta#setUnbreakable(boolean)is 1.11+; before that the same method lived onItemMeta.spigot(). Reflection avoids a direct 1.11 method reference (NoSuchMethodErroron 1.8.8), and theMethodis resolved off the PUBLIC interface (ItemMeta/ItemMeta.Spigot), never off the concrete non-publicCraftMetaItem, soinvoke()can't hit anIllegalAccessException.
-
isUnbreakable
public static boolean isUnbreakable(@Nonnull org.bukkit.inventory.meta.ItemMeta meta) -
getEntity
-
potionEffect
@Nullable public static org.bukkit.potion.PotionEffect potionEffect(@Nonnull String typeName, int duration, int amplifier, boolean ambient, boolean particles, boolean icon) Builds aPotionEffectacross versions, resolving the type by name.- Implementation Note:
- The 6-arg
(type,dur,amp,ambient,particles,icon)constructor is 1.13+ (theiconboolean). The type is resolved by name viaXPotionso 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 thenet.md_5.bungee.api.ChatMessageTypeclass, which does NOT exist on 1.8.8. It is resolved entirely by reflection (Class.forName) so this class never referencesChatMessageTypedirectly, falling back to a plain spigot chat message where the action-bar overload is unavailable.
-
particlesSupported
public static boolean particlesSupported()World#spawnParticle+org.bukkit.Particleare 1.9+. -
spawnParticle
public static void spawnParticle(@Nonnull org.bukkit.Location location, @Nonnull String name, int count) - Implementation Note:
- The actual
org.bukkit.Particlereference lives inParticleCompat, loaded ONLY whenparticlesSupported()passes. Naming a post-1.8 Bukkit type anywhere in THIS class (even a guarded private method) would force its resolution whenCompatUtilsloads, 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 withsetLit(org.bukkit.block.Block, boolean)).- Implementation Note:
org.bukkit.block.data.BlockData/Lightableare 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) andsetLit(org.bukkit.block.Block, boolean)is a silent no-op. TheBlockData/Lightablereferences live inModernBlockCompat, loaded ONLY behindblockDataSupported().
-
setLit
public static void setLit(@Nonnull org.bukkit.block.Block block, boolean lit)
-