001package net.tnemc.item.platform.registry; 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 java.util.HashMap; 022import java.util.LinkedList; 023import java.util.Map; 024 025/** 026 * BaseHelper 027 * 028 * @author creatorfromhell 029 * @since 0.2.0.0 030 */ 031public abstract class BaseHelper { 032 033 protected final Map<String, RegistryHandler> registryHandlers = new HashMap<>(); 034 035 public void initializeHandlers() { 036 registryHandlers.values().forEach(RegistryHandler::initialize); 037 } 038 039 public RegistryHandler getHandler(final String identifier) { 040 return registryHandlers.get(identifier); 041 } 042 043 public void registerHandler(final String identifier, final RegistryHandler handler) { 044 registryHandlers.put(identifier, handler); 045 } 046 047 public LinkedList<String> getKeys(final String identifier) { 048 049 if(registryHandlers.containsKey(identifier)) { 050 return registryHandlers.get(identifier).keys; 051 } 052 return new LinkedList<>(); 053 } 054 055 /** 056 * Returns a collection of materials. 057 * 058 * @return a collection of materials 059 * @since 0.2.0.0 060 */ 061 public LinkedList<String> materials() { 062 063 return getKeys("materials"); 064 } 065 066 /** 067 * Returns a collection of enchantments. 068 * 069 * @return a collection of enchantments 070 * @since 0.2.0.0 071 */ 072 public LinkedList<String> enchantments() { 073 074 return getKeys("enchantments"); 075 } 076 077 /** 078 * Returns a collection of flags. 079 * 080 * @return a collection of flags 081 * @since 0.2.0.0 082 */ 083 public LinkedList<String> flags() { 084 085 return getKeys("flags"); 086 } 087}