From 7d40308cf9cdded54159b783b83149fd43f697b7 Mon Sep 17 00:00:00 2001 From: huskcasaca <100605532+huskcasaca@users.noreply.github.com> Date: Thu, 29 Sep 2022 00:17:10 +0800 Subject: Port to 1.19.2 --- src/main/java/com/keuin/kbackupfabric/KBPluginEvents.java | 15 +++++++++------ .../kbackupfabric/notification/DistinctNotifiable.java | 4 +--- .../kbackupfabric/notification/NotificationManager.java | 12 ++++++------ src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java | 6 ++---- 4 files changed, 18 insertions(+), 19 deletions(-) (limited to 'src/main/java/com') diff --git a/src/main/java/com/keuin/kbackupfabric/KBPluginEvents.java b/src/main/java/com/keuin/kbackupfabric/KBPluginEvents.java index 2b2865e..cc74e3f 100644 --- a/src/main/java/com/keuin/kbackupfabric/KBPluginEvents.java +++ b/src/main/java/com/keuin/kbackupfabric/KBPluginEvents.java @@ -11,8 +11,8 @@ import com.keuin.kbackupfabric.ui.KBCommands; import com.keuin.kbackupfabric.util.DateUtil; import com.keuin.kbackupfabric.util.PrintUtil; import net.fabricmc.api.ModInitializer; -import net.fabricmc.fabric.api.event.server.ServerStartCallback; -import net.fabricmc.fabric.api.registry.CommandRegistry; +import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.minecraft.server.MinecraftServer; import net.minecraft.server.dedicated.MinecraftDedicatedServer; @@ -27,18 +27,21 @@ import static org.apache.commons.io.FileUtils.forceDelete; * This is the Main file of this plugin. * It contains all events, including the init event. */ -public final class KBPluginEvents implements ModInitializer, ServerStartCallback { +public final class KBPluginEvents implements ModInitializer { //private static final Logger LOGGER = LogManager.getLogger(); @Override public void onInitialize() { System.out.println("Binding events and commands ..."); - CommandRegistry.INSTANCE.register(false, KBCommandsRegister::registerCommands); - ServerStartCallback.EVENT.register(this); + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { + KBCommandsRegister.registerCommands(dispatcher); + }); + ServerLifecycleEvents.SERVER_STARTED.register( + this::onStartServer + ); } - @Override public void onStartServer(MinecraftServer server) { // Buggy: this does not work diff --git a/src/main/java/com/keuin/kbackupfabric/notification/DistinctNotifiable.java b/src/main/java/com/keuin/kbackupfabric/notification/DistinctNotifiable.java index 4a01227..1972c4b 100644 --- a/src/main/java/com/keuin/kbackupfabric/notification/DistinctNotifiable.java +++ b/src/main/java/com/keuin/kbackupfabric/notification/DistinctNotifiable.java @@ -1,9 +1,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. @@ -34,7 +32,7 @@ public interface DistinctNotifiable { @Override public void notify(Text text) { - serverPlayerEntity.sendMessage(text, MessageType.SYSTEM, Util.NIL_UUID); + serverPlayerEntity.sendMessageToClient(text, true); } @Override diff --git a/src/main/java/com/keuin/kbackupfabric/notification/NotificationManager.java b/src/main/java/com/keuin/kbackupfabric/notification/NotificationManager.java index 92c119b..a2a241c 100644 --- a/src/main/java/com/keuin/kbackupfabric/notification/NotificationManager.java +++ b/src/main/java/com/keuin/kbackupfabric/notification/NotificationManager.java @@ -3,8 +3,8 @@ package com.keuin.kbackupfabric.notification; import com.keuin.kbackupfabric.metadata.BackupMetadata; import com.keuin.kbackupfabric.metadata.MetadataHolder; import com.keuin.kbackupfabric.util.DateUtil; -import net.minecraft.text.LiteralText; import net.minecraft.text.Style; +import net.minecraft.text.Text; import net.minecraft.util.Formatting; import java.util.HashSet; @@ -37,11 +37,11 @@ public class NotificationManager { if (MetadataHolder.hasMetadata()) { BackupMetadata backup = MetadataHolder.getMetadata(); notifiable.notify( - new LiteralText("The world has been restored to backup ") - .append(new LiteralText("[" + backup.getBackupName() + "]").setStyle(Style.EMPTY.withColor(Formatting.GREEN))) - .append(new LiteralText(" (created at ")) - .append(new LiteralText("[" + DateUtil.fromEpochMillis(backup.getBackupTime()) + "]").setStyle(Style.EMPTY.withColor(Formatting.GREEN))) - .append(new LiteralText(")")) + Text.literal("The world has been restored to backup ") + .append(Text.literal("[" + backup.getBackupName() + "]").setStyle(Style.EMPTY.withColor(Formatting.GREEN))) + .append(Text.literal(" (created at ")) + .append(Text.literal("[" + DateUtil.fromEpochMillis(backup.getBackupTime()) + "]").setStyle(Style.EMPTY.withColor(Formatting.GREEN))) + .append(Text.literal(")")) ); } } diff --git a/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java b/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java index 640794e..e4a1826 100644 --- a/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java +++ b/src/main/java/com/keuin/kbackupfabric/util/PrintUtil.java @@ -1,10 +1,8 @@ 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; import net.minecraft.text.Style; import net.minecraft.text.Text; import net.minecraft.util.Formatting; @@ -44,7 +42,7 @@ public final class PrintUtil { synchronized (syncBroadcast) { if (fuckingPlayerManager != null) // fuckingPlayerManager.sendToAll(new LiteralText(message).setStyle(broadcastStyle)); - fuckingPlayerManager.broadcast(new LiteralText(message).setStyle(broadcastStyle), MessageType.GAME_INFO, UUID.randomUUID()); + fuckingPlayerManager.broadcast(Text.literal(message).setStyle(broadcastStyle), true); else PrintUtil.error("Error in PrintUtil.broadcast: PlayerManager is not initialized."); } @@ -85,7 +83,7 @@ public final class PrintUtil { private static CommandContext message(CommandContext context, String messageText, boolean broadcastToOps, Style style) { if (context != null) { synchronized (syncMessage) { - Text text = new LiteralText(messageText).setStyle(style); + Text text = Text.literal(messageText).setStyle(style); context.getSource().sendFeedback(text, broadcastToOps); } } else { -- cgit v1.2.3