fixing in custom item manager
This commit is contained in:
parent
938aa316ec
commit
ff2aec18c1
7 changed files with 35 additions and 57 deletions
|
@ -6,7 +6,6 @@ import me.night.nullvalkyrie.database.NPCDataManager;
|
||||||
import me.night.nullvalkyrie.discord.DiscordClientManager;
|
import me.night.nullvalkyrie.discord.DiscordClientManager;
|
||||||
import me.night.nullvalkyrie.enchantments.EnchantmentManager;
|
import me.night.nullvalkyrie.enchantments.EnchantmentManager;
|
||||||
import me.night.nullvalkyrie.events.*;
|
import me.night.nullvalkyrie.events.*;
|
||||||
import me.night.nullvalkyrie.items.CustomItemManager;
|
|
||||||
import me.night.nullvalkyrie.npc.*;
|
import me.night.nullvalkyrie.npc.*;
|
||||||
import me.night.nullvalkyrie.ui.ScoreboardListener;
|
import me.night.nullvalkyrie.ui.ScoreboardListener;
|
||||||
import me.night.nullvalkyrie.util.*;
|
import me.night.nullvalkyrie.util.*;
|
||||||
|
|
|
@ -24,12 +24,10 @@ public class MinerCommand extends Command {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(CommandSender sender, String[] args) {
|
public void onCommand(CommandSender sender, String[] args) {
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player player) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
Player player = (Player) sender;
|
|
||||||
new MinerGUI(player);
|
new MinerGUI(player);
|
||||||
int seconds = (int) (new Date().getTime() - MinerDataManager.getLastClaim(1)) / 1000;
|
int seconds = (int) (new Date().getTime() - MinerDataManager.getLastClaim(1)) / 1000;
|
||||||
System.out.println("Seconds: " + seconds);
|
|
||||||
generate(50, seconds);
|
generate(50, seconds);
|
||||||
} else if (args[0].equalsIgnoreCase("new")) {
|
} else if (args[0].equalsIgnoreCase("new")) {
|
||||||
String name = args[1];
|
String name = args[1];
|
||||||
|
@ -41,7 +39,7 @@ public class MinerCommand extends Command {
|
||||||
} else if (args[0].equalsIgnoreCase("claim")) {
|
} else if (args[0].equalsIgnoreCase("claim")) {
|
||||||
String minerIndex = args[1];
|
String minerIndex = args[1];
|
||||||
MinerDataManager.setLastClaim(Long.parseLong(minerIndex));
|
MinerDataManager.setLastClaim(Long.parseLong(minerIndex));
|
||||||
System.out.println("Done");
|
player.sendMessage("Claimed");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ import java.util.List;
|
||||||
|
|
||||||
public class ShopCommand extends Command {
|
public class ShopCommand extends Command {
|
||||||
private final FileConfiguration file = CustomItemManager.loadConfig("shop.yml");
|
private final FileConfiguration file = CustomItemManager.loadConfig("shop.yml");
|
||||||
private Inventory inv;
|
|
||||||
|
|
||||||
public ShopCommand() {
|
public ShopCommand() {
|
||||||
super("7elven",
|
super("7elven",
|
||||||
|
@ -26,10 +25,10 @@ public class ShopCommand extends Command {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCommand(CommandSender sender, String[] args) {
|
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;
|
int counter = 0;
|
||||||
for (String c : file.getKeys(false)) {
|
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();
|
ItemMeta itemMeta = item.getItemMeta();
|
||||||
List<String> lore = itemMeta.getLore();
|
List<String> lore = itemMeta.getLore();
|
||||||
lore.add("Price (BIN): " + file.getString(c + ".price"));
|
lore.add("Price (BIN): " + file.getString(c + ".price"));
|
||||||
|
|
|
@ -13,13 +13,7 @@ import java.util.*;
|
||||||
public class UtilCommand extends Command {
|
public class UtilCommand extends Command {
|
||||||
|
|
||||||
public UtilCommand() {
|
public UtilCommand() {
|
||||||
super(
|
super("util", new String[]{}, "Give you a tool", "");
|
||||||
"util",
|
|
||||||
new String[]{},
|
|
||||||
"Give you a tool",
|
|
||||||
""
|
|
||||||
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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()) {
|
if (item.hasItemMeta()) {
|
||||||
player.getInventory().addItem(item);
|
player.getInventory().addItem(item);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -296,8 +296,8 @@ public class CustomItemEvents implements Listener {
|
||||||
bread.addIngredient(new ItemStack(Material.EMERALD, 10));
|
bread.addIngredient(new ItemStack(Material.EMERALD, 10));
|
||||||
recipes.add(bread);
|
recipes.add(bread);
|
||||||
|
|
||||||
MerchantRecipe tntStick = new MerchantRecipe(CustomItemManager.getItem("Terminator"), 10);
|
MerchantRecipe tntStick = new MerchantRecipe(CustomItemManager.produceItem("Terminator"), 10);
|
||||||
tntStick.addIngredient(CustomItemManager.getItem("Widow Sword"));
|
tntStick.addIngredient(CustomItemManager.produceItem("Widow Sword"));
|
||||||
recipes.add(tntStick);
|
recipes.add(tntStick);
|
||||||
Merchant merchant = Bukkit.createMerchant("Exchange here");
|
Merchant merchant = Bukkit.createMerchant("Exchange here");
|
||||||
merchant.setRecipes(recipes);
|
merchant.setRecipes(recipes);
|
||||||
|
|
|
@ -22,51 +22,42 @@ import java.util.*;
|
||||||
|
|
||||||
import static me.night.nullvalkyrie.database.CustomWeaponsDataManager.getWeapon;
|
import static me.night.nullvalkyrie.database.CustomWeaponsDataManager.getWeapon;
|
||||||
|
|
||||||
|
|
||||||
public class CustomItemManager {
|
public class CustomItemManager {
|
||||||
private static final HashMap<String, ItemStack> weapons = new HashMap<>();
|
|
||||||
public static HashMap<String, NamespacedKey> keys = 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) {
|
public static ItemStack produceItem(String itemName) {
|
||||||
HashMap<String, Object> weapon = getWeapon(itemName);
|
HashMap<String, Object> weapon = getWeapon(itemName);
|
||||||
|
|
||||||
ItemStack item = new ItemStack((Material) weapon.get("Material"));
|
ItemStack item = new ItemStack((Material) weapon.get("Material"));
|
||||||
List<String> properties = new ArrayList<>();
|
List<String> propertiesList = new ArrayList<>();
|
||||||
List<String> itemAbility = new ArrayList<>();
|
List<String> itemAbility = new ArrayList<>();
|
||||||
HashMap<String, Object> enchants = (HashMap<String, Object>) weapon.get("Enchants");
|
HashMap<String, Object> enchants = (HashMap<String, Object>) weapon.get("Enchants");
|
||||||
HashMap<String, Object> attributes = (HashMap<String, Object>) weapon.get("Attributes");
|
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));
|
item.addUnsafeEnchantment(Enchantment.getByKey(NamespacedKey.minecraft(enchant)), (Integer) enchants.get(enchant));
|
||||||
}
|
HashMap<String, Object> lore = (HashMap<String, Object>) weapon.get("Lore");
|
||||||
HashMap<String, Object> lo = (HashMap<String, Object>) weapon.get("Lore");
|
HashMap<String, Object> ability = (HashMap<String, Object>) lore.get("Ability");
|
||||||
HashMap<String, Object> abi = (HashMap<String, Object>) lo.get("Ability");
|
HashMap<String, Object> properties = (HashMap<String, Object>) lore.get("Properties");
|
||||||
HashMap<String, Object> prob = (HashMap<String, Object>) lo.get("Properties");
|
for (String p : properties.keySet())
|
||||||
for (String p : prob.keySet())
|
if ((int) properties.get(p) > 0)
|
||||||
if ((int) prob.get(p) > 0)
|
propertiesList.add(ChatColor.GRAY + Util.capitalize(p) + ": " + ChatColor.RED + "+" + properties.get(p));
|
||||||
properties.add(ChatColor.GRAY + Util.capitalize(p) + ": " + ChatColor.RED + "+" + prob.get(p));
|
itemAbility.add(ChatColor.GOLD + "Item Ability: " + ability.get("Name"));
|
||||||
itemAbility.add(ChatColor.GOLD + "Item Ability: " + abi.get("Name"));
|
for (String line : (List<String>) ability.get("Details"))
|
||||||
for (String line : (List<String>) abi.get("Details"))
|
|
||||||
itemAbility.add(ChatColor.GRAY + line);
|
itemAbility.add(ChatColor.GRAY + line);
|
||||||
//recipe
|
//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> lore = new ArrayList<>();
|
ArrayList<String> loreList = new ArrayList<>();
|
||||||
lore.addAll(properties);
|
loreList.addAll(propertiesList);
|
||||||
lore.add("");
|
loreList.add("");
|
||||||
ArrayList<String> enchantmentList = new ArrayList<>();
|
ArrayList<String> enchantmentList = new ArrayList<>();
|
||||||
for (Enchantment enchantment : item.getEnchantments().keySet()) {
|
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();
|
StringBuilder builder = new StringBuilder();
|
||||||
for (String strings : splitted) {
|
for (String strings : split) {
|
||||||
String formatted = Util.capitalize(strings);
|
String formatted = Util.capitalize(strings);
|
||||||
if (splitted.size() > 1) {
|
if (split.size() > 1) {
|
||||||
if (strings.equals(splitted.get(splitted.size() - 1))) builder.append(formatted);
|
if (strings.equals(split.get(split.size() - 1))) builder.append(formatted);
|
||||||
else {
|
else {
|
||||||
builder.append(formatted);
|
builder.append(formatted);
|
||||||
builder.append(" ");
|
builder.append(" ");
|
||||||
|
@ -75,12 +66,12 @@ public class CustomItemManager {
|
||||||
}
|
}
|
||||||
enchantmentList.add(builder + " " + item.getEnchantmentLevel(enchantment));
|
enchantmentList.add(builder + " " + item.getEnchantmentLevel(enchantment));
|
||||||
}
|
}
|
||||||
lore.add(ChatColor.BLUE + String.join(", ", enchantmentList));
|
loreList.add(ChatColor.BLUE + String.join(", ", enchantmentList));
|
||||||
lore.add("");
|
loreList.add("");
|
||||||
lore.addAll(itemAbility);
|
loreList.addAll(itemAbility);
|
||||||
lore.add("");
|
loreList.add("");
|
||||||
lore.add(Rarity.getRarity((String) weapon.get("Rarity")).getDisplay());
|
loreList.add(Rarity.getRarity((String) weapon.get("Rarity")).getDisplay());
|
||||||
itemMeta.setLore(lore);
|
itemMeta.setLore(loreList);
|
||||||
for (String attribute : attributes.keySet()) {
|
for (String attribute : attributes.keySet()) {
|
||||||
if (attribute.equals("damage")) {
|
if (attribute.equals("damage")) {
|
||||||
AttributeModifier p = new AttributeModifier(UUID.randomUUID(), "generic.attackDamage", (Double) attributes.get(attribute), AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.HAND);
|
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) {
|
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()) {
|
if (!f.exists()) {
|
||||||
try {
|
try {
|
||||||
f.createNewFile();
|
f.createNewFile();
|
||||||
|
@ -133,13 +124,10 @@ public class CustomItemManager {
|
||||||
return YamlConfiguration.loadConfiguration(f);
|
return YamlConfiguration.loadConfiguration(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack getItem(String name) {
|
|
||||||
return weapons.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void updateYamlFilesToPlugin(String path) {
|
public static void updateYamlFilesToPlugin(String path) {
|
||||||
File file = new File(main.getDataFolder(), path);
|
File file = new File(Main.getPlugin(Main.class).getDataFolder(), path);
|
||||||
if (!file.exists()) main.saveResource(path, true);
|
if (!file.exists()) Main.getPlugin(Main.class).saveResource(path, true);
|
||||||
else main.saveResource(path, true);
|
else Main.getPlugin(Main.class).saveResource(path, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue