Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zly2006 committed Nov 17, 2024
1 parent 722c7e7 commit ec720dc
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 6 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ allprojects {
"mc" to mcVer.replace(".", "_"),
"minecraft_version" to mcVer,
"loader_version" to fabricLoaderVer,
"kotlin_loader_version" to kotlinLoaderVer
"kotlin_loader_version" to kotlinLoaderVer,
"build_time" to System.currentTimeMillis(),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.github.zly2006.xbackup.multi;

public interface IColumnPos {
int x$x_backup();
int z$x_backup();
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class BackupDatabaseService(
ServiceLoader.load(IOnedriveUtils::class.java).single()
}
private val ignoredFiles = setOf(
"x_backup.db.back",
"x_backup.db",
"x_backup.db-wal",
"x_backup.db-shm",
Expand Down Expand Up @@ -305,6 +306,8 @@ class BackupDatabaseService(
}
}
val done = atomic(0)
val verbose = map.size < 100
XBackup.log.info("[X Backup] ${map.size} files to restore")
val deferredList = map.map {
this@BackupDatabaseService.async {
val path = target.resolve(it.key).normalize().createParentDirectories()
Expand Down Expand Up @@ -360,7 +363,7 @@ class BackupDatabaseService(
require(path.fileSize() == it.value.size)
path.toFile().setLastModified(it.value.lastModified)
val done = done.incrementAndGet()
if (done % 30 == 0) {
if (done % 30 == 0 || verbose) {
XBackup.log.info("[X Backup] Restored $done files // current: ${it.key}")
}
}
Expand Down
13 changes: 9 additions & 4 deletions core/src/main/kotlin/com/github/zly2006/xbackup/Commands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.github.zly2006.xbackup.Utils.save
import com.github.zly2006.xbackup.Utils.send
import com.github.zly2006.xbackup.Utils.setAutoSaving
import com.github.zly2006.xbackup.ktdsl.register
import com.github.zly2006.xbackup.multi.IColumnPos
import com.mojang.brigadier.CommandDispatcher
import com.mojang.brigadier.arguments.IntegerArgumentType
import com.mojang.brigadier.arguments.StringArgumentType
Expand Down Expand Up @@ -132,8 +133,8 @@ object Commands {
argument("from", ColumnPosArgumentType.columnPos()) {
argument("to", ColumnPosArgumentType.columnPos()).executes {
val id = IntegerArgumentType.getInteger(it, "id")
val from = ColumnPosArgumentType.getColumnPos(it, "from")
val to = ColumnPosArgumentType.getColumnPos(it, "to")
val from = ColumnPosArgumentType.getColumnPos(it, "from") as IColumnPos
val to = ColumnPosArgumentType.getColumnPos(it, "to") as IColumnPos
val path = it.source.server.getSavePath(WorldSavePath.ROOT).toAbsolutePath().normalize()
val world = it.source.world
doRestore(id, it, path) {
Expand All @@ -142,10 +143,14 @@ object Commands {
XBackup.log.debug("[XB] $p is not in world $world, skipping")
return@doRestore false
}
val minX = min(from.`x$x_backup`(), to.`x$x_backup`())
val maxX = max(from.`x$x_backup`(), to.`x$x_backup`())
val minZ = min(from.`z$x_backup`(), to.`z$x_backup`())
val maxZ = max(from.`z$x_backup`(), to.`z$x_backup`())
if (p.extension == "mca") {
val x = p.fileName.toString().split(".")[1].toInt()
val z = p.fileName.toString().split(".")[2].toInt()
if ((x shr 9) >= min(from.x, to.x) shr 9 && (x shr 9) <= max(from.x, to.x) shr 9 && (z shr 9) >= min(from.z, to.z) shr 9 && (z shr 9) <= max(from.z, to.z) shr 9) {
if (x >= minX shr 9 && x <= maxX shr 9 && z >= minZ shr 9 && z <= maxZ shr 9) {
return@doRestore true
}
XBackup.log.debug("[XB] {} is not in chunk range, skipping", p)
Expand All @@ -154,7 +159,7 @@ object Commands {
else if (p.extension == "mcc") {
val x = p.fileName.toString().split(".")[1].toInt()
val z = p.fileName.toString().split(".")[2].toInt()
if ((x shr 4) >= min(from.x, to.x) shr 4 && (x shr 4) <= max(from.x, to.x) shr 4 && (z shr 4) >= min(from.z, to.z) shr 4 && (z shr 4) <= max(from.z, to.z) shr 4) {
if (x >= minX shr 4 && x <= maxX shr 4 && z >= minZ shr 4 && z <= maxZ shr 4) {
return@doRestore true
}
XBackup.log.debug("[XB] {} is not in chunk range, skipping", p)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.github.zly2006.xbackup.mc120.mixin;

import com.github.zly2006.xbackup.multi.IColumnPos;
import net.minecraft.util.math.ColumnPos;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(ColumnPos.class)
public class MixinColumnPos implements IColumnPos {
@Shadow @Final public int x;

@Shadow @Final public int z;

@Override
public int x$x_backup() {
return x;
}

@Override
public int z$x_backup() {
return z;
}
}
1 change: 1 addition & 0 deletions xb-1.20.1/src/main/resources/x_backup.120.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"MixinChunkLoadingManager",
"MixinChunkTaskPrioritySystem",
"MixinChunkTicketManager",
"MixinColumnPos",
"MixinDedicatedServerWatchdog",
"MixinEntityChunkDataAccess",
"MixinLevelPrioritizedQueue",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.github.zly2006.xbackup.mc120.mixin;

import com.github.zly2006.xbackup.multi.IColumnPos;
import net.minecraft.util.math.ColumnPos;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(ColumnPos.class)
public class MixinColumnPos implements IColumnPos {
@Shadow @Final private int x;

@Shadow @Final private int z;

@Override
public int x$x_backup() {
return x;
}

@Override
public int z$x_backup() {
return z;
}
}
1 change: 1 addition & 0 deletions xb-1.20/src/main/resources/x_backup.120.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"MixinChunkLoadingManager",
"MixinChunkTaskPrioritySystem",
"MixinChunkTicketManager",
"MixinColumnPos",
"MixinDedicatedServerWatchdog",
"MixinEntityChunkDataAccess",
"MixinLevelPrioritizedQueue",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.github.zly2006.xbackup.mc121_2.mixin;

import com.github.zly2006.xbackup.multi.IColumnPos;
import net.minecraft.util.math.ColumnPos;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(ColumnPos.class)
public class MixinColumnPos implements IColumnPos {
@Shadow @Final private int x;

@Shadow @Final private int z;

@Override
public int x$x_backup() {
return x;
}

@Override
public int z$x_backup() {
return z;
}
}
1 change: 1 addition & 0 deletions xb-1.21.2/src/main/resources/x_backup.121.2.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"mixins": [
"MixinChunkLoadingManager",
"MixinChunkTicketManager",
"MixinColumnPos",
"MixinDedicatedServerWatchdog",
"MixinEntityChunkDataAccess",
"MixinLevelPrioritizedQueue",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.github.zly2006.xbackup.mc121.mixin;

import com.github.zly2006.xbackup.multi.IColumnPos;
import net.minecraft.util.math.ColumnPos;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(ColumnPos.class)
public class MixinColumnPos implements IColumnPos {
@Shadow @Final private int x;

@Shadow @Final private int z;

@Override
public int x$x_backup() {
return x;
}

@Override
public int z$x_backup() {
return z;
}
}
1 change: 1 addition & 0 deletions xb-1.21/src/main/resources/x_backup.121.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"MixinChunkLoadingManager",
"MixinChunkTaskPrioritySystem",
"MixinChunkTicketManager",
"MixinColumnPos",
"MixinDedicatedServerWatchdog",
"MixinEntityChunkDataAccess",
"MixinLevelPrioritizedQueue",
Expand Down

0 comments on commit ec720dc

Please sign in to comment.