ItemRequirement.java

1
package sh.okx.rankup.requirements.requirement;
2
3
import org.bukkit.Material;
4
import org.bukkit.entity.Player;
5
import org.bukkit.inventory.Inventory;
6
import org.bukkit.inventory.ItemStack;
7
import org.bukkit.inventory.PlayerInventory;
8
import sh.okx.rankup.RankupPlugin;
9
import sh.okx.rankup.requirements.ProgressiveRequirement;
10
import sh.okx.rankup.requirements.Requirement;
11
12
import java.util.Arrays;
13
14
public class ItemRequirement extends ProgressiveRequirement {
15
  public static final boolean USE_STORAGE_CONTENTS;
16
17
  static {
18
    boolean getStorageContentsMethodExists;
19
    try {
20
      Inventory.class.getMethod("getStorageContents");
21
      getStorageContentsMethodExists = true;
22
    } catch (NoSuchMethodException e) {
23
      getStorageContentsMethodExists = false;
24
    }
25
    USE_STORAGE_CONTENTS = getStorageContentsMethodExists;
26
  }
27
28
  public ItemRequirement(RankupPlugin plugin, String name) {
29
    super(plugin, name, true);
30
  }
31
32
  protected ItemRequirement(ItemRequirement clone) {
33
    super(clone);
34
  }
35
36
  @Override
37
  public Requirement clone() {
38 1 1. clone : replaced return value with null for sh/okx/rankup/requirements/requirement/ItemRequirement::clone → NO_COVERAGE
    return new ItemRequirement(this);
39
  }
40
41
  @Override
42
  public double getProgress(Player player) {
43
    PlayerInventory inventory = player.getInventory();
44
    ItemStack[] contents;
45 1 1. getProgress : negated conditional → NO_COVERAGE
    if (USE_STORAGE_CONTENTS) {
46
      contents = inventory.getStorageContents();
47
    } else {
48
      contents = inventory.getContents();
49
    }
50 1 1. getProgress : replaced double return with 0.0d for sh/okx/rankup/requirements/requirement/ItemRequirement::getProgress → NO_COVERAGE
    return Arrays.stream(contents)
51
        .filter(this::matchItem)
52
        .mapToInt(ItemStack::getAmount).sum();
53
  }
54
55
  @SuppressWarnings("deprecation")
56
  protected boolean matchItem(ItemStack item) {
57 1 1. matchItem : negated conditional → NO_COVERAGE
    if (item == null) {
58 1 1. matchItem : replaced boolean return with true for sh/okx/rankup/requirements/requirement/ItemRequirement::matchItem → NO_COVERAGE
      return false;
59
    }
60
61
    String sub = getSub();
62
    String[] parts = sub.split(":");
63
64
    Material material = Material.matchMaterial(parts[0]);
65 1 1. matchItem : negated conditional → NO_COVERAGE
    if (material == null) {
66
      throw new IllegalArgumentException("[item requirement] could not find material name: " + parts[0]);
67
    }
68
69 2 1. matchItem : changed conditional boundary → NO_COVERAGE
2. matchItem : negated conditional → NO_COVERAGE
    if (parts.length > 1) {
70
      int durability;
71
      try {
72
        durability = Integer.parseInt(parts[1]);
73
      } catch (NumberFormatException e) {
74
        throw new IllegalArgumentException("[item requirement] durability '" + parts[1] + "' must be a number in item: '" + sub + "'");
75
      }
76
77 1 1. matchItem : negated conditional → NO_COVERAGE
      if (durability != item.getDurability()) {
78 1 1. matchItem : replaced boolean return with true for sh/okx/rankup/requirements/requirement/ItemRequirement::matchItem → NO_COVERAGE
        return false;
79
      }
80
    }
81
82 2 1. matchItem : negated conditional → NO_COVERAGE
2. matchItem : replaced boolean return with true for sh/okx/rankup/requirements/requirement/ItemRequirement::matchItem → NO_COVERAGE
    return material == item.getType();
83
  }
84
}

Mutations

38

1.1
Location : clone
Killed by : none
replaced return value with null for sh/okx/rankup/requirements/requirement/ItemRequirement::clone → NO_COVERAGE

45

1.1
Location : getProgress
Killed by : none
negated conditional → NO_COVERAGE

50

1.1
Location : getProgress
Killed by : none
replaced double return with 0.0d for sh/okx/rankup/requirements/requirement/ItemRequirement::getProgress → NO_COVERAGE

57

1.1
Location : matchItem
Killed by : none
negated conditional → NO_COVERAGE

58

1.1
Location : matchItem
Killed by : none
replaced boolean return with true for sh/okx/rankup/requirements/requirement/ItemRequirement::matchItem → NO_COVERAGE

65

1.1
Location : matchItem
Killed by : none
negated conditional → NO_COVERAGE

69

1.1
Location : matchItem
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : matchItem
Killed by : none
negated conditional → NO_COVERAGE

77

1.1
Location : matchItem
Killed by : none
negated conditional → NO_COVERAGE

78

1.1
Location : matchItem
Killed by : none
replaced boolean return with true for sh/okx/rankup/requirements/requirement/ItemRequirement::matchItem → NO_COVERAGE

82

1.1
Location : matchItem
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : matchItem
Killed by : none
replaced boolean return with true for sh/okx/rankup/requirements/requirement/ItemRequirement::matchItem → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.7.0