mirror of
https://github.com/NekoMonci12/Git-Craft.git
synced 2025-12-19 14:59:22 +00:00
Automatic Use Saved Credentials
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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.");
|
||||
|
||||
@@ -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.");
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user