package com.mcbans.firestar.mcbans.api;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import com.mcbans.firestar.mcbans.BanType;
import com.mcbans.firestar.mcbans.MCBans;
import com.mcbans.firestar.mcbans.pluginInterface.Ban;
import com.mcbans.firestar.mcbans.pluginInterface.Kick;

public class MCBansAPI {
    private final MCBans plugin;

    public MCBansAPI(final MCBans plugin) {
        this.plugin = plugin;
    }

    private void ban(BanType type, String targetName, String senderName, String reason, String duration, String measure){
        // check null
        if (targetName == null || senderName == null){
            return;
        }

        String targetIP = "";
        if (type != BanType.UNBAN){
            final Player target = Bukkit.getPlayerExact(targetName);
            targetIP = (target != null) ? target.getAddress().getAddress().getHostAddress() : "";
        }

        Ban banControl = new Ban(plugin, type.getActionName(), targetName, targetIP, senderName, reason, duration, measure);
        Thread triggerThread = new Thread(banControl);
        triggerThread.start();
    }

    public void localBan(String targetName, String senderName, String reason){
        reason = (reason == null || reason == "") ? plugin.settings.getString("defaultLocal") : reason;
        this.ban(BanType.LOCAL, targetName, senderName, reason, "", "");
    }

    public void globalBan(String targetName, String senderName, String reason){
        if (reason == null || reason == "") return;
        this.ban(BanType.GLOBAL, targetName, senderName, reason, "", "");
    }

    public void tempBan(String targetName, String senderName, String reason, String duration, String measure){
        reason = (reason == null || reason == "") ? plugin.settings.getString("defaultTemp") : reason;
        duration = (duration == null) ? "" : duration;
        measure = (measure == null) ? "" : measure;
        this.ban(BanType.TEMP, targetName, senderName, reason, duration, measure);
    }

    public void unBan(String targetName, String senderName){
        this.ban(BanType.UNBAN, targetName, senderName, "", "", "");
    }

    public void kick(String targetName, String senderName, String reason){
        reason = (reason == null || reason == "") ? plugin.settings.getString("defaultKick") : reason;

        // Start
        Kick kickPlayer = new Kick(plugin.settings, plugin, targetName, senderName, reason);
        Thread triggerThread = new Thread(kickPlayer);
        triggerThread.start();
    }
}

@@ -1149,32 +1149,208 @@
 rt();%0D%0A    %7D%0D%0A%0D%0A
+    /**%0D%0A     * Add Locally BAN%0D%0A     * @param targetName BAN target player's name%0D%0A     * @param senderName BAN issued admin's name%0D%0A     * @param reason BAN reason%0D%0A     */%0D%0A
     public void 
@@ -1593,32 +1593,209 @@
  %22%22);%0D%0A    %7D%0D%0A%0D%0A
+    /**%0D%0A     * Add Globally BAN%0D%0A     * @param targetName BAN target player's name%0D%0A     * @param senderName BAN issued admin's name%0D%0A     * @param reason BAN reason%0D%0A     */%0D%0A
     public void 
@@ -1988,32 +1988,353 @@
  %22%22);%0D%0A    %7D%0D%0A%0D%0A
+    /**%0D%0A     * Add Temporary BAN%0D%0A     * @param targetName BAN target player's name%0D%0A     * @param senderName BAN issued admin's name%0D%0A     * @param reason BAN reason%0D%0A     * @param duration Banning length duration (intValue)%0D%0A     * @param measure Banning length measure (m(minute), h(hour), d(day), w(week))%0D%0A     */%0D%0A
     public void 
@@ -2743,143 +2743,460 @@
     
-public void unBan(String targetName, String senderName)%7B%0D%0A        this.ban(BanType.UNBAN, targetName, senderName, %22%22, %22%22, %22%22);%0D%0A    %7D%0D%0A
+/**%0D%0A     * Remove BAN%0D%0A     * @param targetName UnBan target player's name%0D%0A     * @param senderName UnBan issued admin's name%0D%0A     */%0D%0A    public void unBan(String targetName, String senderName)%7B%0D%0A        this.ban(BanType.UNBAN, targetName, senderName, %22%22, %22%22, %22%22);%0D%0A    %7D%0D%0A%0D%0A    /**%0D%0A     * Kick Player%0D%0A     * @param targetName Kick target player's name%0D%0A     * @param senderName Kick issued admin's name%0D%0A     * @param reason Kick reason%0D%0A     */
 %0D%0A  

Add MCBansAPI JavaDoc