API

The API is only available for Homestead 3.0.0 and higher.

To access the Homestead API in your plugin, download the Homestead .jar file from SpigotMC and upload it as a third-party JAR to your project. Click here or here for the guide to installing the dependency.

Example plugin

This is an example plugin that uses the Homestead API.

import java.util.logging.Logger;
import org.bukkit.plugin.java.JavaPlugin;

import tfagaming.projects.minecraft.homestead.Homestead;
import tfagaming.projects.minecraft.homestead.api.API;
import tfagaming.projects.minecraft.homestead.api.HomesteadAPI;

public class Plugin extends JavaPlugin {
	private static final Logger logger = Logger.getLogger("Example");

	public void onEnable() {
		logger.info("Example plugin is enabled");
		
		try {
			// Get the instance (verifies if the plugin is installed and enabled)
			Homestead instance = Homestead.getInstance();

			// Showing Homestead's installed version on the server
			logger.info("Homestead's version = " + Homestead.getVersion());

			// Getting the API
			HomesteadAPI api = new API();

			api.getRegionsManager();
			api.getChunksManager();
		} catch (NoClassDefFoundError e) {
			logger.warning("Unable to find Homestead plugin!");
		}
	}

	public void onDisable() {
		logger.info("Example plugin is disabled");
	}
}

Package your Java project and then export it as a .jar file. You will notice a new .jar file appears in the main directory of your project, upload it to your server's plugins folder, and then restart the server!

Last updated