From 1ad3ede4688a4464f7b006a697bcab7aaf5d16f9 Mon Sep 17 00:00:00 2001 From: violetc <58360096+s-yh-china@users.noreply.github.com> Date: Mon, 22 Jul 2024 18:44:34 +0800 Subject: [PATCH] Fix Replay not save mode, and issue #209 done --- patches/server/0097-Replay-Mod-API.patch | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/patches/server/0097-Replay-Mod-API.patch b/patches/server/0097-Replay-Mod-API.patch index b48424f..9568a4f 100644 --- a/patches/server/0097-Replay-Mod-API.patch +++ b/patches/server/0097-Replay-Mod-API.patch @@ -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; @@ -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; @@ -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 photographers = new CopyOnWriteArrayList<>(); @@ -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(); @@ -1453,7 +1451,7 @@ index 0000000000000000000000000000000000000000..99d00b6acd2302e06f70f75786e89286 + + LeavesLogger.LOGGER.info("Photographer " + createState.id + " removed"); + -+ if (save && !recorder.isSaved()) { ++ if (!recorder.isSaved()) { + CompletableFuture future = recorder.saveRecording(saveFile, save); + if (!async) { + future.join(); @@ -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;