001package net.tnemc.item.bukkit.platform;
002/*
003 * The New Item Library
004 * Copyright (C) 2022 - 2025 Daniel "creatorfromhell" Vidmar
005 *
006 * This program is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (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 GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public License
017 * along with this program; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019 */
020
021import net.tnemc.item.platform.registry.BaseHelper;
022import net.tnemc.item.platform.registry.SupplierRegistryHandler;
023import net.tnemc.item.providers.VersionUtil;
024import org.bukkit.Registry;
025import org.bukkit.enchantments.Enchantment;
026import org.bukkit.inventory.ItemFlag;
027
028import java.util.LinkedList;
029
030/**
031 * BukkitHelper
032 *
033 * @author creatorfromhell
034 * @since 0.2.0.0
035 */
036public class BukkitHelper extends BaseHelper {
037
038  public BukkitHelper() {
039    registerHandler("materials", new SupplierRegistryHandler(() -> {
040
041      final LinkedList<String> keys = new LinkedList<>();
042
043      Registry.MATERIAL.forEach(material -> {
044        if(material.isItem()) {
045          keys.add(material.getKey().getKey());
046        }
047      });
048      return keys;
049    }));
050
051    registerHandler("enchantments", new SupplierRegistryHandler(() -> {
052
053      final LinkedList<String> keys = new LinkedList<>();
054      if(VersionUtil.isVersion(BukkitItemPlatform.instance().version(), "1.20.3")) {
055
056        Registry.ENCHANTMENT.forEach((enchantment) -> {
057          if(enchantment != null) {
058
059            keys.add(enchantment.getKey().toString());
060          }
061        });
062
063      } else {
064
065        for(final Enchantment enchantment : Enchantment.values()) {
066          keys.add(enchantment.getKey().toString());
067        }
068      }
069      return keys;
070    }));
071
072    registerHandler("flags", new SupplierRegistryHandler(() -> {
073      final LinkedList<String> keys = new LinkedList<>();
074
075      for(final ItemFlag itemFlag : ItemFlag.values()) {
076        keys.add(itemFlag.name());
077      }
078      return keys;
079    }));
080
081    initializeHandlers();
082  }
083}