mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-02-26 15:21:22 +01:00
Fixed a crafting station condition display issue
This commit is contained in:
parent
7b6388d8ad
commit
4fe7546c2a
@ -49,5 +49,9 @@ public abstract class Condition {
|
|||||||
public Condition getCondition() {
|
public Condition getCondition() {
|
||||||
return condition;
|
return condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String format() {
|
||||||
|
return condition.formatDisplay(isMet() ? condition.getDisplay().getPositive() : condition.getDisplay().getNegative());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,5 +83,9 @@ public abstract class Ingredient {
|
|||||||
public PlayerIngredient getPlayerIngredient() {
|
public PlayerIngredient getPlayerIngredient() {
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String format() {
|
||||||
|
return inventory.formatLoreDisplay(isHad() ? inventory.getDisplay().getPositive() : inventory.getDisplay().getNegative());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,12 +68,12 @@ public class RecipeInfo {
|
|||||||
return recipe.display(this);
|
return recipe.display(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CheckedCondition getCondition(String format) {
|
// public CheckedCondition getCondition(String format) {
|
||||||
for (CheckedCondition condition : conditions)
|
// for (CheckedCondition condition : conditions)
|
||||||
if (condition.getCondition().getId().equals(format))
|
// if (condition.getCondition().getId().equals(format))
|
||||||
return condition;
|
// return condition;
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public Set<CheckedCondition> getConditions() {
|
public Set<CheckedCondition> getConditions() {
|
||||||
return conditions;
|
return conditions;
|
||||||
|
@ -3,8 +3,8 @@ package net.Indyuce.mmoitems.api.item.plugin.crafting;
|
|||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.ListIterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -51,8 +51,10 @@ public class CraftingRecipeDisplay extends ConfigItem {
|
|||||||
|
|
||||||
public ItemStack build() {
|
public ItemStack build() {
|
||||||
Map<String, String> replace = new HashMap<>();
|
Map<String, String> replace = new HashMap<>();
|
||||||
|
int conditionsIndex = -1;
|
||||||
|
|
||||||
for (Iterator<String> iterator = lore.iterator(); iterator.hasNext();) {
|
for (ListIterator<String> iterator = lore.listIterator(); iterator.hasNext();) {
|
||||||
|
int index = iterator.nextIndex();
|
||||||
String str = iterator.next();
|
String str = iterator.next();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -67,30 +69,13 @@ public class CraftingRecipeDisplay extends ConfigItem {
|
|||||||
replace.put(str, str.replace("{crafting_time}", "").replace("#crafting-time#", craftingTimeFormat.format(craftingRecipe.getCraftingTime())));
|
replace.put(str, str.replace("{crafting_time}", "").replace("#crafting-time#", craftingTimeFormat.format(craftingRecipe.getCraftingTime())));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str.equals("{conditions}")) {
|
if (str.startsWith("{conditions}")) {
|
||||||
if (recipe.getConditions().size() == 0) {
|
conditionsIndex = index;
|
||||||
|
if (recipe.getConditions().size() == 0)
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
continue;
|
else
|
||||||
}
|
|
||||||
|
|
||||||
replace.put(str, str.replace("{conditions}", ""));
|
replace.put(str, str.replace("{conditions}", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* load conditions
|
|
||||||
*/
|
|
||||||
if (str.startsWith("#condition_")) {
|
|
||||||
String format = str.substring("#condition_".length(), str.length() - 1);
|
|
||||||
CheckedCondition info = recipe.getCondition(format);
|
|
||||||
if (info == null) {
|
|
||||||
iterator.remove();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
ConditionalDisplay display = info.getCondition().getDisplay();
|
|
||||||
if (display != null)
|
|
||||||
replace.put(str, info.getCondition().formatDisplay(info.isMet() ? display.getPositive() : display.getNegative()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String key : replace.keySet())
|
for (String key : replace.keySet())
|
||||||
@ -102,7 +87,16 @@ public class CraftingRecipeDisplay extends ConfigItem {
|
|||||||
*/
|
*/
|
||||||
int index = lore.indexOf("#ingredients#");
|
int index = lore.indexOf("#ingredients#");
|
||||||
lore.remove(index);
|
lore.remove(index);
|
||||||
recipe.getIngredients().forEach(info -> lore.add(index, info.getIngredient().formatLoreDisplay(info.isHad() ? info.getIngredient().getDisplay().getPositive() : info.getIngredient().getDisplay().getNegative())));
|
recipe.getIngredients().forEach(info -> lore.add(index, info.format()));
|
||||||
|
|
||||||
|
if (conditionsIndex >= 0)
|
||||||
|
for (CheckedCondition condition : recipe.getConditions()) {
|
||||||
|
ConditionalDisplay display = condition.getCondition().getDisplay();
|
||||||
|
if (display != null)
|
||||||
|
// ++ allows to sort displays in the same order as in
|
||||||
|
// the config
|
||||||
|
lore.add(conditionsIndex++, condition.format());
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* apply color to lore
|
* apply color to lore
|
||||||
|
@ -2,8 +2,8 @@ package net.Indyuce.mmoitems.api.item.plugin.crafting;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.ListIterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -47,34 +47,19 @@ public class UpgradingRecipeDisplay extends ConfigItem {
|
|||||||
|
|
||||||
public ItemStack build() {
|
public ItemStack build() {
|
||||||
Map<String, String> replace = new HashMap<>();
|
Map<String, String> replace = new HashMap<>();
|
||||||
|
int conditionsIndex = -1;
|
||||||
|
|
||||||
for (Iterator<String> iterator = lore.iterator(); iterator.hasNext();) {
|
for (ListIterator<String> iterator = lore.listIterator(); iterator.hasNext();) {
|
||||||
|
int index = iterator.nextIndex();
|
||||||
String str = iterator.next();
|
String str = iterator.next();
|
||||||
|
|
||||||
if (str.equals("{conditions}")) {
|
if (str.startsWith("{conditions}")) {
|
||||||
if (recipe.getConditions().size() == 0) {
|
conditionsIndex = index;
|
||||||
|
if (recipe.getConditions().size() == 0)
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
continue;
|
else
|
||||||
}
|
|
||||||
|
|
||||||
replace.put(str, str.replace("{conditions}", ""));
|
replace.put(str, str.replace("{conditions}", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* load conditions
|
|
||||||
*/
|
|
||||||
if (str.startsWith("#condition_")) {
|
|
||||||
String format = str.substring("#condition_".length(), str.length() - 1);
|
|
||||||
CheckedCondition info = recipe.getCondition(format);
|
|
||||||
if (info == null) {
|
|
||||||
iterator.remove();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
ConditionalDisplay display = info.getCondition().getDisplay();
|
|
||||||
if (display != null)
|
|
||||||
replace.put(str, info.getCondition().formatDisplay(info.isMet() ? display.getPositive() : display.getNegative()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String key : replace.keySet())
|
for (String key : replace.keySet())
|
||||||
@ -86,8 +71,16 @@ public class UpgradingRecipeDisplay extends ConfigItem {
|
|||||||
*/
|
*/
|
||||||
int index = lore.indexOf("#ingredients#");
|
int index = lore.indexOf("#ingredients#");
|
||||||
lore.remove(index);
|
lore.remove(index);
|
||||||
recipe.getIngredients().forEach(info -> lore.add(index, info.getIngredient().formatLoreDisplay(info.isHad() ? info.getIngredient().getDisplay().getPositive() : info.getIngredient().getDisplay().getNegative())));
|
recipe.getIngredients().forEach(info -> lore.add(index, info.format()));
|
||||||
|
|
||||||
|
if (conditionsIndex >= 0)
|
||||||
|
for (CheckedCondition condition : recipe.getConditions()) {
|
||||||
|
ConditionalDisplay display = condition.getCondition().getDisplay();
|
||||||
|
if (display != null)
|
||||||
|
// ++ allows to sort displays in the same order as in
|
||||||
|
// the config
|
||||||
|
lore.add(conditionsIndex++, condition.format());
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* apply color to lore
|
* apply color to lore
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user