diff --git a/build.gradle b/build.gradle index 649679e..e2724e7 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.14-SNAPSHOT' + id 'net.fabricmc.fabric-loom' version "${loom_version}" id 'maven-publish' } @@ -21,11 +21,10 @@ repositories { dependencies { // To change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + implementation "net.fabricmc:fabric-loader:${project.loader_version}" - // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + // Fabric API. This is technically optional, but you probably want it anyway. + implementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}" include(implementation 'org.eclipse.jgit:org.eclipse.jgit:6.8.0.202311291450-r') } @@ -43,7 +42,7 @@ processResources { } } -def targetJavaVersion = 17 +def targetJavaVersion = project.target_java_version.toInteger() tasks.withType(JavaCompile).configureEach { // ensure that the encoding is set to UTF-8, no matter what the system default is // this fixes some edge cases with special characters not displaying correctly diff --git a/gradle.properties b/gradle.properties index 2e27f84..77eb959 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,16 +2,21 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties -# check these on https://modmuss50.me/fabric.html -minecraft_version=1.21.11 -yarn_mappings=1.21.11+build.3 -loader_version=0.18.3 +# check these on https://fabricmc.net/develop/ +minecraft_version=26.1 +loader_version=0.18.6 +loom_version=1.15-SNAPSHOT # Mod Properties -mod_version = 1.2.0 +mod_version = 1.3.0 maven_group = dev.neylz archives_base_name = gitpuller # Dependencies -# check this on https://modmuss50.me/fabric.html -fabric_version=0.139.5+1.21.11 \ No newline at end of file +fabric_api_version=0.145.1+26.1 + + +# Do NOT update this in patch versions; +# this is the minimum Java version required to run the mod, and should only be updated in minor/major versions. +# updating it removes support for older Java versions (so backwards compatibility of the mod). +target_java_version=25 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3c0465a..7ca05fa 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1 +1 @@ -distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip diff --git a/src/main/java/dev/neylz/gitpuller/command/GitCheckoutCommand.java b/src/main/java/dev/neylz/gitpuller/command/GitCheckoutCommand.java index 7c12608..cecf5a2 100644 --- a/src/main/java/dev/neylz/gitpuller/command/GitCheckoutCommand.java +++ b/src/main/java/dev/neylz/gitpuller/command/GitCheckoutCommand.java @@ -9,13 +9,13 @@ import dev.neylz.gitpuller.util.GitUtil; import dev.neylz.gitpuller.util.ModConfig; import dev.neylz.gitpuller.util.TokenManager; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.command.CommandSource; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.WorldSavePath; +import net.minecraft.ChatFormatting; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.commands.SharedSuggestionProvider; +import net.minecraft.network.chat.Component; +import net.minecraft.world.level.storage.LevelResource; import org.eclipse.jgit.api.CreateBranchCommand; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; @@ -31,16 +31,16 @@ import java.util.regex.Pattern; public class GitCheckoutCommand { - public static void register(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) { - LiteralArgumentBuilder checkoutCommand = CommandManager.literal("checkout").requires(CommandManager.requirePermissionLevel(CommandManager.GAMEMASTERS_CHECK)); - RequiredArgumentBuilder branchArg = CommandManager.argument("branch", StringArgumentType.greedyString()); + public static void register(CommandDispatcher dispatcher, CommandBuildContext buildContext, Commands.CommandSelection environment) { + LiteralArgumentBuilder checkoutCommand = Commands.literal("checkout").requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS)); + RequiredArgumentBuilder branchArg = Commands.argument("branch", StringArgumentType.greedyString()); if (!ModConfig.isMonoRepo()) { checkoutCommand = checkoutCommand - .then(CommandManager.argument("pack name", StringArgumentType.word()).suggests( - (ctx, builder) -> CommandSource.suggestMatching(GitUtil.getTrackedDatapacks(ctx.getSource().getServer().getSavePath(WorldSavePath.DATAPACKS).toFile()), builder)) + .then(Commands.argument("pack name", StringArgumentType.word()).suggests( + (ctx, builder) -> SharedSuggestionProvider.suggest(GitUtil.getTrackedDatapacks(ctx.getSource().getServer().getWorldPath(LevelResource.DATAPACK_DIR).toFile()), builder)) .then(branchArg.suggests( - (ctx, builder) -> CommandSource.suggestMatching(GitUtil.getBranches(new File(ctx.getSource().getServer().getSavePath(WorldSavePath.DATAPACKS).toFile(), StringArgumentType.getString(ctx, "pack name"))), builder)) + (ctx, builder) -> SharedSuggestionProvider.suggest(GitUtil.getBranches(new File(ctx.getSource().getServer().getWorldPath(LevelResource.DATAPACK_DIR).toFile(), StringArgumentType.getString(ctx, "pack name"))), builder)) .executes( (ctx) -> checkout(ctx, StringArgumentType.getString(ctx, "pack name"), StringArgumentType.getString(ctx, "branch")) ))); @@ -53,28 +53,28 @@ public static void register(CommandDispatcher dispatcher, C )); } - dispatcher.register(CommandManager.literal("git") + dispatcher.register(Commands.literal("git") .then(checkoutCommand) ); } - private static int checkoutMono(CommandContext ctx, String branch) throws CommandSyntaxException { - ctx.getSource().sendFeedback(() -> Text.empty() - .append(Text.literal("Checking out to ").formatted(Formatting.RESET)) - .append(Text.literal(branch).formatted(Formatting.DARK_GREEN)) - .append(Text.literal(" in the mono repo").formatted(Formatting.RESET)), + private static int checkoutMono(CommandContext ctx, String branch) throws CommandSyntaxException { + ctx.getSource().sendSuccess(() -> Component.empty() + .append(Component.literal("Checking out to ").withStyle(ChatFormatting.RESET)) + .append(Component.literal(branch).withStyle(ChatFormatting.DARK_GREEN)) + .append(Component.literal(" in the mono repo").withStyle(ChatFormatting.RESET)), true); - File file = ctx.getSource().getServer().getSavePath(WorldSavePath.DATAPACKS).toFile(); + File file = ctx.getSource().getServer().getWorldPath(LevelResource.DATAPACK_DIR).toFile(); gitCheckout(ctx.getSource(), file, branch); return 1; } - private static int checkout(CommandContext ctx, String pack, String branch) throws CommandSyntaxException { + private static int checkout(CommandContext ctx, String pack, String branch) throws CommandSyntaxException { - File packDir = new File(ctx.getSource().getServer().getSavePath(WorldSavePath.DATAPACKS).toFile(), pack); + File packDir = new File(ctx.getSource().getServer().getWorldPath(LevelResource.DATAPACK_DIR).toFile(), pack); if (!packDir.exists()) { throw new CommandSyntaxException(null, () -> "Datapack " + pack + " does not exist"); } else if (!GitUtil.isGitRepo(packDir)) { @@ -93,7 +93,7 @@ private static int checkout(CommandContext ctx, String pack } - private static void gitCheckout(ServerCommandSource source, File file, String ref) throws CommandSyntaxException { + private static void gitCheckout(CommandSourceStack source, File file, String ref) throws CommandSyntaxException { try (Git git = Git.open(file)) { // Fetch all branches from remote git.fetch() @@ -112,10 +112,10 @@ private static void gitCheckout(ServerCommandSource source, File file, String re .setStartPoint(commit) .call(); - source.sendFeedback( - () -> Text.empty() - .append(Text.literal("Checked out commit ").formatted(Formatting.RESET)) - .append(Text.literal(ref).formatted(Formatting.LIGHT_PURPLE)), + source.sendSuccess( + () -> Component.empty() + .append(Component.literal("Checked out commit ").withStyle(ChatFormatting.RESET)) + .append(Component.literal(ref).withStyle(ChatFormatting.LIGHT_PURPLE)), true); } catch (IOException e) { // e.printStackTrace(); @@ -142,12 +142,12 @@ private static void gitCheckout(ServerCommandSource source, File file, String re .call(); } - source.sendFeedback( - () -> Text.empty() - .append(Text.literal("Checked out branch ").formatted(Formatting.RESET)) - .append(Text.literal(ref).formatted(Formatting.DARK_GREEN)) - .append(Text.literal(" in ").formatted(Formatting.RESET)) - .append(Text.literal("[" + file.getName() + "]").formatted(Formatting.YELLOW)), + source.sendSuccess( + () -> Component.empty() + .append(Component.literal("Checked out branch ").withStyle(ChatFormatting.RESET)) + .append(Component.literal(ref).withStyle(ChatFormatting.DARK_GREEN)) + .append(Component.literal(" in ").withStyle(ChatFormatting.RESET)) + .append(Component.literal("[" + file.getName() + "]").withStyle(ChatFormatting.YELLOW)), true); } diff --git a/src/main/java/dev/neylz/gitpuller/command/GitCloneCommand.java b/src/main/java/dev/neylz/gitpuller/command/GitCloneCommand.java index 438164d..5bc2b30 100644 --- a/src/main/java/dev/neylz/gitpuller/command/GitCloneCommand.java +++ b/src/main/java/dev/neylz/gitpuller/command/GitCloneCommand.java @@ -2,40 +2,37 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import dev.neylz.gitpuller.GitPuller; import dev.neylz.gitpuller.util.GitUtil; import dev.neylz.gitpuller.util.ModConfig; import dev.neylz.gitpuller.util.TokenManager; -import net.minecraft.command.CommandRegistryAccess; +import net.minecraft.ChatFormatting; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.network.chat.Component; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.WorldSavePath; +import net.minecraft.world.level.storage.LevelResource; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; import java.io.File; import java.nio.file.Path; -import java.util.regex.Pattern; public class GitCloneCommand { - public static void register(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) { + public static void register(CommandDispatcher dispatcher, CommandBuildContext buildContext, Commands.CommandSelection environment) { if (ModConfig.isMonoRepo()) { return; } dispatcher.register( - CommandManager.literal("git").then(( - CommandManager.literal("clone").requires(CommandManager.requirePermissionLevel(CommandManager.GAMEMASTERS_CHECK))).then(( - CommandManager.argument("name", StringArgumentType.string())).then(( - CommandManager.argument("url", StringArgumentType.greedyString()).executes( + Commands.literal("git").then(( + Commands.literal("clone").requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS))).then(( + Commands.argument("name", StringArgumentType.string())).then(( + Commands.argument("url", StringArgumentType.greedyString()).executes( (context) -> cloneDatapack(context, StringArgumentType.getString(context, "name"), StringArgumentType.getString(context, "url"))) )) ) @@ -44,31 +41,31 @@ public static void register(CommandDispatcher dispatcher, C ); } - private static int cloneDatapack(CommandContext ctx, String name, String remoteUrl) throws CommandSyntaxException { + private static int cloneDatapack(CommandContext ctx, String name, String remoteUrl) throws CommandSyntaxException { if (!GitUtil.URL_PATTERN.matcher(remoteUrl).matches()) { throw new CommandSyntaxException(null, () -> "Invalid URL: " + remoteUrl); } - ctx.getSource().sendFeedback(() -> Text.empty() - .append(Text.literal("Cloning from ").formatted(Formatting.RESET)) - .append(Text.literal(remoteUrl).formatted(Formatting.AQUA)) - .append(Text.literal(" into the datapack ").formatted(Formatting.RESET)) - .append(Text.literal("[" + name + "]").formatted(Formatting.YELLOW)), + ctx.getSource().sendSuccess(() -> Component.empty() + .append(Component.literal("Cloning from ").withStyle(ChatFormatting.RESET)) + .append(Component.literal(remoteUrl).withStyle(ChatFormatting.AQUA)) + .append(Component.literal(" into the datapack ").withStyle(ChatFormatting.RESET)) + .append(Component.literal("[" + name + "]").withStyle(ChatFormatting.YELLOW)), true); MinecraftServer server = ctx.getSource().getServer(); try { clone(server, remoteUrl, name); } catch (CommandSyntaxException e) { - ctx.getSource().sendFeedback(() -> Text.empty() - .append(Text.literal("Failed to clone repository: ").formatted(Formatting.RED)) - .append(Text.literal(e.getMessage()).formatted(Formatting.RED)), true); + ctx.getSource().sendSuccess(() -> Component.empty() + .append(Component.literal("Failed to clone repository: ").withStyle(ChatFormatting.RED)) + .append(Component.literal(e.getMessage()).withStyle(ChatFormatting.RED)), true); return 0; } - ctx.getSource().sendFeedback(() -> Text.empty() - .append(Text.literal("Successfully cloned repository").formatted(Formatting.GREEN)), true); + ctx.getSource().sendSuccess(() -> Component.empty() + .append(Component.literal("Successfully cloned repository").withStyle(ChatFormatting.GREEN)), true); return 1; @@ -81,7 +78,7 @@ private static void clone(MinecraftServer server, String remoteUrl, String name) // clone the repository into the directory // return true if successful, false otherwise - Path worldDir = server.getSavePath(WorldSavePath.DATAPACKS); + Path worldDir = server.getWorldPath(LevelResource.DATAPACK_DIR); File datapackDir = new File(worldDir.toFile(), name); if (datapackDir.exists()) { diff --git a/src/main/java/dev/neylz/gitpuller/command/GitInfoCommand.java b/src/main/java/dev/neylz/gitpuller/command/GitInfoCommand.java index 792a052..6a18edc 100644 --- a/src/main/java/dev/neylz/gitpuller/command/GitInfoCommand.java +++ b/src/main/java/dev/neylz/gitpuller/command/GitInfoCommand.java @@ -6,22 +6,22 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.neylz.gitpuller.util.GitUtil; import dev.neylz.gitpuller.util.ModConfig; -import net.minecraft.command.CommandRegistryAccess; +import net.minecraft.ChatFormatting; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.WorldSavePath; +import net.minecraft.world.level.storage.LevelResource; import org.eclipse.jgit.api.Git; import java.io.File; import java.io.IOException; public class GitInfoCommand { - public static void register(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) { - LiteralArgumentBuilder infoCommand = CommandManager.literal("info"); + public static void register(CommandDispatcher dispatcher, CommandBuildContext buildContext, Commands.CommandSelection environment) { + LiteralArgumentBuilder infoCommand = Commands.literal("info"); if (!ModConfig.isMonoRepo()) { infoCommand = infoCommand.executes(GitInfoCommand::datapackInfo); @@ -29,13 +29,13 @@ public static void register(CommandDispatcher dispatcher, C infoCommand = infoCommand.executes(GitInfoCommand::datapackMonoInfo); } - dispatcher.register(CommandManager.literal("git") + dispatcher.register(Commands.literal("git") .then(infoCommand) ); } - private static int datapackMonoInfo(CommandContext ctx) throws CommandSyntaxException { - File file = ctx.getSource().getServer().getSavePath(WorldSavePath.DATAPACKS).toFile(); + private static int datapackMonoInfo(CommandContext ctx) throws CommandSyntaxException { + File file = ctx.getSource().getServer().getWorldPath(LevelResource.DATAPACK_DIR).toFile(); String remote = ""; try (Git git = Git.open(file)) { @@ -45,46 +45,46 @@ private static int datapackMonoInfo(CommandContext ctx) thr } String finalRemote = remote; - ctx.getSource().sendFeedback(() -> { - return Text.empty() - .append(Text.literal("Currently tracking as monorepo ") - .append(Text.literal(finalRemote).formatted(Formatting.AQUA)) - .append(Text.literal("\n (").formatted(Formatting.RESET)) - .append(Text.literal(GitUtil.getCurrentBranch(file)).formatted(Formatting.DARK_GREEN)) - .append(Text.literal("-").formatted(Formatting.RESET)) - .append(Text.literal(GitUtil.getCurrentHeadSha1(file, 7)).formatted(Formatting.AQUA)) - .append(Text.literal(")").formatted(Formatting.RESET)) + ctx.getSource().sendSuccess(() -> { + return Component.empty() + .append(Component.literal("Currently tracking as monorepo ") + .append(Component.literal(finalRemote).withStyle(ChatFormatting.AQUA)) + .append(Component.literal("\n (").withStyle(ChatFormatting.RESET)) + .append(Component.literal(GitUtil.getCurrentBranch(file)).withStyle(ChatFormatting.DARK_GREEN)) + .append(Component.literal("-").withStyle(ChatFormatting.RESET)) + .append(Component.literal(GitUtil.getCurrentHeadSha1(file, 7)).withStyle(ChatFormatting.AQUA)) + .append(Component.literal(")").withStyle(ChatFormatting.RESET)) ); }, false); return 1; } - private static int datapackInfo(CommandContext ctx) { + private static int datapackInfo(CommandContext ctx) { MinecraftServer server = ctx.getSource().getServer(); - File file = server.getSavePath(WorldSavePath.DATAPACKS).toFile(); + File file = server.getWorldPath(LevelResource.DATAPACK_DIR).toFile(); // list all files File[] files = file.listFiles(); if (files != null) { - ctx.getSource().sendFeedback(() -> { - MutableText text = Text.empty() - .append(Text.literal("Available datapacks:").formatted(Formatting.UNDERLINE)); + ctx.getSource().sendSuccess(() -> { + MutableComponent text = Component.empty() + .append(Component.literal("Available datapacks:").withStyle(ChatFormatting.UNDERLINE)); for (File f : files) { if (!f.isDirectory()) continue; - text.append(Text.literal("\n ").formatted(Formatting.RESET)) - .append(Text.literal("[" + f.getName() + "]").formatted(Formatting.YELLOW)); + text.append(Component.literal("\n ").withStyle(ChatFormatting.RESET)) + .append(Component.literal("[" + f.getName() + "]").withStyle(ChatFormatting.YELLOW)); if (GitUtil.isGitRepo(f)) { - text.append(Text.literal(" (").formatted(Formatting.RESET)) - .append(Text.literal(GitUtil.getCurrentBranch(f)).formatted(Formatting.DARK_GREEN)) - .append(Text.literal("-").formatted(Formatting.RESET)) - .append(Text.literal(GitUtil.getCurrentHeadSha1(f, 7)).formatted(Formatting.AQUA)) - .append(Text.literal(")").formatted(Formatting.RESET)); + text.append(Component.literal(" (").withStyle(ChatFormatting.RESET)) + .append(Component.literal(GitUtil.getCurrentBranch(f)).withStyle(ChatFormatting.DARK_GREEN)) + .append(Component.literal("-").withStyle(ChatFormatting.RESET)) + .append(Component.literal(GitUtil.getCurrentHeadSha1(f, 7)).withStyle(ChatFormatting.AQUA)) + .append(Component.literal(")").withStyle(ChatFormatting.RESET)); } else { - text.append(Text.literal(" (untracked)").formatted(Formatting.RED).formatted(Formatting.ITALIC)); + text.append(Component.literal(" (untracked)").withStyle(ChatFormatting.RED).withStyle(ChatFormatting.ITALIC)); } } diff --git a/src/main/java/dev/neylz/gitpuller/command/GitPullCommand.java b/src/main/java/dev/neylz/gitpuller/command/GitPullCommand.java index df41b36..f7bfff2 100644 --- a/src/main/java/dev/neylz/gitpuller/command/GitPullCommand.java +++ b/src/main/java/dev/neylz/gitpuller/command/GitPullCommand.java @@ -9,13 +9,13 @@ import dev.neylz.gitpuller.util.GitUtil; import dev.neylz.gitpuller.util.ModConfig; import dev.neylz.gitpuller.util.TokenManager; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.command.CommandSource; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.WorldSavePath; +import net.minecraft.ChatFormatting; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.commands.SharedSuggestionProvider; +import net.minecraft.network.chat.Component; +import net.minecraft.world.level.storage.LevelResource; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; @@ -24,27 +24,27 @@ import java.io.IOException; public class GitPullCommand { - public static void register(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) { - LiteralArgumentBuilder pullCommand = CommandManager.literal("pull").requires(CommandManager.requirePermissionLevel(CommandManager.GAMEMASTERS_CHECK)); + public static void register(CommandDispatcher dispatcher, CommandBuildContext buildContext, Commands.CommandSelection environment) { + LiteralArgumentBuilder pullCommand = Commands.literal("pull").requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS)); if (!ModConfig.isMonoRepo()) { - pullCommand = pullCommand.then(CommandManager.argument("pack name", StringArgumentType.word()).suggests( - (ctx, builder) -> CommandSource.suggestMatching(GitUtil.getTrackedDatapacks(ctx.getSource().getServer().getSavePath(WorldSavePath.DATAPACKS).toFile()), builder)) + pullCommand = pullCommand.then(Commands.argument("pack name", StringArgumentType.word()).suggests( + (ctx, builder) -> SharedSuggestionProvider.suggest(GitUtil.getTrackedDatapacks(ctx.getSource().getServer().getWorldPath(LevelResource.DATAPACK_DIR).toFile()), builder)) .executes((ctx) -> pullPack(ctx, StringArgumentType.getString(ctx, "pack name"))) ); } else { pullCommand = pullCommand.executes(GitPullCommand::pullMonoPack); } - dispatcher.register(CommandManager.literal("git").then(pullCommand)); + dispatcher.register(Commands.literal("git").then(pullCommand)); } - private static int pullMonoPack(CommandContext ctx) throws CommandSyntaxException { - ctx.getSource().sendFeedback(() -> Text.empty() - .append(Text.literal("Pulling changes from remote repository").formatted(Formatting.GREEN)), true); + private static int pullMonoPack(CommandContext ctx) throws CommandSyntaxException { + ctx.getSource().sendSuccess(() -> Component.empty() + .append(Component.literal("Pulling changes from remote repository").withStyle(ChatFormatting.GREEN)), true); - File file = ctx.getSource().getServer().getSavePath(WorldSavePath.DATAPACKS).toFile(); + File file = ctx.getSource().getServer().getWorldPath(LevelResource.DATAPACK_DIR).toFile(); // git pull -f --all String sha1 = GitUtil.getCurrentHeadSha1(file, 7); @@ -54,24 +54,24 @@ private static int pullMonoPack(CommandContext ctx) throws String newSha1 = GitUtil.getCurrentHeadSha1(file, 7); if (!sha1.equals(newSha1)) { - ctx.getSource().sendFeedback( - () -> Text.empty() - .append(Text.literal("Pulled changes").formatted(Formatting.RESET)) - .append(Text.literal(" (").formatted(Formatting.RESET)) - .append(Text.literal(sha1).formatted(Formatting.AQUA)) - .append(Text.literal(" -> ").formatted(Formatting.RESET)) - .append(Text.literal(newSha1).formatted(Formatting.LIGHT_PURPLE)) - .append(Text.literal(")").formatted(Formatting.RESET)), + ctx.getSource().sendSuccess( + () -> Component.empty() + .append(Component.literal("Pulled changes").withStyle(ChatFormatting.RESET)) + .append(Component.literal(" (").withStyle(ChatFormatting.RESET)) + .append(Component.literal(sha1).withStyle(ChatFormatting.AQUA)) + .append(Component.literal(" -> ").withStyle(ChatFormatting.RESET)) + .append(Component.literal(newSha1).withStyle(ChatFormatting.LIGHT_PURPLE)) + .append(Component.literal(")").withStyle(ChatFormatting.RESET)), true ); } return 1; } - private static int pullPack(CommandContext ctx, String packName) throws CommandSyntaxException { + private static int pullPack(CommandContext ctx, String packName) throws CommandSyntaxException { // perform git pull -f --all on the specified pack - File file = new File(ctx.getSource().getServer().getSavePath(WorldSavePath.DATAPACKS).toFile(), packName); + File file = new File(ctx.getSource().getServer().getWorldPath(LevelResource.DATAPACK_DIR).toFile(), packName); if (!file.exists()) { throw new CommandSyntaxException(null, () -> "Datapack " + packName + " does not exist"); @@ -87,15 +87,15 @@ private static int pullPack(CommandContext ctx, String pack String newSha1 = GitUtil.getCurrentHeadSha1(file, 7); if (!sha1.equals(newSha1)) { - ctx.getSource().sendFeedback( - () -> Text.empty() - .append(Text.literal("Pulled changes from ").formatted(Formatting.RESET)) - .append(Text.literal("[" + packName + "]").formatted(Formatting.YELLOW)) - .append(Text.literal(" (").formatted(Formatting.RESET)) - .append(Text.literal(sha1).formatted(Formatting.AQUA)) - .append(Text.literal(" -> ").formatted(Formatting.RESET)) - .append(Text.literal(newSha1).formatted(Formatting.LIGHT_PURPLE)) - .append(Text.literal(")").formatted(Formatting.RESET)), + ctx.getSource().sendSuccess( + () -> Component.empty() + .append(Component.literal("Pulled changes from ").withStyle(ChatFormatting.RESET)) + .append(Component.literal("[" + packName + "]").withStyle(ChatFormatting.YELLOW)) + .append(Component.literal(" (").withStyle(ChatFormatting.RESET)) + .append(Component.literal(sha1).withStyle(ChatFormatting.AQUA)) + .append(Component.literal(" -> ").withStyle(ChatFormatting.RESET)) + .append(Component.literal(newSha1).withStyle(ChatFormatting.LIGHT_PURPLE)) + .append(Component.literal(")").withStyle(ChatFormatting.RESET)), true ); } @@ -107,7 +107,7 @@ private static int pullPack(CommandContext ctx, String pack - private static boolean gitPull(ServerCommandSource sender, File repoDir) throws CommandSyntaxException { + private static boolean gitPull(CommandSourceStack sender, File repoDir) throws CommandSyntaxException { try { Git git = Git.open(repoDir); @@ -122,9 +122,9 @@ private static boolean gitPull(ServerCommandSource sender, File repoDir) throws .call(); GitPuller.LOGGER.info("Fetched changes from remote repository"); - sender.sendFeedback( - () -> Text.empty() - .append("Fetched changes from remote repository").formatted(Formatting.GREEN), + sender.sendSuccess( + () -> Component.empty() + .append("Fetched changes from remote repository").withStyle(ChatFormatting.GREEN), true ); diff --git a/src/main/java/dev/neylz/gitpuller/command/GitTokenCommand.java b/src/main/java/dev/neylz/gitpuller/command/GitTokenCommand.java index 4d02978..f81713f 100644 --- a/src/main/java/dev/neylz/gitpuller/command/GitTokenCommand.java +++ b/src/main/java/dev/neylz/gitpuller/command/GitTokenCommand.java @@ -5,18 +5,18 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import dev.neylz.gitpuller.util.TokenManager; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; +import net.minecraft.ChatFormatting; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.network.chat.Component; public class GitTokenCommand { - public static void register(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) { - dispatcher.register(CommandManager.literal("git") - .then(CommandManager.literal("token") - .requires(CommandManager.requirePermissionLevel(CommandManager.ADMINS_CHECK)) - .then(CommandManager.argument("token", StringArgumentType.greedyString()) + public static void register(CommandDispatcher dispatcher, CommandBuildContext buildContext, Commands.CommandSelection environment) { + dispatcher.register(Commands.literal("git") + .then(Commands.literal("token") + .requires(Commands.hasPermission(Commands.LEVEL_ADMINS)) + .then(Commands.argument("token", StringArgumentType.greedyString()) .executes((context) -> setToken(context, StringArgumentType.getString(context, "token")) ) ) @@ -24,10 +24,10 @@ public static void register(CommandDispatcher dispatcher, C ); } - private static int setToken(CommandContext ctx, String tk) throws CommandSyntaxException { + private static int setToken(CommandContext ctx, String tk) throws CommandSyntaxException { TokenManager.getInstance().setToken(tk); - ctx.getSource().sendFeedback(() -> Text.literal("Git organization token has been set.").formatted(Formatting.GREEN), true); + ctx.getSource().sendSuccess(() -> Component.literal("Git organization token has been set.").withStyle(ChatFormatting.GREEN), true); return 1; } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 80978f8..8961e45 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -19,7 +19,6 @@ }, "depends": { "fabricloader": ">=${loader_version}", - "fabric": "*", "fabric-api": "*" } }