Package fr.neatmonster.nocheatplus.checks.inventory

Source Code of fr.neatmonster.nocheatplus.checks.inventory.Items

package fr.neatmonster.nocheatplus.checks.inventory;

import java.util.HashSet;
import java.util.Map;

import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckType;

public class Items extends Check{
   
    private static Items instance = null;

    public Items() {
        super(CheckType.INVENTORY_ITEMS);
        instance = this;
    }
   
    /**
     *
     * @param player
     * @param stack
     * @return True if the check is failed.
     */
    public static final boolean checkIllegalEnchantments(final Player player, final ItemStack stack){
        if (stack == null) return false;
        final Material type = stack.getType();
        // Fastest checks first.
        // TODO: Make stuff configurable.
        if (type == Material.WRITTEN_BOOK){
            final Map<Enchantment, Integer> enchantments = stack.getEnchantments();
            if (enchantments != null && !enchantments.isEmpty() && instance.isEnabled(player)){
                // TODO: differentiate sub checks maybe or add extra permissions, later.
                for (final Enchantment ench : new HashSet<Enchantment>(enchantments.keySet())){
                    stack.removeEnchantment(ench);
                }
                // TODO: actions and similar.
                return true;
            }
        }
        return false;
    }

}
TOP

Related Classes of fr.neatmonster.nocheatplus.checks.inventory.Items

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.