Skip to content

Commit

Permalink
Merge pull request #67 from DongShaoNB/feat/warp-form
Browse files Browse the repository at this point in the history
FEATURE: warp form
  • Loading branch information
DongShaoNB authored Jul 30, 2024
2 parents 2b4b0e4 + 831282c commit 7e86f8b
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package cc.dsnb.bedrockplayersupport

import cc.dsnb.bedrockplayersupport.AuthPlugin.*
import cc.dsnb.bedrockplayersupport.command.HomeFormCommand
import cc.dsnb.bedrockplayersupport.command.MainCommand
import cc.dsnb.bedrockplayersupport.command.MsgFormCommand
import cc.dsnb.bedrockplayersupport.command.TpFormCommand
import cc.dsnb.bedrockplayersupport.command.*
import cc.dsnb.bedrockplayersupport.config.LangConfig
import cc.dsnb.bedrockplayersupport.config.MainConfig
import cc.dsnb.bedrockplayersupport.form.MainForm
Expand Down Expand Up @@ -228,6 +225,9 @@ class BedrockPlayerSupport : JavaPlugin() {
if (config.enableHomeForm()) {
getCommand("homegui")?.setExecutor(HomeFormCommand())
}
if (config.enableWarpForm()) {
getCommand("warpgui")?.setExecutor(WarpFormCommand())
}
}

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

import cc.dsnb.bedrockplayersupport.BasicPlugin.*
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

/**
* @author DongShaoNB
*/
class WarpFormCommand : CommandExecutor {

override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<String>): Boolean {
if (sender is Player) {
if (BedrockPlayerSupport.floodgateApi.isFloodgatePlayer(sender.uniqueId)) {
when (BedrockPlayerSupport.basicPlugin) {
CMI -> BedrockPlayerSupport.cmiForm.sendWarpForm(sender)
EssentialsX -> BedrockPlayerSupport.essxForm.sendWarpForm(sender)
HuskHomes -> BedrockPlayerSupport.huskhomesForm.sendWarpForm(sender)
AdvancedTeleport -> BedrockPlayerSupport.atForm.sendWarpForm(sender)
None -> {
// Don't need to do anything
}
}
} else {
sender.sendMessage(
BedrockPlayerSupport.miniMessage.deserialize(
BedrockPlayerSupport.langConfigManager.getConfigData().notBedrockPlayer()
)
)
}
}
return false
}

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

@ConfKey("form.warp.title")
@ConfComments(
"传送点表单的标题", "Title of the warp form"
)
@DefaultString("<gold>传送点表单")
@Order(60)
fun warpFormTitle(): String

@ConfKey("message.not-bedrock-player")
@ConfComments(
"不是基岩版的玩家使用表单命令的错误提示", "Error of player use form command but is not bedrock player"
Expand Down
16 changes: 12 additions & 4 deletions src/main/kotlin/cc/dsnb/bedrockplayersupport/config/MainConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -127,28 +127,36 @@ interface MainConfig {
@Order(72)
fun backDeathLocFormOpenDelayTick(): Long

@ConfKey("form.warp.enable")
@ConfComments(
"启用基岩版传送点表单(/warpgui)", "Enable bedrock warp form (/warpgui)"
)
@DefaultBoolean(true)
@Order(80)
fun enableWarpForm(): Boolean

@ConfKey("auth.register.enable")
@ConfComments(
"启用基岩版玩家自动注册功能", "Enable bedrock player automatic register function"
)
@DefaultBoolean(false)
@Order(80)
@Order(100)
fun enableRegister(): Boolean

@ConfKey("auth.register.password-length")
@ConfComments(
"随机的密码的长度", "The length of random password"
)
@DefaultInteger(16)
@Order(81)
@Order(101)
fun passwordLength(): Int

@ConfKey("auth.login.enable")
@ConfComments(
"启用基岩版玩家自动登录功能", "Enable bedrock player automatic login function"
)
@DefaultBoolean(false)
@Order(90)
@Order(110)
fun enableLogin(): Boolean

@ConfKey("auth.login.command")
Expand All @@ -163,7 +171,7 @@ interface MainConfig {
"Available variable: %playerName% player name"
)
@DefaultString("forcelogin %playerName%")
@Order(91)
@Order(111)
fun forceLoginCommand(): String

}
18 changes: 18 additions & 0 deletions src/main/kotlin/cc/dsnb/bedrockplayersupport/form/basic/ATForm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cc.dsnb.bedrockplayersupport.form.basic

import cc.dsnb.bedrockplayersupport.BedrockPlayerSupport
import io.github.niestrat99.advancedteleport.api.ATPlayer
import io.github.niestrat99.advancedteleport.api.AdvancedTeleportAPI
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer
import org.bukkit.entity.Player
import org.geysermc.cumulus.form.SimpleForm
Expand Down Expand Up @@ -48,4 +49,21 @@ class ATForm {
BedrockPlayerSupport.floodgateApi.sendForm(player.uniqueId, form)
}

fun sendWarpForm(player: Player) {
val warps = AdvancedTeleportAPI.getWarps().keys
val form = SimpleForm.builder()
.title(
LegacyComponentSerializer.legacySection().serialize(
BedrockPlayerSupport.miniMessage.deserialize(
BedrockPlayerSupport.langConfigManager.getConfigData().warpFormTitle()
)
)
)
.validResultHandler { simpleFormResponse ->
player.chat("/warp ${simpleFormResponse.clickedButton().text()}")
}
warps.forEach { form.button(it) }
BedrockPlayerSupport.floodgateApi.sendForm(player.uniqueId, form)
}

}
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 @@ -51,4 +51,21 @@ class CMIForm {
BedrockPlayerSupport.floodgateApi.sendForm(player.uniqueId, form)
}

fun sendWarpForm(player: Player) {
val warps = CMI.getInstance().warpManager.warps.keys
val form = SimpleForm.builder()
.title(
LegacyComponentSerializer.legacySection().serialize(
BedrockPlayerSupport.miniMessage.deserialize(
BedrockPlayerSupport.langConfigManager.getConfigData().warpFormTitle()
)
)
)
.validResultHandler { simpleFormResponse ->
player.chat("/warp ${simpleFormResponse.clickedButton().text()}")
}
warps.forEach { form.button(it) }
BedrockPlayerSupport.floodgateApi.sendForm(player.uniqueId, form)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,21 @@ class EssXForm {
BedrockPlayerSupport.floodgateApi.sendForm(player.uniqueId, form)
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,25 @@ class HuskHomesForm {
}
}

fun sendWarpForm(player: Player) {
val warps = HuskHomesAPI.getInstance().warps
val form = SimpleForm.builder()
.title(
LegacyComponentSerializer.legacySection().serialize(
BedrockPlayerSupport.miniMessage.deserialize(
BedrockPlayerSupport.langConfigManager.getConfigData().warpFormTitle()
)
)
)
.validResultHandler { simpleFormResponse ->
player.chat("/warp " + simpleFormResponse.clickedButton().text())
}
warps.thenAccept { warpList ->
for (warp in warpList) {
form.button(warp.identifier)
}
BedrockPlayerSupport.floodgateApi.sendForm(player.uniqueId, form)
}
}

}
6 changes: 6 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ commands:
homegui:
description: "Bedrock player home form"
permission: bedrockplayersupport.command.homegui
warpgui:
description: "Bedrock player warp form"
permission: bedrockplayersupport.command.warpgui

permissions:
bedrockplayersupport.admin:
Expand All @@ -45,4 +48,7 @@ permissions:
default: true
bedrockplayersupport.command.homegui:
description: "Bedrock player home form permission"
default: true
bedrockplayersupport.command.warpgui:
description: "Bedrock player warp form permission"
default: true

0 comments on commit 7e86f8b

Please sign in to comment.