diff options
author | Keuin <[email protected]> | 2023-01-17 01:30:46 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2023-01-17 01:30:46 +0800 |
commit | 822a5c5f53122763bf63e0baff79c435b1a60dbc (patch) | |
tree | 85a0f73b8f651a94ee12d0647f496b70b3d8872d | |
parent | 068e34023d28ce03bf7a9f59ac3e23e73a183db2 (diff) |
Remove deprecated usage and useless code.
-rw-r--r-- | src/main/java/com/keuin/kbackupfabric/KBCommandsRegister.java | 2 | ||||
-rw-r--r-- | src/main/java/com/keuin/kbackupfabric/KBPluginEvents.java | 23 |
2 files changed, 8 insertions, 17 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/KBCommandsRegister.java b/src/main/java/com/keuin/kbackupfabric/KBCommandsRegister.java index 154a39f..5bf92e4 100644 --- a/src/main/java/com/keuin/kbackupfabric/KBCommandsRegister.java +++ b/src/main/java/com/keuin/kbackupfabric/KBCommandsRegister.java @@ -13,7 +13,7 @@ public final class KBCommandsRegister { public static final int DEFAULT_REQUIRED_LEVEL = 2; // First make method to register - public static void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher) { + public static void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher, boolean dedicated) { // register /kb and /kb help for help menu dispatcher.register(CommandManager.literal("kb") diff --git a/src/main/java/com/keuin/kbackupfabric/KBPluginEvents.java b/src/main/java/com/keuin/kbackupfabric/KBPluginEvents.java index d09b9e9..362abb8 100644 --- a/src/main/java/com/keuin/kbackupfabric/KBPluginEvents.java +++ b/src/main/java/com/keuin/kbackupfabric/KBPluginEvents.java @@ -11,10 +11,9 @@ 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.v1.CommandRegistrationCallback; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.dedicated.MinecraftDedicatedServer; import java.io.File; import java.io.FileInputStream; @@ -27,28 +26,20 @@ 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); - } - - @Override - public void onStartServer(MinecraftServer server) { - - // Buggy: this does not work - if (!(server instanceof MinecraftDedicatedServer)) - throw new RuntimeException("KBackup is a server-side-only plugin. Please do not use it in client-side."); - - // Bind fabric events + CommandRegistrationCallback.EVENT.register(KBCommandsRegister::registerCommands); OnPlayerConnect.ON_PLAYER_CONNECT.register((connection, player) -> NotificationManager.INSTANCE.notifyPlayer(DistinctNotifiable.fromServerPlayerEntity(player))); + ServerLifecycleEvents.SERVER_STARTED.register(this::onStartServer); + } + public void onStartServer(MinecraftServer server) { // Initialize player manager reference PrintUtil.setPlayerManager(server.getPlayerManager()); |