Skip to content

Commit

Permalink
🐛 Fix betting gui method(WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nlkomaru committed Jul 19, 2024
1 parent 81458be commit eb12dcb
Show file tree
Hide file tree
Showing 7 changed files with 288 additions and 290 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import com.github.shynixn.mccoroutine.bukkit.launch
import dev.nikomaru.raceassist.RaceAssist
import dev.nikomaru.raceassist.api.VaultAPI
import dev.nikomaru.raceassist.data.database.BetList
import dev.nikomaru.raceassist.data.database.BetList.rowUniqueId
import dev.nikomaru.raceassist.data.files.RaceUtils.getRaceConfig
import dev.nikomaru.raceassist.data.files.RaceUtils.save
import dev.nikomaru.raceassist.data.plugin.BetConfig
Expand All @@ -32,6 +31,7 @@ import dev.nikomaru.raceassist.web.api.BetError
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import org.bukkit.Bukkit
import org.bukkit.OfflinePlayer
import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.transactions.transaction
Expand Down Expand Up @@ -110,17 +110,6 @@ class BetManager(val raceId: String) : KoinComponent {
save()
}

/**
* 賭けのスプレッドシートIDを設定します。
* @param spreadSheetId ベットのスプレッドシートID
*/

fun setSpreadSheetId(spreadSheetId: String) {

betConfig[raceId] = betConfig[raceId]!!.copy(spreadSheetId = spreadSheetId)
save()
}

/**
* 賭けのベット単位を設定します。
* @param betUnit ベットのベット単位
Expand All @@ -146,12 +135,18 @@ class BetManager(val raceId: String) : KoinComponent {
* @param amount 引き出す金額
*
*/
fun withdrawFromPlayer(player: OfflinePlayer, amount: Double) {
fun withdrawFromPlayer(player: OfflinePlayer, amount: Double, uniqueId: UUID) {
val eco = VaultAPI.getEconomy()
val beforePlayer = eco.getBalance(player)
val beforeRecord = betConfig[raceId]!!.money
runBlocking {
VaultAPI.getEconomy().withdrawPlayer(player, amount)
betConfig[raceId] = betConfig[raceId]!!.copy(money = betConfig[raceId]!!.money + amount)
save()
}
val afterPlayer = eco.getBalance(player)
val afterRecord = betConfig[raceId]!!.money
plugin.logger.info("transactionId : $uniqueId, player : ${player.name}, beforePlayer : $beforePlayer, afterPlayer : $afterPlayer, beforeRecord : $beforeRecord, afterRecord : $afterRecord")
}

/**
Expand Down Expand Up @@ -189,7 +184,7 @@ class BetManager(val raceId: String) : KoinComponent {

transaction {
BetList.insert { bet ->
bet[raceId] = raceId
bet[raceId] = this@BetManager.raceId
bet[playerUniqueId] = player.uniqueId.toString()
bet[jockeyUniqueId] = jockey.uniqueId.toString()
bet[betting] = price
Expand All @@ -203,14 +198,16 @@ class BetManager(val raceId: String) : KoinComponent {
Lang.getComponent(
"bet-complete-message-player",
onlinePlayer.locale(),
rowUniqueId.toString(),
uniqueId.toString(),
jockey.name.toString(),
price
)
)

withdrawFromPlayer(player, price.toDouble())
BetEvent(LogDataType.BET, raceId, player, jockey, price).callEvent()
withdrawFromPlayer(player, price.toDouble(), uniqueId)
Bukkit.getScheduler().runTaskAsynchronously(plugin, Runnable {
BetEvent(LogDataType.BET, raceId, player, jockey, price).callEvent()
})
return Triple(null, uniqueId, price)
}

Expand Down
5 changes: 1 addition & 4 deletions src/main/kotlin/dev/nikomaru/raceassist/bet/BetUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package dev.nikomaru.raceassist.bet

import dev.nikomaru.raceassist.RaceAssist
import dev.nikomaru.raceassist.bet.data.TempBetData
import dev.nikomaru.raceassist.bet.gui.components.GuiItems.AllPlayers
import dev.nikomaru.raceassist.bet.gui.BetGui.Companion.AllPlayers
import dev.nikomaru.raceassist.data.database.BetList
import dev.nikomaru.raceassist.data.database.BetListData
import dev.nikomaru.raceassist.utils.Lang
Expand Down Expand Up @@ -73,12 +73,9 @@ object BetUtils {
}

fun initializePlayerTempBetData(raceId: String, sender: Player) {
println(AllPlayers[raceId])
AllPlayers[raceId]?.forEach { jockey ->
tempBetDataList.add(TempBetData(raceId, sender, jockey, 0))
}
println(tempBetDataList)

}

suspend fun listBetData(raceId: String): ArrayList<BetListData> {
Expand Down
30 changes: 0 additions & 30 deletions src/main/kotlin/dev/nikomaru/raceassist/bet/GuiComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ object GuiComponent {
}


fun accept(locale: Locale): ItemStack {
val accept = ItemStack(Material.GREEN_WOOL)
val acceptMeta: ItemMeta = accept.itemMeta
acceptMeta.displayName(Lang.getComponent("gui-decide", locale))
accept.itemMeta = acceptMeta
return accept
}

fun deny(locale: Locale): ItemStack {
val deny = ItemStack(Material.RED_WOOL)
Expand All @@ -56,29 +49,6 @@ object GuiComponent {
return reset
}

fun noBet(locale: Locale): ItemStack {
val noBet = ItemStack(Material.BARRIER)
val noBetMeta: ItemMeta = noBet.itemMeta
noBetMeta.displayName(Lang.getComponent("no-one-betting", locale))
noBet.itemMeta = noBetMeta
return noBet
}

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

fun noHaveMoney(locale: Locale): ItemStack {
val noHaveMoney = ItemStack(Material.BARRIER)
val noHaveMoneyMeta: ItemMeta = noHaveMoney.itemMeta
noHaveMoneyMeta.displayName(Lang.getComponent("no-have-money", locale))
noHaveMoney.itemMeta = noHaveMoneyMeta
return noHaveMoney
}

val noDataGrass = GuiItem(ItemStack(Material.GRAY_STAINED_GLASS_PANE))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,18 @@ class BetRevertCommand {
newSuspendedTransaction(Dispatchers.IO) {
BetList.selectAll().where { (BetList.rowUniqueId eq row.toString()) and (BetList.raceId eq raceId) }
.forEach {
val receiver = Bukkit.getOfflinePlayer(it[BetList.playerUniqueId].toUUID())
betManager.depositToPlayer(receiver, it[BetList.betting].toDouble())
executor.sendMessage(
Lang.getComponent(
"bet-revert-return-message-owner",
locale,
receiver.name,
it[BetList.betting]
val receiver = Bukkit.getOfflinePlayer(it[BetList.playerUniqueId].toUUID())
betManager.depositToPlayer(receiver, it[BetList.betting].toDouble())
executor.sendMessage(
Lang.getComponent(
"bet-revert-return-message-owner",
locale,
receiver.name,
it[BetList.betting]
)
)
)
sendRevertMessage(receiver, owner, it)
}
sendRevertMessage(receiver, owner, it)
}
BetList.deleteWhere { (rowUniqueId eq row.toString()) and (BetList.raceId eq raceId) }
}
}
Expand Down
Loading

0 comments on commit eb12dcb

Please sign in to comment.