fishing treasures pt 3 (shake)

This commit is contained in:
nossr50 2019-02-25 14:52:28 -08:00
parent 99f0e029c2
commit 677e45a811
2 changed files with 99 additions and 3 deletions

View File

@ -35,6 +35,7 @@ public class FishingTreasureConfig extends Config implements UnsafeValueValidati
public static final String CUSTOM_NAME = "Custom_Name"; public static final String CUSTOM_NAME = "Custom_Name";
public static final String LORE = "Lore"; public static final String LORE = "Lore";
public static final String RARITY = "Rarity"; public static final String RARITY = "Rarity";
public static final String DROPS_FROM = "Drops_From";
public HashMap<EntityType, List<ShakeTreasure>> shakeMap = new HashMap<EntityType, List<ShakeTreasure>>(); public HashMap<EntityType, List<ShakeTreasure>> shakeMap = new HashMap<EntityType, List<ShakeTreasure>>();
public HashMap<Rarity, List<FishingTreasure>> fishingRewards = new HashMap<Rarity, List<FishingTreasure>>(); public HashMap<Rarity, List<FishingTreasure>> fishingRewards = new HashMap<Rarity, List<FishingTreasure>>();
@ -103,7 +104,7 @@ public class FishingTreasureConfig extends Config implements UnsafeValueValidati
* PARAMETER INIT * PARAMETER INIT
*/ */
ArrayList<String> dropsFrom = new ArrayList(currentTreasure.getNode("Drops_From").getList(TypeToken.of(String.class))); ArrayList<String> dropsFrom = new ArrayList(currentTreasure.getNode(DROPS_FROM).getList(TypeToken.of(String.class)));
//VALIDATE AMOUNT //VALIDATE AMOUNT
if(amount <= 0) if(amount <= 0)
@ -153,8 +154,8 @@ public class FishingTreasureConfig extends Config implements UnsafeValueValidati
{ {
if(rarity.toString().equalsIgnoreCase(configRarity)) if(rarity.toString().equalsIgnoreCase(configRarity))
{ {
if(fishingRewards.get(rarity) == null) /*if(fishingRewards.get(rarity) == null)
fishingRewards.put(rarity, new ArrayList<>()); fishingRewards.put(rarity, new ArrayList<>());*/
fishingRewards.get(rarity).add(fishingTreasure); fishingRewards.get(rarity).add(fishingTreasure);
} }
@ -188,7 +189,94 @@ public class FishingTreasureConfig extends Config implements UnsafeValueValidati
try { try {
for (String treasureName : shakeTreasureNode.getList(TypeToken.of(String.class))) { for (String treasureName : shakeTreasureNode.getList(TypeToken.of(String.class))) {
//Treasure Material Definition
Material treasureMaterial = Material.matchMaterial(treasureName.toUpperCase());
if(treasureMaterial != null)
{
ConfigurationNode currentTreasure = shakeTreasureNode.getNode(treasureName);
//TODO: Rewrite the entire treasure system because it sucks
/*
* TREASURE PARAMETERS
*/
int amount = currentTreasure.getNode(AMOUNT).getInt();
int xp = currentTreasure.getNode(XP).getInt();
double dropChance = currentTreasure.getNode(DROP_CHANCE).getDouble();
int dropLevel = currentTreasure.getNode(DROP_LEVEL).getInt();
String customName = null;
/*
* PARAMETER INIT
*/
ArrayList<String> dropsFrom = new ArrayList(currentTreasure.getNode(DROPS_FROM).getList(TypeToken.of(String.class)));
//VALIDATE AMOUNT
if(amount <= 0)
{
mcMMO.p.getLogger().severe("Excavation Treasure named "+treasureName+" in the config has an amount of 0 or below, is this intentional?");
mcMMO.p.getLogger().severe("Skipping "+treasureName+" for being invalid");
continue;
}
//VALIDATE XP
if(xp <= 0)
{
mcMMO.p.getLogger().info("Excavation Treasure named "+treasureName+" in the config has xp set to 0 or below, is this intentional?");
xp = 0;
}
//VALIDATE DROP CHANCE
if(dropChance <= 0)
{
mcMMO.p.getLogger().severe("Excavation Treasure named "+treasureName+" in the config has a drop chance of 0 or below, is this intentional?");
mcMMO.p.getLogger().severe("Skipping "+treasureName+" for being invalid");
continue;
}
//VALIDATE DROP LEVEL
if(dropLevel < 0)
{
mcMMO.p.getLogger().info("Excavation Treasure named "+treasureName+" in the config has a drop level below 0, is this intentional?");
dropLevel = 0;
}
//VALIDATE DROP SOURCES
if(dropsFrom == null || dropsFrom.isEmpty())
{
mcMMO.p.getLogger().severe("Excavation Treasure named "+treasureName+" in the config has no drop targets, which would make it impossible to obtain, is this intentional?");
mcMMO.p.getLogger().severe("Skipping "+treasureName+" for being invalid");
continue;
}
/* OPTIONAL PARAMETERS */
//Custom Name
if(currentTreasure.getNode(CUSTOM_NAME) != null && !currentTreasure.getNode(CUSTOM_NAME).getString().equalsIgnoreCase("ChangeMe"))
{
customName = currentTreasure.getNode(CUSTOM_NAME).getString();
}
/*
* REGISTER TREASURE
*/
ShakeTreasure shakeTreasure = TreasureFactory.makeShakeTreasure(treasureMaterial, amount, xp, dropChance, dropLevel, customName, currentTreasure.getNode(LORE));
/*
* Add to map
*/
if(shakeMap.get(entityType) == null)
shakeMap.put(entityType, new ArrayList<>());
shakeMap.get(entityType).add(shakeTreasure);
} else {
mcMMO.p.getLogger().severe("Excavation Treasure Config - Material named "+treasureName+" does not match any known material.");
}
} }
} catch (ObjectMappingException e) { } catch (ObjectMappingException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -3,6 +3,7 @@ package com.gmail.nossr50.config.treasure;
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure; import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
import com.gmail.nossr50.datatypes.treasure.FishingTreasure; import com.gmail.nossr50.datatypes.treasure.FishingTreasure;
import com.gmail.nossr50.datatypes.treasure.HylianTreasure; import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
import com.gmail.nossr50.datatypes.treasure.ShakeTreasure;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
import ninja.leaping.configurate.ConfigurationNode; import ninja.leaping.configurate.ConfigurationNode;
import ninja.leaping.configurate.objectmapping.ObjectMappingException; import ninja.leaping.configurate.objectmapping.ObjectMappingException;
@ -42,6 +43,13 @@ public class TreasureFactory {
return new ExcavationTreasure(treasure, xpReward, dropChance, dropLevel); return new ExcavationTreasure(treasure, xpReward, dropChance, dropLevel);
} }
public static ShakeTreasure makeShakeTreasure(Material material, int dropAmount, int xpReward, double dropChance, int dropLevel, String customName, ConfigurationNode customLore)
{
ItemStack treasure = makeItemStack(material, dropAmount, customName, customLore);
return new ShakeTreasure(treasure, xpReward, dropChance, dropLevel);
}
public static FishingTreasure makeFishingTreasure(Material material, int dropAmount, int xpReward, String customName, ConfigurationNode customLore) public static FishingTreasure makeFishingTreasure(Material material, int dropAmount, int xpReward, String customName, ConfigurationNode customLore)
{ {
ItemStack treasure = makeItemStack(material, dropAmount, customName, customLore); ItemStack treasure = makeItemStack(material, dropAmount, customName, customLore);