fixing in custom item manager

This commit is contained in:
NK 2022-11-30 12:40:29 +00:00
parent 938aa316ec
commit ff2aec18c1
7 changed files with 35 additions and 57 deletions

View file

@ -6,7 +6,6 @@ import me.night.nullvalkyrie.database.NPCDataManager;
import me.night.nullvalkyrie.discord.DiscordClientManager;
import me.night.nullvalkyrie.enchantments.EnchantmentManager;
import me.night.nullvalkyrie.events.*;
import me.night.nullvalkyrie.items.CustomItemManager;
import me.night.nullvalkyrie.npc.*;
import me.night.nullvalkyrie.ui.ScoreboardListener;
import me.night.nullvalkyrie.util.*;

View file

@ -24,12 +24,10 @@ public class MinerCommand extends Command {
@Override
public void onCommand(CommandSender sender, String[] args) {
if (sender instanceof Player) {
if (sender instanceof Player player) {
if (args.length == 0) {
Player player = (Player) sender;
new MinerGUI(player);
int seconds = (int) (new Date().getTime() - MinerDataManager.getLastClaim(1)) / 1000;
System.out.println("Seconds: " + seconds);
generate(50, seconds);
} else if (args[0].equalsIgnoreCase("new")) {
String name = args[1];
@ -41,7 +39,7 @@ public class MinerCommand extends Command {
} else if (args[0].equalsIgnoreCase("claim")) {
String minerIndex = args[1];
MinerDataManager.setLastClaim(Long.parseLong(minerIndex));
System.out.println("Done");
player.sendMessage("Claimed");
}
}

View file

@ -14,7 +14,6 @@ import java.util.List;
public class ShopCommand extends Command {
private final FileConfiguration file = CustomItemManager.loadConfig("shop.yml");
private Inventory inv;
public ShopCommand() {
super("7elven",
@ -26,10 +25,10 @@ public class ShopCommand extends Command {
@Override
public void onCommand(CommandSender sender, String[] args) {
inv = Bukkit.createInventory(null, 45, ChatColor.GREEN + "7-Eleven 24/7");
Inventory inv = Bukkit.createInventory(null, 45, ChatColor.GREEN + "7-Eleven 24/7");
int counter = 0;
for (String c : file.getKeys(false)) {
ItemStack item = CustomItemManager.getItem(file.getString(c + ".name")).clone();
ItemStack item = CustomItemManager.produceItem(file.getString(c + ".name")).clone();
ItemMeta itemMeta = item.getItemMeta();
List<String> lore = itemMeta.getLore();
lore.add("Price (BIN): " + file.getString(c + ".price"));

View file

@ -13,13 +13,7 @@ import java.util.*;
public class UtilCommand extends Command {
public UtilCommand() {
super(
"util",
new String[]{},
"Give you a tool",
""
);
super("util", new String[]{}, "Give you a tool", "");
}
@Override
@ -36,7 +30,7 @@ public class UtilCommand extends Command {
}
}
ItemStack item = CustomItemManager.getItem(s.toString());
ItemStack item = CustomItemManager.produceItem(s.toString());
if (item.hasItemMeta()) {
player.getInventory().addItem(item);
} else {

View file

@ -296,8 +296,8 @@ public class CustomItemEvents implements Listener {
bread.addIngredient(new ItemStack(Material.EMERALD, 10));
recipes.add(bread);
MerchantRecipe tntStick = new MerchantRecipe(CustomItemManager.getItem("Terminator"), 10);
tntStick.addIngredient(CustomItemManager.getItem("Widow Sword"));
MerchantRecipe tntStick = new MerchantRecipe(CustomItemManager.produceItem("Terminator"), 10);
tntStick.addIngredient(CustomItemManager.produceItem("Widow Sword"));
recipes.add(tntStick);
Merchant merchant = Bukkit.createMerchant("Exchange here");
merchant.setRecipes(recipes);

View file

@ -22,51 +22,42 @@ import java.util.*;
import static me.night.nullvalkyrie.database.CustomWeaponsDataManager.getWeapon;
public class CustomItemManager {
private static final HashMap<String, ItemStack> weapons = new HashMap<>();
public static HashMap<String, NamespacedKey> keys = new HashMap<>();
private static Main main;
public CustomItemManager(Main main) {
CustomItemManager.main = main;
}
public static ItemStack produceItem(String itemName) {
HashMap<String, Object> weapon = getWeapon(itemName);
ItemStack item = new ItemStack((Material) weapon.get("Material"));
List<String> properties = new ArrayList<>();
List<String> propertiesList = new ArrayList<>();
List<String> itemAbility = new ArrayList<>();
HashMap<String, Object> enchants = (HashMap<String, Object>) weapon.get("Enchants");
HashMap<String, Object> attributes = (HashMap<String, Object>) weapon.get("Attributes");
for (String enchant : enchants.keySet()) {
for (String enchant : enchants.keySet())
item.addUnsafeEnchantment(Enchantment.getByKey(NamespacedKey.minecraft(enchant)), (Integer) enchants.get(enchant));
}
HashMap<String, Object> lo = (HashMap<String, Object>) weapon.get("Lore");
HashMap<String, Object> abi = (HashMap<String, Object>) lo.get("Ability");
HashMap<String, Object> prob = (HashMap<String, Object>) lo.get("Properties");
for (String p : prob.keySet())
if ((int) prob.get(p) > 0)
properties.add(ChatColor.GRAY + Util.capitalize(p) + ": " + ChatColor.RED + "+" + prob.get(p));
itemAbility.add(ChatColor.GOLD + "Item Ability: " + abi.get("Name"));
for (String line : (List<String>) abi.get("Details"))
HashMap<String, Object> lore = (HashMap<String, Object>) weapon.get("Lore");
HashMap<String, Object> ability = (HashMap<String, Object>) lore.get("Ability");
HashMap<String, Object> properties = (HashMap<String, Object>) lore.get("Properties");
for (String p : properties.keySet())
if ((int) properties.get(p) > 0)
propertiesList.add(ChatColor.GRAY + Util.capitalize(p) + ": " + ChatColor.RED + "+" + properties.get(p));
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> lore = new ArrayList<>();
lore.addAll(properties);
lore.add("");
ArrayList<String> loreList = new ArrayList<>();
loreList.addAll(propertiesList);
loreList.add("");
ArrayList<String> enchantmentList = new ArrayList<>();
for (Enchantment enchantment : item.getEnchantments().keySet()) {
List<String> splitted = Arrays.asList(Arrays.asList(enchantment.getKey().toString().split(":")).get(1).split("_"));
List<String> split = Arrays.asList(Arrays.asList(enchantment.getKey().toString().split(":")).get(1).split("_"));
StringBuilder builder = new StringBuilder();
for (String strings : splitted) {
for (String strings : split) {
String formatted = Util.capitalize(strings);
if (splitted.size() > 1) {
if (strings.equals(splitted.get(splitted.size() - 1))) builder.append(formatted);
if (split.size() > 1) {
if (strings.equals(split.get(split.size() - 1))) builder.append(formatted);
else {
builder.append(formatted);
builder.append(" ");
@ -75,12 +66,12 @@ public class CustomItemManager {
}
enchantmentList.add(builder + " " + item.getEnchantmentLevel(enchantment));
}
lore.add(ChatColor.BLUE + String.join(", ", enchantmentList));
lore.add("");
lore.addAll(itemAbility);
lore.add("");
lore.add(Rarity.getRarity((String) weapon.get("Rarity")).getDisplay());
itemMeta.setLore(lore);
loreList.add(ChatColor.BLUE + String.join(", ", enchantmentList));
loreList.add("");
loreList.addAll(itemAbility);
loreList.add("");
loreList.add(Rarity.getRarity((String) weapon.get("Rarity")).getDisplay());
itemMeta.setLore(loreList);
for (String attribute : attributes.keySet()) {
if (attribute.equals("damage")) {
AttributeModifier p = new AttributeModifier(UUID.randomUUID(), "generic.attackDamage", (Double) attributes.get(attribute), AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.HAND);
@ -121,7 +112,7 @@ public class CustomItemManager {
}
public static YamlConfiguration loadConfig(String path) {
File f = new File(main.getDataFolder(), path);
File f = new File(Main.getPlugin(Main.class).getDataFolder(), path);
if (!f.exists()) {
try {
f.createNewFile();
@ -133,13 +124,10 @@ public class CustomItemManager {
return YamlConfiguration.loadConfiguration(f);
}
public static ItemStack getItem(String name) {
return weapons.get(name);
}
public static void updateYamlFilesToPlugin(String path) {
File file = new File(main.getDataFolder(), path);
if (!file.exists()) main.saveResource(path, true);
else main.saveResource(path, true);
File file = new File(Main.getPlugin(Main.class).getDataFolder(), path);
if (!file.exists()) Main.getPlugin(Main.class).saveResource(path, true);
else Main.getPlugin(Main.class).saveResource(path, true);
}
}