#How can I add optional Adventure support to a library I'm making without adding the dependency?

1 messages · Page 1 of 1 (latest)

pallid wraith
#

I want to add adventure support to my library and have no problem coding it.
but what I am struggling is how I actually implement it?

Like if someone is using adventure support they have to be using 1.16.5 but I want to add the optional dependency but not really since I want to ensure compatibility from 1.8.9 - 1.20.1
(I use some reflection checks as a workaround to know what to use depending on the version but they're mostly stored into constants so I don't have to deal with any runtime overhead).

Any idea how I can add compatibility for both lower versions AND adventure?

small vesselBOT
#

<@&987246652869971988> please have a look, thanks.

small vesselBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

how to make it optional without adding the dependency. Here are a few approaches you can consider:

  1. Reflection: You can use reflection to check if the Adventure library is available at runtime before using it. If it is available, you can dynamically load and use the Adventure classes and methods. If not, you can provide an alternative implementation or gracefully handle the absence of Adventure support.

  2. Conditional Compilation: Use conditional compilation directives specific to your programming language to include or exclude code that depends on the Adventure library. This way, when compiling your library, you can choose whether or not to include the Adventure-specific code based on a configuration flag.

  3. Dependency Injection: Instead of directly depending on the Adventure library, design your library in a way that allows users to provide their own implementation of the Adventure functionality through dependency injection. Users who want Adventure support can then provide their own implementation using the Adventure library, while others can provide alternative implementations or simply omit it.

  4. Adapter Pattern: Create an adapter interface within your library that abstracts away the specific functionality provided by the Adventure library. Implement this interface using the Adventure library if available, and provide alternative implementations for users who do not have the dependency. Users of your library can then interact with this adapter interface without directly depending on the Adventure library.

Remember to clearly document how users should enable or disable Adventure support in your library and provide examples or guidelines for each approach you choose to implement.

pallid wraith
#

like I want to make a way of adventure support that is implemented correctly that doesn't contain much boilerplate or writing a lot

#

and I don't want to have to make a different module containing 1.16.5 because now I'll do double the work.

royal light
#

Otherwise using platform bukkit might work

ember wadi
#

Why are you trying to support multiple versions?

#

But yes, you should create an interface with methods for all things that could be done using adventure.
And then implement 2 versions of it, 1 using adventure and the other using default bukkit methods.

#

Then check if adventure is present, possibly with reflection, and set the correct implementation

#

Providing this much version support is not really necessary tho

#

Always encourage staying up to date

ember wadi
#

I'd assume that

fair loom
#

i guess you could check if the package is present and the version of the server

#

do you use bukkit or paper server§

pallid wraith