| 1 | package sh.okx.rankup.ranksgui; | |
| 2 | ||
| 3 | import java.util.function.BiFunction; | |
| 4 | import lombok.Getter; | |
| 5 | import org.bukkit.Bukkit; | |
| 6 | import org.bukkit.configuration.ConfigurationSection; | |
| 7 | import org.bukkit.entity.Player; | |
| 8 | import org.bukkit.event.inventory.InventoryClickEvent; | |
| 9 | import org.bukkit.inventory.Inventory; | |
| 10 | import org.bukkit.inventory.ItemStack; | |
| 11 | import sh.okx.rankup.RankupPlugin; | |
| 12 | import sh.okx.rankup.gui.Gui; | |
| 13 | import sh.okx.rankup.ranks.Rank; | |
| 14 | import sh.okx.rankup.ranks.RankElement; | |
| 15 | import sh.okx.rankup.util.Colour; | |
| 16 | ||
| 17 | public class RanksGui { | |
| 18 | private final RankupPlugin plugin; | |
| 19 |
1
1. getPlayer : replaced return value with null for sh/okx/rankup/ranksgui/RanksGui::getPlayer → SURVIVED |
@Getter |
| 20 | private final Player player; | |
| 21 | ||
| 22 | private int rankupSlot; | |
| 23 | ||
| 24 |
1
1. getInventory : replaced return value with null for sh/okx/rankup/ranksgui/RanksGui::getInventory → NO_COVERAGE |
@Getter |
| 25 | private Inventory inventory; | |
| 26 | ||
| 27 | public RanksGui(RankupPlugin plugin, Player player) { | |
| 28 | this.plugin = plugin; | |
| 29 | this.player = player; | |
| 30 | } | |
| 31 | ||
| 32 | public void open() { | |
| 33 | RankElement<Rank> playerRankElement = plugin.getRankups().getByPlayer(player); | |
| 34 |
1
1. open : negated conditional → KILLED |
ConfigurationSection playerPath = playerRankElement == null ? null : plugin.getSection(playerRankElement.getRank(), "rankup.ranksgui"); |
| 35 | ConfigurationSection basePath = plugin.getMessages().getConfigurationSection("rankup.ranksgui"); | |
| 36 | ||
| 37 | String title = get(ConfigurationSection::getString, "title", playerPath, basePath, "Ranks"); | |
| 38 | int rows = get(Gui::getInt, "rows", playerPath, basePath, 3); | |
| 39 | int offset = get(Gui::getInt, "offset", playerPath, basePath, 10); | |
| 40 | int width = get(Gui::getInt, "width", playerPath, basePath, 7); | |
| 41 | ||
| 42 |
1
1. open : Replaced integer multiplication with division → KILLED |
inventory = Bukkit.createInventory(null, rows * 9, Colour.translate(title)); |
| 43 | ||
| 44 |
1
1. lambda$open$0 : replaced return value with null for sh/okx/rankup/ranksgui/RanksGui::lambda$open$0 → SURVIVED |
ItemStack fill = get((section, path) -> Gui.getItem(plugin, section.getConfigurationSection(path), player, playerRankElement), "fill", playerPath, basePath, null); |
| 45 | ||
| 46 | int index = offset; | |
| 47 |
1
1. open : Replaced integer addition with subtraction → SURVIVED |
int rowIndex = offset + width; |
| 48 | RankElement<Rank> rankElement = plugin.getRankups().getTree().getFirst(); | |
| 49 |
1
1. open : negated conditional → SURVIVED |
boolean complete = playerRankElement != null; |
| 50 |
1
1. open : negated conditional → SURVIVED |
while(rankElement.hasNext()) { |
| 51 | ConfigurationSection rankPath = plugin.getSection(rankElement.getRank(), "rankup.ranksgui"); | |
| 52 | ||
| 53 | String path; | |
| 54 |
1
1. open : negated conditional → SURVIVED |
if (rankElement == playerRankElement) { |
| 55 | path = "current"; | |
| 56 | complete = false; | |
| 57 | rankupSlot = index; | |
| 58 |
1
1. open : negated conditional → SURVIVED |
} else if (complete) { |
| 59 | path = "complete"; | |
| 60 | } else { | |
| 61 | path = "incomplete"; | |
| 62 | } | |
| 63 | ||
| 64 | RankElement<Rank> rankElement0 = rankElement; | |
| 65 |
1
1. lambda$open$1 : replaced return value with null for sh/okx/rankup/ranksgui/RanksGui::lambda$open$1 → SURVIVED |
ItemStack item = get((section, path0) -> Gui.getItem(plugin, section.getConfigurationSection(path0), player, rankElement0), path, rankPath, basePath, null); |
| 66 | ||
| 67 |
2
1. open : Changed increment from 1 to -1 → SURVIVED 2. open : removed call to org/bukkit/inventory/Inventory::setItem → SURVIVED |
inventory.setItem(index++, item); |
| 68 |
3
1. open : changed conditional boundary → SURVIVED 2. open : Replaced integer multiplication with division → KILLED 3. open : negated conditional → KILLED |
if (index > rows * 9) { |
| 69 | throw new IllegalArgumentException("Ranks GUI is too small for the number of ranks. Increase the number of rows on the ranks GUI."); | |
| 70 | } | |
| 71 |
1
1. open : negated conditional → SURVIVED |
if (index == rowIndex) { |
| 72 |
1
1. open : Changed increment from 9 to -9 → NO_COVERAGE |
rowIndex += 9; |
| 73 |
2
1. open : Replaced integer subtraction with addition → NO_COVERAGE 2. open : Replaced integer addition with subtraction → NO_COVERAGE |
index += 9 - width; |
| 74 | } | |
| 75 | rankElement = rankElement.getNext(); | |
| 76 | } | |
| 77 | ||
| 78 |
1
1. open : negated conditional → SURVIVED |
if (fill != null) { |
| 79 |
4
1. open : Replaced integer multiplication with division → SURVIVED 2. open : negated conditional → SURVIVED 3. open : changed conditional boundary → KILLED 4. open : Changed increment from 1 to -1 → KILLED |
for (int i = 0; i < rows * 9; i++) { |
| 80 | ItemStack item = inventory.getItem(i); | |
| 81 |
1
1. open : negated conditional → SURVIVED |
if (item == null) { |
| 82 |
1
1. open : removed call to org/bukkit/inventory/Inventory::setItem → SURVIVED |
inventory.setItem(i, fill); |
| 83 | } | |
| 84 | } | |
| 85 | } | |
| 86 | ||
| 87 | player.openInventory(inventory); | |
| 88 | } | |
| 89 | ||
| 90 | ||
| 91 | private <T> T get(BiFunction<ConfigurationSection, String, T> fun, String path, ConfigurationSection primary, ConfigurationSection secondary, T def) { | |
| 92 | T get = null; | |
| 93 |
1
1. get : negated conditional → KILLED |
if (primary != null) { |
| 94 | get = fun.apply(primary, path); | |
| 95 | } | |
| 96 |
1
1. get : negated conditional → KILLED |
if (get != null) { |
| 97 |
1
1. get : replaced return value with null for sh/okx/rankup/ranksgui/RanksGui::get → KILLED |
return get; |
| 98 | } | |
| 99 |
1
1. get : negated conditional → SURVIVED |
if (secondary != null) { |
| 100 | get = fun.apply(secondary, path); | |
| 101 | } | |
| 102 |
1
1. get : negated conditional → SURVIVED |
if (get != null) { |
| 103 |
1
1. get : replaced return value with null for sh/okx/rankup/ranksgui/RanksGui::get → KILLED |
return get; |
| 104 | } | |
| 105 |
1
1. get : replaced return value with null for sh/okx/rankup/ranksgui/RanksGui::get → NO_COVERAGE |
return def; |
| 106 | } | |
| 107 | ||
| 108 | public void click(InventoryClickEvent event) { | |
| 109 |
1
1. click : negated conditional → NO_COVERAGE |
if (event.getClickedInventory() != event.getInventory()) { |
| 110 | return; | |
| 111 | } | |
| 112 | int slot = event.getRawSlot(); | |
| 113 |
1
1. click : negated conditional → NO_COVERAGE |
if (slot == rankupSlot) { |
| 114 | Bukkit.getScheduler().runTask(plugin, () -> { | |
| 115 |
1
1. lambda$click$2 : removed call to org/bukkit/entity/Player::closeInventory → NO_COVERAGE |
player.closeInventory(); |
| 116 | Bukkit.dispatchCommand(player, "rankup gui"); | |
| 117 | }); | |
| 118 | } | |
| 119 | } | |
| 120 | ||
| 121 | public void close() { | |
| 122 | ||
| 123 | } | |
| 124 | } | |
Mutations | ||
| 19 |
1.1 |
|
| 24 |
1.1 |
|
| 34 |
1.1 |
|
| 42 |
1.1 |
|
| 44 |
1.1 |
|
| 47 |
1.1 |
|
| 49 |
1.1 |
|
| 50 |
1.1 |
|
| 54 |
1.1 |
|
| 58 |
1.1 |
|
| 65 |
1.1 |
|
| 67 |
1.1 2.2 |
|
| 68 |
1.1 2.2 3.3 |
|
| 71 |
1.1 |
|
| 72 |
1.1 |
|
| 73 |
1.1 2.2 |
|
| 78 |
1.1 |
|
| 79 |
1.1 2.2 3.3 4.4 |
|
| 81 |
1.1 |
|
| 82 |
1.1 |
|
| 93 |
1.1 |
|
| 96 |
1.1 |
|
| 97 |
1.1 |
|
| 99 |
1.1 |
|
| 102 |
1.1 |
|
| 103 |
1.1 |
|
| 105 |
1.1 |
|
| 109 |
1.1 |
|
| 113 |
1.1 |
|
| 115 |
1.1 |