├── .github ├── dependabot.yml └── workflows │ └── dokka.yml ├── .gitignore ├── LICENSE ├── README.md ├── api ├── build.gradle.kts └── src │ └── main │ └── kotlin │ └── com │ └── github │ └── syari │ └── spigot │ └── api │ ├── EasySpigotAPI.kt │ ├── EasySpigotAPIOption.kt │ ├── UnsupportedMinecraftVersion.kt │ ├── command │ ├── CommandArgument.kt │ ├── CommandCreator.kt │ ├── execute │ │ └── CommandExecuteParameter.kt │ ├── extension.kt │ └── tab │ │ ├── CommandTab.kt │ │ └── CommandTabArgument.kt │ ├── component │ ├── TextComponentBuilder.kt │ └── extension.kt │ ├── config │ ├── CustomConfig.kt │ ├── converter │ │ └── ConfigItemConverter.kt │ ├── def │ │ ├── DefaultConfig.kt │ │ ├── DefaultConfigAction.kt │ │ ├── DefaultConfigFile.kt │ │ ├── DefaultConfigMap.kt │ │ ├── DefaultConfigResource.kt │ │ └── DefaultConfigStream.kt │ ├── extension.kt │ └── type │ │ ├── ConfigDataType.kt │ │ ├── ConfigSectionType.kt │ │ ├── data │ │ ├── ConfigBooleanDataType.kt │ │ ├── ConfigCoordinateDataType.kt │ │ ├── ConfigDateDataType.kt │ │ ├── ConfigDoubleDataType.kt │ │ ├── ConfigEnchantmentByKeyDataType.kt │ │ ├── ConfigEnchantmentByNameDataType.kt │ │ ├── ConfigEntityTypeDataType.kt │ │ ├── ConfigEnumDataType.kt │ │ ├── ConfigFloatDataType.kt │ │ ├── ConfigIntDataType.kt │ │ ├── ConfigInventoryDataType.kt │ │ ├── ConfigItemStackDataType.kt │ │ ├── ConfigLocationDataType.kt │ │ ├── ConfigLongDataType.kt │ │ ├── ConfigMaterialDataType.kt │ │ ├── ConfigNumberDataType.kt │ │ ├── ConfigParticleDataType.kt │ │ ├── ConfigPotionEffectTypeDataType.kt │ │ ├── ConfigSerializableInventoryDataType.kt │ │ ├── ConfigSerializableItemStackDataType.kt │ │ ├── ConfigSoundByKeyDataType.kt │ │ ├── ConfigSoundByNameDataType.kt │ │ ├── ConfigStringDataType.kt │ │ ├── ConfigUUIDDataType.kt │ │ ├── ConfigVectorDataType.kt │ │ ├── ConfigWorldDataType.kt │ │ └── list │ │ │ ├── ConfigCoordinateListDataType.kt │ │ │ ├── ConfigEnchantmentByKeyListDataType.kt │ │ │ ├── ConfigEnchantmentByNameListDataType.kt │ │ │ ├── ConfigEntityTypeListDataType.kt │ │ │ ├── ConfigEnumListDataType.kt │ │ │ ├── ConfigItemStackListDataType.kt │ │ │ ├── ConfigLocationListDataType.kt │ │ │ ├── ConfigMaterialListDataType.kt │ │ │ ├── ConfigParticleListDataType.kt │ │ │ ├── ConfigPotionEffectTypeListDataType.kt │ │ │ ├── ConfigSerializableItemStackListDataType.kt │ │ │ ├── ConfigSoundByKeyListDataType.kt │ │ │ ├── ConfigSoundByNameListDataType.kt │ │ │ ├── ConfigStringListDataType.kt │ │ │ ├── ConfigUUIDListDataType.kt │ │ │ ├── ConfigVectorListDataType.kt │ │ │ └── ConfigWorldListDataType.kt │ │ └── section │ │ └── ConfigIntSectionType.kt │ ├── event │ ├── EventAction.kt │ ├── Events.kt │ └── extension.kt │ ├── inventory │ ├── ClickEventAction.kt │ ├── CustomInventory.kt │ ├── InventoryPlayerData.kt │ └── extension.kt │ ├── item │ └── extension.kt │ ├── message │ └── extension.kt │ ├── nms │ ├── CraftItemStackWrapper.kt │ ├── NBTTagCompoundWrapper.kt │ ├── NMSItemStackWrapper.kt │ ├── NMSWrapper.kt │ └── extension.kt │ ├── particle │ └── extension.kt │ ├── scheduler │ └── extension.kt │ ├── sound │ └── extension.kt │ ├── string │ └── extension.kt │ ├── uuid │ ├── UUIDEntity.kt │ ├── UUIDPlayer.kt │ └── extension.kt │ └── world │ ├── Coordinate.kt │ └── Region.kt ├── build.gradle.kts ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── sample ├── README.md ├── build.gradle.kts ├── command │ ├── README.md │ └── src │ │ └── main │ │ └── kotlin │ │ └── com │ │ └── github │ │ └── syari │ │ └── spigot │ │ └── api │ │ └── sample │ │ └── command │ │ ├── Main.kt │ │ ├── TeleportCommand.kt │ │ └── extension.kt ├── component │ └── src │ │ └── main │ │ └── kotlin │ │ └── com │ │ └── github │ │ └── syari │ │ └── spigot │ │ └── api │ │ └── sample │ │ └── component │ │ └── Main.kt ├── config │ ├── README.md │ └── src │ │ └── main │ │ └── kotlin │ │ └── com │ │ └── github │ │ └── syari │ │ └── spigot │ │ └── api │ │ └── sample │ │ └── config │ │ ├── ConfigLoader.kt │ │ └── Main.kt ├── event │ ├── README.md │ └── src │ │ └── main │ │ └── kotlin │ │ └── com │ │ └── github │ │ └── syari │ │ └── spigot │ │ └── api │ │ └── sample │ │ └── event │ │ ├── EventListener.kt │ │ └── Main.kt ├── inventory │ ├── README.md │ └── src │ │ └── main │ │ └── kotlin │ │ └── com │ │ └── github │ │ └── syari │ │ └── spigot │ │ └── api │ │ └── sample │ │ └── inventory │ │ ├── Main.kt │ │ └── OpenInventoryCommand.kt ├── nms │ └── src │ │ └── main │ │ └── kotlin │ │ └── com │ │ └── github │ │ └── syari │ │ └── spigot │ │ └── api │ │ └── sample │ │ └── nms │ │ └── Main.kt ├── scheduler │ ├── README.md │ └── src │ │ └── main │ │ └── kotlin │ │ └── com │ │ └── github │ │ └── syari │ │ └── spigot │ │ └── api │ │ └── sample │ │ └── scheduler │ │ └── Main.kt ├── string │ ├── README.md │ └── src │ │ └── main │ │ └── kotlin │ │ └── com │ │ └── github │ │ └── syari │ │ └── spigot │ │ └── api │ │ └── sample │ │ └── string │ │ ├── Main.kt │ │ └── ToColorCommand.kt └── uuid │ ├── README.md │ └── src │ └── main │ └── kotlin │ └── com │ └── github │ └── syari │ └── spigot │ └── api │ └── sample │ └── uuid │ ├── Main.kt │ └── PlayerJoinChecker.kt └── settings.gradle.kts /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: gradle 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: "20:00" 8 | open-pull-requests-limit: 10 9 | -------------------------------------------------------------------------------- /.github/workflows/dokka.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | tags: 4 | - 'v*' 5 | jobs: 6 | build-and-deploy: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - name: Checkout 10 | uses: actions/checkout@v2 11 | with: 12 | persist-credentials: false 13 | - name: Setup Java 14 | uses: actions/setup-java@v1 15 | with: 16 | java-version: 1.8 17 | - name: Build dokkaHtml 18 | run: gradle dokkaHtml 19 | - name: Deploy To GitHub Pages 20 | uses: JamesIves/github-pages-deploy-action@releases/v4 21 | with: 22 | branch: gh-pages 23 | folder: api/build/dokka/html -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.gradle/ 2 | /.idea/ 3 | build -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EasySpigotAPI 2 | [![GitHub release (latest by date)](https://img.shields.io/github/v/release/sya-ri/EasySpigotAPI)](https://github.com/sya-ri/EasySpigotAPI/releases/latest) 3 | [![maven-central](https://img.shields.io/maven-central/v/com.github.sya-ri/EasySpigotAPI)](https://search.maven.org/artifact/com.github.sya-ri/EasySpigotAPI) 4 | [![ktlint](https://img.shields.io/badge/code%20style-%E2%9D%A4-FF4081.svg)](https://ktlint.github.io/) 5 | [![EasySpigotAPI](https://img.shields.io/badge/EasySpigotAPI-%E2%AC%85-4D4.svg)](https://github.com/sya-ri/EasySpigotAPI) 6 | 7 | A library for easy use of the Spigot API. 8 | 9 | ## サンプルコード 10 | 11 | 12 | ### [Command](sample/README.md#command) 13 | コマンドを簡単に作成することができます。 14 | 15 | #### Without EasySpigotAPI 16 | 17 | ```yaml 18 | # plugin.yml 19 | commands: 20 | teleport: 21 | # ... 22 | ``` 23 | 24 | ```kotlin 25 | override fun onEnable() { 26 | getCommand("teleport")?.setExecutor(TeleportCommand) 27 | } 28 | 29 | object TeleportCommand : CommandExecutor, TabExecutor { 30 | override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array): Boolean { 31 | // ... 32 | } 33 | 34 | override fun onTabComplete(sender: CommandSender, command: Command, alias: String, args: Array): MutableList { 35 | // ... 36 | } 37 | } 38 | ``` 39 | 40 | #### With EasySpigotAPI 41 | `plugin.yml` にコマンドを書く必要はありません。 42 | 43 | ```kotlin 44 | plugin.command("teleport") { 45 | // タブ補完の設定を行える 46 | tab { 47 | // 引数が何も入力されていない場合の補完候補 48 | argument { 49 | add("here") 50 | addAll(onlinePlayerNames) 51 | } 52 | 53 | // 最初の引数が here の場合の補完候補 54 | argument("here **") { 55 | addAll(onlinePlayerNames) 56 | } 57 | } 58 | 59 | // 実行時の処理を設定できる 60 | execute { 61 | // ... 62 | } 63 | } 64 | ``` 65 | 66 | ### [Component](sample/README.md#component) 67 | TextComponentを簡単に生成するための関数・クラスを追加します。 68 | 69 | ### [Config](sample/README.md#config) 70 | コンフィグを簡単に読み込むことができます。 71 | 72 | #### Without EasySpigotAPI 73 | 74 | ```kotlin 75 | val file = File(plugin.dataFolder, "config.yml") 76 | if (file.exists()) { 77 | val config = YamlConfiguration.loadConfiguration(file) 78 | val message = config.getString("message") 79 | // ... 80 | } 81 | 82 | // 複数ファイル 83 | File(plugin.dataFolder, "mobs").listFiles()?.forEach { file -> 84 | val config = YamlConfiguration.loadConfiguration(file) 85 | val id = config.getString("id", file.nameWithoutExtension) 86 | config.getConfigurationSection("attribute")?.getKeys(false)?.forEach { name -> 87 | val level = config.getInt("attribute.$name.level", 1) 88 | // ... 89 | } 90 | // ... 91 | } 92 | ``` 93 | 94 | #### With EasySpigotAPI 95 | ```kotlin 96 | plugin.config(sender, "config.yml") { 97 | val message = get("message", ConfigDataType.String) 98 | // ... 99 | } 100 | 101 | // 複数ファイル 102 | plugin.configDirectory(sender, "mobs") { 103 | val id = get("id", ConfigDataType.String, file.nameWithoutExtension) 104 | section("attribute")?.forEach { name -> 105 | val level = get("attribute.$name.level", ConfigDataType.Int, 1) 106 | // ... 107 | } 108 | // ... 109 | } 110 | ``` 111 | 112 | ### [Event](sample/README.md#event) 113 | イベント定義をラムダ式で書くことができます。 114 | 115 | #### Without EasySpigotAPI 116 | ```kotlin 117 | @EventHandler 118 | fun on(e: PlayerJoinEvent) { 119 | e.joinMessage = ">> Join ${e.player.displayName}" 120 | } 121 | ``` 122 | 123 | #### With EasySpigotAPI 124 | ```kotlin 125 | event { e -> 126 | e.joinMessage = ">> Join ${it.player.displayName}" 127 | } 128 | ``` 129 | 130 | ### [Inventory](sample/README.md#inventory) 131 | インベントリを簡単に扱うことができます。 132 | 133 | #### Without EasySpigotAPI 134 | ```kotlin 135 | val inventoryTitle = "Inventory Title" 136 | 137 | @EventHandler 138 | fun on(event: InventoryClickEvent) { 139 | if (event.inventory == event.clickedInventory && event.view.title == inventoryTitle) { 140 | when (event.slot) { 141 | 4 -> { 142 | val player = event.whoClicked as? Player ?: return 143 | player.playSound(player.location, Sound.ENTITY_PLAYER_LEVELUP, 1F, 1F) 144 | } 145 | 13 -> { 146 | when (event.type) { 147 | ClickType.LEFT -> { 148 | event.inventory.setItem(13, ItemStack(Material.BUCKET)) 149 | } 150 | ClickType.RIGHT -> { 151 | event.inventory.setItem(13, ItemStack(Material.WATER_BUCKET)) 152 | } 153 | } 154 | } 155 | } 156 | } 157 | } 158 | 159 | fun open(player: Player) { 160 | player.openInventory( 161 | Bukkit.createInventory(null, 36, inventoryTitle).apply { 162 | setItem(4, ItemStack(Material.PUFFERFISH).apply { 163 | itemMeta = itemMeta?.apply { 164 | setDisplayName("§6フグだょ") 165 | } 166 | }) 167 | setItem(13, ItemStack(Material.WATER_BUCKET)) 168 | } 169 | ) 170 | } 171 | ``` 172 | 173 | #### With EasySpigotAPI 174 | ```kotlin 175 | inventory("Inventory Title", 4) { 176 | item(4, Material.PUFFERFISH, "&6フグだょ") { 177 | onClick { 178 | player.playSound(Sound.ENTITY_PLAYER_LEVELUP) 179 | } 180 | } 181 | item(13, Material.WATER_BUCKET) { 182 | onClick(ClickType.LEFT) { 183 | item(13, Material.BUCKET) 184 | } 185 | onClick(ClickType.RIGHT) { 186 | item(13, Material.WATER_BUCKET) 187 | } 188 | } 189 | }.open(player) 190 | ``` 191 | 192 | ### [Item](sample/README.md#item) 193 | アイテム関連の便利な関数を追加します。 194 | 195 | ### [Message](sample/README.md#message) 196 | メッセージ関連の便利な関数を追加します。 197 | 198 | ### [NMS](sample/README.md#nms) 199 | NMSを使うための関数を追加します。 200 | 201 | ### [Particle](sample/README.md#particle) 202 | パーティクル関連の便利な関数を追加します。 203 | 204 | ### [Scheduler](sample/README.md#scheduler) 205 | スケジューラを簡単に使うことができます。 206 | 207 | #### Without EasySpigotAPI 208 | ```kotlin 209 | object : BukkitRunnable() { 210 | override fun run() { 211 | // ... 212 | } 213 | }.runTaskTimer(plugin, 0, 30 * 20) 214 | 215 | object : BukkitRunnable() { 216 | override fun run() { 217 | // ... 218 | } 219 | }.runTaskTimerAsynchronously(plugin, 0, 30 * 20) 220 | ``` 221 | 222 | #### With EasySpigotAPI 223 | ```kotlin 224 | plugin.runTaskTimer(30 * 20) { 225 | // ... 226 | } 227 | 228 | plugin.runTaskTimer(30 * 20, async = true) { 229 | // ... 230 | } 231 | ``` 232 | 233 | ### [Sound](sample/README.md#sound) 234 | 音関連の便利な関数を追加します。 235 | 236 | ### [String](sample/README.md#string) 237 | 文字列関連の便利な関数を追加します。 238 | 239 | ### [UUID](sample/README.md#uuid) 240 | UUIDの便利な関数・クラスを追加します。 241 | 242 | ### [World](sample/README.md#world) 243 | ワールド関連の便利なクラスを追加します。 244 | 245 | ### その他 246 | - [Plugin Using EasySpigotAPI](sample/README.md#plugin-using-easyspigotapi) 247 | 248 | ## テンプレートプロジェクト 249 | 250 | [![Spigot](https://github-readme-stats.vercel.app/api/pin/?username=sya-ri&repo=SpigotPluginTemplate)](https://github.com/sya-ri/SpigotPluginTemplate) 251 | [![Paper](https://github-readme-stats.vercel.app/api/pin/?username=sya-ri&repo=PaperPluginTemplate)](https://github.com/sya-ri/PaperPluginTemplate) 252 | [![Purpur](https://github-readme-stats.vercel.app/api/pin/?username=sya-ri&repo=PurpurPluginTemplate)](https://github.com/sya-ri/PurpurPluginTemplate) 253 | [![Yatopia](https://github-readme-stats.vercel.app/api/pin/?username=sya-ri&repo=YatopiaPluginTemplate)](https://github.com/sya-ri/YatopiaPluginTemplate) 254 | 255 | ## 導入 256 | 257 | ### EasySpigotAPI をプラグインとして導入する 258 | EasySpigotAPI を導入したプラグインに加えて EasySpigotAPI もサーバーのプラグインに追加する必要があります。 259 | 260 | #### build.gradle 261 | 262 | ```groovy 263 | repositories { 264 | mavenCentral() 265 | } 266 | 267 | dependencies { 268 | api('com.github.sya-ri:EasySpigotAPI:2.3.2') { 269 | exclude group: 'org.spigotmc', module: 'spigot-api' 270 | } 271 | } 272 | ``` 273 | 274 | #### build.gradle.kts 275 | 276 | ```kotlin 277 | repositories { 278 | mavenCentral() 279 | } 280 | 281 | dependencies { 282 | api("com.github.sya-ri:EasySpigotAPI:2.3.2") { 283 | exclude(group = "org.spigotmc", module = "spigot-api") 284 | } 285 | } 286 | ``` 287 | 288 | ### 一つのプラグインの中に EasySpigotAPI もまとめる 289 | EasySpigotAPI を導入したプラグインの中に必要なものが同梱され、EasySpigotAPI を別で導入する必要がありません。 290 | 291 | #### build.gradle 292 | 293 | ```groovy 294 | plugins { 295 | id 'com.github.johnrengelman.shadow' version '6.1.0' 296 | } 297 | 298 | repositories { 299 | mavenCentral() 300 | } 301 | 302 | configurations { 303 | shadowApi 304 | api.extendsFrom shadowApi 305 | } 306 | 307 | dependencies { 308 | shadowApi('com.github.sya-ri:EasySpigotAPI:2.3.2') { 309 | exclude group: 'org.spigotmc', module: 'spigot-api' 310 | } 311 | } 312 | 313 | shadowJar { 314 | configurations = [project.configurations.shadowApi] 315 | } 316 | ``` 317 | 318 | #### build.gradle.kts 319 | 320 | ```kotlin 321 | plugins { 322 | id("com.github.johnrengelman.shadow") version "6.1.0" 323 | } 324 | 325 | val shadowApi by configurations.creating 326 | configurations["api"].extendsFrom(shadowApi) 327 | 328 | repositories { 329 | mavenCentral() 330 | } 331 | 332 | dependencies { 333 | shadowApi("com.github.sya-ri:EasySpigotAPI:2.3.2") { 334 | exclude(group = "org.spigotmc", module = "spigot-api") 335 | } 336 | } 337 | 338 | tasks.withType { 339 | configurations = listOf(shadowApi) 340 | } 341 | ``` 342 | 343 | ## バッジ 344 | [![EasySpigotAPI](https://img.shields.io/badge/EasySpigotAPI-%E2%AC%85-4D4.svg)](https://github.com/sya-ri/EasySpigotAPI) 345 | 346 | ``` 347 | [![EasySpigotAPI](https://img.shields.io/badge/EasySpigotAPI-%E2%AC%85-4D4.svg)](https://github.com/sya-ri/EasySpigotAPI) 348 | ``` 349 | -------------------------------------------------------------------------------- /api/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar 2 | import org.jetbrains.dokka.gradle.DokkaTask 3 | 4 | plugins { 5 | id("org.jetbrains.dokka") version "1.5.0" 6 | `maven-publish` 7 | signing 8 | } 9 | 10 | group = "com.github.sya-ri.spigot.api" 11 | version = "2.5.0-SNAPSHOT" 12 | 13 | bukkit { 14 | name = "EasySpigotAPI" 15 | version = project.version.toString() 16 | description = "A library for easy use of the Spigot API." 17 | main = "com.github.syari.spigot.api.EasySpigotAPI" 18 | author = "sya_ri" 19 | website = "https://github.com/sya-ri/EasySpigotAPI" 20 | apiVersion = "1.13" 21 | } 22 | 23 | tasks.withType { 24 | archiveBaseName.set("EasySpigotAPI") 25 | } 26 | 27 | val sourceJar by tasks.registering(Jar::class) { 28 | archiveClassifier.set("sources") 29 | from(sourceSets["main"].allSource) 30 | } 31 | 32 | tasks.withType().configureEach { 33 | dokkaSourceSets { 34 | named("main") { 35 | moduleName.set("EasySpigotAPI") 36 | } 37 | } 38 | } 39 | 40 | publishing { 41 | repositories { 42 | maven { 43 | url = uri( 44 | if (version.toString().endsWith("SNAPSHOT")) { 45 | "https://oss.sonatype.org/content/repositories/snapshots" 46 | } else { 47 | "https://oss.sonatype.org/service/local/staging/deploy/maven2" 48 | } 49 | ) 50 | credentials { 51 | username = System.getenv("SONATYPE_USER") 52 | password = System.getenv("SONATYPE_PASSWORD") 53 | } 54 | } 55 | } 56 | publications { 57 | register("maven") { 58 | groupId = "com.github.sya-ri" 59 | artifactId = "EasySpigotAPI" 60 | from(components["kotlin"]) 61 | artifact(sourceJar.get()) 62 | pom { 63 | packaging = "pom" 64 | name.set("EasySpigotAPI") 65 | description.set("A library for easy use of the Spigot API.") 66 | url.set("https://github.com/sya-ri/EasySpigotAPI") 67 | licenses { 68 | license { 69 | name.set("Eclipse Public License 2.0") 70 | url.set("https://www.eclipse.org/legal/epl-2.0/") 71 | } 72 | } 73 | developers { 74 | developer { 75 | id.set("sya-ri") 76 | name.set("sya-ri") 77 | email.set("sya79lua@gmail.com") 78 | } 79 | } 80 | scm { 81 | url.set("https://github.com/sya-ri/EasySpigotAPI.git") 82 | } 83 | } 84 | } 85 | } 86 | } 87 | 88 | signing { 89 | sign(publishing.publications["maven"]) 90 | } 91 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/EasySpigotAPI.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api 2 | 3 | import org.bukkit.plugin.java.JavaPlugin 4 | import java.util.logging.Logger 5 | 6 | /** 7 | * メインクラス。 8 | * @since 1.0.0 9 | */ 10 | @Suppress("unused") 11 | class EasySpigotAPI : JavaPlugin() { 12 | companion object { 13 | /** 14 | * 内部で使用するロガー 15 | * @since 2.3.0 16 | */ 17 | internal val logger = Logger.getLogger("EasySpigotAPI(Internal)") 18 | } 19 | 20 | override fun onEnable() { 21 | EasySpigotAPIOption.useCustomInventory(this) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/EasySpigotAPIOption.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api 2 | 3 | import com.github.syari.spigot.api.inventory.CustomInventory 4 | import org.bukkit.plugin.java.JavaPlugin 5 | 6 | /** 7 | * EasySpigotAPI の設定 8 | * @since 2.3.3 9 | */ 10 | object EasySpigotAPIOption { 11 | /** 12 | * [CustomInventory] が有効化されているか取得します 13 | * @since 2.3.3 14 | */ 15 | internal var isEnableCustomInventory = false 16 | private set 17 | 18 | /** 19 | * [CustomInventory] を使用します。 20 | * @param plugin イベント呼び出しに使うプラグイン 21 | * @since 2.3.3 22 | */ 23 | fun useCustomInventory(plugin: JavaPlugin) { 24 | if (isEnableCustomInventory) return 25 | isEnableCustomInventory = true 26 | EasySpigotAPI.logger.info("CustomInventory is now available") 27 | CustomInventory.onEnableInternal(plugin) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/UnsupportedMinecraftVersion.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api 2 | 3 | /** 4 | * 非対応のマインクラフトバージョンを羅列する。非対応の場合に使用しても [NoSuchMethodError] 等の例外が投げられてしまう。 5 | * @since 2.2.0 6 | */ 7 | annotation class UnsupportedMinecraftVersion(vararg val version: Int) 8 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/command/CommandArgument.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.command 2 | 3 | /** 4 | * コマンドの引数。 5 | * @param array 実際の引数 6 | * @since 1.2.0 7 | */ 8 | class CommandArgument( 9 | private val array: List 10 | ) : List by array { 11 | /** 12 | * 小文字・大文字を区別せずに引数の判定を行える。以下の処理を実行しているだけだが、使うことが多いので定義されている。 13 | * ``` 14 | * getOrNull(index)?.toLowerCase() 15 | * ``` 16 | * @param index 取得する位置 17 | * @return 取得出来た場合は小文字、出来なかった場合は null 18 | * @since 1.2.0 19 | */ 20 | fun lowerOrNull(index: Int) = getOrNull(index)?.lowercase() 21 | } 22 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/command/CommandCreator.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.command 2 | 3 | import com.github.syari.spigot.api.command.execute.CommandExecuteParameter 4 | import com.github.syari.spigot.api.command.tab.CommandTab 5 | import org.bukkit.command.Command 6 | import org.bukkit.command.CommandSender 7 | 8 | /** 9 | * コマンドの設定を行うクラス。 10 | * @param label コマンド名 11 | * @since 1.2.0 12 | */ 13 | class CommandCreator(val label: String) { 14 | /** 15 | * コマンドの説明文。 16 | * @since 1.2.0 17 | */ 18 | var description = "" 19 | 20 | /** 21 | * コマンドの使い方。 22 | * @since 1.2.0 23 | */ 24 | var usageMessage = "/" 25 | 26 | /** 27 | * コマンドの別名。 28 | * @since 1.2.0 29 | */ 30 | var aliases = listOf() 31 | 32 | /** 33 | * コマンドの実行権限。 34 | * @since 1.3.4 35 | */ 36 | var permission: String? = null 37 | 38 | /** 39 | * 実行権限がない場合のメッセージ。 40 | * @since 1.3.4 41 | */ 42 | var permissionMessage: String? = null 43 | 44 | private val tabContainer = CommandTab.Container() 45 | private var executeAction: CommandExecuteAction = {} 46 | 47 | /** 48 | * タブ補完の処理を設定する。 49 | * @param action タブ補完した時の処理 50 | * @since 1.2.0 51 | */ 52 | fun tab(action: CommandTabAction) { 53 | tabContainer.action() 54 | } 55 | 56 | /** 57 | * コマンド実行の処理を設定する。 58 | * @param action コマンドを実行した時の処理 59 | * @since 1.2.0 60 | */ 61 | fun execute(action: CommandExecuteAction) { 62 | executeAction = action 63 | } 64 | 65 | /** 66 | * 設定から [Command] のインスタンスを生成する。 67 | * @return [Command] のインスタンス 68 | * @since 1.2.0 69 | */ 70 | fun create(): Command { 71 | return object : Command(label, description, usageMessage, aliases) { 72 | init { 73 | permission = this@CommandCreator.permission 74 | permissionMessage = this@CommandCreator.permissionMessage 75 | } 76 | 77 | override fun execute( 78 | sender: CommandSender, 79 | commandLabel: String, 80 | args: Array 81 | ): Boolean { 82 | if (testPermission(sender)) { 83 | executeAction(CommandExecuteParameter(sender, commandLabel, CommandArgument(args.toList()))) 84 | } 85 | return true 86 | } 87 | 88 | override fun tabComplete( 89 | sender: CommandSender, 90 | alias: String, 91 | args: Array 92 | ): List { 93 | return tabContainer.get(sender, args) 94 | } 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/command/execute/CommandExecuteParameter.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.command.execute 2 | 3 | import com.github.syari.spigot.api.command.CommandArgument 4 | import org.bukkit.command.CommandSender 5 | 6 | /** 7 | * コマンド実行の処理で使用するクラス。 8 | * @param sender コマンド実行者 9 | * @param label コマンド名 10 | * @param args コマンドの引数 11 | * @since 2.3.3 12 | */ 13 | class CommandExecuteParameter(val sender: CommandSender, val label: String, val args: CommandArgument) 14 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/command/extension.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.command 2 | 3 | import com.github.syari.spigot.api.command.execute.CommandExecuteParameter 4 | import com.github.syari.spigot.api.command.tab.CommandTab 5 | import org.bukkit.command.Command 6 | import org.bukkit.command.CommandMap 7 | import org.bukkit.plugin.java.JavaPlugin 8 | 9 | /** 10 | * `CommandCreator.() -> Unit` 11 | * @since 2.3.3 12 | */ 13 | typealias CommandCreateAction = CommandCreator.() -> Unit 14 | 15 | /** 16 | * `CommandTab.Container.() -> Unit` 17 | * @since 2.3.3 18 | */ 19 | typealias CommandTabAction = CommandTab.Container.() -> Unit 20 | 21 | /** 22 | * `CommandTab.Element.() -> Unit` 23 | * @since 2.3.3 24 | */ 25 | typealias CommandTabCompleteAction = CommandTab.Element.() -> Unit 26 | 27 | /** 28 | * `CommandExecuteParameter.() -> Unit` 29 | * @since 2.3.3 30 | */ 31 | typealias CommandExecuteAction = CommandExecuteParameter.() -> Unit 32 | 33 | /** 34 | * コマンドを作成し、登録する。 35 | * @param label コマンド名 /label 36 | * @param action [CommandCreator] コマンドの設定を行う 37 | * @since 1.2.0 38 | */ 39 | fun JavaPlugin.command(label: String, action: CommandCreateAction) { 40 | registerCommand(this, CommandCreator(label).apply(action).create()) 41 | } 42 | 43 | /** 44 | * コマンド登録の処理を行う。 45 | * @param plugin 登録するプラグイン 46 | * @param command 登録するコマンド 47 | * @since 1.2.0 48 | */ 49 | private fun registerCommand(plugin: JavaPlugin, command: Command) { 50 | try { 51 | val commandMapField = plugin.server.javaClass.getDeclaredField("commandMap") 52 | commandMapField.isAccessible = true 53 | val commandMap = commandMapField.get(plugin.server) as CommandMap 54 | commandMap.register(plugin.name, command) 55 | commandMapField.isAccessible = false 56 | } catch (ex: Exception) { 57 | ex.printStackTrace() 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/command/tab/CommandTab.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.command.tab 2 | 3 | import com.github.syari.spigot.api.command.CommandArgument 4 | import org.bukkit.command.CommandSender 5 | 6 | /** 7 | * コマンド補完の処理を行う基底クラス。 8 | * @since 1.2.0 9 | */ 10 | interface CommandTab { 11 | /** 12 | * コマンド補完の内容を決定する。 13 | * @param sender タブ補完者 14 | * @param args 入力済みの引数 15 | * @return 補完結果 16 | * @since 1.2.0 17 | */ 18 | fun complete(sender: CommandSender, args: Array): Iterable 19 | 20 | /** 21 | * 補完の内容を保持する。 22 | * @param sender タブ補完者 23 | * @param args 入力済みの引数 24 | * @since 1.2.0 25 | */ 26 | class Element(val sender: CommandSender, val args: CommandArgument) : LinkedHashSet() { 27 | /** 28 | * 補完候補をまとめて追加する。 29 | * @param value 候補 30 | * @return 追加されたかどうか 31 | * @since 1.5.1 32 | */ 33 | fun addAll(vararg value: String) = addAll(value) 34 | } 35 | 36 | /** 37 | * コマンド補完クラスを格納するクラス。 38 | * @since 1.2.0 39 | */ 40 | class Container { 41 | private val tabList = mutableSetOf() 42 | 43 | /** 44 | * コマンド補完クラスを追加する。 45 | * @param commandTab 補完クラス 46 | * @since 1.2.0 47 | */ 48 | fun add(commandTab: CommandTab) { 49 | tabList.add(commandTab) 50 | } 51 | 52 | /** 53 | * コマンド補完を行う。 54 | * @param sender 補完者 55 | * @param args 入力済みの引数 56 | * @return 補完結果 57 | * @since 1.2.0 58 | */ 59 | internal fun get(sender: CommandSender, args: Array): List { 60 | return tabList.flatMap { it.complete(sender, args) }.sorted() 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/command/tab/CommandTabArgument.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.command.tab 2 | 3 | import com.github.syari.spigot.api.command.CommandArgument 4 | import com.github.syari.spigot.api.command.CommandTabCompleteAction 5 | import org.bukkit.command.CommandSender 6 | 7 | /** 8 | * 入力済みの引数のみで補完内容を決める。 9 | * @param requires 入力済み引数の中で一致したものが存在していた場合 [action] を実行する。`*` や `**` といったワイルドカードを利用できる。 10 | * @param action 補完する内容を決める処理 11 | * @see argument 12 | * @since 1.2.0 13 | */ 14 | class CommandTabArgument internal constructor( 15 | private val requires: List, 16 | private val action: CommandTabCompleteAction 17 | ) : CommandTab { 18 | companion object { 19 | /** 20 | * 入力済みの引数のみで補完内容を決める。 21 | * @param require 入力済み引数の中で一致したものが存在していた場合 [action] を実行する。`*` や `**` といったワイルドカードを利用できる。 22 | * @param action 補完する内容を決める処理 23 | * @see argument 24 | * @since 1.2.0 25 | */ 26 | fun CommandTab.Container.argument( 27 | vararg require: String, 28 | action: CommandTabCompleteAction 29 | ) { 30 | add(CommandTabArgument(require.toList(), action)) 31 | } 32 | } 33 | 34 | /** 35 | * コマンド補完の内容を決定する。 36 | * @param sender タブ補完者 37 | * @param args 入力済みの引数 38 | * @return 補完結果 39 | * @since 1.2.0 40 | */ 41 | override fun complete( 42 | sender: CommandSender, 43 | args: Array 44 | ): Iterable { 45 | val element = CommandTab.Element(sender, CommandArgument(args.toList())).apply(action) 46 | 47 | fun complete(line: String, transform: (String) -> String = { it }): Iterable { 48 | return element.filter { 49 | transform(it).lowercase().startsWith(line) 50 | } 51 | } 52 | 53 | return when { 54 | requires.isNotEmpty() -> requires.flatMap { _require -> 55 | val requireSplit = _require.split("\\s+".toRegex()).toMutableList() 56 | val isDoubleWildcard = requireSplit.size <= args.size && requireSplit.last() == "**" 57 | when { 58 | isDoubleWildcard || requireSplit.size == args.lastIndex -> { 59 | val require = if (_require.contains('*')) { 60 | buildString { 61 | if (isDoubleWildcard) { 62 | requireSplit.removeLast() 63 | } 64 | requireSplit.forEachIndexed { index, it -> 65 | append(if (it == "*") args[index] else it) 66 | append(" ") 67 | } 68 | }.substringBeforeLast(" ") 69 | } else { 70 | _require 71 | } 72 | val argsJoin = args.joinToString(" ").lowercase() 73 | when { 74 | isDoubleWildcard.not() -> complete(argsJoin) { "$require $it" } 75 | argsJoin.startsWith(require) -> complete(args.last().lowercase()) 76 | else -> listOf() 77 | } 78 | } 79 | else -> listOf() 80 | } 81 | } 82 | args.size == 1 -> complete(args[0].lowercase()) 83 | else -> listOf() 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/component/TextComponentBuilder.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.component 2 | 3 | import net.md_5.bungee.api.chat.BaseComponent 4 | import net.md_5.bungee.api.chat.ClickEvent 5 | import net.md_5.bungee.api.chat.HoverEvent 6 | import net.md_5.bungee.api.chat.TextComponent 7 | 8 | /** 9 | * [TextComponent] のビルダークラス 10 | * @since 1.6.0 11 | */ 12 | class TextComponentBuilder { 13 | private val components = mutableListOf() 14 | 15 | /** 16 | * 末尾に文字列を挿入する。 17 | * @param text 文字列 18 | * @param hover ホバーイベント 19 | * @param click クリックイベント 20 | * @return [TextComponentBuilder] 21 | * @since 1.6.0 22 | */ 23 | fun append( 24 | text: String, 25 | hover: HoverEvent? = null, 26 | click: ClickEvent? = null 27 | ) = append(textComponent(text, hover, click)) 28 | 29 | /** 30 | * 末尾に [BaseComponent] を挿入する。 31 | * @param component 32 | * @return [TextComponentBuilder] 33 | * @since 2.2.3 34 | */ 35 | fun append(component: BaseComponent) = apply { 36 | components.add(component) 37 | } 38 | 39 | /** 40 | * 末尾に改行を挿入する。 41 | * @return [TextComponentBuilder] 42 | * @since 1.6.0 43 | */ 44 | fun appendLine() = append(NewLine) 45 | 46 | /** 47 | * 末尾に文字列を挿入し、改行する。 48 | * @param text 文字列 49 | * @param hover ホバーイベント 50 | * @param click クリックイベント 51 | * @return [TextComponentBuilder] 52 | * @since 1.6.0 53 | */ 54 | fun appendLine( 55 | text: String, 56 | hover: HoverEvent? = null, 57 | click: ClickEvent? = null 58 | ) = append(text, hover, click).appendLine() 59 | 60 | /** 61 | * 末尾に [BaseComponent] を挿入し、改行する。 62 | * @param component 63 | * @return [TextComponentBuilder] 64 | * @since 2.2.3 65 | */ 66 | fun appendLine(component: BaseComponent) = append(component).appendLine() 67 | 68 | /** 69 | * [TextComponent] に変換する。 70 | * @return [TextComponent] 71 | * @since 1.6.0 72 | */ 73 | fun build() = TextComponent().apply { 74 | components.forEach(::addExtra) 75 | } 76 | 77 | companion object { 78 | /** 79 | * 改行のための [TextComponent] 80 | * @since 2.2.3 81 | */ 82 | val NewLine = TextComponent("\n") 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/component/extension.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.component 2 | 3 | import com.github.syari.spigot.api.UnsupportedMinecraftVersion 4 | import com.github.syari.spigot.api.item.nbtTag 5 | import com.github.syari.spigot.api.string.toColor 6 | import net.md_5.bungee.api.chat.BaseComponent 7 | import net.md_5.bungee.api.chat.ClickEvent 8 | import net.md_5.bungee.api.chat.HoverEvent 9 | import net.md_5.bungee.api.chat.ItemTag 10 | import net.md_5.bungee.api.chat.KeybindComponent 11 | import net.md_5.bungee.api.chat.TextComponent 12 | import net.md_5.bungee.api.chat.TranslatableComponent 13 | import net.md_5.bungee.api.chat.hover.content.Item 14 | import net.md_5.bungee.api.chat.hover.content.Text 15 | import org.bukkit.Material 16 | import org.bukkit.command.CommandSender 17 | import org.bukkit.inventory.ItemStack 18 | 19 | /** 20 | * [org.bukkit.ChatColor] と混同しないようにするためのエイリアス 21 | * @see net.md_5.bungee.api.ChatColor 22 | * @since 2.2.4 23 | */ 24 | typealias BungeeChatColor = net.md_5.bungee.api.ChatColor 25 | 26 | /** 27 | * `TextComponentBuilder.() -> Unit` 28 | * @since 2.3.3 29 | */ 30 | typealias TextComponentBuildAction = TextComponentBuilder.() -> Unit 31 | 32 | /** 33 | * [TextComponent] を生成する。 34 | * @see TextComponentBuilder 35 | * @param action [TextComponentBuilder] に対して実行する処理 36 | * @return [TextComponent] 37 | * @since 1.6.0 38 | */ 39 | inline fun buildTextComponent(action: TextComponentBuildAction) = TextComponentBuilder().apply(action).build() 40 | 41 | /** 42 | * [BaseComponent] のチャットメッセージを送信する 43 | * @param message 送信するメッセージ 44 | * @see CommandSender.Spigot.sendMessage 45 | * @since 2.3.5 46 | */ 47 | fun CommandSender.sendComponentMessage(message: BaseComponent) { 48 | spigot().sendMessage(message) 49 | } 50 | 51 | /** 52 | * [BaseComponent] のチャットメッセージを送信する 53 | * @param builder TextComponent を操作する処理 54 | * @see CommandSender.Spigot.sendMessage 55 | * @since 2.3.5 56 | */ 57 | inline fun CommandSender.sendComponentMessage(builder: TextComponentBuildAction) { 58 | sendComponentMessage(buildTextComponent(builder)) 59 | } 60 | 61 | /** 62 | * [BaseComponent] の hoverEvent, clickEvent を設定する。 63 | * @param hover [HoverEvent] default: null 64 | * @param click [ClickEvent] default: null 65 | * @return [TextComponentBuilder] 66 | * @since 2.2.3 67 | */ 68 | fun T.with( 69 | hover: HoverEvent? = null, 70 | click: ClickEvent? = null, 71 | ) = apply { 72 | hoverEvent = hover 73 | clickEvent = click 74 | } 75 | 76 | /** 77 | * フォーマットを変更する。 78 | * @param color 文字色 79 | * @param bold 太字 80 | * @param italic 斜体 81 | * @param underline 下線 82 | * @param strike 取り消し線 83 | * @param obfuscate 難読化 84 | * @return [T] 85 | * @since 2.2.4 86 | */ 87 | fun T.with( 88 | color: BungeeChatColor? = getColor(), 89 | bold: Boolean = isBold, 90 | italic: Boolean = isItalic, 91 | underline: Boolean = isUnderlined, 92 | strike: Boolean = isStrikethrough, 93 | obfuscate: Boolean = isObfuscated, 94 | ) = apply { 95 | setColor(color) 96 | isBold = bold 97 | isItalic = italic 98 | isUnderlined = underline 99 | isStrikethrough = strike 100 | isObfuscated = obfuscate 101 | } 102 | 103 | /** 104 | * 文字列とイベントから [TextComponent] を生成する。 105 | * @param text 文字列 106 | * @param hover [HoverEvent] default: null 107 | * @param click [ClickEvent] default: null 108 | * @return [TextComponent] 109 | * @since 2.2.2 110 | */ 111 | fun textComponent( 112 | text: String, 113 | hover: HoverEvent? = null, 114 | click: ClickEvent? = null, 115 | ) = TextComponent(text.toColor()).with(hover, click) 116 | 117 | /** 118 | * 翻訳キーとイベントから [TranslatableComponent] を生成する。 119 | * @param translate 翻訳キー 120 | * @param hover [HoverEvent] default: null 121 | * @param click [ClickEvent] default: null 122 | * @return [TranslatableComponent] 123 | * @since 2.2.3 124 | */ 125 | fun translateComponent( 126 | translate: String, 127 | hover: HoverEvent? = null, 128 | click: ClickEvent? = null, 129 | ) = TranslatableComponent(translate).with(hover, click) 130 | 131 | /** 132 | * [Material] とイベントから [TranslatableComponent] を生成する。 133 | * @param material 翻訳するアイテム 134 | * @param hover [HoverEvent] default: null 135 | * @param click [ClickEvent] default: null 136 | * @return [TranslatableComponent] 137 | * @since 2.2.3 138 | */ 139 | @UnsupportedMinecraftVersion(8, 9, 10, 11, 12) 140 | fun translateComponent( 141 | material: Material, 142 | hover: HoverEvent? = null, 143 | click: ClickEvent? = null, 144 | ) = translateComponent((if (material.isBlock) "block" else "item") + ".minecraft." + material.key.key, hover, click) 145 | 146 | /** 147 | * キーバインド識別子とイベントから [KeybindComponent] を生成する。 148 | * @param identifier 識別子 [net.md_5.bungee.api.chat.Keybinds] 149 | * @param hover [HoverEvent] default: null 150 | * @param click [ClickEvent] default: null 151 | * @return [KeybindComponent] 152 | * @since 2.2.3 153 | */ 154 | @UnsupportedMinecraftVersion(8, 9, 10, 11) 155 | fun keybindComponent( 156 | identifier: String, 157 | hover: HoverEvent? = null, 158 | click: ClickEvent? = null, 159 | ) = KeybindComponent(identifier).with(hover, click) 160 | 161 | /** 162 | * クリックした時にコマンドを実行する。 163 | * @param command 実行するコマンド 164 | * @return [ClickEvent.Action.RUN_COMMAND] の [ClickEvent] 165 | * @since 1.6.0 166 | */ 167 | fun clickRunCommand(command: String) = ClickEvent(ClickEvent.Action.RUN_COMMAND, command) 168 | 169 | /** 170 | * クリックした時に文字列を自動入力する。 171 | * @param text 自動入力する文字列 172 | * @return [ClickEvent.Action.SUGGEST_COMMAND] の [ClickEvent] 173 | * @since 1.6.0 174 | */ 175 | fun clickTypeText(text: String) = ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, text) 176 | 177 | /** 178 | * クリックした時にURLを開く。 179 | * @param url 開くURL 180 | * @return [ClickEvent.Action.OPEN_URL] の [ClickEvent] 181 | * @since 1.6.0 182 | */ 183 | fun clickOpenURL(url: String) = ClickEvent(ClickEvent.Action.OPEN_URL, url) 184 | 185 | /** 186 | * クリックした時にクリップボードに文字列をコピーする。 187 | * @param text コピーする文字列 188 | * @return [ClickEvent.Action.COPY_TO_CLIPBOARD] の [ClickEvent] 189 | * @since 1.6.0 190 | */ 191 | @UnsupportedMinecraftVersion(8, 9, 10, 11, 12, 13, 14) 192 | fun clickCopyToClipboard(text: String) = ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, text) 193 | 194 | /** 195 | * ホバーした時に文字列を表示する。 196 | * @param text 表示する文字列 197 | * @return [HoverEvent.Action.SHOW_TEXT] の [HoverEvent] 198 | * @since 1.6.0 199 | */ 200 | @UnsupportedMinecraftVersion(8, 9, 10, 11, 12, 13, 14, 15) 201 | fun hoverText(text: String) = HoverEvent(HoverEvent.Action.SHOW_TEXT, Text(text.toColor())) 202 | 203 | /** 204 | * ホバーした時に文字列を表示する。 205 | * @param text 表示する文字列 206 | * @return [HoverEvent.Action.SHOW_TEXT] の [HoverEvent] 207 | * @since 2.3.5 208 | */ 209 | @Suppress("DEPRECATION") 210 | fun hoverTextLegacy(text: String) = HoverEvent(HoverEvent.Action.SHOW_TEXT, arrayOf(TextComponent(text.toColor()))) 211 | 212 | /** 213 | * ホバーした時にアイテムを表示する。 214 | * @param itemStack 表示するアイテム 215 | * @return [HoverEvent.Action.SHOW_ITEM] の [HoverEvent] 216 | * @since 1.8.0 217 | */ 218 | @UnsupportedMinecraftVersion(8, 9, 10, 11, 12, 13, 14, 15) 219 | fun hoverItem(itemStack: ItemStack) = HoverEvent(HoverEvent.Action.SHOW_ITEM, Item(itemStack.type.key.key, 1, ItemTag.ofNbt(itemStack.nbtTag))) 220 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/converter/ConfigItemConverter.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.converter 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import org.bukkit.inventory.ItemStack 5 | 6 | /** 7 | * [String] と [ItemStack] の変換を行う。 8 | * @since 1.7.0 9 | */ 10 | interface ConfigItemConverter { 11 | /** 12 | * [String] を [ItemStack] に変換する。 13 | * @param config 文字列の取得に使ったコンフィグ 14 | * @param path 文字列の取得に使ったパス 15 | * @param line 変換する文字列 16 | * @return 変換後のアイテム 17 | * @since 1.7.0 18 | */ 19 | fun stringToItem(config: CustomConfig, path: String, line: String): ItemStack? 20 | 21 | /** 22 | * [ItemStack] を [String] に変換する。 23 | * @param itemStack 変換するアイテム 24 | * @return 変換後の文字列 25 | * @since 1.7.0 26 | */ 27 | fun itemToString(itemStack: ItemStack): String? 28 | } 29 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/def/DefaultConfig.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.def 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | 5 | /** 6 | * デフォルト設定 7 | * @since 1.7.0 8 | */ 9 | interface DefaultConfig { 10 | /** 11 | * デフォルト設定を適用する。 12 | * @param config 適用するコンフィグ 13 | * @since 1.7.0 14 | */ 15 | fun set(config: CustomConfig) 16 | } 17 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/def/DefaultConfigAction.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.def 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import com.github.syari.spigot.api.config.CustomConfigAction 5 | 6 | /** 7 | * デフォルト設定として [CustomConfig] に対して処理を実行する。 8 | * @param action 実行する処理 9 | * @since 1.7.0 10 | */ 11 | class DefaultConfigAction(val action: CustomConfigAction) : DefaultConfig { 12 | /** 13 | * デフォルト設定を適用する。 14 | * @param config 適用するコンフィグ 15 | * @since 1.7.0 16 | */ 17 | override fun set(config: CustomConfig) { 18 | config.apply(action).save() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/def/DefaultConfigFile.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.def 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import java.io.File 5 | 6 | /** 7 | * デフォルト設定として別のファイルを [CustomConfig] にコピーする。 8 | * @param file コピー元のファイル 9 | * @since 2.2.1 10 | */ 11 | class DefaultConfigFile(val file: File) : DefaultConfig { 12 | /** 13 | * デフォルト設定を適用する。 14 | * @param config 適用するコンフィグ 15 | * @since 2.2.1 16 | */ 17 | override fun set(config: CustomConfig) { 18 | file.inputStream().let(::DefaultConfigStream).set(config) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/def/DefaultConfigMap.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("DEPRECATION") 2 | 3 | package com.github.syari.spigot.api.config.def 4 | 5 | import com.github.syari.spigot.api.config.CustomConfig 6 | 7 | /** 8 | * デフォルト設定としてパスと値のマップを利用する。 9 | * @param map パスと値 10 | * @since 1.7.0 11 | */ 12 | class DefaultConfigMap(val map: Map) : DefaultConfig { 13 | /** 14 | * デフォルト設定を適用する。 15 | * @param config 適用するコンフィグ 16 | * @since 1.7.0 17 | */ 18 | override fun set(config: CustomConfig) { 19 | if (map.isEmpty()) { 20 | map.forEach { (key, value) -> 21 | config.setUnsafe(key, value) 22 | } 23 | config.save() 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/def/DefaultConfigResource.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.def 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import org.bukkit.plugin.java.JavaPlugin 5 | 6 | /** 7 | * デフォルト設定としてリソースファイルを [CustomConfig] にコピーする。 8 | * @param plugin 参照するリソースファイルが存在するプラグイン 9 | * @param fileName リソースファイルのパス 10 | * @since 2.2.1 11 | */ 12 | class DefaultConfigResource(val plugin: JavaPlugin, val fileName: String) : DefaultConfig { 13 | /** 14 | * デフォルト設定を適用する。 15 | * @param config 適用するコンフィグ 16 | * @since 2.2.1 17 | */ 18 | override fun set(config: CustomConfig) { 19 | plugin.getResource(fileName)?.let(::DefaultConfigStream)?.set(config) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/def/DefaultConfigStream.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.def 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import java.io.InputStream 5 | 6 | /** 7 | * デフォルト設定としてストリームを [CustomConfig] にコピーする。 8 | * @since 2.2.1 9 | */ 10 | class DefaultConfigStream(val inputStream: InputStream) : DefaultConfig { 11 | /** 12 | * デフォルト設定を適用する。 13 | * @param config 適用するコンフィグ 14 | * @since 2.2.1 15 | */ 16 | override fun set(config: CustomConfig) { 17 | inputStream.use { input -> 18 | config.file.outputStream().use { output -> 19 | input.copyTo(output) 20 | output.flush() 21 | } 22 | } 23 | config.reload() 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/extension.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config 2 | 3 | import com.github.syari.spigot.api.config.def.DefaultConfig 4 | import org.bukkit.command.CommandSender 5 | import org.bukkit.plugin.java.JavaPlugin 6 | import java.io.File 7 | 8 | /** 9 | * `CustomConfig.() -> Unit` 10 | * @since 2.3.3 11 | */ 12 | typealias CustomConfigAction = CustomConfig.() -> Unit 13 | 14 | /** 15 | * コンフィグをロードする。 16 | * @param output メッセージの出力先 17 | * @param file ファイル 18 | * @param default デフォルト設定 19 | * @return コンフィグ 20 | * @since 2.3.5 21 | */ 22 | fun JavaPlugin.config( 23 | output: CommandSender?, 24 | file: File, 25 | default: DefaultConfig? = null 26 | ) = CustomConfig(this, output, file, default) 27 | 28 | /** 29 | * コンフィグをロードする。 30 | * @param output メッセージの出力先 31 | * @param file ファイル 32 | * @param default デフォルト設定 33 | * @param action コンフィグに対して実行する処理 34 | * @return コンフィグ 35 | * @since 2.3.5 36 | */ 37 | fun JavaPlugin.config( 38 | output: CommandSender?, 39 | file: File, 40 | default: DefaultConfig? = null, 41 | action: CustomConfigAction 42 | ) = config(output, file, default).apply(action) 43 | 44 | /** 45 | * コンフィグをロードする。 46 | * @param output メッセージの出力先 47 | * @param fileName ファイル名 48 | * @param default デフォルト設定 49 | * @return コンフィグ 50 | * @since 1.7.0 51 | */ 52 | fun JavaPlugin.config( 53 | output: CommandSender?, 54 | fileName: String, 55 | default: DefaultConfig? = null 56 | ) = config(output, File(dataFolder, fileName), default) 57 | 58 | /** 59 | * コンフィグをロードする。 60 | * @param output メッセージの出力先 61 | * @param fileName ファイル名 62 | * @param default デフォルト設定 63 | * @param action コンフィグに対して実行する処理 64 | * @return コンフィグ 65 | * @since 1.7.0 66 | */ 67 | fun JavaPlugin.config( 68 | output: CommandSender?, 69 | fileName: String, 70 | default: DefaultConfig? = null, 71 | action: CustomConfigAction 72 | ) = config(output, fileName, default).apply(action) 73 | 74 | /** 75 | * フォルダ内のコンフィグを全てロードする。 76 | * @param output メッセージの出力先 77 | * @param directory フォルダ 78 | * @return ファイルパスとコンフィグ 79 | * @since 2.3.5 80 | */ 81 | fun JavaPlugin.configDirectory( 82 | output: CommandSender?, 83 | directory: File 84 | ): Map { 85 | directory.mkdirs() 86 | return mutableMapOf().apply { 87 | fun File.loadFiles() { 88 | listFiles()?.forEach { file -> 89 | if (file.isFile) { 90 | CustomConfig(this@configDirectory, output, file, null).run { 91 | put(filePath, this) 92 | } 93 | } else if (file.isDirectory) { 94 | file.loadFiles() 95 | } 96 | } 97 | } 98 | directory.loadFiles() 99 | } 100 | } 101 | 102 | /** 103 | * フォルダ内のコンフィグを全てロードする。 104 | * @param output メッセージの出力先 105 | * @param directory フォルダ 106 | * @param action コンフィグに対して実行する処理 107 | * @return ファイルパスとコンフィグ 108 | * @since 2.3.5 109 | */ 110 | fun JavaPlugin.configDirectory( 111 | output: CommandSender?, 112 | directory: File, 113 | action: CustomConfigAction 114 | ) = configDirectory(output, directory).onEach { it.value.action() } 115 | 116 | /** 117 | * フォルダ内のコンフィグを全てロードする。 118 | * @param output メッセージの出力先 119 | * @param directoryName フォルダ名 120 | * @return ファイルパスとコンフィグ 121 | * @since 1.3.0 122 | */ 123 | fun JavaPlugin.configDirectory( 124 | output: CommandSender?, 125 | directoryName: String 126 | ) = configDirectory(output, dataFolder.resolve(directoryName)) 127 | 128 | /** 129 | * フォルダ内のコンフィグを全てロードする。 130 | * @param output メッセージの出力先 131 | * @param directoryName フォルダ名 132 | * @param action コンフィグに対して実行する処理 133 | * @return ファイルパスとコンフィグ 134 | * @since 1.3.0 135 | */ 136 | fun JavaPlugin.configDirectory( 137 | output: CommandSender?, 138 | directoryName: String, 139 | action: CustomConfigAction 140 | ) = configDirectory(output, directoryName).onEach { it.value.action() } 141 | 142 | /** 143 | * ファイルが存在するか取得する。 144 | * @param fileName ファイル名 145 | * @return 存在するか 146 | * @since 1.5.1 147 | */ 148 | fun JavaPlugin.existsConfig(fileName: String) = dataFolder.resolve(fileName).exists() 149 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/ConfigSectionType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import com.github.syari.spigot.api.config.type.section.ConfigIntSectionType 5 | 6 | /** 7 | * コンフィグセクションタイプ 8 | * @param T データ型 9 | * @since 1.3.0 10 | */ 11 | interface ConfigSectionType { 12 | /** 13 | * データ型の名前。 14 | * @since 1.3.0 15 | */ 16 | val typeName: String 17 | 18 | /** 19 | * 文字列を任意の型に変換する。 20 | * @param config [CustomConfig] 21 | * @param path セクションパス 22 | * @param value セクションキー 23 | * @return 変換した後の値 24 | * @since 1.3.0 25 | */ 26 | fun parse( 27 | config: CustomConfig, 28 | path: String, 29 | value: String 30 | ): T? 31 | 32 | /** 33 | * 定義済みのコンフィグセクションタイプの一覧。 34 | * @since 1.3.0 35 | */ 36 | companion object { 37 | /** 38 | * 整数型。 39 | * @since 1.3.0 40 | */ 41 | val Int = ConfigIntSectionType 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigBooleanDataType.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("DEPRECATION") 2 | 3 | package com.github.syari.spigot.api.config.type.data 4 | 5 | import com.github.syari.spigot.api.config.CustomConfig 6 | import com.github.syari.spigot.api.config.type.ConfigDataType 7 | 8 | /** 9 | * 真偽型。 10 | * @see ConfigDataType.Boolean 11 | * @since 1.3.0 12 | */ 13 | object ConfigBooleanDataType : ConfigDataType { 14 | /** 15 | * データ型の名前。 16 | * @since 1.3.0 17 | */ 18 | override val typeName = "Boolean" 19 | 20 | /** 21 | * コンフィグから値を取得する。 22 | * @param config [CustomConfig] 23 | * @param path コンフィグパス 24 | * @param notFoundError 存在しないデータの場合にエラーを出す 25 | * @return 取得した値 26 | * @since 1.3.0 27 | */ 28 | override fun get( 29 | config: CustomConfig, 30 | path: String, 31 | notFoundError: Boolean 32 | ): Boolean? { 33 | return config.getUnsafe(path, typeName, notFoundError) 34 | } 35 | 36 | /** 37 | * コンフィグの値を変更する。 38 | * @param config [CustomConfig] 39 | * @param path コンフィグパス 40 | * @param value 設定する値 41 | * @since 1.3.0 42 | */ 43 | override fun set( 44 | config: CustomConfig, 45 | path: String, 46 | value: Boolean? 47 | ) { 48 | config.setUnsafe(path, value) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigCoordinateDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import com.github.syari.spigot.api.config.type.ConfigDataType 5 | import com.github.syari.spigot.api.world.Coordinate 6 | 7 | /** 8 | * 座標。X, Y, Z, Yaw, Pitch の値を持つ。 9 | * @see ConfigDataType.Coordinate 10 | * @since 1.4.0 11 | */ 12 | object ConfigCoordinateDataType : ConfigDataType { 13 | /** 14 | * データ型の名前。 15 | * @since 1.4.0 16 | */ 17 | override val typeName = "Coordinate" 18 | 19 | /** 20 | * コンフィグから値を取得する。 21 | * @param config [CustomConfig] 22 | * @param path コンフィグパス 23 | * @param notFoundError 存在しないデータの場合にエラーを出す 24 | * @return 取得した値 25 | * @since 1.4.0 26 | */ 27 | override fun get( 28 | config: CustomConfig, 29 | path: String, 30 | notFoundError: Boolean 31 | ): Coordinate? { 32 | return config.get(path, ConfigDataType.String, notFoundError)?.let { 33 | stringToCoordinate(config, path, it) ?: config.nullError(path, typeName).run { null } 34 | } 35 | } 36 | 37 | /** 38 | * コンフィグの値を変更する。 39 | * @param config [CustomConfig] 40 | * @param path コンフィグパス 41 | * @param value 設定する値 42 | * @since 1.4.0 43 | */ 44 | override fun set( 45 | config: CustomConfig, 46 | path: String, 47 | value: Coordinate? 48 | ) { 49 | config.set(path, ConfigDataType.String, value?.let(::coordinateToString)) 50 | } 51 | 52 | /** 53 | * [String] を [Coordinate] に変換する。 54 | * @since 1.4.0 55 | */ 56 | fun stringToCoordinate(config: CustomConfig, path: String, value: String): Coordinate? { 57 | val element = value.split(",\\s*".toRegex()) 58 | when (val size = element.size) { 59 | 3, 5 -> { 60 | try { 61 | val x = element[0].toDouble() 62 | val y = element[1].toDouble() 63 | val z = element[2].toDouble() 64 | if (size == 3) return Coordinate(x, y, z) 65 | val yaw = element[3].toFloat() 66 | val pitch = element[4].toFloat() 67 | return Coordinate(x, y, z, yaw, pitch) 68 | } catch (ex: NumberFormatException) { 69 | config.formatMismatchError(path) 70 | return null 71 | } 72 | } 73 | else -> { 74 | config.formatMismatchError(path) 75 | return null 76 | } 77 | } 78 | } 79 | 80 | /** 81 | * [Coordinate] を [String] に変換する。 82 | * @since 1.4.0 83 | */ 84 | fun coordinateToString(value: Coordinate): String { 85 | return if (value.yaw == 0F && value.pitch == 0F) { 86 | "${value.x}, ${value.y}, ${value.z}" 87 | } else { 88 | "${value.x}, ${value.y}, ${value.z}, ${value.yaw}, ${value.pitch}" 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigDateDataType.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("DEPRECATION") 2 | 3 | package com.github.syari.spigot.api.config.type.data 4 | 5 | import com.github.syari.spigot.api.config.CustomConfig 6 | import com.github.syari.spigot.api.config.type.ConfigDataType 7 | import java.util.Date 8 | 9 | /** 10 | * 日付型。 11 | * @see ConfigDataType.Date 12 | * @since 1.3.0 13 | */ 14 | object ConfigDateDataType : ConfigDataType { 15 | /** 16 | * データ型の名前。 17 | * @since 1.3.0 18 | */ 19 | override val typeName = "Date" 20 | 21 | /** 22 | * コンフィグから値を取得する。 23 | * @param config [CustomConfig] 24 | * @param path コンフィグパス 25 | * @param notFoundError 存在しないデータの場合にエラーを出す 26 | * @return 取得した値 27 | * @since 1.3.0 28 | */ 29 | override fun get( 30 | config: CustomConfig, 31 | path: String, 32 | notFoundError: Boolean 33 | ): Date? { 34 | return config.getUnsafe(path, typeName, notFoundError) 35 | } 36 | 37 | /** 38 | * コンフィグの値を変更する。 39 | * @param config [CustomConfig] 40 | * @param path コンフィグパス 41 | * @param value 設定する値 42 | * @since 1.3.0 43 | */ 44 | override fun set( 45 | config: CustomConfig, 46 | path: String, 47 | value: Date? 48 | ) { 49 | config.setUnsafe(path, value) 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigDoubleDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import com.github.syari.spigot.api.config.type.ConfigDataType 5 | 6 | /** 7 | * [ConfigDataType.Float] よりも精度の高い浮動小数型。 8 | * @see ConfigDataType.Double 9 | * @since 1.3.0 10 | */ 11 | object ConfigDoubleDataType : ConfigDataType { 12 | /** 13 | * データ型の名前。 14 | * @since 1.3.0 15 | */ 16 | override val typeName = "Double" 17 | 18 | /** 19 | * コンフィグから値を取得する。 20 | * @param config [CustomConfig] 21 | * @param path コンフィグパス 22 | * @param notFoundError 存在しないデータの場合にエラーを出す 23 | * @return 取得した値 24 | * @since 1.3.0 25 | */ 26 | override fun get( 27 | config: CustomConfig, 28 | path: String, 29 | notFoundError: Boolean 30 | ): Double? { 31 | return config.get(path, ConfigDataType.Number, notFoundError)?.toDouble() 32 | } 33 | 34 | /** 35 | * コンフィグの値を変更する。 36 | * @param config [CustomConfig] 37 | * @param path コンフィグパス 38 | * @param value 設定する値 39 | * @since 1.3.0 40 | */ 41 | override fun set( 42 | config: CustomConfig, 43 | path: String, 44 | value: Double? 45 | ) { 46 | config.set(path, ConfigDataType.Number, value) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigEnchantmentByKeyDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data 2 | 3 | import com.github.syari.spigot.api.UnsupportedMinecraftVersion 4 | import com.github.syari.spigot.api.config.CustomConfig 5 | import com.github.syari.spigot.api.config.type.ConfigDataType 6 | import org.bukkit.NamespacedKey 7 | import org.bukkit.enchantments.Enchantment 8 | 9 | /** 10 | * エンチャント。固有名から取得する。 11 | * @see ConfigDataType.EnchantmentByKey 12 | * @since 1.5.1 13 | */ 14 | @UnsupportedMinecraftVersion(8, 9, 10, 11, 12) 15 | object ConfigEnchantmentByKeyDataType : ConfigDataType { 16 | /** 17 | * データ型の名前。 18 | * @since 1.5.1 19 | */ 20 | override val typeName = "Enchantment(Key)" 21 | 22 | /** 23 | * コンフィグから値を取得する。 24 | * @param config [CustomConfig] 25 | * @param path コンフィグパス 26 | * @param notFoundError 存在しないデータの場合にエラーを出す 27 | * @return 取得した値 28 | * @since 1.5.1 29 | */ 30 | override fun get( 31 | config: CustomConfig, 32 | path: String, 33 | notFoundError: Boolean 34 | ): Enchantment? { 35 | return config.get(path, ConfigDataType.String, notFoundError)?.let { 36 | stringToEnchantment(it) ?: config.nullError(path, typeName).run { null } 37 | } 38 | } 39 | 40 | /** 41 | * コンフィグの値を変更する。 42 | * @param config [CustomConfig] 43 | * @param path コンフィグパス 44 | * @param value 設定する値 45 | * @since 1.5.1 46 | */ 47 | override fun set( 48 | config: CustomConfig, 49 | path: String, 50 | value: Enchantment? 51 | ) { 52 | config.set(path, ConfigDataType.String, value?.let(::enchantmentToString)) 53 | } 54 | 55 | /** 56 | * [String] を [Enchantment] に変換する。 57 | * @since 1.5.1. 58 | */ 59 | fun stringToEnchantment(value: String): Enchantment? { 60 | return Enchantment.getByKey(NamespacedKey.minecraft(value.lowercase())) 61 | } 62 | 63 | /** 64 | * [Enchantment] を [String] に変換する。 65 | * @since 1.5.1 66 | */ 67 | fun enchantmentToString(value: Enchantment): String { 68 | return value.key.key 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigEnchantmentByNameDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import com.github.syari.spigot.api.config.type.ConfigDataType 5 | import org.bukkit.enchantments.Enchantment 6 | 7 | /** 8 | * エンチャント。名前から取得する。 9 | * @see ConfigDataType.EnchantmentByName 10 | * @since 1.5.1 11 | */ 12 | @Deprecated("Enchantment::getByName は非推奨です。", ReplaceWith("ConfigEnchantmentByKeyDataType")) 13 | object ConfigEnchantmentByNameDataType : ConfigDataType { 14 | /** 15 | * データ型の名前 16 | * @since 1.5.1 17 | */ 18 | override val typeName = "Enchantment(Name)" 19 | 20 | /** 21 | * コンフィグから値を取得する。 22 | * @param config [CustomConfig] 23 | * @param path コンフィグパス 24 | * @param notFoundError 存在しないデータの場合にエラーを出す 25 | * @return 取得した値 26 | * @since 1.5.1 27 | */ 28 | override fun get( 29 | config: CustomConfig, 30 | path: String, 31 | notFoundError: Boolean 32 | ): Enchantment? { 33 | return config.get(path, ConfigDataType.String, notFoundError)?.let { 34 | stringToEnchantment(it) ?: config.nullError(path, typeName).run { null } 35 | } 36 | } 37 | 38 | /** 39 | * コンフィグの値を変更する。 40 | * @param config [CustomConfig] 41 | * @param path コンフィグパス 42 | * @param value 設定する値 43 | * @since 1.5.1 44 | */ 45 | override fun set( 46 | config: CustomConfig, 47 | path: String, 48 | value: Enchantment? 49 | ) { 50 | config.set(path, ConfigDataType.String, value?.let(::enchantmentToString)) 51 | } 52 | 53 | /** 54 | * [String] を [Enchantment] に変換する。 55 | * @since 1.5.1. 56 | */ 57 | fun stringToEnchantment(value: String): Enchantment? { 58 | @Suppress("DEPRECATION") 59 | return Enchantment.getByName(value.toUpperCase()) 60 | } 61 | 62 | /** 63 | * [Enchantment] を [String] に変換する。 64 | * @since 1.5.1 65 | */ 66 | fun enchantmentToString(value: Enchantment): String { 67 | @Suppress("DEPRECATION") 68 | return value.name 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigEntityTypeDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data 2 | 3 | import com.github.syari.spigot.api.config.type.ConfigDataType 4 | import org.bukkit.entity.EntityType 5 | 6 | /** 7 | * エンティティの種類。 8 | * @see ConfigDataType.EntityType 9 | * @since 1.5.0 10 | */ 11 | object ConfigEntityTypeDataType : ConfigEnumDataType { 12 | /** 13 | * データ型の名前。 14 | * @since 1.5.0 15 | */ 16 | override val typeName = "EntityType" 17 | 18 | /** 19 | * 列挙型の要素を名前から取得する。 20 | * @param name 名前 21 | * @return 取得した要素 22 | * @since 1.5.0 23 | */ 24 | override fun stringToEnum(name: String): EntityType? { 25 | val upperName = name.uppercase() 26 | return EntityType.values().firstOrNull { it.name == upperName } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigEnumDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import com.github.syari.spigot.api.config.type.ConfigDataType 5 | 6 | /** 7 | * 列挙型の要素からデータタイプを作成する為のインターフェース。 8 | * @since 1.5.0 9 | */ 10 | interface ConfigEnumDataType> : ConfigDataType { 11 | /** 12 | * [String] を 列挙型の要素 に変換する。 13 | * @param name 名前 14 | * @return 変換した後の値 15 | * @since 1.5.0 16 | */ 17 | fun stringToEnum(name: String): T? 18 | 19 | /** 20 | * コンフィグから値を取得する。 21 | * @param config [CustomConfig] 22 | * @param path コンフィグパス 23 | * @param notFoundError 存在しないデータの場合にエラーを出す 24 | * @return 取得した値 25 | * @since 1.5.0 26 | */ 27 | override fun get( 28 | config: CustomConfig, 29 | path: String, 30 | notFoundError: Boolean 31 | ): T? { 32 | return config.get(path, ConfigDataType.String, notFoundError)?.let { 33 | stringToEnum(it) ?: config.nullError(path, typeName).run { null } 34 | } 35 | } 36 | 37 | /** 38 | * コンフィグの値を変更する。 39 | * @param config [CustomConfig] 40 | * @param path コンフィグパス 41 | * @param value 設定する値 42 | * @since 1.5.0 43 | */ 44 | override fun set( 45 | config: CustomConfig, 46 | path: String, 47 | value: T? 48 | ) { 49 | config.set(path, ConfigDataType.String, value?.name) 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigFloatDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import com.github.syari.spigot.api.config.type.ConfigDataType 5 | 6 | /** 7 | * 浮動小数型。 8 | * @see ConfigDataType.Float 9 | * @since 1.3.0 10 | */ 11 | object ConfigFloatDataType : ConfigDataType { 12 | /** 13 | * データ型の名前。 14 | * @since 1.3.0 15 | */ 16 | override val typeName = "Float" 17 | 18 | /** 19 | * コンフィグから値を取得する。 20 | * @param config [CustomConfig] 21 | * @param path コンフィグパス 22 | * @param notFoundError 存在しないデータの場合にエラーを出す 23 | * @return 取得した値 24 | * @since 1.3.0 25 | */ 26 | override fun get( 27 | config: CustomConfig, 28 | path: String, 29 | notFoundError: Boolean 30 | ): Float? { 31 | return config.get(path, ConfigDataType.Number, notFoundError)?.toFloat() 32 | } 33 | 34 | /** 35 | * コンフィグの値を変更する。 36 | * @param config [CustomConfig] 37 | * @param path コンフィグパス 38 | * @param value 設定する値 39 | * @since 1.3.0 40 | */ 41 | override fun set( 42 | config: CustomConfig, 43 | path: String, 44 | value: Float? 45 | ) { 46 | config.set(path, ConfigDataType.Number, value) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigIntDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import com.github.syari.spigot.api.config.type.ConfigDataType 5 | 6 | /** 7 | * 整数型。 8 | * @see ConfigDataType.Int 9 | * @since 1.3.0 10 | */ 11 | object ConfigIntDataType : ConfigDataType { 12 | /** 13 | * データ型の名前。 14 | * @since 1.3.0 15 | */ 16 | override val typeName = "Int" 17 | 18 | /** 19 | * コンフィグから値を取得する。 20 | * @param config [CustomConfig] 21 | * @param path コンフィグパス 22 | * @param notFoundError 存在しないデータの場合にエラーを出す 23 | * @return 取得した値 24 | * @since 1.3.0 25 | */ 26 | override fun get( 27 | config: CustomConfig, 28 | path: String, 29 | notFoundError: Boolean 30 | ): Int? { 31 | return config.get(path, ConfigDataType.Number, notFoundError)?.toInt() 32 | } 33 | 34 | /** 35 | * コンフィグの値を変更する。 36 | * @param config [CustomConfig] 37 | * @param path コンフィグパス 38 | * @param value 設定する値 39 | * @since 1.3.0 40 | */ 41 | override fun set( 42 | config: CustomConfig, 43 | path: String, 44 | value: Int? 45 | ) { 46 | config.set(path, ConfigDataType.Number, value) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigInventoryDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import com.github.syari.spigot.api.config.converter.ConfigItemConverter 5 | import com.github.syari.spigot.api.config.type.ConfigDataType 6 | import com.github.syari.spigot.api.config.type.ConfigSectionType 7 | import org.bukkit.inventory.ItemStack 8 | 9 | /** 10 | * インベントリ。[ConfigItemConverter] を使用して保存・読込を行う。 11 | * @see ConfigDataType.Inventory 12 | * @since 1.7.0 13 | */ 14 | class ConfigInventoryDataType(private val itemConverter: ConfigItemConverter) : ConfigDataType> { 15 | override val typeName = "Inventory" 16 | 17 | /** 18 | * コンフィグから値を取得する。 19 | * @param config [CustomConfig] 20 | * @param path コンフィグパス 21 | * @param notFoundError 存在しないデータの場合にエラーを出す 22 | * @return 取得した値 23 | * @since 1.7.0 24 | */ 25 | override fun get( 26 | config: CustomConfig, 27 | path: String, 28 | notFoundError: Boolean 29 | ): Map { 30 | val itemDataType = ConfigDataType.ItemStack(itemConverter) 31 | return mutableMapOf().apply { 32 | config.section(path, ConfigSectionType.Int, notFoundError)?.forEach { slot -> 33 | config.get("$path.$slot", itemDataType)?.let { put(slot, it) } 34 | } 35 | } 36 | } 37 | 38 | /** 39 | * コンフィグの値を変更する。 40 | * @param config [CustomConfig] 41 | * @param path コンフィグパス 42 | * @param value 設定する値 43 | * @since 1.3.0 44 | */ 45 | override fun set( 46 | config: CustomConfig, 47 | path: String, 48 | value: Map? 49 | ) { 50 | config.setNull(path) 51 | value?.forEach { (slot, item) -> 52 | config.set("$path.$slot", ConfigDataType.String, itemConverter.itemToString(item)) 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigItemStackDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import com.github.syari.spigot.api.config.converter.ConfigItemConverter 5 | import com.github.syari.spigot.api.config.type.ConfigDataType 6 | import org.bukkit.inventory.ItemStack 7 | 8 | /** 9 | * アイテムスタック。[ConfigItemConverter] を使用して保存・読込を行う。 10 | * @see ConfigDataType.ItemStack 11 | * @since 1.7.0 12 | */ 13 | class ConfigItemStackDataType(private val itemConverter: ConfigItemConverter) : ConfigDataType { 14 | override val typeName = "ItemStack" 15 | 16 | /** 17 | * コンフィグから値を取得する。 18 | * @param config [CustomConfig] 19 | * @param path コンフィグパス 20 | * @param notFoundError 存在しないデータの場合にエラーを出す 21 | * @return 取得した値 22 | * @since 1.7.0 23 | */ 24 | override fun get( 25 | config: CustomConfig, 26 | path: String, 27 | notFoundError: Boolean 28 | ): ItemStack? { 29 | val line = config.get(path, ConfigDataType.String, notFoundError) ?: return config.nullError(path, "String").run { null } 30 | return itemConverter.stringToItem(config, path, line) 31 | } 32 | 33 | /** 34 | * コンフィグの値を変更する。 35 | * @param config [CustomConfig] 36 | * @param path コンフィグパス 37 | * @param value 設定する値 38 | * @since 1.7.0 39 | */ 40 | override fun set( 41 | config: CustomConfig, 42 | path: String, 43 | value: ItemStack? 44 | ) { 45 | config.set(path, ConfigDataType.String, value?.let(itemConverter::itemToString)) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigLocationDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import com.github.syari.spigot.api.config.type.ConfigDataType 5 | import org.bukkit.Bukkit 6 | import org.bukkit.Location 7 | 8 | /** 9 | * ワールド座標。World, X, Y, Z, Yaw, Pitch の値を持つ。 10 | * @see ConfigDataType.Location 11 | * @since 1.3.0 12 | */ 13 | object ConfigLocationDataType : ConfigDataType { 14 | /** 15 | * データ型の名前。 16 | * @since 1.3.0 17 | */ 18 | override val typeName = "Location" 19 | 20 | /** 21 | * コンフィグから値を取得する。 22 | * @param config [CustomConfig] 23 | * @param path コンフィグパス 24 | * @param notFoundError 存在しないデータの場合にエラーを出す 25 | * @return 取得した値 26 | * @since 1.3.0 27 | */ 28 | override fun get( 29 | config: CustomConfig, 30 | path: String, 31 | notFoundError: Boolean 32 | ): Location? { 33 | return config.get(path, ConfigDataType.String, notFoundError)?.let { 34 | stringToLocation(config, path, it) ?: config.nullError(path, typeName).run { null } 35 | } 36 | } 37 | 38 | /** 39 | * コンフィグの値を変更する。 40 | * @param config [CustomConfig] 41 | * @param path コンフィグパス 42 | * @param value 設定する値 43 | * @since 1.3.0 44 | */ 45 | override fun set( 46 | config: CustomConfig, 47 | path: String, 48 | value: Location? 49 | ) { 50 | config.set(path, ConfigDataType.String, value?.let(::locationToString)) 51 | } 52 | 53 | /** 54 | * [String] を [Location] に変換する。 55 | * @since 1.3.0 56 | */ 57 | fun stringToLocation(config: CustomConfig, path: String, value: String): Location? { 58 | val element = value.split(",\\s*".toRegex()) 59 | when (val size = element.size) { 60 | 4, 6 -> { 61 | val world = Bukkit.getWorld(element[0]) 62 | if (world == null) { 63 | config.nullError(path, "World(${element[0]})") 64 | return null 65 | } 66 | try { 67 | val x = element[1].toDouble() 68 | val y = element[2].toDouble() 69 | val z = element[3].toDouble() 70 | if (size == 4) return Location(world, x, y, z) 71 | val yaw = element[4].toFloat() 72 | val pitch = element[5].toFloat() 73 | return Location(world, x, y, z, yaw, pitch) 74 | } catch (ex: NumberFormatException) { 75 | config.formatMismatchError(path) 76 | return null 77 | } 78 | } 79 | else -> { 80 | config.formatMismatchError(path) 81 | return null 82 | } 83 | } 84 | } 85 | 86 | /** 87 | * [Location] を [String] に変換する。 88 | * @since 1.3.0 89 | */ 90 | fun locationToString(value: Location): String { 91 | return if (value.yaw == 0F && value.pitch == 0F) { 92 | "${value.world?.name}, ${value.x}, ${value.y}, ${value.z}" 93 | } else { 94 | "${value.world?.name}, ${value.x}, ${value.y}, ${value.z}, ${value.yaw}, ${value.pitch}" 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigLongDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import com.github.syari.spigot.api.config.type.ConfigDataType 5 | 6 | /** 7 | * [ConfigDataType.Int] より大きい整数型。 8 | * @see ConfigDataType.Long 9 | * @since 1.3.0 10 | */ 11 | object ConfigLongDataType : ConfigDataType { 12 | /** 13 | * データ型の名前。 14 | * @since 1.3.0 15 | */ 16 | override val typeName = "Long" 17 | 18 | /** 19 | * コンフィグから値を取得する。 20 | * @param config [CustomConfig] 21 | * @param path コンフィグパス 22 | * @param notFoundError 存在しないデータの場合にエラーを出す 23 | * @return 取得した値 24 | * @since 1.3.0 25 | */ 26 | override fun get( 27 | config: CustomConfig, 28 | path: String, 29 | notFoundError: Boolean 30 | ): Long? { 31 | return config.get(path, ConfigDataType.Number, notFoundError)?.toLong() 32 | } 33 | 34 | /** 35 | * コンフィグの値を変更する。 36 | * @param config [CustomConfig] 37 | * @param path コンフィグパス 38 | * @param value 設定する値 39 | * @since 1.3.0 40 | */ 41 | override fun set( 42 | config: CustomConfig, 43 | path: String, 44 | value: Long? 45 | ) { 46 | config.set(path, ConfigDataType.Number, value) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigMaterialDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data 2 | 3 | import com.github.syari.spigot.api.config.type.ConfigDataType 4 | import org.bukkit.Material 5 | 6 | /** 7 | * マテリアル。 8 | * @see ConfigDataType.Material 9 | * @since 1.3.0 10 | */ 11 | object ConfigMaterialDataType : ConfigEnumDataType { 12 | /** 13 | * データ型の名前。 14 | * @since 1.3.0 15 | */ 16 | override val typeName = "Material" 17 | 18 | /** 19 | * 列挙型の要素を名前から取得する。 20 | * @param name 名前 21 | * @return 取得した要素 22 | * @since 1.5.0 23 | */ 24 | override fun stringToEnum(name: String): Material? { 25 | return Material.getMaterial(name.uppercase()) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigNumberDataType.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("DEPRECATION") 2 | 3 | package com.github.syari.spigot.api.config.type.data 4 | 5 | import com.github.syari.spigot.api.config.CustomConfig 6 | import com.github.syari.spigot.api.config.type.ConfigDataType 7 | 8 | /** 9 | * 数字。別の数字型に変換して使う。 10 | * @see ConfigDataType.Number 11 | * @see ConfigDataType.Int 12 | * @see ConfigDataType.Long 13 | * @see ConfigDataType.Float 14 | * @see ConfigDataType.Double 15 | * @since 1.3.0 16 | */ 17 | object ConfigNumberDataType : ConfigDataType { 18 | /** 19 | * データ型の名前。 20 | * @since 1.3.0 21 | */ 22 | override val typeName = "Number" 23 | 24 | /** 25 | * コンフィグから値を取得する。 26 | * @param config [CustomConfig] 27 | * @param path コンフィグパス 28 | * @param notFoundError 存在しないデータの場合にエラーを出す 29 | * @return 取得した値 30 | * @since 1.3.0 31 | */ 32 | override fun get( 33 | config: CustomConfig, 34 | path: String, 35 | notFoundError: Boolean 36 | ): Number? { 37 | return config.getUnsafe(path, typeName, notFoundError) 38 | } 39 | 40 | /** 41 | * コンフィグの値を変更する。 42 | * @param config [CustomConfig] 43 | * @param path コンフィグパス 44 | * @param value 設定する値 45 | * @since 1.3.0 46 | */ 47 | override fun set( 48 | config: CustomConfig, 49 | path: String, 50 | value: Number? 51 | ) { 52 | config.setUnsafe(path, value) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigParticleDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data 2 | 3 | import com.github.syari.spigot.api.UnsupportedMinecraftVersion 4 | import com.github.syari.spigot.api.config.type.ConfigDataType 5 | import org.bukkit.Particle 6 | 7 | /** 8 | * パーティクルの種類。 9 | * @see ConfigDataType.Particle 10 | * @since 1.5.0 11 | */ 12 | @UnsupportedMinecraftVersion(8) 13 | object ConfigParticleDataType : ConfigEnumDataType { 14 | /** 15 | * データ型の名前。 16 | * @since 1.5.0 17 | */ 18 | override val typeName = "Particle" 19 | 20 | /** 21 | * 列挙型の要素を名前から取得する。 22 | * @param name 名前 23 | * @return 取得した要素 24 | * @since 1.5.0 25 | */ 26 | override fun stringToEnum(name: String): Particle? { 27 | val upperName = name.uppercase() 28 | return Particle.values().firstOrNull { it.name == upperName } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigPotionEffectTypeDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import com.github.syari.spigot.api.config.type.ConfigDataType 5 | import org.bukkit.potion.PotionEffectType 6 | 7 | /** 8 | * ポーションエフェクトの種類。 9 | * @see ConfigDataType.PotionEffectType 10 | * @since 1.5.0 11 | */ 12 | object ConfigPotionEffectTypeDataType : ConfigDataType { 13 | /** 14 | * データ型の名前。 15 | * @since 1.5.0 16 | */ 17 | override val typeName = "PotionEffectType" 18 | 19 | /** 20 | * コンフィグから値を取得する。 21 | * @param config [CustomConfig] 22 | * @param path コンフィグパス 23 | * @param notFoundError 存在しないデータの場合にエラーを出す 24 | * @return 取得した値 25 | * @since 1.5.0 26 | */ 27 | override fun get( 28 | config: CustomConfig, 29 | path: String, 30 | notFoundError: Boolean 31 | ): PotionEffectType? { 32 | return config.get(path, ConfigDataType.String, notFoundError)?.let { 33 | stringToPotionEffectType(it) ?: config.nullError(path, typeName).run { null } 34 | } 35 | } 36 | 37 | /** 38 | * コンフィグの値を変更する。 39 | * @param config [CustomConfig] 40 | * @param path コンフィグパス 41 | * @param value 設定する値 42 | * @since 1.5.0 43 | */ 44 | override fun set( 45 | config: CustomConfig, 46 | path: String, 47 | value: PotionEffectType? 48 | ) { 49 | config.set(path, ConfigDataType.String, value?.let(::potionEffectTypeToString)) 50 | } 51 | 52 | /** 53 | * [String] を [PotionEffectType] に変換する。 54 | * @since 1.5.1. 55 | */ 56 | fun stringToPotionEffectType(value: String): PotionEffectType? { 57 | return PotionEffectType.getByName(value) 58 | } 59 | 60 | /** 61 | * [PotionEffectType] を [String] に変換する。 62 | * @since 1.5.1 63 | */ 64 | fun potionEffectTypeToString(value: PotionEffectType): String { 65 | return value.name 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigSerializableInventoryDataType.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("DEPRECATION") 2 | 3 | package com.github.syari.spigot.api.config.type.data 4 | 5 | import com.github.syari.spigot.api.config.CustomConfig 6 | import com.github.syari.spigot.api.config.type.ConfigDataType 7 | import org.bukkit.inventory.ItemStack 8 | 9 | /** 10 | * インベントリ。シリアライズを使用して保存・読込を行う。 11 | * @see ConfigDataType.SerializableInventory 12 | * @since 1.6.0 13 | */ 14 | object ConfigSerializableInventoryDataType : ConfigDataType> { 15 | /** 16 | * データ型の名前。 17 | * @since 1.6.0 18 | */ 19 | override val typeName = "Inventory(Serialize)" 20 | 21 | /** 22 | * コンフィグから値を取得する。 23 | * @param config [CustomConfig] 24 | * @param path コンフィグパス 25 | * @param notFoundError 存在しないデータの場合にエラーを出す 26 | * @return 取得した値 27 | * @since 1.6.0 28 | */ 29 | override fun get( 30 | config: CustomConfig, 31 | path: String, 32 | notFoundError: Boolean 33 | ): Array? { 34 | return config.getUnsafe>(path, typeName, notFoundError)?.toTypedArray() 35 | } 36 | 37 | /** 38 | * @param path コンフィグパス 39 | * @param value 設定する値 40 | * @since 1.6.0 41 | */ 42 | override fun set( 43 | config: CustomConfig, 44 | path: String, 45 | value: Array? 46 | ) { 47 | config.setUnsafe(path, value) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigSerializableItemStackDataType.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("DEPRECATION") 2 | 3 | package com.github.syari.spigot.api.config.type.data 4 | 5 | import com.github.syari.spigot.api.config.CustomConfig 6 | import com.github.syari.spigot.api.config.type.ConfigDataType 7 | import org.bukkit.inventory.ItemStack 8 | 9 | /** 10 | * アイテムスタック。シリアライズを使用して保存・読込を行う。 11 | * @see ConfigDataType.SerializableItemStack 12 | * @since 1.6.0 13 | */ 14 | object ConfigSerializableItemStackDataType : ConfigDataType { 15 | /** 16 | * データ型の名前。 17 | * @since 1.6.0 18 | */ 19 | override val typeName = "ItemStack(Serialize)" 20 | 21 | /** 22 | * コンフィグから値を取得する。 23 | * @param config [CustomConfig] 24 | * @param path コンフィグパス 25 | * @param notFoundError 存在しないデータの場合にエラーを出す 26 | * @return 取得した値 27 | * @since 1.6.0 28 | */ 29 | override fun get( 30 | config: CustomConfig, 31 | path: String, 32 | notFoundError: Boolean 33 | ): ItemStack? { 34 | return config.getUnsafe(path, typeName, notFoundError) 35 | } 36 | 37 | /** 38 | * コンフィグの値を変更する。 39 | * @param config [CustomConfig] 40 | * @param path コンフィグパス 41 | * @param value 設定する値 42 | * @since 1.6.0 43 | */ 44 | override fun set( 45 | config: CustomConfig, 46 | path: String, 47 | value: ItemStack? 48 | ) { 49 | config.setUnsafe(path, value) 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigSoundByKeyDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data 2 | 3 | import com.github.syari.spigot.api.UnsupportedMinecraftVersion 4 | import com.github.syari.spigot.api.config.type.ConfigDataType 5 | import org.bukkit.Sound 6 | 7 | /** 8 | * サウンドの種類。固有名から取得する。 9 | * @see ConfigDataType.SoundByKey 10 | * @since 1.6.0 11 | */ 12 | @UnsupportedMinecraftVersion(8, 9, 10, 11, 12, 13, 14, 15) 13 | object ConfigSoundByKeyDataType : ConfigEnumDataType { 14 | /** 15 | * データ型の名前。 16 | * @since 1.6.0 17 | */ 18 | override val typeName = "Sound(Key)" 19 | 20 | /** 21 | * 列挙型の要素を名前から取得する。 22 | * @param name 名前 23 | * @return 取得した要素 24 | * @since 1.6.0 25 | */ 26 | override fun stringToEnum(name: String): Sound? { 27 | val lowerName = name.lowercase() 28 | return Sound.values().firstOrNull { it.key.key == lowerName } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigSoundByNameDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data 2 | 3 | import com.github.syari.spigot.api.config.type.ConfigDataType 4 | import org.bukkit.Sound 5 | 6 | /** 7 | * サウンドの種類。名前から取得する。 8 | * @see ConfigDataType.SoundByName 9 | * @since 1.6.0 10 | */ 11 | object ConfigSoundByNameDataType : ConfigEnumDataType { 12 | /** 13 | * データ型の名前。 14 | * @since 1.6.0 15 | */ 16 | override val typeName = "Sound(Name)" 17 | 18 | /** 19 | * 列挙型の要素を名前から取得する。 20 | * @param name 名前 21 | * @return 取得した要素 22 | * @since 1.6.0 23 | */ 24 | override fun stringToEnum(name: String): Sound? { 25 | val upperName = name.uppercase() 26 | return Sound.values().firstOrNull { it.name == upperName } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigStringDataType.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("DEPRECATION") 2 | 3 | package com.github.syari.spigot.api.config.type.data 4 | 5 | import com.github.syari.spigot.api.config.CustomConfig 6 | import com.github.syari.spigot.api.config.type.ConfigDataType 7 | 8 | /** 9 | * 文字列型。 10 | * @see ConfigDataType.String 11 | * @since 1.3.0 12 | */ 13 | object ConfigStringDataType : ConfigDataType { 14 | /** 15 | * データ型の名前。 16 | * @since 1.3.0 17 | */ 18 | override val typeName = "String" 19 | 20 | /** 21 | * コンフィグから値を取得する。 22 | * @param config [CustomConfig] 23 | * @param path コンフィグパス 24 | * @param notFoundError 存在しないデータの場合にエラーを出す 25 | * @return 取得した値 26 | * @since 1.3.0 27 | */ 28 | override fun get( 29 | config: CustomConfig, 30 | path: String, 31 | notFoundError: Boolean 32 | ): String? { 33 | return config.getUnsafe(path, typeName, notFoundError) 34 | } 35 | 36 | /** 37 | * コンフィグの値を変更する。 38 | * @param config [CustomConfig] 39 | * @param path コンフィグパス 40 | * @param value 設定する値 41 | * @since 1.3.0 42 | */ 43 | override fun set( 44 | config: CustomConfig, 45 | path: String, 46 | value: String? 47 | ) { 48 | config.setUnsafe(path, value) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigUUIDDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import com.github.syari.spigot.api.config.type.ConfigDataType 5 | import com.github.syari.spigot.api.uuid.uuidOrNull 6 | import java.util.UUID 7 | 8 | /** 9 | * UUID。 10 | * @see ConfigDataType.UUID 11 | * @since 1.3.4 12 | */ 13 | object ConfigUUIDDataType : ConfigDataType { 14 | /** 15 | * データ型の名前。 16 | * @since 1.3.4 17 | */ 18 | override val typeName = "UUID" 19 | 20 | /** 21 | * コンフィグから値を取得する。 22 | * @param config [CustomConfig] 23 | * @param path コンフィグパス 24 | * @param notFoundError 存在しないデータの場合にエラーを出す 25 | * @return 取得した値 26 | * @since 1.3.4 27 | */ 28 | override fun get( 29 | config: CustomConfig, 30 | path: String, 31 | notFoundError: Boolean 32 | ): UUID? { 33 | return config.get(path, ConfigDataType.String, notFoundError)?.let { 34 | uuidOrNull(it) ?: config.formatMismatchError(path).run { null } 35 | } 36 | } 37 | 38 | /** 39 | * コンフィグの値を変更する。 40 | * @param config [CustomConfig] 41 | * @param path コンフィグパス 42 | * @param value 設定する値 43 | * @since 1.3.4 44 | */ 45 | override fun set( 46 | config: CustomConfig, 47 | path: String, 48 | value: UUID? 49 | ) { 50 | config.set(path, ConfigDataType.String, value?.toString()) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigVectorDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import com.github.syari.spigot.api.config.type.ConfigDataType 5 | import org.bukkit.util.Vector 6 | 7 | /** 8 | * ベクトル。X, Y, Z の値を持つ。 9 | * @see ConfigDataType.Vector 10 | * @since 1.4.0 11 | */ 12 | object ConfigVectorDataType : ConfigDataType { 13 | /** 14 | * データ型の名前。 15 | * @since 1.4.0 16 | */ 17 | override val typeName = "Vector" 18 | 19 | /** 20 | * コンフィグから値を取得する。 21 | * @param config [CustomConfig] 22 | * @param path コンフィグパス 23 | * @param notFoundError 存在しないデータの場合にエラーを出す 24 | * @return 取得した値 25 | * @since 1.4.0 26 | */ 27 | override fun get( 28 | config: CustomConfig, 29 | path: String, 30 | notFoundError: Boolean 31 | ): Vector? { 32 | val line = config.get(path, ConfigDataType.String, notFoundError) ?: return null 33 | return stringToVector(config, path, line) ?: config.nullError(path, typeName).run { null } 34 | } 35 | 36 | /** 37 | * コンフィグの値を変更する。 38 | * @param config [CustomConfig] 39 | * @param path コンフィグパス 40 | * @param value 設定する値 41 | * @since 1.4.0 42 | */ 43 | override fun set( 44 | config: CustomConfig, 45 | path: String, 46 | value: Vector? 47 | ) { 48 | config.set(path, ConfigDataType.String, value?.let(::vectorToString)) 49 | } 50 | 51 | /** 52 | * [String] を [Vector] に変換する。 53 | * @since 1.4.0 54 | */ 55 | fun stringToVector(config: CustomConfig, path: String, value: String): Vector? { 56 | val element = value.split(",\\s*".toRegex()) 57 | when (element.size) { 58 | 3 -> { 59 | return try { 60 | val x = element[0].toDouble() 61 | val y = element[1].toDouble() 62 | val z = element[2].toDouble() 63 | Vector(x, y, z) 64 | } catch (ex: NumberFormatException) { 65 | config.formatMismatchError(path) 66 | null 67 | } 68 | } 69 | else -> { 70 | config.formatMismatchError(path) 71 | return null 72 | } 73 | } 74 | } 75 | 76 | /** 77 | * [Vector] を [String] に変換する。 78 | * @since 1.4.0 79 | */ 80 | fun vectorToString(value: Vector): String { 81 | return "${value.x}, ${value.y}, ${value.z}" 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/ConfigWorldDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import com.github.syari.spigot.api.config.type.ConfigDataType 5 | import org.bukkit.Bukkit 6 | import org.bukkit.World 7 | 8 | /** 9 | * ワールド。 10 | * @see ConfigDataType.World 11 | * @since 1.3.0 12 | */ 13 | object ConfigWorldDataType : ConfigDataType { 14 | /** 15 | * データ型の名前。 16 | * @since 1.3.0 17 | */ 18 | override val typeName = "World" 19 | 20 | /** 21 | * コンフィグから値を取得する。 22 | * @param config [CustomConfig] 23 | * @param path コンフィグパス 24 | * @param notFoundError 存在しないデータの場合にエラーを出す 25 | * @return 取得した値 26 | * @since 1.3.0 27 | */ 28 | override fun get( 29 | config: CustomConfig, 30 | path: String, 31 | notFoundError: Boolean 32 | ): World? { 33 | return config.get(path, ConfigDataType.String, notFoundError)?.let { 34 | Bukkit.getWorld(it) ?: config.nullError(path, typeName).run { null } 35 | } 36 | } 37 | 38 | /** 39 | * コンフィグの値を変更する。 40 | * @param config [CustomConfig] 41 | * @param path コンフィグパス 42 | * @param value 設定する値 43 | * @since 1.3.0 44 | */ 45 | override fun set( 46 | config: CustomConfig, 47 | path: String, 48 | value: World? 49 | ) { 50 | config.set(path, ConfigDataType.String, value?.name) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/list/ConfigCoordinateListDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data.list 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import com.github.syari.spigot.api.config.type.ConfigDataType 5 | import com.github.syari.spigot.api.config.type.data.ConfigCoordinateDataType.coordinateToString 6 | import com.github.syari.spigot.api.config.type.data.ConfigCoordinateDataType.stringToCoordinate 7 | import com.github.syari.spigot.api.world.Coordinate 8 | 9 | /** 10 | * 座標のリスト。 11 | * @see ConfigDataType.CoordinateList 12 | * @since 1.4.0 13 | */ 14 | object ConfigCoordinateListDataType : ConfigDataType> { 15 | /** 16 | * データ型の名前。 17 | * @since 1.4.0 18 | */ 19 | override val typeName = "Coordinate" 20 | 21 | /** 22 | * コンフィグから値を取得する。 23 | * @param config [CustomConfig] 24 | * @param path コンフィグパス 25 | * @param notFoundError 存在しないデータの場合にエラーを出す 26 | * @return 取得した値 27 | * @since 1.4.0 28 | */ 29 | override fun get( 30 | config: CustomConfig, 31 | path: String, 32 | notFoundError: Boolean 33 | ): List { 34 | return config.get(path, ConfigDataType.StringList, notFoundError)?.mapNotNull { 35 | stringToCoordinate(config, "$path.$it", it) ?: config.nullError("$path.$it", typeName).run { null } 36 | }.orEmpty() 37 | } 38 | 39 | /** 40 | * コンフィグの値を変更する。 41 | * @param config [CustomConfig] 42 | * @param path コンフィグパス 43 | * @param value 設定する値 44 | * @since 1.4.0 45 | */ 46 | override fun set( 47 | config: CustomConfig, 48 | path: String, 49 | value: List? 50 | ) { 51 | config.set(path, ConfigDataType.StringList, value?.map(::coordinateToString)) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/list/ConfigEnchantmentByKeyListDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data.list 2 | 3 | import com.github.syari.spigot.api.UnsupportedMinecraftVersion 4 | import com.github.syari.spigot.api.config.CustomConfig 5 | import com.github.syari.spigot.api.config.type.ConfigDataType 6 | import com.github.syari.spigot.api.config.type.data.ConfigEnchantmentByKeyDataType.enchantmentToString 7 | import com.github.syari.spigot.api.config.type.data.ConfigEnchantmentByKeyDataType.stringToEnchantment 8 | import org.bukkit.enchantments.Enchantment 9 | 10 | /** 11 | * エンチャントの一覧。固有名から取得する。 12 | * @see ConfigDataType.EnchantmentByKeyList 13 | * @since 1.5.1 14 | */ 15 | @UnsupportedMinecraftVersion(8, 9, 10, 11, 12) 16 | object ConfigEnchantmentByKeyListDataType : ConfigDataType> { 17 | /** 18 | * データ型の名前。 19 | * @since 1.5.1 20 | */ 21 | override val typeName = "Enchantment(Key)" 22 | 23 | /** 24 | * コンフィグから値を取得する。 25 | * @param config [CustomConfig] 26 | * @param path コンフィグパス 27 | * @param notFoundError 存在しないデータの場合にエラーを出す 28 | * @return 取得した値 29 | * @since 1.5.1 30 | */ 31 | override fun get( 32 | config: CustomConfig, 33 | path: String, 34 | notFoundError: Boolean 35 | ): List { 36 | return config.get(path, ConfigDataType.StringList, notFoundError)?.mapNotNull { 37 | stringToEnchantment(it) ?: config.nullError("$path.$it", typeName).run { null } 38 | }.orEmpty() 39 | } 40 | 41 | /** 42 | * コンフィグの値を変更する。 43 | * @param config [CustomConfig] 44 | * @param path コンフィグパス 45 | * @param value 設定する値 46 | * @since 1.5.1 47 | */ 48 | override fun set( 49 | config: CustomConfig, 50 | path: String, 51 | value: List? 52 | ) { 53 | config.set(path, ConfigDataType.StringList, value?.map(::enchantmentToString)) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/list/ConfigEnchantmentByNameListDataType.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("DEPRECATION") 2 | 3 | package com.github.syari.spigot.api.config.type.data.list 4 | 5 | import com.github.syari.spigot.api.config.CustomConfig 6 | import com.github.syari.spigot.api.config.type.ConfigDataType 7 | import com.github.syari.spigot.api.config.type.data.ConfigEnchantmentByNameDataType.enchantmentToString 8 | import com.github.syari.spigot.api.config.type.data.ConfigEnchantmentByNameDataType.stringToEnchantment 9 | import org.bukkit.enchantments.Enchantment 10 | 11 | /** 12 | * [ConfigDataType.EnchantmentByNameList] 13 | * @since 1.5.1 14 | */ 15 | @Deprecated("Enchantment::getByName は非推奨です。", ReplaceWith("ConfigEnchantmentByKeyListDataType")) 16 | object ConfigEnchantmentByNameListDataType : ConfigDataType> { 17 | /** 18 | * データ型の名前。 19 | * @since 1.5.1 20 | */ 21 | override val typeName = "Enchantment(Name)" 22 | 23 | /** 24 | * コンフィグから値を取得する。 25 | * @param config [CustomConfig] 26 | * @param path コンフィグパス 27 | * @param notFoundError 存在しないデータの場合にエラーを出す 28 | * @return 取得した値 29 | * @since 1.5.1 30 | */ 31 | override fun get( 32 | config: CustomConfig, 33 | path: String, 34 | notFoundError: Boolean 35 | ): List { 36 | return config.get(path, ConfigDataType.StringList, notFoundError)?.mapNotNull { 37 | stringToEnchantment(it) ?: config.nullError("$path.$it", typeName).run { null } 38 | }.orEmpty() 39 | } 40 | 41 | /** 42 | * コンフィグの値を変更する。 43 | * @param config [CustomConfig] 44 | * @param path コンフィグパス 45 | * @param value 設定する値 46 | * @since 1.5.1 47 | */ 48 | override fun set( 49 | config: CustomConfig, 50 | path: String, 51 | value: List? 52 | ) { 53 | config.set(path, ConfigDataType.StringList, value?.map(::enchantmentToString)) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/list/ConfigEntityTypeListDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data.list 2 | 3 | import com.github.syari.spigot.api.config.type.ConfigDataType 4 | import com.github.syari.spigot.api.config.type.data.ConfigEntityTypeDataType 5 | import org.bukkit.entity.EntityType 6 | 7 | /** 8 | * エンティティの種類のリスト。 9 | * @see ConfigDataType.EntityTypeList 10 | * @since 1.5.0 11 | */ 12 | object ConfigEntityTypeListDataType : ConfigEnumListDataType { 13 | /** 14 | * データ型の名前。 15 | * @since 1.5.0 16 | */ 17 | override val typeName = "EntityType" 18 | 19 | /** 20 | * 列挙型の要素を名前から取得する。 21 | * @param name 名前 22 | * @return 取得した要素 23 | * @since 1.5.0 24 | */ 25 | override fun stringToEnum(name: String) = ConfigEntityTypeDataType.stringToEnum(name) 26 | } 27 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/list/ConfigEnumListDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data.list 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import com.github.syari.spigot.api.config.type.ConfigDataType 5 | 6 | /** 7 | * 列挙型の要素からリスト形式のデータタイプを作成する為のインターフェース。 8 | * @since 1.5.0 9 | */ 10 | interface ConfigEnumListDataType> : ConfigDataType> { 11 | /** 12 | * [String] を 列挙型の要素 に変換する。 13 | * @param name 名前 14 | * @return 変換した後の値 15 | * @since 1.5.0 16 | */ 17 | fun stringToEnum(name: String): T? 18 | 19 | /** 20 | * コンフィグから値を取得する。 21 | * @param config [CustomConfig] 22 | * @param path コンフィグパス 23 | * @param notFoundError 存在しないデータの場合にエラーを出す 24 | * @return 取得した値 25 | * @since 1.5.0 26 | */ 27 | override fun get( 28 | config: CustomConfig, 29 | path: String, 30 | notFoundError: Boolean 31 | ): List { 32 | return config.get(path, ConfigDataType.StringList, notFoundError)?.mapNotNull { 33 | stringToEnum(it) ?: config.nullError("$path.$it", typeName).run { null } 34 | }.orEmpty() 35 | } 36 | 37 | /** 38 | * コンフィグの値を変更する。 39 | * @param config [CustomConfig] 40 | * @param path コンフィグパス 41 | * @param value 設定する値 42 | * @since 1.5.0 43 | */ 44 | override fun set( 45 | config: CustomConfig, 46 | path: String, 47 | value: List? 48 | ) { 49 | config.set(path, ConfigDataType.StringList, value?.map(Enum<*>::name)) 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/list/ConfigItemStackListDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data.list 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import com.github.syari.spigot.api.config.converter.ConfigItemConverter 5 | import com.github.syari.spigot.api.config.type.ConfigDataType 6 | import org.bukkit.inventory.ItemStack 7 | 8 | /** 9 | * アイテムスタックのリスト。[ConfigItemConverter] を使用して保存・読込を行う。 10 | * @see ConfigDataType.ItemStackList 11 | * @since 1.7.0 12 | */ 13 | class ConfigItemStackListDataType(private val itemConverter: ConfigItemConverter) : ConfigDataType> { 14 | override val typeName = "List" 15 | 16 | /** 17 | * コンフィグから値を取得する。 18 | * @param config [CustomConfig] 19 | * @param path コンフィグパス 20 | * @param notFoundError 存在しないデータの場合にエラーを出す 21 | * @return 取得した値 22 | * @since 1.7.0 23 | */ 24 | override fun get( 25 | config: CustomConfig, 26 | path: String, 27 | notFoundError: Boolean 28 | ): List { 29 | return mutableListOf().apply { 30 | config.get(path, ConfigDataType.StringList, notFoundError)?.forEach { 31 | itemConverter.stringToItem(config, path, it)?.let(::add) 32 | } 33 | } 34 | } 35 | 36 | /** 37 | * コンフィグの値を変更する。 38 | * @param config [CustomConfig] 39 | * @param path コンフィグパス 40 | * @param value 設定する値 41 | * @since 1.7.0 42 | */ 43 | override fun set( 44 | config: CustomConfig, 45 | path: String, 46 | value: List? 47 | ) { 48 | config.set(path, ConfigDataType.StringList, value?.mapNotNull(itemConverter::itemToString)) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/list/ConfigLocationListDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data.list 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import com.github.syari.spigot.api.config.type.ConfigDataType 5 | import com.github.syari.spigot.api.config.type.data.ConfigLocationDataType.locationToString 6 | import com.github.syari.spigot.api.config.type.data.ConfigLocationDataType.stringToLocation 7 | import org.bukkit.Location 8 | 9 | /** 10 | * ワールド座標のリスト。 11 | * @see ConfigDataType.LocationList 12 | * @since 1.3.0 13 | */ 14 | object ConfigLocationListDataType : ConfigDataType> { 15 | /** 16 | * データ型の名前。 17 | * @since 1.3.0 18 | */ 19 | override val typeName = "Location" 20 | 21 | /** 22 | * コンフィグから値を取得する。 23 | * @param config [CustomConfig] 24 | * @param path コンフィグパス 25 | * @param notFoundError 存在しないデータの場合にエラーを出す 26 | * @return 取得した値 27 | * @since 1.3.0 28 | */ 29 | override fun get( 30 | config: CustomConfig, 31 | path: String, 32 | notFoundError: Boolean 33 | ): List { 34 | return config.get(path, ConfigDataType.StringList, notFoundError)?.mapNotNull { 35 | stringToLocation(config, "$path.$it", it) ?: config.nullError("$path.$it", typeName).run { null } 36 | }.orEmpty() 37 | } 38 | 39 | /** 40 | * コンフィグの値を変更する。 41 | * @param config [CustomConfig] 42 | * @param path コンフィグパス 43 | * @param value 設定する値 44 | * @since 1.3.0 45 | */ 46 | override fun set( 47 | config: CustomConfig, 48 | path: String, 49 | value: List? 50 | ) { 51 | config.set(path, ConfigDataType.StringList, value?.map(::locationToString)) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/list/ConfigMaterialListDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data.list 2 | 3 | import com.github.syari.spigot.api.config.type.ConfigDataType 4 | import com.github.syari.spigot.api.config.type.data.ConfigMaterialDataType 5 | import org.bukkit.Material 6 | 7 | /** 8 | * マテリアルのリスト。 9 | * @see ConfigDataType.MaterialList 10 | * @since 1.3.0 11 | */ 12 | object ConfigMaterialListDataType : ConfigEnumListDataType { 13 | /** 14 | * データ型の名前。 15 | * @since 1.3.0 16 | */ 17 | override val typeName = "Material" 18 | 19 | /** 20 | * 列挙型の要素を名前から取得する。 21 | * @param name 名前 22 | * @return 取得した要素 23 | * @since 1.5.0 24 | */ 25 | override fun stringToEnum(name: String) = ConfigMaterialDataType.stringToEnum(name) 26 | } 27 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/list/ConfigParticleListDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data.list 2 | 3 | import com.github.syari.spigot.api.UnsupportedMinecraftVersion 4 | import com.github.syari.spigot.api.config.type.ConfigDataType 5 | import com.github.syari.spigot.api.config.type.data.ConfigParticleDataType 6 | import org.bukkit.Particle 7 | 8 | /** 9 | * パーティクルの種類のリスト。 10 | * @see ConfigDataType.ParticleList 11 | * @since 1.5.0 12 | */ 13 | @UnsupportedMinecraftVersion(8) 14 | object ConfigParticleListDataType : ConfigEnumListDataType { 15 | /** 16 | * データ型の名前。 17 | * @since 1.5.0 18 | */ 19 | override val typeName = "Particle" 20 | 21 | /** 22 | * 列挙型の要素を名前から取得する。 23 | * @param name 名前 24 | * @return 取得した要素 25 | * @since 1.5.0 26 | */ 27 | override fun stringToEnum(name: String) = ConfigParticleDataType.stringToEnum(name) 28 | } 29 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/list/ConfigPotionEffectTypeListDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data.list 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import com.github.syari.spigot.api.config.type.ConfigDataType 5 | import com.github.syari.spigot.api.config.type.data.ConfigPotionEffectTypeDataType.potionEffectTypeToString 6 | import com.github.syari.spigot.api.config.type.data.ConfigPotionEffectTypeDataType.stringToPotionEffectType 7 | import org.bukkit.potion.PotionEffectType 8 | 9 | /** 10 | * ポーションエフェクトの種類のリスト。 11 | * @see ConfigDataType.PotionEffectTypeList 12 | * @since 1.5.0 13 | */ 14 | object ConfigPotionEffectTypeListDataType : ConfigDataType> { 15 | /** 16 | * データ型の名前。 17 | * @since 1.5.0 18 | */ 19 | override val typeName = "PotionEffectType" 20 | 21 | /** 22 | * コンフィグから値を取得する。 23 | * @param config [CustomConfig] 24 | * @param path コンフィグパス 25 | * @param notFoundError 存在しないデータの場合にエラーを出す 26 | * @return 取得した値 27 | * @since 1.5.0 28 | */ 29 | override fun get( 30 | config: CustomConfig, 31 | path: String, 32 | notFoundError: Boolean 33 | ): List { 34 | return config.get(path, ConfigDataType.StringList, notFoundError)?.mapNotNull { 35 | stringToPotionEffectType(it) ?: config.nullError("$path.$it", typeName).run { null } 36 | }.orEmpty() 37 | } 38 | 39 | /** 40 | * コンフィグの値を変更する。 41 | * @param config [CustomConfig] 42 | * @param path コンフィグパス 43 | * @param value 設定する値 44 | * @since 1.5.0 45 | */ 46 | override fun set( 47 | config: CustomConfig, 48 | path: String, 49 | value: List? 50 | ) { 51 | config.set(path, ConfigDataType.StringList, value?.map(::potionEffectTypeToString)) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/list/ConfigSerializableItemStackListDataType.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("DEPRECATION") 2 | 3 | package com.github.syari.spigot.api.config.type.data.list 4 | 5 | import com.github.syari.spigot.api.config.CustomConfig 6 | import com.github.syari.spigot.api.config.type.ConfigDataType 7 | import org.bukkit.inventory.ItemStack 8 | 9 | /** 10 | * アイテムスタックのリスト。シリアライズを使用して保存・読込を行う。 11 | * @see ConfigDataType.SerializableItemStackList 12 | * @since 1.6.0 13 | */ 14 | object ConfigSerializableItemStackListDataType : ConfigDataType> { 15 | /** 16 | * データ型の名前。 17 | * @since 1.6.0 18 | */ 19 | override val typeName = "ItemStack(Serialize)" 20 | 21 | /** 22 | * コンフィグから値を取得する。 23 | * @param config [CustomConfig] 24 | * @param path コンフィグパス 25 | * @param notFoundError 存在しないデータの場合にエラーを出す 26 | * @return 取得した値 27 | * @since 1.6.0 28 | */ 29 | override fun get( 30 | config: CustomConfig, 31 | path: String, 32 | notFoundError: Boolean 33 | ): List { 34 | return config.getListUnsafe(path, "List<$typeName>", notFoundError) 35 | } 36 | 37 | /** 38 | * @param path コンフィグパス 39 | * @param value 設定する値 40 | * @since 1.6.0 41 | */ 42 | override fun set( 43 | config: CustomConfig, 44 | path: String, 45 | value: List? 46 | ) { 47 | config.setUnsafe(path, value) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/list/ConfigSoundByKeyListDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data.list 2 | 3 | import com.github.syari.spigot.api.UnsupportedMinecraftVersion 4 | import com.github.syari.spigot.api.config.type.ConfigDataType 5 | import com.github.syari.spigot.api.config.type.data.ConfigSoundByKeyDataType 6 | import org.bukkit.Sound 7 | 8 | /** 9 | * サウンドの種類のリスト。固有名から取得する。 10 | * @see ConfigDataType.SoundByKeyList 11 | * @since 1.6.0 12 | */ 13 | @UnsupportedMinecraftVersion(8, 9, 10, 11, 12, 13, 14, 15) 14 | object ConfigSoundByKeyListDataType : ConfigEnumListDataType { 15 | /** 16 | * データ型の名前。 17 | * @since 1.6.0 18 | */ 19 | override val typeName = "Sound(Key)" 20 | 21 | /** 22 | * 列挙型の要素を名前から取得する。 23 | * @param name 名前 24 | * @return 取得した要素 25 | * @since 1.6.0 26 | */ 27 | override fun stringToEnum(name: String) = ConfigSoundByKeyDataType.stringToEnum(name) 28 | } 29 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/list/ConfigSoundByNameListDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data.list 2 | 3 | import com.github.syari.spigot.api.config.type.ConfigDataType 4 | import com.github.syari.spigot.api.config.type.data.ConfigSoundByNameDataType 5 | import org.bukkit.Sound 6 | 7 | /** 8 | * サウンドの種類のリスト。名前から取得する。 9 | * @see ConfigDataType.SoundByNameList 10 | * @since 1.6.0 11 | */ 12 | object ConfigSoundByNameListDataType : ConfigEnumListDataType { 13 | /** 14 | * データ型の名前。 15 | * @since 1.6.0 16 | */ 17 | override val typeName = "Sound(Name)" 18 | 19 | /** 20 | * 列挙型の要素を名前から取得する。 21 | * @param name 名前 22 | * @return 取得した要素 23 | * @since 1.6.0 24 | */ 25 | override fun stringToEnum(name: String) = ConfigSoundByNameDataType.stringToEnum(name) 26 | } 27 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/list/ConfigStringListDataType.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("DEPRECATION") 2 | 3 | package com.github.syari.spigot.api.config.type.data.list 4 | 5 | import com.github.syari.spigot.api.config.CustomConfig 6 | import com.github.syari.spigot.api.config.type.ConfigDataType 7 | 8 | /** 9 | * 文字列型のリスト。 10 | * @see ConfigDataType.StringList 11 | * @since 1.3.0 12 | */ 13 | object ConfigStringListDataType : ConfigDataType> { 14 | /** 15 | * データ型の名前。 16 | * @since 1.3.0 17 | */ 18 | override val typeName = "String" 19 | 20 | /** 21 | * コンフィグから値を取得する。 22 | * @param config [CustomConfig] 23 | * @param path コンフィグパス 24 | * @param notFoundError 存在しないデータの場合にエラーを出す 25 | * @return 取得した値 26 | * @since 1.3.0 27 | */ 28 | override fun get( 29 | config: CustomConfig, 30 | path: String, 31 | notFoundError: Boolean 32 | ): List { 33 | return config.getListUnsafe(path, "List<$typeName>", notFoundError) 34 | } 35 | 36 | /** 37 | * @param path コンフィグパス 38 | * @param value 設定する値 39 | * @since 1.3.0 40 | */ 41 | override fun set( 42 | config: CustomConfig, 43 | path: String, 44 | value: List? 45 | ) { 46 | config.setUnsafe(path, value) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/list/ConfigUUIDListDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data.list 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import com.github.syari.spigot.api.config.type.ConfigDataType 5 | import com.github.syari.spigot.api.uuid.uuidOrNull 6 | import java.util.UUID 7 | 8 | /** 9 | * UUIDのリスト。 10 | * @see ConfigDataType.UUIDList 11 | * @since 1.3.4 12 | */ 13 | object ConfigUUIDListDataType : ConfigDataType> { 14 | /** 15 | * データ型の名前。 16 | * @since 1.3.4 17 | */ 18 | override val typeName = "UUID" 19 | 20 | /** 21 | * コンフィグから値を取得する。 22 | * @param config [CustomConfig] 23 | * @param path コンフィグパス 24 | * @param notFoundError 存在しないデータの場合にエラーを出す 25 | * @return 取得した値 26 | * @since 1.3.4 27 | */ 28 | override fun get( 29 | config: CustomConfig, 30 | path: String, 31 | notFoundError: Boolean 32 | ): List { 33 | return config.get(path, ConfigDataType.StringList, notFoundError)?.mapNotNull { 34 | uuidOrNull(it) ?: config.formatMismatchError(path).run { null } 35 | }.orEmpty() 36 | } 37 | 38 | /** 39 | * コンフィグの値を変更する。 40 | * @param config [CustomConfig] 41 | * @param path コンフィグパス 42 | * @param value 設定する値 43 | * @since 1.3.4 44 | */ 45 | override fun set( 46 | config: CustomConfig, 47 | path: String, 48 | value: List? 49 | ) { 50 | config.set(path, ConfigDataType.StringList, value?.map(UUID::toString)) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/list/ConfigVectorListDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data.list 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import com.github.syari.spigot.api.config.type.ConfigDataType 5 | import com.github.syari.spigot.api.config.type.data.ConfigVectorDataType.stringToVector 6 | import com.github.syari.spigot.api.config.type.data.ConfigVectorDataType.vectorToString 7 | import org.bukkit.util.Vector 8 | 9 | /** 10 | * ベクトルのリスト。 11 | * @see ConfigDataType.VectorList 12 | * @since 1.4.0 13 | */ 14 | object ConfigVectorListDataType : ConfigDataType> { 15 | /** 16 | * データ型の名前。 17 | * @since 1.4.0 18 | */ 19 | override val typeName = "Vector" 20 | 21 | /** 22 | * コンフィグから値を取得する。 23 | * @param config [CustomConfig] 24 | * @param path コンフィグパス 25 | * @param notFoundError 存在しないデータの場合にエラーを出す 26 | * @return 取得した値 27 | * @since 1.4.0 28 | */ 29 | override fun get( 30 | config: CustomConfig, 31 | path: String, 32 | notFoundError: Boolean 33 | ): List { 34 | return config.get(path, ConfigDataType.StringList, notFoundError)?.mapNotNull { 35 | stringToVector(config, "$path.$it", it) ?: config.nullError("$path.$it", typeName).run { null } 36 | }.orEmpty() 37 | } 38 | 39 | /** 40 | * コンフィグの値を変更する。 41 | * @param config [CustomConfig] 42 | * @param path コンフィグパス 43 | * @param value 設定する値 44 | * @since 1.4.0 45 | */ 46 | override fun set( 47 | config: CustomConfig, 48 | path: String, 49 | value: List? 50 | ) { 51 | config.set(path, ConfigDataType.StringList, value?.map(::vectorToString)) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/data/list/ConfigWorldListDataType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.data.list 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import com.github.syari.spigot.api.config.type.ConfigDataType 5 | import org.bukkit.Bukkit 6 | import org.bukkit.World 7 | 8 | /** 9 | * ワールドのリスト。 10 | * @see ConfigDataType.WorldList 11 | * @since 1.3.0 12 | */ 13 | object ConfigWorldListDataType : ConfigDataType> { 14 | /** 15 | * データ型の名前。 16 | * @since 1.3.0 17 | */ 18 | override val typeName = "World" 19 | 20 | /** 21 | * コンフィグから値を取得する。 22 | * @param config [CustomConfig] 23 | * @param path コンフィグパス 24 | * @param notFoundError 存在しないデータの場合にエラーを出す 25 | * @return 取得した値 26 | * @since 1.3.0 27 | */ 28 | override fun get( 29 | config: CustomConfig, 30 | path: String, 31 | notFoundError: Boolean 32 | ): List { 33 | return config.get(path, ConfigDataType.StringList, notFoundError)?.mapNotNull { 34 | Bukkit.getWorld(it) ?: config.nullError("$path.$it", typeName).run { null } 35 | }.orEmpty() 36 | } 37 | 38 | /** 39 | * コンフィグの値を変更する。 40 | * @param config [CustomConfig] 41 | * @param path コンフィグパス 42 | * @param value 設定する値 43 | * @since 1.3.0 44 | */ 45 | override fun set( 46 | config: CustomConfig, 47 | path: String, 48 | value: List? 49 | ) { 50 | config.set(path, ConfigDataType.StringList, value?.map(World::getName)) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/config/type/section/ConfigIntSectionType.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.config.type.section 2 | 3 | import com.github.syari.spigot.api.config.CustomConfig 4 | import com.github.syari.spigot.api.config.type.ConfigSectionType 5 | 6 | /** 7 | * 整数型。 8 | * @see ConfigSectionType.Int 9 | * @since 1.3.0 10 | */ 11 | object ConfigIntSectionType : ConfigSectionType { 12 | /** 13 | * データ型の名前。 14 | * @since 1.3.0 15 | */ 16 | override val typeName = "Int" 17 | 18 | /** 19 | * 文字列を [Int] に変換する。 20 | * @param config [CustomConfig] 21 | * @param path セクションパス 22 | * @param value セクションキー 23 | * @since 1.3.0 24 | */ 25 | override fun parse( 26 | config: CustomConfig, 27 | path: String, 28 | value: String 29 | ): Int? { 30 | return value.toIntOrNull() ?: config.typeMismatchError(path, typeName).run { null } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/event/EventAction.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.event 2 | 3 | import org.bukkit.event.Cancellable 4 | import org.bukkit.event.Event 5 | import org.bukkit.event.EventPriority 6 | 7 | /** 8 | * 登録のネストをエラーにするためのクラス。 9 | * @since 2.4.0 10 | */ 11 | object EventAction { 12 | /** 13 | * イベントを定義する。 14 | * 15 | * 以下のようなコードをエラーにするためのメソッド。 16 | * ```kotlin 17 | * plugin.events { 18 | * event { 19 | * event { // ERROR 20 | * 21 | * } 22 | * } 23 | * } 24 | * ``` 25 | * 26 | * @param T イベント 27 | * @param priority 優先度 default: NORMAL 28 | * @param ignoreCancelled キャンセルされていたら実行しない default: false 29 | * @param action 実行する処理 30 | * @see com.github.syari.spigot.api.event.Events.event 31 | * @since 2.4.0 32 | */ 33 | @Suppress("unused", "unused_parameter") 34 | @Deprecated("event の中に event を使用できません", level = DeprecationLevel.ERROR) 35 | inline fun event( 36 | priority: EventPriority = EventPriority.NORMAL, 37 | ignoreCancelled: Boolean = false, 38 | crossinline action: (T) -> Unit 39 | ) = Unit 40 | 41 | /** 42 | * 条件に一致した時に特定のイベントをキャンセルする。 43 | * 44 | * 以下のようなコードをエラーにするためのメソッド。 45 | * ```kotlin 46 | * plugin.events { 47 | * event { 48 | * event { // ERROR 49 | * 50 | * } 51 | * } 52 | * } 53 | * ``` 54 | * 55 | * @param T イベント 56 | * @param priority 優先度 default: NORMAL 57 | * @param action 条件 58 | * @see com.github.syari.spigot.api.event.Events.cancelEventIf 59 | * @since 2.4.0 60 | */ 61 | @Suppress("unused", "unused_parameter") 62 | @Deprecated("event の中に event を使用できません", level = DeprecationLevel.ERROR) 63 | inline fun cancelEventIf( 64 | priority: EventPriority = EventPriority.NORMAL, 65 | crossinline action: EventAction.(T) -> Boolean 66 | ) where T : Event, T : Cancellable = Unit 67 | 68 | /** 69 | * 条件に一致しなかった時に特定のイベントをキャンセルする。 70 | * 71 | * 以下のようなコードをエラーにするためのメソッド。 72 | * ```kotlin 73 | * plugin.events { 74 | * event { 75 | * event { // ERROR 76 | * 77 | * } 78 | * } 79 | * } 80 | * ``` 81 | * 82 | * @param T イベント 83 | * @param priority 優先度 default: NORMAL 84 | * @param action 条件 85 | * @see com.github.syari.spigot.api.event.Events.cancelEventIfNot 86 | * @since 2.4.0 87 | */ 88 | @Suppress("unused", "unused_parameter") 89 | @Deprecated("event の中に event を使用できません", level = DeprecationLevel.ERROR) 90 | inline fun cancelEventIfNot( 91 | priority: EventPriority = EventPriority.NORMAL, 92 | crossinline action: EventAction.(T) -> Boolean 93 | ) where T : Event, T : Cancellable = Unit 94 | } 95 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/event/Events.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.event 2 | 3 | import org.bukkit.event.Cancellable 4 | import org.bukkit.event.Event 5 | import org.bukkit.event.EventPriority 6 | import org.bukkit.event.Listener 7 | import org.bukkit.plugin.java.JavaPlugin 8 | 9 | /** 10 | * [EventRegister.register] で使われている。イベントの定義を行える。 11 | * @param plugin 登録先のプラグイン 12 | * @since 1.0.0 13 | */ 14 | class Events internal constructor(val plugin: JavaPlugin) : Listener { 15 | /** 16 | * イベントの登録を行う。 17 | * 18 | * 以下のようなコードをエラーにするためのメソッド。 19 | * ```kotlin 20 | * plugin.events { 21 | * plugin.events { // ERROR 22 | * 23 | * } 24 | * } 25 | * ``` 26 | * 27 | * @param action イベント一覧 28 | * @see com.github.syari.spigot.api.event.events 29 | * @since 2.4.0 30 | */ 31 | @Suppress("unused", "unused_parameter") 32 | @Deprecated("events の中で events を使用できません", level = DeprecationLevel.ERROR) 33 | fun JavaPlugin.events(action: EventsAction) = Unit 34 | 35 | /** 36 | * イベントを定義する。 37 | * @param T イベント 38 | * @param priority 優先度 default: NORMAL 39 | * @param ignoreCancelled キャンセルされていたら実行しない default: false 40 | * @param action 実行する処理 41 | * @since 1.0.0 42 | */ 43 | inline fun event( 44 | priority: EventPriority = EventPriority.NORMAL, 45 | ignoreCancelled: Boolean = false, 46 | crossinline action: EventAction.(T) -> Unit 47 | ) { 48 | plugin.server.pluginManager.registerEvent( 49 | T::class.java, 50 | this, 51 | priority, 52 | { _, event -> 53 | (event as? T)?.let { EventAction.action(it) } 54 | }, 55 | plugin, 56 | ignoreCancelled 57 | ) 58 | } 59 | 60 | /** 61 | * 条件に一致した時に特定のイベントをキャンセルする。 62 | * @param T イベント 63 | * @param priority 優先度 default: NORMAL 64 | * @param action 条件 65 | * @since 1.0.0 66 | */ 67 | inline fun cancelEventIf( 68 | priority: EventPriority = EventPriority.NORMAL, 69 | crossinline action: EventAction.(T) -> Boolean 70 | ) where T : Event, T : Cancellable { 71 | event(priority, true) { 72 | it.isCancelled = action(it) 73 | } 74 | } 75 | 76 | /** 77 | * 条件に一致しなかった時に特定のイベントをキャンセルする。 78 | * @param T イベント 79 | * @param priority 優先度 default: NORMAL 80 | * @param action 条件 81 | * @since 1.0.0 82 | */ 83 | inline fun cancelEventIfNot( 84 | priority: EventPriority = EventPriority.NORMAL, 85 | crossinline action: EventAction.(T) -> Boolean 86 | ) where T : Event, T : Cancellable { 87 | cancelEventIf(priority) { 88 | action(it).not() 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/event/extension.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.event 2 | 3 | import org.bukkit.plugin.java.JavaPlugin 4 | 5 | /** 6 | * `Events.() -> Unit` 7 | * @since 2.3.3 8 | */ 9 | typealias EventsAction = Events.() -> Unit 10 | 11 | /** 12 | * イベントの登録を行う。 13 | * @param action イベント一覧 14 | * @since 2.2.4 15 | */ 16 | fun JavaPlugin.events(action: EventsAction) { 17 | Events(this).action() 18 | } 19 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/inventory/ClickEventAction.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.inventory 2 | 3 | import org.bukkit.event.inventory.ClickType 4 | import org.bukkit.event.inventory.InventoryClickEvent 5 | import java.util.Objects 6 | 7 | /** 8 | * アイテムをクリックした時に処理を実行する。 9 | * @param slots アイテムの場所 10 | * @param types クリックの種類 11 | * @param action 実行処理 12 | * @since 2.3.0 13 | */ 14 | class ClickEventAction internal constructor( 15 | private val slots: Iterable, 16 | private val types: Array?, 17 | private val action: (InventoryClickEvent) -> Unit 18 | ) { 19 | /** 20 | * アイテムの場所とクリックの種類が一致していれば処理を実行する。 21 | * @param slot アイテムの場所 22 | * @param type クリックの種類 23 | * @param event クリックイベント 24 | * @since 2.3.0 25 | */ 26 | internal operator fun invoke( 27 | slot: Int, 28 | type: ClickType, 29 | event: InventoryClickEvent 30 | ) { 31 | if (slots.contains(slot) && (types?.contains(type) != false)) { 32 | action(event) 33 | } 34 | } 35 | 36 | override fun hashCode(): Int { 37 | return Objects.hash(slots, types) 38 | } 39 | 40 | override fun equals(other: Any?): Boolean { 41 | if (this === other) return true 42 | if (other !is ClickEventAction) return false 43 | if (slots != other.slots) return false 44 | if (types != null) { 45 | if (other.types == null) return false 46 | return types.contentEquals(other.types) 47 | } else { 48 | return other.types == null 49 | } 50 | } 51 | 52 | /** 53 | * インベントリスロットに対して処理を定義する。 54 | * @param slots アイテムの場所 55 | * @since 2.3.0 56 | */ 57 | class Builder internal constructor( 58 | private val slots: Iterable 59 | ) { 60 | private val events = mutableSetOf() 61 | 62 | /** 63 | * クリックの種類が一致した時に実行する。 64 | * @param clickType クリックタイプ 65 | * @param action 実行する処理 66 | * @since 2.3.0 67 | */ 68 | fun onClick( 69 | vararg clickType: ClickType, 70 | action: (InventoryClickEvent) -> Unit 71 | ) { 72 | events.add(ClickEventAction(slots, clickType, action)) 73 | } 74 | 75 | /** 76 | * アイテムがクリックされた時に必ず実行する。 77 | * @param action 実行する処理 78 | * @since 2.3.0 79 | */ 80 | fun onClick( 81 | action: (InventoryClickEvent) -> Unit 82 | ) { 83 | events.add(ClickEventAction(slots, null, action)) 84 | } 85 | 86 | /** 87 | * [ClickEventAction] を生成する。 88 | * @return [ClickEventAction] 89 | * @since 2.3.0 90 | */ 91 | internal fun build() = events.toSet() 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/inventory/CustomInventory.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.inventory 2 | 3 | import com.github.syari.spigot.api.EasySpigotAPIOption 4 | import com.github.syari.spigot.api.event.events 5 | import com.github.syari.spigot.api.inventory.InventoryPlayerData.Companion.inventoryPlayerData 6 | import com.github.syari.spigot.api.item.itemStack 7 | import com.github.syari.spigot.api.scheduler.runTaskLater 8 | import com.github.syari.spigot.api.uuid.UUIDPlayer 9 | import org.bukkit.Material 10 | import org.bukkit.entity.HumanEntity 11 | import org.bukkit.entity.Player 12 | import org.bukkit.event.inventory.InventoryClickEvent 13 | import org.bukkit.event.inventory.InventoryCloseEvent 14 | import org.bukkit.inventory.Inventory 15 | import org.bukkit.inventory.ItemStack 16 | import org.bukkit.plugin.java.JavaPlugin 17 | 18 | /** 19 | * インベントリの設定をするクラス 20 | * @param inventory 対象のインベントリ 21 | * @param id インベントリの識別子 22 | * @since 2.3.0 23 | */ 24 | class CustomInventory internal constructor( 25 | val inventory: Inventory, 26 | val id: String 27 | ) { 28 | companion object { 29 | /** 30 | * [CustomInventory] を利用する場合、あらかじめ呼び出しておく必要がある。 31 | * @param plugin イベントの定義に使うプラグイン 32 | * @see EasySpigotAPIOption.useCustomInventory 33 | * @since 2.3.3 34 | */ 35 | internal fun onEnableInternal(plugin: JavaPlugin) { 36 | plugin.events { 37 | event { 38 | val player = it.whoClicked as? Player ?: return@event 39 | val uuidPlayer = UUIDPlayer.from(player) 40 | uuidPlayer.inventoryPlayerData?.run { 41 | if (cancel) { 42 | it.isCancelled = true 43 | } 44 | if (it.inventory == it.clickedInventory) { 45 | clickEvents.toList().forEach { action -> 46 | action(it.slot, it.click, it) 47 | } 48 | } 49 | onClick?.invoke(it) 50 | } 51 | } 52 | event { 53 | val player = it.player as Player 54 | val uuidPlayer = UUIDPlayer.from(player) 55 | uuidPlayer.inventoryPlayerData?.run { 56 | onClose?.invoke(it) 57 | uuidPlayer.inventoryPlayerData = null 58 | plugin.runTaskLater(5) { 59 | player.updateInventory() 60 | } 61 | } 62 | } 63 | } 64 | } 65 | } 66 | 67 | init { 68 | if (EasySpigotAPIOption.isEnableCustomInventory.not()) { 69 | throw IllegalStateException("CustomInventory is not available. EasySpigotAPIOption::useInventory must be called when the server started.") 70 | } 71 | } 72 | 73 | private val clickEvents = mutableSetOf() 74 | 75 | /** 76 | * クリックイベントをキャンセルする。 77 | * @since 2.3.0 78 | */ 79 | var isCancel = true 80 | 81 | /** 82 | * クリックイベントを定義する。 83 | * @since 2.3.0 84 | */ 85 | var onClick: ((InventoryClickEvent) -> Unit)? = null 86 | 87 | /** 88 | * クローズイベントを定義する。 89 | * @since 2.3.0 90 | */ 91 | var onClose: ((InventoryCloseEvent) -> Unit)? = null 92 | 93 | /** 94 | * アイテムを配置する。 95 | * @param slot アイテムの場所 96 | * @param item アイテム 97 | * @param onClick クリック時の処理 98 | * @since 2.3.0 99 | */ 100 | fun item( 101 | slot: Int, 102 | item: ItemStack, 103 | onClick: ClickEventBuilderAction? = null 104 | ) { 105 | item(listOf(slot), item, onClick) 106 | } 107 | 108 | /** 109 | * アイテムを配置する。 110 | * @param slot アイテムの場所 111 | * @param item アイテム 112 | * @param onClick クリック時の処理 113 | * @since 2.3.0 114 | */ 115 | fun item( 116 | slot: Iterable, 117 | item: ItemStack, 118 | onClick: ClickEventBuilderAction? = null 119 | ) { 120 | slot.filter { it in 0 until inventory.size }.let { 121 | it.forEach { i -> 122 | inventory.setItem(i, item) 123 | } 124 | if (onClick != null) { 125 | clickEvents.addAll(ClickEventAction.Builder(it).apply(onClick).build()) 126 | } 127 | } 128 | } 129 | 130 | /** 131 | * アイテムを配置する。 132 | * @param slot アイテムの場所 133 | * @param material アイテムタイプ 134 | * @param display アイテム名 135 | * @param lore アイテムの説明文 136 | * @param onClick クリック時の処理 137 | * @since 2.3.0 138 | */ 139 | fun item( 140 | slot: Int, 141 | material: Material, 142 | display: String = "", 143 | lore: List = listOf(), 144 | onClick: ClickEventBuilderAction? = null 145 | ) { 146 | item(listOf(slot), material, display, lore, onClick) 147 | } 148 | 149 | /** 150 | * アイテムを配置する。 151 | * @param slot アイテムの場所 152 | * @param material アイテムタイプ 153 | * @param display アイテム名 154 | * @param lore アイテムの説明文 155 | * @param onClick クリック時の処理 156 | * @since 2.3.0 157 | */ 158 | fun item( 159 | slot: Iterable, 160 | material: Material, 161 | display: String = "", 162 | lore: List = listOf(), 163 | onClick: ClickEventBuilderAction? = null 164 | ) { 165 | item(slot, itemStack(material, display, lore), onClick) 166 | } 167 | 168 | /** 169 | * アイテムを配置する。 170 | * @param slot アイテムの場所 171 | * @param material アイテムタイプ 172 | * @param display アイテム名 173 | * @param lore アイテムの説明文 174 | * @param onClick クリック時の処理 175 | * @since 2.3.0 176 | */ 177 | fun item( 178 | slot: Int, 179 | material: Material, 180 | display: String = "", 181 | vararg lore: String, 182 | onClick: (ClickEventAction.Builder.() -> Unit)? = null 183 | ) { 184 | item(listOf(slot), material, display, lore.toList(), onClick) 185 | } 186 | 187 | /** 188 | * アイテムを配置する。 189 | * @param slot アイテムの場所 190 | * @param material アイテムタイプ 191 | * @param display アイテム名 192 | * @param lore アイテムの説明文 193 | * @param onClick クリック時の処理 194 | * @since 2.3.0 195 | */ 196 | fun item( 197 | slot: Iterable, 198 | material: Material, 199 | display: String = "", 200 | vararg lore: String, 201 | onClick: ClickEventBuilderAction? = null 202 | ) { 203 | item(slot, material, display, lore.toList(), onClick) 204 | } 205 | 206 | /** 207 | * プレイヤーにインベントリを開かせる。 208 | * @param player 対象プレイヤー 209 | * @since 2.3.0 210 | */ 211 | fun open(player: Player) { 212 | player.openInventory(inventory) 213 | player.inventoryPlayerData = InventoryPlayerData(id, isCancel, onClick, onClose, clickEvents) 214 | } 215 | 216 | /** 217 | * プレイヤーのインベントリを閉じる。 218 | * @param player 対象プレイヤー 219 | * @since 2.3.2 220 | */ 221 | fun close(player: Player) { 222 | player.closeInventory() 223 | } 224 | 225 | /** 226 | * このインベントリを開いている全プレイヤーのインベントリを閉じる。 227 | * @since 2.3.2 228 | */ 229 | fun closeAll() { 230 | inventory.viewers.toList().forEach(HumanEntity::closeInventory) 231 | } 232 | } 233 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/inventory/InventoryPlayerData.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.inventory 2 | 3 | import com.github.syari.spigot.api.uuid.UUIDPlayer 4 | import org.bukkit.entity.Player 5 | import org.bukkit.event.inventory.InventoryClickEvent 6 | import org.bukkit.event.inventory.InventoryCloseEvent 7 | 8 | /** 9 | * [CustomInventory] を開いているプレイヤーのデータ 10 | * @param id インベントリの識別子 11 | * @param cancel クリックイベントをキャンセルするか 12 | * @param onClick クリック時の処理 13 | * @param onClose クローズ時の処理 14 | * @param clickEvents アイテムをクリックした時の処理 15 | * @since 2.3.0 16 | */ 17 | internal class InventoryPlayerData( 18 | val id: String, 19 | val cancel: Boolean, 20 | val onClick: ((InventoryClickEvent) -> Unit)?, 21 | val onClose: ((InventoryCloseEvent) -> Unit)?, 22 | val clickEvents: Set 23 | ) { 24 | companion object { 25 | private val list = mutableMapOf() 26 | 27 | /** 28 | * インベントリのプレイヤーデータ 29 | * @since 2.3.0 30 | */ 31 | var UUIDPlayer.inventoryPlayerData 32 | get() = list[this] 33 | internal set(value) { 34 | if (value != null) { 35 | list[this] = value 36 | } else { 37 | list.remove(this) 38 | } 39 | } 40 | 41 | /** 42 | * インベントリのプレイヤーデータ 43 | * @since 2.3.0 44 | */ 45 | var Player.inventoryPlayerData 46 | get() = UUIDPlayer.from(this).inventoryPlayerData 47 | internal set(value) { 48 | UUIDPlayer.from(this).inventoryPlayerData = value 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/inventory/extension.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.inventory 2 | 3 | import com.github.syari.spigot.api.inventory.InventoryPlayerData.Companion.inventoryPlayerData 4 | import com.github.syari.spigot.api.string.toColor 5 | import com.github.syari.spigot.api.uuid.UUIDPlayer 6 | import org.bukkit.Bukkit 7 | import org.bukkit.entity.Player 8 | import org.bukkit.event.inventory.InventoryType 9 | import org.bukkit.inventory.Inventory 10 | 11 | /** 12 | * `CustomInventory.() -> Unit` 13 | */ 14 | typealias CustomInventoryAction = CustomInventory.() -> Unit 15 | 16 | /** 17 | * `ClickEventAction.Builder.() -> Unit` 18 | * @since 2.3.3 19 | */ 20 | typealias ClickEventBuilderAction = ClickEventAction.Builder.() -> Unit 21 | 22 | /** 23 | * [Inventory] から [CustomInventory] を生成する。 24 | * @param inventory [Inventory] 25 | * @param id インベントリの識別子 default: inventory.toString() 26 | * @return [CustomInventory] 27 | * @since 2.3.0 28 | */ 29 | fun inventory( 30 | inventory: Inventory, 31 | id: String = inventory.toString() 32 | ) = CustomInventory(inventory, id) 33 | 34 | /** 35 | * [Inventory] から [CustomInventory] を生成する。 36 | * @param inventory [Inventory] 37 | * @param id インベントリの識別子 default: inventory.toString() 38 | * @return [CustomInventory] 39 | * @since 2.3.0 40 | */ 41 | fun inventory( 42 | inventory: Inventory, 43 | id: String = inventory.toString(), 44 | action: CustomInventory.() -> Unit 45 | ) = inventory(inventory, id).apply(action) 46 | 47 | /** 48 | * [InventoryType] から [CustomInventory] を生成する。 49 | * @param display インベントリのタイトル 50 | * @param type インベントリの種類 51 | * @param id インベントリの識別子 default: display 52 | * @return [CustomInventory] 53 | * @since 2.3.0 54 | */ 55 | fun inventory( 56 | display: String, 57 | type: InventoryType, 58 | id: String = display 59 | ) = inventory(Bukkit.createInventory(null, type, display.toColor()), id) 60 | 61 | /** 62 | * [InventoryType] から [CustomInventory] を生成する。 63 | * @param display インベントリのタイトル 64 | * @param type インベントリの種類 65 | * @param id インベントリの識別子 default: display 66 | * @param action インベントリに対して実行する処理 67 | * @return [CustomInventory] 68 | * @since 2.3.0 69 | */ 70 | fun inventory( 71 | display: String, 72 | type: InventoryType, 73 | id: String = display, 74 | action: CustomInventoryAction 75 | ) = inventory(display, type, id).apply(action) 76 | 77 | /** 78 | * チェストタイプの [CustomInventory] を生成する。 79 | * @param display インベントリのタイトル 80 | * @param line インベントリの行数 default: 3 81 | * @param id インベントリの識別子 default: display 82 | * @return [CustomInventory] 83 | * @since 2.3.0 84 | */ 85 | fun inventory( 86 | display: String, 87 | line: Int = 3, 88 | id: String = display 89 | ) = inventory(Bukkit.createInventory(null, line * 9, display.toColor()), id) 90 | 91 | /** 92 | * チェストタイプの [CustomInventory] を生成する。 93 | * @param display インベントリのタイトル 94 | * @param line インベントリの行数 default: 3 95 | * @param id インベントリの識別子 default: display 96 | * @param action インベントリに対して実行する処理 97 | * @return [CustomInventory] 98 | * @since 2.3.0 99 | */ 100 | fun inventory( 101 | display: String, 102 | line: Int = 3, 103 | id: String = display, 104 | action: CustomInventoryAction 105 | ) = inventory(display, line, id).apply(action) 106 | 107 | /** 108 | * プレイヤーが開いているインベントリの識別子を取得する。 109 | * @since 2.3.0 110 | */ 111 | val UUIDPlayer.inventoryId 112 | get() = inventoryPlayerData?.id 113 | 114 | /** 115 | * プレイヤーが開いているインベントリの識別子を取得する。 116 | * @since 2.3.0 117 | */ 118 | val Player.inventoryId 119 | get() = inventoryPlayerData?.id 120 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/message/extension.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.message 2 | 3 | import com.github.syari.spigot.api.UnsupportedMinecraftVersion 4 | import com.github.syari.spigot.api.string.toColor 5 | import net.md_5.bungee.api.ChatMessageType 6 | import net.md_5.bungee.api.chat.TextComponent 7 | import org.bukkit.command.CommandSender 8 | import org.bukkit.entity.Player 9 | 10 | /** 11 | * チャット欄に色付きメッセージを送信する。 12 | * @param message 送信するメッセージ 13 | * @since 2.3.1 14 | */ 15 | fun CommandSender.sendChatMessage(message: String) { 16 | sendMessage(message.toColor()) 17 | } 18 | 19 | /** 20 | * アクションバーに色付きメッセージを送信する。 21 | * @param message 送信するメッセージ 22 | * @since 2.3.1 23 | */ 24 | @UnsupportedMinecraftVersion(8) 25 | fun Player.sendActionMessage(message: String) { 26 | spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent(message.toColor())) 27 | } 28 | 29 | /** 30 | * タイトルに色付きメッセージを送信する。 31 | * @param title タイトル default: null 32 | * @param subtitle サブタイトル default: null 33 | * @param fadeIn フェードイン default: 10 34 | * @param stay 表示時間 default: 70 35 | * @param fadeOut フェードアウト default: 20 36 | * @since 2.3.1 37 | */ 38 | @UnsupportedMinecraftVersion(8, 9, 10) 39 | fun Player.sendTitleMessage( 40 | title: String? = null, 41 | subtitle: String? = null, 42 | fadeIn: Int = 10, 43 | stay: Int = 70, 44 | fadeOut: Int = 20 45 | ) { 46 | sendTitle(title?.toColor(), subtitle?.toColor(), fadeIn, stay, fadeOut) 47 | } 48 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/nms/CraftItemStackWrapper.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.nms 2 | 3 | /** 4 | * `org.bukkit.craftbukkit.%s.inventory.CraftItemStack` を扱う。 5 | * @param instance CraftItemStack のインスタンス 6 | * @since 1.8.0 7 | */ 8 | class CraftItemStackWrapper(override val instance: Any) : NMSWrapper() { 9 | companion object : NMSWrapper.Companion { 10 | /** 11 | * クラス。 12 | * @since 1.8.0 13 | */ 14 | override val clazz = getNMSClass("org.bukkit.craftbukkit.%s.inventory.CraftItemStack") 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/nms/NBTTagCompoundWrapper.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.nms 2 | 3 | /** 4 | * `net.minecraft.server.%s.NBTTagCompound` を扱う。 5 | * @param instance NBTTagCompound のインスタンス 6 | * @since 1.8.0 7 | */ 8 | class NBTTagCompoundWrapper(override val instance: Any = clazz.getConstructor().newInstance()) : NMSWrapper() { 9 | companion object : NMSWrapper.Companion { 10 | /** 11 | * クラス。 12 | * @since 1.8.0 13 | */ 14 | override val clazz = getNMSClass("net.minecraft.server.%s.NBTTagCompound") 15 | } 16 | 17 | init { 18 | require(clazz.isInstance(instance)) { "instance must be NBTTagCompound" } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/nms/NMSItemStackWrapper.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.nms 2 | 3 | import org.bukkit.inventory.ItemStack 4 | 5 | /** 6 | * `net.minecraft.server.%s.ItemStack` を扱う。 7 | * @param instance NMS の ItemStack のインスタンス 8 | * @since 1.8.0 9 | */ 10 | class NMSItemStackWrapper(override val instance: Any) : NMSWrapper() { 11 | companion object : NMSWrapper.Companion { 12 | /** 13 | * クラス。 14 | * @since 1.8.0 15 | */ 16 | override val clazz = getNMSClass("net.minecraft.server.%s.ItemStack") 17 | } 18 | 19 | /** 20 | * Bukkit の ItemStack から NMS の ItemStack を操作する。 21 | * @param itemStack Bukkit の ItemStack 22 | * @since 1.8.0 23 | */ 24 | constructor(itemStack: ItemStack) : this(CraftItemStackWrapper.clazz.getDeclaredMethod("asNMSCopy", ItemStack::class.java).invoke(null, itemStack)) 25 | 26 | /** 27 | * [org.bukkit.inventory.ItemStack] から [NBTTagCompoundWrapper] のインスタンスを取得する。 28 | * @return NBTTagCompound 29 | * @since 1.8.0 30 | */ 31 | fun getTag(): NBTTagCompoundWrapper? { 32 | return clazz.getDeclaredMethod("getTag").invoke(instance)?.let(::NBTTagCompoundWrapper) 33 | } 34 | 35 | /** 36 | * [org.bukkit.inventory.ItemStack] の NBTTagCompound を変更する。 37 | * @param nbtTagCompound NBTTagCompound 38 | * @since 1.8.0 39 | */ 40 | fun setTag(nbtTagCompound: NBTTagCompoundWrapper) { 41 | clazz.getDeclaredMethod("setTag", NBTTagCompoundWrapper.clazz).invoke(instance, nbtTagCompound.instance) 42 | } 43 | 44 | /** 45 | * [org.bukkit.inventory.ItemStack] から NBTTagCompound を取得する。存在しない場合は空のインスタンスを作成する 46 | * @return NBTTagCompound 47 | * @since 1.8.0 48 | */ 49 | fun getOrCreateTag(): NBTTagCompoundWrapper { 50 | return getTag() ?: NBTTagCompoundWrapper().apply(::setTag) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/nms/NMSWrapper.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.nms 2 | 3 | /** 4 | * NMS を扱う為の基底クラス。 5 | * @since 1.8.0 6 | */ 7 | abstract class NMSWrapper { 8 | /** 9 | * インスタンス。 10 | * @since 1.8.0 11 | */ 12 | abstract val instance: Any 13 | 14 | override fun toString() = instance.toString() 15 | 16 | override fun hashCode() = instance.hashCode() 17 | 18 | override fun equals(other: Any?) = when { 19 | this === other -> true 20 | other is NMSWrapper -> instance == other.instance 21 | else -> false 22 | } 23 | 24 | /** 25 | * [NMSWrapper] の Companion に継承するインターフェース。 26 | * @since 1.8.0 27 | */ 28 | interface Companion { 29 | /** 30 | * クラス。 31 | * @since 1.8.0 32 | */ 33 | val clazz: Class<*> 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/nms/extension.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.nms 2 | 3 | import org.bukkit.Bukkit 4 | 5 | /** 6 | * NMS のバージョン。 7 | * @since 1.8.0 8 | */ 9 | val NMS_VERSION = Bukkit.getServer()::class.java.`package`.name.substring(23) 10 | 11 | /** 12 | * サーバーのメジャーバージョン。1.16.5 であれば 16 になる。 13 | * @since 2.3.0 14 | */ 15 | val SERVER_VERSION = NMS_VERSION.split('_')[1].toInt() 16 | 17 | /** 18 | * NMS のクラスを取得する。`%s` が [NMS_VERSION] に置き換わる。 19 | * ``` 20 | * getNMSClass("net.minecraft.server.%s.NBTTagCompound") 21 | * getNMSClass("org.bukkit.craftbukkit.%s.inventory.CraftItemStack") 22 | * ``` 23 | * @since 1.8.0 24 | */ 25 | fun getNMSClass(className: String): Class<*> = Class.forName(className.format(NMS_VERSION)) 26 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/particle/extension.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.particle 2 | 3 | import com.github.syari.spigot.api.UnsupportedMinecraftVersion 4 | import org.bukkit.Location 5 | import org.bukkit.Particle 6 | import org.bukkit.entity.Player 7 | 8 | /** 9 | * 指定の座標にパーティクルを表示する。 10 | * @param particle パーティクルの種類 11 | * @param count パーティクルの量 default: 1 12 | * @param offsetX X方向の最大誤差 default: 0 13 | * @param offsetY Y方向の最大誤差 default: 0 14 | * @param offsetZ Z方向の最大誤差 default: 0 15 | * @param speed パーティクルの速度 default: 1.0 16 | * @param data パーティクルデータ [Particle.getDataType] default: null 17 | * @param force クライアント設定に関係なく表示するか default: true 18 | * @since 2.1.0 19 | */ 20 | @UnsupportedMinecraftVersion(8, 9, 10, 11, 12) 21 | fun Location.spawnParticle( 22 | particle: Particle, 23 | count: Int = 1, 24 | offsetX: Double = 0.0, 25 | offsetY: Double = 0.0, 26 | offsetZ: Double = 0.0, 27 | speed: Double = 1.0, 28 | data: Any? = null, 29 | force: Boolean = true 30 | ) = world?.spawnParticle(particle, this, count, offsetX, offsetY, offsetZ, speed, data, force) 31 | 32 | /** 33 | * 指定の座標にパーティクルを表示する。 34 | * @param particle パーティクルの種類 35 | * @param count パーティクルの量 default: 1 36 | * @param offsetX X方向の最大誤差 default: 0 37 | * @param offsetY Y方向の最大誤差 default: 0 38 | * @param offsetZ Z方向の最大誤差 default: 0 39 | * @param speed パーティクルの速度 default: 1.0 40 | * @param data パーティクルデータ [Particle.getDataType] default: null 41 | * @since 2.1.0 42 | */ 43 | @UnsupportedMinecraftVersion(8) 44 | fun Location.spawnParticleLegacy( 45 | particle: Particle, 46 | count: Int = 1, 47 | offsetX: Double = 0.0, 48 | offsetY: Double = 0.0, 49 | offsetZ: Double = 0.0, 50 | speed: Double = 1.0, 51 | data: Any? = null 52 | ) = world?.spawnParticle(particle, this, count, offsetX, offsetY, offsetZ, speed, data) 53 | 54 | /** 55 | * 指定の座標にパーティクルを表示する。 56 | * @param particle パーティクルの種類 57 | * @param count パーティクルの量 default: 1 58 | * @param offsetX X方向の最大誤差 default: 0 59 | * @param offsetY Y方向の最大誤差 default: 0 60 | * @param offsetZ Z方向の最大誤差 default: 0 61 | * @param speed パーティクルの速度 default: 1.0 62 | * @param data パーティクルデータ [Particle.getDataType] default: null 63 | * @since 2.1.0 64 | */ 65 | @UnsupportedMinecraftVersion(8) 66 | fun Player.spawnParticleLegacy( 67 | particle: Particle, 68 | count: Int = 1, 69 | offsetX: Double = 0.0, 70 | offsetY: Double = 0.0, 71 | offsetZ: Double = 0.0, 72 | speed: Double = 1.0, 73 | data: Any? = null 74 | ) = spawnParticle(particle, location, count, offsetX, offsetY, offsetZ, speed, data) 75 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/scheduler/extension.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.scheduler 2 | 3 | import org.bukkit.plugin.java.JavaPlugin 4 | import org.bukkit.scheduler.BukkitRunnable 5 | import org.bukkit.scheduler.BukkitTask 6 | 7 | /** 8 | * [BukkitRunnable] のインスタンスを生成する。 9 | * @param action 実行する処理 10 | * @return [BukkitRunnable] 11 | * @since 1.5.1 12 | */ 13 | inline fun bukkitRunnable(crossinline action: BukkitRunnable.() -> Unit) = object : BukkitRunnable() { 14 | override fun run() = action() 15 | } 16 | 17 | /** 18 | * タスクを実行する。 19 | * @param async 非同期か default: false 20 | * @param action 実行する処理 21 | * @return [BukkitTask] 22 | * @since 1.2.0 23 | */ 24 | inline fun JavaPlugin.runTask( 25 | async: Boolean = false, 26 | crossinline action: BukkitRunnable.() -> Unit 27 | ): BukkitTask { 28 | val runnable = bukkitRunnable(action) 29 | return if (async) { 30 | runnable.runTaskAsynchronously(this) 31 | } else { 32 | runnable.runTask(this) 33 | } 34 | } 35 | 36 | /** 37 | * 遅らせてタスクを実行する。 38 | * @param delay 遅らせる時間 tick 39 | * @param async 非同期か default: false 40 | * @param action 遅らせて実行する処理 41 | * @return [BukkitTask] 42 | * @since 1.2.0 43 | */ 44 | inline fun JavaPlugin.runTaskLater( 45 | delay: Long, 46 | async: Boolean = false, 47 | crossinline action: BukkitRunnable.() -> Unit 48 | ): BukkitTask { 49 | val runnable = bukkitRunnable(action) 50 | return if (async) { 51 | runnable.runTaskLaterAsynchronously(this, delay) 52 | } else { 53 | runnable.runTaskLater(this, delay) 54 | } 55 | } 56 | 57 | /** 58 | * 繰り返しタスクを実行する。 59 | * @param period 繰り返し間隔 tick 60 | * @param delay 遅らせる時間 tick default: 0 61 | * @param async 非同期か default: false 62 | * @param action 繰り返し実行する処理 63 | * @return [BukkitTask] 64 | * @since 1.2.0 65 | */ 66 | inline fun JavaPlugin.runTaskTimer( 67 | period: Long, 68 | delay: Long = 0, 69 | async: Boolean = false, 70 | crossinline action: BukkitRunnable.() -> Unit 71 | ): BukkitTask { 72 | val runnable = bukkitRunnable(action) 73 | return if (async) { 74 | runnable.runTaskTimerAsynchronously(this, delay, period) 75 | } else { 76 | runnable.runTaskTimer(this, delay, period) 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/sound/extension.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.sound 2 | 3 | import com.github.syari.spigot.api.UnsupportedMinecraftVersion 4 | import org.bukkit.Location 5 | import org.bukkit.Sound 6 | import org.bukkit.SoundCategory 7 | import org.bukkit.entity.Player 8 | 9 | /** 10 | * 座標の周囲に音を再生する。 11 | * @param sound サウンドの種類 12 | * @param volume 音量 0~1.0 で変更可能。1.0 より大きい値では、聞こえる範囲が [volume] * 16 ブロックになる。 13 | * @param pitch ピッチ 0.5~2.0 で変更可能。0.5から1.0までの値が2倍になると1オクターブ高くなる。 14 | * @since 2.2.0 15 | */ 16 | fun Location.playSoundLegacy( 17 | sound: Sound, 18 | volume: Float = 1F, 19 | pitch: Float = 1F, 20 | ) = world?.playSound(this, sound, volume, pitch) 21 | 22 | /** 23 | * 座標の周囲に音を再生する。 24 | * @param sound サウンドの種類 25 | * @param soundCategory サウンドソース default: [SoundCategory.MASTER] 26 | * @param volume 音量 0~1.0 で変更可能。1.0 より大きい値では、聞こえる範囲が [volume] * 16 ブロックになる。 27 | * @param pitch ピッチ 0.5~2.0 で変更可能。0.5から1.0までの値が2倍になると1オクターブ高くなる。 28 | * @since 2.1.0 29 | */ 30 | @UnsupportedMinecraftVersion(8, 9, 10) 31 | fun Location.playSound( 32 | sound: Sound, 33 | soundCategory: SoundCategory = SoundCategory.MASTER, 34 | volume: Float = 1F, 35 | pitch: Float = 1F, 36 | ) = world?.playSound(this, sound, soundCategory, volume, pitch) 37 | 38 | /** 39 | * 座標の周囲に音を再生する。 40 | * @param sound サウンド 41 | * @param volume 音量 0~1.0 で変更可能。1.0 より大きい値では、聞こえる範囲が [volume] * 16 ブロックになる。 42 | * @param pitch ピッチ 0.5~2.0 で変更可能。0.5から1.0までの値が2倍になると1オクターブ高くなる。 43 | * @since 2.2.0 44 | */ 45 | @UnsupportedMinecraftVersion(8) 46 | fun Location.playSoundLegacy( 47 | sound: String, 48 | volume: Float = 1F, 49 | pitch: Float = 1F, 50 | ) = world?.playSound(this, sound, volume, pitch) 51 | 52 | /** 53 | * 座標の周囲に音を再生する。 54 | * @param sound サウンド 55 | * @param soundCategory サウンドの種類 default: [SoundCategory.MASTER] 56 | * @param volume 音量 0~1.0 で変更可能。1.0 より大きい値では、聞こえる範囲が [volume] * 16 ブロックになる。 57 | * @param pitch ピッチ 0.5~2.0 で変更可能。0.5から1.0までの値が2倍になると1オクターブ高くなる。 58 | * @since 2.1.0 59 | */ 60 | @UnsupportedMinecraftVersion(8, 9, 10) 61 | fun Location.playSound( 62 | sound: String, 63 | soundCategory: SoundCategory = SoundCategory.MASTER, 64 | volume: Float = 1F, 65 | pitch: Float = 1F, 66 | ) = world?.playSound(this, sound, soundCategory, volume, pitch) 67 | 68 | /** 69 | * プレイヤーに対してに音を再生する。 70 | * @param sound サウンド 71 | * @param volume 音量 0~1.0 で変更可能。1.0 より大きい値では、聞こえる範囲が [volume] * 16 ブロックになる。 72 | * @param pitch ピッチ 0.5~2.0 で変更可能。0.5から1.0までの値が2倍になると1オクターブ高くなる。 73 | * @since 2.2.0 74 | */ 75 | fun Player.playSoundLegacy( 76 | sound: Sound, 77 | volume: Float = 1F, 78 | pitch: Float = 1F, 79 | ) = playSound(location, sound, volume, pitch) 80 | 81 | /** 82 | * プレイヤーに対してに音を再生する。 83 | * @param sound サウンド 84 | * @param soundCategory サウンドの種類 default: [SoundCategory.MASTER] 85 | * @param volume 音量 0~1.0 で変更可能。1.0 より大きい値では、聞こえる範囲が [volume] * 16 ブロックになる。 86 | * @param pitch ピッチ 0.5~2.0 で変更可能。0.5から1.0までの値が2倍になると1オクターブ高くなる。 87 | * @since 2.1.0 88 | */ 89 | @UnsupportedMinecraftVersion(8, 9, 10) 90 | fun Player.playSound( 91 | sound: Sound, 92 | soundCategory: SoundCategory = SoundCategory.MASTER, 93 | volume: Float = 1F, 94 | pitch: Float = 1F, 95 | ) = playSound(location, sound, soundCategory, volume, pitch) 96 | 97 | /** 98 | * プレイヤーに対してに音を再生する。 99 | * @param sound サウンド 100 | * @param volume 音量 0~1.0 で変更可能。1.0 より大きい値では、聞こえる範囲が [volume] * 16 ブロックになる。 101 | * @param pitch ピッチ 0.5~2.0 で変更可能。0.5から1.0までの値が2倍になると1オクターブ高くなる。 102 | * @since 2.2.0 103 | */ 104 | @UnsupportedMinecraftVersion(8) 105 | fun Player.playSoundLegacy( 106 | sound: String, 107 | volume: Float = 1F, 108 | pitch: Float = 1F, 109 | ) = playSound(location, sound, volume, pitch) 110 | 111 | /** 112 | * プレイヤーに対してに音を再生する。 113 | * @param sound サウンド 114 | * @param soundCategory サウンドの種類 default: [SoundCategory.MASTER] 115 | * @param volume 音量 0~1.0 で変更可能。1.0 より大きい値では、聞こえる範囲が [volume] * 16 ブロックになる。 116 | * @param pitch ピッチ 0.5~2.0 で変更可能。0.5から1.0までの値が2倍になると1オクターブ高くなる。 117 | * @since 2.1.0 118 | */ 119 | @UnsupportedMinecraftVersion(8, 9, 10) 120 | fun Player.playSound( 121 | sound: String, 122 | soundCategory: SoundCategory = SoundCategory.MASTER, 123 | volume: Float = 1F, 124 | pitch: Float = 1F, 125 | ) = playSound(location, sound, soundCategory, volume, pitch) 126 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/string/extension.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.string 2 | 3 | import org.bukkit.ChatColor 4 | 5 | /** 6 | * [ChatColor.translateAlternateColorCodes] を実行する。`&` を文字コードとして認識する。 7 | * @return 変換後の文字列 8 | * @since 1.4.0 9 | */ 10 | fun String.toColor(): String = ChatColor.translateAlternateColorCodes('&', this) 11 | 12 | /** 13 | * [ChatColor.stripColor] を実行する。 14 | * @return 変換後の文字列 15 | * @since 1.4.0 16 | */ 17 | fun String.toUncolor(): String = ChatColor.stripColor(this)!! 18 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/uuid/UUIDEntity.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.uuid 2 | 3 | import com.github.syari.spigot.api.UnsupportedMinecraftVersion 4 | import org.bukkit.Bukkit 5 | import org.bukkit.entity.Entity 6 | import java.util.UUID 7 | 8 | /** 9 | * [Entity] が持つ [UUID] を操作しやすくしたクラス。 10 | * 11 | * 変数に保存する際には [Entity] ではなく [UUID] で保存することを推奨する。 12 | * @param uniqueId [UUID] 13 | * @since 1.1.0 14 | */ 15 | @UnsupportedMinecraftVersion(8, 9, 10) 16 | data class UUIDEntity(val uniqueId: UUID) : Comparable { 17 | /** 18 | * [Entity] として取得する。 19 | * @since 1.1.0 20 | */ 21 | val entity: Entity? 22 | get() = Bukkit.getEntity(uniqueId) 23 | 24 | /** 25 | * 同じエンティティであるか 26 | * @return [Boolean] 27 | * @since 2.5.0 28 | */ 29 | fun match(other: UUID) = uniqueId == other 30 | 31 | /** 32 | * 同じエンティティであるか 33 | * @return [Boolean] 34 | * @since 2.5.0 35 | */ 36 | fun match(other: Entity) = match(other.uniqueId) 37 | 38 | /** 39 | * [UUIDEntity.uniqueId] を文字列として取得する。 40 | * @see [UUID.toString] 41 | * @since 1.1.0 42 | */ 43 | override fun toString() = uniqueId.toString() 44 | 45 | /** 46 | * [UUIDEntity.uniqueId] を比較する。 47 | * @see [UUID.compareTo] 48 | * @since 1.1.0 49 | */ 50 | override fun compareTo(other: UUIDEntity) = uniqueId.compareTo(other.uniqueId) 51 | 52 | /** 53 | * @see UUIDEntity.from 54 | */ 55 | companion object { 56 | /** 57 | * [Entity] を [UUIDEntity] に変換する。 58 | * @return [UUIDEntity] 59 | * @since 2.5.0 60 | */ 61 | val Entity.uuidEntity 62 | get() = UUIDEntity(uniqueId) 63 | 64 | /** 65 | * [Entity] を [UUIDEntity] に変換する。 66 | * @param entity [Entity] 67 | * @return [UUIDEntity] 68 | * @since 1.1.0 69 | */ 70 | fun from(entity: Entity) = entity.uuidEntity 71 | 72 | /** 73 | * [UUID] を表す文字列から [UUIDEntity] に変換する。 74 | * @param uniqueId [UUID] の文字列 75 | * @return [UUIDEntity] 76 | * @since 1.1.0 77 | */ 78 | fun from(uniqueId: String) = uuidOrNull(uniqueId)?.let(::UUIDEntity) 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/uuid/UUIDPlayer.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.uuid 2 | 3 | import org.bukkit.Bukkit 4 | import org.bukkit.OfflinePlayer 5 | import org.bukkit.entity.Player 6 | import java.util.UUID 7 | 8 | /** 9 | * [Player] が持つ [UUID] を操作しやすくしたクラス。 10 | * 11 | * 変数に保存する際には [Player] や [OfflinePlayer] ではなく [UUID] で保存することを推奨する。 12 | * @param uniqueId [UUID] 13 | * @since 1.1.0 14 | */ 15 | data class UUIDPlayer(val uniqueId: UUID) : Comparable { 16 | /** 17 | * [Player] として取得する。 18 | * @since 1.1.0 19 | */ 20 | val player: Player? 21 | get() = Bukkit.getPlayer(uniqueId) 22 | 23 | /** 24 | * [OfflinePlayer] として取得する。 25 | * @since 1.1.0 26 | */ 27 | val offlinePlayer: OfflinePlayer 28 | get() = Bukkit.getOfflinePlayer(uniqueId) 29 | 30 | /** 31 | * 同じプレイヤーであるか 32 | * @return [Boolean] 33 | * @since 2.5.0 34 | */ 35 | fun match(other: UUID) = uniqueId == other 36 | 37 | /** 38 | * 同じプレイヤーであるか 39 | * @return [Boolean] 40 | * @since 2.5.0 41 | */ 42 | fun match(other: OfflinePlayer) = match(other.uniqueId) 43 | 44 | /** 45 | * [UUIDPlayer.uniqueId] を文字列として取得する。 46 | * @see [UUID.toString] 47 | * @since 1.1.0 48 | */ 49 | override fun toString() = uniqueId.toString() 50 | 51 | /** 52 | * [UUIDPlayer.uniqueId] を比較する。 53 | * @see [UUID.compareTo] 54 | * @since 1.1.0 55 | */ 56 | override fun compareTo(other: UUIDPlayer) = uniqueId.compareTo(other.uniqueId) 57 | 58 | /** 59 | * @see UUIDPlayer.from 60 | */ 61 | companion object { 62 | /** 63 | * [OfflinePlayer] を [UUIDPlayer] に変換する。 64 | * @return [UUIDPlayer] 65 | * @since 2.5.0 66 | */ 67 | val OfflinePlayer.uuidPlayer 68 | get() = UUIDPlayer(uniqueId) 69 | 70 | /** 71 | * [OfflinePlayer] を [UUIDPlayer] に変換する。 72 | * @param player [OfflinePlayer] 73 | * @return [UUIDPlayer] 74 | * @since 1.1.0 75 | */ 76 | fun from(player: OfflinePlayer) = player.uuidPlayer 77 | 78 | /** 79 | * [UUID] を表す文字列から [UUIDPlayer] に変換する。 80 | * @param uniqueId [UUID] の文字列 81 | * @return [UUIDPlayer] 82 | * @since 1.1.0 83 | */ 84 | fun from(uniqueId: String) = uuidOrNull(uniqueId)?.let(::UUIDPlayer) 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/uuid/extension.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.uuid 2 | 3 | import java.util.UUID 4 | 5 | /** 6 | * [UUID.fromString] を実行する。 7 | * @param name [UUID] の文字列 8 | * @return [UUID] 9 | * @since 1.1.0 10 | */ 11 | fun uuid(name: String): UUID = UUID.fromString(name) 12 | 13 | /** 14 | * [uuid] を実行するが、例外が発生した場合は null を返す。 15 | * @param name [UUID] の文字列 16 | * @return [UUID]? 17 | * @since 1.1.0 18 | */ 19 | fun uuidOrNull(name: String): UUID? = try { 20 | uuid(name) 21 | } catch (ex: IllegalArgumentException) { 22 | null 23 | } 24 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/world/Coordinate.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.world 2 | 3 | import org.bukkit.Location 4 | import org.bukkit.World 5 | import org.bukkit.util.NumberConversions 6 | import org.bukkit.util.Vector 7 | import kotlin.math.sqrt 8 | 9 | /** 10 | * ワールドを考慮せず、座標情報のみを保持できるクラス。 11 | * @since 1.4.0 12 | */ 13 | data class Coordinate( 14 | var x: Double, 15 | var y: Double, 16 | var z: Double, 17 | var yaw: Float = 0F, 18 | var pitch: Float = 0F 19 | ) { 20 | /** 21 | * X 座標の小数点以下を切り捨てた値を取得する。ブロックの座標を示す。 22 | * @see Location.getBlockX 23 | * @since 1.4.0 24 | */ 25 | val blockX 26 | get() = Location.locToBlock(x) 27 | 28 | /** 29 | * Y 座標の小数点以下を切り捨てた値を取得する。ブロックの座標を示す。 30 | * @see Location.getBlockY 31 | * @since 1.4.0 32 | */ 33 | val blockY 34 | get() = Location.locToBlock(y) 35 | 36 | /** 37 | * Z 座標の小数点以下を切り捨てた値を取得する。ブロックの座標を示す。 38 | * @see Location.getBlockX 39 | * @since 1.4.0 40 | */ 41 | val blockZ 42 | get() = Location.locToBlock(z) 43 | 44 | /** 45 | * 別の座標の値を足す。 46 | * @param vec 足す座標値 47 | * @return this 48 | * @see Location.add 49 | * @since 1.4.0 50 | */ 51 | fun add(vec: Coordinate): Coordinate { 52 | x += vec.x 53 | y += vec.y 54 | z += vec.z 55 | return this 56 | } 57 | 58 | /** 59 | * 別の座標の値を足す。 60 | * @param vec 足す座標値 61 | * @return this 62 | * @see Location.add 63 | * @since 1.4.0 64 | */ 65 | fun add(vec: Vector): Coordinate { 66 | x += vec.x 67 | y += vec.y 68 | z += vec.z 69 | return this 70 | } 71 | 72 | /** 73 | * 別の座標の値を足す。 74 | * @param x 足すX座標 75 | * @param y 足すY座標 76 | * @param z 足すZ座標 77 | * @return this 78 | * @see Location.add 79 | * @since 1.4.0 80 | */ 81 | fun add(x: Double, y: Double, z: Double): Coordinate { 82 | this.x += x 83 | this.y += y 84 | this.z += z 85 | return this 86 | } 87 | 88 | /** 89 | * 別の座標の値を引く。 90 | * @param vec 引く座標値 91 | * @return this 92 | * @see Location.subtract 93 | * @since 1.4.0 94 | */ 95 | fun subtract(vec: Coordinate): Coordinate { 96 | x -= vec.x 97 | y -= vec.y 98 | z -= vec.z 99 | return this 100 | } 101 | 102 | /** 103 | * 別の座標の値を引く。 104 | * @param vec 引く座標値 105 | * @return this 106 | * @see Location.subtract 107 | * @since 1.4.0 108 | */ 109 | fun subtract(vec: Vector): Coordinate { 110 | x -= vec.x 111 | y -= vec.y 112 | z -= vec.z 113 | return this 114 | } 115 | 116 | /** 117 | * 別の座標の値を引く。 118 | * @param x 引くX座標 119 | * @param y 引くY座標 120 | * @param z 引くZ座標 121 | * @return this 122 | * @see Location.subtract 123 | * @since 1.4.0 124 | */ 125 | fun subtract(x: Double, y: Double, z: Double): Coordinate { 126 | this.x -= x 127 | this.y -= y 128 | this.z -= z 129 | return this 130 | } 131 | 132 | /** 133 | * 座標の大きさ `sqrt(x^2 + y^2 + z^2)` を取得する。 134 | * @see Location.length 135 | * @since 1.4.0 136 | */ 137 | val length 138 | get() = sqrt(lengthSquared) 139 | 140 | /** 141 | * 座標の大きさの二乗 `x^2 + y^2 + z^2` を取得する。 142 | * @see Location.lengthSquared 143 | * @since 1.4.0 144 | */ 145 | val lengthSquared 146 | get() = NumberConversions.square(x) + NumberConversions.square(y) + NumberConversions.square(z) 147 | 148 | /** 149 | * 別の座標との距離を取得する。 150 | * @param c 距離を取得する片方の座標 151 | * @return 距離 152 | * @see Location.distance 153 | * @since 1.4.0 154 | */ 155 | fun distance(c: Coordinate) = sqrt(distanceSquared(c)) 156 | 157 | /** 158 | * 別の座標との距離の二乗を取得する。 159 | * @param c 距離を取得する片方の座標 160 | * @return 距離の二乗 161 | * @see Location.distanceSquared 162 | * @since 1.4.0 163 | */ 164 | fun distanceSquared(c: Coordinate) = NumberConversions.square(x - c.x) + NumberConversions.square(y - c.y) + NumberConversions.square(z - c.z) 165 | 166 | /** 167 | * XYZ 座標を定数倍する。 168 | * @param m 定数倍 169 | * @return this 170 | * @see Location.multiply 171 | * @since 1.4.0 172 | */ 173 | fun multiply(m: Double): Coordinate { 174 | x *= m 175 | y *= m 176 | z *= m 177 | return this 178 | } 179 | 180 | /** 181 | * XYZ 座標を 0 にする。 182 | * @return this 183 | * @see Location.multiply 184 | * @since 1.4.0 185 | */ 186 | fun zero(): Coordinate { 187 | x = 0.0 188 | y = 0.0 189 | z = 0.0 190 | return this 191 | } 192 | 193 | /** 194 | * [Vector] に変換する。 195 | * @return [Vector] 196 | * @see Location.toVector 197 | * @since 1.4.0 198 | */ 199 | fun toVector() = Vector(x, y, z) 200 | 201 | /** 202 | * ワールドの情報を加えて、[Location] に変換する。 203 | * @param world ワールド 204 | * @return [Location] 205 | * @since 1.4.0 206 | */ 207 | fun toLocation(world: World?) = Location(world, x, y, z, yaw, pitch) 208 | } 209 | -------------------------------------------------------------------------------- /api/src/main/kotlin/com/github/syari/spigot/api/world/Region.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.world 2 | 3 | import org.bukkit.Location 4 | import org.bukkit.World 5 | import org.bukkit.util.Vector 6 | 7 | /** 8 | * 領域を表す。 9 | * @since 1.4.0 10 | */ 11 | class Region( 12 | val world: World, 13 | pos1: Vector, 14 | pos2: Vector 15 | ) { 16 | /** 17 | * 領域の片方の頂点 18 | * @since 1.4.0 19 | */ 20 | val pos1: Vector 21 | 22 | /** 23 | * 領域の片方の頂点 24 | * @since 1.4.0 25 | */ 26 | val pos2: Vector 27 | 28 | init { 29 | val rangeX = range(pos1.x, pos2.x) 30 | val rangeY = range(pos1.y, pos2.y) 31 | val rangeZ = range(pos1.z, pos2.z) 32 | this.pos1 = Vector(rangeX.first, rangeY.first, rangeZ.first) 33 | this.pos2 = Vector(rangeX.second, rangeY.second, rangeZ.second) 34 | } 35 | 36 | /** 37 | * 領域内の座標かどうかを取得する。 38 | * @param o 判定する座標 39 | * @return 領域内か 40 | * @since 1.4.0 41 | */ 42 | fun inRegion(o: Location): Boolean { 43 | if (o.world != world) return false 44 | if (o.x !in pos1.x..pos2.x) return false 45 | if (o.y !in pos1.y..pos2.y) return false 46 | if (o.z !in pos1.z..pos2.z) return false 47 | return true 48 | } 49 | 50 | companion object { 51 | /** 52 | * 値の小さい方を `first` に、大きい方を `second` に入れた範囲に変換する。 53 | * @since 1.4.0 54 | */ 55 | private fun range(v1: Double, v2: Double): Pair { 56 | return if (v1 < v2) { 57 | v1 to v2 58 | } else { 59 | v2 to v1 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar 2 | 3 | plugins { 4 | kotlin("jvm") version "1.5.30" 5 | id("org.jmailen.kotlinter") version "3.5.1" 6 | id("com.github.johnrengelman.shadow") version "7.0.0" apply false 7 | id("net.minecrell.plugin-yml.bukkit") version "0.5.0" apply false 8 | id("com.github.ben-manes.versions") version "0.39.0" 9 | } 10 | 11 | allprojects { 12 | apply(plugin = "org.jmailen.kotlinter") 13 | apply(plugin = "com.github.ben-manes.versions") 14 | 15 | repositories { 16 | mavenCentral() 17 | } 18 | } 19 | 20 | subprojects { 21 | apply(plugin = "kotlin") 22 | apply(plugin = "com.github.johnrengelman.shadow") 23 | 24 | repositories { 25 | maven(url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/") 26 | maven(url = "https://oss.sonatype.org/content/groups/public/") 27 | } 28 | 29 | val shadowImplementation: Configuration by configurations.creating 30 | configurations["implementation"].extendsFrom(shadowImplementation) 31 | 32 | dependencies { 33 | shadowImplementation(kotlin("stdlib")) 34 | 35 | val minecraftVersion = when (17) { 36 | 8 -> "1.8.8" 37 | 9 -> "1.9.4" 38 | 10 -> "1.10.2" 39 | 11 -> "1.11.2" 40 | 12 -> "1.12.2" 41 | 13 -> "1.13.2" 42 | 14 -> "1.14.4" 43 | 15 -> "1.15.2" 44 | 16 -> "1.16.5" 45 | 17 -> "1.17.1" 46 | else -> error("Unsupported Version") 47 | } 48 | 49 | implementation("org.spigotmc:spigot-api:$minecraftVersion-R0.1-SNAPSHOT") 50 | } 51 | 52 | tasks.withType { 53 | configurations = listOf(shadowImplementation) 54 | archiveClassifier.set("") 55 | } 56 | 57 | java { 58 | sourceCompatibility = JavaVersion.VERSION_1_8 59 | targetCompatibility = JavaVersion.VERSION_1_8 60 | } 61 | } 62 | 63 | project(":api") { 64 | apply(plugin = "net.minecrell.plugin-yml.bukkit") 65 | } 66 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sya-ri/EasySpigotAPI/46c3494e251f8338b608a6dfbc5ec898b8435c76/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /sample/README.md: -------------------------------------------------------------------------------- 1 | # Sample 2 | 3 | ## [Command](command) 4 | コマンドを簡単に作成することができます。`plugin.yml` にコマンドを書く必要はありません。 5 | 6 | ```kotlin 7 | plugin.command("teleport") { 8 | description = "テレポート系の処理を行う" 9 | aliases = listOf("tp", "sample-teleport") 10 | 11 | // タブ補完の設定を行える 12 | tab { 13 | // 引数が何も入力されていない場合の補完候補 14 | argument { 15 | add("here") 16 | addAll(onlinePlayerNames) 17 | } 18 | 19 | // 最初の引数が here の場合の補完候補 20 | argument("here **") { 21 | addAll(onlinePlayerNames) 22 | } 23 | } 24 | 25 | // 実行時の処理を設定できる 26 | execute { 27 | // ... 28 | } 29 | } 30 | ``` 31 | 32 | ## Component 33 | TextComponent 関連の便利な関数・クラスを追加します。 34 | 35 | - [component/extension.kt](../api/src/main/kotlin/com/github/syari/spigot/api/component/extension.kt) 36 | - [component/TextComponentBuilder.kt](../api/src/main/kotlin/com/github/syari/spigot/api/component/TextComponentBuilder.kt) 37 | 38 | ## [Config](config) 39 | コンフィグを簡単に読み込むことができます。 40 | 41 | ```kotlin 42 | plugin.config(sender, "config.yml") { 43 | val message: String? = get("message", ConfigDataType.String) 44 | // ... 45 | } 46 | 47 | // 複数ファイルにまたがったコンフィグも扱えます。 48 | plugin.configDirectory(sender, "mobs") { 49 | // id が指定されていなければファイル名を使用します。 50 | val id: String = get("id", ConfigDataType.String, file.nameWithoutExtension) 51 | section("attribute")?.forEach { name -> 52 | val level = get("attribute.$name.level", ConfigDataType.Int, 1) 53 | // ... 54 | } 55 | // ... 56 | } 57 | ``` 58 | 59 | ## [Event](event) 60 | イベントを簡単に定義・登録することができます。 61 | 62 | ```kotlin 63 | // event<>{} で定義できる 64 | object EventListener { 65 | override fun register() { 66 | plugin.events { 67 | // 入退出メッセージを変更する 68 | event { 69 | it.joinMessage = ">> Join ${it.player.displayName}" 70 | } 71 | event { 72 | it.quitMessage = ">> Quit ${it.player.displayName}" 73 | } 74 | 75 | // プレイヤーに対するダメージをキャンセルする 76 | cancelEventIf { 77 | it.entity is Player 78 | } 79 | 80 | // OP 以外の移動をキャンセルする 81 | cancelEventIfNot { 82 | it.player.isOp 83 | } 84 | } 85 | } 86 | } 87 | ``` 88 | 89 | ## Inventory 90 | インベントリを簡単に扱うことができます。使用する場合は必ず、`EasySpigotAPIOption::useInventory` を実行してください。 91 | 92 | ```kotlin 93 | class Main : JavaPlugin() { 94 | override fun onEnable() { 95 | CustomInventory.onEnable(this) 96 | } 97 | } 98 | 99 | fun open(player: Player) { 100 | inventory("&9&lサンプルインベントリ", 4) { 101 | item(4, Material.PUFFERFISH) { 102 | onClick { 103 | player.playSound(Sound.ENTITY_PLAYER_LEVELUP) 104 | } 105 | } 106 | item(22, Material.ORANGE_STAINED_GLASS_PANE, "&a&l◀ &c&l▶") { 107 | onClick(ClickType.LEFT) { 108 | item(22, Material.LIME_STAINED_GLASS_PANE, "&a&l◀ &c&l▶") 109 | } 110 | onClick(ClickType.MIDDLE) { 111 | item(22, Material.ORANGE_STAINED_GLASS_PANE, "&a&l◀ &c&l▶") 112 | } 113 | onClick(ClickType.RIGHT) { 114 | item(22, Material.RED_STAINED_GLASS_PANE, "&a&l◀ &c&l▶") 115 | } 116 | } 117 | }.open(player) 118 | } 119 | ``` 120 | 121 | ## Item 122 | Item 関連の便利な関数を追加します。 123 | 124 | - [item/extension.kt](../api/src/main/kotlin/com/github/syari/spigot/api/item/extension.kt) 125 | 126 | ## Message 127 | メッセージ関連の便利な関数を追加します。 128 | 129 | - [message/extension.kt](../api/src/main/kotlin/com/github/syari/spigot/api/message/extension.kt) 130 | 131 | ## NMS 132 | NMSを使うための関数・クラスを追加します。 133 | 134 | - [nms/CraftItemStackWrapper.kt](../api/src/main/kotlin/com/github/syari/spigot/api/nms/CraftItemStackWrapper.kt) 135 | - [nms/extension.kt](../api/src/main/kotlin/com/github/syari/spigot/api/nms/extension.kt) 136 | - [nms/NBTTagCompoundWrapper.kt](../api/src/main/kotlin/com/github/syari/spigot/api/nms/NBTTagCompoundWrapper.kt) 137 | - [nms/NMSItemStackWrapper.kt](../api/src/main/kotlin/com/github/syari/spigot/api/nms/NMSItemStackWrapper.kt) 138 | - [nms/NMSWrapper.kt](../api/src/main/kotlin/com/github/syari/spigot/api/nms/NMSWrapper.kt) 139 | 140 | ## Particle 141 | パーティクル関連の便利な関数を追加します。 142 | 143 | - [particle/extension.kt](../api/src/main/kotlin/com/github/syari/spigot/api/particle/extension.kt) 144 | 145 | ## [Scheduler](scheduler) 146 | スケジューラを簡単に使うことができます。 147 | 148 | ```kotlin 149 | // 10秒後に実行されます 150 | runTaskLater(10 * 20) { 151 | // async: false ... サーバーに同期した処理です 152 | server.broadcastMessage("プラグインが有効になってから10秒経ちました") 153 | } 154 | 155 | // 30秒毎に実行されます 156 | runTaskTimer(30 * 20, async = true) { 157 | // async: true ... サーバーに同期していない処理です 158 | server.onlinePlayers.forEach { 159 | it.giveExpLevels(1) 160 | } 161 | } 162 | ``` 163 | 164 | ## Sound 165 | 音関連の便利な関数を追加します。 166 | 167 | - [sound/extension.kt](../api/src/main/kotlin/com/github/syari/spigot/api/sound/extension.kt) 168 | 169 | ## [String](string) 170 | String 関連の便利な関数を追加します。 171 | 172 | 173 | - [string/extension.kt](../api/src/main/kotlin/com/github/syari/spigot/api/string/extension.kt) 174 | 175 | ## [UUID](uuid) 176 | UUID 関連の便利な関数・クラスを追加します。 177 | 178 | - [uuid/extension.kt](../api/src/main/kotlin/com/github/syari/spigot/api/uuid/extension.kt) 179 | 180 | ## World 181 | World 関連の便利なクラスを追加します。 182 | 183 | - [world/Coordinate.kt](../api/src/main/kotlin/com/github/syari/spigot/api/world/Coordinate.kt) 184 | - [world/Region.kt](../api/src/main/kotlin/com/github/syari/spigot/api/world/Region.kt) 185 | 186 | ## Plugin Using EasySpigotAPI 187 | EasySpigotAPI を使用してプラグインを製作した場合は以下に追加してください。参考にしていただけたらと思います。 188 | 189 | 190 | - [SecondStoryServer/SS-Plugins](https://github.com/SecondStoryServer/SS-Plugins) 191 | - [sya-ri/CraftKing](https://github.com/sya-ri/CraftKing) 192 | - [sya-ri/imEntity](https://github.com/sya-ri/imEntity) 193 | - [sya-ri/IncreaseOnSee](https://github.com/sya-ri/IncreaseOnSee) 194 | - [sya-ri/LetsGoTogether](https://github.com/sya-ri/LetsGoTogether) 195 | - [sya-ri/RandomCraft](https://github.com/sya-ri/RandomCraft) 196 | - [sya-ri/RandomSpawnMob](https://github.com/sya-ri/RandomSpawnMob) 197 | - [sya-ri/TalkWithNearPlayer](https://github.com/sya-ri/TalkWithNearPlayer) 198 | - [sya-ri/WorldBorderTester](https://github.com/sya-ri/WorldBorderTester) 199 | - [sya-ri/YouAreMyDoll](https://github.com/sya-ri/YouAreMyDoll) 200 | 201 | [<< 戻る](../README.md) -------------------------------------------------------------------------------- /sample/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar 2 | import net.minecrell.pluginyml.bukkit.BukkitPluginDescription 3 | 4 | tasks.withType { 5 | enabled = false 6 | } 7 | 8 | subprojects { 9 | apply(plugin = "net.minecrell.plugin-yml.bukkit") 10 | 11 | dependencies { 12 | implementation(project(":api")) 13 | } 14 | 15 | tasks.withType { 16 | archiveBaseName.set("EasySpigotAPI-Sample-${project.name}") 17 | } 18 | 19 | configure { 20 | name = "EasySpigotAPI-Sample-${project.name}" 21 | version = project(":api").version.toString() 22 | description = "EasySpigotAPI Sample: ${project.name}" 23 | main = "com.github.syari.spigot.api.sample.${project.name.replace('-', '.')}.Main" 24 | author = "sya_ri" 25 | website = "https://github.com/sya-ri/EasySpigotAPI" 26 | apiVersion = "1.13" 27 | depend = listOf("EasySpigotAPI") 28 | } 29 | 30 | tasks.withType { 31 | configurations = listOf() 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sample/command/README.md: -------------------------------------------------------------------------------- 1 | # Command 2 | 3 | ## [Main.kt](src/main/kotlin/com/github/syari/spigot/api/sample/command/Main.kt) 4 | プラグインのメイン処理です。`onEnable` 内で `TeleportCommand::register` を呼び出すことによりコマンドの登録をしています。 5 | 6 | ```kotlin 7 | class Main : JavaPlugin() { 8 | companion object { 9 | // インスタンスを扱いたい場合、この書き方だとスマートに書ける 10 | internal lateinit var plugin: JavaPlugin 11 | } 12 | 13 | init { 14 | plugin = this 15 | } 16 | 17 | override fun onEnable() { 18 | TeleportCommand.register() 19 | } 20 | } 21 | ``` 22 | 23 | ## [TeleportCommand.kt](src/main/kotlin/com/github/syari/spigot/api/sample/command/TeleportCommand.kt) 24 | コマンドを定義しています。例としてテレポートのコマンドを実装しています。 25 | `JavaPlugin::command` を呼び出すことによりコマンドを作成することができます。 26 | 27 | ```kotlin 28 | object TeleportCommand { 29 | fun register() { 30 | plugin.command("teleport") { 31 | description = "テレポート系の処理を行う" 32 | aliases = listOf("tp", "sample-teleport") 33 | 34 | // タブ補完の設定を行える 35 | tab { 36 | // 引数が何も入力されていない場合の補完候補 37 | argument { 38 | add("here") 39 | addAll(onlinePlayerNames) 40 | } 41 | 42 | // 最初の引数が here の場合の補完候補 43 | argument("here **") { 44 | addAll(onlinePlayerNames) 45 | } 46 | } 47 | 48 | // 実行時の処理を設定できる 49 | execute { 50 | when (args.lowerOrNull(0)) { 51 | // 0 番目の引数が here だった時の処理 52 | "here" -> { 53 | // ... 54 | } 55 | // 0 番目の引数が何も入力されていない時の処理 56 | null -> { 57 | sender.sendMessage( 58 | """ 59 | §a/$label here [Player...] §7複数のプレイヤーを自分の場所へテレポートさせます 60 | §a/$label [Player] §7別のプレイヤーの場所へテレポートします 61 | """.trimIndent() 62 | ) 63 | } 64 | // here 以外の引数が入力されている時の処理 65 | else -> { 66 | // ... 67 | } 68 | } 69 | } 70 | } 71 | } 72 | } 73 | ``` 74 | 75 | ## [extension.kt](src/main/kotlin/com/github/syari/spigot/api/sample/command/extension.kt) 76 | 拡張関数を定義しています。よく使うものはこのように定義しておくと綺麗に書くことができます。 77 | 78 | ```kotlin 79 | fun CommandExecuteAction.getPlayer(index: Int): Player? { 80 | val name = args.getOrNull(index) 81 | return if (name != null) { 82 | plugin.server.getPlayer(name) 83 | } else { 84 | sender.sendMessage("§cプレイヤー名を入力してください") 85 | null 86 | } 87 | } 88 | 89 | val onlinePlayerNames 90 | get() = plugin.server.onlinePlayers.map(Player::getName) 91 | ``` 92 | 93 | [<< 戻る](../README.md) -------------------------------------------------------------------------------- /sample/command/src/main/kotlin/com/github/syari/spigot/api/sample/command/Main.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.sample.command 2 | 3 | import org.bukkit.plugin.java.JavaPlugin 4 | 5 | class Main : JavaPlugin() { 6 | companion object { 7 | // インスタンスを扱いたい場合、この書き方だとスマートに書ける 8 | internal lateinit var plugin: JavaPlugin 9 | } 10 | 11 | init { 12 | plugin = this 13 | } 14 | 15 | override fun onEnable() { 16 | TeleportCommand.register() 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /sample/command/src/main/kotlin/com/github/syari/spigot/api/sample/command/TeleportCommand.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.sample.command 2 | 3 | import com.github.syari.spigot.api.command.command 4 | import com.github.syari.spigot.api.command.tab.CommandTabArgument.Companion.argument 5 | import com.github.syari.spigot.api.sample.command.Main.Companion.plugin 6 | import org.bukkit.Bukkit 7 | import org.bukkit.entity.Player 8 | 9 | object TeleportCommand { 10 | fun register() { 11 | plugin.command("teleport") { 12 | description = "テレポート系の処理を行う" 13 | aliases = listOf("tp", "sample-teleport") 14 | 15 | // タブ補完の設定を行える 16 | tab { 17 | // 引数が何も入力されていない場合の補完候補 18 | argument { 19 | add("here") 20 | addAll(onlinePlayerNames) 21 | } 22 | 23 | // 最初の引数が here の場合の補完候補 24 | argument("here **") { 25 | addAll(onlinePlayerNames) 26 | } 27 | } 28 | 29 | // 実行時の処理を設定できる 30 | execute { 31 | when (args.lowerOrNull(0)) { 32 | // 0 番目の引数が here だった時の処理 33 | "here" -> { 34 | val player = sender as? Player 35 | if (player is Player) { 36 | args.subList(1, args.size).mapNotNull { Bukkit.getPlayer(it) }.forEach { 37 | it.teleport(player) 38 | } 39 | } else { 40 | sender.sendMessage("§cプレイヤーからのみ実行できるコマンドです") 41 | } 42 | } 43 | // 0 番目の引数が何も入力されていない時の処理 44 | null -> { 45 | sender.sendMessage( 46 | """ 47 | §a/$label here [Player...] §7複数のプレイヤーを自分の場所へテレポートさせます 48 | §a/$label [Player] §7別のプレイヤーの場所へテレポートします 49 | """.trimIndent() 50 | ) 51 | } 52 | // here 以外の引数が入力されている時の処理 53 | else -> { 54 | // スマートキャストが機能しないのでキャストする必要がある 55 | val player = sender as? Player 56 | if (player != null) { 57 | val target = getPlayer(0) ?: return@execute 58 | player.teleport(target) 59 | } else { 60 | sender.sendMessage("§cプレイヤーからのみ実行できるコマンドです") 61 | } 62 | } 63 | } 64 | } 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /sample/command/src/main/kotlin/com/github/syari/spigot/api/sample/command/extension.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.sample.command 2 | 3 | import com.github.syari.spigot.api.command.execute.CommandExecuteParameter 4 | import com.github.syari.spigot.api.sample.command.Main.Companion.plugin 5 | import org.bukkit.entity.Player 6 | 7 | fun CommandExecuteParameter.getPlayer(index: Int): Player? { 8 | val name = args.getOrNull(index) 9 | return if (name != null) { 10 | plugin.server.getPlayer(name) 11 | } else { 12 | sender.sendMessage("§cプレイヤー名を入力してください") 13 | null 14 | } 15 | } 16 | 17 | val onlinePlayerNames 18 | get() = plugin.server.onlinePlayers.map(Player::getName) 19 | -------------------------------------------------------------------------------- /sample/component/src/main/kotlin/com/github/syari/spigot/api/sample/component/Main.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.sample.component 2 | 3 | import com.github.syari.spigot.api.command.command 4 | import com.github.syari.spigot.api.component.buildTextComponent 5 | import com.github.syari.spigot.api.component.clickCopyToClipboard 6 | import com.github.syari.spigot.api.component.clickOpenURL 7 | import com.github.syari.spigot.api.component.clickRunCommand 8 | import com.github.syari.spigot.api.component.clickTypeText 9 | import com.github.syari.spigot.api.component.hoverText 10 | import com.github.syari.spigot.api.component.translateComponent 11 | import org.bukkit.Material 12 | import org.bukkit.plugin.java.JavaPlugin 13 | 14 | @Suppress("unused") 15 | class Main : JavaPlugin() { 16 | companion object { 17 | internal lateinit var plugin: JavaPlugin 18 | } 19 | 20 | init { 21 | plugin = this 22 | } 23 | 24 | override fun onEnable() { 25 | command("show_component") { 26 | execute { 27 | sender.spigot().sendMessage( 28 | buildTextComponent { 29 | append("&dTextComponent") 30 | appendLine() 31 | appendLine("&aRunCommand", hoverText("&6Click"), clickRunCommand("/say hello")) 32 | appendLine("&aTypeText", hoverText("&6Click"), clickTypeText("Hello")) 33 | appendLine("&aOpenURL", hoverText("&6Click"), clickOpenURL("https://github.com/sya-ri/EasySpigotAPI")) 34 | appendLine("&aCopyToClipboard", hoverText("&6Click"), clickCopyToClipboard("Hello")) 35 | appendLine() 36 | appendLine("&dTranslatableComponent") 37 | append(translateComponent(Material.STONE_AXE)) 38 | } 39 | ) 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /sample/config/README.md: -------------------------------------------------------------------------------- 1 | # Config 2 | 3 | ## [Main.kt](src/main/kotlin/com/github/syari/spigot/api/sample/config/Main.kt) 4 | プラグインのメイン処理です。`onEnable` 内で `ConfigLoader::load` を呼び出すことによりコンフィグを読み込んでいます。 5 | また、`/reload-sample-config` コマンドを実行することでも読み込めるようにしています。 6 | 7 | ```kotlin 8 | class Main : JavaPlugin() { 9 | companion object { 10 | internal lateinit var plugin: JavaPlugin 11 | } 12 | 13 | init { 14 | plugin = this 15 | } 16 | 17 | override fun onEnable() { 18 | ConfigLoader.load(server.consoleSender) 19 | command("reload-sample-config") { 20 | execute { 21 | ConfigLoader.load(sender) 22 | } 23 | } 24 | } 25 | } 26 | ``` 27 | 28 | ## [ConfigLoader.kt](src/main/kotlin/com/github/syari/spigot/api/sample/config/ConfigLoader.kt) 29 | コンフィグを読み込んでいます。`JavaPlugin::config` を呼び出すことで単一ファイルのコンフィグを読み込めます。 30 | また、`JavaPlugin::configDirectory` を呼び出すことでフォルダに存在する全てのファイルを読み込めます。 31 | `CustomConfig::get` によって値の取得を行いますが、第2引数で値の種類を決定します。 32 | 33 | ```kotlin 34 | object ConfigLoader { 35 | fun load(sender: CommandSender) { 36 | // 特定のファイルを読み込みます。固有の設定をコンフィグに格納する時に使います。 37 | plugin.config(sender, "depth1/depth2/config.yml") { 38 | val stringValue = get("string_value", ConfigDataType.String) 39 | plugin.server.broadcastMessage("($filePath) string_value: $stringValue") 40 | } 41 | // フォルダの中に存在する全てのファイルを読み込みます。 42 | plugin.configDirectory(sender, "depth1/depth2/depth3") { 43 | val intValue = get("int_value", ConfigDataType.Int) 44 | plugin.server.broadcastMessage("($filePath) int_value: $intValue") 45 | } 46 | } 47 | } 48 | ``` 49 | 50 | [<< 戻る](../README.md) -------------------------------------------------------------------------------- /sample/config/src/main/kotlin/com/github/syari/spigot/api/sample/config/ConfigLoader.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.sample.config 2 | 3 | import com.github.syari.spigot.api.config.config 4 | import com.github.syari.spigot.api.config.configDirectory 5 | import com.github.syari.spigot.api.config.type.ConfigDataType 6 | import com.github.syari.spigot.api.sample.config.Main.Companion.plugin 7 | import org.bukkit.command.CommandSender 8 | 9 | object ConfigLoader { 10 | fun load(sender: CommandSender) { 11 | // 特定のファイルを読み込みます。固有の設定をコンフィグに格納する時に使います。 12 | plugin.config(sender, "depth1/depth2/config.yml") { 13 | val stringValue = get("string_value", ConfigDataType.String) 14 | plugin.server.broadcastMessage("($filePath) string_value: $stringValue") 15 | } 16 | // フォルダの中に存在する全てのファイルを読み込みます。 17 | plugin.configDirectory(sender, "depth1/depth2/depth3") { 18 | val intValue = get("int_value", ConfigDataType.Int) 19 | plugin.server.broadcastMessage("($filePath) int_value: $intValue") 20 | } 21 | // フォルダを直接指定することで、ワールドディレクトリ下のコンフィグを操作する 22 | plugin.server.worlds.forEach { world -> 23 | plugin.config(sender, world.worldFolder.resolve("config.yml")) { 24 | val spawn = get("spawn", ConfigDataType.Location) 25 | sendMessage("spawn", spawn?.let(ConfigDataType.Location::locationToString).toString()) 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /sample/config/src/main/kotlin/com/github/syari/spigot/api/sample/config/Main.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.sample.config 2 | 3 | import com.github.syari.spigot.api.command.command 4 | import org.bukkit.plugin.java.JavaPlugin 5 | 6 | class Main : JavaPlugin() { 7 | companion object { 8 | internal lateinit var plugin: JavaPlugin 9 | } 10 | 11 | init { 12 | plugin = this 13 | } 14 | 15 | override fun onEnable() { 16 | ConfigLoader.load(server.consoleSender) 17 | command("reload-sample-config") { 18 | execute { 19 | ConfigLoader.load(sender) 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /sample/event/README.md: -------------------------------------------------------------------------------- 1 | # Event 2 | 3 | ## [Main.kt](src/main/kotlin/com/github/syari/spigot/api/sample/event/Main.kt) 4 | プラグインのメイン処理です。 5 | 6 | ```kotlin 7 | @Suppress("unused") 8 | class Main : JavaPlugin() { 9 | companion object { 10 | internal lateinit var plugin: JavaPlugin 11 | } 12 | 13 | init { 14 | plugin = this 15 | } 16 | 17 | override fun onEnable() { 18 | EventListener.register() 19 | } 20 | } 21 | ``` 22 | 23 | ## [EventListener.kt](src/main/kotlin/com/github/syari/spigot/api/sample/event/EventListener.kt) 24 | 25 | イベントの定義をします。`events {}` の中でイベントの定義を羅列していきます。 26 | 27 | - `event<>{}` 基本的なイベントです。これを主に使います。 28 | - `cancelEventIf<>{}` 条件に一致した時にイベントをキャンセルします。単純な処理のみで用いることを推奨します。 29 | - `cancelEventIfNot<>{}` 条件に一致しなかった時にイベントをキャンセルします。単純な処理のみで用いることを推奨します。 30 | 31 | ```kotlin 32 | object EventListener { 33 | fun register() { 34 | plugin.events { 35 | // 入退出メッセージを変更する 36 | event { 37 | it.joinMessage = ">> Join ${it.player.displayName}" 38 | } 39 | event { 40 | it.quitMessage = ">> Quit ${it.player.displayName}" 41 | } 42 | 43 | // プレイヤーに対するダメージをキャンセルする 44 | cancelEventIf { 45 | it.entity is Player 46 | } 47 | 48 | // OP 以外の移動をキャンセルする 49 | cancelEventIfNot { 50 | it.player.isOp 51 | } 52 | } 53 | } 54 | } 55 | ``` 56 | 57 | [<< 戻る](../README.md) -------------------------------------------------------------------------------- /sample/event/src/main/kotlin/com/github/syari/spigot/api/sample/event/EventListener.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.sample.event 2 | 3 | import com.github.syari.spigot.api.event.events 4 | import com.github.syari.spigot.api.sample.event.Main.Companion.plugin 5 | import org.bukkit.entity.Player 6 | import org.bukkit.event.entity.EntityDamageEvent 7 | import org.bukkit.event.player.PlayerJoinEvent 8 | import org.bukkit.event.player.PlayerMoveEvent 9 | import org.bukkit.event.player.PlayerQuitEvent 10 | 11 | object EventListener { 12 | fun register() { 13 | plugin.events { 14 | // 入退出メッセージを変更する 15 | event { 16 | it.joinMessage = ">> Join ${it.player.displayName}" 17 | } 18 | event { 19 | it.quitMessage = ">> Quit ${it.player.displayName}" 20 | } 21 | 22 | // プレイヤーに対するダメージをキャンセルする 23 | cancelEventIf { 24 | it.entity is Player 25 | } 26 | 27 | // OP 以外の移動をキャンセルする 28 | cancelEventIfNot { 29 | it.player.isOp 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sample/event/src/main/kotlin/com/github/syari/spigot/api/sample/event/Main.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.sample.event 2 | 3 | import org.bukkit.plugin.java.JavaPlugin 4 | 5 | @Suppress("unused") 6 | class Main : JavaPlugin() { 7 | companion object { 8 | internal lateinit var plugin: JavaPlugin 9 | } 10 | 11 | init { 12 | plugin = this 13 | } 14 | 15 | override fun onEnable() { 16 | EventListener.register() 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /sample/inventory/README.md: -------------------------------------------------------------------------------- 1 | # Inventory 2 | 3 | ## [Main.kt](src/main/kotlin/com/github/syari/spigot/api/sample/inventory/Main.kt) 4 | プラグインが起動した時に `CustomInventory::onEnable` を実行しておかなければ `inventory` を使用することができません。他のプラグインで実行している可能性があっても実行しておくようにしてください。 5 | 6 | ```kotlin 7 | override fun onEnable() { 8 | CustomInventory.onEnable(this) 9 | OpenInventoryCommand.register() 10 | } 11 | ``` 12 | 13 | ## [OpenInventoryCommand.kt](src/main/kotlin/com/github/syari/spigot/api/sample/inventory/OpenInventoryCommand.kt) 14 | 15 | ```kotlin 16 | inventory("&9&lサンプルインベントリ", 4) { 17 | item(4, Material.PUFFERFISH) { 18 | onClick { 19 | player.playSound(Sound.ENTITY_PLAYER_LEVELUP) 20 | } 21 | } 22 | item(22, Material.ORANGE_STAINED_GLASS_PANE, "&a&l◀ &c&l▶") { 23 | onClick(ClickType.LEFT) { 24 | item(22, Material.LIME_STAINED_GLASS_PANE, "&a&l◀ &c&l▶") 25 | } 26 | onClick(ClickType.MIDDLE) { 27 | item(22, Material.ORANGE_STAINED_GLASS_PANE, "&a&l◀ &c&l▶") 28 | } 29 | onClick(ClickType.RIGHT) { 30 | item(22, Material.RED_STAINED_GLASS_PANE, "&a&l◀ &c&l▶") 31 | } 32 | } 33 | }.open(player) 34 | ``` 35 | -------------------------------------------------------------------------------- /sample/inventory/src/main/kotlin/com/github/syari/spigot/api/sample/inventory/Main.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.sample.inventory 2 | 3 | import com.github.syari.spigot.api.EasySpigotAPIOption 4 | import org.bukkit.plugin.java.JavaPlugin 5 | 6 | class Main : JavaPlugin() { 7 | companion object { 8 | internal lateinit var plugin: JavaPlugin 9 | } 10 | 11 | init { 12 | plugin = this 13 | } 14 | 15 | override fun onEnable() { 16 | EasySpigotAPIOption.useCustomInventory(this) 17 | OpenInventoryCommand.register() 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /sample/inventory/src/main/kotlin/com/github/syari/spigot/api/sample/inventory/OpenInventoryCommand.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.sample.inventory 2 | 3 | import com.github.syari.spigot.api.command.command 4 | import com.github.syari.spigot.api.inventory.inventory 5 | import com.github.syari.spigot.api.sample.inventory.Main.Companion.plugin 6 | import com.github.syari.spigot.api.sound.playSound 7 | import org.bukkit.Material 8 | import org.bukkit.Sound 9 | import org.bukkit.entity.Player 10 | import org.bukkit.event.inventory.ClickType 11 | 12 | object OpenInventoryCommand { 13 | fun register() { 14 | plugin.command("open-inv") { 15 | execute { 16 | val player = sender as? Player ?: return@execute 17 | inventory("&9&lサンプルインベントリ", 4) { 18 | item(4, Material.PUFFERFISH) { 19 | onClick { 20 | player.playSound(Sound.ENTITY_PLAYER_LEVELUP) 21 | } 22 | } 23 | item(22, Material.ORANGE_STAINED_GLASS_PANE, "&a&l◀ &c&l▶") { 24 | onClick(ClickType.LEFT) { 25 | item(22, Material.LIME_STAINED_GLASS_PANE, "&a&l◀ &c&l▶") 26 | } 27 | onClick(ClickType.MIDDLE) { 28 | item(22, Material.ORANGE_STAINED_GLASS_PANE, "&a&l◀ &c&l▶") 29 | } 30 | onClick(ClickType.RIGHT) { 31 | item(22, Material.RED_STAINED_GLASS_PANE, "&a&l◀ &c&l▶") 32 | } 33 | } 34 | }.open(player) 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /sample/nms/src/main/kotlin/com/github/syari/spigot/api/sample/nms/Main.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.sample.nms 2 | 3 | import com.github.syari.spigot.api.item.displayName 4 | import com.github.syari.spigot.api.item.nbtTag 5 | import com.github.syari.spigot.api.nms.NMS_VERSION 6 | import org.bukkit.Material 7 | import org.bukkit.inventory.ItemStack 8 | import org.bukkit.plugin.java.JavaPlugin 9 | 10 | class Main : JavaPlugin() { 11 | override fun onEnable() { 12 | logger.info("NMS_Version: $NMS_VERSION") 13 | 14 | ItemStack(Material.LAVA_BUCKET).apply { 15 | displayName = "&cLava Bucket" 16 | }.run { logger.info("NBT Tag: $nbtTag") } 17 | 18 | ItemStack(Material.LAVA_BUCKET).run { logger.info("NBT Tag: $nbtTag") } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /sample/scheduler/README.md: -------------------------------------------------------------------------------- 1 | # Scheduler 2 | 3 | ## [Main.kt](src/main/kotlin/com/github/syari/spigot/api/sample/scheduler/Main.kt) 4 | サーバー起動時にスケジューラを動作させている。`async` という引数の真偽値によって同期・非同期を決め流ことができる。 5 | 6 | ```kotlin 7 | @Suppress("unused") 8 | class Main : JavaPlugin() { 9 | override fun onEnable() { 10 | // 10秒後に実行されます 11 | runTaskLater(10 * 20) { 12 | // async: false ... サーバーに同期した処理です 13 | server.broadcastMessage("プラグインが有効になってから10秒経ちました") 14 | } 15 | 16 | // 30秒毎に実行されます 17 | runTaskTimer(30 * 20, async = true) { 18 | // async: true ... サーバーに同期していない処理です 19 | server.onlinePlayers.forEach { 20 | it.giveExpLevels(1) 21 | } 22 | } 23 | } 24 | } 25 | ``` 26 | 27 | [<< 戻る](../README.md) -------------------------------------------------------------------------------- /sample/scheduler/src/main/kotlin/com/github/syari/spigot/api/sample/scheduler/Main.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.sample.scheduler 2 | 3 | import com.github.syari.spigot.api.scheduler.runTaskLater 4 | import com.github.syari.spigot.api.scheduler.runTaskTimer 5 | import org.bukkit.plugin.java.JavaPlugin 6 | 7 | @Suppress("unused") 8 | class Main : JavaPlugin() { 9 | override fun onEnable() { 10 | // 10秒後に実行されます 11 | runTaskLater(10 * 20) { 12 | // async: false ... サーバーに同期した処理です 13 | server.broadcastMessage("プラグインが有効になってから10秒経ちました") 14 | } 15 | 16 | // 30秒毎に実行されます 17 | runTaskTimer(30 * 20, async = true) { 18 | // async: true ... サーバーに同期していない処理です 19 | server.onlinePlayers.forEach { 20 | it.giveExpLevels(1) 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /sample/string/README.md: -------------------------------------------------------------------------------- 1 | # String 2 | 3 | ## [ToColorCommand.kt](src/main/kotlin/com/github/syari/spigot/api/sample/string/ToColorCommand.kt) 4 | `String::toColor`, `String::toUncolor` の処理を確認している。 5 | 6 | ```kotlin 7 | plugin.command("to-color") { 8 | execute { 9 | val text = args.joinToString(" ") 10 | sender.sendMessage("toColor: " + text.toColor()) 11 | sender.sendMessage("toUncolor: " + text.toUncolor()) 12 | sender.sendMessage("toColor -> toUncolor: " + text.toColor().toUncolor()) 13 | } 14 | } 15 | ``` 16 | 17 | ``` 18 | > to-color &atest &6message 19 | [12:11:46 INFO]: toColor: test message 20 | [12:11:46 INFO]: toUncolor: &atest &6message 21 | [12:11:46 INFO]: toColor -> toUncolor: test message 22 | ``` 23 | 24 | `&` をカラーコードとして認識するので、1行目は文字に色がつき、それ以外に色はついていない。 25 | また、`String::toUncolor` は色付き文字から色を無くすだけなので、 26 | `String::toColor` で一度変換しなければ、カラーコードは消えない。 27 | 28 | [<< 戻る](../README.md) -------------------------------------------------------------------------------- /sample/string/src/main/kotlin/com/github/syari/spigot/api/sample/string/Main.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.sample.string 2 | 3 | import org.bukkit.plugin.java.JavaPlugin 4 | 5 | class Main : JavaPlugin() { 6 | companion object { 7 | internal lateinit var plugin: JavaPlugin 8 | } 9 | 10 | init { 11 | plugin = this 12 | } 13 | 14 | override fun onEnable() { 15 | ToColorCommand.register() 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /sample/string/src/main/kotlin/com/github/syari/spigot/api/sample/string/ToColorCommand.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.sample.string 2 | 3 | import com.github.syari.spigot.api.command.command 4 | import com.github.syari.spigot.api.sample.string.Main.Companion.plugin 5 | import com.github.syari.spigot.api.string.toColor 6 | import com.github.syari.spigot.api.string.toUncolor 7 | 8 | object ToColorCommand { 9 | fun register() { 10 | plugin.command("to-color") { 11 | execute { 12 | val text = args.joinToString(" ") 13 | sender.sendMessage("toColor: " + text.toColor()) 14 | sender.sendMessage("toUncolor: " + text.toUncolor()) 15 | sender.sendMessage("toColor -> toUncolor: " + text.toColor().toUncolor()) 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /sample/uuid/README.md: -------------------------------------------------------------------------------- 1 | # UUID 2 | 3 | ## [PlayerJoinChecker.kt](src/main/kotlin/com/github/syari/spigot/api/sample/uuid/PlayerJoinChecker.kt) 4 | 5 | `UUID`, `UUIDPlayer` を使わないと同じプレイヤーがログインしても、別のプレイヤーとして扱われてしまう。 6 | そのため、変数として格納する時は必ずそれらを使用する。 7 | 以下の例では、`Player` を用いた時に正常に動作しないことを確認している。 8 | 9 | ```kotlin 10 | object PlayerJoinChecker { 11 | /** 12 | * [UUIDPlayer] を使うと再ログインしても同一プレイヤーとして認識される 13 | * 14 | * 2回目のログイン以降は true と出力される 15 | */ 16 | private val useUuidPlayer = mutableSetOf() 17 | 18 | /** 19 | * [Player] を使うと再ログインすると別のインスタンスになる 20 | * 21 | * 2回目のログイン以降も false と出力される 22 | */ 23 | private val usePlayer = mutableSetOf() 24 | 25 | fun register() { 26 | events { 27 | event { 28 | val player = it.player 29 | val uuidPlayer = UUIDPlayer.from(player) 30 | player.sendMessage( 31 | """ 32 | UUIDPlayer を使用: ${useUuidPlayer.contains(uuidPlayer)} (${useUuidPlayer.size}) 33 | Player を使用: ${usePlayer.contains(player)} (${usePlayer.size}) 34 | """.trimIndent() 35 | ) 36 | useUuidPlayer.add(uuidPlayer) 37 | usePlayer.add(player) 38 | } 39 | } 40 | } 41 | } 42 | ``` 43 | 44 | [<< 戻る](../README.md) -------------------------------------------------------------------------------- /sample/uuid/src/main/kotlin/com/github/syari/spigot/api/sample/uuid/Main.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.sample.uuid 2 | 3 | import org.bukkit.plugin.java.JavaPlugin 4 | 5 | @Suppress("unused") 6 | class Main : JavaPlugin() { 7 | companion object { 8 | internal lateinit var plugin: JavaPlugin 9 | } 10 | 11 | init { 12 | plugin = this 13 | } 14 | 15 | override fun onEnable() { 16 | PlayerJoinChecker.register() 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /sample/uuid/src/main/kotlin/com/github/syari/spigot/api/sample/uuid/PlayerJoinChecker.kt: -------------------------------------------------------------------------------- 1 | package com.github.syari.spigot.api.sample.uuid 2 | 3 | import com.github.syari.spigot.api.event.events 4 | import com.github.syari.spigot.api.sample.uuid.Main.Companion.plugin 5 | import com.github.syari.spigot.api.uuid.UUIDPlayer 6 | import org.bukkit.entity.Player 7 | import org.bukkit.event.player.PlayerJoinEvent 8 | 9 | object PlayerJoinChecker { 10 | /** 11 | * [UUIDPlayer] を使うと再ログインしても同一プレイヤーとして認識される 12 | * 13 | * 2回目のログイン以降は true と出力される 14 | */ 15 | private val useUuidPlayer = mutableSetOf() 16 | 17 | /** 18 | * [Player] を使うと再ログインすると別のインスタンスになる 19 | * 20 | * 2回目のログイン以降も false と出力される 21 | */ 22 | private val usePlayer = mutableSetOf() 23 | 24 | fun register() { 25 | plugin.events { 26 | event { 27 | val player = it.player 28 | val uuidPlayer = UUIDPlayer.from(player) 29 | player.sendMessage( 30 | """ 31 | UUIDPlayer を使用: ${useUuidPlayer.contains(uuidPlayer)} (${useUuidPlayer.size}) 32 | Player を使用: ${usePlayer.contains(player)} (${usePlayer.size}) 33 | """.trimIndent() 34 | ) 35 | useUuidPlayer.add(uuidPlayer) 36 | usePlayer.add(player) 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "EasySpigotAPI" 2 | 3 | include( 4 | "api", 5 | "sample", 6 | "sample:command", 7 | "sample:component", 8 | "sample:config", 9 | "sample:event", 10 | "sample:inventory", 11 | "sample:nms", 12 | "sample:scheduler", 13 | "sample:string", 14 | "sample:uuid" 15 | ) 16 | --------------------------------------------------------------------------------