开发者 API
要求
BetterStructures 要求:
- Java 17 或更高版本
- Spigot/Paper 服务器
- WorldEdit 插件 (7.3.0+)
可选依赖:
- WorldGuard (7.0.7+) - 用于区域保护功能
- EliteMobs - 用于精英怪物生成集成
- MythicMobs - 用于神话怪物集成
公开仓库
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>
注:访问 https://repo.magmaguy.com/releases/com/magmaguy/BetterStructures 查看可用版本。最新稳定版:2.0.4
Gradle
repositories {
maven {
name = "magmaguyRepoReleases"
url = uri("https://repo.magmaguy.com/releases")
}
}
dependencies {
implementation 'com.magmaguy:BetterStructures:2.0.4'
}
注:访问 https://repo.magmaguy.com/releases/com/magmaguy/BetterStructures 查看可用版本。最新稳定版:2.0.4
事件
注:事件在 com.magmaguy.betterstructures.api 中
包导入
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
在建筑即将被放置时调用。通过 FitAnything 对象暴露有关将要放置哪个建筑以及放置位置等的数据。
不要尝试修改正在放置的建筑! 你可以修改一些小内容,但更改整个建筑可能会导致建筑位置不适当。
此事件可以被取消。
ChestFillEvent
在宝箱被填充时调用。使用容器快照库存来安全地存储要应用的数据。
你可以使用容器快照库存上的库存方法 addItem() 或 removeItem() 来修改战利品,通过 getContainer().getSnapshotInventory() 获得。
此事件可以被取消。
WorldGenerationFinishEvent
在世界生成完成时调用。提供对包含生成世界的所有数据的 ModularWorld 对象的访问,包括生成点、宝箱位置和出口点。
此事件不可被取消。
你可以通过 getModularWorld() 方法访问世界数据,该方法提供:
getWorld()- Bukkit 世界对象getSpawnLocations()- 生成点位置列表getChestLocations()- 宝箱位置列表getBarrelLocations()- 桶位置列表getExitLocations()- 出口点位置列表spawnChests()- 在标记位置手动生成宝箱spawnBarrels()- 在标记位置手动生成桶
事件监听器示例
public class MyBetterStructuresListener implements Listener {
@EventHandler
public void onBuildPlace(BuildPlaceEvent event) {
FitAnything build = event.getFitAnything();
Location location = build.getLocation();
// 自定义逻辑在此处
// event.setCancelled(true); // 防止放置
}
@EventHandler
public void onChestFill(ChestFillEvent event) {
Container container = event.getContainer();
Inventory inv = container.getSnapshotInventory();
// 在此修改库存
inv.addItem(new ItemStack(Material.DIAMOND, 1));
}
@EventHandler
public void onWorldGenFinish(WorldGenerationFinishEvent event) {
ModularWorld world = event.getModularWorld();
// 访问生成的世界数据
List<Location> spawns = world.getSpawnLocations();
}
}
关键类
FitAnything
FitAnything 类是在建筑被粘贴时实例化的类,处理粘贴的每个方面,包括填充宝箱和生成怪物。
可用的 getter 方法:
getSchematicContainer()- 返回方案容器getSchematicClipboard()- 返回 WorldEdit Clipboard 对象getSchematicOffset()- 返回放置的向量偏移getLocation()- 返回放置位置
这些方法在创建自定义区域保护或分析建筑放置时很有用。
ModularWorld
ModularWorld 类代表生成的模块化世界,并通过 WorldGenerationFinishEvent 提供。它包含所有位置数据和在生成的世界中生成实体和容器的方法。
关键方法:
getWorld()- 返回 Bukkit 世界实例getWorldFolder()- 返回世界的文件夹getSpawnLocations()- 返回所有标记的生成位置getChestLocations()- 返回所有宝箱生成位置getBarrelLocations()- 返回所有桶生成位置getExitLocations()- 返回所有出口点位置spawnChests()- 在标记位置生成宝箱,返回 Block 列表spawnBarrels()- 在标记位置生成桶,返回 Block 列表spawnInaccessibleExitLocations()- 生成上层电梯方案spawnAccessibleExitLocations()- 生成下层电梯方案spawnOtherEntities()- 从生成池生成自定义实体
WorldGuard
WorldGuard 类处理 WorldGuard 区域保护。工具方法 public static ProtectedRegion generateProtectedRegion(FitAnything fitAnything, String regionName) 对开发者可用,以便轻松在 BetterStructures 之上挂钩自定义区域保护方案。
其他有用的方法:
checkArea(Location, Player)- 检查玩家是否可以在某个位置建造Protect(...)- 以编程方式创建受保护的区域Unprotect(CustomBossEntity)- 移除区域保护