Getting Started

Setting Up Your Development Environment

Before you can start developing plugins, you need to set up your development environment:

  1. Install Java Development Kit (JDK) 17 or higher

    Spigot requires JDK 17 or higher for the latest versions. Download it from Adoptium or Oracle.

  2. Choose an IDE

    We recommend IntelliJ IDEA or Eclipse for Java development.

  3. Set up a build system

    Maven or Gradle are recommended for managing dependencies and building your plugin.

  4. Get the Spigot API

    Add the Spigot API as a dependency in your project.

Creating Your First Plugin

Here's a basic structure for a simple plugin:

MyPlugin.java
123456789101112131415
package com.example.myplugin;

import org.bukkit.plugin.java.JavaPlugin;

public class MyPlugin extends JavaPlugin {
    @Override
    public void onEnable() {
        getLogger().info("MyPlugin has been enabled!");
    }

    @Override
    public void onDisable() {
        getLogger().info("MyPlugin has been disabled!");
    }
}

You'll also need a plugin.yml file in your resources directory:

plugin.yml
123456
name: MyPlugin
version: 1.0
main: com.example.myplugin.MyPlugin
api-version: 1.19
author: YourName
description: My first Spigot plugin

Core Concepts

Plugin Structure

A well-organized plugin typically includes:

  • Main class - Extends JavaPlugin and serves as the entry point
  • Commands - Classes that implement CommandExecutor
  • Listeners - Classes that implement Listener for event handling
  • Configuration - Managing plugin settings
  • Data storage - Saving and loading data

Event Handling

Events are a core concept in Bukkit/Spigot development. They allow your plugin to respond to things happening in the game.

MyListener.java
12345678910
public class MyListener implements Listener {
    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        Player player = event.getPlayer();
        player.sendMessage("Welcome to the server!");
    }
}

// In your main class:
getServer().getPluginManager().registerEvents(new MyListener(), this);

Commands

Commands allow players to interact with your plugin:

MyCommand.java
12345678910111213
public class MyCommand implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (sender instanceof Player) {
            Player player = (Player) sender;
            player.sendMessage("Command executed!");
        }
        return true;
    }
}

// In your main class:
getCommand("mycommand").setExecutor(new MyCommand());

Don't forget to register your command in plugin.yml:

plugin.yml (commands section)
12345
commands:
  mycommand:
    description: My custom command
    usage: /mycommand
    permission: myplugin.mycommand

Advanced Topics

Data Storage

There are several ways to store data in your plugin:

  • Configuration files - Using YAML with Bukkit's configuration API
  • Custom files - Creating your own file formats
  • Databases - MySQL, SQLite, MongoDB, etc.

Example of using configuration:

Configuration Example
123456789
// Save default config
saveDefaultConfig();

// Get a value
String message = getConfig().getString("welcome-message", "Welcome!");

// Set a value
getConfig().set("last-reload", System.currentTimeMillis());
saveConfig();

Plugin Optimization

Performance is crucial for Minecraft plugins. Here are some tips:

  • Avoid blocking the main thread with heavy operations
  • Use Bukkit's scheduler for delayed or repeating tasks
  • Cache data when possible to avoid repeated calculations
  • Be mindful of memory usage, especially with large collections
  • Use efficient algorithms and data structures

Plugin Integration

Your plugin can integrate with other plugins using:

  • Soft dependencies - Optional integration
  • Hard dependencies - Required for your plugin to function
  • Service registration - Providing services to other plugins
  • Custom events - Creating your own events for other plugins to listen to

Example of checking for another plugin:

Plugin Integration Example
1234
if (getServer().getPluginManager().getPlugin("SomeOtherPlugin") != null) {
    // SomeOtherPlugin is installed
    // Integrate with it here
}