PlotSquared
  • README
  • Getting Started
    • Why should you switch to PlotSquared?
    • Installation
  • Features
    • Block Buckets
    • ChestShop Compatibility
    • Commands
    • Plot backups
    • Plot flags
    • Plot membership tiers
    • UUID conversion
    • Vanilla tags
    • WorldEdit & FastAsyncWorldEdit features
  • API
    • API documentation
    • Event API
    • Flag API
  • Configuration
    • General Settings
    • Storage Configuration
    • World Configuration
  • Customization
    • Placeholders
    • Plot component presets
    • Plot components
    • Single plot area
  • Optimization
    • Chunk Processor
    • Plot Analysis
    • World Reduction
  • Permissions
    • Bypass Permissions
    • Permission Packs
  • Schematics
    • Plotworld Road Schematics
    • Schematic export
    • Plot Schematic on Generation
    • Plot Schematic on Claim
Powered by GitBook
On this page
  • Introduction
  • Event List
  • Getting an instance
  • Registering a Listener
Edit on GitHub
  1. API

Event API

Introduction

PlotSquared uses the Guava EventBus to register listeners and dispatch events.

Event List

Check the Javadoc of PlotSquared events.

Getting an instance

import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

public class MyPlotPlugin extends JavaPlugin {
    public static MyPlotPlugin THIS;

    @Override
    public void onEnable() {
        MyPlotPlugin.THIS = this;
        if (Bukkit.getPluginManager().getPlugin("PlotSquared") != null) {
        // Do something
       }
    }
}

Registering a Listener

Registering a listener is super easy. Add the @Subscribe (from the com.google.common.eventbus package) annotation to any methods that are listening to events, register the class with the EventBus through PlotAPI#registerListener(Class) and you're done! One example:

public class P2Listener {

  // if you like the dependency-injection-like approach:
  public P2Listener(PlotAPI api) {
    api.registerListener(this);
  }

  // less OOP, but if you want to make things easy:
  public P2Listener() {
    PlotAPI api = new PlotAPI();
    api.registerListener(this);
  }

  // A method handling a PlayerEnterPlotEvent
  @Subscribe
  public void onPlayerEnterPlot(PlayerEnterPlotEvent e) {
    //do stuff
  }
}
PreviousAPI documentationNextFlag API

Last updated 1 year ago