From 12964a816db1a848dfcecdfc45671bc7fae2860b Mon Sep 17 00:00:00 2001 From: nossr50 Date: Sun, 16 Jun 2019 12:41:14 -0700 Subject: [PATCH] RepairWildcard wip --- .../serializers/RepairWildcardSerializer.java | 22 ++++++++++ .../hocon/skills/repair/ConfigRepair.java | 18 +++++++- .../hocon/skills/repair/RepairWildcard.java | 42 +++++++++++++++++++ 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/config/hocon/serializers/RepairWildcardSerializer.java create mode 100644 src/main/java/com/gmail/nossr50/config/hocon/skills/repair/RepairWildcard.java diff --git a/src/main/java/com/gmail/nossr50/config/hocon/serializers/RepairWildcardSerializer.java b/src/main/java/com/gmail/nossr50/config/hocon/serializers/RepairWildcardSerializer.java new file mode 100644 index 000000000..d9a5e4004 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/hocon/serializers/RepairWildcardSerializer.java @@ -0,0 +1,22 @@ +package com.gmail.nossr50.config.hocon.serializers; + +import com.gmail.nossr50.config.hocon.skills.repair.RepairWildcard; +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.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; + +public class RepairWildcardSerializer implements TypeSerializer { + @Nullable + @Override + public RepairWildcard deserialize(@NonNull TypeToken type, @NonNull ConfigurationNode value) throws ObjectMappingException { + return null; + } + + @Override + public void serialize(@NonNull TypeToken type, @Nullable RepairWildcard obj, @NonNull ConfigurationNode value) throws ObjectMappingException { + + } +} diff --git a/src/main/java/com/gmail/nossr50/config/hocon/skills/repair/ConfigRepair.java b/src/main/java/com/gmail/nossr50/config/hocon/skills/repair/ConfigRepair.java index a97c5b929..67a47ab3b 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/skills/repair/ConfigRepair.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/skills/repair/ConfigRepair.java @@ -9,8 +9,7 @@ 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 java.util.*; import static org.bukkit.Material.*; @@ -18,6 +17,7 @@ import static org.bukkit.Material.*; public class ConfigRepair { public static final ArrayList CONFIG_REPAIRABLES_DEFAULTS; + public static final HashSet REPAIR_WILDCARDS_DEFAULTS; public static final Material[] PLANKS = new Material[]{OAK_PLANKS, BIRCH_PLANKS, DARK_OAK_PLANKS, ACACIA_PLANKS, JUNGLE_PLANKS, SPRUCE_PLANKS}; static { @@ -70,6 +70,13 @@ public class ConfigRepair { CONFIG_REPAIRABLES_DEFAULTS.add(new Repairable(DIAMOND_LEGGINGS, DIAMOND, 1, 0, 2D)); CONFIG_REPAIRABLES_DEFAULTS.add(new Repairable(DIAMOND_BOOTS, DIAMOND, 1, 0, 2D)); + REPAIR_WILDCARDS_DEFAULTS = new HashSet<>(); + + RepairWildcard repairWildcardPlanks = new RepairWildcard("Planks"); + List planksList = Arrays.asList(new String[]{OAK_PLANKS.getKey().toString(), + BIRCH_PLANKS.getKey().toString(), DARK_OAK_PLANKS.getKey().toString(), ACACIA_PLANKS.getKey().toString(), JUNGLE_PLANKS.getKey().toString(), SPRUCE_PLANKS.getKey().toString()}); + repairWildcardPlanks.addMatchCandidates(planksList); + REPAIR_WILDCARDS_DEFAULTS.add(repairWildcardPlanks); } @Setting(value = "General") @@ -90,6 +97,9 @@ public class ConfigRepair { "\nTIP: You can omit \"minecraft:\" from the Name ID if you want to, for example you can write \"red_wool\" instead of \"minecraft:red_wool\"") private ArrayList configRepairablesList = CONFIG_REPAIRABLES_DEFAULTS; + @Setting(value = "Z-Repairables-Wildcards", comment = "Used to define an alias that can be matched to several materials.") + private HashSet repairWildcards = new HashSet<>(); + public ConfigRepairGeneral getRepairGeneral() { return repairGeneral; } @@ -113,4 +123,8 @@ public class ConfigRepair { public ArrayList getConfigRepairablesList() { return configRepairablesList; } + + public HashSet getRepairWildcards() { + return repairWildcards; + } } \ No newline at end of file diff --git a/src/main/java/com/gmail/nossr50/config/hocon/skills/repair/RepairWildcard.java b/src/main/java/com/gmail/nossr50/config/hocon/skills/repair/RepairWildcard.java new file mode 100644 index 000000000..092c791c2 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/hocon/skills/repair/RepairWildcard.java @@ -0,0 +1,42 @@ +package com.gmail.nossr50.config.hocon.skills.repair; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public class RepairWildcard { + + private String wildcardName; + private ArrayList matchCandidates; + + public RepairWildcard(String wildcardName) { + this.wildcardName = wildcardName; + matchCandidates = new ArrayList<>(); + } + + public void addMatchCandidates(List arrayList) { + matchCandidates.addAll(arrayList); + } + + public ArrayList getMatchCandidates() { + return matchCandidates; + } + + public String getWildcardName() { + return wildcardName; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof RepairWildcard)) return false; + RepairWildcard that = (RepairWildcard) o; + return getWildcardName().equals(that.getWildcardName()) && + Objects.equals(getMatchCandidates(), that.getMatchCandidates()); + } + + @Override + public int hashCode() { + return Objects.hash(getWildcardName(), getMatchCandidates()); + } +}