Getting Started - litjisz/Astra GitHub Wiki
This guide will help you create your first plugin using the Astra framework.
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>
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!");
}
}
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!");
}
}
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<>();
}
}
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());
}
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
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");
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!");
});
});
Now that you've created your first plugin with Astra, explore these topics to learn more:
- Module System - Learn about the modular architecture
- Command System - Discover advanced command features
- Configuration Management - Master the configuration system
- Task System - Understand asynchronous task handling
- Best Practices - Tips for effective Astra development
- 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
- 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
- Ensure modules are properly registered using
Implements.register()
- Check for circular dependencies between modules
- Make sure module dependencies are registered before dependent