001/*
002 * PlotSquared, a land and world management plugin for Minecraft.
003 * Copyright (C) IntellectualSites <https://intellectualsites.com>
004 * Copyright (C) IntellectualSites team and contributors
005 *
006 * This program is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
018 */
019package com.plotsquared.core.util.entity;
020
021import com.plotsquared.core.util.WorldUtil;
022import com.sk89q.worldedit.registry.Category;
023import com.sk89q.worldedit.registry.Keyed;
024import com.sk89q.worldedit.registry.NamespacedRegistry;
025import com.sk89q.worldedit.world.entity.EntityType;
026
027import java.util.Set;
028
029/**
030 * Categories to which an {@link com.sk89q.worldedit.entity.Entity} may belong
031 */
032public class EntityCategory extends Category<EntityType> implements Keyed {
033
034    public static final NamespacedRegistry<EntityCategory> REGISTRY =
035            new NamespacedRegistry<>("entity type");
036
037    private final WorldUtil worldUtil;
038    private final String key;
039
040    protected EntityCategory(final WorldUtil worldUtil, final String id) {
041        super("plotsquared:" + id);
042        this.key = id;
043        this.worldUtil = worldUtil;
044    }
045
046    @Override
047    protected Set<EntityType> load() {
048        return this.worldUtil.getTypesInCategory(this.key);
049    }
050
051}