Extra slots fix

This commit is contained in:
TomTom 2024-07-01 09:38:55 +02:00
parent 80d440c538
commit d04eae11ac
3 changed files with 14 additions and 0 deletions

View File

@ -38,6 +38,8 @@ interface DataHandler {
fun getIsland(island: String): Int
fun addUser(uuid: UUID, name: String)
fun addExtraSlot(user: UUID, amount: Int)
fun getExtraSlots(user: UUID): Int

View File

@ -195,6 +195,7 @@ class AxMinionsCommand {
fun extraSlot(commandSender: CommandSender, offlinePlayer: OfflinePlayer, amount: Int) {
AxMinionsPlugin.dataQueue.submit {
val original = AxMinionsPlugin.dataHandler.getExtraSlots(offlinePlayer.uniqueId)
AxMinionsPlugin.dataHandler.addUser(offlinePlayer.uniqueId, offlinePlayer.name ?: "---")
AxMinionsPlugin.dataHandler.addExtraSlot(offlinePlayer.uniqueId, amount)
commandSender.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.SLOT_GIVE(), Placeholder.unparsed("player", offlinePlayer.name ?: "???"), Placeholder.unparsed("amount", amount.toString())))
offlinePlayer.player?.sendMessage(StringUtils.formatToString(Messages.PREFIX() + Messages.SLOT_RECEIVE(), Placeholder.unparsed("amount", amount.toString()), Placeholder.unparsed("from", original.toString()), Placeholder.unparsed("to", (original + amount).toString())))

View File

@ -427,6 +427,17 @@ class H2DataHandler : DataHandler {
return 0
}
override fun addUser(uuid: UUID, name: String) {
dataSource.connection.use { connection ->
connection.prepareStatement("INSERT IGNORE INTO `axminions_users`(`uuid`, `name`, `island_slots`) VALUES (?,?,?);").use { statement ->
statement.setObject(1, uuid)
statement.setString(2, name)
statement.setInt(3, 0)
statement.executeUpdate()
}
}
}
override fun addExtraSlot(user: UUID, amount: Int) {
dataSource.connection.use { connection ->
connection.prepareStatement("UPDATE `axminions_users` SET `island_slots` = `island_slots` + ? WHERE `uuid` = ?;").use { statement ->