NeumimTo / NT-Rpg

Plugin which brings RPG features into minecraft.
12
Download

Developers

Addons

If you would like to add custom Skills, Effects, Guis and other stuff into ntrpg you have two ways how to achieve this.

  • Create a Sponge plugin with NT-RPG as a dependecy, and load all your stuff manually.

     @Plugin( ..., dependency="after:NtRpg")
      public class something {
    
     public oninit(GamePostInitializationEvent e) {     
         IoC c = IoC.get();
         ResourceLoader cl = c.build(ResourceLoader.class);
         //load everything from your jar
         cl.loadJarFile(yourjarfile,false)
         //or a single class
         cl.loadClass(YourAwesomeSkill.class);      
     }
    
  • Let the plugin’s classloader load everything automatically.

    • Simply annotate your Skills, Commands and listeners, with either @ResourceLoader.Skill,@ResourceLoader.Command, @ResourceLoader.ListenerClass annotations and place compiled jar into ntrpg/addons folder.

Annotation based Inversion of controll & Dependency injection

This concept is very similar to for example Spring’s @Component annotation.

https://github.com/NeumimTo/IoC - code

@Singleton - Each class annotated with this annotation is a Singleton (By default there is exactly one instance of the class present at runtime). Its constructor must be without arguments

@Inject - To each non-static field in a class annotated with the @Singleton annotation will be assigned its coresponding object reference at runtime.

@Command, @ListenerClass, @Skill- You can also use those as a replacement for @Singleton. This tells the classloader what to do with the class after its instance is created.

@PostProcess - Method annotation, which will be executed once the container loads all singletons from the classpath.

What does this mean?

@ResourceLoader.Skill
public void Something extends ActiveSkill {

    @Inject
    private SomeService someService   
     
    public SkillResult cast(...) {
          
    }
     
    @PostProcess(priority = 900) 
    public void somemethod() {
   
    }
}

Once the classloader discovers this class its recognized as a singleton, its instance is created. Once it has the instance the IoC container iterates over all fields(even in its subclasses). If the container finds an @Inject it assigns its value. If the required instance is not present in the container (has not been discovered yet) it tris to do the process again but now with another class (Recursive loop). Once the classloader finds all Singletons all methods annotated with PostProcess are called in a order according to its priority

Creating a persistent content with Hibernate

If you would like to add persistent data its recommended to use hibernate and jpa.

Listen to FindPersistenceContextEvent (requires ntcore as a dependency) and add the class of your Entity. The entity must follow standart JPA specification https://en.wikipedia.org/wiki/Java_Persistence_API

if you would like to manage persistent context extend a generic class GenericDao and annotate the class with @Singleton Annotation. You might want to override its methods. By default there is no cache, no locking, and only DETACHED! entites are returned.

Category: Role Playing

Published on Jul 2, 2017

5926 views

12 stars

714 total downloads

Licensed under GNU General Public License (GPL)

Members