mirror of
https://github.com/NekoMonci12/Git-Craft.git
synced 2025-12-19 14:59:22 +00:00
Add Coloring System On Git Status
This commit is contained in:
@@ -6,11 +6,9 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.yuemi.git.GitManager;
|
||||
import org.eclipse.jgit.api.Status;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class GitStatusSubcommand implements SubcommandExecutor {
|
||||
|
||||
@@ -35,28 +33,29 @@ public class GitStatusSubcommand implements SubcommandExecutor {
|
||||
GitManager git = new GitManager(repoFolder);
|
||||
Status status = git.getStatus();
|
||||
|
||||
Stream<String> changes = Stream.concat(
|
||||
status.getUncommittedChanges().stream().map(f -> "Uncommitted: " + f),
|
||||
Stream.concat(
|
||||
status.getUntracked().stream().map(f -> "Untracked: " + f),
|
||||
status.getModified().stream().map(f -> "Modified: " + f)
|
||||
)
|
||||
);
|
||||
List<String> changes = new ArrayList<>();
|
||||
|
||||
List<String> messages = changes.collect(Collectors.toList());
|
||||
status.getUncommittedChanges().forEach(file ->
|
||||
changes.add("§cUnstaged: §7" + file));
|
||||
status.getModified().forEach(file ->
|
||||
changes.add("§6Modified: §7" + file));
|
||||
status.getAdded().forEach(file ->
|
||||
changes.add("§aStaged: §7" + file));
|
||||
status.getUntracked().forEach(file ->
|
||||
changes.add("§fUntracked: §7" + file));
|
||||
|
||||
if (messages.isEmpty()) {
|
||||
if (changes.isEmpty()) {
|
||||
sender.sendMessage("§aClean working directory.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (sender instanceof Player) {
|
||||
messages.stream().limit(10).forEach(msg -> sender.sendMessage("§e" + msg));
|
||||
if (messages.size() > 10) {
|
||||
sender.sendMessage("§7... and " + (messages.size() - 10) + " more.");
|
||||
changes.stream().limit(10).forEach(sender::sendMessage);
|
||||
if (changes.size() > 10) {
|
||||
sender.sendMessage("§7... and " + (changes.size() - 10) + " more.");
|
||||
}
|
||||
} else {
|
||||
messages.forEach(msg -> sender.sendMessage("[GitStatus] " + msg));
|
||||
changes.forEach(sender::sendMessage);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in New Issue
Block a user