diff --git a/app/src/main/java/org/yuemi/commands/SubcommandHandler.java b/app/src/main/java/org/yuemi/commands/SubcommandHandler.java index b153539..272e20a 100644 --- a/app/src/main/java/org/yuemi/commands/SubcommandHandler.java +++ b/app/src/main/java/org/yuemi/commands/SubcommandHandler.java @@ -29,14 +29,14 @@ public class SubcommandHandler { this.dbPassword = dbPassword; commands.put("add", new GitAddSubcommand(plugin)); commands.put("commit", new GitCommitSubcommand(plugin)); - commands.put("push", new GitPushSubcommand(plugin)); commands.put("reset", new GitResetSubcommand(plugin)); commands.put("init", new GitInitSubcommand(plugin)); commands.put("remote", new GitRemoteSubcommand(plugin)); - commands.put("fetch", new GitFetchSubcommand(plugin)); - commands.put("pull", new GitPullSubcommand(plugin)); commands.put("status", new GitStatusSubcommand(plugin)); commands.put("help", new GitHelpSubcommand(plugin)); + commands.put("push", new GitPushSubcommand(plugin, filePassword, dbPassword)); + commands.put("fetch", new GitFetchSubcommand(plugin, filePassword, dbPassword)); + commands.put("pull", new GitPullSubcommand(plugin, filePassword, dbPassword)); commands.put("login", new GitLoginSubcommand(plugin, filePassword, dbPassword)); commands.put("whoami", new GitWhoamiSubcommand(plugin, filePassword, dbPassword)); commands.put("logout", new GitLogoutSubcommand(plugin, filePassword, dbPassword)); diff --git a/app/src/main/java/org/yuemi/commands/subcommands/GitFetchSubcommand.java b/app/src/main/java/org/yuemi/commands/subcommands/GitFetchSubcommand.java index 1023a82..7a90e7e 100644 --- a/app/src/main/java/org/yuemi/commands/subcommands/GitFetchSubcommand.java +++ b/app/src/main/java/org/yuemi/commands/subcommands/GitFetchSubcommand.java @@ -4,40 +4,41 @@ import org.yuemi.commands.SubcommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.plugin.java.JavaPlugin; import org.yuemi.git.GitManager; +import org.yuemi.git.GitCredentialDatabaseManager; import java.io.File; public class GitFetchSubcommand implements SubcommandExecutor { private final JavaPlugin plugin; + private final GitCredentialDatabaseManager credentialDB; - public GitFetchSubcommand(JavaPlugin plugin) { + public GitFetchSubcommand(JavaPlugin plugin, String filePassword, String dbPassword) { this.plugin = plugin; + this.credentialDB = new GitCredentialDatabaseManager(plugin.getDataFolder(), filePassword, dbPassword); } @Override public void execute(CommandSender sender, String[] args) { plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> { File repoFolder = new File("."); - String username = null; - String token = null; for (String arg : args) { if (arg.startsWith("--path=")) { repoFolder = new File(arg.substring("--path=".length())); - } else if (arg.startsWith("--username=")) { - username = arg.substring("--username=".length()); - } else if (arg.startsWith("--token=")) { - token = arg.substring("--token=".length()); } } - if (username == null || token == null) { - sender.sendMessage("§cUsage: /git fetch --username=... --token=..."); - return; - } - try { + String[] creds = credentialDB.getCredentials(); + if (creds == null) { + sender.sendMessage("§cNo stored credentials found. Use §e/git login§c to set them."); + return; + } + + String username = creds[0]; + String token = creds[1]; + GitManager git = new GitManager(repoFolder); git.fetch(username, token); sender.sendMessage("§aFetched remote updates."); diff --git a/app/src/main/java/org/yuemi/commands/subcommands/GitPullSubcommand.java b/app/src/main/java/org/yuemi/commands/subcommands/GitPullSubcommand.java index 1488c75..3bcd0d8 100644 --- a/app/src/main/java/org/yuemi/commands/subcommands/GitPullSubcommand.java +++ b/app/src/main/java/org/yuemi/commands/subcommands/GitPullSubcommand.java @@ -3,6 +3,7 @@ package org.yuemi.commands.subcommands; import org.yuemi.commands.SubcommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.plugin.java.JavaPlugin; +import org.yuemi.git.GitCredentialDatabaseManager; import org.yuemi.git.GitManager; import java.io.File; @@ -10,34 +11,34 @@ import java.io.File; public class GitPullSubcommand implements SubcommandExecutor { private final JavaPlugin plugin; + private final GitCredentialDatabaseManager credentialDB; - public GitPullSubcommand(JavaPlugin plugin) { + public GitPullSubcommand(JavaPlugin plugin, String filePassword, String dbPassword) { this.plugin = plugin; + this.credentialDB = new GitCredentialDatabaseManager(plugin.getDataFolder(), filePassword, dbPassword); } @Override public void execute(CommandSender sender, String[] args) { plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> { File repoFolder = new File("."); - String username = null; - String token = null; for (String arg : args) { if (arg.startsWith("--path=")) { repoFolder = new File(arg.substring("--path=".length())); - } else if (arg.startsWith("--username=")) { - username = arg.substring("--username=".length()); - } else if (arg.startsWith("--token=")) { - token = arg.substring("--token=".length()); } } - if (username == null || token == null) { - sender.sendMessage("§cUsage: /git pull --username=... --token=..."); - return; - } - try { + String[] creds = credentialDB.getCredentials(); + if (creds == null) { + sender.sendMessage("§cNo stored credentials found. Use §e/git login§c to set them."); + return; + } + + String username = creds[0]; + String token = creds[1]; + GitManager git = new GitManager(repoFolder); git.pull(username, token); sender.sendMessage("§aPulled and merged from origin."); diff --git a/app/src/main/java/org/yuemi/commands/subcommands/GitPushSubcommand.java b/app/src/main/java/org/yuemi/commands/subcommands/GitPushSubcommand.java index 8154399..123f805 100644 --- a/app/src/main/java/org/yuemi/commands/subcommands/GitPushSubcommand.java +++ b/app/src/main/java/org/yuemi/commands/subcommands/GitPushSubcommand.java @@ -3,6 +3,7 @@ package org.yuemi.commands.subcommands; import org.yuemi.commands.SubcommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.plugin.java.JavaPlugin; +import org.yuemi.git.GitCredentialDatabaseManager; import org.yuemi.git.GitManager; import java.io.File; @@ -10,37 +11,37 @@ import java.io.File; public class GitPushSubcommand implements SubcommandExecutor { private final JavaPlugin plugin; + private final GitCredentialDatabaseManager credentialDB; - public GitPushSubcommand(JavaPlugin plugin) { + public GitPushSubcommand(JavaPlugin plugin, String filePassword, String dbPassword) { this.plugin = plugin; + this.credentialDB = new GitCredentialDatabaseManager(plugin.getDataFolder(), filePassword, dbPassword); } @Override public void execute(CommandSender sender, String[] args) { plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> { File repoFolder = new File("."); - String username = null; - String token = null; for (String arg : args) { if (arg.startsWith("--path=")) { repoFolder = new File(arg.substring("--path=".length())); - } else if (arg.startsWith("--username=")) { - username = arg.substring("--username=".length()); - } else if (arg.startsWith("--token=")) { - token = arg.substring("--token=".length()); } } - if (username == null || token == null) { - sender.sendMessage("§cUsage: /git push --username=... --token=..."); - return; - } - try { + String[] creds = credentialDB.getCredentials(); + if (creds == null) { + sender.sendMessage("§cNo stored credentials found. Use §e/git login§c to set them."); + return; + } + + String username = creds[0]; + String token = creds[1]; + GitManager git = new GitManager(repoFolder); git.push(username, token); - sender.sendMessage("§aPushed to remote."); + sender.sendMessage("§aPushed to remote repository successfully."); } catch (Exception e) { sender.sendMessage("§cGit push failed: " + e.getMessage()); e.printStackTrace();