package me.rbrickis.mojo.bukkit;

import me.rbrickis.mojo.annotations.Command;
import me.rbrickis.mojo.annotations.Default;
import me.rbrickis.mojo.annotations.Text;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.stream.IntStream;

public class ExampleCommands {

    private Map<UUID, UUID> replyMap = new HashMap<>();

    @Command(aliases = "hello")
    @me.rbrickis.mojo.bukkit.annotations.Player
    public void helloWorld(Player player) {
        player.sendMessage(ChatColor.GOLD + "Hello, " + player.getName());
    }

    @Command(aliases = {"broadcast", "bc"})
    public void broadcast(CommandSender sender, @Text @Default("&6Hello World!") String message) {
        Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', message));
    }

    @Command(aliases = {"message", "msg", "tell"})
    @me.rbrickis.mojo.bukkit.annotations.Player
    public void message(Player sender, Player receiver, @Text String message) {
        if (receiver == null) {
            sender.sendMessage(ChatColor.RED + "Could not find player!");
        } else {
            replyMap.put(sender.getUniqueId(), receiver.getUniqueId());
            replyMap.put(receiver.getUniqueId(), sender.getUniqueId());

            sender.sendMessage(ChatColor.GRAY + "(To " + receiver.getDisplayName() + ChatColor.GRAY + "): "
                    + ChatColor.WHITE + message);
            sender.playSound(sender.getLocation(), Sound.SUCCESSFUL_HIT, 1f, 0.1f);
            receiver.sendMessage(ChatColor.GRAY + "(From " + sender.getDisplayName() + ChatColor.GRAY + "): "
                    + ChatColor.WHITE + message);

            receiver.playSound(sender.getLocation(), Sound.SUCCESSFUL_HIT, 1f, 0.1f);
        }
    }

    @Command(aliases = {"reply", "r"}, desc = "Reply to someone who has messaged you!")
    @me.rbrickis.mojo.bukkit.annotations.Player
    public void reply(Player sender, @Text String message) {
        if (replyMap.containsKey(sender.getUniqueId())) {
            UUID toSend = replyMap.get(sender.getUniqueId());

            if (Bukkit.getPlayer(toSend) != null) {
                Player toSendPlayer = Bukkit.getPlayer(toSend);
                sender.sendMessage(ChatColor.GRAY + "(To " + toSendPlayer.getDisplayName() + ChatColor.GRAY + "): "
                        + ChatColor.WHITE + message);
                sender.playSound(sender.getLocation(), Sound.SUCCESSFUL_HIT, 1f, 0.1f);
                toSendPlayer.sendMessage(ChatColor.GRAY + "(From " + sender.getDisplayName() + ChatColor.GRAY + "): "
                        + ChatColor.WHITE + message);
                toSendPlayer.playSound(sender.getLocation(), Sound.SUCCESSFUL_HIT, 1f, 0.1f);
            } else {
                replyMap.remove(toSend);
                replyMap.remove(sender.getUniqueId());
                sender.sendMessage(ChatColor.RED + "The player you were messaging is not online!");
            }
        } else {
            sender.sendMessage(ChatColor.RED + "You have no one to reply to!");
        }
    }

    @Command(aliases = {"clearchat", "cc"})
    public void clearChat(CommandSender sender, @Default("120") int lines) {
        IntStream.range(0, lines).forEach(i -> Bukkit.broadcastMessage(""));
        Bukkit.broadcastMessage("Chat has been cleared by " + sender.getName());
    }


}

@@ -313,16 +313,313 @@
 Player;%0A
+import org.json.simple.JSONArray;%0Aimport org.json.simple.JSONObject;%0Aimport org.json.simple.parser.JSONParser;%0Aimport org.json.simple.parser.ParseException;%0A%0Aimport java.io.IOException;%0Aimport java.io.InputStreamReader;%0Aimport java.net.URI;%0Aimport java.net.URISyntaxException;%0Aimport java.net.URL;
 %0Aimport 
@@ -3793,10 +3793,1497 @@
     %7D%0A%0A%0A
+    // gets a commit from the latest build%0A    @Command(aliases = %7B%22getcommit%22%7D)%0A    public void getGitCommit(CommandSender sender, @Default(%22Mojo%22) String project) %7B%0A        try %7B%0A            URL uri = new URI(%22http://localhost:8080/job/%22+ project +%22/lastBuild/api/json?pretty=true%22).toURL();%0A            final JSONParser parser = new JSONParser();%0A            final JSONObject object = (JSONObject)parser.parse(new InputStreamReader(uri.openStream()));%0A            final JSONObject changeSet = (JSONObject) object.get(%22changeSet%22);%0A            final JSONArray items = (JSONArray) changeSet.get(%22items%22);%0A            final JSONObject commitObject = (JSONObject) items.get(0);%0A            final String buildDisplayName = (String) object.get(%22fullDisplayName%22);%0A            final String commitMessage = (String) commitObject.get(%22msg%22);%0A            final String commitId = (String) commitObject.get(%22commitId%22);%0A            final String date = (String) commitObject.get(%22date%22);%0A            sender.sendMessage(ChatColor.GREEN + buildDisplayName + %22:%22);%0A            sender.sendMessage(ChatColor.YELLOW + %22 Commit ID: %22 + ChatColor.GREEN + commitId.substring(0, 12));%0A            sender.sendMessage(ChatColor.YELLOW + %22 Commit Message: %22 + ChatColor.GREEN + commitMessage);%0A            sender.sendMessage(ChatColor.YELLOW + %22 Date of Commit%22 + ChatColor.GREEN + date);%0A        %7D catch (URISyntaxException %7C IOException %7C ParseException e) %7B%0A            e.printStackTrace();%0A        %7D%0A    %7D%0A
 %7D%0A

Add getcommit command