summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/util
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-01-04 19:09:33 +0800
committerKeuin <[email protected]>2022-01-08 19:13:50 +0800
commit549cb62df5065b4e3617633d5b2b062c925a9279 (patch)
tree37f122f9a2428bfaa8b7adebeeee9b2faa3d594c /src/main/java/com/keuin/kbackupfabric/util
parentef310895b62682b4c87487a532455738da7dbedd (diff)
Make it compile for Minecraft 1.18.
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/util')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java36
-rw-r--r--src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java3
2 files changed, 19 insertions, 20 deletions
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()));