edit on custom item manager to accept pdc and recipes

This commit is contained in:
NK 2022-12-06 12:33:46 +00:00
parent a1ac430d0e
commit d763a05158
5 changed files with 49 additions and 27 deletions

View file

@ -1,6 +1,5 @@
package me.night.nullvalkyrie.commands;
import me.night.nullvalkyrie.database.UserDataManager;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -15,7 +14,6 @@ public class BetaCommand extends Command {
@Override
public void onCommand(CommandSender sender, String[] args) {
if (sender instanceof Player player) {
UserDataManager.updateUserBank(player.getUniqueId().toString(), 10);
}
}

View file

@ -11,6 +11,7 @@ import java.util.List;
public class CustomWeaponsDataManager {
public static HashMap<String, Object> getWeapon(String itemName) {
HashMap<String, Object> item = new HashMap<>();
try (MongoCursor<Document> cursor = DatabaseManager.getCustomWeaponsDB().find(Filters.eq("Name", itemName)).cursor()) {
@ -37,6 +38,21 @@ public class CustomWeaponsDataManager {
HashMap<String, Object> attr = new HashMap<>();
for (String a : enchants.keySet()) ench.put(a, enchants.get(a));
for (String a : attributes.keySet()) attr.put(a, attributes.get(a));
Document pdc = (Document) doc.get("PDC");
HashMap<String, Object> pdcdata = new HashMap<>();
for (String i : pdc.keySet())
pdcdata.put(i, pdc.get(i));
Document recipe = (Document) doc.get("Recipes");
HashMap<String, Object> recipes = new HashMap<>();
Document ing = (Document) recipe.get("Ingredients");
HashMap<String, String> ingredients = new HashMap<>();
for (String i : ing.keySet())
ingredients.put(i, ing.getString(i));
List<String> shapes = new ArrayList<>();
if (recipe.get("Shapes") != null) for (String s : (List<String>) recipe.get("Shapes")) shapes.add(s);
recipes.put("Shape", shapes);
recipes.put("Amount", recipe.getInteger("Amount"));
recipes.put("Ingredients", ingredients);
item.put("Name", name);
item.put("Material", Material.matchMaterial(doc.getString("Material")));
item.put("Type", doc.getString("Type"));
@ -44,6 +60,8 @@ public class CustomWeaponsDataManager {
item.put("Lore", lores);
item.put("Enchants", ench);
item.put("Attributes", attr);
item.put("PDC", pdcdata);
item.put("Recipes", recipes);
}
return item;
}

View file

@ -96,7 +96,7 @@ public class CustomItemEvents implements Listener {
NamespacedKey ammoKey = CustomItemManager.keys.get(name + ".ammo");
int ammo = container.get(ammoKey, PersistentDataType.INTEGER);
container.set(ammoKey, PersistentDataType.INTEGER, ammo - 1);
int max = container.get(CustomItemManager.keys.get(name + ".maxload"), PersistentDataType.INTEGER);
int max = container.get(CustomItemManager.keys.get(name + ".max"), PersistentDataType.INTEGER);
weapon.setItemMeta(weaponMeta);
e.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', "&6AK-47 ( " + (ammo - 1) + "/ " + max + " )")));

View file

@ -42,7 +42,7 @@ public class ServerEvents implements Listener {
@EventHandler
public void onClickHologram(InteractHologramEvent e) {
if (e.getHologram().getCustomName().equals(ChatColor.GOLD + "Click me to change!!!")) {
System.out.println(true);
// TODO: change hologram things
}
}
}

View file

@ -3,6 +3,7 @@ package me.night.nullvalkyrie.items;
import me.night.nullvalkyrie.Main;
import me.night.nullvalkyrie.enums.Rarity;
import me.night.nullvalkyrie.util.Util;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
@ -12,7 +13,10 @@ import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import java.io.File;
import java.util.*;
@ -40,10 +44,11 @@ public class CustomItemManager {
itemAbility.add(ChatColor.GOLD + "Item Ability: " + ability.get("Name"));
for (String line : (List<String>) ability.get("Details"))
itemAbility.add(ChatColor.GRAY + line);
//recipe
ItemMeta itemMeta = item.getItemMeta();
itemMeta.setDisplayName(Rarity.getRarity((String) weapon.get("Rarity")).getColor() + weapon.get("Name"));
itemMeta.setUnbreakable(true);
ArrayList<String> loreList = new ArrayList<>();
loreList.addAll(propertiesList);
loreList.add("");
@ -79,32 +84,33 @@ public class CustomItemManager {
}
}
itemMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_UNBREAKABLE, ItemFlag.HIDE_ENCHANTS);
// for (String key : fileConfig.getKeys(true)) {
// if (key.startsWith("pdc.")) {
// String property = Arrays.asList(key.split("\\.")).get(1);
// if (property.equals("ammo")) {
// PersistentDataContainer container = itemMeta.getPersistentDataContainer();
// NamespacedKey key1 = new NamespacedKey(main, "ammo");
// keys.put(Rarity.getRarity(fileConfig.getString("rarity")).getColor() + fileConfig.getString("name") + "." + property, key1);
// container.set(key1, PersistentDataType.INTEGER, fileConfig.getInt(key));
// } else if (property.equals("maxload")) {
// PersistentDataContainer container = itemMeta.getPersistentDataContainer();
// NamespacedKey key2 = new NamespacedKey(main, "maxload");
// keys.put(Rarity.getRarity(fileConfig.getString("rarity")).getColor() + fileConfig.getString("name") + "." + property, key2);
// container.set(key2, PersistentDataType.INTEGER, fileConfig.getInt(key));
// }
// }
// }
HashMap<String, Object> pdcdata = (HashMap<String, Object>) weapon.get("PDC");
for (String key : pdcdata.keySet()) {
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
NamespacedKey key1 = new NamespacedKey(Main.getPlugin(Main.class), key);
keys.put(Rarity.getRarity((String) weapon.get("Rarity")).getColor() + weapon.get("Name") + "." + key, key1);
container.set(key1, PersistentDataType.INTEGER, (int) pdcdata.get(key));
}
item.setItemMeta(itemMeta);
HashMap<String, Object> recipes = (HashMap<String, Object>) weapon.get("Recipes");
List<String> shapes = (List<String>) recipes.get("Shape");
HashMap<String, String> ind = (HashMap<String, String>) recipes.get("Ingredients");
HashMap<Character, Material> indgredients = new HashMap<>();
for (String i : ind.keySet())
indgredients.put(i.charAt(0), Material.matchMaterial(ind.get(i)));
setItemRecipe((String) weapon.get("Name"), item, shapes, indgredients, (int) recipes.get("Amount"));
return item;
}
public static void setItemRecipe(NamespacedKey key, ItemStack i, int ingredient, String shape1, String shape2, String shape3, List<Material> ingredients) {
// ShapedRecipe wither_sword_recipe = new ShapedRecipe(new NamespacedKey(main, "widow_sword"), widow_sword);
// wither_sword_recipe.shape(" A ", " A "," B ");
// wither_sword_recipe.setIngredient('A', Material.IRON_INGOT);
// wither_sword_recipe.setIngredient('B', Material.STICK);
// Bukkit.addRecipe(wither_sword_recipe);
public static void setItemRecipe(String key, ItemStack i, List<String> shapes, HashMap<Character, Material> ingredients, int amount) {
NamespacedKey nsk = new NamespacedKey(Main.getPlugin(Main.class), key.replaceAll("\\s", ""));
ShapedRecipe recipe = new ShapedRecipe(nsk, i);
recipe.shape(shapes.get(0), shapes.get(1), shapes.get(2));
List<Character> abcs = List.of('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I');
for (int ei = 0; ei < amount; ei++)
recipe.setIngredient(abcs.get(ei), ingredients.get(abcs.get(ei)));
if (Bukkit.getRecipe(nsk) != null) Bukkit.removeRecipe(nsk);
Bukkit.addRecipe(recipe);
}
public static void updateYamlFilesToPlugin(String path) {