diff options
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric')
10 files changed, 33 insertions, 33 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/backup/BackupFilesystemUtil.java b/src/main/java/com/keuin/kbackupfabric/backup/BackupFilesystemUtil.java index eac7ce9..49fe6a0 100644 --- a/src/main/java/com/keuin/kbackupfabric/backup/BackupFilesystemUtil.java +++ b/src/main/java/com/keuin/kbackupfabric/backup/BackupFilesystemUtil.java @@ -53,7 +53,7 @@ public final class BackupFilesystemUtil { public static String getLevelPath(MinecraftServer server) throws IOException { if (!(server instanceof MinecraftDedicatedServer)) throw new IllegalStateException("This plugin is server-side only."); - String path = (new File(server.getRunDirectory().getCanonicalPath(), server.getLevelName())).getAbsolutePath(); + String path = (new File(server.getRunDirectory().getCanonicalPath(), ((MinecraftDedicatedServer) server).getLevelName())).getAbsolutePath(); Logger.getLogger("getLevelPath").info(String.format("Level path: %s", path)); assert (new File(path)).exists(); return path; diff --git a/src/main/java/com/keuin/kbackupfabric/backup/suggestion/BackupNameSuggestionProvider.java b/src/main/java/com/keuin/kbackupfabric/backup/suggestion/BackupNameSuggestionProvider.java index 9c0c1c2..3a5108e 100644 --- a/src/main/java/com/keuin/kbackupfabric/backup/suggestion/BackupNameSuggestionProvider.java +++ b/src/main/java/com/keuin/kbackupfabric/backup/suggestion/BackupNameSuggestionProvider.java @@ -1,7 +1,7 @@ package com.keuin.kbackupfabric.backup.suggestion; import com.mojang.brigadier.suggestion.SuggestionProvider; -import net.minecraft.server.command.CommandSource; +import net.minecraft.command.CommandSource; import net.minecraft.server.command.ServerCommandSource; import java.io.File; diff --git a/src/main/java/com/keuin/kbackupfabric/notification/DistinctNotifiable.java b/src/main/java/com/keuin/kbackupfabric/notification/DistinctNotifiable.java index b44bfce..4a01227 100644 --- a/src/main/java/com/keuin/kbackupfabric/notification/DistinctNotifiable.java +++ b/src/main/java/com/keuin/kbackupfabric/notification/DistinctNotifiable.java @@ -3,6 +3,7 @@ package com.keuin.kbackupfabric.notification; import net.minecraft.network.MessageType; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; +import net.minecraft.util.Util; /** * Decouple from ServerPlayerEntity, in case further migration to other APIs. @@ -33,7 +34,7 @@ public interface DistinctNotifiable { @Override public void notify(Text text) { - serverPlayerEntity.sendChatMessage(text, MessageType.SYSTEM); + serverPlayerEntity.sendMessage(text, MessageType.SYSTEM, Util.NIL_UUID); } @Override diff --git a/src/main/java/com/keuin/kbackupfabric/notification/NotificationManager.java b/src/main/java/com/keuin/kbackupfabric/notification/NotificationManager.java index 5536a1a..92c119b 100644 --- a/src/main/java/com/keuin/kbackupfabric/notification/NotificationManager.java +++ b/src/main/java/com/keuin/kbackupfabric/notification/NotificationManager.java @@ -38,9 +38,9 @@ public class NotificationManager { BackupMetadata backup = MetadataHolder.getMetadata(); notifiable.notify( new LiteralText("The world has been restored to backup ") - .append(new LiteralText("[" + backup.getBackupName() + "]").setStyle(new Style().setColor(Formatting.GREEN))) + .append(new LiteralText("[" + backup.getBackupName() + "]").setStyle(Style.EMPTY.withColor(Formatting.GREEN))) .append(new LiteralText(" (created at ")) - .append(new LiteralText("[" + DateUtil.fromEpochMillis(backup.getBackupTime()) + "]").setStyle(new Style().setColor(Formatting.GREEN))) + .append(new LiteralText("[" + DateUtil.fromEpochMillis(backup.getBackupTime()) + "]").setStyle(Style.EMPTY.withColor(Formatting.GREEN))) .append(new LiteralText(")")) ); } diff --git a/src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java index 1798fb7..75977a0 100644 --- a/src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java +++ b/src/main/java/com/keuin/kbackupfabric/operation/BackupOperation.java @@ -32,7 +32,7 @@ public class BackupOperation extends InvokableAsyncBlockingOperation { @Override protected void async() { String backupSaveDirectory = ""; - MinecraftServer server = context.getSource().getMinecraftServer(); + MinecraftServer server = context.getSource().getServer(); boolean success = false; // only success when everything is done try { //// Do our main backup logic @@ -72,7 +72,7 @@ public class BackupOperation extends InvokableAsyncBlockingOperation { PrintUtil.broadcast("Making backup, please wait ..."); // Get server - MinecraftServer server = context.getSource().getMinecraftServer(); + MinecraftServer server = context.getSource().getServer(); // Save old auto-save switch state for restoration after finished oldWorldsSavingDisabled.clear(); diff --git a/src/main/java/com/keuin/kbackupfabric/operation/DeleteOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/DeleteOperation.java index 7bfb0b7..9428592 100644 --- a/src/main/java/com/keuin/kbackupfabric/operation/DeleteOperation.java +++ b/src/main/java/com/keuin/kbackupfabric/operation/DeleteOperation.java @@ -48,7 +48,7 @@ public class DeleteOperation extends InvokableAsyncBlockingOperation { private void delete() { try { - MinecraftServer server = context.getSource().getMinecraftServer(); + MinecraftServer server = context.getSource().getServer(); PrintUtil.info("Deleting backup file " + this.backupFileName); File backupFile = new File(getBackupSaveDirectory(server), backupFileName); SavedIncrementalBackup incrementalBackup = null; @@ -82,7 +82,7 @@ public class DeleteOperation extends InvokableAsyncBlockingOperation { new IncrementalBackupStorageManager(getIncrementalBackupBaseDirectory(server).toPath()); Iterable<ObjectCollection2> backups = ObjectCollectionSerializer .fromDirectory(BackupFilesystemUtil - .getBackupSaveDirectory(context.getSource().getMinecraftServer())); + .getBackupSaveDirectory(context.getSource().getServer())); int deleted = manager.deleteObjectCollection(incrementalBackup.getObjectCollection(), backups); PrintUtil.info("Deleted " + deleted + " unused file(s)."); } diff --git a/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java b/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java index e18f3c8..999e39a 100644 --- a/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java +++ b/src/main/java/com/keuin/kbackupfabric/operation/RestoreOperation.java @@ -19,7 +19,7 @@ public class RestoreOperation extends InvokableBlockingOperation { private final ConfiguredBackupMethod configuredBackupMethod; public RestoreOperation(CommandContext<ServerCommandSource> context, ConfiguredBackupMethod configuredBackupMethod) { - server = Objects.requireNonNull(context.getSource().getMinecraftServer()); + server = Objects.requireNonNull(context.getSource().getServer()); this.serverThread = Objects.requireNonNull(server.getThread()); this.context = Objects.requireNonNull(context); this.configuredBackupMethod = Objects.requireNonNull(configuredBackupMethod); diff --git a/src/main/java/com/keuin/kbackupfabric/ui/KBCommands.java b/src/main/java/com/keuin/kbackupfabric/ui/KBCommands.java index e148f24..784cd65 100644 --- a/src/main/java/com/keuin/kbackupfabric/ui/KBCommands.java +++ b/src/main/java/com/keuin/kbackupfabric/ui/KBCommands.java @@ -255,7 +255,7 @@ public final class KBCommands { public static int delete(CommandContext<ServerCommandSource> context) { String backupFileName = parseBackupFileName(context, StringArgumentType.getString(context, "backupName")); - MinecraftServer server = context.getSource().getMinecraftServer(); + MinecraftServer server = context.getSource().getServer(); if (backupFileName == null) return list(context); // Show the list and return @@ -286,7 +286,7 @@ public final class KBCommands { public static int restore(CommandContext<ServerCommandSource> context) { try { //KBMain.restore("name") - MinecraftServer server = context.getSource().getMinecraftServer(); + MinecraftServer server = context.getSource().getServer(); String backupFileName = parseBackupFileName(context, StringArgumentType.getString(context, "backupName")); // backupFileName = parseBackupFileName(context, backupFileName); @@ -344,7 +344,7 @@ public final class KBCommands { PrintUtil.info("Start backup..."); // configure backup method - MinecraftServer server = context.getSource().getMinecraftServer(); + MinecraftServer server = context.getSource().getServer(); ConfiguredBackupMethod method = !incremental ? new ConfiguredPrimitiveBackupMethod( PrimitiveBackupFileNameEncoder.INSTANCE.encode(customBackupName, LocalDateTime.now()), getLevelPath(server), diff --git a/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java b/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java index 34b548a..640794e 100644 --- a/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java +++ b/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java @@ -1,6 +1,7 @@ package com.keuin.kbackupfabric.util; import com.mojang.brigadier.context.CommandContext; +import net.minecraft.network.MessageType; import net.minecraft.server.PlayerManager; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.LiteralText; @@ -13,24 +14,26 @@ import org.jetbrains.annotations.Nullable; import java.util.Optional; +import java.util.UUID; + public final class PrintUtil { private static final Object syncMessage = new Object(); private static final Object syncBroadcast = new Object(); - private static final Style broadcastStyle = new Style().setColor(Formatting.AQUA); - private static final Style infoStyle = new Style().setColor(Formatting.WHITE); - private static final Style stressStyle = new Style().setColor(Formatting.AQUA); - private static final Style warnStyle = new Style().setColor(Formatting.YELLOW); - private static final Style errorStyle = new Style().setColor(Formatting.DARK_RED); + private static final Style broadcastStyle = Style.EMPTY.withColor(Formatting.AQUA); + private static final Style infoStyle = Style.EMPTY.withColor(Formatting.WHITE); + private static final Style stressStyle = Style.EMPTY.withColor(Formatting.AQUA); + private static final Style warnStyle = Style.EMPTY.withColor(Formatting.YELLOW); + private static final Style errorStyle = Style.EMPTY.withColor(Formatting.DARK_RED); private static final Logger LOGGER = LogManager.getLogger(); - private static PlayerManager playerManager = null; + private static PlayerManager fuckingPlayerManager = null; public static void setPlayerManager(PlayerManager playerManager) { - if (PrintUtil.playerManager == null) - PrintUtil.playerManager = playerManager; + if (fuckingPlayerManager == null) + fuckingPlayerManager = playerManager; } public static void broadcast(String message) { @@ -39,9 +42,11 @@ public final class PrintUtil { public static void broadcast(String message, Style style) { synchronized (syncBroadcast) { - Optional.ofNullable(playerManager) - .ifPresent(pm -> - pm.sendToAll(new LiteralText(message).setStyle(style))); + if (fuckingPlayerManager != null) +// fuckingPlayerManager.sendToAll(new LiteralText(message).setStyle(broadcastStyle)); + fuckingPlayerManager.broadcast(new LiteralText(message).setStyle(broadcastStyle), MessageType.GAME_INFO, UUID.randomUUID()); + else + PrintUtil.error("Error in PrintUtil.broadcast: PlayerManager is not initialized."); } } @@ -77,19 +82,16 @@ public final class PrintUtil { return message(context, messageText, broadcastToOps, errorStyle); } - private static CommandContext<ServerCommandSource> message(@Nullable CommandContext<ServerCommandSource> context, String messageText, boolean broadcastToOps, Style style) { + private static CommandContext<ServerCommandSource> message(CommandContext<ServerCommandSource> context, String messageText, boolean broadcastToOps, Style style) { if (context != null) { synchronized (syncMessage) { - Text text = new LiteralText(messageText); - text.setStyle(style); + Text text = new LiteralText(messageText).setStyle(style); context.getSource().sendFeedback(text, broadcastToOps); } - return context; } else { - // if context is null, then `broadcastToOps` will be ignored for simplicity broadcast(messageText, style); - return null; } + return context; } /** diff --git a/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java b/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java index eea1148..3497f20 100644 --- a/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java +++ b/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java @@ -208,9 +208,6 @@ public final class ZipUtil { // 创建解压文件 entryFile = new File(entryFilePath); if (entryFile.exists()) { - // 检测文件是否允许删除,如果不允许删除,将会抛出SecurityException - SecurityManager securityManager = new SecurityManager(); - securityManager.checkDelete(entryFilePath); // 删除已存在的目标文件 if (!entryFile.delete()) throw new IOException(String.format("Failed to delete existing file %s", entryFile.toString())); |