Compatre is a very small and fast tool to assist with version-dependent Bukkit programming. It makes "version-checkers" and multiple implementations for different versions redundant by replacing the required nms/craftbukkit types at runtime.
I.e. if you were to write a plugin that depends on anything from net.minecraft.server or org.bukkit.craftbukkit, you could simply mark the classes with an annotation and Compatre would replace the version if necessary when the plugin is loaded.
Here's an example of how compatre works: even though this is coded using nms version v1_12_R1 (1.12.2), it will run for any version if Compatre is used.
This is still in early development, but it does work already. See
my presents plugin for a production example.
Feel free to ask questions about details and give feedback in this resource's discussion.
I.e. if you were to write a plugin that depends on anything from net.minecraft.server or org.bukkit.craftbukkit, you could simply mark the classes with an annotation and Compatre would replace the version if necessary when the plugin is loaded.
Here's an example of how compatre works: even though this is coded using nms version v1_12_R1 (1.12.2), it will run for any version if Compatre is used.
Code (Java):
import
org.bukkit.command.Command
;
import org.bukkit.command.CommandExecutor ;
import org.bukkit.command.CommandSender ;
import org.bukkit.entity.Player ;
import com.github.johnnyjayjay.compatre.NmsDependent ; // the annotation
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer ; // <-- Version specific - usually wouldn't work on any other version
@NmsDependent // lets Compatre replace v1_12_R1 CraftPlayer with the correct CraftPlayer at runtime
public class VersionIndependentCommand implements CommandExecutor {
@Override
public boolean onCommand (CommandSender sender, Command command, String label, String [ ] args ) {
if (sender instanceof Player ) {
CraftPlayer player = (CraftPlayer ) sender ;
// do something with it
}
return true ;
}
}
import org.bukkit.command.CommandExecutor ;
import org.bukkit.command.CommandSender ;
import org.bukkit.entity.Player ;
import com.github.johnnyjayjay.compatre.NmsDependent ; // the annotation
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer ; // <-- Version specific - usually wouldn't work on any other version
@NmsDependent // lets Compatre replace v1_12_R1 CraftPlayer with the correct CraftPlayer at runtime
public class VersionIndependentCommand implements CommandExecutor {
@Override
public boolean onCommand (CommandSender sender, Command command, String label, String [ ] args ) {
if (sender instanceof Player ) {
CraftPlayer player = (CraftPlayer ) sender ;
// do something with it
}
return true ;
}
}
Feel free to ask questions about details and give feedback in this resource's discussion.
Quick facts
- Edition: Minecraft Java
- File type: .jar
- How to install: Install the matching mod loader (Forge, Fabric or NeoForge) for your Minecraft version. → Download the .jar. → Put it in the .minecraft/mods folder and launch that loader profile.
- Where to get it: Opens on Spigot — not every file is mirrored on our own servers.
Install steps are the general flow for this file type — How to install Minecraft Java mods & modpacks walks through it step by step.
[Tool] Compatre (Alpha - Looking for testers) is a free Minecraft Java mod. Downloaded 216 times (via Spigot). Download it and open it directly in the game.