Starting simplification
This commit is contained in:
@@ -32,7 +32,7 @@ public class RankList<T extends Rank> {
|
||||
for (T rank : ranks) {
|
||||
// see if anything ranks up to this
|
||||
for (T rank0 : ranks) {
|
||||
if (!rank0.isLast() && rank0.getNext().equals(rank.getName())) {
|
||||
if (rank0.getNext().equals(rank.getRank())) {
|
||||
continue OUTER;
|
||||
}
|
||||
}
|
||||
@@ -45,21 +45,20 @@ public class RankList<T extends Rank> {
|
||||
public List<T> getOrderedList() {
|
||||
List<T> list = new ArrayList<>();
|
||||
T t = getFirst();
|
||||
list.add(t);
|
||||
do {
|
||||
t = next(t);
|
||||
while (t != null) {
|
||||
list.add(t);
|
||||
} while (!t.isLast());
|
||||
t = next(t);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public T getByName(String name) {
|
||||
for (T rank : ranks) {
|
||||
if (rank.getName().equalsIgnoreCase(name)) {
|
||||
if (rank.getRank().equalsIgnoreCase(name)) {
|
||||
return rank;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("Invalid rank: " + name);
|
||||
return null;
|
||||
}
|
||||
|
||||
public T getByPlayer(Player player) {
|
||||
@@ -74,15 +73,11 @@ public class RankList<T extends Rank> {
|
||||
}
|
||||
|
||||
public T next(T rank) {
|
||||
if (rank.isLast()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (T nextRank : ranks) {
|
||||
if (rank.getNext().equalsIgnoreCase(nextRank.getName())) {
|
||||
if (rank.getNext().equalsIgnoreCase(nextRank.getRank())) {
|
||||
return nextRank;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException(rank.getName() + " has an invalid next rank");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,10 +25,8 @@ import sh.okx.rankup.prestige.Prestige;
|
||||
import sh.okx.rankup.prestige.Prestiges;
|
||||
import sh.okx.rankup.ranks.Rank;
|
||||
import sh.okx.rankup.ranks.Rankups;
|
||||
import sh.okx.rankup.requirements.OperationRegistry;
|
||||
import sh.okx.rankup.requirements.Requirement;
|
||||
import sh.okx.rankup.requirements.RequirementRegistry;
|
||||
import sh.okx.rankup.requirements.operation.*;
|
||||
import sh.okx.rankup.requirements.requirement.*;
|
||||
import sh.okx.rankup.requirements.requirement.XpLevelRequirement;
|
||||
import sh.okx.rankup.requirements.requirement.advancedachievements.*;
|
||||
@@ -53,8 +51,6 @@ public class Rankup extends JavaPlugin {
|
||||
@Getter
|
||||
private RequirementRegistry requirementRegistry;
|
||||
@Getter
|
||||
private OperationRegistry operationRegistry;
|
||||
@Getter
|
||||
private FileConfiguration messages;
|
||||
@Getter
|
||||
private FileConfiguration config;
|
||||
@@ -226,12 +222,6 @@ public class Rankup extends JavaPlugin {
|
||||
requirementRegistry.addRequirement(new AdvancedAchievementsAchievementRequirement(this));
|
||||
requirementRegistry.addRequirement(new AdvancedAchievementsTotalRequirement(this));
|
||||
}
|
||||
|
||||
operationRegistry = new OperationRegistry();
|
||||
operationRegistry.addOperation("all", new AllOperation());
|
||||
operationRegistry.addOperation("none", new NoneOperation());
|
||||
operationRegistry.addOperation("one", new OneOperation());
|
||||
operationRegistry.addOperation("any", new AnyOperation());
|
||||
}
|
||||
|
||||
private void setupPermissions() {
|
||||
@@ -266,7 +256,7 @@ public class Rankup extends JavaPlugin {
|
||||
|
||||
public MessageBuilder getMessage(Rank rank, Message message) {
|
||||
ConfigurationSection messages = (rank instanceof Prestige ? prestiges : rankups).getConfig()
|
||||
.getConfigurationSection(rank.getName());
|
||||
.getConfigurationSection(rank.getRank());
|
||||
if (messages == null || !messages.isSet(message.getName())) {
|
||||
messages = this.messages;
|
||||
}
|
||||
@@ -410,7 +400,7 @@ public class Rankup extends JavaPlugin {
|
||||
|
||||
public boolean checkPrestige(Player player, boolean message) {
|
||||
Prestige prestige = prestiges.getByPlayer(player);
|
||||
if (!prestige.isEligable(player)) { // check if in ladder
|
||||
if (!prestige.isIn(player)) { // check if in ladder
|
||||
getMessage(Message.NOT_HIGH_ENOUGH)
|
||||
.failIf(!message)
|
||||
.replace(Variable.PLAYER, player.getName())
|
||||
@@ -486,12 +476,10 @@ public class Rankup extends JavaPlugin {
|
||||
builder.replace(variable + " " + requirement.getName(), value.get());
|
||||
}
|
||||
|
||||
public void sendMessage(CommandSender player, Message message, Rank oldRank, Rank rank) {
|
||||
replaceMoneyRequirements(getMessage(oldRank, message)
|
||||
.replaceFirstPrestige(oldRank, prestiges, config.getString("placeholders.first-prestige-rank"))
|
||||
public MessageBuilder getMessage(CommandSender player, Message message, Rank oldRank, Rank rank) {
|
||||
return replaceMoneyRequirements(getMessage(oldRank, message)
|
||||
.replaceRanks(player, oldRank, rank), player, oldRank)
|
||||
.replaceFromTo(oldRank)
|
||||
.send(player);
|
||||
.replaceFromTo(oldRank);
|
||||
}
|
||||
|
||||
public void sendHeaderFooter(CommandSender sender, Rank rank, Message type) {
|
||||
@@ -508,4 +496,9 @@ public class Rankup extends JavaPlugin {
|
||||
}
|
||||
builder.send(sender);
|
||||
}
|
||||
|
||||
public boolean isLegacy() {
|
||||
String version = Bukkit.getVersion();
|
||||
return !(version.startsWith("1.13") || version.startsWith("1.14"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,12 @@ import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import sh.okx.rankup.requirements.Operation;
|
||||
import sh.okx.rankup.requirements.OperationRegistry;
|
||||
import sh.okx.rankup.requirements.Requirement;
|
||||
import sh.okx.rankup.requirements.RequirementRegistry;
|
||||
|
||||
/**
|
||||
* Called immediately before rankups and prestiges are registered,
|
||||
* and immediately after the built-in requirements and operations are registered.
|
||||
* and immediately after the built-in requirements are registered.
|
||||
* This is used to register custom requirements.
|
||||
* This is called when the plugin is enabled, and when it is reloaded from a command.
|
||||
*/
|
||||
@@ -29,18 +27,10 @@ public class RankupRegisterEvent extends Event {
|
||||
return plugin.getRequirementRegistry();
|
||||
}
|
||||
|
||||
public OperationRegistry getOperationRegistry() {
|
||||
return plugin.getOperationRegistry();
|
||||
}
|
||||
|
||||
public void addRequirement(Requirement requirement) {
|
||||
plugin.getRequirementRegistry().addRequirement(requirement);
|
||||
}
|
||||
|
||||
public void addOperation(String name, Operation operation) {
|
||||
plugin.getOperationRegistry().addOperation(name, operation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
|
||||
@@ -26,13 +26,17 @@ public class PrestigesCommand implements CommandExecutor {
|
||||
|
||||
Message message = playerRank == null ? Message.PRESTIGES_INCOMPLETE : Message.PRESTIGES_COMPLETE;
|
||||
Prestige prestige = prestiges.getFirst();
|
||||
while (!prestige.isLast()) {
|
||||
Prestige next = prestiges.next(prestige);
|
||||
Prestige next;
|
||||
while ((next = prestiges.next(prestige)) != null) {
|
||||
if (prestige.equals(playerRank)) {
|
||||
plugin.sendMessage(sender, Message.PRESTIGES_CURRENT, prestige, next);
|
||||
plugin.getMessage(sender, Message.PRESTIGES_CURRENT, prestige, next)
|
||||
.replaceFirstPrestige(prestige, prestiges, prestige.getFrom())
|
||||
.send(sender);
|
||||
message = Message.PRESTIGES_INCOMPLETE;
|
||||
} else {
|
||||
plugin.sendMessage(sender, message, prestige, next);
|
||||
plugin.getMessage(sender, message, prestige, next)
|
||||
.replaceFirstPrestige(prestige, prestiges, prestige.getFrom())
|
||||
.send(sender);
|
||||
}
|
||||
prestige = next;
|
||||
}
|
||||
|
||||
@@ -26,25 +26,16 @@ public class RanksCommand implements CommandExecutor {
|
||||
|
||||
Message message = playerRank == null ? Message.RANKS_INCOMPLETE : Message.RANKS_COMPLETE;
|
||||
Rank rank = rankups.getFirst();
|
||||
do {
|
||||
Rank next = rankups.next(rank);
|
||||
Rank next;
|
||||
while ((next = rankups.next(rank)) != null) {
|
||||
if (rank.equals(playerRank)) {
|
||||
plugin.sendMessage(sender, Message.RANKS_CURRENT, rank, next);
|
||||
plugin.getMessage(sender, Message.RANKS_CURRENT, rank, next).send(sender);
|
||||
message = Message.RANKS_INCOMPLETE;
|
||||
} else {
|
||||
// helpful message to say there is a null rankup
|
||||
if (next == null) {
|
||||
plugin.getMessage(Message.INVALID_RANKUP).failIfEmpty().send(sender);
|
||||
plugin.getLogger().severe("Rankup from " + rank.getName() + " to " + rank.getNext()
|
||||
+ " is defined but " + rank.getNext() + " does not exist.");
|
||||
return true;
|
||||
}
|
||||
|
||||
plugin.sendMessage(sender, message, rank, next);
|
||||
plugin.getMessage(sender, message, rank, next).send(sender);
|
||||
}
|
||||
rank = next;
|
||||
} while (!rank.isLast());
|
||||
|
||||
}
|
||||
plugin.sendHeaderFooter(sender, playerRank, Message.RANKS_FOOTER);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class RankupCommand implements CommandExecutor {
|
||||
}
|
||||
Rank next = rankups.next(rank);
|
||||
if (next == null) {
|
||||
plugin.getLogger().severe("Rankup from " + rank.getName() + " to " + rank.getNext() +
|
||||
plugin.getLogger().severe("Rankup from " + rank.getRank() + " to " + rank.getNext() +
|
||||
" is defined but " + rank.getNext() + " does not exist.");
|
||||
plugin.getMessage(Message.INVALID_RANKUP).failIfEmpty().send(player);
|
||||
return true;
|
||||
|
||||
@@ -59,18 +59,18 @@ public class Gui implements InventoryHolder {
|
||||
return gui;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static ItemStack getItem(Rankup plugin, String name, Player player, Rank oldRank, Rank rank) {
|
||||
ConfigurationSection section = plugin.getConfig().getConfigurationSection("gui").getConfigurationSection(name);
|
||||
boolean legacy = !Bukkit.getVersion().contains("1.13");
|
||||
|
||||
String materialName = section.getString("material").toUpperCase();
|
||||
// handle default material correctly on older versions
|
||||
if (legacy && materialName.equals("BLACK_STAINED_GLASS_PANE")) {
|
||||
if (plugin.isLegacy() && materialName.equals("BLACK_STAINED_GLASS_PANE")) {
|
||||
materialName = "STAINED_GLASS_PANE:15";
|
||||
}
|
||||
|
||||
ItemStack item;
|
||||
if (legacy) {
|
||||
if (plugin.isLegacy()) {
|
||||
String[] parts = materialName.split(":");
|
||||
Material material = Material.valueOf(parts[0]);
|
||||
|
||||
|
||||
@@ -64,14 +64,14 @@ public class MessageBuilder {
|
||||
|
||||
public MessageBuilder replaceRanks(Rank rank) {
|
||||
replace(Variable.RANK, rank.getRank());
|
||||
replace(Variable.RANK_NAME, rank.getName());
|
||||
replace(Variable.RANK_NAME, rank.getRank());
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessageBuilder replaceRanks(Rank oldRank, Rank rank) {
|
||||
replaceRanks(rank);
|
||||
replace(Variable.OLD_RANK, oldRank.getRank());
|
||||
replace(Variable.OLD_RANK_NAME, oldRank.getName());
|
||||
replace(Variable.OLD_RANK_NAME, oldRank.getRank());
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import sh.okx.rankup.ranks.Rank;
|
||||
import sh.okx.rankup.ranks.Rankups;
|
||||
import sh.okx.rankup.requirements.Requirement;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@@ -47,7 +48,7 @@ public class RankupExpansion extends PlaceholderExpansion {
|
||||
// return placeholders.getSimpleFormat().format(orElse(rankups.getByName(parts[2]).getRequirement(parts[3]), Requirement::getValueDouble, 0));
|
||||
} else if (params.startsWith("rank_money_")) {
|
||||
String[] parts = params.split("_", 4);
|
||||
double amount = rankups.getByName(parts[2]).getRequirement("money").getValueDouble();
|
||||
double amount = Objects.requireNonNull(rankups.getByName(parts[2]), "Rankup " + parts[2] + " does not exist").getRequirement("money").getValueDouble();
|
||||
if (parts.length > 3 && parts[3].equalsIgnoreCase("left")) {
|
||||
amount = amount - plugin.getEconomy().getBalance(player);
|
||||
}
|
||||
@@ -56,25 +57,17 @@ public class RankupExpansion extends PlaceholderExpansion {
|
||||
|
||||
switch (params) {
|
||||
case "current_prestige":
|
||||
return prestige.getRank();
|
||||
case "current_prestige_name":
|
||||
return prestige.getName();
|
||||
return Objects.requireNonNull(prestige, "Using current_prestige placeholder but prestiging is disabled").getRank();
|
||||
case "next_prestige":
|
||||
return orElsePlaceholder(nextPrestige, Prestige::getRank, "highest-rank");
|
||||
case "next_prestige_name":
|
||||
return orElsePlaceholder(nextPrestige, Prestige::getName, "highest-rank");
|
||||
case "prestige_money":
|
||||
return String.valueOf(simplify(orElse(prestige, r -> r.isEligable(player) ? r.getRequirement("money").getValueDouble() : 0, 0)));
|
||||
return String.valueOf(simplify(orElse(prestige, r -> r.isIn(player) ? r.getRequirement("money").getValueDouble() : 0, 0)));
|
||||
case "prestige_money_formatted":
|
||||
return plugin.formatMoney(orElse(prestige, r -> r.isEligable(player) ? r.getRequirement("money").getValueDouble() : 0, 0D));
|
||||
return plugin.formatMoney(orElse(prestige, r -> r.isIn(player) ? r.getRequirement("money").getValueDouble() : 0, 0D));
|
||||
case "current_rank":
|
||||
return orElsePlaceholder(rank, Rank::getRank, "not-in-ladder");
|
||||
case "current_rank_name":
|
||||
return orElsePlaceholder(rank, Rank::getName, "not-in-ladder");
|
||||
case "next_rank":
|
||||
return orElsePlaceholder(rank, r -> orElsePlaceholder(nextRank, Rank::getRank, "highest-rank"), "not-in-ladder");
|
||||
case "next_rank_name":
|
||||
return orElsePlaceholder(rank, r -> orElsePlaceholder(nextRank, Rank::getName, "highest-rank"), "not-in-ladder");
|
||||
case "money":
|
||||
return String.valueOf(orElse(rank, r -> simplify(r.getRequirement("money").getValueDouble()), 0));
|
||||
case "money_formatted":
|
||||
|
||||
@@ -1,65 +1,42 @@
|
||||
package sh.okx.rankup.prestige;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import sh.okx.rankup.Rankup;
|
||||
import sh.okx.rankup.ranks.Rank;
|
||||
import sh.okx.rankup.requirements.Operation;
|
||||
import sh.okx.rankup.requirements.Requirement;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Prestige extends Rank {
|
||||
@Getter
|
||||
private final String from;
|
||||
@Getter
|
||||
private final String to;
|
||||
|
||||
private Prestige(Rankup plugin, String name, String next, String rank, Set<Requirement> requirements, Operation operation, List<String> commands, String from, String to) {
|
||||
super(plugin, name, next, rank, requirements, operation, commands);
|
||||
private Prestige(Rankup plugin, String next, String rank, Set<Requirement> requirements, List<String> commands, String from, String to) {
|
||||
super(plugin, next, rank, requirements, commands);
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
public static Prestige deserialize(Rankup plugin, ConfigurationSection section) {
|
||||
Set<Requirement> requirements = new HashSet<>();
|
||||
Operation operation = null;
|
||||
ConfigurationSection requirementsSection = section.getConfigurationSection("requirements");
|
||||
|
||||
if (requirementsSection != null) {
|
||||
requirements = plugin.getRequirementRegistry().getRequirements(requirementsSection);
|
||||
operation = plugin.getOperationRegistry().getOperation(section.getString("operation"));
|
||||
}
|
||||
Validate.notNull(requirementsSection, "No requirements defined for section " + section.getName());
|
||||
Set<Requirement> requirements = plugin.getRequirementRegistry().getRequirements(requirementsSection);
|
||||
|
||||
return new Prestige(plugin,
|
||||
section.getName(),
|
||||
section.getString("next"),
|
||||
section.getString("rank"),
|
||||
requirements,
|
||||
operation,
|
||||
section.getStringList("commands"),
|
||||
section.getString("from"),
|
||||
section.getString("to"));
|
||||
}
|
||||
|
||||
public boolean isEligable(Player player) {
|
||||
String[] groups = plugin.getPermissions().getPlayerGroups(null, player);
|
||||
for (String group : groups) {
|
||||
if (group.equalsIgnoreCase(from)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof Prestige)) {
|
||||
return false;
|
||||
}
|
||||
return ((Prestige) o).name.equals(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,62 +1,55 @@
|
||||
package sh.okx.rankup.ranks;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import sh.okx.rankup.Rankup;
|
||||
import sh.okx.rankup.messages.MessageBuilder;
|
||||
import sh.okx.rankup.requirements.DeductibleRequirement;
|
||||
import sh.okx.rankup.requirements.Operation;
|
||||
import sh.okx.rankup.requirements.Requirement;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@EqualsAndHashCode
|
||||
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
|
||||
public class Rank {
|
||||
protected final Rankup plugin;
|
||||
@Getter
|
||||
protected final String name;
|
||||
@Getter
|
||||
protected final String next;
|
||||
@Getter
|
||||
protected final String rank;
|
||||
@Getter
|
||||
protected final Set<Requirement> requirements;
|
||||
protected final Operation operation;
|
||||
protected final List<String> commands;
|
||||
|
||||
public static Rank deserialize(Rankup plugin, ConfigurationSection section) {
|
||||
Set<Requirement> requirements = new HashSet<>();
|
||||
Operation operation = null;
|
||||
ConfigurationSection requirementsSection = section.getConfigurationSection("requirements");
|
||||
|
||||
if (requirementsSection != null) {
|
||||
requirements = plugin.getRequirementRegistry().getRequirements(requirementsSection);
|
||||
operation = plugin.getOperationRegistry().getOperation(section.getString("operation"));
|
||||
} else if (section.contains("next")) {
|
||||
plugin.getLogger().severe("Rank " + section.getName() + " has no requirements.");
|
||||
return null;
|
||||
}
|
||||
Validate.notNull(requirementsSection, "No requirements defined for section " + section.getName());
|
||||
Set<Requirement> requirements = plugin.getRequirementRegistry().getRequirements(requirementsSection);
|
||||
|
||||
return new Rank(plugin,
|
||||
section.getName(),
|
||||
section.getString("next"),
|
||||
section.getString("rank"),
|
||||
requirements,
|
||||
operation,
|
||||
section.getStringList("commands"));
|
||||
}
|
||||
|
||||
public boolean hasRequirements(Player player) {
|
||||
return operation.check(requirements.stream()
|
||||
.map(requirement -> requirement.check(player))
|
||||
.collect(Collectors.toList()));
|
||||
for (Requirement requirement : requirements) {
|
||||
if (!requirement.check(player)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isIn(Player player) {
|
||||
@@ -70,7 +63,7 @@ public class Rank {
|
||||
}
|
||||
|
||||
public boolean isLast() {
|
||||
return next == null;
|
||||
return plugin.getRankups().getByName(next) == null;
|
||||
}
|
||||
|
||||
public Requirement getRequirement(String name) {
|
||||
@@ -96,12 +89,4 @@ public class Rank {
|
||||
new MessageBuilder(command).replaceRanks(player, this, nextRank).toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof Rank)) {
|
||||
return false;
|
||||
}
|
||||
return ((Rank) o).name.equals(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package sh.okx.rankup.requirements;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Operation {
|
||||
boolean check(List<Boolean> booleans);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package sh.okx.rankup.requirements;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class OperationRegistry {
|
||||
private Map<String, Operation> operations = new HashMap<>();
|
||||
|
||||
public void addOperation(String name, Operation operation) {
|
||||
operations.put(name.toLowerCase(), operation);
|
||||
}
|
||||
|
||||
public Operation getOperation(String name) {
|
||||
return operations.get(name == null ? "all" : name.toLowerCase());
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package sh.okx.rankup.requirements;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ReducerOperation implements Operation {
|
||||
public abstract boolean check(boolean a, boolean b);
|
||||
|
||||
@Override
|
||||
public boolean check(List<Boolean> booleans) {
|
||||
return booleans.stream().reduce(this::check).orElse(true);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package sh.okx.rankup.requirements.operation;
|
||||
|
||||
import sh.okx.rankup.requirements.ReducerOperation;
|
||||
|
||||
public class AllOperation extends ReducerOperation {
|
||||
@Override
|
||||
public boolean check(boolean a, boolean b) {
|
||||
return a && b;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package sh.okx.rankup.requirements.operation;
|
||||
|
||||
import sh.okx.rankup.requirements.ReducerOperation;
|
||||
|
||||
public class AnyOperation extends ReducerOperation {
|
||||
@Override
|
||||
public boolean check(boolean a, boolean b) {
|
||||
return a || b;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package sh.okx.rankup.requirements.operation;
|
||||
|
||||
import sh.okx.rankup.requirements.ReducerOperation;
|
||||
|
||||
public class NoneOperation extends ReducerOperation {
|
||||
@Override
|
||||
public boolean check(boolean a, boolean b) {
|
||||
return !a && !b;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package sh.okx.rankup.requirements.operation;
|
||||
|
||||
import sh.okx.rankup.requirements.ReducerOperation;
|
||||
|
||||
public class OneOperation extends ReducerOperation {
|
||||
@Override
|
||||
public boolean check(boolean a, boolean b) {
|
||||
return (a && !b) || (b && !a);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user