Improve update helper task

This commit is contained in:
Jason Penilla 2023-12-05 21:46:41 -07:00
parent 2d702b9bad
commit 6aedc2af5d
10 changed files with 72 additions and 26 deletions

View File

@ -4,6 +4,7 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import java.io.ByteArrayOutputStream
import java.nio.file.Path
import java.util.regex.Pattern
import kotlin.io.path.*
plugins {
@ -177,14 +178,21 @@ abstract class RebasePatches : BaseTask() {
private fun unapplied(): List<Path> =
unappliedPatches.path.listDirectoryEntries("*.patch").sortedBy { it.name }
private fun appliedLoc(patch: Path): Path = appliedPatches.path.resolve(unappliedPatches.path.relativize(patch))
companion object {
val regex = Pattern.compile("Patch failed at ([0-9]{4}) (.*)")
const val subjectPrefix = "Subject: [PATCH] "
}
@TaskAction
fun run() {
for (patch in unapplied()) {
val appliedLoc = appliedPatches.path.resolve(unappliedPatches.path.relativize(patch))
patch.copyTo(appliedLoc)
val unapplied = unapplied()
for (patch in unapplied) {
patch.copyTo(appliedLoc(patch))
}
val out = ByteArrayOutputStream()
val proc = ProcessBuilder()
.directory(projectDir.path)
.command("./gradlew", "applyServerPatches")
@ -195,19 +203,57 @@ abstract class RebasePatches : BaseTask() {
val exit = proc.waitFor()
patch.deleteIfExists()
if (exit != 0) {
logger.lifecycle("Patch failed at $patch; Git output:")
logger.lifecycle(String(out.toByteArray()))
val outStr = String(out.toByteArray())
val matcher = regex.matcher(outStr)
if (!matcher.find()) error("Could not determine failure point")
val failedSubjectFragment = matcher.group(2)
val failed = unapplied.single { p ->
p.useLines { lines ->
val subjectLine = lines.single { it.startsWith(subjectPrefix) }
.substringAfter(subjectPrefix)
subjectLine.startsWith(failedSubjectFragment)
}
}
// delete successful & failure point from unapplied patches dir
for (path in unapplied) {
path.deleteIfExists()
if (path == failed) {
break
}
}
// delete failed from patches dir
var started = false
for (path in unapplied) {
if (path == failed) {
started = true
continue
}
if (started) {
appliedLoc(path).deleteIfExists()
}
}
// Apply again to reset the am session (so it ends on the failed patch, to allow us to rebuild after fixing it)
val apply2 = ProcessBuilder()
.directory(projectDir.path)
.command("./gradlew", "applyServerPatches")
.redirectErrorStream(true)
.start()
redirect(apply2.inputStream, System.out)
logger.lifecycle(outStr)
logger.lifecycle("Patch failed at $failed; See Git output above.")
} else {
unapplied.forEach { it.deleteIfExists() }
logger.lifecycle("All patches applied!")
}
val git = Git(projectDir.path)
git("add", appliedPatches.path.toString() + "/*").runSilently()
git("add", unappliedPatches.path.toString() + "/*").runSilently()
logger.lifecycle("Applied $patch")
}
}
}

View File

@ -8,7 +8,7 @@ diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/jav
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
} else {
// CraftBukkit start
worldserver = shapedetectorshape.world;
@ -37,7 +37,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
if (worldserver == this.level) {
// SPIGOT-6782: Just move the entity if a plugin changed the world to the one the entity is already in
this.moveTo(shapedetectorshape.pos.x, shapedetectorshape.pos.y, shapedetectorshape.pos.z, shapedetectorshape.yRot, shapedetectorshape.xRot);
@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
@@ -0,0 +0,0 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
if (entity != null) {
entity.restoreFrom(this);
@ -45,6 +45,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
- entity.setDeltaMovement(shapedetectorshape.speed);
+ entity.moveTo(position.x, position.y, position.z, yaw, pitch); // Paper - use EntityPortalExitEvent values
+ entity.setDeltaMovement(velocity); // Paper - use EntityPortalExitEvent values
// CraftBukkit start - Don't spawn the new entity if the current entity isn't spawned
if (this.inWorld) {
worldserver.addDuringTeleport(entity);
if (worldserver.getTypeKey() == LevelStem.END) { // CraftBukkit
ServerLevel.makeObsidianPlatform(worldserver, this); // CraftBukkit