enchantment manager

This commit is contained in:
NK 2022-12-19 20:27:16 +00:00
parent c89d48910c
commit 0f39c1bc73
11 changed files with 263 additions and 229 deletions

View file

@ -6,7 +6,7 @@ import me.night.nullvalkyrie.tasks.AlwaysDayTask;
import me.night.nullvalkyrie.ui.inventory.InventoryListener; import me.night.nullvalkyrie.ui.inventory.InventoryListener;
import me.night.nullvalkyrie.database.NPCDataManager; 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.util.enchantments.EnchantmentManager;
import me.night.nullvalkyrie.ui.player.ScoreboardListener; import me.night.nullvalkyrie.ui.player.ScoreboardListener;
import me.night.nullvalkyrie.util.*; import me.night.nullvalkyrie.util.*;
import me.night.nullvalkyrie.commands.*; import me.night.nullvalkyrie.commands.*;

View file

@ -1,7 +1,7 @@
package me.night.nullvalkyrie.commands; package me.night.nullvalkyrie.commands;
import me.night.nullvalkyrie.database.CustomWeaponsDataManager; import me.night.nullvalkyrie.database.CustomWeaponsDataManager;
import me.night.nullvalkyrie.items.CustomItemManager; import me.night.nullvalkyrie.entities.items.CustomItemManager;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View file

@ -1,7 +1,7 @@
package me.night.nullvalkyrie.commands; package me.night.nullvalkyrie.commands;
import me.night.nullvalkyrie.database.CustomWeaponsDataManager; import me.night.nullvalkyrie.database.CustomWeaponsDataManager;
import me.night.nullvalkyrie.items.CustomItemManager; import me.night.nullvalkyrie.entities.items.CustomItemManager;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View file

@ -1,4 +1,4 @@
package me.night.nullvalkyrie.items; package me.night.nullvalkyrie.entities.items;
import me.night.nullvalkyrie.Main; import me.night.nullvalkyrie.Main;
import me.night.nullvalkyrie.enums.Rarity; import me.night.nullvalkyrie.enums.Rarity;
@ -38,11 +38,13 @@ public class CustomItemManager {
for (String p : properties.keySet()) for (String p : properties.keySet())
if ((int) properties.get(p) > 0) if ((int) properties.get(p) > 0)
propertiesList.add(ChatColor.GRAY + Util.capitalize(p) + ": " + ChatColor.RED + "+" + properties.get(p)); propertiesList.add(ChatColor.GRAY + Util.capitalize(p) + ": " + ChatColor.RED + "+" + properties.get(p));
if (ability.get("Name") != null) {
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);
}
ItemMeta itemMeta = item.getItemMeta(); ItemMeta itemMeta = item.getItemMeta();
if (itemMeta == null) return item;
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);

View file

@ -1,4 +1,4 @@
package me.night.nullvalkyrie.items; package me.night.nullvalkyrie.entities.items;
import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ArrayListMultimap;
import org.bukkit.Material; import org.bukkit.Material;

View file

@ -0,0 +1,34 @@
package me.night.nullvalkyrie.enums;
import me.night.nullvalkyrie.util.enchantments.EnchantmentManager;
import org.bukkit.enchantments.Enchantment;
public enum Enchantments {
THUNDERBOLT("thunderbolt", "ThunderBolt", 5),
SMELTING_TOUCH("smelting-touch", "Smelting Touch", 1);
public final String namespacekey;
public final String name;
public final int maxLevel;
Enchantments(String namespacekey, String name, int maxLevel) {
this.namespacekey = namespacekey;
this.name = name;
this.maxLevel = maxLevel;
}
public String getNamespacekey() {
return namespacekey;
}
public String getName() {
return name;
}
public int getMaxLevel() {
return maxLevel;
}
public Enchantment getEnchant() {
return EnchantmentManager.enchants.get(this.ordinal());
}
}

View file

@ -5,8 +5,8 @@ import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.BlockPosition; import com.comphenix.protocol.wrappers.BlockPosition;
import me.night.nullvalkyrie.items.CustomItemManager; import me.night.nullvalkyrie.entities.items.CustomItemManager;
import me.night.nullvalkyrie.items.Pickaxe; import me.night.nullvalkyrie.entities.items.Pickaxe;
import me.night.nullvalkyrie.enums.Rarity; import me.night.nullvalkyrie.enums.Rarity;
import me.night.nullvalkyrie.Main; import me.night.nullvalkyrie.Main;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;

View file

@ -1,7 +1,7 @@
package me.night.nullvalkyrie.ui.inventory; package me.night.nullvalkyrie.ui.inventory;
import me.night.nullvalkyrie.database.ShopDataManager; import me.night.nullvalkyrie.database.ShopDataManager;
import me.night.nullvalkyrie.items.CustomItemManager; import me.night.nullvalkyrie.entities.items.CustomItemManager;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View file

@ -1,6 +1,6 @@
package me.night.nullvalkyrie.util; package me.night.nullvalkyrie.util;
import static me.night.nullvalkyrie.items.CustomItemManager.updateYamlFilesToPlugin; import static me.night.nullvalkyrie.entities.items.CustomItemManager.updateYamlFilesToPlugin;
public class FileManager { public class FileManager {
public FileManager() { public FileManager() {

View file

@ -1,4 +1,4 @@
package me.night.nullvalkyrie.enchantments; package me.night.nullvalkyrie.util.enchantments;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;

View file

@ -1,5 +1,6 @@
package me.night.nullvalkyrie.enchantments; package me.night.nullvalkyrie.util.enchantments;
import me.night.nullvalkyrie.enums.Enchantments;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@ -8,16 +9,13 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
public class EnchantmentManager { public class EnchantmentManager {
public static final Enchantment ThunderBolt = new CustomEnchantment("thunderbolt", "ThunderBolt", 5); public static List<Enchantment> enchants = new ArrayList<>();
public static final Enchantment SmeltingTouch = new CustomEnchantment("smelting-touch", "Smelting Touch", 1);
public static void register() { public static void register() {
List<Enchantment> enchants = new ArrayList<>();
enchants.add(ThunderBolt);
enchants.add(SmeltingTouch);
List<Boolean> registeredList = new ArrayList<>(); List<Boolean> registeredList = new ArrayList<>();
for (Enchantment enchant : enchants) { for (Enchantments enchantment : Enchantments.values()) {
registeredList.add(Arrays.stream(Enchantment.values()).toList().contains(enchant)); Enchantment en = new CustomEnchantment(enchantment.getNamespacekey(), enchantment.getName(), enchantment.getMaxLevel());
enchants.add(en);
registeredList.add(Arrays.stream(Enchantment.values()).toList().contains(en));
} }
for (int counter = 0; counter < registeredList.size(); counter++) { for (int counter = 0; counter < registeredList.size(); counter++) {
if (!registeredList.get(counter)) registerEnchantment(enchants.get(counter)); if (!registeredList.get(counter)) registerEnchantment(enchants.get(counter));