diff --git a/pom.xml b/pom.xml
index 7cc96f0e..722fa573 100644
--- a/pom.xml
+++ b/pom.xml
@@ -44,8 +44,8 @@
maven-compiler-plugin3.8.1
-
- 9
+
+ 10UTF-8
diff --git a/src/main/java/net/Indyuce/mmoitems/api/crafting/ConditionalDisplay.java b/src/main/java/net/Indyuce/mmoitems/api/crafting/ConditionalDisplay.java
index b71705d2..86c1d80b 100644
--- a/src/main/java/net/Indyuce/mmoitems/api/crafting/ConditionalDisplay.java
+++ b/src/main/java/net/Indyuce/mmoitems/api/crafting/ConditionalDisplay.java
@@ -10,19 +10,15 @@ public class ConditionalDisplay {
this.negative = negative;
}
- /*
- * used when loading translations
+ /**
+ * Used when loading translations
*/
public ConditionalDisplay(ConfigurationSection config) {
this(config.getString("positive"), config.getString("negative"));
}
- public String getPositive() {
- return positive;
- }
-
- public String getNegative() {
- return negative;
+ public String format(boolean positive) {
+ return positive ? this.positive : negative;
}
public void setup(ConfigurationSection config) {
diff --git a/src/main/java/net/Indyuce/mmoitems/api/crafting/condition/CheckedCondition.java b/src/main/java/net/Indyuce/mmoitems/api/crafting/condition/CheckedCondition.java
index 1ecf409a..0819041d 100644
--- a/src/main/java/net/Indyuce/mmoitems/api/crafting/condition/CheckedCondition.java
+++ b/src/main/java/net/Indyuce/mmoitems/api/crafting/condition/CheckedCondition.java
@@ -26,6 +26,6 @@ public class CheckedCondition {
}
public String format() {
- return condition.formatDisplay(isMet() ? condition.getDisplay().getPositive() : condition.getDisplay().getNegative());
+ return condition.formatDisplay(condition.getDisplay().format(met));
}
}
\ No newline at end of file
diff --git a/src/main/java/net/Indyuce/mmoitems/api/crafting/condition/Condition.java b/src/main/java/net/Indyuce/mmoitems/api/crafting/condition/Condition.java
index 201b2c17..7d830182 100644
--- a/src/main/java/net/Indyuce/mmoitems/api/crafting/condition/Condition.java
+++ b/src/main/java/net/Indyuce/mmoitems/api/crafting/condition/Condition.java
@@ -8,8 +8,8 @@ public abstract class Condition {
private final String id;
/**
- * Instanciated for every condition in a crafting recipe when loading a
- * crafting station from the config file.
+ * Instanciated for every condition in a crafting recipe
+ * when loading a crafting station from the config file.
*
* @param id The condition id
*/
@@ -21,12 +21,8 @@ public abstract class Condition {
return id;
}
- /*
- * Shortcut to RecipeManager map lookup, may throw a stream lookup error if
- * the condition has not been registered.
- */
public ConditionalDisplay getDisplay() {
- return MMOItems.plugin.getCrafting().getConditions().stream().filter(type -> type.getId().equals(id)).findAny().orElse(null).getDisplay();
+ return MMOItems.plugin.getCrafting().getConditionInfo(id).getDisplay();
}
/**
diff --git a/src/main/java/net/Indyuce/mmoitems/api/crafting/condition/PlaceholderCondition.java b/src/main/java/net/Indyuce/mmoitems/api/crafting/condition/PlaceholderCondition.java
index 00e46132..b2fcb4f5 100644
--- a/src/main/java/net/Indyuce/mmoitems/api/crafting/condition/PlaceholderCondition.java
+++ b/src/main/java/net/Indyuce/mmoitems/api/crafting/condition/PlaceholderCondition.java
@@ -5,10 +5,16 @@ import me.clip.placeholderapi.PlaceholderAPI;
import net.Indyuce.mmoitems.api.player.PlayerData;
public class PlaceholderCondition extends Condition {
- private final String value;
- private final String placeholder;
- private final String comparator;
- private final String compareTo;
+ private final String value, placeholder, comparator, compareTo;
+
+ /**
+ * Permissions are super ugly to display so MI uses a string instead.
+ * This way 'Only for Mages' is used instead of 'class.mage'
+ *
+ * One string can also replace multiple permissions.
+ * 'Magic Classes Only' instead of 'class.mage' and 'class.apprentice'
+ */
+ private final String display;
public PlaceholderCondition(MMOLineConfig config) {
super("placeholder");
@@ -19,6 +25,7 @@ public class PlaceholderCondition extends Condition {
placeholder = array[0];
comparator = array[1];
compareTo = array[2];
+ display = config.getString("display", "");
}
@Override
@@ -46,7 +53,7 @@ public class PlaceholderCondition extends Condition {
@Override
public String formatDisplay(String string) {
- return string.replace("#placeholder#", "" + placeholder);
+ return string.replace("#placeholder#", "" + placeholder).replace("#display#", display);
}
@Override
diff --git a/src/main/java/net/Indyuce/mmoitems/api/crafting/ingredient/CheckedIngredient.java b/src/main/java/net/Indyuce/mmoitems/api/crafting/ingredient/CheckedIngredient.java
index ce8e189a..228ebef8 100644
--- a/src/main/java/net/Indyuce/mmoitems/api/crafting/ingredient/CheckedIngredient.java
+++ b/src/main/java/net/Indyuce/mmoitems/api/crafting/ingredient/CheckedIngredient.java
@@ -90,6 +90,6 @@ public class CheckedIngredient {
@NotNull
public String format() {
- return ingredient.formatDisplay(isHad() ? ingredient.getDisplay().getPositive() : ingredient.getDisplay().getNegative());
+ return ingredient.formatDisplay(ingredient.getDisplay().format(isHad));
}
}
\ No newline at end of file
diff --git a/src/main/java/net/Indyuce/mmoitems/api/crafting/ingredient/Ingredient.java b/src/main/java/net/Indyuce/mmoitems/api/crafting/ingredient/Ingredient.java
index 63fd5863..5156a6ff 100644
--- a/src/main/java/net/Indyuce/mmoitems/api/crafting/ingredient/Ingredient.java
+++ b/src/main/java/net/Indyuce/mmoitems/api/crafting/ingredient/Ingredient.java
@@ -40,12 +40,12 @@ public abstract class Ingredient {
return amount;
}
- /*
- * shortcut to RecipeManager map lookup, may throw a stream lookup error if
- * the condition has not been registered.
+ /**
+ * Shortcut to RecipeManager map lookup, may throw a stream
+ * lookup error if the ingredient has not been registered.
*/
public ConditionalDisplay getDisplay() {
- return MMOItems.plugin.getCrafting().getIngredients().stream().filter(type -> type.getId().equals(id)).findAny().orElse(null).getDisplay();
+ return MMOItems.plugin.getCrafting().getIngredients().stream().filter(type -> type.getId().equals(id)).findAny().orElseThrow().getDisplay();
}
/**
diff --git a/src/main/java/net/Indyuce/mmoitems/comp/mmocore/MMOCoreMMOLoader.java b/src/main/java/net/Indyuce/mmoitems/comp/mmocore/MMOCoreMMOLoader.java
index 9f507975..49407d18 100644
--- a/src/main/java/net/Indyuce/mmoitems/comp/mmocore/MMOCoreMMOLoader.java
+++ b/src/main/java/net/Indyuce/mmoitems/comp/mmocore/MMOCoreMMOLoader.java
@@ -63,9 +63,7 @@ public class MMOCoreMMOLoader extends MMOLoader {
MMOItems.plugin.getStats().register(MAX_STELLIUM);
MMOItems.plugin.getStats().register(ADDITIONAL_EXPERIENCE);
- /*
- * register extra conditions for MMOItems crafting.
- */
+ // Register extra conditions for MMOItems crafting.
MMOItems.plugin.getCrafting().registerCondition("profession", ProfessionCondition::new,
new ConditionalDisplay(
"&a" + AltChar.check + " Requires #level# in #profession#",
diff --git a/src/main/java/net/Indyuce/mmoitems/manager/CraftingManager.java b/src/main/java/net/Indyuce/mmoitems/manager/CraftingManager.java
index ddcc8c7a..9b6ee251 100644
--- a/src/main/java/net/Indyuce/mmoitems/manager/CraftingManager.java
+++ b/src/main/java/net/Indyuce/mmoitems/manager/CraftingManager.java
@@ -36,8 +36,8 @@ public class CraftingManager implements Reloadable {
* ingredient matches, the item is considered as a vanilla item.
*/
private final List ingredients = new ArrayList<>();
- private final Set> conditions = new HashSet<>();
- private final Set> triggers = new HashSet<>();
+ private final Map> conditions = new HashMap<>();
+ private final Map> triggers = new HashMap<>();
private final Map stations = new HashMap<>();
@@ -107,7 +107,7 @@ public class CraftingManager implements Reloadable {
} catch (IllegalArgumentException|NullPointerException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load station '" + file.getName() + "': " + exception.getMessage());
}
-
+
for (CraftingStation station : stations.values())
try {
station.postLoad();
@@ -151,46 +151,48 @@ public class CraftingManager implements Reloadable {
throw new IllegalArgumentException("Could not match ingredient");
}
- /**
- * Finds the corresponding condition type, and from there
- * load the corresponding condition from the line config
- */
- @NotNull
- public Condition getCondition(MMOLineConfig config) {
- String key = config.getKey();
+ /**
+ * Finds the corresponding condition type, and from there
+ * load the corresponding condition from the line config
+ *
+ * @throws NullPointerException If not found
+ */
+ @NotNull
+ public Condition getCondition(MMOLineConfig config) {
+ return getConditionInfo(config.getKey()).load(config);
+ }
- for (LoadedCraftingObject condition : conditions)
- if (condition.getId().equalsIgnoreCase(key))
- return condition.load(config);
+ @NotNull
+ public LoadedCraftingObject getConditionInfo(String key) {
+ return Objects.requireNonNull(conditions.get(key), "Could not match condition");
+ }
- throw new IllegalArgumentException("Could not match condition");
- }
+ /**
+ * Finds the corresponding trigger type, and from there
+ * load the corresponding trigger from the line config
+ *
+ * @throws NullPointerException If not found
+ */
+ @NotNull
+ public Trigger getTrigger(MMOLineConfig config) {
+ return getTriggerInfo(config.getKey()).load(config);
+ }
- /**
- * Finds the corresponding trigger type, and from there
- * load the corresponding trigger from the line config
- */
- @NotNull
- public Trigger getTrigger(MMOLineConfig config) {
- String key = config.getKey();
-
- for (LoadedCraftingObject trigger : triggers)
- if (trigger.getId().equalsIgnoreCase(key))
- return trigger.load(config);
-
- throw new IllegalArgumentException("Could not match trigger");
- }
+ @NotNull
+ public LoadedCraftingObject getTriggerInfo(String key) {
+ return Objects.requireNonNull(triggers.get(key), "Could not match trigger");
+ }
public List getIngredients() {
return ingredients;
}
- public Set> getConditions() {
- return conditions;
+ public Collection> getConditions() {
+ return conditions.values();
}
- public Set> getTriggers() {
- return triggers;
+ public Collection> getTriggers() {
+ return triggers.values();
}
/**
@@ -217,7 +219,8 @@ public class CraftingManager implements Reloadable {
* @param display How it displays in the item lore, null if it should not
*/
public void registerCondition(String id, Function function, @Nullable ConditionalDisplay display) {
- conditions.add(new LoadedCraftingObject<>(id, function, display));
+ LoadedCraftingObject obj = new LoadedCraftingObject<>(id, function, display);
+ conditions.put(obj.getId(), obj);
}
/**
@@ -229,7 +232,8 @@ public class CraftingManager implements Reloadable {
* @param function Function that loads that type of trigger from a line configuration
*/
public void registerTrigger(String id, Function function) {
- triggers.add(new LoadedCraftingObject(id, function, null));
+ LoadedCraftingObject obj = new LoadedCraftingObject<>(id, function, null);
+ triggers.put(obj.getId(), obj);
}
public Collection getAll() {