mirror of
https://github.com/NekoMonci12/Git-Craft.git
synced 2025-12-19 14:59:22 +00:00
Player Name As Commit Author
This commit is contained in:
@@ -2,6 +2,7 @@ package org.yuemi.commands.subcommands;
|
|||||||
|
|
||||||
import org.yuemi.commands.SubcommandExecutor;
|
import org.yuemi.commands.SubcommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.yuemi.git.GitManager;
|
import org.yuemi.git.GitManager;
|
||||||
|
|
||||||
@@ -38,10 +39,20 @@ public class GitCommitSubcommand implements SubcommandExecutor {
|
|||||||
return;
|
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 {
|
try {
|
||||||
GitManager git = new GitManager(repoFolder);
|
GitManager git = new GitManager(repoFolder);
|
||||||
git.commit(message);
|
git.commit(message, authorName, authorEmail);
|
||||||
sender.sendMessage("§aCommitted: §f" + message);
|
sender.sendMessage("§aCommitted as §f" + authorName + " §a→ §f" + message);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
sender.sendMessage("§cGit commit failed: " + e.getMessage());
|
sender.sendMessage("§cGit commit failed: " + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -53,11 +53,11 @@ public class GitManager {
|
|||||||
add.call();
|
add.call();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void commit(String message) throws Exception {
|
public void commit(String message, String authorName, String authorEmail) throws Exception {
|
||||||
getOrOpenGit()
|
getOrOpenGit()
|
||||||
.commit()
|
.commit()
|
||||||
.setMessage(message)
|
.setMessage(message)
|
||||||
.setAuthor("Minecraft", "mc@localhost")
|
.setAuthor(authorName, authorEmail)
|
||||||
.call();
|
.call();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user