Skip to content

Commit

Permalink
Update Replay API
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Feb 17, 2024
1 parent 9dcc9ee commit febb22e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
8 changes: 5 additions & 3 deletions patches/api/0010-Replay-Mod-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subject: [PATCH] Replay Mod API


diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index d3efd7baa57135aafe840f9de06f42b73e1e4447..1c1f1c0c7ef30bde55137bc29564d8ab84dd8437 100644
index 7b5bb4b8075206c4e8a6854e42ab11e571aaf0b2..13c64a50e1dbdec5b621d059b37d67d728669bd4 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -59,6 +59,7 @@ import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -50,10 +50,10 @@ index c3f30fcf4bafd61331aeffab9539c86a0220f85d..0162f771532a6899a60dc56b2effdd25
}
diff --git a/src/main/java/top/leavesmc/leaves/entity/Photographer.java b/src/main/java/top/leavesmc/leaves/entity/Photographer.java
new file mode 100644
index 0000000000000000000000000000000000000000..985f8ff42a326d10edb582e5e24947f301fceb0c
index 0000000000000000000000000000000000000000..bfa6fe2a0ca095170aa5e073251402cf83a53ba0
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/entity/Photographer.java
@@ -0,0 +1,25 @@
@@ -0,0 +1,27 @@
+package top.leavesmc.leaves.entity;
+
+import org.bukkit.entity.Player;
Expand All @@ -73,6 +73,8 @@ index 0000000000000000000000000000000000000000..985f8ff42a326d10edb582e5e24947f3
+
+ public void stopRecording(boolean async);
+
+ public void stopRecording(boolean async, boolean save);
+
+ public void pauseRecording();
+
+ public void resumeRecording();
Expand Down
54 changes: 41 additions & 13 deletions patches/server/0106-Replay-Mod-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,10 @@ index 39b25c2478eadd373383a3445a7f27ea30d18550..0a1190e7331de715a2568ad7911fdb18
@Override
diff --git a/src/main/java/top/leavesmc/leaves/entity/CraftPhotographer.java b/src/main/java/top/leavesmc/leaves/entity/CraftPhotographer.java
new file mode 100644
index 0000000000000000000000000000000000000000..65fd6fd9e6af4e43268f1f1507a37e1bd95d41b8
index 0000000000000000000000000000000000000000..4f58b6623a6b5c726d718ced6ab106af3e665e35
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/entity/CraftPhotographer.java
@@ -0,0 +1,68 @@
@@ -0,0 +1,73 @@
+package top.leavesmc.leaves.entity;
+
+import net.minecraft.server.level.ServerPlayer;
Expand All @@ -474,7 +474,12 @@ index 0000000000000000000000000000000000000000..65fd6fd9e6af4e43268f1f1507a37e1b
+
+ @Override
+ public void stopRecording(boolean async) {
+ this.getHandle().remove(async);
+ this.stopRecording(async, true);
+ }
+
+ @Override
+ public void stopRecording(boolean async, boolean save) {
+ this.getHandle().remove(async, save);
+ }
+
+ @Override
Expand Down Expand Up @@ -690,10 +695,10 @@ index 0000000000000000000000000000000000000000..46a86cfce4aa859b8de7c126c22f64a9
+}
diff --git a/src/main/java/top/leavesmc/leaves/replay/Recorder.java b/src/main/java/top/leavesmc/leaves/replay/Recorder.java
new file mode 100644
index 0000000000000000000000000000000000000000..c15ef462524871564cdc3fae4ab4eac9b5d35f02
index 0000000000000000000000000000000000000000..7626e7b1171fcf829673a5fb3c07b3d9e5de48bf
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/replay/Recorder.java
@@ -0,0 +1,260 @@
@@ -0,0 +1,264 @@
+package top.leavesmc.leaves.replay;
+
+import io.netty.channel.local.LocalChannel;
Expand Down Expand Up @@ -918,7 +923,7 @@ index 0000000000000000000000000000000000000000..c15ef462524871564cdc3fae4ab4eac9
+ return isSaved;
+ }
+
+ public CompletableFuture<Void> saveRecording(File dest) {
+ public CompletableFuture<Void> saveRecording(File dest, boolean save) {
+ isSaved = true;
+ if (!isSaving) {
+ isSaving = true;
Expand All @@ -933,7 +938,11 @@ index 0000000000000000000000000000000000000000..c15ef462524871564cdc3fae4ab4eac9
+ interrupted = true;
+ }
+ try {
+ replayFile.closeAndSave(dest);
+ if (save) {
+ replayFile.closeAndSave(dest);
+ } else {
+ replayFile.closeNotSave();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new CompletionException(e);
Expand Down Expand Up @@ -1019,10 +1028,10 @@ index 0000000000000000000000000000000000000000..06e7166336d621e1a8edb4a2ad88e2cb
+}
diff --git a/src/main/java/top/leavesmc/leaves/replay/ReplayFile.java b/src/main/java/top/leavesmc/leaves/replay/ReplayFile.java
new file mode 100644
index 0000000000000000000000000000000000000000..57e55d4d0eff91784e977f19fdad3e552a5cfb44
index 0000000000000000000000000000000000000000..8cb0f7e2c9f6b7455541c5e06acca0e1ceb60a11
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/replay/ReplayFile.java
@@ -0,0 +1,163 @@
@@ -0,0 +1,178 @@
+package top.leavesmc.leaves.replay;
+
+import com.google.gson.Gson;
Expand Down Expand Up @@ -1156,6 +1165,21 @@ index 0000000000000000000000000000000000000000..57e55d4d0eff91784e977f19fdad3e55
+ Files.delete(tmpDir.toPath());
+ }
+
+ public synchronized void closeNotSave() throws IOException {
+ packetStream.close();
+
+ String[] files = tmpDir.list();
+ if (files == null) {
+ return;
+ }
+
+ for (String fileName : files) {
+ File f = new File(tmpDir, fileName);
+ Files.delete(f.toPath());
+ }
+ Files.delete(tmpDir.toPath());
+ }
+
+ private void copy(@NotNull InputStream in, OutputStream out) throws IOException {
+ byte[] buffer = new byte[8192];
+ int len;
Expand Down Expand Up @@ -1237,10 +1261,10 @@ index 0000000000000000000000000000000000000000..852f2098d93d4437fe79af06e454d849
+}
diff --git a/src/main/java/top/leavesmc/leaves/replay/ServerPhotographer.java b/src/main/java/top/leavesmc/leaves/replay/ServerPhotographer.java
new file mode 100644
index 0000000000000000000000000000000000000000..86e8dbaf5f5648ae992a26b35236150e13eb685b
index 0000000000000000000000000000000000000000..27005d997eb1e3f4a3b1a357f818586d55c5c88c
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/replay/ServerPhotographer.java
@@ -0,0 +1,212 @@
@@ -0,0 +1,216 @@
+package top.leavesmc.leaves.replay;
+
+import com.mojang.authlib.GameProfile;
Expand Down Expand Up @@ -1367,15 +1391,19 @@ index 0000000000000000000000000000000000000000..86e8dbaf5f5648ae992a26b35236150e
+ }
+
+ public void remove(boolean async) {
+ this.remove(async, true);
+ }
+
+ public void remove(boolean async, boolean save) {
+ super.remove(RemovalReason.KILLED);
+ photographers.remove(this);
+ this.recorder.stop();
+ this.server.getPlayerList().removePhotographer(this);
+
+ LeavesLogger.LOGGER.info("Photographer " + createState.id + " removed");
+
+ if (!recorder.isSaved()) {
+ CompletableFuture<Void> future = recorder.saveRecording(saveFile);
+ if (save && !recorder.isSaved()) {
+ CompletableFuture<Void> future = recorder.saveRecording(saveFile, save);
+ if (!async) {
+ future.join();
+ }
Expand Down

0 comments on commit febb22e

Please sign in to comment.