Skip to content

Commit

Permalink
Merge pull request #76 from DongShaoNB/feat/kit-form
Browse files Browse the repository at this point in the history
[FEATURE] kit form
  • Loading branch information
DongShaoNB authored Aug 18, 2024
2 parents 3aaa417 + f898d04 commit 02f009a
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ class BedrockPlayerSupport : JavaPlugin() {
if (config.enableWarpForm()) {
getCommand("warpgui")?.setExecutor(WarpFormCommand())
}
if (config.enableKitForm()) {
getCommand("kitgui")?.setExecutor(KitFormCommand())
}
}

private fun loadMetrics() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cc.dsnb.bedrockplayersupport.command

import cc.dsnb.bedrockplayersupport.BedrockPlayerSupport
import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player

class KitFormCommand : CommandExecutor {

override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<String>): Boolean {
if (sender is Player) {
if (BedrockPlayerSupport.floodgateApi.isFloodgatePlayer(sender.uniqueId)) {
BedrockPlayerSupport.mainForm.openBedrockKitForm(sender)
} else {
sender.sendMessage(
BedrockPlayerSupport.miniMessage.deserialize(
BedrockPlayerSupport.langConfigManager.getConfigData().notBedrockPlayer()
)
)
}
}
return false
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ interface LangConfig {
@Order(60)
fun warpFormTitle(): String

@ConfKey("form.kit.title")
@ConfComments(
"礼包表单的标题", "Title of the kit form"
)
@DefaultString("<gold>礼包表单")
@Order(70)
fun kitFormTitle(): String

@ConfKey("message.not-bedrock-player")
@ConfComments(
"不是基岩版的玩家使用表单命令的错误提示", "Error of player use form command but is not bedrock player"
Expand Down
11 changes: 11 additions & 0 deletions src/main/kotlin/cc/dsnb/bedrockplayersupport/config/MainConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@ interface MainConfig {
@Order(80)
fun enableWarpForm(): Boolean

@ConfKey("form.kit.enable")
@ConfComments(
"启用基岩版礼包表单(/kitgui)",
"只有 CMI / EssentialsX / SunLight 可用",
"Enable bedrock kit form (/kitgui)",
"Only CMI / EssentialsX / SunLight is available",
)
@DefaultBoolean(true)
@Order(90)
fun enableKitForm(): Boolean

@ConfKey("auth.register.enable")
@ConfComments(
"启用基岩版玩家自动注册功能", "Enable bedrock player automatic register function"
Expand Down
10 changes: 10 additions & 0 deletions src/main/kotlin/cc/dsnb/bedrockplayersupport/form/MainForm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,14 @@ class MainForm {
}
}

fun openBedrockKitForm(player: Player) {
when (BedrockPlayerSupport.basicPlugin) {
CMI -> BedrockPlayerSupport.cmiForm.sendKitForm(player)
EssentialsX -> BedrockPlayerSupport.essxForm.sendKitForm(player)
SunLight -> BedrockPlayerSupport.sunlightForm.sendKitForm(player)
else -> {
// Don't need to do anything
}
}
}
}
17 changes: 17 additions & 0 deletions src/main/kotlin/cc/dsnb/bedrockplayersupport/form/basic/CMIForm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,21 @@ class CMIForm {
BedrockPlayerSupport.floodgateApi.sendForm(player.uniqueId, form)
}

fun sendKitForm(player: Player) {
val kits = CMI.getInstance().kitsManager.kitMap
val form = SimpleForm.builder()
.title(
LegacyComponentSerializer.legacySection().serialize(
BedrockPlayerSupport.miniMessage.deserialize(
BedrockPlayerSupport.langConfigManager.getConfigData().kitFormTitle()
)
)
)
.validResultHandler { simpleFormResponse ->
player.chat("/kit ${simpleFormResponse.clickedButton().text()}")
}
kits.forEach { form.button(it.key)}
BedrockPlayerSupport.floodgateApi.sendForm(player.uniqueId, form)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import org.geysermc.cumulus.form.SimpleForm
class EssXForm {

fun sendDelHomeForm(player: Player) {
val userHomes = User(player, Bukkit.getPluginManager().getPlugin("Essentials") as Essentials).homes
val userHomes =
User(player, Bukkit.getPluginManager().getPlugin("Essentials") as Essentials).homes
val form = SimpleForm.builder()
.title(
LegacyComponentSerializer.legacySection().serialize(
Expand All @@ -31,7 +32,8 @@ class EssXForm {
}

fun sendGoHomeForm(player: Player) {
val userHomes = User(player, Bukkit.getPluginManager().getPlugin("Essentials") as Essentials).homes
val userHomes =
User(player, Bukkit.getPluginManager().getPlugin("Essentials") as Essentials).homes
val form = SimpleForm.builder()
.title(
LegacyComponentSerializer.legacySection().serialize(
Expand Down Expand Up @@ -64,4 +66,21 @@ class EssXForm {
BedrockPlayerSupport.floodgateApi.sendForm(player.uniqueId, form)
}

fun sendKitForm(player: Player) {
val kits = (Bukkit.getPluginManager().getPlugin("Essentials") as Essentials).kits.kitKeys
val form = SimpleForm.builder()
.title(
LegacyComponentSerializer.legacySection().serialize(
BedrockPlayerSupport.miniMessage.deserialize(
BedrockPlayerSupport.langConfigManager.getConfigData().kitFormTitle()
)
)
)
.validResultHandler { simpleFormResponse ->
player.chat("/kit " + simpleFormResponse.clickedButton().text())
}
kits.forEach { form.button(it) }
BedrockPlayerSupport.floodgateApi.sendForm(player.uniqueId, form)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer
import org.bukkit.entity.Player
import org.geysermc.cumulus.form.SimpleForm
import su.nightexpress.sunlight.SunLightAPI
import su.nightexpress.sunlight.module.kits.KitsModule
import su.nightexpress.sunlight.module.warps.WarpsModule

class SunLightForm {
Expand Down Expand Up @@ -73,4 +74,31 @@ class SunLightForm {
BedrockPlayerSupport.floodgateApi.sendForm(player.uniqueId, form)
}

fun sendKitForm(player: Player) {
val kits = SunLightAPI.PLUGIN.moduleManager.getModule(KitsModule::class.java).let {
if (it.isPresent) {
it.get().kits
} else {
if ("zh_cn".equals(BedrockPlayerSupport.languageInUse, ignoreCase = true)) {
throw NullPointerException("在加载礼包模块时遇到错误, 请联系 BedrockPlayerSupport 插件作者")
} else {
throw NullPointerException("An error was encountered while loading the kit module, please contact BedrockPlayerSupport plguin author")
}
}
}
val form = SimpleForm.builder()
.title(
LegacyComponentSerializer.legacySection().serialize(
BedrockPlayerSupport.miniMessage.deserialize(
BedrockPlayerSupport.langConfigManager.getConfigData().kitFormTitle()
)
)
)
.validResultHandler { simpleFormResponse ->
player.chat("/kit ${simpleFormResponse.clickedButton().text()}")
}
kits.forEach { form.button(it.id) }
BedrockPlayerSupport.floodgateApi.sendForm(player.uniqueId, form)
}

}
7 changes: 7 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ softdepend:
- Essentials
- HuskHomes
- AdvancedTeleport
- SunLight
- AuthMe
- CatSeedLogin
- NexAuth
Expand All @@ -35,6 +36,9 @@ commands:
warpgui:
description: "Bedrock player warp form"
permission: bedrockplayersupport.command.warpgui
kitgui:
description: "Bedrock player kit form"
permission: bedrockplayersupport.command.kitgui

permissions:
bedrockplayersupport.admin:
Expand All @@ -51,4 +55,7 @@ permissions:
default: true
bedrockplayersupport.command.warpgui:
description: "Bedrock player warp form permission"
default: true
bedrockplayersupport.command.kitgui:
description: "Bedrock player kit form permission"
default: true

0 comments on commit 02f009a

Please sign in to comment.