| 1 | package sh.okx.rankup.requirements.requirement; | |
| 2 | ||
| 3 | import org.bukkit.entity.Player; | |
| 4 | import org.bukkit.inventory.ItemStack; | |
| 5 | import org.bukkit.inventory.PlayerInventory; | |
| 6 | import sh.okx.rankup.RankupPlugin; | |
| 7 | import sh.okx.rankup.requirements.DeductibleRequirement; | |
| 8 | import sh.okx.rankup.requirements.Requirement; | |
| 9 | ||
| 10 | public class ItemDeductibleRequirement extends ItemRequirement implements DeductibleRequirement { | |
| 11 | ||
| 12 | public ItemDeductibleRequirement(RankupPlugin plugin, String name) { | |
| 13 | super(plugin, name); | |
| 14 | } | |
| 15 | ||
| 16 | public ItemDeductibleRequirement(ItemDeductibleRequirement clone) { | |
| 17 | super(clone); | |
| 18 | } | |
| 19 | ||
| 20 | @Override | |
| 21 | public void apply(Player player, double multiplier) { | |
| 22 |
1
1. apply : Replaced double multiplication with division → NO_COVERAGE |
int count = (int) (getTotal(player) * multiplier); |
| 23 | ||
| 24 | PlayerInventory inventory = player.getInventory(); | |
| 25 | ItemStack[] contents; | |
| 26 |
1
1. apply : negated conditional → NO_COVERAGE |
if (ItemRequirement.USE_STORAGE_CONTENTS) { |
| 27 | contents = inventory.getStorageContents(); | |
| 28 | } else { | |
| 29 | contents = inventory.getContents(); | |
| 30 | } | |
| 31 |
5
1. apply : changed conditional boundary → NO_COVERAGE 2. apply : changed conditional boundary → NO_COVERAGE 3. apply : Changed increment from 1 to -1 → NO_COVERAGE 4. apply : negated conditional → NO_COVERAGE 5. apply : negated conditional → NO_COVERAGE |
for (int i = 0; i < contents.length && count > 0; i++) { |
| 32 | ItemStack item = contents[i]; | |
| 33 | ||
| 34 |
1
1. apply : negated conditional → NO_COVERAGE |
if (matchItem(item)) { |
| 35 |
2
1. apply : changed conditional boundary → NO_COVERAGE 2. apply : negated conditional → NO_COVERAGE |
if (count < item.getAmount()) { |
| 36 |
2
1. apply : Replaced integer subtraction with addition → NO_COVERAGE 2. apply : removed call to org/bukkit/inventory/ItemStack::setAmount → NO_COVERAGE |
item.setAmount(item.getAmount() - count); |
| 37 | count = 0; | |
| 38 | } else { | |
| 39 |
1
1. apply : Replaced integer subtraction with addition → NO_COVERAGE |
count -= item.getAmount(); |
| 40 | contents[i] = null; | |
| 41 | } | |
| 42 | } | |
| 43 | } | |
| 44 | ||
| 45 |
1
1. apply : negated conditional → NO_COVERAGE |
if (ItemRequirement.USE_STORAGE_CONTENTS) { |
| 46 |
1
1. apply : removed call to org/bukkit/inventory/PlayerInventory::setStorageContents → NO_COVERAGE |
inventory.setStorageContents(contents); |
| 47 | } else { | |
| 48 |
1
1. apply : removed call to org/bukkit/inventory/PlayerInventory::setContents → NO_COVERAGE |
inventory.setContents(contents); |
| 49 | } | |
| 50 | ||
| 51 |
2
1. apply : changed conditional boundary → NO_COVERAGE 2. apply : negated conditional → NO_COVERAGE |
if (count > 0) { |
| 52 | throw new IllegalStateException("REPORT THIS ERROR TO THE DEV - COULD NOT DEDUCT ALL ITEMS"); | |
| 53 | } | |
| 54 | } | |
| 55 | ||
| 56 | @Override | |
| 57 | public Requirement clone() { | |
| 58 |
1
1. clone : replaced return value with null for sh/okx/rankup/requirements/requirement/ItemDeductibleRequirement::clone → NO_COVERAGE |
return new ItemDeductibleRequirement(this); |
| 59 | } | |
| 60 | } | |
Mutations | ||
| 22 |
1.1 |
|
| 26 |
1.1 |
|
| 31 |
1.1 2.2 3.3 4.4 5.5 |
|
| 34 |
1.1 |
|
| 35 |
1.1 2.2 |
|
| 36 |
1.1 2.2 |
|
| 39 |
1.1 |
|
| 45 |
1.1 |
|
| 46 |
1.1 |
|
| 48 |
1.1 |
|
| 51 |
1.1 2.2 |
|
| 58 |
1.1 |