package leigh.minecraft.link.bukkit;

import leigh.minecraft.link.faction.ReputationEventHandler;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import java.util.UUID;

/**
 * Implementation of {@link ReputationEventHandler} for the Bukkit API. This implementation sends messages to the
 * player when their reputation changes.
 *
 * @author Alex Leigh
 */
public class BukkitReputationEventHandler implements ReputationEventHandler {
    @Override
    public void reputationChanged(UUID playerId, String factionDisplayName, int delta) {
        Player p = Bukkit.getPlayer(playerId);
        if (p != null) {
            if (delta >= 0) {
                p.sendMessage("Your reputation with " + factionDisplayName + " has increased by " + delta + " points.");
            } else {
                int x = -delta;
                p.sendMessage("Your reputation with " + factionDisplayName + " has decreased by " + x + " points.");
            }
        }
    }

    @Override
    public void reputationLevelChanged(UUID playerId, String factionDisplayName, String factionLevel) {
        Player p = Bukkit.getPlayer(playerId);
        if (p != null) {
            p.sendMessage(factionDisplayName + " now consider you " + factionLevel + "!");
        }
    }
}
