/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pw.yumc.Residence.itemlist;

import java.util.Map;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;

import com.bekvon.bukkit.residence.permissions.PermissionGroup;
import com.bekvon.bukkit.residence.protection.ClaimedResidence;

import pw.yumc.Residence.ResidenceMain;

/**
 *
 * @author Administrator
 */
public class ResidenceItemList extends ItemList {
    ResidenceMain plugin;
    ClaimedResidence res;

    public ResidenceItemList(final ResidenceMain plugin, final ClaimedResidence parent, final ListType type) {
        super(type);
        this.plugin = plugin;
        res = parent;
    }

    private ResidenceItemList(final ResidenceMain plugin) {
        this.plugin = plugin;
    }

    public static ResidenceItemList load(final ResidenceMain plugin, final ClaimedResidence parent, final Map<String, Object> map) {
        final ResidenceItemList newlist = new ResidenceItemList(plugin);
        newlist.res = parent;
        return (ResidenceItemList) ItemList.load(map, newlist);
    }

    public void playerListChange(final Player player, final Material mat, final boolean resadmin) {
        final PermissionGroup group = plugin.getPermissionManager().getGroup(player);
        if (resadmin || (res.getPermissions().hasResidencePermission(player, true) && group.itemListAccess())) {
            if (super.toggle(mat)) {
                player.sendMessage(ChatColor.YELLOW + plugin.getLanguage().getPhrase("ListMaterialAdd",
                        ChatColor.GREEN + mat.toString() + ChatColor.YELLOW + "." + ChatColor.GREEN + type.toString().toLowerCase() + ChatColor.YELLOW));
            } else {
                player.sendMessage(ChatColor.YELLOW + plugin.getLanguage().getPhrase("ListMaterialRemove",
                        ChatColor.GREEN + mat.toString() + ChatColor.YELLOW + "." + ChatColor.GREEN + type.toString().toLowerCase() + ChatColor.YELLOW));
            }
        } else {
            player.sendMessage(ChatColor.RED + plugin.getLanguage().getPhrase("NoPermission"));
        }
    }
}
