edit on custom item manager to accept pdc and recipes
This commit is contained in:
parent
a1ac430d0e
commit
d763a05158
5 changed files with 49 additions and 27 deletions
|
@ -1,6 +1,5 @@
|
||||||
package me.night.nullvalkyrie.commands;
|
package me.night.nullvalkyrie.commands;
|
||||||
|
|
||||||
import me.night.nullvalkyrie.database.UserDataManager;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@ -15,7 +14,6 @@ public class BetaCommand extends Command {
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(CommandSender sender, String[] args) {
|
public void onCommand(CommandSender sender, String[] args) {
|
||||||
if (sender instanceof Player player) {
|
if (sender instanceof Player player) {
|
||||||
UserDataManager.updateUserBank(player.getUniqueId().toString(), 10);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
public class CustomWeaponsDataManager {
|
public class CustomWeaponsDataManager {
|
||||||
|
|
||||||
public static HashMap<String, Object> getWeapon(String itemName) {
|
public static HashMap<String, Object> getWeapon(String itemName) {
|
||||||
HashMap<String, Object> item = new HashMap<>();
|
HashMap<String, Object> item = new HashMap<>();
|
||||||
try (MongoCursor<Document> cursor = DatabaseManager.getCustomWeaponsDB().find(Filters.eq("Name", itemName)).cursor()) {
|
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<>();
|
HashMap<String, Object> attr = new HashMap<>();
|
||||||
for (String a : enchants.keySet()) ench.put(a, enchants.get(a));
|
for (String a : enchants.keySet()) ench.put(a, enchants.get(a));
|
||||||
for (String a : attributes.keySet()) attr.put(a, attributes.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("Name", name);
|
||||||
item.put("Material", Material.matchMaterial(doc.getString("Material")));
|
item.put("Material", Material.matchMaterial(doc.getString("Material")));
|
||||||
item.put("Type", doc.getString("Type"));
|
item.put("Type", doc.getString("Type"));
|
||||||
|
@ -44,6 +60,8 @@ public class CustomWeaponsDataManager {
|
||||||
item.put("Lore", lores);
|
item.put("Lore", lores);
|
||||||
item.put("Enchants", ench);
|
item.put("Enchants", ench);
|
||||||
item.put("Attributes", attr);
|
item.put("Attributes", attr);
|
||||||
|
item.put("PDC", pdcdata);
|
||||||
|
item.put("Recipes", recipes);
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ public class CustomItemEvents implements Listener {
|
||||||
NamespacedKey ammoKey = CustomItemManager.keys.get(name + ".ammo");
|
NamespacedKey ammoKey = CustomItemManager.keys.get(name + ".ammo");
|
||||||
int ammo = container.get(ammoKey, PersistentDataType.INTEGER);
|
int ammo = container.get(ammoKey, PersistentDataType.INTEGER);
|
||||||
container.set(ammoKey, PersistentDataType.INTEGER, ammo - 1);
|
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);
|
weapon.setItemMeta(weaponMeta);
|
||||||
e.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', "&6AK-47 ( " + (ammo - 1) + "/ " + max + " )")));
|
e.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', "&6AK-47 ( " + (ammo - 1) + "/ " + max + " )")));
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class ServerEvents implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onClickHologram(InteractHologramEvent e) {
|
public void onClickHologram(InteractHologramEvent e) {
|
||||||
if (e.getHologram().getCustomName().equals(ChatColor.GOLD + "Click me to change!!!")) {
|
if (e.getHologram().getCustomName().equals(ChatColor.GOLD + "Click me to change!!!")) {
|
||||||
System.out.println(true);
|
// TODO: change hologram things
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package me.night.nullvalkyrie.items;
|
||||||
import me.night.nullvalkyrie.Main;
|
import me.night.nullvalkyrie.Main;
|
||||||
import me.night.nullvalkyrie.enums.Rarity;
|
import me.night.nullvalkyrie.enums.Rarity;
|
||||||
import me.night.nullvalkyrie.util.Util;
|
import me.night.nullvalkyrie.util.Util;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
|
@ -12,7 +13,10 @@ import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
import org.bukkit.inventory.ItemFlag;
|
import org.bukkit.inventory.ItemFlag;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.ShapedRecipe;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -40,10 +44,11 @@ public class CustomItemManager {
|
||||||
itemAbility.add(ChatColor.GOLD + "Item Ability: " + ability.get("Name"));
|
itemAbility.add(ChatColor.GOLD + "Item Ability: " + ability.get("Name"));
|
||||||
for (String line : (List<String>) ability.get("Details"))
|
for (String line : (List<String>) ability.get("Details"))
|
||||||
itemAbility.add(ChatColor.GRAY + line);
|
itemAbility.add(ChatColor.GRAY + line);
|
||||||
//recipe
|
|
||||||
ItemMeta itemMeta = item.getItemMeta();
|
ItemMeta itemMeta = item.getItemMeta();
|
||||||
itemMeta.setDisplayName(Rarity.getRarity((String) weapon.get("Rarity")).getColor() + weapon.get("Name"));
|
itemMeta.setDisplayName(Rarity.getRarity((String) weapon.get("Rarity")).getColor() + weapon.get("Name"));
|
||||||
itemMeta.setUnbreakable(true);
|
itemMeta.setUnbreakable(true);
|
||||||
|
|
||||||
ArrayList<String> loreList = new ArrayList<>();
|
ArrayList<String> loreList = new ArrayList<>();
|
||||||
loreList.addAll(propertiesList);
|
loreList.addAll(propertiesList);
|
||||||
loreList.add("");
|
loreList.add("");
|
||||||
|
@ -79,32 +84,33 @@ public class CustomItemManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
itemMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_UNBREAKABLE, ItemFlag.HIDE_ENCHANTS);
|
itemMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_UNBREAKABLE, ItemFlag.HIDE_ENCHANTS);
|
||||||
// for (String key : fileConfig.getKeys(true)) {
|
HashMap<String, Object> pdcdata = (HashMap<String, Object>) weapon.get("PDC");
|
||||||
// if (key.startsWith("pdc.")) {
|
for (String key : pdcdata.keySet()) {
|
||||||
// String property = Arrays.asList(key.split("\\.")).get(1);
|
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
|
||||||
// if (property.equals("ammo")) {
|
NamespacedKey key1 = new NamespacedKey(Main.getPlugin(Main.class), key);
|
||||||
// PersistentDataContainer container = itemMeta.getPersistentDataContainer();
|
keys.put(Rarity.getRarity((String) weapon.get("Rarity")).getColor() + weapon.get("Name") + "." + key, key1);
|
||||||
// NamespacedKey key1 = new NamespacedKey(main, "ammo");
|
container.set(key1, PersistentDataType.INTEGER, (int) pdcdata.get(key));
|
||||||
// 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));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
item.setItemMeta(itemMeta);
|
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;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setItemRecipe(NamespacedKey key, ItemStack i, int ingredient, String shape1, String shape2, String shape3, List<Material> ingredients) {
|
public static void setItemRecipe(String key, ItemStack i, List<String> shapes, HashMap<Character, Material> ingredients, int amount) {
|
||||||
// ShapedRecipe wither_sword_recipe = new ShapedRecipe(new NamespacedKey(main, "widow_sword"), widow_sword);
|
NamespacedKey nsk = new NamespacedKey(Main.getPlugin(Main.class), key.replaceAll("\\s", ""));
|
||||||
// wither_sword_recipe.shape(" A ", " A "," B ");
|
ShapedRecipe recipe = new ShapedRecipe(nsk, i);
|
||||||
// wither_sword_recipe.setIngredient('A', Material.IRON_INGOT);
|
recipe.shape(shapes.get(0), shapes.get(1), shapes.get(2));
|
||||||
// wither_sword_recipe.setIngredient('B', Material.STICK);
|
List<Character> abcs = List.of('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I');
|
||||||
// Bukkit.addRecipe(wither_sword_recipe);
|
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) {
|
public static void updateYamlFilesToPlugin(String path) {
|
||||||
|
|
Loading…
Reference in a new issue