diff --git a/paper/src/main/java/com/badbones69/crazyenchantments/paper/api/CrazyManager.java b/paper/src/main/java/com/badbones69/crazyenchantments/paper/api/CrazyManager.java index 9d7a2944..e6a4b48e 100644 --- a/paper/src/main/java/com/badbones69/crazyenchantments/paper/api/CrazyManager.java +++ b/paper/src/main/java/com/badbones69/crazyenchantments/paper/api/CrazyManager.java @@ -2,6 +2,7 @@ import com.badbones69.crazyenchantments.paper.CrazyEnchantments; import com.badbones69.crazyenchantments.paper.Methods; +import com.badbones69.crazyenchantments.paper.Starter; import com.badbones69.crazyenchantments.paper.api.FileManager.Files; import com.badbones69.crazyenchantments.paper.api.enums.CEnchantments; import com.badbones69.crazyenchantments.paper.api.enums.Dust; @@ -22,8 +23,8 @@ import com.badbones69.crazyenchantments.paper.listeners.ScrollListener; import com.badbones69.crazyenchantments.paper.listeners.SlotCrystalListener; import com.badbones69.crazyenchantments.paper.utilities.WingsUtils; -import com.badbones69.crazyenchantments.paper.utilities.misc.ColorUtils; -import com.badbones69.crazyenchantments.paper.utilities.misc.NumberUtils; +import com.badbones69.crazyenchantments.paper.api.utils.ColorUtils; +import com.badbones69.crazyenchantments.paper.api.utils.NumberUtils; import com.google.gson.Gson; import de.tr7zw.changeme.nbtapi.NBTItem; import net.kyori.adventure.text.Component; @@ -121,18 +122,18 @@ public void load() { FileConfiguration blocks = Files.BLOCKLIST.getFile(); FileConfiguration heads = Files.HEADMAP.getFile(); - blockList.clear(); - headMap.clear(); - gkitz.clear(); - enchantmentBookSettings.getRegisteredEnchantments().clear(); - enchantmentBookSettings.getCategories().clear(); + this.blockList.clear(); + this.headMap.clear(); + this.gkitz.clear(); + this.enchantmentBookSettings.getRegisteredEnchantments().clear(); + this.enchantmentBookSettings.getCategories().clear(); - plugin.getStarter().getPluginSupport().updateHooks(); + this.starter.getPluginSupport().updateHooks(); // Check if we should patch player health. - boolean playerHealthPatch = config.getBoolean("Settings.Reset-Players-Max-Health"); + boolean playerHealthPatch = config.getBoolean("Settings.Reset-Players-Max-Health", true); - plugin.getServer().getOnlinePlayers().forEach(player -> { + this.plugin.getServer().getOnlinePlayers().forEach(player -> { // Load our players. loadCEPlayer(player); @@ -144,7 +145,7 @@ public void load() { if (playerHealthPatch) player.getAttribute(genericAttribute).setBaseValue(baseValue); // Loop through all players & back them up. - plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, task -> + this.plugin.getServer().getScheduler().runTaskTimerAsynchronously(this.plugin, task -> getCEPlayers().forEach(name -> backupCEPlayer(name.getPlayer())), 5 * 20 * 60, 5 * 20 * 60); }); @@ -155,36 +156,39 @@ public void load() { // Loop through block list. blocks.getStringList("Block-List").forEach(id -> { try { - blockList.add(new ItemBuilder().setMaterial(id).getMaterial()); + this.blockList.add(new ItemBuilder().setMaterial(id).getMaterial()); } catch (Exception ignored) {} }); ConfigurationSection headSec = heads.getConfigurationSection("HeadOdds"); - headSec.getKeys(false).forEach(id -> { - try { - Material mat = new ItemBuilder().setMaterial(id).getMaterial(); - headMap.put(mat, headSec.getDouble(id)); - } catch (Exception ignored) {} - }); + + if (headSec != null) { + headSec.getKeys(false).forEach(id -> { + try { + Material mat = new ItemBuilder().setMaterial(id).getMaterial(); + this.headMap.put(mat, headSec.getDouble(id)); + } catch (Exception ignored) {} + }); + } // Loads the info menu manager and the enchantment types. - infoMenuManager.load(); + this.infoMenuManager.load(); Scrolls.getWhiteScrollProtectionName(); - enchantmentBookSettings.setEnchantmentBook(new ItemBuilder().setMaterial(Objects.requireNonNull(config.getString("Settings.Enchantment-Book-Item")))); - useUnsafeEnchantments = config.getBoolean("Settings.EnchantmentOptions.UnSafe-Enchantments"); - maxEnchantmentCheck = config.getBoolean("Settings.EnchantmentOptions.MaxAmountOfEnchantmentsToggle"); - checkVanillaLimit = config.getBoolean("Settings.EnchantmentOptions.IncludeVanillaEnchantments"); - gkitzToggle = !config.contains("Settings.GKitz.Enabled") || config.getBoolean("Settings.GKitz.Enabled"); - rageMaxLevel = config.contains("Settings.EnchantmentOptions.MaxRageLevel") ? config.getInt("Settings.EnchantmentOptions.MaxRageLevel") : 4; - breakRageOnDamage = !config.contains("Settings.EnchantmentOptions.Break-Rage-On-Damage") || config.getBoolean("Settings.EnchantmentOptions.Break-Rage-On-Damage"); - useRageBossBar = config.contains("Settings.EnchantmentOptions.Rage-Boss-Bar") && config.getBoolean("Settings.EnchantmentOptions.Rage-Boss-Bar"); - enchantStackedItems = config.contains("Settings.EnchantmentOptions.Enchant-Stacked-Items") && config.getBoolean("Settings.EnchantmentOptions.Enchant-Stacked-Items"); + this.enchantmentBookSettings.setEnchantmentBook(new ItemBuilder().setMaterial(config.getString("Settings.Enchantment-Book-Item", "BOOK"))); + this.useUnsafeEnchantments = config.getBoolean("Settings.EnchantmentOptions.UnSafe-Enchantments", true); + this.maxEnchantmentCheck = config.getBoolean("Settings.EnchantmentOptions.MaxAmountOfEnchantmentsToggle", true); + this.checkVanillaLimit = config.getBoolean("Settings.EnchantmentOptions.IncludeVanillaEnchantments", false); + this.gkitzToggle = !config.contains("Settings.GKitz.Enabled") || config.getBoolean("Settings.GKitz.Enabled", true); + this.rageMaxLevel = config.getInt("Settings.EnchantmentOptions.MaxRageLevel", 4); + this.breakRageOnDamage = !config.contains("Settings.EnchantmentOptions.Break-Rage-On-Damage") || config.getBoolean("Settings.EnchantmentOptions.Break-Rage-On-Damage"); + this.useRageBossBar = config.contains("Settings.EnchantmentOptions.Rage-Boss-Bar") && config.getBoolean("Settings.EnchantmentOptions.Rage-Boss-Bar"); + this.enchantStackedItems = config.contains("Settings.EnchantmentOptions.Enchant-Stacked-Items") && config.getBoolean("Settings.EnchantmentOptions.Enchant-Stacked-Items"); setDropBlocksBlast(config.getBoolean("Settings.EnchantmentOptions.Drop-Blocks-For-Blast", true)); setDropBlocksVeinMiner(config.getBoolean("Settings.EnchantmentOptions.Drop-Blocks-For-VeinMiner", true)); - enchantmentBookSettings.populateMaps(); + this.enchantmentBookSettings.populateMaps(); for (CEnchantments cEnchantment : CEnchantments.values()) { String name = cEnchantment.getName(); @@ -203,7 +207,7 @@ public void load() { .setChanceIncrease(cEnchantment.getChanceIncrease()) .setSound(enchants.getString(path + ".Sound")); - if (enchants.contains(path + ".Enchantment-Type")) enchantment.setEnchantmentType(methods.getFromName(enchants.getString(path + ".Enchantment-Type"))); + if (enchants.contains(path + ".Enchantment-Type")) enchantment.setEnchantmentType(this.methods.getFromName(enchants.getString(path + ".Enchantment-Type"))); if (cEnchantment.hasChanceSystem()) { if (enchants.contains(path + ".Chance-System.Base")) { @@ -223,15 +227,15 @@ public void load() { } } - if (gkitzToggle) { + if (this.gkitzToggle) { for (String kit : gkit.getConfigurationSection("GKitz").getKeys(false)) { String path = "GKitz." + kit + "."; int slot = gkit.getInt(path + "Display.Slot"); String time = gkit.getString(path + "Cooldown"); boolean autoEquip = gkit.getBoolean(path + "Auto-Equip"); NBTItem displayItem = new NBTItem(new ItemBuilder() - .setMaterial(gkit.getString(path + "Display.Item")) - .setName(gkit.getString(path + "Display.Name")) + .setMaterial(gkit.getString(path + "Display.Item", ColorUtils.getRandomPaneColor().getName())) + .setName(gkit.getString(path + "Display.Name", "Error getting name.")) .setLore(gkit.getStringList(path + "Display.Lore")) .setGlow(gkit.getBoolean(path + "Display.Glowing")).build()); displayItem.setString("gkit", kit); @@ -239,7 +243,7 @@ public void load() { List itemStrings = gkit.getStringList(path + "Items"); List previewItems = getInfoGKit(itemStrings); previewItems.addAll(getInfoGKit(gkit.getStringList(path + "Fake-Items"))); - gkitz.add(new GKitz(kit, slot, time, displayItem.getItem(), previewItems, commands, itemStrings, autoEquip)); + this.gkitz.add(new GKitz(kit, slot, time, displayItem.getItem(), previewItems, commands, itemStrings, autoEquip)); } } @@ -249,15 +253,15 @@ public void load() { Dust.loadDust(); // Loads the protection crystals. - protectionCrystalSettings.loadProtectionCrystal(); + this.protectionCrystalSettings.loadProtectionCrystal(); // Loads the scrambler. - scramblerListener.loadScrambler(); + this.scramblerListener.loadScrambler(); // Loads Slot Crystal. - slotCrystalListener.load(); + this.slotCrystalListener.load(); // Loads the Scroll Control settings. - scrollListener.loadScrollControl(); + this.scrollListener.loadScrollControl(); - cropManagerVersion = new CropManager(); + this.cropManagerVersion = new CropManager(); // Loads the scrolls. Scrolls.loadScrolls(); @@ -268,19 +272,19 @@ public void load() { ShopOption.loadShopOptions(); // Loads the shop manager. - shopManager.load(); + this.shopManager.load(); // Loads the settings for wings enchantment. - wingsManager.load(); + this.wingsManager.load(); // Loads the settings for the bow enchantments. - bowEnchantmentManager.load(); + this.bowEnchantmentManager.load(); // Loads the settings for the armor enchantments. - armorEnchantmentManager.load(); + this.armorEnchantmentManager.load(); // Loads the settings for the ally enchantments. - allyManager.load(); + this.allyManager.load(); // Starts the wings task. WingsUtils.startWings(); @@ -363,11 +367,11 @@ private void backupCEPlayer(CEPlayer cePlayer) { * @return NMS support class. */ public CropManagerVersion getNMSSupport() { - return cropManagerVersion; + return this.cropManagerVersion; } public boolean checkVanillaLimit() { - return checkVanillaLimit; + return this.checkVanillaLimit; } /** @@ -375,7 +379,7 @@ public boolean checkVanillaLimit() { * @return True if it is on and false if it is off. */ public boolean isGkitzEnabled() { - return gkitzToggle; + return this.gkitzToggle; } /** @@ -396,7 +400,7 @@ public GKitz getGKitFromName(String kitName) { * @return All the loaded gkitz. */ public List getGKitz() { - return gkitz; + return this.gkitz; } /** @@ -425,16 +429,17 @@ public CEPlayer getCEPlayer(UUID uuid) { * @return All CEPlayer's that are loading and in a list. */ public List getCEPlayers() { - return players; + return this.players; } + public CEBook getRandomEnchantmentBook(Category category) { try { List enchantments = category.getEnabledEnchantments(); - CEnchantment enchantment = enchantments.get(random.nextInt(enchantments.size())); + CEnchantment enchantment = enchantments.get(new Random().nextInt(enchantments.size())); return new CEBook(enchantment, randomLevel(enchantment, category), 1, category); } catch (Exception e) { - plugin.getLogger().info("The category " + category.getName() + " has no enchantments." + this.plugin.getLogger().info("The category " + category.getName() + " has no enchantments." + " Please add enchantments to the category in the Enchantments.yml. If you do not wish to have the category feel free to delete it from the Config.yml."); return null; } @@ -445,7 +450,7 @@ public CEBook getRandomEnchantmentBook(Category category) { * @return A list of all the registered enchantments in the plugin. */ public List getRegisteredEnchantments() { - return new ArrayList<>(enchantmentBookSettings.getRegisteredEnchantments()); + return new ArrayList<>(this.enchantmentBookSettings.getRegisteredEnchantments()); } /** @@ -454,7 +459,7 @@ public List getRegisteredEnchantments() { * @return The enchantment as a CEnchantment but if not found will be null. */ public CEnchantment getEnchantmentFromName(String enchantmentString) { - for (CEnchantment enchantment : enchantmentBookSettings.getRegisteredEnchantments()) { + for (CEnchantment enchantment : this.enchantmentBookSettings.getRegisteredEnchantments()) { if (enchantment.getName().equalsIgnoreCase(enchantmentString)) return enchantment; enchantmentString = enchantmentString.replaceAll("([&§]?#[0-9a-f]{6}|[&§][1-9a-fk-or]| |_)", ""); if (enchantment.getCustomName().replaceAll("([&§]?#[0-9a-f]{6}|[&§][1-9a-fk-or]| |_)", "").equalsIgnoreCase(enchantmentString)) return enchantment; @@ -467,7 +472,7 @@ public CEnchantment getEnchantmentFromName(String enchantmentString) { * @param enchantment The enchantment you wish to register. */ public void registerEnchantment(CEnchantment enchantment) { - enchantmentBookSettings.getRegisteredEnchantments().add(enchantment); + this.enchantmentBookSettings.getRegisteredEnchantments().add(enchantment); } /** @@ -475,7 +480,7 @@ public void registerEnchantment(CEnchantment enchantment) { * @param enchantment The enchantment you wish to unregister. */ public void unregisterEnchantment(CEnchantment enchantment) { - enchantmentBookSettings.getRegisteredEnchantments().remove(enchantment); + this.enchantmentBookSettings.getRegisteredEnchantments().remove(enchantment); } /** @@ -503,13 +508,12 @@ public ItemStack addEnchantments(ItemStack item, Map ench * @return The item with the enchantment on it. */ public ItemMeta addEnchantments(ItemMeta meta, Map enchantments) { - Gson gson = new Gson(); - Map currentEnchantments = enchantmentBookSettings.getEnchantments(meta); + Map currentEnchantments = this.enchantmentBookSettings.getEnchantments(meta); - meta = enchantmentBookSettings.removeEnchantments(meta, enchantments.keySet().stream().filter(currentEnchantments::containsKey).toList()); + meta = this.enchantmentBookSettings.removeEnchantments(meta, enchantments.keySet().stream().filter(currentEnchantments::containsKey).toList()); - String data = meta.getPersistentDataContainer().get(DataKeys.ENCHANTMENTS.getKey(), PersistentDataType.STRING); + String data = meta.getPersistentDataContainer().get(DataKeys.enchantments.getNamespacedKey(), PersistentDataType.STRING); Enchant enchantData = data != null ? gson.fromJson(data, Enchant.class) : new Enchant(new HashMap<>()); List lore = meta.lore(); @@ -529,7 +533,7 @@ public ItemMeta addEnchantments(ItemMeta meta, Map enchan } meta.lore(lore); - meta.getPersistentDataContainer().set(DataKeys.ENCHANTMENTS.getKey(), PersistentDataType.STRING, gson.toJson(enchantData)); + meta.getPersistentDataContainer().set(DataKeys.enchantments.getNamespacedKey(), PersistentDataType.STRING, gson.toJson(enchantData)); return meta; } @@ -541,20 +545,20 @@ public ItemStack changeEnchantmentLimiter(ItemStack item, int amount) { public ItemMeta changeEnchantmentLimiter(ItemMeta meta, int amount) { PersistentDataContainer container = meta.getPersistentDataContainer(); - int newAmount = container.getOrDefault(DataKeys.LIMIT_REDUCER.getKey(), PersistentDataType.INTEGER, 0); + int newAmount = container.getOrDefault(DataKeys.limit_reducer.getNamespacedKey(), PersistentDataType.INTEGER, 0); newAmount += amount; if (newAmount == 0) { - container.remove(DataKeys.LIMIT_REDUCER.getKey()); + container.remove(DataKeys.limit_reducer.getNamespacedKey()); } else { - container.set(DataKeys.LIMIT_REDUCER.getKey(), PersistentDataType.INTEGER, newAmount); + container.set(DataKeys.limit_reducer.getNamespacedKey(), PersistentDataType.INTEGER, newAmount); } return meta; } public int getEnchantmentLimiter(ItemStack item) { - return item.getItemMeta().getPersistentDataContainer().getOrDefault(DataKeys.LIMIT_REDUCER.getKey(), PersistentDataType.INTEGER, 0); + return item.getItemMeta().getPersistentDataContainer().getOrDefault(DataKeys.limit_reducer.getNamespacedKey(), PersistentDataType.INTEGER, 0); } /** @@ -566,7 +570,7 @@ public void updatePlayerEffects(Player player) { // TODO Remove this method. Set allEnchantPotionEffects = getEnchantmentPotions().keySet(); for (ItemStack armor : player.getEquipment().getArmorContents()) { - Map enchantments = enchantmentBookSettings.getEnchantments(armor); + Map enchantments = this.enchantmentBookSettings.getEnchantments(armor); for (CEnchantments ench : allEnchantPotionEffects) { if (!enchantments.containsKey(ench.getEnchantment())) continue; Map effects = getUpdatedEffects(player, armor, new ItemStack(Material.AIR), ench); @@ -609,11 +613,11 @@ public Map getUpdatedEffects(Player player, ItemStack for (ItemStack armor : items) { if (armor == null || armor.isSimilar(excludedItem)) continue; - Map ench = enchantmentBookSettings.getEnchantments(armor); + Map ench = this.enchantmentBookSettings.getEnchantments(armor); for (Entry> enchantments : armorEffects.entrySet()) { if (!ench.containsKey(enchantments.getKey().getEnchantment())) continue; int level = ench.get(enchantments.getKey().getEnchantment()); - if (!useUnsafeEnchantments && level > enchantments.getKey().getEnchantment().getMaxLevel()) level = enchantments.getKey().getEnchantment().getMaxLevel(); + if (!this.useUnsafeEnchantments && level > enchantments.getKey().getEnchantment().getMaxLevel()) level = enchantments.getKey().getEnchantment().getMaxLevel(); for (PotionEffectType type : enchantments.getValue().keySet()) { if (effects.containsKey(type)) { @@ -730,9 +734,10 @@ public int getPlayerBaseEnchantments(Player player) { } public boolean canAddEnchantment(Player player, ItemStack item) { - if (!maxEnchantmentCheck || player.hasPermission("crazyenchantments.bypass.limit")) return true; + //todo() update permissions + if (!this.maxEnchantmentCheck || player.hasPermission("crazyenchantments.bypass.limit")) return true; - return enchantmentBookSettings.getEnchantmentAmount(item, checkVanillaLimit) < + return this.enchantmentBookSettings.getEnchantmentAmount(item, this.checkVanillaLimit) < Math.min(getPlayerBaseEnchantments(player) - getEnchantmentLimiter(item), getPlayerMaxEnchantments(player)); } @@ -742,15 +747,15 @@ public boolean canAddEnchantment(Player player, ItemStack item) { * @return The level the enchantment has. */ public int getLevel(ItemStack item, CEnchantments enchant) { - return enchantmentBookSettings.getLevel(item, enchant.getEnchantment()); + return this.enchantmentBookSettings.getLevel(item, enchant.getEnchantment()); } public int randomLevel(CEnchantment enchantment, Category category) { int enchantmentMax = enchantment.getMaxLevel(); // Max set by the enchantment. - int randomLevel = 1 + random.nextInt(enchantmentMax); + int randomLevel = 1 + new Random().nextInt(enchantmentMax); if (category.useMaxLevel()) { - if (randomLevel > category.getMaxLevel()) randomLevel = 1 + random.nextInt(category.getMaxLevel()); + if (randomLevel > category.getMaxLevel()) randomLevel = 1 + new Random().nextInt(category.getMaxLevel()); if (randomLevel < category.getMinLevel()) randomLevel = category.getMinLevel(); @@ -764,28 +769,28 @@ public int randomLevel(CEnchantment enchantment, Category category) { * @return The head multiplier map for decapitation and headless. */ public Map getDecapitationHeadMap() { - return headMap; + return this.headMap; } /** * @return The block list for blast. */ public List getBlastBlockList() { - return blockList; + return this.blockList; } /** * @return If the blast enchantment drops blocks. */ public boolean isDropBlocksBlast() { - return dropBlocksBlast; + return this.dropBlocksBlast; } /** * @return If the vein-miner enchantment drops blocks. */ public boolean isDropBlocksVeinMiner() { - return dropBlocksVeinMiner; + return this.dropBlocksVeinMiner; } /** @@ -806,7 +811,7 @@ public void setDropBlocksVeinMiner(boolean dropBlocksVeinMiner) { * @return The max rage stack level. */ public int getRageMaxLevel() { - return rageMaxLevel; + return this.rageMaxLevel; } /** @@ -814,29 +819,29 @@ public int getRageMaxLevel() { * @return True if they do and false if not. */ public boolean isBreakRageOnDamageOn() { - return breakRageOnDamage; + return this.breakRageOnDamage; } /** * @return True if a boss bar will be used to display rage notifications. */ public boolean useRageBossBar() { - return useRageBossBar; + return this.useRageBossBar; } /** * Check if players can enchant a stack of items with an enchantment book. */ public boolean enchantStackedItems() { - return enchantStackedItems; + return this.enchantStackedItems; } private void addCEPlayer(CEPlayer player) { - players.add(player); + this.players.add(player); } private void removeCEPlayer(CEPlayer player) { - players.remove(player); + this.players.remove(player); } private List getInfoGKit(List itemStrings) { @@ -852,7 +857,7 @@ private List getInfoGKit(List itemStrings) { for (String option : itemString.split(", ")) { try { - Enchantment enchantment = methods.getEnchantment(option.split(":")[0]); + Enchantment enchantment = this.methods.getEnchantment(option.split(":")[0]); CEnchantment cEnchantment = getEnchantmentFromName(option.split(":")[0]); String level = option.split(":")[1]; @@ -874,7 +879,7 @@ private List getInfoGKit(List itemStrings) { NBTItem nbtItem = new NBTItem(itemBuilder.build()); // This is done so items do not stack if there are multiple of the same. - nbtItem.setInteger("random-number", random.nextInt(Integer.MAX_VALUE)); + nbtItem.setInteger("random-number", new Random().nextInt(Integer.MAX_VALUE)); items.add(nbtItem.getItem()); } @@ -903,6 +908,6 @@ public String getNewItemString(String itemString) { } public int pickLevel(int min, int max) { - return min + random.nextInt((max + 1) - min); + return min + new Random().nextInt((max + 1) - min); } } diff --git a/paper/src/main/java/com/badbones69/crazyenchantments/paper/api/enums/Dust.java b/paper/src/main/java/com/badbones69/crazyenchantments/paper/api/enums/Dust.java index f56f4c22..e15c8a29 100644 --- a/paper/src/main/java/com/badbones69/crazyenchantments/paper/api/enums/Dust.java +++ b/paper/src/main/java/com/badbones69/crazyenchantments/paper/api/enums/Dust.java @@ -31,16 +31,21 @@ public enum Dust { private final int max; private final int min; - private final CrazyEnchantments plugin = CrazyEnchantments.getPlugin(); + @NotNull + private final CrazyEnchantments plugin = CrazyEnchantments.get(); - private final Methods methods = plugin.getStarter().getMethods(); + @NotNull + private final Methods methods = this.plugin.getStarter().getMethods(); Dust(String name, String configName, List knowNames) { this.name = name; this.knownNames = knowNames; this.configName = configName; - this.max = Files.CONFIG.getFile().getInt("Settings.Dust." + configName + ".PercentRange.Max", 100); - this.min = Files.CONFIG.getFile().getInt("Settings.Dust." + configName + ".PercentRange.Min", max); + + FileConfiguration config = Files.CONFIG.getFile(); + + this.max = config.getInt("Settings.Dust." + configName + ".PercentRange.Max", 100); + this.min = config.getInt("Settings.Dust." + configName + ".PercentRange.Min", max); } public static void loadDust() { @@ -50,9 +55,9 @@ public static void loadDust() { for (Dust dust : values()) { String path = "Settings.Dust." + dust.getConfigName() + "."; Dust.itemBuilderDust.put(dust, new ItemBuilder() - .setName(config.getString(path + "Name")) + .setName(config.getString(path + "Name", "Error getting name.")) .setLore(config.getStringList(path + "Lore")) - .setMaterial(config.getString(path + "Item"))); + .setMaterial(config.getString(path + "Item", "GLOWSTONE_DUST"))); } } @@ -66,15 +71,15 @@ public static Dust getFromName(String nameString) { } public String getName() { - return name; + return this.name; } public List getKnownNames() { - return knownNames; + return this.knownNames; } public String getConfigName() { - return configName; + return this.configName; } public ItemStack getDust() { @@ -82,17 +87,14 @@ public ItemStack getDust() { } public ItemStack getDust(int amount) { - - return getDust(methods.percentPick(max, min), amount); + return getDust(this.methods.percentPick(this.max, this.min), amount); } public ItemStack getDust(int percent, int amount) { - ItemStack item = itemBuilderDust.get(this) - .addLorePlaceholder("%Percent%", String.valueOf(percent)) - .setAmount(amount).build(); + ItemStack item = itemBuilderDust.get(this).addLorePlaceholder("%Percent%", String.valueOf(percent)).setAmount(amount).build(); // PDC Start - Gson gson = new Gson(); + Gson gson = new Gson(); ItemMeta meta = item.getItemMeta(); meta.getPersistentDataContainer().set(DataKeys.dust.getNamespacedKey(), PersistentDataType.STRING, gson.toJson(new DustData(getConfigName(), this.min, this.max, percent))); diff --git a/paper/src/main/java/com/badbones69/crazyenchantments/paper/api/enums/Scrolls.java b/paper/src/main/java/com/badbones69/crazyenchantments/paper/api/enums/Scrolls.java index 6809df41..1b3e19c5 100644 --- a/paper/src/main/java/com/badbones69/crazyenchantments/paper/api/enums/Scrolls.java +++ b/paper/src/main/java/com/badbones69/crazyenchantments/paper/api/enums/Scrolls.java @@ -42,10 +42,10 @@ public static void loadScrolls() { for (Scrolls scroll : values()) { String path = "Settings." + scroll.getConfigName() + "."; itemBuilderScrolls.put(scroll, new ItemBuilder() - .setName(config.getString(path + "Name")) + .setName(config.getString(path + "Name", "Error getting name.")) .setLore(config.getStringList(path + "Item-Lore")) - .setMaterial(config.getString(path + "Item")) - .setGlow(config.getBoolean(path + "Glowing"))); + .setMaterial(config.getString(path + "Item", "BOOK")) + .setGlow(config.getBoolean(path + "Glowing", false))); } } @@ -58,15 +58,15 @@ public static Scrolls getFromName(String nameString) { } public String getName() { - return name; + return this.name; } public List getKnownNames() { - return knownNames; + return this.knownNames; } public String getConfigName() { - return configName; + return this.configName; } private static final NamespacedKey scroll = DataKeys.scroll.getNamespacedKey(); diff --git a/paper/src/main/java/com/badbones69/crazyenchantments/paper/api/enums/ShopOption.java b/paper/src/main/java/com/badbones69/crazyenchantments/paper/api/enums/ShopOption.java index 37e8ffb3..8efe0e12 100644 --- a/paper/src/main/java/com/badbones69/crazyenchantments/paper/api/enums/ShopOption.java +++ b/paper/src/main/java/com/badbones69/crazyenchantments/paper/api/enums/ShopOption.java @@ -56,18 +56,17 @@ public static void loadShopOptions() { try { shopOptions.put(shopOption, new Option(new ItemBuilder() - .setName(config.getString(itemPath + shopOption.getNamePath())) + .setName(config.getString(itemPath + shopOption.getNamePath(), "Error getting name.")) .setLore(config.getStringList(itemPath + shopOption.getLorePath())) - .setMaterial(config.getString(itemPath + "Item")) + .setMaterial(config.getString(itemPath + "Item", "CHEST")) .setPlayerName(config.getString(itemPath + "Player")) - .setGlow(config.getBoolean(itemPath + "Glowing")), + .setGlow(config.getBoolean(itemPath + "Glowing", false)), config.getInt(itemPath + "Slot", 1) - 1, - config.getBoolean(itemPath + "InGUI"), + config.getBoolean(itemPath + "InGUI", true), config.getInt(costPath + "Cost", 100), Currency.getCurrency(config.getString(costPath + "Currency", "Vault")))); - } catch (Exception e) { - plugin.getLogger().info("The option " + shopOption.getOptionPath() + " has failed to load."); - Log.error(e); + } catch (Exception exception) { + plugin.getLogger().log(Level.SEVERE, "The option " + shopOption.getOptionPath() + " has failed to load.", exception); } } } diff --git a/paper/src/main/java/com/badbones69/crazyenchantments/paper/api/objects/CEBook.java b/paper/src/main/java/com/badbones69/crazyenchantments/paper/api/objects/CEBook.java index 24761387..6b95fb6e 100644 --- a/paper/src/main/java/com/badbones69/crazyenchantments/paper/api/objects/CEBook.java +++ b/paper/src/main/java/com/badbones69/crazyenchantments/paper/api/objects/CEBook.java @@ -63,13 +63,16 @@ public CEBook(CEnchantment enchantment, int level, int amount) { this.enchantment = enchantment; this.amount = amount; this.level = level; - this.glowing = Files.CONFIG.getFile().getBoolean("Settings.Enchantment-Book-Glowing"); - int successMax = Files.CONFIG.getFile().getInt("Settings.BlackScroll.SuccessChance.Max"); - int successMin = Files.CONFIG.getFile().getInt("Settings.BlackScroll.SuccessChance.Min"); - int destroyMax = Files.CONFIG.getFile().getInt("Settings.BlackScroll.DestroyChance.Max"); - int destroyMin = Files.CONFIG.getFile().getInt("Settings.BlackScroll.DestroyChance.Min"); - this.destroyRate = methods.percentPick(destroyMax, destroyMin); - this.successRate = methods.percentPick(successMax, successMin); + + FileConfiguration config = Files.CONFIG.getFile(); + + this.glowing = config.getBoolean("Settings.Enchantment-Book-Glowing", true); + int successMax = config.getInt("Settings.BlackScroll.SuccessChance.Max", 100); + int successMin = config.getInt("Settings.BlackScroll.SuccessChance.Min", 15); + int destroyMax = config.getInt("Settings.BlackScroll.DestroyChance.Max", 100); + int destroyMin = config.getInt("Settings.BlackScroll.DestroyChance.Min", 15); + this.destroyRate = this.methods.percentPick(destroyMax, destroyMin); + this.successRate = this.methods.percentPick(successMax, successMin); } /** @@ -91,9 +94,9 @@ public CEBook(CEnchantment enchantment, int level, int amount, Category category this.enchantment = enchantment; this.amount = amount; this.level = level; - this.glowing = Files.CONFIG.getFile().getBoolean("Settings.Enchantment-Book-Glowing"); - this.destroyRate = methods.percentPick(category.getMaxDestroyRate(), category.getMinDestroyRate()); - this.successRate = methods.percentPick(category.getMaxSuccessRate(), category.getMinSuccessRate()); + this.glowing = Files.CONFIG.getFile().getBoolean("Settings.Enchantment-Book-Glowing", true); + this.destroyRate = this.methods.percentPick(category.getMaxDestroyRate(), category.getMinDestroyRate()); + this.successRate = this.methods.percentPick(category.getMaxSuccessRate(), category.getMinSuccessRate()); } /** @@ -107,7 +110,7 @@ public CEBook(CEnchantment enchantment, int level, int amount, int destroyRate, this.enchantment = enchantment; this.amount = amount; this.level = level; - this.glowing = Files.CONFIG.getFile().getBoolean("Settings.Enchantment-Book-Glowing"); + this.glowing = Files.CONFIG.getFile().getBoolean("Settings.Enchantment-Book-Glowing", true); this.destroyRate = destroyRate; this.successRate = successRate; } @@ -218,29 +221,28 @@ public CEBook setSuccessRate(int successRate) { * @return Return the book as an ItemBuilder. */ public ItemBuilder getItemBuilder() { - String name = enchantment.getCustomName() + " " + NumberUtils.convertLevelString(level); + String name = this.enchantment.getCustomName() + " " + NumberUtils.convertLevelString(level); List lore = new ArrayList<>(); for (String bookLine : Files.CONFIG.getFile().getStringList("Settings.EnchantmentBookLore")) { if (bookLine.contains("%Description%") || bookLine.contains("%description%")) { - for (String enchantmentLine : enchantment.getInfoDescription()) { + for (String enchantmentLine : this.enchantment.getInfoDescription()) { lore.add(ColorUtils.color(enchantmentLine)); } } else { lore.add(ColorUtils.color(bookLine) - .replace("%Destroy_Rate%", String.valueOf(destroyRate)).replace("%destroy_rate%", String.valueOf(destroyRate)) - .replace("%Success_Rate%", String.valueOf(successRate)).replace("%success_rate%", String.valueOf(successRate))); + .replace("%Destroy_Rate%", String.valueOf(this.destroyRate)).replace("%destroy_rate%", String.valueOf(this.destroyRate)) + .replace("%Success_Rate%", String.valueOf(this.successRate)).replace("%success_rate%", String.valueOf(this.successRate))); } } - return enchantmentBookSettings.getNormalBook().setAmount(amount).setName(name).setLore(lore).setGlow(glowing); + return this.enchantmentBookSettings.getNormalBook().setAmount(this.amount).setName(name).setLore(lore).setGlow(this.glowing); } /** * @return Return the book as an ItemStack. */ public ItemStack buildBook() { - ItemStack item = getItemBuilder().build(); ItemMeta meta = item.getItemMeta(); diff --git a/paper/src/main/java/com/badbones69/crazyenchantments/paper/controllers/settings/EnchantmentBookSettings.java b/paper/src/main/java/com/badbones69/crazyenchantments/paper/controllers/settings/EnchantmentBookSettings.java index 070a3044..b9456393 100644 --- a/paper/src/main/java/com/badbones69/crazyenchantments/paper/controllers/settings/EnchantmentBookSettings.java +++ b/paper/src/main/java/com/badbones69/crazyenchantments/paper/controllers/settings/EnchantmentBookSettings.java @@ -35,10 +35,11 @@ public class EnchantmentBookSettings { * @return True if unsafe enchantments are enabled. */ public boolean useUnsafeEnchantments() { - FileConfiguration config = FileManager.Files.CONFIG.getFile(); + FileConfiguration config = Files.CONFIG.getFile(); return config.getBoolean("Settings.EnchantmentOptions.UnSafe-Enchantments"); } + public boolean hasEnchantment(ItemMeta meta, CEnchantment enchantment) { PersistentDataContainer data = meta.getPersistentDataContainer(); @@ -67,6 +68,7 @@ public CEBook getCEBook(ItemStack book) { break; } } + return new CEBook(enchantment, data.getLevel(), book.getAmount()) .setSuccessRate(data.getSuccessChance()) .setDestroyRate(data.getDestroyChance()); @@ -121,7 +123,7 @@ public boolean isEnchantmentBook(ItemStack book) { * @return A list of all active enchantments. */ public List getRegisteredEnchantments() { - return registeredEnchantments; + return this.registeredEnchantments; } /** @@ -129,14 +131,14 @@ public List getRegisteredEnchantments() { * @return itemBuilder for an enchanted book. */ public ItemBuilder getNormalBook() { - return new ItemBuilder(enchantmentBook); + return new ItemBuilder(this.enchantmentBook); } /** * @return the itemstack of the enchantment book. */ public ItemStack getEnchantmentBookItem() { - return new ItemBuilder(enchantmentBook).build(); + return new ItemBuilder(this.enchantmentBook).build(); } /** @@ -215,14 +217,14 @@ public int getEnchantmentAmount(ItemStack item, boolean includeVanillaEnchantmen * @return List of all the categories. */ public List getCategories() { - return categories; + return this.categories; } /** * Loads in all config options. */ public void populateMaps() { - FileConfiguration config = FileManager.Files.CONFIG.getFile(); + FileConfiguration config = Files.CONFIG.getFile(); for (String category : config.getConfigurationSection("Categories").getKeys(false)) { String path = "Categories." + category; @@ -230,27 +232,28 @@ public void populateMaps() { config.getInt(path + ".LostBook.Slot"), config.getBoolean(path + ".LostBook.InGUI"), new ItemBuilder() - .setMaterial(config.getString(path + ".LostBook.Item")) + .setMaterial(config.getString(path + ".LostBook.Item", "BOOK")) .setPlayerName(config.getString(path + ".LostBook.Player")) - .setName(config.getString(path + ".LostBook.Name")) + .setName(config.getString(path + ".LostBook.Name", "Error getting name.")) .setLore(config.getStringList(path + ".LostBook.Lore")) - .setGlow(config.getBoolean(path + ".LostBook.Glowing")), + .setGlow(config.getBoolean(path + ".LostBook.Glowing", true)), config.getInt(path + ".LostBook.Cost"), Currency.getCurrency(config.getString(path + ".LostBook.Currency")), - config.getBoolean(path + ".LostBook.FireworkToggle"), - getColors(config.getString(path + ".LostBook.FireworkColors")), - config.getBoolean(path + ".LostBook.Sound-Toggle"), - config.getString(path + ".LostBook.Sound")); - categories.add(new Category( + config.getBoolean(path + ".LostBook.FireworkToggle", false), + getColors(config.getString(path + ".LostBook.FireworkColors", "Red, White, Blue")), + config.getBoolean(path + ".LostBook.Sound-Toggle", false), + config.getString(path + ".LostBook.Sound", "BLOCK_ANVIL_PLACE")); + + this.categories.add(new Category( category, config.getInt(path + ".Slot"), - config.getBoolean(path + ".InGUI"), + config.getBoolean(path + ".InGUI", true), new ItemBuilder() - .setMaterial(config.getString(path + ".Item")) + .setMaterial(config.getString(path + ".Item", ColorUtils.getRandomPaneColor().getName())) .setPlayerName(config.getString(path + ".Player")) - .setName(config.getString(path + ".Name")) + .setName(config.getString(path + ".Name", "Error getting name.")) .setLore(config.getStringList(path + ".Lore")) - .setGlow(config.getBoolean(path + ".Glowing")), + .setGlow(config.getBoolean(path + ".Glowing", false)), config.getInt(path + ".Cost"), Currency.getCurrency(config.getString(path + ".Currency")), config.getInt(path + ".Rarity"), @@ -270,14 +273,12 @@ public void populateMaps() { * @return The category object. */ public Category getCategory(String name) { - for (Category category : categories) { + for (Category category : this.categories) { if (category.getName().equalsIgnoreCase(name)) return category; } return null; } - - private List getColors(String string) { List colors = new ArrayList<>(); @@ -313,8 +314,8 @@ public ItemStack removeEnchantment(ItemStack item, CEnchantment enchant) { return item; } - public ItemMeta removeEnchantment(ItemMeta meta, CEnchantment enchant) { + public ItemMeta removeEnchantment(ItemMeta meta, CEnchantment enchant) { List lore = meta.lore(); if (lore != null) { diff --git a/paper/src/main/java/com/badbones69/crazyenchantments/paper/controllers/settings/ProtectionCrystalSettings.java b/paper/src/main/java/com/badbones69/crazyenchantments/paper/controllers/settings/ProtectionCrystalSettings.java index cb7ba873..46ffc5e5 100644 --- a/paper/src/main/java/com/badbones69/crazyenchantments/paper/controllers/settings/ProtectionCrystalSettings.java +++ b/paper/src/main/java/com/badbones69/crazyenchantments/paper/controllers/settings/ProtectionCrystalSettings.java @@ -38,12 +38,13 @@ public class ProtectionCrystalSettings { private ItemBuilder crystal; public void loadProtectionCrystal() { - FileConfiguration config = FileManager.Files.CONFIG.getFile(); - crystal = new ItemBuilder() - .setMaterial(Objects.requireNonNull(config.getString("Settings.ProtectionCrystal.Item"))) - .setName(config.getString("Settings.ProtectionCrystal.Name")) + FileConfiguration config = Files.CONFIG.getFile(); + + this.crystal = new ItemBuilder() + .setMaterial(config.getString("Settings.ProtectionCrystal.Item", "EMERALD")) + .setName(config.getString("Settings.ProtectionCrystal.Name", "Error getting name.")) .setLore(config.getStringList("Settings.ProtectionCrystal.Lore")) - .setGlow(config.getBoolean("Settings.ProtectionCrystal.Glowing")); + .setGlow(config.getBoolean("Settings.ProtectionCrystal.Glowing", false)); } public ItemStack getCrystals() { @@ -108,9 +109,9 @@ public HashMap> getCrystalItems() { public boolean isProtectionSuccessful(Player player) { if (player.hasPermission("crazyenchantments.bypass.protectioncrystal")) return true; - FileConfiguration config = FileManager.Files.CONFIG.getFile(); + FileConfiguration config = Files.CONFIG.getFile(); - if (config.getBoolean("Settings.ProtectionCrystal.Chance.Toggle")) return methods.randomPicker(config.getInt("Settings.ProtectionCrystal.Chance.Success-Chance", 100), 100); + if (config.getBoolean("Settings.ProtectionCrystal.Chance.Toggle", false)) return this.methods.randomPicker(config.getInt("Settings.ProtectionCrystal.Chance.Success-Chance", 100), 100); return true; } diff --git a/paper/src/main/java/com/badbones69/crazyenchantments/paper/listeners/ScramblerListener.java b/paper/src/main/java/com/badbones69/crazyenchantments/paper/listeners/ScramblerListener.java index a944be73..9ff2d328 100644 --- a/paper/src/main/java/com/badbones69/crazyenchantments/paper/listeners/ScramblerListener.java +++ b/paper/src/main/java/com/badbones69/crazyenchantments/paper/listeners/ScramblerListener.java @@ -54,17 +54,17 @@ public class ScramblerListener implements Listener { public void loadScrambler() { FileConfiguration config = Files.CONFIG.getFile(); - scramblerItem = new ItemBuilder() - .setMaterial(Objects.requireNonNull(config.getString("Settings.Scrambler.Item"))) - .setName(config.getString("Settings.Scrambler.Name")) + this.scramblerItem = new ItemBuilder() + .setMaterial(config.getString("Settings.Scrambler.Item", "SUNFLOWER")) + .setName(config.getString("Settings.Scrambler.Name", "Error getting name.")) .setLore(config.getStringList("Settings.Scrambler.Lore")) - .setGlow(config.getBoolean("Settings.Scrambler.Glowing")); - pointer = new ItemBuilder() - .setMaterial(Objects.requireNonNull(config.getString("Settings.Scrambler.GUI.Pointer.Item"))) - .setName(config.getString("Settings.Scrambler.GUI.Pointer.Name")) + .setGlow(config.getBoolean("Settings.Scrambler.Glowing", false)); + this.pointer = new ItemBuilder() + .setMaterial(config.getString("Settings.Scrambler.GUI.Pointer.Item", "REDSTONE_TORCH")) + .setName(config.getString("Settings.Scrambler.GUI.Pointer.Name", "Error getting name.")) .setLore(config.getStringList("Settings.Scrambler.GUI.Pointer.Lore")); - animationToggle = Files.CONFIG.getFile().getBoolean("Settings.Scrambler.GUI.Toggle"); - guiName = ColorUtils.color(Files.CONFIG.getFile().getString("Settings.Scrambler.GUI.Name")); + this.animationToggle = Files.CONFIG.getFile().getBoolean("Settings.Scrambler.GUI.Toggle", true); + this.guiName = ColorUtils.color(Files.CONFIG.getFile().getString("Settings.Scrambler.GUI.Name", "Error getting name.")); } /**