Player Name As Commit Author

This commit is contained in:
Muhammad Tamir
2025-06-20 11:04:26 +07:00
parent 7699b307c8
commit 634b8fa31b
2 changed files with 15 additions and 4 deletions

View File

@@ -2,6 +2,7 @@ package org.yuemi.commands.subcommands;
import org.yuemi.commands.SubcommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.yuemi.git.GitManager;
@@ -38,10 +39,20 @@ public class GitCommitSubcommand implements SubcommandExecutor {
return;
}
String authorName;
String authorEmail;
if (sender instanceof Player player) {
authorName = player.getName();
authorEmail = player.getName().toLowerCase() + "@server.local";
} else {
authorName = "Console";
authorEmail = "console@localhost";
}
try {
GitManager git = new GitManager(repoFolder);
git.commit(message);
sender.sendMessage("§aCommitted: §f" + message);
git.commit(message, authorName, authorEmail);
sender.sendMessage("§aCommitted as §f" + authorName + " §a→ §f" + message);
} catch (Exception e) {
sender.sendMessage("§cGit commit failed: " + e.getMessage());
e.printStackTrace();

View File

@@ -53,11 +53,11 @@ public class GitManager {
add.call();
}
public void commit(String message) throws Exception {
public void commit(String message, String authorName, String authorEmail) throws Exception {
getOrOpenGit()
.commit()
.setMessage(message)
.setAuthor("Minecraft", "mc@localhost")
.setAuthor(authorName, authorEmail)
.call();
}