package org.black_ixx.bossshop.points;

import org.black_ixx.bossshop.BossShop;
import org.black_ixx.playerpoints.PlayerPoints;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.Plugin;

public class PlayerPointsAPI extends IPointsAPI{

    public PlayerPointsAPI(BossShop pPlugin){
        super(pPlugin,"PlayerPoints");
        final Plugin plugin=Bukkit.getServer().getPluginManager().getPlugin("PlayerPoints");
        if(plugin!=null){
            pp=(PlayerPoints.class.cast(plugin));
        }else{
            // Sinnlos? Wird Klasse wird eh nur erstellt wenn es Plugin gibt
            this.mPlugin.warn("PlayerPoints was not found... You need it if you want to work with Points! Get it there: http://dev.bukkit.org/server-mods/playerpoints/");
            return;
        }
    }

    private PlayerPoints pp;

    @Override
    public int getPoints(OfflinePlayer player){
        return pp.getAPI().look(player.getName());
    }

    @Override
    public int setPoints(OfflinePlayer player,int points){
        pp.getAPI().set(player.getName(),points);
        return points;
    }

    @Override
    public int takePoints(OfflinePlayer player,int points){
        pp.getAPI().take(player.getName(),points);
        return getPoints(player);
    }

    @Override
    public int givePoints(OfflinePlayer player,int points){
        pp.getAPI().give(player.getName(),points);
        return getPoints(player);
    }

}
