forked from freeserverproject/FSLink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
170 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/main/kotlin/jp/aoichaan0513/fslink/commands/main/CheckVerified.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package jp.aoichaan0513.fslink.commands.main | ||
|
||
import jp.aoichaan0513.fslink.Main | ||
import jp.aoichaan0513.fslink.api.MainAPI | ||
import jp.aoichaan0513.fslink.api.MainAPI.Companion.getPostgrestClient | ||
import jp.aoichaan0513.fslink.commands.ICommand | ||
import jp.aoichaan0513.fslink.consts.FreeserverUser | ||
import net.dv8tion.jda.api.EmbedBuilder | ||
import net.luckperms.api.model.data.DataMutateResult | ||
import net.luckperms.api.node.Node | ||
import org.bukkit.Bukkit | ||
import org.bukkit.command.BlockCommandSender | ||
import org.bukkit.command.Command | ||
import org.bukkit.command.ConsoleCommandSender | ||
import org.bukkit.entity.Player | ||
import java.lang.Error | ||
import java.lang.NullPointerException | ||
import java.time.Instant | ||
|
||
class CheckVerified(name: String) : ICommand(name){ | ||
override fun onPlayerCommand(sp: Player, cmd: Command, label: String, args: Array<String>) { | ||
val playerList = getPostgrestClient() | ||
?.from<FreeserverUser>(MainAPI.TableName.FREESERVER_USER.table) | ||
?.select("discord_id") | ||
?.executeAndGetList<FreeserverUser>() | ||
val userManager = Main.luckPerms.userManager | ||
val groupName = Main.pluginInstance.config.getString("authedGroup", "sabamin")!! | ||
val defaultGroupName = "default" | ||
|
||
if (playerList != null) { | ||
for (player in playerList) { | ||
if (player.discord_id != null) { | ||
val userFuture = userManager.loadUser(player.mcuuid) | ||
userFuture.thenAcceptAsync { lpUser -> | ||
val result1 = lpUser.data().remove(Node.builder("group.${groupName}").build()) | ||
val result2 = lpUser.data().add(Node.builder("group.${defaultGroupName}").build()) | ||
if (result1 == DataMutateResult.SUCCESS && result2 == DataMutateResult.SUCCESS) { | ||
lpUser.primaryGroup = defaultGroupName | ||
Main.luckPerms.userManager.saveUser(lpUser) | ||
Bukkit.getLogger().info("The discordID of ${player.mcuuid} is ${player.discord_id}.") | ||
} else { | ||
Bukkit.getLogger().severe("予期しないエラーが発生しました") | ||
return@thenAcceptAsync | ||
} | ||
} | ||
} else { | ||
Bukkit.getLogger().info("${player.mcuuid} is not verified.") | ||
} | ||
} | ||
return | ||
} | ||
throw NullPointerException("playerList is null") | ||
} | ||
|
||
override fun onBlockCommand(bs: BlockCommandSender, cmd: Command, label: String, args: Array<String>) {} | ||
|
||
override fun onConsoleCommand(cs: ConsoleCommandSender, cmd: Command, label: String, args: Array<String>) {} | ||
|
||
override fun onPlayerTabComplete(sp: Player, cmd: Command, alias: String, args: Array<String>): List<String> { | ||
return emptyList() | ||
} | ||
|
||
override fun onBlockTabComplete( | ||
bs: BlockCommandSender, | ||
cmd: Command, | ||
alias: String, | ||
args: Array<String> | ||
): List<String> { | ||
return emptyList() | ||
} | ||
|
||
override fun onConsoleTabComplete( | ||
cs: ConsoleCommandSender, | ||
cmd: Command, | ||
alias: String, | ||
args: Array<String> | ||
): List<String> { | ||
return emptyList() | ||
} | ||
|
||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/jp/aoichaan0513/fslink/consts/FreeserverUser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package jp.aoichaan0513.fslink.consts | ||
|
||
import java.util.* | ||
|
||
data class FreeserverUser constructor( | ||
val mcuuid: UUID, | ||
val discord_id: String?, | ||
val permissions: String, | ||
val bank_id: UUID?, | ||
val wallet_id: UUID? | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters