{"id":18011306,"url":"https://github.com/johnnyjayjay/compatre","last_synced_at":"2025-03-26T15:32:43.540Z","repository":{"id":138563063,"uuid":"194443197","full_name":"JohnnyJayJay/compatre","owner":"JohnnyJayJay","description":"An extremely small and fast Bukkit tool to dynamically replace version-specific types (nms, craftbukkit) at runtime without any boilerplate.","archived":false,"fork":false,"pushed_at":"2020-08-21T14:38:53.000Z","size":776,"stargazers_count":19,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-22T02:02:46.658Z","etag":null,"topics":["bytecode-manipulation","compatibility","hacktoberfest","java","minecraft","spigot"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JohnnyJayJay.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-29T19:50:52.000Z","updated_at":"2025-01-01T20:48:57.000Z","dependencies_parsed_at":"2023-03-16T12:01:07.391Z","dependency_job_id":null,"html_url":"https://github.com/JohnnyJayJay/compatre","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohnnyJayJay%2Fcompatre","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohnnyJayJay%2Fcompatre/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohnnyJayJay%2Fcompatre/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JohnnyJayJay%2Fcompatre/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JohnnyJayJay","download_url":"https://codeload.github.com/JohnnyJayJay/compatre/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245681562,"owners_count":20655219,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bytecode-manipulation","compatibility","hacktoberfest","java","minecraft","spigot"],"created_at":"2024-10-30T03:08:57.714Z","updated_at":"2025-03-26T15:32:43.535Z","avatar_url":"https://github.com/JohnnyJayJay.png","language":"Java","readme":"# Compatre\n[![](https://jitpack.io/v/johnnyjayjay/compatre.svg)](https://jitpack.io/#johnnyjayjay/compatre)\n\nCompatre is a very small and fast tool to assist with version-dependent Bukkit programming. \nIt makes \"version-checkers\" and multiple implementations for different versions (but the same functionality)\nredundant by replacing the required nms/craftbukkit types at runtime.\n\n**Features include:**\n- A java agent to dynamically replace types (no boilerplate)\n- A custom ClassLoader as an alternative to the agent (very little boilerplate)\n- A library to support cases where more than just a type replacement is needed *coming soon...*\n\n## Dependency\n### Maven\n```xml\n\u003crepositories\u003e\n    \u003crepository\u003e\n        \u003cid\u003ejitpack.io\u003c/id\u003e\n        \u003curl\u003ehttps://jitpack.io\u003c/url\u003e\n    \u003c/repository\u003e\n\u003c/repositories\u003e\n\n\u003cdependencies\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003ecom.github.johnnyjayjay\u003c/groupId\u003e\n        \u003cartifactId\u003ecompatre\u003c/artifactId\u003e\n        \u003cversion\u003ev0.2.2-alpha\u003c/version\u003e\n    \u003c/dependency\u003e\n\u003c/dependencies\u003e\n```\n### Gradle\n```groovy\nrepositories {\n    maven {\n        url(\"https://jitpack.io\")\n    }\n}\n\ndependencies {\n    implementation(\"com.github.johnnyjayjay:compatre:v0.2.2-alpha\")\n}\n```\n\n## Note\nThis project is still in early development/alpha. This mainly needs testing now and breaking \nchanges may occur at any time. Please leave requests, ideas and bug reports in the \n[issues section](https://github.com/johnnyjayjay/compatre/issues) of this repository.\n\n## Agent Setup\nSetting up the agent is fairly easy. Head over to the [releases](../../releases) and download \nthe latest `all` jar file from there. Now place the file somewhere near your server jar, e.g. in the `lib` \ndirectory of your Minecraft server directory.\n\nNow add the the agent to your JVM arguments when starting the server:\n```batch\njava -jar -javaagent:\"./lib/compatre.jar\" \"spigot-1.12.2.jar\"\n```\n(Replace the `javaagent` path and name as well as the server jar with your equivalents)\n\n## Usage (Code)\nThe usage of compatre in your code differs depending on what parts of the library you use.\n### Agent\nThe agent has the simplest usage. Since it is defined in the JVM arguments, you don't have \nto write any additional code. Just annotate classes that depend on version specific nms / craftbukkit\ntypes with `@NmsDependent`:\n```java\nimport org.bukkit.command.Command;\nimport org.bukkit.command.CommandExecutor;\nimport org.bukkit.command.CommandSender;\nimport org.bukkit.entity.Player;\n\nimport com.github.johnnyjayjay.compatre.NmsDependent; // the annotation\n\nimport org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer; // \u003c-- Version specific - usually wouldn't work on any other version\n\n@NmsDependent // makes the agent replace v1_12_R1 CraftPlayer with the correct CraftPlayer at runtime\npublic class VersionIndependentCommand implements CommandExecutor {\n  @Override\n  public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {\n    if (sender instanceof Player) {\n      CraftPlayer player = (CraftPlayer) sender;\n      // do something with it\n    } \n    return true;\n  }\n}\n```\n\n### ClassLoader\nJust like with the agent, you simply need to annotate version dependent classes as `@NmsDependent`. \nYou just need to do one more thing though: manually load these classes.\nThat's much simpler than it sounds; just modify your plugin class like this:\n```java\nimport org.bukkit.plugin.JavaPlugin;\nimport com.github.johnnyjayjay.compatre.NmsClassLoader;\n\npublic class MyPlugin extends JavaPlugin {\n  // this will only run once when MyPlugin is loaded\n  static {\n    NmsClassLoader.loadNmsDependents(MyPlugin.class); // loads all nms dependents of this plugin\n  }\n  \n  // etc.\n}\n```\nNote that there is no way to modify the class this method is invoked in. So `MyPlugin` here could \nnot depend on version specific classes.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnnyjayjay%2Fcompatre","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohnnyjayjay%2Fcompatre","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnnyjayjay%2Fcompatre/lists"}