開發者 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
在箱子被填充時調用。使用容器快照清單來安全地儲存要應用的數據。
您可以使用通過 getContainer().getSnapshotInventory() 獲得的容器快照清單上的 Inventory 方法 addItem() 或 removeItem() 來修改戰利品。
這是可取消的。
WorldGenerationFinishEvent
在世界生成完成時調用。提供對 ModularWorld 物件的訪問,該物件包含有關生成的世界的所有數據,包括衍生點、箱子位置和出口點。
此事件不可取消。
您可以通過 getModularWorld() 方法訪問世界數據,該方法提供:
getWorld()- Bukkit World 物件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();
// 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();
}
}
關鍵類別
FitAnything
FitAnything 類別是在貼上建築時實例化的類別,它處理貼上的每個方面,包括填充箱子和衍生生物。
可用的 getter 方法:
getSchematicContainer()- 返回示意圖容器getSchematicClipboard()- 返回 WorldEdit Clipboard 物件getSchematicOffset()- 返回放置的 Vector 偏移getLocation()- 返回放置位置
這些方法在創建自定義區域保護或分析建築放置時很有用。
ModularWorld
ModularWorld 類別代表生成的模組化世界,並通過 WorldGenerationFinishEvent 提供。它包含所有位置數據以及在生成的世界中衍生實體和容器的方法。
關鍵方法:
getWorld()- 返回 Bukkit World 實例getWorldFolder()- 返回世界的 File 資料夾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)- 移除區域保護