diff --git a/build.gradle.kts b/build.gradle.kts index cb9e7e93b8..5449518dba 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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,37 +178,82 @@ abstract class RebasePatches : BaseTask() { private fun unapplied(): List = 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 out = ByteArrayOutputStream() + val proc = ProcessBuilder() + .directory(projectDir.path) + .command("./gradlew", "applyServerPatches") + .redirectErrorStream(true) + .start() - val proc = ProcessBuilder() + redirect(proc.inputStream, out) + + val exit = proc.waitFor() + + if (exit != 0) { + 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(proc.inputStream, out) + redirect(apply2.inputStream, System.out) - val exit = proc.waitFor() - - patch.deleteIfExists() - - if (exit != 0) { - logger.lifecycle("Patch failed at $patch; Git output:") - logger.lifecycle(String(out.toByteArray())) - break - } - - val git = Git(projectDir.path) - git("add", appliedPatches.path.toString() + "/*").runSilently() - git("add", unappliedPatches.path.toString() + "/*").runSilently() - - logger.lifecycle("Applied $patch") + 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() } } diff --git a/patches/unapplied/server/0649-Configurable-item-frame-map-cursor-update-interval.patch b/patches/server/0649-Configurable-item-frame-map-cursor-update-interval.patch similarity index 100% rename from patches/unapplied/server/0649-Configurable-item-frame-map-cursor-update-interval.patch rename to patches/server/0649-Configurable-item-frame-map-cursor-update-interval.patch diff --git a/patches/unapplied/server/0650-Make-EntityUnleashEvent-cancellable.patch b/patches/server/0650-Make-EntityUnleashEvent-cancellable.patch similarity index 94% rename from patches/unapplied/server/0650-Make-EntityUnleashEvent-cancellable.patch rename to patches/server/0650-Make-EntityUnleashEvent-cancellable.patch index 17a8a654c4..027330d9f9 100644 --- a/patches/unapplied/server/0650-Make-EntityUnleashEvent-cancellable.patch +++ b/patches/server/0650-Make-EntityUnleashEvent-cancellable.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Make EntityUnleashEvent cancellable diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java -index 2e8b1d7b81e212a7b06f4844d0633241dc4b77bf..1e997c1758ed86dc563983317ceb17e626b8dba7 100644 +index 764a5dd85e3fb581b1e713ce9b148be1874d55be..16d84042e2575418880897c728a99d1b8bbcdd15 100644 --- a/src/main/java/net/minecraft/world/entity/Mob.java +++ b/src/main/java/net/minecraft/world/entity/Mob.java -@@ -1549,7 +1549,7 @@ public abstract class Mob extends LivingEntity implements Targeting { +@@ -1550,7 +1550,7 @@ public abstract class Mob extends LivingEntity implements Targeting { if (flag1 && this.isLeashed()) { // Paper start - drop leash variable EntityUnleashEvent event = new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.UNKNOWN, true); diff --git a/patches/unapplied/server/0651-Clear-bucket-NBT-after-dispense.patch b/patches/server/0651-Clear-bucket-NBT-after-dispense.patch similarity index 91% rename from patches/unapplied/server/0651-Clear-bucket-NBT-after-dispense.patch rename to patches/server/0651-Clear-bucket-NBT-after-dispense.patch index 1f2a7cae78..e0ba56c333 100644 --- a/patches/unapplied/server/0651-Clear-bucket-NBT-after-dispense.patch +++ b/patches/server/0651-Clear-bucket-NBT-after-dispense.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Clear bucket NBT after dispense diff --git a/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java b/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java -index d500de41d0a61d67aff523fe436da06e625687dd..b5ea499b78970ec1575893e3b52900bf34feb3ec 100644 +index 8c8d2e81f0866dc1441e181f2580852d87263bcc..9f220c99d7374ab3d9db222346694342d3e926c1 100644 --- a/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java +++ b/src/main/java/net/minecraft/core/dispenser/DispenseItemBehavior.java @@ -650,8 +650,7 @@ public interface DispenseItemBehavior { diff --git a/patches/unapplied/server/0652-Change-EnderEye-target-without-changing-other-things.patch b/patches/server/0652-Change-EnderEye-target-without-changing-other-things.patch similarity index 100% rename from patches/unapplied/server/0652-Change-EnderEye-target-without-changing-other-things.patch rename to patches/server/0652-Change-EnderEye-target-without-changing-other-things.patch diff --git a/patches/unapplied/server/0653-Add-BlockBreakBlockEvent.patch b/patches/server/0653-Add-BlockBreakBlockEvent.patch similarity index 94% rename from patches/unapplied/server/0653-Add-BlockBreakBlockEvent.patch rename to patches/server/0653-Add-BlockBreakBlockEvent.patch index 52a9d63ddc..bd3d51aa81 100644 --- a/patches/unapplied/server/0653-Add-BlockBreakBlockEvent.patch +++ b/patches/server/0653-Add-BlockBreakBlockEvent.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Add BlockBreakBlockEvent diff --git a/src/main/java/net/minecraft/world/level/block/Block.java b/src/main/java/net/minecraft/world/level/block/Block.java -index 36b196c8834c4eb873bfca0b12f1fc2b421ea071..9522e646529f3d849471931b4b3c0d133e7fcfc5 100644 +index 2c190473b98899e86d8bcd5a81c72bbc0a85b2a9..f0a85f1b48a911ffd8740df5ebe869e8f0371a58 100644 --- a/src/main/java/net/minecraft/world/level/block/Block.java +++ b/src/main/java/net/minecraft/world/level/block/Block.java -@@ -319,6 +319,23 @@ public class Block extends BlockBehaviour implements ItemLike { +@@ -326,6 +326,23 @@ public class Block extends BlockBehaviour implements ItemLike { } } @@ -33,10 +33,10 @@ index 36b196c8834c4eb873bfca0b12f1fc2b421ea071..9522e646529f3d849471931b4b3c0d13 public static void dropResources(BlockState state, Level world, BlockPos pos, @Nullable BlockEntity blockEntity, @Nullable Entity entity, ItemStack tool) { if (world instanceof ServerLevel) { diff --git a/src/main/java/net/minecraft/world/level/block/piston/PistonBaseBlock.java b/src/main/java/net/minecraft/world/level/block/piston/PistonBaseBlock.java -index 929241e479a42011f073fb9d144739b6504132b1..b9896fd8e96a908637ce1edf9413166192903ce7 100644 +index 565da027ca7c395f9b965505cbe9e85e62367834..cda90023ad662e8875365eac98ec69f476dcb42d 100644 --- a/src/main/java/net/minecraft/world/level/block/piston/PistonBaseBlock.java +++ b/src/main/java/net/minecraft/world/level/block/piston/PistonBaseBlock.java -@@ -402,7 +402,7 @@ public class PistonBaseBlock extends DirectionalBlock { +@@ -415,7 +415,7 @@ public class PistonBaseBlock extends DirectionalBlock { iblockdata1 = world.getBlockState(blockposition3); BlockEntity tileentity = iblockdata1.hasBlockEntity() ? world.getBlockEntity(blockposition3) : null; diff --git a/patches/unapplied/server/0654-Option-to-prevent-NBT-copy-in-smithing-recipes.patch b/patches/server/0654-Option-to-prevent-NBT-copy-in-smithing-recipes.patch similarity index 98% rename from patches/unapplied/server/0654-Option-to-prevent-NBT-copy-in-smithing-recipes.patch rename to patches/server/0654-Option-to-prevent-NBT-copy-in-smithing-recipes.patch index 1002fe00f7..bd57709b19 100644 --- a/patches/unapplied/server/0654-Option-to-prevent-NBT-copy-in-smithing-recipes.patch +++ b/patches/server/0654-Option-to-prevent-NBT-copy-in-smithing-recipes.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Option to prevent NBT copy in smithing recipes diff --git a/src/main/java/net/minecraft/world/item/crafting/SmithingTransformRecipe.java b/src/main/java/net/minecraft/world/item/crafting/SmithingTransformRecipe.java -index 3036abbcf12753a43f520fc2528928cb9849c311..473b3f7aa7ca4d1c4b9e911984bc7b2647c9bdec 100644 +index 566b588006da2b46ec1727be85560ccd59c42c6f..8f71a60c1d83dfad67ac77ec4464a55c7439d4b3 100644 --- a/src/main/java/net/minecraft/world/item/crafting/SmithingTransformRecipe.java +++ b/src/main/java/net/minecraft/world/item/crafting/SmithingTransformRecipe.java @@ -23,8 +23,15 @@ public class SmithingTransformRecipe implements SmithingRecipe { diff --git a/patches/unapplied/server/0655-More-CommandBlock-API.patch b/patches/server/0655-More-CommandBlock-API.patch similarity index 100% rename from patches/unapplied/server/0655-More-CommandBlock-API.patch rename to patches/server/0655-More-CommandBlock-API.patch diff --git a/patches/unapplied/server/0656-Add-missing-team-sidebar-display-slots.patch b/patches/server/0656-Add-missing-team-sidebar-display-slots.patch similarity index 98% rename from patches/unapplied/server/0656-Add-missing-team-sidebar-display-slots.patch rename to patches/server/0656-Add-missing-team-sidebar-display-slots.patch index 446d882c45..0d7e79e26d 100644 --- a/patches/unapplied/server/0656-Add-missing-team-sidebar-display-slots.patch +++ b/patches/server/0656-Add-missing-team-sidebar-display-slots.patch @@ -52,7 +52,7 @@ index 73c5ffff70605b32188a9bb5fb6c0ee04cb66efe..711d227f5ee6d63356a94a0567968da4 } diff --git a/src/main/java/org/bukkit/craftbukkit/util/Commodore.java b/src/main/java/org/bukkit/craftbukkit/util/Commodore.java -index 12972cf5876da72cc5d097aeedb13c9addd98add..e0c1131687fffd7f215505caafe6ef2292ac8672 100644 +index 128c9d81814ba1fb24895962e5f08495dbedb176..812819e814cfbdb542051a7dbfe123d3c59e66bd 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/Commodore.java +++ b/src/main/java/org/bukkit/craftbukkit/util/Commodore.java @@ -239,6 +239,14 @@ public class Commodore diff --git a/patches/unapplied/server/0657-Add-back-EntityPortalExitEvent.patch b/patches/server/0657-Add-back-EntityPortalExitEvent.patch similarity index 84% rename from patches/unapplied/server/0657-Add-back-EntityPortalExitEvent.patch rename to patches/server/0657-Add-back-EntityPortalExitEvent.patch index 37828943ad..9314a6cd93 100644 --- a/patches/unapplied/server/0657-Add-back-EntityPortalExitEvent.patch +++ b/patches/server/0657-Add-back-EntityPortalExitEvent.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Add back EntityPortalExitEvent diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java -index c65986830ce27a2fac7b3154df8db47a021a064e..44c63a57cc6bb992ae6788e23cc23300d43430f0 100644 +index 2731b44b3cd5de300ffcf93c690a617091b199ef..5f642ba64877a3ba53f69b8cffd99ed8c56a3d3f 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java -@@ -3344,6 +3344,28 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource { +@@ -3373,6 +3373,28 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S } else { // CraftBukkit start worldserver = shapedetectorshape.world; @@ -37,7 +37,7 @@ index c65986830ce27a2fac7b3154df8db47a021a064e..44c63a57cc6bb992ae6788e23cc23300 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); -@@ -3363,8 +3385,8 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource { +@@ -3392,8 +3414,8 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S if (entity != null) { entity.restoreFrom(this); @@ -45,6 +45,6 @@ index c65986830ce27a2fac7b3154df8db47a021a064e..44c63a57cc6bb992ae6788e23cc23300 - 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 - worldserver.addDuringTeleport(entity); - if (worldserver.getTypeKey() == LevelStem.END) { // CraftBukkit - ServerLevel.makeObsidianPlatform(worldserver, this); // CraftBukkit + // CraftBukkit start - Don't spawn the new entity if the current entity isn't spawned + if (this.inWorld) { + worldserver.addDuringTeleport(entity);