001package net.tnemc.item.paper;
002
003/*
004 * The New Item Library Minecraft Server Plugin
005 *
006 * Copyright (C) 2022 - 2025 Daniel "creatorfromhell" Vidmar
007 *
008 * This program is free software; you can redistribute it and/or
009 * modify it under the terms of the GNU Lesser General Public
010 * License as published by the Free Software Foundation; either
011 * version 3 of the License, or (at your option) any later version.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
016 * Lesser General Public License for more details.
017 *
018 * You should have received a copy of the GNU Lesser General Public License
019 * along with this program; if not, write to the Free Software Foundation,
020 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
021 */
022
023import com.destroystokyo.paper.profile.PlayerProfile;
024import com.destroystokyo.paper.profile.ProfileProperty;
025import io.papermc.paper.registry.RegistryAccess;
026import io.papermc.paper.registry.RegistryKey;
027import net.tnemc.item.paper.platform.PaperItemPlatform;
028import net.tnemc.item.providers.HelperMethods;
029import net.tnemc.item.providers.VersionUtil;
030import org.bukkit.Bukkit;
031import org.bukkit.Registry;
032import org.bukkit.inventory.ItemFlag;
033
034import java.util.LinkedList;
035import java.util.UUID;
036
037/**
038 * BukkitHelper
039 *
040 * @author creatorfromhell
041 * @since 0.1.7.5-Pre-5
042 */
043public class PaperHelper implements HelperMethods {
044
045  final LinkedList<String> materialKeys = new LinkedList<>();
046  final LinkedList<String> enchantmentKeys = new LinkedList<>();
047  final LinkedList<String> itemFlagKeys = new LinkedList<>();
048
049  public PaperHelper() {
050
051    Registry.MATERIAL.forEach((material)->{
052
053      if(material.isItem()) {
054        materialKeys.add(material.getKey().getKey());
055      }
056    });
057
058    if(VersionUtil.isVersion(PaperItemPlatform.instance().version(), "1.21")) {
059
060      RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT).forEach((enchantment)->{
061        if(enchantment != null) {
062
063          enchantmentKeys.add(enchantment.getKey().toString());
064        }
065      });
066
067
068    } else {
069
070      Registry.ENCHANTMENT.forEach((enchantment) -> {
071        if(enchantment != null) {
072
073          enchantmentKeys.add(enchantment.getKey().toString());
074        }
075      });
076    }
077
078    for(final ItemFlag itemFlag : ItemFlag.values()) {
079      itemFlagKeys.add(itemFlag.name());
080    }
081  }
082
083  @Override
084  public LinkedList<String> materials() {
085
086    return materialKeys;
087  }
088
089  @Override
090  public LinkedList<String> enchantments() {
091
092    return enchantmentKeys;
093  }
094
095  @Override
096  public LinkedList<String> flags() {
097
098    return itemFlagKeys;
099  }
100
101  public PlayerProfile base64(final String base64) {
102
103    final PlayerProfile profile = Bukkit.createProfile(new UUID(base64.hashCode(), base64.hashCode()));
104    profile.setProperty(new ProfileProperty("textures", base64));
105    return profile;
106  }
107}