Skip to content

Commit

Permalink
Merge branch 'master' into 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
DrexHD committed Jun 13, 2024
2 parents 541be9d + 0c0ebec commit 7c0ec5e
Show file tree
Hide file tree
Showing 20 changed files with 425 additions and 136 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up python 3
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Install mkdocs and mike
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v1
uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'temurin'
- name: Build artifacts
run: ./gradlew build
- name: Upload build artifacts
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: build/libs
path: build/libs
5 changes: 3 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v1
uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'temurin'

- name: Build release
run: ./gradlew build
Expand Down
15 changes: 14 additions & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,20 @@ Found under `[database]`

`queueTimeoutMin` [Default: 5] is the maximum amount of time to wait for the queue to drain when the server stops in minutes

`queueCheckDelaySec` [Default: 10] is the amount of time between checking if the queue is empty when the server stops in seconds
`queueCheckDelaySec` [Default: 10] is the frequency in seconds to notify in console that the queue is not empty when the server stops

`autoPurgeDays` [Default: -1] is the number of days to keep actions in the database. If set to -1, actions will never be purged automatically

`batchSize` [Default: 1000] is the number of actions to insert into the database at once.
This can be increased to improve performance, but may cause issues with slow databases

`batchDelay` [Default: 10] is the amount of time in ticks to wait between batches if the next batch isn't full.
This can be increased to improve performance, but may cause issues with slow databases

`location` [Default: Nothing] is the location of the database file when using the default SQLite database or other file based databases like H2.
The path is relative to the server's root directory. If the path is left out, the database will default to the server's world directory.

`logSQL` [Default: false] will log all SQL queries to the console. This is useful for debugging, but can be very spammy

### Search settings

Expand Down
2 changes: 1 addition & 1 deletion docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ properties = []
`url`: Must be URL of database with `/<database_name>` appended. An example URL would be `localhost/ledger`. You can optionally add port information such as `localhost:3000/ledger`

### PostgreSQL
MySQL requires running a separate PostgreSQL database and more setup than just plug and play SQLite, but can support much larger databases at faster speeds. It is more experimental the MySQL but may yield faster performance.
PostgreSQL requires running a separate PostgreSQL database and more setup than just plug and play SQLite, but can support much larger databases at faster speeds. It is more experimental the MySQL but may yield faster performance.

Add the following to the bottom of your Ledger config file:

Expand Down
2 changes: 1 addition & 1 deletion docs/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ An easy way to remember the difference between `before:1d` and `after:1d` is to
If you go back in time 1 day, do you want everything that happened `before` then or `after` then.
Usually you want `after`.

### Rollback Status
## Rollback Status
Key - `rolledback:`
Value - `true` or `false`
Negative Allowed - `No`
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ kotlin.code.style=official
org.gradle.jvmargs=-Xmx2G

# Mod Properties
modVersion = 1.3.0
modVersion = 1.3.2
mavenGroup = com.github.quiltservertools
modId = ledger
modName = Ledger
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.quiltservertools.ledger.actions

import com.github.quiltservertools.ledger.actionutils.Preview
import com.github.quiltservertools.ledger.utility.NbtUtils
import com.github.quiltservertools.ledger.utility.TextColorPallet
import com.github.quiltservertools.ledger.utility.getOtherChestSide
import com.github.quiltservertools.ledger.utility.getWorld
Expand All @@ -16,7 +17,6 @@ import net.minecraft.item.AliasedBlockItem
import net.minecraft.item.BlockItem
import net.minecraft.item.ItemStack
import net.minecraft.item.Items
import net.minecraft.nbt.StringNbtReader
import net.minecraft.registry.Registries
import net.minecraft.server.MinecraftServer
import net.minecraft.server.command.ServerCommandSource
Expand All @@ -37,8 +37,14 @@ abstract class ItemChangeActionType : AbstractActionType() {
}
}

private fun getStack(server: MinecraftServer) = NbtUtils.itemFromProperties(
extraData,
objectIdentifier,
server.registryManager
)

override fun getObjectMessage(source: ServerCommandSource): Text {
val stack = ItemStack.fromNbtOrEmpty(source.registryManager, StringNbtReader.parse(extraData))
val stack = getStack(source.server)

return "${stack.count} ".literal().append(
Text.translatable(
Expand Down Expand Up @@ -74,7 +80,7 @@ abstract class ItemChangeActionType : AbstractActionType() {
private fun addPreview(preview: Preview, player: ServerPlayerEntity, pos: BlockPos, insert: Boolean) {
preview.modifiedItems.compute(pos) { _, list ->
list ?: mutableListOf()
}?.add(Pair(ItemStack.fromNbtOrEmpty(player.server.registryManager, StringNbtReader.parse(extraData)), insert))
}?.add(Pair(getStack(player.server), insert))
}

private fun getInventory(world: ServerWorld): Inventory? {
Expand All @@ -100,8 +106,8 @@ abstract class ItemChangeActionType : AbstractActionType() {
val world = server.getWorld(world)
val inventory = world?.let { getInventory(it) }

if (world != null && inventory != null) {
val rollbackStack = ItemStack.fromNbtOrEmpty(server.registryManager, StringNbtReader.parse(extraData))
if (world != null) {
val rollbackStack = getStack(server)

if (inventory != null) {
for (i in 0 until inventory.size()) {
Expand Down Expand Up @@ -129,7 +135,7 @@ abstract class ItemChangeActionType : AbstractActionType() {
val inventory = world?.let { getInventory(it) }

if (world != null) {
val rollbackStack = ItemStack.fromNbtOrEmpty(server.registryManager, StringNbtReader.parse(extraData))
val rollbackStack = getStack(server)

if (inventory != null) {
for (i in 0 until inventory.size()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.quiltservertools.ledger.actions

import com.github.quiltservertools.ledger.utility.NbtUtils
import com.github.quiltservertools.ledger.utility.TextColorPallet
import com.github.quiltservertools.ledger.utility.UUID
import com.github.quiltservertools.ledger.utility.getWorld
Expand All @@ -9,7 +10,6 @@ import net.minecraft.entity.EntityType
import net.minecraft.entity.ItemEntity
import net.minecraft.item.AliasedBlockItem
import net.minecraft.item.BlockItem
import net.minecraft.item.ItemStack
import net.minecraft.nbt.StringNbtReader
import net.minecraft.registry.Registries
import net.minecraft.server.MinecraftServer
Expand All @@ -30,8 +30,14 @@ open class ItemDropActionType : AbstractActionType() {
}
}

private fun getStack(server: MinecraftServer) = NbtUtils.itemFromProperties(
extraData,
objectIdentifier,
server.registryManager
)

override fun getObjectMessage(source: ServerCommandSource): Text {
val stack = ItemStack.fromNbtOrEmpty(source.registryManager, StringNbtReader.parse(extraData))
val stack = getStack(source.server)

return "${stack.count} ".literal().append(
Text.translatable(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.quiltservertools.ledger.actions

import com.github.quiltservertools.ledger.utility.NbtUtils
import com.github.quiltservertools.ledger.utility.TextColorPallet
import com.github.quiltservertools.ledger.utility.UUID
import com.github.quiltservertools.ledger.utility.getWorld
Expand All @@ -9,7 +10,6 @@ import net.minecraft.entity.EntityType
import net.minecraft.entity.ItemEntity
import net.minecraft.item.AliasedBlockItem
import net.minecraft.item.BlockItem
import net.minecraft.item.ItemStack
import net.minecraft.nbt.StringNbtReader
import net.minecraft.registry.Registries
import net.minecraft.server.MinecraftServer
Expand All @@ -30,8 +30,14 @@ open class ItemPickUpActionType : AbstractActionType() {
}
}

private fun getStack(server: MinecraftServer) = NbtUtils.itemFromProperties(
extraData,
objectIdentifier,
server.registryManager
)

override fun getObjectMessage(source: ServerCommandSource): Text {
val stack = ItemStack.fromNbtOrEmpty(source.registryManager, StringNbtReader.parse(extraData))
val stack = getStack(source.server)

return "${stack.count} ".literal().append(
Text.translatable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.github.quiltservertools.ledger.api

import com.github.quiltservertools.ledger.Ledger
import com.github.quiltservertools.ledger.config.config
import com.github.quiltservertools.ledger.config.getDatabasePath
import net.minecraft.server.MinecraftServer
import net.minecraft.util.WorldSavePath
import javax.sql.DataSource

object ExtensionManager {
Expand All @@ -30,7 +30,7 @@ object ExtensionManager {
extensions.forEach {
if (it is DatabaseExtension) {
if (dataSource == null) {
dataSource = it.getDataSource(server.getSavePath(WorldSavePath.ROOT))
dataSource = it.getDataSource(config.getDatabasePath())
} else {
failExtensionRegistration(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import net.minecraft.util.math.BlockBox
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Vec3i
import java.time.Instant
import java.util.*
import java.util.concurrent.CompletableFuture

object SearchParamArgument {
Expand Down Expand Up @@ -140,7 +141,8 @@ object SearchParamArgument {
}
} else {
val profile = source.server.userCache?.findByName(sourceInput.property)
val id = profile?.orElse(null)?.id
// If the player doesn't exist use a random UUID to make the query not match
val id = profile?.orElse(null)?.id ?: UUID.randomUUID()

if (id != null) {
val playerIdEntry = Negatable(id, sourceInput.allowed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ class SourceParameter : SimpleParameter<String>() {
val stringReader = StringReader(builder.input)
stringReader.cursor = builder.start

val players = context.source.playerNames
val sources = context.source.playerNames
DatabaseManager.getKnownSources().forEach {
players.add("@$it")
sources.add("@$it")
}
// TODO suggest non-player sources

return CommandSource.suggestMatching(
players,
sources,
builder
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.github.quiltservertools.ledger.config

import com.github.quiltservertools.ledger.Ledger
import com.uchuhimo.konf.Config
import com.uchuhimo.konf.ConfigSpec
import net.minecraft.util.WorldSavePath
import java.nio.file.Path

@Suppress("MagicNumber")
object DatabaseSpec : ConfigSpec() {
Expand All @@ -10,4 +14,14 @@ object DatabaseSpec : ConfigSpec() {
val batchSize by optional<Int>(1000)
val batchDelay by optional<Int>(10)
val logSQL by optional<Boolean>(false)
val location by optional<String?>(null)
}

fun Config.getDatabasePath(): Path {
val location = config[DatabaseSpec.location]
return if (location != null) {
Path.of(location)
} else {
Ledger.server.getSavePath(WorldSavePath.ROOT)
}
}
Loading

0 comments on commit 7c0ec5e

Please sign in to comment.