開発者向け API
必要条件
BetterStructures には以下が必要です:
- Java 21 以上
- Spigot/Paper サーバー
- WorldEdit プラグイン(必須依存関係)
オプションの依存関係:
- WorldGuard - リージョン保護機能用(完全な統合には EliteMobs もインストールされている必要があります)
- EliteMobs - エリートモブのスポーン統合用
- MythicMobs - MythicMobs 統合用
- Terralith, Iris, Terra, TerraformGenerator - カスタムバイオーム互換用
公開リポジトリ
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.5.0</version>
<scope>provided</scope>
</dependency>
注: 利用可能なバージョンは https://repo.magmaguy.com/releases/com/magmaguy/BetterStructures を参照してください。最新の安定版: 2.5.0
Gradle
repositories {
maven {
name = "magmaguyRepoReleases"
url = uri("https://repo.magmaguy.com/releases")
}
}
dependencies {
implementation 'com.magmaguy:BetterStructures:2.5.0'
}
注: 利用可能なバージョンは https://repo.magmaguy.com/releases/com/magmaguy/BetterStructures を参照してください。最新の安定版: 2.5.0
イベント
注: イベントは 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() メソッドを使用することで、ルートを変更できます。
また、getTreasureConfigFilename() を呼び出すことで、このチェストの補充に使用されたルートテーブル設定を特定できます。
このイベントはキャンセル可能です。
WorldGenerationFinishEvent
ワールド生成が完了したときに呼び出されます。スポーンポイント、チェストの位置、出口ポイントなど、生成されたワールドに関するすべてのデータを含む ModularWorld オブジェクトへのアクセスを提供します。
このイベントはキャンセル不可です。
getModularWorld() メソッドを通じてワールドデータにアクセスできます。利用可能なすべてのメソッドについては、以下の ModularWorld セクションを参照してください。
イベントリスナーの例
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()- 配置先の Location を返します
これらのメソッドは、カスタムリージョン保護を作成したり、ビルド配置を解析したりする際に便利です。
ModularWorld
ModularWorld クラスは、生成されたモジュラー型ワールドを表すクラスで、WorldGenerationFinishEvent を通じて提供されます。生成されたワールド内でエンティティやコンテナをスポーンさせるためのすべての位置データとメソッドを含みます。
主要メソッド:
getWorld()- Bukkit の World インスタンスを返しますgetWorldFolder()- ワールドの File フォルダを返しますgetSpawnLocations()- マークされたすべてのスポーン位置を返します(List<Location>)getChestLocations()- すべてのチェストスポーン位置を返します(List<Location>)getBarrelLocations()- すべての樽スポーン位置を返します(List<Location>)getExitLocations()- すべての出口ポイント位置を返します(List<ExitLocation>)spawnChests()- マークされた位置にチェストをスポーンさせ、List<Block>を返しますspawnBarrels()- マークされた位置に樽をスポーンさせ、List<Block>を返しますspawnInaccessibleExitLocations()- 上部エレベーターのスキマティックをスポーンさせ、List<Location>を返しますspawnAccessibleExitLocations()- 下部エレベーターのスキマティックをスポーンさせ、List<Location>を返しますspawnOtherEntities()- スポーンプールからカスタムエンティティをスポーンさせますspawnInstancedEntities(MatchInstance)- インスタンス化されたボスエンティティをスポーンさせ、List<InstancedBossEntity>を返します
WorldGuard
WorldGuard クラスは WorldGuard のリージョン保護を処理します。ユーティリティメソッド public static ProtectedRegion generateProtectedRegion(FitAnything fitAnything, String regionName) が提供されており、開発者は BetterStructures の上にカスタムリージョン保護スキームを簡単にフックできます。
その他の便利なメソッド:
checkArea(Location, Player)- ある位置が BetterStructures によって保護されたリージョン内にあるかを確認します(保護されていれば true を返し、プレイヤーに警告メッセージを送信します)Protect(...)- プログラム的に保護リージョンを作成しますUnprotect(CustomBossEntity)- ボスが倒されたときにリージョン保護を解除します