mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-25 10:14:43 +02:00
Move fishing treasues to new file fishing_treasures.yml, replace Records rarity with Mythic, and allow for Enchanted_Book in the treasures list with new optional whitelist/blacklist parameters
read the changelog for information about this
This commit is contained in:
@ -0,0 +1,57 @@
|
||||
//package com.gmail.nossr50.commands.admin;
|
||||
//
|
||||
//import com.gmail.nossr50.config.treasure.FishingTreasureConfig;
|
||||
//import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
//import com.gmail.nossr50.datatypes.treasure.FishingTreasure;
|
||||
//import com.gmail.nossr50.datatypes.treasure.Rarity;
|
||||
//import com.gmail.nossr50.mcMMO;
|
||||
//import com.gmail.nossr50.skills.fishing.FishingManager;
|
||||
//import com.gmail.nossr50.util.player.UserManager;
|
||||
//import org.bukkit.Location;
|
||||
//import org.bukkit.command.Command;
|
||||
//import org.bukkit.command.CommandExecutor;
|
||||
//import org.bukkit.command.CommandSender;
|
||||
//import org.bukkit.entity.Player;
|
||||
//import org.jetbrains.annotations.NotNull;
|
||||
//
|
||||
//public class DropTreasureCommand implements CommandExecutor {
|
||||
// @Override
|
||||
// public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
// if(sender instanceof Player) {
|
||||
// if(!sender.isOp()) {
|
||||
// sender.sendMessage("This command is for Operators only");
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// Player player = (Player) sender;
|
||||
// Location location = player.getLocation();
|
||||
// McMMOPlayer mmoPlayer = UserManager.getPlayer(player);
|
||||
//
|
||||
// if(mmoPlayer == null) {
|
||||
// //TODO: Localize
|
||||
// player.sendMessage("Your player data is not loaded yet");
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// if(args.length == 0) {
|
||||
// mcMMO.p.getLogger().info(player.toString() +" is dropping all mcMMO treasures via admin command at location "+location.toString());
|
||||
// for(Rarity rarity : FishingTreasureConfig.getInstance().fishingRewards.keySet()) {
|
||||
// for(FishingTreasure fishingTreasure : FishingTreasureConfig.getInstance().fishingRewards.get(rarity)) {
|
||||
// FishingManager fishingManager = mmoPlayer.getFishingManager();
|
||||
// }
|
||||
// }
|
||||
// //TODO: impl
|
||||
// } else {
|
||||
// String targetTreasure = args[1];
|
||||
//
|
||||
// //Drop all treasures matching the name
|
||||
// //TODO: impl
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
// } else {
|
||||
// sender.sendMessage("No console support for this command");
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//}
|
@ -29,7 +29,7 @@ public class FishingCommand extends SkillCommand {
|
||||
private String rareTreasure;
|
||||
private String epicTreasure;
|
||||
private String legendaryTreasure;
|
||||
private String recordTreasure;
|
||||
private String mythicTreasure;
|
||||
|
||||
private String magicChance;
|
||||
|
||||
@ -60,13 +60,13 @@ public class FishingCommand extends SkillCommand {
|
||||
rareTreasure = percent.format(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.RARE) / 100.0);
|
||||
epicTreasure = percent.format(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.EPIC) / 100.0);
|
||||
legendaryTreasure = percent.format(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.LEGENDARY) / 100.0);
|
||||
recordTreasure = percent.format(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.RECORD) / 100.0);
|
||||
mythicTreasure = percent.format(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.MYTHIC) / 100.0);
|
||||
|
||||
// Magic hunter drop rates
|
||||
double totalEnchantChance = 0;
|
||||
|
||||
for (Rarity rarity : Rarity.values()) {
|
||||
if (rarity != Rarity.RECORD) {
|
||||
if (rarity != Rarity.MYTHIC) {
|
||||
totalEnchantChance += TreasureConfig.getInstance().getEnchantmentDropRate(lootTier, rarity);
|
||||
}
|
||||
}
|
||||
@ -145,7 +145,7 @@ public class FishingCommand extends SkillCommand {
|
||||
String.valueOf(rareTreasure),
|
||||
String.valueOf(epicTreasure),
|
||||
String.valueOf(legendaryTreasure),
|
||||
String.valueOf(recordTreasure)));
|
||||
String.valueOf(mythicTreasure)));
|
||||
}
|
||||
|
||||
return messages;
|
||||
|
368
src/main/java/com/gmail/nossr50/config/treasure/FishingTreasureConfig.java
Executable file
368
src/main/java/com/gmail/nossr50/config/treasure/FishingTreasureConfig.java
Executable file
@ -0,0 +1,368 @@
|
||||
package com.gmail.nossr50.config.treasure;
|
||||
|
||||
import com.gmail.nossr50.config.ConfigLoader;
|
||||
import com.gmail.nossr50.datatypes.treasure.*;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.EnchantmentUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.potion.PotionData;
|
||||
import org.bukkit.potion.PotionType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class FishingTreasureConfig extends ConfigLoader {
|
||||
|
||||
public static final String FILENAME = "fishing_treasures.yml";
|
||||
private static FishingTreasureConfig instance;
|
||||
|
||||
public @NotNull HashMap<Rarity, List<FishingTreasure>> fishingRewards = new HashMap<>();
|
||||
public @NotNull HashMap<Rarity, List<EnchantmentTreasure>> fishingEnchantments = new HashMap<>();
|
||||
public @NotNull HashMap<EntityType, List<ShakeTreasure>> shakeMap = new HashMap<>();
|
||||
|
||||
private FishingTreasureConfig() {
|
||||
super(FILENAME);
|
||||
loadKeys();
|
||||
validate();
|
||||
}
|
||||
|
||||
public static FishingTreasureConfig getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new FishingTreasureConfig();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean validateKeys() {
|
||||
// Validate all the settings!
|
||||
List<String> reason = new ArrayList<>();
|
||||
for (String tier : config.getConfigurationSection("Enchantment_Drop_Rates").getKeys(false)) {
|
||||
double totalEnchantDropRate = 0;
|
||||
double totalItemDropRate = 0;
|
||||
|
||||
for (Rarity rarity : Rarity.values()) {
|
||||
double enchantDropRate = config.getDouble("Enchantment_Drop_Rates." + tier + "." + rarity.toString());
|
||||
double itemDropRate = config.getDouble("Item_Drop_Rates." + tier + "." + rarity.toString());
|
||||
|
||||
if ((enchantDropRate < 0.0 || enchantDropRate > 100.0)) {
|
||||
reason.add("The enchant drop rate for " + tier + " items that are " + rarity.toString() + "should be between 0.0 and 100.0!");
|
||||
}
|
||||
|
||||
if (itemDropRate < 0.0 || itemDropRate > 100.0) {
|
||||
reason.add("The item drop rate for " + tier + " items that are " + rarity.toString() + "should be between 0.0 and 100.0!");
|
||||
}
|
||||
|
||||
totalEnchantDropRate += enchantDropRate;
|
||||
totalItemDropRate += itemDropRate;
|
||||
}
|
||||
|
||||
if (totalEnchantDropRate < 0 || totalEnchantDropRate > 100.0) {
|
||||
reason.add("The total enchant drop rate for " + tier + " should be between 0.0 and 100.0!");
|
||||
}
|
||||
|
||||
if (totalItemDropRate < 0 || totalItemDropRate > 100.0) {
|
||||
reason.add("The total item drop rate for " + tier + " should be between 0.0 and 100.0!");
|
||||
}
|
||||
}
|
||||
|
||||
return noErrorsInConfig(reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadKeys() {
|
||||
if (config.getConfigurationSection("Treasures") != null) {
|
||||
backup();
|
||||
return;
|
||||
}
|
||||
|
||||
loadTreasures("Fishing");
|
||||
loadEnchantments();
|
||||
|
||||
for (EntityType entity : EntityType.values()) {
|
||||
if (entity.isAlive()) {
|
||||
loadTreasures("Shake." + entity.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadTreasures(String type) {
|
||||
boolean isFishing = type.equals("Fishing");
|
||||
boolean isShake = type.contains("Shake");
|
||||
|
||||
ConfigurationSection treasureSection = config.getConfigurationSection(type);
|
||||
|
||||
if (treasureSection == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialize fishing HashMap
|
||||
for (Rarity rarity : Rarity.values()) {
|
||||
if (!fishingRewards.containsKey(rarity)) {
|
||||
fishingRewards.put(rarity, (new ArrayList<>()));
|
||||
}
|
||||
}
|
||||
|
||||
for (String treasureName : treasureSection.getKeys(false)) {
|
||||
// Validate all the things!
|
||||
List<String> reason = new ArrayList<>();
|
||||
|
||||
String[] treasureInfo = treasureName.split("[|]");
|
||||
String materialName = treasureInfo[0];
|
||||
|
||||
/*
|
||||
* Material, Amount, and Data
|
||||
*/
|
||||
Material material;
|
||||
|
||||
if (materialName.contains("INVENTORY")) {
|
||||
// Use magic material BEDROCK to know that we're grabbing something from the inventory and not a normal treasure
|
||||
if (!shakeMap.containsKey(EntityType.PLAYER))
|
||||
shakeMap.put(EntityType.PLAYER, new ArrayList<>());
|
||||
shakeMap.get(EntityType.PLAYER).add(new ShakeTreasure(new ItemStack(Material.BEDROCK, 1, (byte) 0), 1, getInventoryStealDropChance(), getInventoryStealDropLevel()));
|
||||
continue;
|
||||
} else {
|
||||
material = Material.matchMaterial(materialName);
|
||||
}
|
||||
|
||||
int amount = config.getInt(type + "." + treasureName + ".Amount");
|
||||
short data = (treasureInfo.length == 2) ? Short.parseShort(treasureInfo[1]) : (short) config.getInt(type + "." + treasureName + ".Data");
|
||||
|
||||
if (material == null) {
|
||||
reason.add("Invalid material: " + materialName);
|
||||
}
|
||||
|
||||
if (amount <= 0) {
|
||||
amount = 1;
|
||||
}
|
||||
|
||||
if (material != null && material.isBlock() && (data > 127 || data < -128)) {
|
||||
reason.add("Data of " + treasureName + " is invalid! " + data);
|
||||
}
|
||||
|
||||
/*
|
||||
* XP, Drop Chance, and Drop Level
|
||||
*/
|
||||
|
||||
int xp = config.getInt(type + "." + treasureName + ".XP");
|
||||
double dropChance = config.getDouble(type + "." + treasureName + ".Drop_Chance");
|
||||
int dropLevel = config.getInt(type + "." + treasureName + ".Drop_Level");
|
||||
|
||||
if (xp < 0) {
|
||||
reason.add(treasureName + " has an invalid XP value: " + xp);
|
||||
}
|
||||
|
||||
if (dropChance < 0.0D) {
|
||||
reason.add(treasureName + " has an invalid Drop_Chance: " + dropChance);
|
||||
}
|
||||
|
||||
if (dropLevel < 0) {
|
||||
reason.add(treasureName + " has an invalid Drop_Level: " + dropLevel);
|
||||
}
|
||||
|
||||
/*
|
||||
* Specific Types
|
||||
*/
|
||||
Rarity rarity = null;
|
||||
|
||||
if (isFishing) {
|
||||
rarity = Rarity.getRarity(config.getString(type + "." + treasureName + ".Rarity"));
|
||||
|
||||
if (rarity == null) {
|
||||
reason.add("Invalid Rarity for item: " + treasureName);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Itemstack
|
||||
*/
|
||||
ItemStack item = null;
|
||||
|
||||
|
||||
String customName = null;
|
||||
|
||||
if(hasCustomName(type, treasureName)) {
|
||||
customName = config.getString(type + "." + treasureName + ".Custom_Name");
|
||||
}
|
||||
|
||||
if (materialName.contains("POTION")) {
|
||||
Material mat = Material.matchMaterial(materialName);
|
||||
if (mat == null) {
|
||||
reason.add("Potion format for Treasures.yml has changed");
|
||||
} else {
|
||||
item = new ItemStack(mat, amount, data);
|
||||
PotionMeta itemMeta = (PotionMeta) item.getItemMeta();
|
||||
|
||||
PotionType potionType = null;
|
||||
try {
|
||||
potionType = PotionType.valueOf(config.getString(type + "." + treasureName + ".PotionData.PotionType", "WATER"));
|
||||
} catch (IllegalArgumentException ex) {
|
||||
reason.add("Invalid Potion_Type: " + config.getString(type + "." + treasureName + ".PotionData.PotionType", "WATER"));
|
||||
}
|
||||
boolean extended = config.getBoolean(type + "." + treasureName + ".PotionData.Extended", false);
|
||||
boolean upgraded = config.getBoolean(type + "." + treasureName + ".PotionData.Upgraded", false);
|
||||
itemMeta.setBasePotionData(new PotionData(potionType, extended, upgraded));
|
||||
|
||||
if (customName != null) {
|
||||
itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', customName));
|
||||
}
|
||||
|
||||
if (config.contains(type + "." + treasureName + ".Lore")) {
|
||||
List<String> lore = new ArrayList<>();
|
||||
for (String s : config.getStringList(type + "." + treasureName + ".Lore")) {
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', s));
|
||||
}
|
||||
itemMeta.setLore(lore);
|
||||
}
|
||||
item.setItemMeta(itemMeta);
|
||||
}
|
||||
} else if (material != null) {
|
||||
if(material == Material.ENCHANTED_BOOK) {
|
||||
//If any whitelisted enchants exist we use whitelist-based matching
|
||||
item = new ItemStack(material, 1);
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
|
||||
List<String> allowedEnchantsList = config.getStringList(type + "." + treasureName + ".Enchantments_Whitelist");
|
||||
List<String> disallowedEnchantsList = config.getStringList(type + "." + treasureName + ".Enchantments_Blacklist");
|
||||
|
||||
Set<Enchantment> blackListedEnchants = new HashSet<>();
|
||||
Set<Enchantment> whiteListedEnchants = new HashSet<>();
|
||||
|
||||
matchAndFillSet(disallowedEnchantsList, blackListedEnchants);
|
||||
matchAndFillSet(allowedEnchantsList, whiteListedEnchants);
|
||||
|
||||
if (customName != null && itemMeta != null) {
|
||||
itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', customName));
|
||||
item.setItemMeta(itemMeta);
|
||||
}
|
||||
|
||||
FishingTreasureBook fishingTreasureBook = new FishingTreasureBook(item, xp, blackListedEnchants, whiteListedEnchants);
|
||||
//TODO: Add book support for shake
|
||||
continue; //The code in this whole file is a disaster, ignore this hacky solution :P
|
||||
} else {
|
||||
item = new ItemStack(material, amount, data);
|
||||
|
||||
if (customName != null) {
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', customName));
|
||||
item.setItemMeta(itemMeta);
|
||||
}
|
||||
|
||||
if (config.contains(type + "." + treasureName + ".Lore")) {
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
List<String> lore = new ArrayList<>();
|
||||
for (String s : config.getStringList(type + "." + treasureName + ".Lore")) {
|
||||
lore.add(ChatColor.translateAlternateColorCodes('&', s));
|
||||
}
|
||||
itemMeta.setLore(lore);
|
||||
item.setItemMeta(itemMeta);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (noErrorsInConfig(reason)) {
|
||||
if (isFishing) {
|
||||
fishingRewards.get(rarity).add(new FishingTreasure(item, xp));
|
||||
} else if (isShake) {
|
||||
ShakeTreasure shakeTreasure = new ShakeTreasure(item, xp, dropChance, dropLevel);
|
||||
|
||||
EntityType entityType = EntityType.valueOf(type.substring(6));
|
||||
if (!shakeMap.containsKey(entityType))
|
||||
shakeMap.put(entityType, new ArrayList<>());
|
||||
shakeMap.get(entityType).add(shakeTreasure);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasCustomName(@NotNull String type, @NotNull String treasureName) {
|
||||
return config.contains(type + "." + treasureName + ".Custom_Name");
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches enchantments on a list (user provided string) to known enchantments in the Spigot API
|
||||
* Any matches are added to the passed set
|
||||
* @param enchantListStr the users string list of enchantments
|
||||
* @param permissiveList the permissive list of enchantments
|
||||
*/
|
||||
private void matchAndFillSet(List<String> enchantListStr, Set<Enchantment> permissiveList) {
|
||||
if(enchantListStr.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for(String str : enchantListStr) {
|
||||
boolean foundMatch = false;
|
||||
for(Enchantment enchantment : Enchantment.values()) {
|
||||
if(enchantment.getKey().getKey().equalsIgnoreCase(str)) {
|
||||
permissiveList.add(enchantment);
|
||||
foundMatch = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!foundMatch) {
|
||||
mcMMO.p.getLogger().info("[Fishing Treasure Init] Could not find any enchantments which matched the user defined enchantment named: "+str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadEnchantments() {
|
||||
for (Rarity rarity : Rarity.values()) {
|
||||
if (!fishingEnchantments.containsKey(rarity)) {
|
||||
fishingEnchantments.put(rarity, (new ArrayList<>()));
|
||||
}
|
||||
|
||||
ConfigurationSection enchantmentSection = config.getConfigurationSection("Enchantments_Rarity." + rarity.toString());
|
||||
|
||||
if (enchantmentSection == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (String enchantmentName : enchantmentSection.getKeys(false)) {
|
||||
int level = config.getInt("Enchantments_Rarity." + rarity.toString() + "." + enchantmentName);
|
||||
Enchantment enchantment = EnchantmentUtils.getByName(enchantmentName);
|
||||
|
||||
if (enchantment == null) {
|
||||
plugin.getLogger().warning("Skipping invalid enchantment in " + FILENAME + ": " + enchantmentName);
|
||||
continue;
|
||||
}
|
||||
|
||||
fishingEnchantments.get(rarity).add(new EnchantmentTreasure(enchantment, level));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getInventoryStealEnabled() {
|
||||
return config.contains("Shake.PLAYER.INVENTORY");
|
||||
}
|
||||
|
||||
public boolean getInventoryStealStacks() {
|
||||
return config.getBoolean("Shake.PLAYER.INVENTORY.Whole_Stacks");
|
||||
}
|
||||
|
||||
public double getInventoryStealDropChance() {
|
||||
return config.getDouble("Shake.PLAYER.INVENTORY.Drop_Chance");
|
||||
}
|
||||
|
||||
public int getInventoryStealDropLevel() {
|
||||
return config.getInt("Shake.PLAYER.INVENTORY.Drop_Level");
|
||||
}
|
||||
|
||||
public double getItemDropRate(int tier, Rarity rarity) {
|
||||
return config.getDouble("Item_Drop_Rates.Tier_" + tier + "." + rarity.toString());
|
||||
}
|
||||
|
||||
public double getEnchantmentDropRate(int tier, Rarity rarity) {
|
||||
return config.getDouble("Enchantment_Drop_Rates.Tier_" + tier + "." + rarity.toString());
|
||||
}
|
||||
}
|
@ -1,14 +1,14 @@
|
||||
package com.gmail.nossr50.config.treasure;
|
||||
|
||||
import com.gmail.nossr50.config.ConfigLoader;
|
||||
import com.gmail.nossr50.datatypes.treasure.*;
|
||||
import com.gmail.nossr50.util.EnchantmentUtils;
|
||||
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
|
||||
import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
|
||||
import com.gmail.nossr50.datatypes.treasure.Rarity;
|
||||
import com.gmail.nossr50.util.text.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@ -22,18 +22,14 @@ import java.util.List;
|
||||
|
||||
public class TreasureConfig extends ConfigLoader {
|
||||
|
||||
public static final String FILENAME = "treasures.yml";
|
||||
private static TreasureConfig instance;
|
||||
|
||||
public HashMap<String, List<ExcavationTreasure>> excavationMap = new HashMap<>();
|
||||
|
||||
public HashMap<EntityType, List<ShakeTreasure>> shakeMap = new HashMap<>();
|
||||
public HashMap<String, List<HylianTreasure>> hylianMap = new HashMap<>();
|
||||
|
||||
public HashMap<Rarity, List<FishingTreasure>> fishingRewards = new HashMap<>();
|
||||
public HashMap<Rarity, List<EnchantmentTreasure>> fishingEnchantments = new HashMap<>();
|
||||
|
||||
private TreasureConfig() {
|
||||
super("treasures.yml");
|
||||
super(FILENAME);
|
||||
loadKeys();
|
||||
validate();
|
||||
}
|
||||
@ -51,29 +47,18 @@ public class TreasureConfig extends ConfigLoader {
|
||||
// Validate all the settings!
|
||||
List<String> reason = new ArrayList<>();
|
||||
for (String tier : config.getConfigurationSection("Enchantment_Drop_Rates").getKeys(false)) {
|
||||
double totalEnchantDropRate = 0;
|
||||
double totalItemDropRate = 0;
|
||||
|
||||
for (Rarity rarity : Rarity.values()) {
|
||||
double enchantDropRate = config.getDouble("Enchantment_Drop_Rates." + tier + "." + rarity.toString());
|
||||
double itemDropRate = config.getDouble("Item_Drop_Rates." + tier + "." + rarity.toString());
|
||||
|
||||
if ((enchantDropRate < 0.0 || enchantDropRate > 100.0) && rarity != Rarity.RECORD) {
|
||||
reason.add("The enchant drop rate for " + tier + " items that are " + rarity.toString() + "should be between 0.0 and 100.0!");
|
||||
}
|
||||
|
||||
if (itemDropRate < 0.0 || itemDropRate > 100.0) {
|
||||
reason.add("The item drop rate for " + tier + " items that are " + rarity.toString() + "should be between 0.0 and 100.0!");
|
||||
}
|
||||
|
||||
totalEnchantDropRate += enchantDropRate;
|
||||
totalItemDropRate += itemDropRate;
|
||||
}
|
||||
|
||||
if (totalEnchantDropRate < 0 || totalEnchantDropRate > 100.0) {
|
||||
reason.add("The total enchant drop rate for " + tier + " should be between 0.0 and 100.0!");
|
||||
}
|
||||
|
||||
if (totalItemDropRate < 0 || totalItemDropRate > 100.0) {
|
||||
reason.add("The total item drop rate for " + tier + " should be between 0.0 and 100.0!");
|
||||
}
|
||||
@ -92,7 +77,6 @@ public class TreasureConfig extends ConfigLoader {
|
||||
loadTreasures("Fishing");
|
||||
loadTreasures("Excavation");
|
||||
loadTreasures("Hylian_Luck");
|
||||
loadEnchantments();
|
||||
|
||||
for (EntityType entity : EntityType.values()) {
|
||||
if (entity.isAlive()) {
|
||||
@ -102,8 +86,6 @@ public class TreasureConfig extends ConfigLoader {
|
||||
}
|
||||
|
||||
private void loadTreasures(String type) {
|
||||
boolean isFishing = type.equals("Fishing");
|
||||
boolean isShake = type.contains("Shake");
|
||||
boolean isExcavation = type.equals("Excavation");
|
||||
boolean isHylian = type.equals("Hylian_Luck");
|
||||
|
||||
@ -113,13 +95,6 @@ public class TreasureConfig extends ConfigLoader {
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialize fishing HashMap
|
||||
for (Rarity rarity : Rarity.values()) {
|
||||
if (!fishingRewards.containsKey(rarity)) {
|
||||
fishingRewards.put(rarity, (new ArrayList<>()));
|
||||
}
|
||||
}
|
||||
|
||||
for (String treasureName : treasureSection.getKeys(false)) {
|
||||
// Validate all the things!
|
||||
List<String> reason = new ArrayList<>();
|
||||
@ -131,16 +106,7 @@ public class TreasureConfig extends ConfigLoader {
|
||||
* Material, Amount, and Data
|
||||
*/
|
||||
Material material;
|
||||
|
||||
if (materialName.contains("INVENTORY")) {
|
||||
// Use magic material BEDROCK to know that we're grabbing something from the inventory and not a normal treasure
|
||||
if (!shakeMap.containsKey(EntityType.PLAYER))
|
||||
shakeMap.put(EntityType.PLAYER, new ArrayList<>());
|
||||
shakeMap.get(EntityType.PLAYER).add(new ShakeTreasure(new ItemStack(Material.BEDROCK, 1, (byte) 0), 1, getInventoryStealDropChance(), getInventoryStealDropLevel()));
|
||||
continue;
|
||||
} else {
|
||||
material = Material.matchMaterial(materialName);
|
||||
}
|
||||
material = Material.matchMaterial(materialName);
|
||||
|
||||
int amount = config.getInt(type + "." + treasureName + ".Amount");
|
||||
short data = (treasureInfo.length == 2) ? Short.parseShort(treasureInfo[1]) : (short) config.getInt(type + "." + treasureName + ".Data");
|
||||
@ -177,19 +143,6 @@ public class TreasureConfig extends ConfigLoader {
|
||||
reason.add(treasureName + " has an invalid Drop_Level: " + dropLevel);
|
||||
}
|
||||
|
||||
/*
|
||||
* Specific Types
|
||||
*/
|
||||
Rarity rarity = null;
|
||||
|
||||
if (isFishing) {
|
||||
rarity = Rarity.getRarity(config.getString(type + "." + treasureName + ".Rarity"));
|
||||
|
||||
if (rarity == null) {
|
||||
reason.add("Invalid Rarity for item: " + treasureName);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Itemstack
|
||||
*/
|
||||
@ -198,7 +151,7 @@ public class TreasureConfig extends ConfigLoader {
|
||||
if (materialName.contains("POTION")) {
|
||||
Material mat = Material.matchMaterial(materialName);
|
||||
if (mat == null) {
|
||||
reason.add("Potion format for Treasures.yml has changed");
|
||||
reason.add("Potion format for " + FILENAME + " has changed");
|
||||
} else {
|
||||
item = new ItemStack(mat, amount, data);
|
||||
PotionMeta itemMeta = (PotionMeta) item.getItemMeta();
|
||||
@ -247,16 +200,7 @@ public class TreasureConfig extends ConfigLoader {
|
||||
}
|
||||
|
||||
if (noErrorsInConfig(reason)) {
|
||||
if (isFishing) {
|
||||
fishingRewards.get(rarity).add(new FishingTreasure(item, xp));
|
||||
} else if (isShake) {
|
||||
ShakeTreasure shakeTreasure = new ShakeTreasure(item, xp, dropChance, dropLevel);
|
||||
|
||||
EntityType entityType = EntityType.valueOf(type.substring(6));
|
||||
if (!shakeMap.containsKey(entityType))
|
||||
shakeMap.put(entityType, new ArrayList<>());
|
||||
shakeMap.get(entityType).add(shakeTreasure);
|
||||
} else if (isExcavation) {
|
||||
if (isExcavation) {
|
||||
ExcavationTreasure excavationTreasure = new ExcavationTreasure(item, xp, dropChance, dropLevel);
|
||||
List<String> dropList = config.getStringList(type + "." + treasureName + ".Drops_From");
|
||||
|
||||
@ -309,36 +253,6 @@ public class TreasureConfig extends ConfigLoader {
|
||||
hylianMap.get(dropper).add(treasure);
|
||||
}
|
||||
|
||||
private void loadEnchantments() {
|
||||
for (Rarity rarity : Rarity.values()) {
|
||||
if (rarity == Rarity.RECORD) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!fishingEnchantments.containsKey(rarity)) {
|
||||
fishingEnchantments.put(rarity, (new ArrayList<>()));
|
||||
}
|
||||
|
||||
ConfigurationSection enchantmentSection = config.getConfigurationSection("Enchantments_Rarity." + rarity.toString());
|
||||
|
||||
if (enchantmentSection == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (String enchantmentName : enchantmentSection.getKeys(false)) {
|
||||
int level = config.getInt("Enchantments_Rarity." + rarity.toString() + "." + enchantmentName);
|
||||
Enchantment enchantment = EnchantmentUtils.getByName(enchantmentName);
|
||||
|
||||
if (enchantment == null) {
|
||||
plugin.getLogger().warning("Skipping invalid enchantment in treasures.yml: " + enchantmentName);
|
||||
continue;
|
||||
}
|
||||
|
||||
fishingEnchantments.get(rarity).add(new EnchantmentTreasure(enchantment, level));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getInventoryStealEnabled() {
|
||||
return config.contains("Shake.PLAYER.INVENTORY");
|
||||
}
|
||||
|
@ -56,7 +56,6 @@ import com.gmail.nossr50.util.sounds.SoundManager;
|
||||
import com.gmail.nossr50.util.sounds.SoundType;
|
||||
import net.kyori.adventure.identity.Identified;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
|
@ -0,0 +1,44 @@
|
||||
package com.gmail.nossr50.datatypes.treasure;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EnchantmentWrapper {
|
||||
private final @NotNull Enchantment enchantment;
|
||||
private final int enchantmentLevel;
|
||||
|
||||
public EnchantmentWrapper(@NotNull Enchantment enchantment, int enchantmentLevel) {
|
||||
this.enchantment = enchantment;
|
||||
this.enchantmentLevel = enchantmentLevel;
|
||||
}
|
||||
|
||||
public @NotNull Enchantment getEnchantment() {
|
||||
return enchantment;
|
||||
}
|
||||
|
||||
public int getEnchantmentLevel() {
|
||||
return enchantmentLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EnchantmentWrapper{" +
|
||||
"enchantment=" + enchantment +
|
||||
", enchantmentLevel=" + enchantmentLevel +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
EnchantmentWrapper that = (EnchantmentWrapper) o;
|
||||
return enchantmentLevel == that.enchantmentLevel && Objects.equal(enchantment, that.enchantment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(enchantment, enchantmentLevel);
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package com.gmail.nossr50.datatypes.treasure;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class FishingTreasureBook extends FishingTreasure {
|
||||
private final @Nullable Set<Enchantment> blackListedEnchantments;
|
||||
private final @Nullable Set<Enchantment> whiteListedEnchantments;
|
||||
private final @NotNull List<EnchantmentWrapper> legalEnchantments; //TODO: Make immutable
|
||||
|
||||
public FishingTreasureBook(@NotNull ItemStack enchantedBook, int xp, @Nullable Set<Enchantment> blackListedEnchantments, @Nullable Set<Enchantment> whiteListedEnchantments) {
|
||||
super(enchantedBook, xp);
|
||||
|
||||
this.blackListedEnchantments = blackListedEnchantments;
|
||||
this.whiteListedEnchantments = whiteListedEnchantments;
|
||||
this.legalEnchantments = new ArrayList<>();
|
||||
|
||||
initLegalEnchantments();
|
||||
}
|
||||
|
||||
private void initLegalEnchantments() {
|
||||
mcMMO.p.getLogger().info("Registering enchantments for Fishing Book...");
|
||||
|
||||
for(Enchantment enchantment : Enchantment.values()) {
|
||||
if(isEnchantAllowed(enchantment)) {
|
||||
addAllLegalEnchants(enchantment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the enchantments which can drop for this book
|
||||
* This list can be empty, but should in practice never be empty...
|
||||
*
|
||||
* @return all the enchantments that can drop for this book
|
||||
*/
|
||||
public @NotNull List<EnchantmentWrapper> getLegalEnchantments() {
|
||||
return legalEnchantments;
|
||||
}
|
||||
|
||||
private @Nullable Set<Enchantment> getBlacklistedEnchantments() {
|
||||
return blackListedEnchantments;
|
||||
}
|
||||
|
||||
private @Nullable Set<Enchantment> getWhitelistedEnchantments() {
|
||||
return whiteListedEnchantments;
|
||||
}
|
||||
|
||||
private void addAllLegalEnchants(@NotNull Enchantment enchantment) {
|
||||
int legalEnchantCap = enchantment.getMaxLevel();
|
||||
|
||||
for(int i = 0; i < legalEnchantCap; i++) {
|
||||
int enchantLevel = i+1;
|
||||
EnchantmentWrapper enchantmentWrapper = new EnchantmentWrapper(enchantment, enchantLevel);
|
||||
legalEnchantments.add(enchantmentWrapper);
|
||||
mcMMO.p.getLogger().info("Fishing treasure book enchantment added: " + enchantmentWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isEnchantAllowed(@NotNull Enchantment enchantment) {
|
||||
if(whiteListedEnchantments != null && !whiteListedEnchantments.isEmpty()) {
|
||||
return whiteListedEnchantments.contains(enchantment);
|
||||
} else if(blackListedEnchantments != null && !blackListedEnchantments.isEmpty()) {
|
||||
return !blackListedEnchantments.contains(enchantment);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +1,16 @@
|
||||
package com.gmail.nossr50.datatypes.treasure;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public enum Rarity {
|
||||
RECORD,
|
||||
MYTHIC,
|
||||
LEGENDARY,
|
||||
EPIC,
|
||||
RARE,
|
||||
UNCOMMON,
|
||||
COMMON;
|
||||
|
||||
public static Rarity getRarity(String string) {
|
||||
public static @NotNull Rarity getRarity(@NotNull String string) {
|
||||
try {
|
||||
return valueOf(string);
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import com.gmail.nossr50.config.mods.ToolConfigManager;
|
||||
import com.gmail.nossr50.config.skills.alchemy.PotionConfig;
|
||||
import com.gmail.nossr50.config.skills.repair.RepairConfigManager;
|
||||
import com.gmail.nossr50.config.skills.salvage.SalvageConfigManager;
|
||||
import com.gmail.nossr50.config.treasure.FishingTreasureConfig;
|
||||
import com.gmail.nossr50.config.treasure.TreasureConfig;
|
||||
import com.gmail.nossr50.database.DatabaseManager;
|
||||
import com.gmail.nossr50.database.DatabaseManagerFactory;
|
||||
@ -517,6 +518,7 @@ public class mcMMO extends JavaPlugin {
|
||||
private void loadConfigFiles() {
|
||||
// Force the loading of config files
|
||||
TreasureConfig.getInstance();
|
||||
FishingTreasureConfig.getInstance();
|
||||
HiddenConfig.getInstance();
|
||||
AdvancedConfig.getInstance();
|
||||
PotionConfig.getInstance();
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.gmail.nossr50.skills.fishing;
|
||||
|
||||
import com.gmail.nossr50.config.treasure.TreasureConfig;
|
||||
import com.gmail.nossr50.config.treasure.FishingTreasureConfig;
|
||||
import com.gmail.nossr50.datatypes.treasure.ShakeTreasure;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.adapter.BiomeAdapter;
|
||||
@ -31,8 +31,8 @@ public final class Fishing {
|
||||
* @return possibleDrops List of ItemStack that can be dropped
|
||||
*/
|
||||
protected static List<ShakeTreasure> findPossibleDrops(LivingEntity target) {
|
||||
if (TreasureConfig.getInstance().shakeMap.containsKey(target.getType()))
|
||||
return TreasureConfig.getInstance().shakeMap.get(target.getType());
|
||||
if (FishingTreasureConfig.getInstance().shakeMap.containsKey(target.getType()))
|
||||
return FishingTreasureConfig.getInstance().shakeMap.get(target.getType());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -4,16 +4,14 @@ import com.gmail.nossr50.api.ItemSpawnReason;
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
||||
import com.gmail.nossr50.config.treasure.FishingTreasureConfig;
|
||||
import com.gmail.nossr50.config.treasure.TreasureConfig;
|
||||
import com.gmail.nossr50.datatypes.experience.XPGainReason;
|
||||
import com.gmail.nossr50.datatypes.interactions.NotificationType;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.datatypes.treasure.EnchantmentTreasure;
|
||||
import com.gmail.nossr50.datatypes.treasure.FishingTreasure;
|
||||
import com.gmail.nossr50.datatypes.treasure.Rarity;
|
||||
import com.gmail.nossr50.datatypes.treasure.ShakeTreasure;
|
||||
import com.gmail.nossr50.datatypes.treasure.*;
|
||||
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerFishingTreasureEvent;
|
||||
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerShakeEvent;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
@ -40,10 +38,12 @@ import org.bukkit.entity.*;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -370,9 +370,7 @@ public class FishingManager extends SkillManager {
|
||||
return AdvancedConfig.getInstance().getFishingBoatReductionMaxWaitTicks();
|
||||
}
|
||||
|
||||
|
||||
public boolean isMagicHunterEnabled()
|
||||
{
|
||||
public boolean isMagicHunterEnabled() {
|
||||
return RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.FISHING_MAGIC_HUNTER)
|
||||
&& RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.FISHING_TREASURE_HUNTER)
|
||||
&& Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.FISHING_TREASURE_HUNTER);
|
||||
@ -383,12 +381,14 @@ public class FishingManager extends SkillManager {
|
||||
*
|
||||
* @param fishingCatch The {@link Item} initially caught
|
||||
*/
|
||||
public void handleFishing(Item fishingCatch) {
|
||||
public void handleFishing(@NotNull Item fishingCatch) {
|
||||
this.fishingCatch = fishingCatch;
|
||||
int fishXp = ExperienceConfig.getInstance().getXp(PrimarySkillType.FISHING, fishingCatch.getItemStack().getType());
|
||||
int treasureXp = 0;
|
||||
ItemStack treasureDrop = null;
|
||||
Player player = getPlayer();
|
||||
FishingTreasure treasure = null;
|
||||
boolean fishingSucceeds = false;
|
||||
|
||||
if (Config.getInstance().getFishingDropsEnabled() && Permissions.isSubSkillEnabled(player, SubSkillType.FISHING_TREASURE_HUNTER)) {
|
||||
treasure = getFishingTreasure();
|
||||
@ -396,49 +396,92 @@ public class FishingManager extends SkillManager {
|
||||
}
|
||||
|
||||
if (treasure != null) {
|
||||
ItemStack treasureDrop = treasure.getDrop().clone(); // Not cloning is bad, m'kay?
|
||||
Map<Enchantment, Integer> enchants = new HashMap<>();
|
||||
if(treasure instanceof FishingTreasureBook) {
|
||||
treasureDrop = createEnchantBook((FishingTreasureBook) treasure);
|
||||
} else {
|
||||
treasureDrop = treasure.getDrop().clone(); // Not cloning is bad, m'kay?
|
||||
|
||||
if (isMagicHunterEnabled()
|
||||
&& ItemUtils.isEnchantable(treasureDrop)) {
|
||||
enchants = handleMagicHunter(treasureDrop);
|
||||
}
|
||||
Map<Enchantment, Integer> enchants = new HashMap<>();
|
||||
McMMOPlayerFishingTreasureEvent event;
|
||||
|
||||
McMMOPlayerFishingTreasureEvent event = EventUtils.callFishingTreasureEvent(player, treasureDrop, treasure.getXp(), enchants);
|
||||
/*
|
||||
* Books get some special treatment
|
||||
*/
|
||||
if(treasure instanceof FishingTreasureBook) {
|
||||
//Skip the magic hunter stuff
|
||||
if(treasureDrop.getItemMeta() != null) {
|
||||
enchants.putAll(treasureDrop.getItemMeta().getEnchants());
|
||||
}
|
||||
|
||||
event = EventUtils.callFishingTreasureEvent(player, treasureDrop, treasure.getXp(), enchants);
|
||||
} else {
|
||||
if (isMagicHunterEnabled() && ItemUtils.isEnchantable(treasureDrop)) {
|
||||
enchants = processMagicHunter(treasureDrop);
|
||||
}
|
||||
|
||||
event = EventUtils.callFishingTreasureEvent(player, treasureDrop, treasure.getXp(), enchants);
|
||||
}
|
||||
|
||||
if (!event.isCancelled()) {
|
||||
treasureDrop = event.getTreasure();
|
||||
treasureXp = event.getXp();
|
||||
}
|
||||
else {
|
||||
|
||||
// Drop the original catch at the feet of the player and set the treasure as the real catch
|
||||
if (treasureDrop != null) {
|
||||
fishingSucceeds = true;
|
||||
boolean enchanted = false;
|
||||
|
||||
if(treasure instanceof FishingTreasureBook) {
|
||||
enchanted = true;
|
||||
} else if (!enchants.isEmpty()) {
|
||||
treasureDrop.addUnsafeEnchantments(enchants);
|
||||
enchanted = true;
|
||||
}
|
||||
|
||||
if (enchanted) {
|
||||
NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE, "Fishing.Ability.TH.MagicFound");
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
treasureDrop = null;
|
||||
treasureXp = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Drop the original catch at the feet of the player and set the treasure as the real catch
|
||||
if (treasureDrop != null) {
|
||||
boolean enchanted = false;
|
||||
if(fishingSucceeds) {
|
||||
fishingCatch.setItemStack(treasureDrop);
|
||||
|
||||
if (!enchants.isEmpty()) {
|
||||
treasureDrop.addUnsafeEnchantments(enchants);
|
||||
enchanted = true;
|
||||
}
|
||||
|
||||
if (enchanted) {
|
||||
NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE, "Fishing.Ability.TH.MagicFound");
|
||||
}
|
||||
|
||||
if (Config.getInstance().getFishingExtraFish()) {
|
||||
Misc.spawnItem(player.getEyeLocation(), fishingCatch.getItemStack(), ItemSpawnReason.FISHING_EXTRA_FISH);
|
||||
}
|
||||
|
||||
fishingCatch.setItemStack(treasureDrop);
|
||||
if (Config.getInstance().getFishingExtraFish()) {
|
||||
Misc.spawnItem(player.getEyeLocation(), fishingCatch.getItemStack(), ItemSpawnReason.FISHING_EXTRA_FISH);
|
||||
}
|
||||
}
|
||||
|
||||
applyXpGain(fishXp + treasureXp, XPGainReason.PVE);
|
||||
}
|
||||
|
||||
|
||||
private @NotNull ItemStack createEnchantBook(@NotNull FishingTreasureBook fishingTreasureBook) {
|
||||
ItemStack itemStack = fishingTreasureBook.getDrop().clone();
|
||||
EnchantmentWrapper enchantmentWrapper = getRandomEnchantment(fishingTreasureBook.getLegalEnchantments());
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
if(itemMeta == null)
|
||||
return itemStack;
|
||||
|
||||
itemMeta.addEnchant(enchantmentWrapper.getEnchantment(), enchantmentWrapper.getEnchantmentLevel(), ExperienceConfig.getInstance().allowUnsafeEnchantments());
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
private @NotNull EnchantmentWrapper getRandomEnchantment(@NotNull List<EnchantmentWrapper> enchantmentWrappers) {
|
||||
Collections.shuffle(enchantmentWrappers, Misc.getRandom());
|
||||
|
||||
int randomIndex = Misc.getRandom().nextInt(enchantmentWrappers.size());
|
||||
return enchantmentWrappers.get(randomIndex+1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the vanilla XP boost for Fishing
|
||||
*
|
||||
@ -548,7 +591,7 @@ public class FishingManager extends SkillManager {
|
||||
*
|
||||
* @return The {@link FishingTreasure} found, or null if no treasure was found.
|
||||
*/
|
||||
private FishingTreasure getFishingTreasure() {
|
||||
private @Nullable FishingTreasure getFishingTreasure() {
|
||||
double diceRoll = Misc.getRandom().nextDouble() * 100;
|
||||
int luck;
|
||||
|
||||
@ -569,12 +612,8 @@ public class FishingManager extends SkillManager {
|
||||
double dropRate = TreasureConfig.getInstance().getItemDropRate(getLootTier(), rarity);
|
||||
|
||||
if (diceRoll <= dropRate) {
|
||||
/*if (rarity == Rarity.TRAP) {
|
||||
handleTraps();
|
||||
break;
|
||||
}*/
|
||||
|
||||
List<FishingTreasure> fishingTreasures = TreasureConfig.getInstance().fishingRewards.get(rarity);
|
||||
List<FishingTreasure> fishingTreasures = FishingTreasureConfig.getInstance().fishingRewards.get(rarity);
|
||||
|
||||
if (fishingTreasures.isEmpty()) {
|
||||
return null;
|
||||
@ -612,19 +651,14 @@ public class FishingManager extends SkillManager {
|
||||
* Process the Magic Hunter ability
|
||||
*
|
||||
* @param treasureDrop The {@link ItemStack} to enchant
|
||||
*
|
||||
* @return true if the item has been enchanted
|
||||
*/
|
||||
private Map<Enchantment, Integer> handleMagicHunter(ItemStack treasureDrop) {
|
||||
private Map<Enchantment, Integer> processMagicHunter(@NotNull ItemStack treasureDrop) {
|
||||
Map<Enchantment, Integer> enchants = new HashMap<>();
|
||||
List<EnchantmentTreasure> fishingEnchantments = null;
|
||||
|
||||
double diceRoll = Misc.getRandom().nextDouble() * 100;
|
||||
|
||||
for (Rarity rarity : Rarity.values()) {
|
||||
if (rarity == Rarity.RECORD) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double dropRate = TreasureConfig.getInstance().getEnchantmentDropRate(getLootTier(), rarity);
|
||||
|
||||
@ -634,7 +668,8 @@ public class FishingManager extends SkillManager {
|
||||
diceRoll = dropRate + 1;
|
||||
continue;
|
||||
}
|
||||
fishingEnchantments = TreasureConfig.getInstance().fishingEnchantments.get(rarity);
|
||||
|
||||
fishingEnchantments = FishingTreasureConfig.getInstance().fishingEnchantments.get(rarity);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
||||
import com.gmail.nossr50.datatypes.experience.XPGainReason;
|
||||
import com.gmail.nossr50.datatypes.experience.XPGainSource;
|
||||
import com.gmail.nossr50.datatypes.party.Party;
|
||||
|
@ -142,6 +142,15 @@ public final class CommandRegistrationManager {
|
||||
command.setExecutor(new McgodCommand());
|
||||
}
|
||||
|
||||
// private static void registerDropTreasureCommand() {
|
||||
// PluginCommand command = mcMMO.p.getCommand("mmodroptreasures");
|
||||
// command.setDescription(LocaleLoader.getString("Commands.Description.droptreasures"));
|
||||
// command.setPermission("mcmmo.commands.droptreasures");
|
||||
// command.setPermissionMessage(permissionsMessage);
|
||||
// command.setUsage(LocaleLoader.getString("Commands.Usage.0", "mcgod"));
|
||||
// command.setExecutor(new DropTreasureCommand());
|
||||
// }
|
||||
|
||||
private static void registerMmoInfoCommand() {
|
||||
PluginCommand command = mcMMO.p.getCommand("mmoinfo");
|
||||
command.setDescription(LocaleLoader.getString("Commands.Description.mmoinfo"));
|
||||
|
Reference in New Issue
Block a user