| 1 | package sh.okx.rankup.requirements.requirement; | |
| 2 | ||
| 3 | import me.clip.placeholderapi.PlaceholderAPI; | |
| 4 | import org.bukkit.entity.Player; | |
| 5 | import sh.okx.rankup.RankupPlugin; | |
| 6 | import sh.okx.rankup.requirements.ProgressiveRequirement; | |
| 7 | import sh.okx.rankup.requirements.Requirement; | |
| 8 | ||
| 9 | public class PlaceholderRequirement extends ProgressiveRequirement { | |
| 10 | ||
| 11 | public static final double DELTA = 0.00001D; | |
| 12 | ||
| 13 | public PlaceholderRequirement(RankupPlugin plugin) { | |
| 14 | super(plugin, "placeholder"); | |
| 15 | } | |
| 16 | ||
| 17 | public PlaceholderRequirement(PlaceholderRequirement clone) { | |
| 18 | super(clone); | |
| 19 | } | |
| 20 | ||
| 21 | @Override | |
| 22 | public double getProgress(Player player) { | |
| 23 | String[] parts = getParts(player); | |
| 24 | String parsed = parts[0]; | |
| 25 | String value = parts[2]; | |
| 26 | ||
| 27 | // string operations | |
| 28 | switch (parts[1]) { | |
| 29 | case "=": | |
| 30 |
1
1. getProgress : negated conditional → NO_COVERAGE |
return parsed.equals(value) ? 1 : 0; |
| 31 | case "!=": | |
| 32 |
2
1. getProgress : negated conditional → NO_COVERAGE 2. getProgress : replaced double return with 0.0d for sh/okx/rankup/requirements/requirement/PlaceholderRequirement::getProgress → NO_COVERAGE |
return parsed.equals(value) ? 0 : 1; |
| 33 | } | |
| 34 | ||
| 35 | // numeric operations | |
| 36 | double p = Double.parseDouble(parsed.replace(",", "")); | |
| 37 | double v = Double.parseDouble(value.replace(",", "")); | |
| 38 | switch (parts[1]) { | |
| 39 | case ">": | |
| 40 |
2
1. getProgress : changed conditional boundary → NO_COVERAGE 2. getProgress : negated conditional → NO_COVERAGE |
return p > v ? 1 : 0; |
| 41 | case ">=": | |
| 42 |
1
1. getProgress : replaced double return with 0.0d for sh/okx/rankup/requirements/requirement/PlaceholderRequirement::getProgress → NO_COVERAGE |
return Math.min(p, v); |
| 43 | case "<": | |
| 44 |
2
1. getProgress : changed conditional boundary → NO_COVERAGE 2. getProgress : negated conditional → NO_COVERAGE |
return p < v ? 1 : 0; |
| 45 | case "<=": | |
| 46 |
2
1. getProgress : changed conditional boundary → NO_COVERAGE 2. getProgress : negated conditional → NO_COVERAGE |
return p <= v ? 1 : 0; |
| 47 | case "==": | |
| 48 |
1
1. getProgress : negated conditional → NO_COVERAGE |
return p == v ? 1 : 0; |
| 49 | } | |
| 50 | throw new IllegalArgumentException("Invalid operation: " + parts[1]); | |
| 51 | } | |
| 52 | ||
| 53 | @Override | |
| 54 | public double getTotal(Player player) { | |
| 55 | String[] parts = getParts(player); | |
| 56 | ||
| 57 | switch (parts[1]) { | |
| 58 | case ">=": | |
| 59 |
1
1. getTotal : replaced double return with 0.0d for sh/okx/rankup/requirements/requirement/PlaceholderRequirement::getTotal → NO_COVERAGE |
return Double.parseDouble(parts[2]); |
| 60 | default: | |
| 61 |
1
1. getTotal : replaced double return with 0.0d for sh/okx/rankup/requirements/requirement/PlaceholderRequirement::getTotal → NO_COVERAGE |
return 1; |
| 62 | } | |
| 63 | } | |
| 64 | ||
| 65 | private String[] getParts(Player player) { | |
| 66 | String[] parts = getValueString().split(" "); | |
| 67 |
2
1. getParts : changed conditional boundary → NO_COVERAGE 2. getParts : negated conditional → NO_COVERAGE |
if (parts.length < 3) { |
| 68 | throw new IllegalArgumentException( | |
| 69 | "Placeholder requirements must be in the form %placeholder% <operation> string"); | |
| 70 | } | |
| 71 | String parsed = PlaceholderAPI.setPlaceholders(player, parts[0]); | |
| 72 |
2
1. getParts : negated conditional → NO_COVERAGE 2. getParts : negated conditional → NO_COVERAGE |
if (!PlaceholderAPI.containsPlaceholders(parts[0]) || parsed.equals(parts[0])) { |
| 73 | throw new IllegalArgumentException(parts[0] + " is not a PlaceholderAPI placeholder!"); | |
| 74 | } | |
| 75 | parts[0] = parsed; | |
| 76 |
1
1. getParts : replaced return value with null for sh/okx/rankup/requirements/requirement/PlaceholderRequirement::getParts → NO_COVERAGE |
return parts; |
| 77 | } | |
| 78 | ||
| 79 | @Override | |
| 80 | public String getFullName() { | |
| 81 | String[] parts = getValueString().split(" "); | |
| 82 |
1
1. getFullName : replaced return value with "" for sh/okx/rankup/requirements/requirement/PlaceholderRequirement::getFullName → NO_COVERAGE |
return name + "#" + parts[0].replace("%", ""); |
| 83 | } | |
| 84 | ||
| 85 | @Override | |
| 86 | public boolean check(Player player) { | |
| 87 |
3
1. check : changed conditional boundary → NO_COVERAGE 2. check : negated conditional → NO_COVERAGE 3. check : replaced boolean return with true for sh/okx/rankup/requirements/requirement/PlaceholderRequirement::check → NO_COVERAGE |
return getRemaining(player) <= 0; |
| 88 | } | |
| 89 | ||
| 90 | @Override | |
| 91 | public Requirement clone() { | |
| 92 |
1
1. clone : replaced return value with null for sh/okx/rankup/requirements/requirement/PlaceholderRequirement::clone → NO_COVERAGE |
return new PlaceholderRequirement(this); |
| 93 | } | |
| 94 | } | |
Mutations | ||
| 30 |
1.1 |
|
| 32 |
1.1 2.2 |
|
| 40 |
1.1 2.2 |
|
| 42 |
1.1 |
|
| 44 |
1.1 2.2 |
|
| 46 |
1.1 2.2 |
|
| 48 |
1.1 |
|
| 59 |
1.1 |
|
| 61 |
1.1 |
|
| 67 |
1.1 2.2 |
|
| 72 |
1.1 2.2 |
|
| 76 |
1.1 |
|
| 82 |
1.1 |
|
| 87 |
1.1 2.2 3.3 |
|
| 92 |
1.1 |