メインコンテンツまでスキップ

開発者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()を通じて取得したコンテナのスナップショットインベントリで、インベントリメソッドaddItem()またはremoveItem()を使用してルートを変更できます。

これはキャンセル可能です。

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();
// 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クラスはビルドが貼り付けられたときにインスタンス化されるクラスで、チェストの満たしやモブのスポーンを含む、貼り付けのあらゆる側面を処理します。

利用可能なゲッターメソッド:

  • getSchematicContainer() - シェマティックコンテナを返します
  • getSchematicClipboard() - WorldEditクリップボードオブジェクトを返します
  • getSchematicOffset() - 配置用のベクトルオフセットを返します
  • getLocation() - 配置位置を返します

これらのメソッドは、カスタムリージョン保護を作成したり、ビルド配置を分析したりする際に役立ちます。

ModularWorld

ModularWorldクラスは生成されたモジュール式ワールドを表し、WorldGenerationFinishEventを通じて提供されます。すべての位置データと、生成されたワールドでエンティティとコンテナをスポーンするためのメソッドが含まれます。

主要メソッド:

  • getWorld() - Bukkitワールドインスタンスを返します
  • getWorldFolder() - ワールドのファイルフォルダを返します
  • getSpawnLocations() - マークされたすべてのスポーン位置を返します
  • getChestLocations() - すべてのチェストスポーン位置を返します
  • getBarrelLocations() - すべてのバレルスポーン位置を返します
  • getExitLocations() - すべての出口ポイント位置を返します
  • spawnChests() - マークされた位置にチェストをスポーンし、ブロックのリストを返します
  • spawnBarrels() - マークされた位置にバレルをスポーンし、ブロックのリストを返します
  • spawnInaccessibleExitLocations() - 上部エレベーターシェマティックスをスポーン
  • spawnAccessibleExitLocations() - 下部エレベーターシェマティックスをスポーン
  • spawnOtherEntities() - スポーンプールからカスタムエンティティをスポーン

WorldGuard

WorldGuardクラスはWorldGuardリージョン保護を処理します。ユーティリティメソッドpublic static ProtectedRegion generateProtectedRegion(FitAnything fitAnything, String regionName)は、開発者がBetterStructuresの上にカスタムリージョン保護スキームを簡単にフックできるように利用可能です。

その他の便利なメソッド:

  • checkArea(Location, Player) - プレイヤーが位置に建築できるかを確認
  • Protect(...) - プログラム的に保護されたリージョンを作成
  • Unprotect(CustomBossEntity) - リージョン保護を削除