Getting Started - litjisz/Astra GitHub Wiki

Getting Started with Astra

This guide will help you create your first plugin using the Astra framework.

Installation

Adding Astra as a Dependency

Add Astra as a dependency in your pom.xml:

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>
	<dependency>
	    <groupId>com.github.litjisz</groupId>
	    <artifactId>Astra</artifactId>
	    <version>Tag</version>
	</dependency>

Creating Your First Astra Plugin

1. Create the Main Plugin Class

Create a main class that extends Astra:

package com.example.myplugin;

import lol.jisz.astra.Astra;

public class MyPlugin extends Astra {

    @Override
    protected void onInitialize() {
        logger().info("My plugin has been initialized!");
        
        // Register modules, commands, etc.
    }

    @Override
    protected void onShutdown() {
        logger().info("My plugin is shutting down!");
    }

    @Override
    protected void onReload() {
        logger().info("My plugin is reloading!");
    }
}

2. Create a Module

Create a module by extending AbstractModule:

package com.example.myplugin.modules;

import lol.jisz.astra.module.AbstractModule;

public class ExampleModule extends AbstractModule {

    @Override
    public void onEnable() {
        getLogger().info("Example module enabled");
    }

    @Override
    public void onDisable() {
        getLogger().info("Example module disabled");
    }

    @Override
    public void onReload() {
        getLogger().info("Example module reloaded");
    }
    
    public void doSomething() {
        getLogger().info("Doing something useful!");
    }
}

3. Create a Command

Create a command by extending CommandBase:

package com.example.myplugin.commands;

import lol.jisz.astra.command.CommandBase;
import org.bukkit.command.CommandSender;
import org.bukkit.command.Command;

import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;

public class ExampleCommand extends CommandBase {

    public ExampleCommand() {
        super("example", "myplugin.command.example", false, Arrays.asList("ex", "examplecmd"));
    }

    @Override
    public boolean execute(CommandSender sender, String label, String[] args) {
        sender.sendMessage("This is an example command!");
        return true;
    }

    @Override
    public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
        if (args.length == 1) {
            return Arrays.asList("option1", "option2", "option3");
        }
        return new ArrayList<>();
    }
}

4. Register Modules and Commands

Register your modules and commands in the main class:

@Override
protected void onInitialize() {
    logger().info("My plugin has been initialized!");
    
    // Register module
    ExampleModule exampleModule = Implements.register(new ExampleModule());
    
    // Register command
    getCommandManager().register(new ExampleCommand());
}

5. Configure the paper-plugin.yml file

Create a paper-plugin.yml file in your resources folder:

name: MyPlugin
version: '1.0.0'
main: com.example.myplugin.MyPlugin
api-version: '1.19'
description: My first plugin with Astra
author: YourName

Using Configuration Files

Astra makes it easy to work with configuration files:

// In your main plugin class or a module
ConfigManager configManager = Implements.fetch(ConfigManager.class);

// Load a configuration file
FileConfiguration config = configManager.loadConfig("settings");

// Get values with default fallbacks
String serverName = configManager.getString("settings", "server.name", "Default Server");
int maxPlayers = configManager.getInt("settings", "server.max-players", 20);

// Set values
configManager.set("settings", "server.name", "Awesome Server");

// Save changes
configManager.saveConfig("settings");

Working with Tasks

Astra provides a task system for handling asynchronous operations:

// In your main plugin class or a module
TaskManager taskManager = Implements.fetch(TaskManager.class);

// Create and run a simple task
taskManager.runAsync("example-task", () -> {
    // This code runs asynchronously
    System.out.println("Running in async thread!");
    
    // Then run something back on the main thread
    taskManager.runSync(() -> {
        System.out.println("Back on the main thread!");
    });
});

Next Steps

Now that you've created your first plugin with Astra, explore these topics to learn more:

Common Issues

Plugin Not Loading

  • Ensure your main class extends Astra
  • Check that your paper-plugin.yml file is correctly configured
  • Verify that the package path in paper-plugin.yml matches your main class

Commands Not Registering

  • Make sure you're registering commands in the onInitialize method
  • Check that your command class extends CommandBase
  • Verify that the command name doesn't conflict with existing commands

Modules Not Working

  • Ensure modules are properly registered using Implements.register()
  • Check for circular dependencies between modules
  • Make sure module dependencies are registered before dependent
⚠️ **GitHub.com Fallback** ⚠️