mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-07-01 13:14:44 +02:00
Repairables can now specify multiple items that can be used for repairs
This commit is contained in:
@ -47,7 +47,6 @@ import com.gmail.nossr50.config.treasure.HerbalismTreasureConfig;
|
||||
import com.gmail.nossr50.datatypes.party.PartyFeature;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.skills.repair.repairables.Repairable;
|
||||
import com.gmail.nossr50.skills.repair.repairables.SimpleRepairable;
|
||||
import com.gmail.nossr50.skills.repair.repairables.SimpleRepairableManager;
|
||||
import com.gmail.nossr50.skills.salvage.salvageables.Salvageable;
|
||||
|
@ -5,7 +5,10 @@ import com.google.common.reflect.TypeToken;
|
||||
import ninja.leaping.configurate.ConfigurationNode;
|
||||
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
||||
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer;
|
||||
import org.bukkit.Material;
|
||||
import ninja.leaping.configurate.util.EnumLookup;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class RepairableSerializer implements TypeSerializer<SimpleRepairable> {
|
||||
|
||||
@ -37,23 +40,46 @@ public class RepairableSerializer implements TypeSerializer<SimpleRepairable> {
|
||||
|
||||
/* SimpleRepairable(Material itemMaterial, Material repairMaterial, int minimumQuantity, int minimumLevel, double xpMultiplier) */
|
||||
|
||||
Material item = value.getNode("Item").getValue(TypeToken.of(Material.class));
|
||||
Material repairItem = value.getNode("Item-Used-To-Repair").getValue(TypeToken.of(Material.class));
|
||||
String item = value.getNode("Item").getValue(TypeToken.of(String.class));
|
||||
List<String> repairItems = value.getNode("Items-Used-To-Repair").getValue(new TypeToken<List<String>>() {});
|
||||
|
||||
|
||||
/*String itemConstant = HOCONUtil.deserializeENUMName(value.getNode("Item").getString());
|
||||
String repairConstant = HOCONUtil.deserializeENUMName(value.getNode("Item-Used-To-Repair").getString());
|
||||
|
||||
Material item = (Material) getEnum(itemConstant, TypeToken.of(Material.class));
|
||||
Material repairItem = (Material) getEnum(repairConstant, TypeToken.of(Material.class));*/
|
||||
|
||||
int minimumQuantity = value.getNode("Minimum-Quantity-Used-To-Repair").getValue(TypeToken.of(Integer.class));
|
||||
int minimumLevel = value.getNode("Skill-Level-Required-To-Repair").getValue(TypeToken.of(Integer.class));
|
||||
double xpMultiplier = value.getNode("XP-Multiplier").getValue(TypeToken.of(Double.class));
|
||||
|
||||
return new SimpleRepairable(item, repairItem, minimumQuantity, minimumLevel, xpMultiplier);
|
||||
return new SimpleRepairable(item, repairItems, minimumQuantity, minimumLevel, xpMultiplier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(TypeToken<?> type, SimpleRepairable obj, ConfigurationNode value) throws ObjectMappingException {
|
||||
|
||||
value.getNode("Item").setValue(obj.getItemMaterial());
|
||||
value.getNode("Item-Used-To-Repair").setValue(obj.getRepairMaterial());
|
||||
/*value.getNode("Item").setValue(HOCONUtil.serializeENUMName(obj.getItemMaterial().getKey().getKey()));
|
||||
value.getNode("Item-Used-To-Repair").setValue(HOCONUtil.serializeENUMName(obj.getRepairMaterials().getKey().getKey()));*/
|
||||
value.getNode("Item").setValue(obj.getItemMaterial().getKey().toString());
|
||||
value.getNode("Items-Used-To-Repair").setValue(obj.getRepairMaterialsRegistryKeys());
|
||||
value.getNode("Minimum-Quantity-Used-To-Repair").setValue(obj.getMinimumQuantity());
|
||||
value.getNode("Skill-Level-Required-To-Repair").setValue(obj.getMinimumLevel());
|
||||
value.getNode("XP-Multiplier").setValue(obj.getXpMultiplier());
|
||||
|
||||
}
|
||||
|
||||
private Enum getEnum(String enumConstant, TypeToken<?> type) throws ObjectMappingException
|
||||
{
|
||||
Optional<Enum> ret = (Optional) EnumLookup.lookupEnum(type.getRawType().asSubclass(Enum.class),
|
||||
enumConstant); // XXX: intellij says this cast is optional but it isnt
|
||||
|
||||
if (!ret.isPresent()) {
|
||||
throw new ObjectMappingException("Invalid enum constant provided for " + enumConstant + ": " +
|
||||
"Expected a value of enum " + type + ", got " + enumConstant);
|
||||
}
|
||||
|
||||
return ret.get();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,8 +5,10 @@ import com.gmail.nossr50.config.hocon.skills.repair.repairmastery.ConfigRepairMa
|
||||
import com.gmail.nossr50.skills.repair.repairables.SimpleRepairable;
|
||||
import ninja.leaping.configurate.objectmapping.Setting;
|
||||
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.bukkit.Material.*;
|
||||
|
||||
@ -14,14 +16,15 @@ import static org.bukkit.Material.*;
|
||||
public class ConfigRepair {
|
||||
|
||||
public static final ArrayList<SimpleRepairable> CONFIG_REPAIRABLES_DEFAULTS;
|
||||
public static final Material[] PLANKS = new Material[] { OAK_PLANKS, BIRCH_PLANKS, DARK_OAK_PLANKS, ACACIA_PLANKS, JUNGLE_PLANKS, SPRUCE_PLANKS};
|
||||
|
||||
static {
|
||||
CONFIG_REPAIRABLES_DEFAULTS = new ArrayList<>();
|
||||
CONFIG_REPAIRABLES_DEFAULTS.add(new SimpleRepairable(WOODEN_SWORD, OAK_PLANKS, 1, 0, .25D));
|
||||
CONFIG_REPAIRABLES_DEFAULTS.add(new SimpleRepairable(WOODEN_SHOVEL, OAK_PLANKS, 1, 0, .15D));
|
||||
CONFIG_REPAIRABLES_DEFAULTS.add(new SimpleRepairable(WOODEN_PICKAXE, OAK_PLANKS, 1, 0, .5D));
|
||||
CONFIG_REPAIRABLES_DEFAULTS.add(new SimpleRepairable(WOODEN_AXE, OAK_PLANKS, 1, 0, .5D));
|
||||
CONFIG_REPAIRABLES_DEFAULTS.add(new SimpleRepairable(WOODEN_HOE, OAK_PLANKS, 1, 0, .25D));
|
||||
CONFIG_REPAIRABLES_DEFAULTS.add(new SimpleRepairable(WOODEN_SWORD, Arrays.asList(PLANKS), 1, 0, .25D));
|
||||
CONFIG_REPAIRABLES_DEFAULTS.add(new SimpleRepairable(WOODEN_SHOVEL, Arrays.asList(PLANKS), 1, 0, .15D));
|
||||
CONFIG_REPAIRABLES_DEFAULTS.add(new SimpleRepairable(WOODEN_PICKAXE, Arrays.asList(PLANKS), 1, 0, .5D));
|
||||
CONFIG_REPAIRABLES_DEFAULTS.add(new SimpleRepairable(WOODEN_AXE, Arrays.asList(PLANKS), 1, 0, .5D));
|
||||
CONFIG_REPAIRABLES_DEFAULTS.add(new SimpleRepairable(WOODEN_HOE, Arrays.asList(PLANKS), 1, 0, .25D));
|
||||
|
||||
/*
|
||||
Repairables:
|
||||
|
Reference in New Issue
Block a user