Skip to content

bytezlol/FlameAPI

Repository files navigation

FlameAPI — Developer Guide

FlameAPI is the framework our plugins are built on. It bundles a Folia-aware scheduler, a database layer (SQLite / MySQL via HikariCP), an annotation-based command framework, a GUI builder, an event bus, hooks (Vault / PlaceholderAPI), an ItemBuilder, MiniMessage / hex utilities, and more.

You can use FlameAPI as a library inside your own plugin.

Adding FlameAPI to your project

repositories {
    maven("https://jitpack.io")
}

dependencies {
    implementation("com.github.bytezlol:FlameAPI:1.0.0")
}

Bootstrapping FlameAPI

Call FlameAPI.bootstrap(this) once in your plugin's onEnable. After that, anything in your plugin can call FlameAPI.get().

public final class MyPlugin extends JavaPlugin {

    @Override
    public void onEnable() {
        FlameAPI api = FlameAPI.bootstrap(this);

        api.commands().register(new MyCommand());
    }

    @Override
    public void onDisable() {
        FlameAPI.get().shutdown();
    }
}

Scheduler

FlameAPI.get().scheduler().async(() -> {
    // off the main thread
});

FlameAPI.get().scheduler().atEntity(player, () -> {
    player.sendMessage("on the player's region thread (Folia-safe)");
});

FlameAPI.get().scheduler().repeatAsync(() -> tick(), 0L, 20L);

Annotation-based commands

@Command(name = "heal", aliases = {"h"}, permission = "myplugin.heal", playerOnly = true)
public class HealCommand extends AbstractCommand {

    @Override
    public void onCommand(@NotNull CommandContext context) {
        Player player = context.asPlayer();
        player.setHealth(20);
        FlameAPI.get().messages().send(player, "<#8DFB08>Healed!");
    }

    @SubCommand(value = "all", permission = "myplugin.heal.all")
    public void healAll(@NotNull CommandContext context) {
        Bukkit.getOnlinePlayers().forEach(p -> p.setHealth(20));
    }
}

// register
FlameAPI.get().commands().register(new HealCommand());

GUI builder

public class ShopGui extends Gui {

    public ShopGui() {
        super(27, "<#FF6B00>Shop");

        setButton(13,
            ItemBuilder.of(Material.DIAMOND).name("<aqua>Buy Diamond").lore("<gray>Costs $100").build(),
            click -> ((Player) click.getWhoClicked()).sendMessage("Bought!")
        );
    }
}

new ShopGui().open(player);

Database

DatabaseProvider db = new SqliteProvider(new File(getDataFolder(), "data.db"));
db.connect();

db.execute("CREATE TABLE IF NOT EXISTS players (uuid TEXT PRIMARY KEY, balance REAL);").join();

db.update("INSERT OR REPLACE INTO players VALUES (?, ?);", uuid, 100.0);
db.queryOne("SELECT balance FROM players WHERE uuid = ?;", rs -> rs.getDouble("balance"), uuid)
  .thenAccept(balance -> System.out.println("Balance: " + balance));

Hooks

VaultHook vault = FlameAPI.get().hooks().get(VaultHook.class);
if (vault != null && vault.hasEconomy()) {
    vault.withdraw(player, 100.0);
}

PlaceholderHook papi = FlameAPI.get().hooks().get(PlaceholderHook.class);
String parsed = papi.set(player, "Hello %player_name%");

Events (lambda-based)

FlameAPI.get().events().listen(PlayerJoinEvent.class, event -> {
    event.getPlayer().sendMessage("Welcome!");
});

FlameRTP API

If you want to integrate with FlameRTP from another plugin:

FlameRTPAPI api = FlameRTP.getInstance().getApi();

api.teleport(player).thenAccept(result -> {
    if (result.isSuccess()) {
        getLogger().info("Sent " + player.getName() + " to " + result.getLocation());
    }
});

// Listen to RTP events
FlameAPI.get().events().listen(PreRTPEvent.class, event -> {
    if (event.getRequest().getPlayer().getName().equals("Notch")) event.setCancelled(true);
});

Authors

  • bytezlol

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages