Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.14-SNAPSHOT'
id 'net.fabricmc.fabric-loom' version "${loom_version}"
id 'maven-publish'
}

Expand All @@ -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')
}
Expand All @@ -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
Expand Down
19 changes: 12 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
66 changes: 33 additions & 33 deletions src/main/java/dev/neylz/gitpuller/command/GitCheckoutCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,16 +31,16 @@
import java.util.regex.Pattern;

public class GitCheckoutCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
LiteralArgumentBuilder<ServerCommandSource> checkoutCommand = CommandManager.literal("checkout").requires(CommandManager.requirePermissionLevel(CommandManager.GAMEMASTERS_CHECK));
RequiredArgumentBuilder<ServerCommandSource, String> branchArg = CommandManager.argument("branch", StringArgumentType.greedyString());
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext buildContext, Commands.CommandSelection environment) {
LiteralArgumentBuilder<CommandSourceStack> checkoutCommand = Commands.literal("checkout").requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS));
RequiredArgumentBuilder<CommandSourceStack, String> 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"))
)));
Expand All @@ -53,28 +53,28 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher, C
));
}

dispatcher.register(CommandManager.literal("git")
dispatcher.register(Commands.literal("git")
.then(checkoutCommand)
);
}

private static int checkoutMono(CommandContext<ServerCommandSource> 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<CommandSourceStack> 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<ServerCommandSource> ctx, String pack, String branch) throws CommandSyntaxException {
private static int checkout(CommandContext<CommandSourceStack> 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)) {
Expand All @@ -93,7 +93,7 @@ private static int checkout(CommandContext<ServerCommandSource> 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()
Expand All @@ -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();
Expand All @@ -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);
}

Expand Down
49 changes: 23 additions & 26 deletions src/main/java/dev/neylz/gitpuller/command/GitCloneCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
public static void register(CommandDispatcher<CommandSourceStack> 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")))
))
)
Expand All @@ -44,31 +41,31 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher, C
);
}

private static int cloneDatapack(CommandContext<ServerCommandSource> ctx, String name, String remoteUrl) throws CommandSyntaxException {
private static int cloneDatapack(CommandContext<CommandSourceStack> 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;
Expand All @@ -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()) {
Expand Down
Loading