Fix a bug where books weren't registered + tweaked how treasures were loaded

This commit is contained in:
nossr50 2020-12-29 12:39:06 -08:00
parent 0f4455d5a8
commit d9f98b1aa9
4 changed files with 74 additions and 54 deletions

View File

@ -15,6 +15,7 @@ import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
@ -94,7 +95,7 @@ public class FishingTreasureConfig extends ConfigLoader {
}
}
private void loadTreasures(String type) {
private void loadTreasures(@NotNull String type) {
boolean isFishing = type.equals("Fishing");
boolean isShake = type.contains("Shake");
@ -125,9 +126,7 @@ public class FishingTreasureConfig extends ConfigLoader {
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()));
addShakeTreasure(new ShakeTreasure(new ItemStack(Material.BEDROCK, 1, (byte) 0), 1, getInventoryStealDropChance(), getInventoryStealDropLevel()), EntityType.PLAYER);
continue;
} else {
material = Material.matchMaterial(materialName);
@ -145,7 +144,7 @@ public class FishingTreasureConfig extends ConfigLoader {
amount = 1;
}
if (material != null && material.isBlock() && (data > 127 || data < -128)) {
if (material.isBlock() && (data > 127 || data < -128)) {
reason.add("Data of " + treasureName + " is invalid! " + data);
}
@ -175,10 +174,14 @@ public class FishingTreasureConfig extends ConfigLoader {
Rarity rarity = null;
if (isFishing) {
rarity = Rarity.getRarity(config.getString(type + "." + treasureName + ".Rarity"));
String rarityStr = config.getString(type + "." + treasureName + ".Rarity");
if (rarity == null) {
reason.add("Invalid Rarity for item: " + treasureName);
if(rarityStr != null) {
rarity = Rarity.getRarity(rarityStr);
} else {
mcMMO.p.getLogger().severe("Please edit your config and add a Rarity definition for - " + treasureName);
mcMMO.p.getLogger().severe("Skipping this treasure until rarity is defined - " + treasureName);
continue;
}
}
@ -202,6 +205,11 @@ public class FishingTreasureConfig extends ConfigLoader {
item = new ItemStack(mat, amount, data);
PotionMeta itemMeta = (PotionMeta) item.getItemMeta();
if(itemMeta == null) {
mcMMO.p.getLogger().severe("Item meta when adding potion to fishing treasure was null, contact the mcMMO devs!");
continue;
}
PotionType potionType = null;
try {
potionType = PotionType.valueOf(config.getString(type + "." + treasureName + ".PotionData.PotionType", "WATER"));
@ -225,8 +233,7 @@ public class FishingTreasureConfig extends ConfigLoader {
}
item.setItemMeta(itemMeta);
}
} else if (material != null) {
if(material == Material.ENCHANTED_BOOK) {
} else if(material == Material.ENCHANTED_BOOK) {
//If any whitelisted enchants exist we use whitelist-based matching
item = new ItemStack(material, 1);
ItemMeta itemMeta = item.getItemMeta();
@ -246,6 +253,7 @@ public class FishingTreasureConfig extends ConfigLoader {
}
FishingTreasureBook fishingTreasureBook = new FishingTreasureBook(item, xp, blackListedEnchants, whiteListedEnchants);
addFishingTreasure(rarity, fishingTreasureBook);
//TODO: Add book support for shake
continue; //The code in this whole file is a disaster, ignore this hacky solution :P
} else {
@ -268,22 +276,29 @@ public class FishingTreasureConfig extends ConfigLoader {
}
}
}
if (noErrorsInConfig(reason)) {
if (isFishing) {
fishingRewards.get(rarity).add(new FishingTreasure(item, xp));
addFishingTreasure(rarity, new FishingTreasure(item, xp));
} else if (isShake) {
ShakeTreasure shakeTreasure = new ShakeTreasure(item, xp, dropChance, dropLevel);
EntityType entityType = EntityType.valueOf(type.substring(6));
addShakeTreasure(shakeTreasure, entityType);
}
}
}
}
private void addShakeTreasure(@NotNull ShakeTreasure shakeTreasure, @NotNull EntityType entityType) {
if (!shakeMap.containsKey(entityType))
shakeMap.put(entityType, new ArrayList<>());
shakeMap.get(entityType).add(shakeTreasure);
}
}
}
private void addFishingTreasure(@NotNull Rarity rarity, @NotNull FishingTreasure fishingTreasure) {
fishingRewards.get(rarity).add(fishingTreasure);
}
private boolean hasCustomName(@NotNull String type, @NotNull String treasureName) {
@ -296,7 +311,7 @@ public class FishingTreasureConfig extends ConfigLoader {
* @param enchantListStr the users string list of enchantments
* @param permissiveList the permissive list of enchantments
*/
private void matchAndFillSet(List<String> enchantListStr, Set<Enchantment> permissiveList) {
private void matchAndFillSet(@NotNull List<String> enchantListStr, @NotNull Set<Enchantment> permissiveList) {
if(enchantListStr.isEmpty()) {
return;
}
@ -359,11 +374,11 @@ public class FishingTreasureConfig extends ConfigLoader {
return config.getInt("Shake.PLAYER.INVENTORY.Drop_Level");
}
public double getItemDropRate(int tier, Rarity rarity) {
public double getItemDropRate(int tier, @NotNull Rarity rarity) {
return config.getDouble("Item_Drop_Rates.Tier_" + tier + "." + rarity.toString());
}
public double getEnchantmentDropRate(int tier, Rarity rarity) {
public double getEnchantmentDropRate(int tier, @NotNull Rarity rarity) {
return config.getDouble("Enchantment_Drop_Rates.Tier_" + tier + "." + rarity.toString());
}
}

View File

@ -1,5 +1,6 @@
package com.gmail.nossr50.datatypes.treasure;
import com.gmail.nossr50.mcMMO;
import org.jetbrains.annotations.NotNull;
public enum Rarity {
@ -11,6 +12,10 @@ public enum Rarity {
COMMON;
public static @NotNull Rarity getRarity(@NotNull String string) {
if(string.equalsIgnoreCase("Records")) {
mcMMO.p.getLogger().severe("Entries in fishing treasures have Records set as rarity, however Records was renamed to Mythic. Please update your treasures to read MYTHIC instead of RECORDS for rarity, or delete the config file to regenerate a new one.");
return Rarity.MYTHIC; //People that copy paste their configs will have Records interpretted as Mythic
}
try {
return valueOf(string);
}

View File

@ -419,7 +419,7 @@ public class PlayerListener implements Listener {
}
}
fishingManager.handleFishing((Item) caught);
fishingManager.processFishing((Item) caught);
fishingManager.setFishingTarget();
}
return;

View File

@ -380,7 +380,7 @@ public class FishingManager extends SkillManager {
*
* @param fishingCatch The {@link Item} initially caught
*/
public void handleFishing(@NotNull Item fishingCatch) {
public void processFishing(@NotNull Item fishingCatch) {
this.fishingCatch = fishingCatch;
int fishXp = ExperienceConfig.getInstance().getXp(PrimarySkillType.FISHING, fishingCatch.getItemStack().getType());
int treasureXp = 0;