Skip to content

Commit

Permalink
fix: warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
zly2006 committed Jun 2, 2024
1 parent 0610f62 commit 3de15ab
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 66 deletions.
3 changes: 2 additions & 1 deletion src/main/kotlin/com/github/quiltservertools/ledger/Ledger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
import org.jetbrains.exposed.sql.vendors.SQLiteDialect
import java.nio.file.Files
import java.util.UUID
import java.util.*
import java.util.concurrent.ConcurrentHashMap
import kotlin.coroutines.CoroutineContext
import kotlin.time.Duration.Companion.minutes
Expand Down Expand Up @@ -112,6 +112,7 @@ object Ledger : DedicatedServerModInitializer, CoroutineScope {
}
}

@Suppress("UNUSED_PARAMETER")
private fun serverStopped(server: MinecraftServer) {
runBlocking {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ open class ItemDropActionType : AbstractActionType() {
override fun restore(server: MinecraftServer): Boolean {
val world = server.getWorld(world)

val newEntity = StringNbtReader.parse(objectState)
val uuid = newEntity!!.getUuid(UUID) ?: return false
val newEntityNbt = StringNbtReader.parse(objectState)
val uuid = newEntityNbt!!.getUuid(UUID) ?: return false
val entity = world?.getEntity(uuid)

if (entity == null) {
val entity = ItemEntity(EntityType.ITEM, world)
entity.readNbt(newEntity)
world?.spawnEntity(entity)
val newEntity = ItemEntity(EntityType.ITEM, world)
newEntity.readNbt(newEntityNbt)
world?.spawnEntity(newEntity)
}
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ open class ItemPickUpActionType : AbstractActionType() {
override fun rollback(server: MinecraftServer): Boolean {
val world = server.getWorld(world)

val oldEntity = StringNbtReader.parse(oldObjectState)
val uuid = oldEntity!!.getUuid(UUID) ?: return false
val oldEntityNbt = StringNbtReader.parse(oldObjectState)
val uuid = oldEntityNbt!!.getUuid(UUID) ?: return false
val entity = world?.getEntity(uuid)

if (entity == null) {
val entity = ItemEntity(EntityType.ITEM, world)
entity.readNbt(oldEntity)
world?.spawnEntity(entity)
val oldEntity = ItemEntity(EntityType.ITEM, world)
oldEntity.readNbt(oldEntityNbt)
world?.spawnEntity(oldEntity)
}
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,23 +452,11 @@ object DatabaseManager {

private fun Transaction.selectActionsSearch(params: ActionSearchParams, page: Int): SearchResults {
val actions = mutableListOf<ActionType>()
var totalActions: Long

var query = Tables.Actions
.innerJoin(Tables.ActionIdentifiers)
.innerJoin(Tables.Worlds)
.leftJoin(Tables.Players)
.innerJoin(
Tables.oldObjectTable,
{ Tables.Actions.oldObjectId },
{ Tables.oldObjectTable[Tables.ObjectIdentifiers.id] }
)
.innerJoin(Tables.ObjectIdentifiers, { Tables.Actions.objectId }, { Tables.ObjectIdentifiers.id })
.innerJoin(Tables.Sources)
.selectAll()

var query = joinTables().selectAll()
.andWhere { buildQueryParams(params) }

totalActions = countActions(params)
val totalActions = countActions(params)
if (totalActions == 0L) return SearchResults(actions, params, page, 0)

query = query.orderBy(Tables.Actions.id, SortOrder.DESC)
Expand Down Expand Up @@ -497,18 +485,7 @@ object DatabaseManager {

val isRestore = type == Preview.Type.RESTORE

val selectQuery = Tables.Actions
.innerJoin(Tables.ActionIdentifiers)
.innerJoin(Tables.Worlds)
.leftJoin(Tables.Players)
.innerJoin(
Tables.oldObjectTable,
{ Tables.Actions.oldObjectId },
{ Tables.oldObjectTable[Tables.ObjectIdentifiers.id] }
)
.innerJoin(Tables.ObjectIdentifiers, { Tables.Actions.objectId }, { Tables.ObjectIdentifiers.id })
.innerJoin(Tables.Sources)
.selectAll()
val selectQuery = joinTables().selectAll()
.andWhere { buildQueryParams(params) and (Tables.Actions.rolledBack eq isRestore) }
.orderBy(Tables.Actions.id, if (isRestore) SortOrder.ASC else SortOrder.DESC)
actions.addAll(getActionsFromQuery(selectQuery))
Expand All @@ -519,18 +496,7 @@ object DatabaseManager {
private fun Transaction.selectAndRollbackActions(params: ActionSearchParams): MutableList<ActionType> {
val actions = mutableListOf<ActionType>()

val selectQuery = Tables.Actions
.innerJoin(Tables.ActionIdentifiers)
.innerJoin(Tables.Worlds)
.leftJoin(Tables.Players)
.innerJoin(
Tables.oldObjectTable,
{ Tables.Actions.oldObjectId },
{ Tables.oldObjectTable[Tables.ObjectIdentifiers.id] }
)
.innerJoin(Tables.ObjectIdentifiers, { Tables.Actions.objectId }, { Tables.ObjectIdentifiers.id })
.innerJoin(Tables.Sources)
.selectAll()
val selectQuery = joinTables().selectAll()
.andWhere { buildQueryParams(params) and (Tables.Actions.rolledBack eq false) }
.orderBy(Tables.Actions.id, SortOrder.DESC)
val actionIds = selectQuery.map { it[Tables.Actions.id] }
Expand All @@ -545,21 +511,22 @@ object DatabaseManager {
return actions
}

private fun Transaction.joinTables() = Tables.Actions
.innerJoin(Tables.ActionIdentifiers)
.innerJoin(Tables.Worlds)
.leftJoin(Tables.Players)
.innerJoin(
Tables.oldObjectTable,
{ Tables.Actions.oldObjectId },
{ Tables.oldObjectTable[Tables.ObjectIdentifiers.id] }
)
.innerJoin(Tables.ObjectIdentifiers, { Tables.Actions.objectId }, { Tables.ObjectIdentifiers.id })
.innerJoin(Tables.Sources)

private fun Transaction.selectAndRestoreActions(params: ActionSearchParams): MutableList<ActionType> {
val actions = mutableListOf<ActionType>()

val selectQuery = Tables.Actions
.innerJoin(Tables.ActionIdentifiers)
.innerJoin(Tables.Worlds)
.leftJoin(Tables.Players)
.innerJoin(
Tables.oldObjectTable,
{ Tables.Actions.oldObjectId },
{ Tables.oldObjectTable[Tables.ObjectIdentifiers.id] }
)
.innerJoin(Tables.ObjectIdentifiers, { Tables.Actions.objectId }, { Tables.ObjectIdentifiers.id })
.innerJoin(Tables.Sources)
.selectAll()
val selectQuery = joinTables().selectAll()
.andWhere { buildQueryParams(params) and (Tables.Actions.rolledBack eq true) }
.orderBy(Tables.Actions.id, SortOrder.ASC)
val actionIds = selectQuery.map { it[Tables.Actions.id] }.toSet()
Expand All @@ -576,14 +543,14 @@ object DatabaseManager {
fun getKnownSources() =
cache.sourceKeys.asMap().keys

private fun <T> getObjectId(
private fun <T : Any> getObjectId(
obj: T,
cache: Cache<T, Int>,
table: EntityClass<Int, Entity<Int>>,
column: Column<T>
): Int? = getObjectId(obj, Function.identity(), cache, table, column)

private fun <T, S> getObjectId(
private fun <T : Any, S> getObjectId(
obj: T,
mapper: Function<T, S>,
cache: Cache<T, Int>,
Expand All @@ -596,7 +563,7 @@ object DatabaseManager {
}
}

private fun <T> getOrCreateObjectId(
private fun <T : Any> getOrCreateObjectId(
obj: T,
cache: Cache<T, Int>,
entity: IntEntityClass<*>,
Expand All @@ -605,7 +572,7 @@ object DatabaseManager {
): Int =
getOrCreateObjectId(obj, Function.identity(), cache, entity, table, column)

private fun <T, S> getOrCreateObjectId(
private fun <T : Any, S> getOrCreateObjectId(
obj: T,
mapper: Function<T, S>,
cache: Cache<T, Int>,
Expand Down

0 comments on commit 3de15ab

Please sign in to comment.