Developer API
Requirements
BetterStructures requires:
- Java 17 or higher
- Spigot/Paper server
- WorldEdit plugin (7.3.0+)
Optional dependencies:
- WorldGuard (7.0.7+) - For region protection features
- EliteMobs - For elite mob spawning integration
- MythicMobs - For mythic mob integration
Public Repository
Maven
<repositories>
<repository>
<id>magmaguy-repo-releases</id>
<name>MagmaGuy's Repository</name>
<url>https://repo.magmaguy.com/releases</url>
</repository>
</repositories>
<dependency>
<groupId>com.magmaguy</groupId>
<artifactId>BetterStructures</artifactId>
<version>2.0.4</version>
<scope>provided</scope>
</dependency>
Note: Visit https://repo.magmaguy.com/releases/com/magmaguy/BetterStructures to see available versions. Latest stable: 2.0.4
Gradle
repositories {
maven {
name = "magmaguyRepoReleases"
url = uri("https://repo.magmaguy.com/releases")
}
}
dependencies {
implementation 'com.magmaguy:BetterStructures:2.0.4'
}
Note: Visit https://repo.magmaguy.com/releases/com/magmaguy/BetterStructures to see available versions. Latest stable: 2.0.4
Events
Note: Events are in com.magmaguy.betterstructures.api
Package Imports
import com.magmaguy.betterstructures.api.BuildPlaceEvent;
import com.magmaguy.betterstructures.api.ChestFillEvent;
import com.magmaguy.betterstructures.api.WorldGenerationFinishEvent;
import com.magmaguy.betterstructures.buildingfitter.FitAnything;
import com.magmaguy.betterstructures.modules.ModularWorld;
import com.magmaguy.betterstructures.thirdparty.WorldGuard;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
BuildPlaceEvent
Called when a build is about to be placed. Exposes data about which build is going to be placed and where, among other things, through the FitAnything object.
Don't attempt to modify the build getting placed! You can modify minor things, but changing the whole build will probably result in a build with a poor fit.
This is cancellable.
ChestFillEvent
Called when a chest is filled. Uses the container snapshot inventory to safely store the data to be applied.
You can modify the loot using the Inventory methods addItem() or removeItem() on the container's snapshot inventory obtained via getContainer().getSnapshotInventory().
This is cancellable.
WorldGenerationFinishEvent
Called when world generation finishes. Provides access to the ModularWorld object containing all data about the generated world including spawn points, chest locations, and exit points.
This event is NOT cancellable.
You can access world data through the getModularWorld() method, which provides:
getWorld()- The Bukkit World objectgetSpawnLocations()- List of spawn point locationsgetChestLocations()- List of chest locationsgetBarrelLocations()- List of barrel locationsgetExitLocations()- List of exit point locationsspawnChests()- Manually spawn chests at marked locationsspawnBarrels()- Manually spawn barrels at marked locations
Example Event Listener
public class MyBetterStructuresListener implements Listener {
@EventHandler
public void onBuildPlace(BuildPlaceEvent event) {
FitAnything build = event.getFitAnything();
Location location = build.getLocation();
// Custom logic here
// event.setCancelled(true); // To prevent placement
}
@EventHandler
public void onChestFill(ChestFillEvent event) {
Container container = event.getContainer();
Inventory inv = container.getSnapshotInventory();
// Modify inventory here
inv.addItem(new ItemStack(Material.DIAMOND, 1));
}
@EventHandler
public void onWorldGenFinish(WorldGenerationFinishEvent event) {
ModularWorld world = event.getModularWorld();
// Access generated world data
List<Location> spawns = world.getSpawnLocations();
}
}
Key classes
FitAnything
The FitAnything class is the class that gets instantiated when a build gets pasted in and handles every aspect of the paste, including filling chests and spawning mobs.
Available getter methods:
getSchematicContainer()- Returns the schematic containergetSchematicClipboard()- Returns the WorldEdit Clipboard objectgetSchematicOffset()- Returns the Vector offset for placementgetLocation()- Returns the placement Location
These methods are useful when creating custom region protections or analyzing build placements.
ModularWorld
The ModularWorld class represents a generated modular world and is provided through the WorldGenerationFinishEvent. It contains all location data and methods for spawning entities and containers in the generated world.
Key methods:
getWorld()- Returns the Bukkit World instancegetWorldFolder()- Returns the world's File foldergetSpawnLocations()- Returns all marked spawn locationsgetChestLocations()- Returns all chest spawn locationsgetBarrelLocations()- Returns all barrel spawn locationsgetExitLocations()- Returns all exit point locationsspawnChests()- Spawns chests at marked locations, returns List of BlockspawnBarrels()- Spawns barrels at marked locations, returns List of BlockspawnInaccessibleExitLocations()- Spawns upper elevator schematicsspawnAccessibleExitLocations()- Spawns lower elevator schematicsspawnOtherEntities()- Spawns custom entities from spawn pools
WorldGuard
The WorldGuard class handles the WorldGuard region protections. The utility method public static ProtectedRegion generateProtectedRegion(FitAnything fitAnything, String regionName) is made available for developers to easily hook in a custom region protection scheme on top of BetterStructures.
Other useful methods:
checkArea(Location, Player)- Check if a player can build at a locationProtect(...)- Create protected regions programmaticallyUnprotect(CustomBossEntity)- Remove region protection