mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 14:46:46 +01:00
Hylian Treasure pt 1
This commit is contained in:
parent
bef86f0e97
commit
31402d97c4
@ -3,11 +3,13 @@ package com.gmail.nossr50.config.treasure;
|
|||||||
import com.gmail.nossr50.config.Config;
|
import com.gmail.nossr50.config.Config;
|
||||||
import com.gmail.nossr50.config.Registers;
|
import com.gmail.nossr50.config.Registers;
|
||||||
import com.gmail.nossr50.config.UnsafeValueValidation;
|
import com.gmail.nossr50.config.UnsafeValueValidation;
|
||||||
|
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
|
||||||
import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
|
import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
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;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -15,6 +17,13 @@ import java.util.List;
|
|||||||
|
|
||||||
public class HerbalismTreasureConfig extends Config implements UnsafeValueValidation, Registers {
|
public class HerbalismTreasureConfig extends Config implements UnsafeValueValidation, Registers {
|
||||||
public static final String HYLIAN_LUCK = "Hylian_Luck";
|
public static final String HYLIAN_LUCK = "Hylian_Luck";
|
||||||
|
public static final String AMOUNT = "Amount";
|
||||||
|
public static final String XP = "XP";
|
||||||
|
public static final String DROP_CHANCE = "Drop_Chance";
|
||||||
|
public static final String DROP_LEVEL = "Drop_Level";
|
||||||
|
public static final String CUSTOM_NAME = "Custom_Name";
|
||||||
|
public static final String LORE = "Lore";
|
||||||
|
|
||||||
public HashMap<String, List<HylianTreasure>> hylianMap = new HashMap<String, List<HylianTreasure>>();
|
public HashMap<String, List<HylianTreasure>> hylianMap = new HashMap<String, List<HylianTreasure>>();
|
||||||
|
|
||||||
public HerbalismTreasureConfig() {
|
public HerbalismTreasureConfig() {
|
||||||
@ -43,13 +52,103 @@ public class HerbalismTreasureConfig extends Config implements UnsafeValueValida
|
|||||||
|
|
||||||
if(herbalismTreasureNode == null)
|
if(herbalismTreasureNode == null)
|
||||||
{
|
{
|
||||||
mcMMO.p.getLogger().info("Hylian_Luck in treasures config not defined");
|
mcMMO.p.getLogger().info("Excavation treasures in treasures config not defined");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (String treasureName : herbalismTreasureNode.getList(TypeToken.of(String.class))) {
|
for (String treasureName : herbalismTreasureNode.getList(TypeToken.of(String.class))) {
|
||||||
|
//Treasure Material Definition
|
||||||
|
Material treasureMaterial = Material.matchMaterial(treasureName.toUpperCase());
|
||||||
|
|
||||||
|
if(treasureMaterial != null)
|
||||||
|
{
|
||||||
|
ConfigurationNode currentTreasure = herbalismTreasureNode.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("Herbalism Hylian Luck 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("Herbalism Hylian Luck 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("Herbalism Hylian Luck 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("Herbalism Hylian Luck 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("Herbalism Hylian Luck 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
HylianTreasure hylianTreasure = TreasureFactory.makeHylianTreasure(treasureMaterial, amount, xp, dropChance, dropLevel, customName, currentTreasure.getNode(LORE));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add to map
|
||||||
|
*/
|
||||||
|
for(String dropBlock : dropsFrom)
|
||||||
|
{
|
||||||
|
if(hylianMap.get(dropBlock) == null)
|
||||||
|
hylianMap.put(dropBlock, new ArrayList<>());
|
||||||
|
|
||||||
|
hylianMap.get(dropBlock).add(hylianTreasure);
|
||||||
|
}
|
||||||
|
|
||||||
|
} 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();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.gmail.nossr50.config.treasure;
|
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.HylianTreasure;
|
||||||
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;
|
||||||
@ -37,6 +38,13 @@ public class TreasureFactory {
|
|||||||
return new ExcavationTreasure(treasure, xpReward, dropChance, dropLevel);
|
return new ExcavationTreasure(treasure, xpReward, dropChance, dropLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static HylianTreasure makeHylianTreasure(Material material, int dropAmount, int xpReward, double dropChance, int dropLevel, String customName, ConfigurationNode customLore)
|
||||||
|
{
|
||||||
|
ItemStack treasure = makeItemStack(material, dropAmount, customName, customLore);
|
||||||
|
|
||||||
|
return new HylianTreasure(treasure, xpReward, dropChance, dropLevel);
|
||||||
|
}
|
||||||
|
|
||||||
private static ItemStack makeItemStack(Material material, int dropAmount, String customName, ConfigurationNode customLore) {
|
private static ItemStack makeItemStack(Material material, int dropAmount, String customName, ConfigurationNode customLore) {
|
||||||
ItemStack treasure = new ItemStack(material, dropAmount);
|
ItemStack treasure = new ItemStack(material, dropAmount);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user