Build plugins that work across multiple Minecraft versions using MinecraftVersion and Remain classes
Foundation makes it easy to create plugins that work across multiple Minecraft versions, from 1.8 through the latest releases. This is achieved through the MinecraftVersion and Remain utility classes.
// Get the current version enumMinecraftVersion.V current = MinecraftVersion.getCurrent();// Returns: V.v1_20, V.v1_19, V.v1_8, etc.// Get the full version stringString fullVersion = MinecraftVersion.getFullVersion();// Returns: "1.20.4", "1.8.8", etc.// Get the subversion numberint subversion = MinecraftVersion.getSubversion();// Returns: 4 for 1.20.4, 8 for 1.8.8
Foundation provides intuitive methods for comparing Minecraft versions:
// Check if running exactly this versionif (MinecraftVersion.equals(V.v1_20)) { // Running MC 1.20.x}// Check if running older than a versionif (MinecraftVersion.olderThan(V.v1_13)) { // Running MC 1.12 or older // Use legacy Material names}// Check if running newer than a versionif (MinecraftVersion.newerThan(V.v1_12)) { // Running MC 1.13 or newer // Can use new features}// Check if running at least a versionif (MinecraftVersion.atLeast(V.v1_16)) { // Running MC 1.16 or newer // Can use hex colors}
Health changed from integers to doubles in MC 1.6:
// Get entity health (always returns int)int health = Remain.getHealth(entity);// Get max healthint maxHealth = Remain.getMaxHealth(entity);// Instead of:// entity.getHealth() // Returns int in old versions, double in new
// Send boss bar with percentageRemain.sendBossbarPercent(player, "&6Downloading...", 0.75f);// Send boss bar with custom color and styleRemain.sendBossbarPercent(player, "&cBoss Fight", 1.0f, CompBarColor.RED, CompBarStyle.SEGMENTED_10);// Send timed boss bar (auto-removes)Remain.sendBossbarTimed(player, "&aEvent starting!", 10);// Remove boss barRemain.removeBossbar(player);
// Set block type and data (works pre and post 1.13)Remain.setTypeAndData(block, Material.WOOL, (byte) 14);Remain.setTypeAndData(block, CompMaterial.RED_WOOL);// Set block dataRemain.setData(block, 5);// Spawn falling blockFallingBlock falling = Remain.spawnFallingBlock(location, Material.SAND);FallingBlock falling = Remain.spawnFallingBlock(block); // From block
// Create namespaced key (safe on old versions)if (MinecraftVersion.atLeast(V.v1_13)) { NamespacedKey key = Remain.newNamespaced("my_key"); // With random suffix NamespacedKey random = Remain.newNamespaced(); // Returns: "myplugin_a1b2c3d4e5f6g7h8"}
// Get inventory locationLocation loc = Remain.getLocation(inventory);// Get player localeString locale = Remain.getLocale(player); // "en_US"// Respawn playerRemain.respawn(player);Remain.respawn(player, 5); // After 5 ticks// Get biome at location (Y-coordinate safe)Biome biome = Remain.getBiome(location);// Open sign editor (1.8+)Remain.openSign(player, signBlock);
When you need version-specific behavior, use clear conditional blocks:
public void handleParticles(Location location) { if (MinecraftVersion.atLeast(V.v1_9)) { // Use new particle API location.getWorld().spawnParticle( Particle.FLAME, location, 10); } else { // Use legacy particle spawning location.getWorld().playEffect( location, Effect.MOBSPAWNER_FLAMES, 0); }}
Specify supported versions in your main plugin class:
public class MyPlugin extends SimplePlugin { @Override public MinecraftVersion.V getMinimumVersion() { return V.v1_8; } @Override public MinecraftVersion.V getMaximumVersion() { return V.v1_20; } @Override protected void onPluginStart() { // Plugin will auto-disable if version is out of range }}
Foundation will automatically prevent your plugin from loading if the server version is outside your specified range.