Redo the item registry system for the mod

This commit is contained in:
Aubri Seebauer committed 2023-05-02 15:56:01 -04:00
1 parent c2b5629df5
commit 1dd938da60
10 files changed
+212 -152

No files matched your search

@@ -0,0 +1,81 @@
package me.ShermansWorld.AlathraWar.items;
import me.ShermansWorld.AlathraWar.Helper;
import me.ShermansWorld.AlathraWar.Main;
import me.ShermansWorld.AlathraWar.items.item.RamItem;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class WarItemRegistry {
private static final HashMap<String, IWarItem> itemRegistry = new HashMap<>();
public static final String namespace = Main.getInstance().getName().toLowerCase();
/**
* loads all items into the plugin registry list
*/
public WarItemRegistry() {
Main.warLogger.log(Helper.chatLabel() + "Registering AlathraWar items.");
itemRegistry.put(registryName("ram"), new RamItem());
Main.warLogger.log(Helper.chatLabel() + "Registered AlathraWar items.");
}
/**
* generate a registry name
* @param item
* @return
*/
public static String registryName(String item) {
return namespace + ":" + item;
}
public Map<String, ItemStack> getItemRegistry() {
return itemRegistry.entrySet()
.stream()
.filter(v -> v.getValue() != null)
.collect(Collectors.toMap(
Map.Entry::getKey,
v -> v.getValue().getItemStack()));
}
/**
* returns the associated itemstack with the item key, use for finding without namespace
* @param registryName
* @return
*/
public ItemStack getOrNull(String registryName) {
return itemRegistry.get(registryName(registryName)).getItemStack().clone();
}
/**
* returns the associated itemstack with the item key, use for finding with namespace
* @param registryName
* @return
*/
public ItemStack getOrNullNamespace(String registryName) {
return itemRegistry.get(registryName).getItemStack().clone();
}
/**
* returns the associated IWarItem with the item key, use for finding with namespace
* @param registryName
* @return
*/
public IWarItem getWarItem(String registryName) {
return itemRegistry.get(registryName);
}
}