Skip to content

Commit

Permalink
Fix Replay not save mode, and issue #209 done
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Jul 22, 2024
1 parent 752a60d commit 1ad3ede
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions patches/server/0097-Replay-Mod-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1312,10 +1312,10 @@ index 0000000000000000000000000000000000000000..1568f6928d5d4f38ca1919c6de6ec9bb
+}
diff --git a/src/main/java/org/leavesmc/leaves/replay/ServerPhotographer.java b/src/main/java/org/leavesmc/leaves/replay/ServerPhotographer.java
new file mode 100644
index 0000000000000000000000000000000000000000..99d00b6acd2302e06f70f75786e8928610592261
index 0000000000000000000000000000000000000000..f5c6e823d7ab9a61307e27e7b859e76bdfdd1e58
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/replay/ServerPhotographer.java
@@ -0,0 +1,216 @@
@@ -0,0 +1,222 @@
+package org.leavesmc.leaves.replay;
+
+import com.mojang.authlib.GameProfile;
Expand All @@ -1325,8 +1325,8 @@ index 0000000000000000000000000000000000000000..99d00b6acd2302e06f70f75786e89286
+import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.stats.ServerStatsCounter;
+import net.minecraft.world.damagesource.DamageSource;
+import net.minecraft.world.level.GameType;
+import net.minecraft.world.phys.Vec3;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.CraftWorld;
+import org.jetbrains.annotations.NotNull;
Expand All @@ -1342,8 +1342,6 @@ index 0000000000000000000000000000000000000000..99d00b6acd2302e06f70f75786e89286
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import static org.leavesmc.leaves.bot.ServerBot.isCreateLegal;
+
+public class ServerPhotographer extends ServerPlayer {
+
+ private static final List<ServerPhotographer> photographers = new CopyOnWriteArrayList<>();
Expand All @@ -1366,7 +1364,7 @@ index 0000000000000000000000000000000000000000..99d00b6acd2302e06f70f75786e89286
+
+ public static ServerPhotographer createPhotographer(@NotNull PhotographerCreateState state) throws IOException {
+ if (!isCreateLegal(state.id)) {
+ return null;
+ throw new IllegalArgumentException(state.id + " is a invalid photographer id");
+ }
+
+ MinecraftServer server = MinecraftServer.getServer();
Expand Down Expand Up @@ -1453,7 +1451,7 @@ index 0000000000000000000000000000000000000000..99d00b6acd2302e06f70f75786e89286
+
+ LeavesLogger.LOGGER.info("Photographer " + createState.id + " removed");
+
+ if (save && !recorder.isSaved()) {
+ if (!recorder.isSaved()) {
+ CompletableFuture<Void> future = recorder.saveRecording(saveFile, save);
+ if (!async) {
+ future.join();
Expand Down Expand Up @@ -1510,6 +1508,14 @@ index 0000000000000000000000000000000000000000..99d00b6acd2302e06f70f75786e89286
+ return (CraftPhotographer) super.getBukkitEntity();
+ }
+
+ public static boolean isCreateLegal(@NotNull String name) {
+ if (!name.matches("^[a-zA-Z0-9_]{4,16}$")) {
+ return false;
+ }
+
+ return Bukkit.getPlayerExact(name) == null && ServerPhotographer.getPhotographer(name) == null;
+ }
+
+ public static class PhotographerCreateState {
+
+ public RecorderOption option;
Expand Down

0 comments on commit 1ad3ede

Please sign in to comment.