Skip to content

Commit

Permalink
👍Fixed a bug in which spreadsheets could not be set individually and …
Browse files Browse the repository at this point in the history
…some tab completion properties did not work properly.
  • Loading branch information
Nlkomaru committed Jan 23, 2022
1 parent ce318b6 commit 7eaa92c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 26 deletions.
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

### Bet

/raceassist bet can [RaceID] on/off 対象のレースに対して賭けが可能か変更します
/raceassist bet can [RaceID] on/off 対象のレースに対して賭けが可能か変更します <br>
/raceassist bet delete [RaceID] 賭けを削除します <br>
/raceassist bet list [RaceID] 賭けの一覧を表示します<br>
/raceassist bet open [RaceID] 賭けをすることのできる画面を開くことができます <br>
Expand Down Expand Up @@ -50,15 +50,6 @@ https://docs.google.com/spreadsheets/d/***********/edit#gid=0 *****の部分を

pluginフォルダの中のRaceAssistフォルダに**credentials.json**を入れます 最初の賭けが行われるとコンソールにOAuthの認証画面が開かれるのでスプレッドシートの所有者が認証してください

### Config.ymlの設定

```yaml
Sheets:
applicationName: 'RaceAssist'
#applicationNameは好きな名前にしてください
spreadsheetId: '******'
#spreadsheetIdはhttps://docs.google.com/spreadsheets/d/******/edit#gid=0の******の部分
```

### credentials.jsonの設定

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ import java.io.*
import java.security.GeneralSecurityException

object GoogleAuthorizeUtil {
private val tokensDirectoryPath = File(plugin!!.dataFolder, "tokens")

private val credentialsFilePath = File(plugin!!.dataFolder, "credentials.json")

@Throws(IOException::class, GeneralSecurityException::class)
fun authorize(): Credential {
fun authorize(spreadsheetId: String): Credential {
val tokensDirectoryPath = File(File(plugin!!.dataFolder, "tokens"), "${spreadsheetId}_tokens")
if (!tokensDirectoryPath.exists()) {
tokensDirectoryPath.mkdirs()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ object SheetsServiceUtil {


@Throws(IOException::class, GeneralSecurityException::class)
fun getSheetsService(): Sheets? {
val credential: Credential = GoogleAuthorizeUtil.authorize()
fun getSheetsService(spreadsheetId: String): Sheets? {
val credential: Credential = GoogleAuthorizeUtil.authorize(spreadsheetId)
return Sheets.Builder(GoogleNetHttpTransport.newTrustedTransport(), GsonFactory.getDefaultInstance(), credential)
.setApplicationName("RaceAssist")
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ class SetBetCommand : BaseCommand() {
player.sendMessage("ほかのプレイヤーのレースを設定することはできません")
return@withContext
}
if (eco.getBalance(player) < BetList.select { BetList.raceID eq raceID }.sumOf { it[BetList.betting] }) {
if (eco.getBalance(player) < getBetSum(raceID)) {
player.sendMessage("お金が足りません")
return@withContext
}
}

if (canRevert[player.uniqueId] == true) {

newSuspendedTransaction(Dispatchers.Main) {
transaction {

BetList.select { BetList.raceID eq raceID }.forEach {

Expand All @@ -176,8 +176,16 @@ class SetBetCommand : BaseCommand() {
}
}

private suspend fun getBetSum(raceID: String) =
newSuspendedTransaction(Dispatchers.IO) {
BetList.select { BetList.raceID eq raceID }.sumOf {
it[BetList
.betting]
}
}

@Subcommand("sheet")
@CommandAlias("@RaceID")
@CommandCompletion("@RaceID")
fun sheet(player: Player, @Single raceID: String, @Single sheetId: String) {
plugin!!.launch {
withContext(Dispatchers.IO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,8 @@ class BetGuiClickEvent : Listener {
}

private suspend fun putSheetsData(raceID: String) = withContext(Dispatchers.Default) {

if (getSheetID(raceID) == null) {
return@withContext
}
val sheetsService = getSheetsService()
val spreadsheetId = getSheetID(raceID) ?: return@withContext
val sheetsService = getSheetsService(spreadsheetId)

var i = 1
val data: ArrayList<ValueRange> = ArrayList()
Expand Down Expand Up @@ -386,7 +383,7 @@ class BetGuiClickEvent : Listener {
.setValueInputOption("USER_ENTERED")
.setData(data)

sheetsService?.spreadsheets()?.values()?.batchUpdate(getSheetID(raceID), batchBody)?.execute()
sheetsService?.spreadsheets()?.values()?.batchUpdate(spreadsheetId, batchBody)?.execute()
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,9 @@ class RaceCommand : BaseCommand() {
BetList.deleteWhere { BetList.raceID eq raceID }
BetSetting.deleteWhere { BetSetting.raceID eq raceID }
TempBetData.deleteWhere { TempBetData.raceID eq raceID }

if (getSheetID(raceID) != null) {
val sheetsService = SheetsServiceUtil.getSheetsService()
val spreadsheetId = getSheetID(raceID)
if (spreadsheetId != null) {
val sheetsService = SheetsServiceUtil.getSheetsService(spreadsheetId)

val range = "${raceID}_RaceAssist!A1:E"
val requestBody = ClearValuesRequest()
Expand Down

0 comments on commit 7eaa92c

Please sign in to comment.