developers

RegionAPI allows simple management of regions

RegionAPI GitHub

Developers of Region plugins

If you wish your Region plugin to be supported by RegionAPI, follow these instructions:

1. Add the latest jar file (from the main BukkitDev page) to your build path.

2. In your plugin.yml, add "RegionAPI" as a soft-dependency.

softdepend: [RegionAPI]
OR
softdepend: [OtherPlugin,RegionAPI]

3. In your onEnable() method, add the following code:

Plugin regionapi = Bukkit.getServer().getPluginManager().getPlugin("RegionAPI");
if (regionapi != null && regionapi.isEnabled() && regionapi instanceof com.yoshigenius.regionapi.RegionAPI) {
    YourPluginRegionProvider provider = new YourPluginRegionProvider(); // you need to make an object called this (change YourPlugin to your plugin's name, and the constructor can be anything, RegionAPI doesn't mind) and make it extend com.yoshigenius.regionapi.RegionProvider
    boolean success = com.yoshigenius.regionapi.RegionAPI.getConnector().registerRegionProvider(provider); // this tells RegionAPI to use it as a possible provider
    if (success) {
        // do something here like stating that it's connected or not.
    }
}

4. Make sure in your region provider class that you fill out all the methods that are abstracted! be sure to convert every region to either a CuboidRegion or PolygonalRegion if possible, if not, make it a Region, but that doesn't store points. If you have any region shapes that aren't supported by RegionAPI yet, PM YoshiGenius here on BukkitDev and they will be added!

5. Your plugin is ready to be used on a server that runs RegionAPI too!

Developers of plugins hooking into RegionAPI for region info

1. Add the latest jar file (from the main BukkitDev page) to your build path.

2. In your plugin.yml, add "RegionAPI" as a soft-dependency.

softdepend: [RegionAPI]
OR
softdepend: [OtherPlugin,RegionAPI]

3. In your onEnable() method, add the following code:

Plugin regionapi = Bukkit.getServer().getPluginManager().getPlugin("RegionAPI");
if (regionapi != null && regionapi.isEnabled() && regionapi instanceof com.yoshigenius.regionapi.RegionAPI) {
    // code stating that RegionAPI was found
    enableRegionAPIHook(); // whatever you wanna do, you should make a global variable that manages if regionapi is on the server or not
}

4. In any event or other methods, you can manage RegionAPIs regions. Just connect to the connector ( RegionConnector connector = com.yoshigenius.regionapi.RegionAPI.getConnector() ) and you'll be able to manage it using the connector variable. You can access individual RegionProviders or all of them at once, using the connector's main methods. For example:

@EventHandler
public void onClick(PlayerInteractEvent event) {
    Location loc = event.getClickedBlock().getLocation();
    Region[] regions = mainPlugin.getRegionAPIConnector().getRegions(loc);
    if (regions.length == 0) {
        // there are no regions there, do something
    } else {
        // there are regions there, do something!
        for (Region region : regions) {
            if (region instanceof CuboidRegion) {
                CuboidRegion cregion = (CuboidRegion) region;
                // do something with it
            } else if (region instanceof PolygonalRegion) {
                PolygonalRegion pregion = (PolygonalRegion) region;
                // do something with it
            } else {
                // Either the region type isn't supported by the current version of RegionAPI, the developer of the plugin that owns the region has converted it into a normal region, or the developer has made a mistake!
            }
        }
    }
}

5. That's all. I hope this helped!


Comments

Posts Quoted:
Reply
Clear All Quotes