Skip to content

Commit

Permalink
👍 Changed the output to match the language of each player
Browse files Browse the repository at this point in the history
  • Loading branch information
Nlkomaru committed Jan 26, 2022
1 parent 0a36ddd commit a76cc41
Show file tree
Hide file tree
Showing 21 changed files with 701 additions and 317 deletions.
3 changes: 0 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ plugins {
id("com.github.johnrengelman.shadow") version "7.0.0"
}




group = "dev.nikomaru"
version = "1.0-SNAPSHOT"

Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/dev/nikomaru/raceassist/RaceAssist.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import java.io.File
import java.util.*

class RaceAssist : SuspendingJavaPlugin() {

Expand All @@ -54,7 +55,7 @@ class RaceAssist : SuspendingJavaPlugin() {
registerEvents()

if (!VaultAPI.setupEconomy()) {
plugin!!.logger.info(Lang.getText("no-economy-plugin-found-disabling-vault"))
plugin!!.logger.info(Lang.getText("no-economy-plugin-found-disabling-vault", Locale.getDefault()))
server.pluginManager.disablePlugin(this)
return
}
Expand Down
41 changes: 21 additions & 20 deletions src/main/kotlin/dev/nikomaru/raceassist/bet/GuiComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,29 @@ import org.bukkit.Material
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.ItemMeta
import java.text.MessageFormat
import java.util.*

object GuiComponent {

fun guiComponent(): TextComponent {
return text("レース賭け自販機").color(TextColor.fromHexString("#228b22"))
}

fun onceUp(): ItemStack {
fun onceUp(locale: Locale): ItemStack {
val onceUp = ItemStack(Material.PINK_STAINED_GLASS_PANE)
val onceUpMeta: ItemMeta = onceUp.itemMeta
onceUpMeta.displayName(text(MessageFormat.format(Lang.getText("to-bet-one-unit"), betUnit)).color(TextColor.fromHexString("#f08080")))
onceUpMeta.displayName(text(MessageFormat.format(Lang.getText("to-bet-one-unit", locale), betUnit)).color(TextColor.fromHexString("#f08080")))
onceUp.itemMeta = onceUpMeta
return onceUp
}

fun onceDown(): ItemStack {
fun onceDown(locale: Locale): ItemStack {
val onceDown = ItemStack(Material.LIGHT_BLUE_STAINED_GLASS_PANE)
val onceDownMeta: ItemMeta = onceDown.itemMeta
onceDownMeta.displayName(
text(
MessageFormat.format(
Lang.getText("to-cancel-bet-one-unit"),
Lang.getText("to-cancel-bet-one-unit", locale),
betUnit
)
).color(TextColor.fromHexString("#add8e6"))
Expand All @@ -55,13 +56,13 @@ object GuiComponent {
return onceDown
}

fun tenTimesUp(): ItemStack {
fun tenTimesUp(locale: Locale): ItemStack {
val tenTimesUp = ItemStack(Material.RED_STAINED_GLASS_PANE)
val tenTimesUpMeta: ItemMeta = tenTimesUp.itemMeta
tenTimesUpMeta.displayName(
text(
MessageFormat.format(
Lang.getText("to-bet-ten-unit"),
Lang.getText("to-bet-ten-unit", locale),
betUnit * 10
)
).color(TextColor.fromHexString("#ff0000"))
Expand All @@ -70,13 +71,13 @@ object GuiComponent {
return tenTimesUp
}

fun tenTimesDown(): ItemStack {
fun tenTimesDown(locale: Locale): ItemStack {
val tenTimesDown = ItemStack(Material.BLUE_STAINED_GLASS_PANE)
val tenTimesDownMeta: ItemMeta = tenTimesDown.itemMeta
tenTimesDownMeta.displayName(
text(
MessageFormat.format(
Lang.getText("to-cancel-bet-ten-unit"),
Lang.getText("to-cancel-bet-ten-unit", locale),
betUnit * 10
)
).color(TextColor.fromHexString("#0000cd"))
Expand All @@ -85,50 +86,50 @@ object GuiComponent {
return tenTimesDown
}

fun accept(): ItemStack {
fun accept(locale: Locale): ItemStack {
val accept = ItemStack(Material.GREEN_WOOL)
val acceptMeta: ItemMeta = accept.itemMeta
acceptMeta.displayName(text(Lang.getText("gui-decide")).color(TextColor.fromHexString("#228b22")))
acceptMeta.displayName(text(Lang.getText("gui-decide", locale)).color(TextColor.fromHexString("#228b22")))
accept.itemMeta = acceptMeta
return accept
}

fun deny(): ItemStack {
fun deny(locale: Locale): ItemStack {
val deny = ItemStack(Material.RED_WOOL)
val denyMeta: ItemMeta = deny.itemMeta
denyMeta.displayName(text(Lang.getText("gui-cancel")).color(TextColor.fromHexString("#ff0000")))
denyMeta.displayName(text(Lang.getText("gui-cancel", locale)).color(TextColor.fromHexString("#ff0000")))
deny.itemMeta = denyMeta
return deny
}

fun reset(): ItemStack {
fun reset(locale: Locale): ItemStack {
val reset = ItemStack(Material.WHITE_WOOL)
val resetMeta: ItemMeta = reset.itemMeta
resetMeta.displayName(text(Lang.getText("gui-reset")).color(TextColor.fromHexString("#ffffff")))
resetMeta.displayName(text(Lang.getText("gui-reset", locale)).color(TextColor.fromHexString("#ffffff")))
reset.itemMeta = resetMeta
return reset
}

fun noBet(): ItemStack {
fun noBet(locale: Locale): ItemStack {
val noBet = ItemStack(Material.BARRIER)
val noBetMeta: ItemMeta = noBet.itemMeta
noBetMeta.displayName(text(Lang.getText("gui-no-one-betting")).color(TextColor.fromHexString("#ff0000")))
noBetMeta.displayName(text(Lang.getText("gui-no-one-betting", locale)).color(TextColor.fromHexString("#ff0000")))
noBet.itemMeta = noBetMeta
return noBet
}

fun noUnderNotice(): ItemStack {
fun noUnderNotice(locale: Locale): ItemStack {
val noUnderNotice = ItemStack(Material.BARRIER)
val noUnderNoticeMeta: ItemMeta = noUnderNotice.itemMeta
noUnderNoticeMeta.displayName(text(Lang.getText("cannot-decrease-more-money"), TextColor.fromHexString("#ff0000")))
noUnderNoticeMeta.displayName(text(Lang.getText("cannot-decrease-more-money", locale), TextColor.fromHexString("#ff0000")))
noUnderNotice.itemMeta = noUnderNoticeMeta
return noUnderNotice
}

fun noHaveMoney(): ItemStack {
fun noHaveMoney(locale: Locale): ItemStack {
val noHaveMoney = ItemStack(Material.BARRIER)
val noHaveMoneyMeta: ItemMeta = noHaveMoney.itemMeta
noHaveMoneyMeta.displayName(text(Lang.getText("no-have-money"), TextColor.fromHexString("#ff0000")))
noHaveMoneyMeta.displayName(text(Lang.getText("no-have-money", locale), TextColor.fromHexString("#ff0000")))
noHaveMoney.itemMeta = noHaveMoneyMeta
return noHaveMoney
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ class OpenBetGuiCommand : BaseCommand() {
@CommandCompletion("@RaceID")
fun openVending(player: Player, @Single raceID: String) {
if (!raceExist(raceID)) {
player.sendMessage(Lang.getText("no-exist-this-raceid-race"))
player.sendMessage(Lang.getText("no-exist-this-raceid-race", player.locale()))
return
}
val vending = BetChestGui()
val canBet = transaction { BetSetting.select { BetSetting.raceID eq raceID }.first()[BetSetting.canBet] }
if (!canBet) {
player.sendMessage(Lang.getText("now-cannot-bet-race"))
player.sendMessage(Lang.getText("now-cannot-bet-race", player.locale()))
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ class SetBetCommand : BaseCommand() {
fun setCanBet(player: Player, @Single raceID: String, @Single type: String) {
plugin!!.launch {
if (!raceExist(raceID)) {
player.sendMessage(MessageFormat.format(Lang.getText("no-exist-this-raceid-race"), raceID))
player.sendMessage(MessageFormat.format(Lang.getText("no-exist-this-raceid-race", player.locale()), raceID))
return@launch
}
if (getRaceCreator(raceID) != player.uniqueId.toString()) {
player.sendMessage(Lang.getText("only-race-creator-can-setting"))
player.sendMessage(Lang.getText("only-race-creator-can-setting", player.locale()))
return@launch
}
if (type == "on") {
Expand All @@ -63,14 +63,14 @@ class SetBetCommand : BaseCommand() {
it[canBet] = true
}
}
player.sendMessage(MessageFormat.format(Lang.getText("can-bet-this-raceid"), raceID))
player.sendMessage(MessageFormat.format(Lang.getText("can-bet-this-raceid", player.locale()), raceID))
} else if (type == "off") {
newSuspendedTransaction(Dispatchers.IO) {
BetSetting.update({ BetSetting.raceID eq raceID }) {
it[canBet] = false
}
}
player.sendMessage(MessageFormat.format(Lang.getText("cannot-bet-this-raceid"), raceID))
player.sendMessage(MessageFormat.format(Lang.getText("cannot-bet-this-raceid", player.locale()), raceID))
}
}
}
Expand All @@ -80,15 +80,15 @@ class SetBetCommand : BaseCommand() {
fun setRate(player: Player, @Single raceID: String, @Single rate: Int) {
plugin!!.launch {
if (!raceExist(raceID)) {
player.sendMessage(Lang.getText("no-exist-this-raceid-race"))
player.sendMessage(Lang.getText("no-exist-this-raceid-race", player.locale()))
return@launch
}
if (getRaceCreator(raceID) != player.uniqueId.toString()) {
player.sendMessage(Lang.getText("only-race-creator-can-setting"))
player.sendMessage(Lang.getText("only-race-creator-can-setting", player.locale()))
return@launch
}
if (rate !in 1..100) {
player.sendMessage(Lang.getText("set-rate-message-in1-100"))
player.sendMessage(Lang.getText("set-rate-message-in1-100", player.locale()))
return@launch
}
newSuspendedTransaction(Dispatchers.IO) {
Expand All @@ -97,7 +97,7 @@ class SetBetCommand : BaseCommand() {
}
}
}
player.sendMessage(MessageFormat.format(Lang.getText("change-bet-rate-message"), raceID, rate))
player.sendMessage(MessageFormat.format(Lang.getText("change-bet-rate-message", player.locale()), raceID, rate))
}

@Subcommand("delete")
Expand All @@ -106,11 +106,11 @@ class SetBetCommand : BaseCommand() {
plugin!!.launch {
withContext(Dispatchers.IO) {
if (!raceExist(raceID)) {
player.sendMessage(Lang.getText("no-exist-this-raceid-race"))
player.sendMessage(Lang.getText("no-exist-this-raceid-race", player.locale()))
return@withContext
}
if (getRaceCreator(raceID) != player.uniqueId.toString()) {
player.sendMessage(Lang.getText("only-race-creator-can-setting"))
player.sendMessage(Lang.getText("only-race-creator-can-setting", player.locale()))
return@withContext
}
}
Expand All @@ -119,10 +119,10 @@ class SetBetCommand : BaseCommand() {
newSuspendedTransaction(Dispatchers.IO) {
BetList.deleteWhere { BetList.raceID eq raceID }
}
player.sendMessage(MessageFormat.format(Lang.getText("bet-remove-race"), raceID))
player.sendMessage(MessageFormat.format(Lang.getText("bet-remove-race", player.locale()), raceID))
} else {
canDelete[player.uniqueId] = true
player.sendMessage(MessageFormat.format(Lang.getText("bet-remove-race-confirm-message"), raceID))
player.sendMessage(MessageFormat.format(Lang.getText("bet-remove-race-confirm-message", player.locale()), raceID))
delay(5000)
canDelete.remove(player.uniqueId)
}
Expand All @@ -136,15 +136,15 @@ class SetBetCommand : BaseCommand() {
plugin!!.launch {
withContext(Dispatchers.IO) {
if (!raceExist(raceID)) {
player.sendMessage(Lang.getText("no-exist-this-raceid-race"))
player.sendMessage(Lang.getText("no-exist-this-raceid-race", player.locale()))
return@withContext
}
if (getRaceCreator(raceID) != player.uniqueId.toString()) {
player.sendMessage(Lang.getText("only-race-creator-can-setting"))
player.sendMessage(Lang.getText("only-race-creator-can-setting", player.locale()))
return@withContext
}
if (eco.getBalance(player) < getBetSum(raceID)) {
player.sendMessage(Lang.getText("no-have-money"))
player.sendMessage(Lang.getText("no-have-money", player.locale()))
return@withContext
}
}
Expand All @@ -159,12 +159,17 @@ class SetBetCommand : BaseCommand() {
eco.withdrawPlayer(player, it[BetList.betting].toDouble())

eco.depositPlayer(receiver, it[BetList.betting].toDouble())
player.sendMessage(MessageFormat.format(Lang.getText("bet-revert-return-message-owner"), receiver.name, it[BetList.betting]))
player.sendMessage(
MessageFormat.format(
Lang.getText("bet-revert-return-message-owner", player.locale()), receiver.name,
it[BetList.betting]
)
)

if (receiver.isOnline) {
(receiver as Player).sendMessage(
MessageFormat.format(
Lang.getText("bet-revert-return-message-player"),
Lang.getText("bet-revert-return-message-player", receiver.locale()),
player.name,
it[BetList.raceID],
it[BetList.jockey],
Expand All @@ -174,10 +179,10 @@ class SetBetCommand : BaseCommand() {
}
}
}
player.sendMessage(MessageFormat.format(Lang.getText("bet-revert-complete-message"), raceID))
player.sendMessage(MessageFormat.format(Lang.getText("bet-revert-complete-message", player.locale()), raceID))
} else {
canRevert[player.uniqueId] = true
player.sendMessage(MessageFormat.format(Lang.getText("bet-revert-race-confirm-message"), raceID))
player.sendMessage(MessageFormat.format(Lang.getText("bet-revert-race-confirm-message", player.locale()), raceID))
delay(5000)
canRevert.remove(player.uniqueId)
}
Expand All @@ -198,11 +203,11 @@ class SetBetCommand : BaseCommand() {
plugin!!.launch {
withContext(Dispatchers.IO) {
if (!raceExist(raceID)) {
player.sendMessage(Lang.getText("no-exist-this-raceid-race"))
player.sendMessage(Lang.getText("no-exist-this-raceid-race", player.locale()))
return@withContext
}
if (getRaceCreator(raceID) != player.uniqueId.toString()) {
player.sendMessage(Lang.getText("only-race-creator-can-setting"))
player.sendMessage(Lang.getText("only-race-creator-can-setting", player.locale()))
return@withContext
}
}
Expand All @@ -220,19 +225,19 @@ class SetBetCommand : BaseCommand() {
plugin!!.launch {
withContext(Dispatchers.IO) {
if (!raceExist(raceID)) {
player.sendMessage(Lang.getText("no-exist-this-raceid-race"))
player.sendMessage(Lang.getText("no-exist-this-raceid-race", player.locale()))
return@withContext
}
if (getRaceCreator(raceID) != player.uniqueId.toString()) {
player.sendMessage(Lang.getText("only-race-creator-can-setting"))
player.sendMessage(Lang.getText("only-race-creator-can-setting", player.locale()))
return@withContext
}
}
newSuspendedTransaction(Dispatchers.IO) {
BetList.select { BetList.raceID eq raceID }.forEach {
player.sendMessage(
MessageFormat.format(
Lang.getText("bet-list-detail-message"),
Lang.getText("bet-list-detail-message", player.locale()),
it[BetList.rowNum],
it[BetList.timeStamp],
it[BetList.playerName],
Expand Down
Loading

0 comments on commit a76cc41

Please sign in to comment.