mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2024-12-31 06:07:34 +01:00
Added 'display' option to the placeholder condition
This commit is contained in:
parent
02da23566e
commit
c2fe7eb5b6
pom.xml
src/main/java/net/Indyuce/mmoitems
4
pom.xml
4
pom.xml
@ -44,8 +44,8 @@
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>9</source>
|
||||
<target>9</target>
|
||||
<source>10</source>
|
||||
<target>10</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
@ -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) {
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
@ -40,12 +40,12 @@ public abstract class Ingredient<C extends PlayerIngredient> {
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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#",
|
||||
|
@ -36,8 +36,8 @@ public class CraftingManager implements Reloadable {
|
||||
* ingredient matches, the item is considered as a vanilla item.
|
||||
*/
|
||||
private final List<IngredientType> ingredients = new ArrayList<>();
|
||||
private final Set<LoadedCraftingObject<Condition>> conditions = new HashSet<>();
|
||||
private final Set<LoadedCraftingObject<Trigger>> triggers = new HashSet<>();
|
||||
private final Map<String, LoadedCraftingObject<Condition>> conditions = new HashMap<>();
|
||||
private final Map<String, LoadedCraftingObject<Trigger>> triggers = new HashMap<>();
|
||||
|
||||
private final Map<String, CraftingStation> 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> condition : conditions)
|
||||
if (condition.getId().equalsIgnoreCase(key))
|
||||
return condition.load(config);
|
||||
@NotNull
|
||||
public LoadedCraftingObject<Condition> 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> trigger : triggers)
|
||||
if (trigger.getId().equalsIgnoreCase(key))
|
||||
return trigger.load(config);
|
||||
|
||||
throw new IllegalArgumentException("Could not match trigger");
|
||||
}
|
||||
@NotNull
|
||||
public LoadedCraftingObject<Trigger> getTriggerInfo(String key) {
|
||||
return Objects.requireNonNull(triggers.get(key), "Could not match trigger");
|
||||
}
|
||||
|
||||
public List<IngredientType> getIngredients() {
|
||||
return ingredients;
|
||||
}
|
||||
|
||||
public Set<LoadedCraftingObject<Condition>> getConditions() {
|
||||
return conditions;
|
||||
public Collection<LoadedCraftingObject<Condition>> getConditions() {
|
||||
return conditions.values();
|
||||
}
|
||||
|
||||
public Set<LoadedCraftingObject<Trigger>> getTriggers() {
|
||||
return triggers;
|
||||
public Collection<LoadedCraftingObject<Trigger>> 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<MMOLineConfig, Condition> function, @Nullable ConditionalDisplay display) {
|
||||
conditions.add(new LoadedCraftingObject<>(id, function, display));
|
||||
LoadedCraftingObject<Condition> 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<MMOLineConfig, Trigger> function) {
|
||||
triggers.add(new LoadedCraftingObject<Trigger>(id, function, null));
|
||||
LoadedCraftingObject<Trigger> obj = new LoadedCraftingObject<>(id, function, null);
|
||||
triggers.put(obj.getId(), obj);
|
||||
}
|
||||
|
||||
public Collection<CraftingStation> getAll() {
|
||||
|
Loading…
Reference in New Issue
Block a user