I am writing a plugin for Minecraft which uses WorldEdit. There is a class BlockVector3 with methods getBlockX() and getX() which are deprecated and marked for removal, to be replaced by x().
The problem is that if I use the new method, users who are using an older version of WorldEdit will no longer be able to use my plugin. And if I retain the deprecated method, it will soon cease to function with the latest dependency.
I could write two different plugins. However, is there a way to work around this particular issue using reflection or some other introspection?
There are multiple ways to do this.
It's a common way to do it. Mostly, people do an interface like this :
Then, create a new class for each version like this:
Then, in the
onEnable(), firstly check for which version is used, then instanciate it withnew WorldEdit3()for example, then save it asWorldEditAdapter. Now, your full plugin will useWorldEditAdapter.About how to use method not available, if you don't have compilation plugin, maybe you can import multiple file to "fake" the existance of method for 2 versions. This could be tricky.
You can also use reflection as you mentionned. It's not preferable. To use it, do:
Static call of method:
With gradle and maven it would be easier. You can do solution 1 but by putting the
WorldEdit3in different subproject loaded by the main one. It would be easier to manage, but it's not your case.