Skip to content

RoughlyUnderscore/UnderscoreEnchantsAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License Maven Central

UnderscoreEnchantsAPI

This is the API for my project UnderscoreEnchants. UnderscoreEnchantsAPI is hosted in Maven Central, so it's trivially easy to use it in your projects!

Dependency

<dependency>
  <groupId>io.github.zbll-cuber.enchantsapi</groupId>
  <artifactId>UnderscoreEnchantsAPI</artifactId>
  <version>2.1.2</version> <!-- Make sure to always use the latest version! -->
  <scope>provided</scope>
</dependency>

How to use it

// 1) Create an undeclared UEnchantsAPI instance
public UEnchantsAPI ueAPI;
@Override
public void onEnable() {
  
  // 2) Make sure that UnderscoreEnchants is installed
  Plugin plugin = getServer().getPluginManager().getPlugin("UnderscoreEnchants");
  if (plugin == null) {
    getLogger().severe("UnderscoreEnchants is not installed!");
    return;
  }
  // 3) Cast
  ueAPI = (UEnchantsAPI) plugin;
    
  // How to use the methods?
  ueAPI.enchant();
  // Easy as that.
}

If you want to use the methods from other classes, access this very instance with dependency injection of the main class.

class AnotherClass {
  private final MainClass mc;
  public AnotherClass(MainClass mc) {
    this.mc = mc;
  }
  
  public void usage() {
    mc.ueAPI.enchant();
  }
}

Listening to events is nothing new.

@EventHandler
public void onAnvilCombine(EnchantmentsCombineEvent ev) {
}

If you would like to see the implementation of this API in UnderscoreEnchants, click here.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Languages