AdvancedPluginApi 1.4.0

No permission to download
Make plugin coding as easy as never before
Supported software
Tags
Tags
None
An easy way to create plugins. it will easy your plugin development as never before. Everyone who has used Spring may be familiar with annotation development, which this API gives you!

To be able to use this resource, first of all, you must add the dependency to it
Code:
depend: [AdvancedPluginApi]

In your onEnable method, you must register this plugin to the API and it will handle the rest work

Java:
final Plugin advancedPluginApi = Bukkit.getPluginManager().getPlugin("AdvancedPluginApi");
if (advancedPluginApi != null) {
    final AdvancedPlugin pluginApi = (AdvancedPlugin) advancedPluginApi;
    pluginApi.registerPlugin(this);
}
  • Dependency Injection
You can use this plugin's integrated dependency injection.
you will have to annotate all Singleton classes with @ Component.
You may or may not include constructor. It doesn't matter
as long as you don't have a constructor that accepts non-component parameters.
like so
Java:
@Component
public class Boss {

    private Boss() {
        //Do not remove me plox
        //I am sexy <3
    }

    public void doSmthng(..) {
        ..
    }
}

Now you can do that with any other class using annotation Component, RegisterListener, RegisterCommand or the main class of your plugin and it will work fine.

Java:
public class CoolPlugin extends JavaPlugin {

    @AutoInject
    private Boss boss;

    @Override
    public void onEnable() {
        //register this plugin to the api(shown above)
        boss.doSmthng();
    }

}


You can see the example usages there:
https://github.com/ablax/AdvancedPluginApi/tree/master/examples/

You don't need to manually register listeners, for every listener class, you just need to add
@ RegisterListener annotation.

You don't need to manually set command executors, for every listener class, you just need to add
@ RegisterCommand(commandName = "cmdName") annotation.

You can add as many components as you want in the components' constructors, as long as you have just one constructor, and they will be auto injected as well.


  • Caching
This API provides caching functionality out of the box. What does that mean? Let's say that you are making a lot of calls to the database and it's costly for you. And most of the time the results are the same.
Instead of calling the database every time, you can get an OptionalCache implementation and make it do it for you, and save all the received records and not repeat the database calls.

How to do that?

Well let's say that this is your database call method:
Java:
public String getNameFromDb(UUID uuid){
  return db.connect().getName(uuid);
}

if you are using this repeatedly, with repeating uuids' it may be real performance bad.

You can create an OptionalCache variable in your class with getNameFromDb doing so.
Java:
OptionalCache<UUID, String> optionalCache = CacheFactory.buildOptionalCache(15 (max cache size), 1 (time), TimeUnit.HOURS (time unit);

Now you must initialize this OptionalCache providing with function to fetch from DB. You can do it in any constructor/init method/onEnable

like so:
Java:
@Override
public void onEnable() {
    optionalCache.init(uuid -> Optional.ofNullable(getNameFromDb(uuid)));
}

and every time you call optionalCache.loadAndGetByKey(uuid)
it will give you the cached value if there is one. If it doesn't contain cached value, then it will call the database and cache the given value.

Latest updates

  1. ConfigValue

    Fixed issues with AutoInject Fixed Interfaces injection - now it woks (only for 1 impl per...
  2. Update caching and autoinjecting

    CacheFactory Injecting interfaces, as much as possible
  3. AdvancedPluginApi v1.2.0

    Caching out of the box. Now you can use implemented caching functions out of the box.

Author

Ablax

Owner
Author
Ablax
Downloads
3
Views
160
First release
Last update
Rating
0.00 star(s) 0 ratings
Top
You need to upgrade!
Our dark style is reserved for our Premium members. Upgrade here.