aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt6
-rw-r--r--src/main/kotlin/moe/nea/ledger/Ledger.kt2
-rw-r--r--src/main/kotlin/moe/nea/ledger/QueryCommand.kt28
3 files changed, 34 insertions, 2 deletions
diff --git a/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt b/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt
index c269c3d..30610e9 100644
--- a/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt
+++ b/src/main/kotlin/moe/nea/ledger/ItemIdProvider.kt
@@ -137,7 +137,7 @@ class ItemIdProvider {
ItemId("SKYBLOCK_POWDER_${generateName(it).string}")
} ?: id.ifDropLast(" Essence") {
ItemId("ESSENCE_${generateName(it).string}")
- } ?: generateName(id)
+ } ?: generateName(id)
}
}
return Pair(id, parseShortNumber(group("amount")))
@@ -155,4 +155,8 @@ class ItemIdProvider {
}
return findForName(properName, fallbackToGenerated)?.let { Pair(it, 1.0) }
}
+
+ fun getKnownItemIds(): Collection<ItemId> {
+ return knownNames.values
+ }
} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/ledger/Ledger.kt b/src/main/kotlin/moe/nea/ledger/Ledger.kt
index e5af95c..2f828b0 100644
--- a/src/main/kotlin/moe/nea/ledger/Ledger.kt
+++ b/src/main/kotlin/moe/nea/ledger/Ledger.kt
@@ -87,13 +87,13 @@ class Ledger {
fun runLater(runnable: Runnable) {
tickQueue.add(runnable)
}
+ val di = DI()
}
@Mod.EventHandler
fun init(event: FMLInitializationEvent) {
logger.info("Initializing ledger")
- val di = DI()
TelemetryProvider.setupFor(di)
di.registerSingleton(this)
di.registerSingleton(Minecraft.getMinecraft())
diff --git a/src/main/kotlin/moe/nea/ledger/QueryCommand.kt b/src/main/kotlin/moe/nea/ledger/QueryCommand.kt
index 71a57e1..9967a4a 100644
--- a/src/main/kotlin/moe/nea/ledger/QueryCommand.kt
+++ b/src/main/kotlin/moe/nea/ledger/QueryCommand.kt
@@ -9,6 +9,7 @@ import moe.nea.ledger.database.Database
import moe.nea.ledger.utils.di.Inject
import net.minecraft.command.CommandBase
import net.minecraft.command.ICommandSender
+import net.minecraft.util.BlockPos
import net.minecraft.util.ChatComponentText
import net.minecraft.util.ChatStyle
import net.minecraft.util.EnumChatFormatting
@@ -68,6 +69,18 @@ class QueryCommand : CommandBase() {
}
}
+ override fun addTabCompletionOptions(
+ sender: ICommandSender,
+ args: Array<out String>,
+ pos: BlockPos
+ ): MutableList<String>? {
+ when (val p = parseArgs(args)) {
+ is ParseResult.MissingArg -> return null
+ is ParseResult.Success -> return p.lastFilterM.tabComplete(args.last())
+ is ParseResult.UnknownFilter -> return getListOfStringsMatchingLastWord(args, mFilters.keys)
+ }
+ }
+
@Inject
lateinit var database: Database
private fun executeQuery(parse: ParseResult.Success) {
@@ -148,20 +161,35 @@ class QueryCommand : CommandBase() {
val preparedText = "%" + text.trim('%') + "%"
return Clause { column(DBLogEntry.type) like preparedText }
}
+
+ override fun tabComplete(partialArg: String): MutableList<String> {
+ return TransactionType.entries.asSequence().map { it.name }.filter { partialArg in it }.toMutableList()
+ }
}
object ItemFilter : FilterM {
override val name: String
get() = "withitem"
+ private val itemIdProvider = Ledger.di.provide<ItemIdProvider>() // TODO: close this escape hatch
override fun getFilter(text: String): BooleanExpression {
return Clause { column(DBItemEntry.itemId) like text }
}
+
+ override fun tabComplete(partialArg: String): MutableList<String>? {
+ return itemIdProvider.getKnownItemIds()
+ .asSequence()
+ .map { it.string }
+ .filter { partialArg in it }
+ .take(100)
+ .toMutableList()
+ }
}
interface FilterM {
val name: String
fun getFilter(text: String): BooleanExpression
+ fun tabComplete(partialArg: String): MutableList<String>?
// fun tabCompleteFilter() TODO
}