| 1 | package sh.okx.rankup.commands; | |
| 2 | ||
| 3 | import java.util.Map; | |
| 4 | import java.util.WeakHashMap; | |
| 5 | import lombok.RequiredArgsConstructor; | |
| 6 | import org.bukkit.ChatColor; | |
| 7 | import org.bukkit.command.Command; | |
| 8 | import org.bukkit.command.CommandExecutor; | |
| 9 | import org.bukkit.command.CommandSender; | |
| 10 | import org.bukkit.configuration.file.FileConfiguration; | |
| 11 | import org.bukkit.entity.Player; | |
| 12 | import sh.okx.rankup.RankupPlugin; | |
| 13 | import sh.okx.rankup.gui.Gui; | |
| 14 | import sh.okx.rankup.messages.Message; | |
| 15 | import sh.okx.rankup.ranks.Rank; | |
| 16 | import sh.okx.rankup.ranks.RankElement; | |
| 17 | import sh.okx.rankup.ranks.Rankups; | |
| 18 | ||
| 19 | @RequiredArgsConstructor | |
| 20 | public class RankupCommand implements CommandExecutor { | |
| 21 | // weak hash maps so players going offline are automatically removed. | |
| 22 | // otherwise there is a potential (albeit small) memory leak. | |
| 23 | private final Map<Player, Long> confirming = new WeakHashMap<>(); | |
| 24 | private final RankupPlugin plugin; | |
| 25 | ||
| 26 | @Override | |
| 27 | public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | |
| 28 |
1
1. onCommand : negated conditional → NO_COVERAGE |
if (plugin.error(sender)) { |
| 29 |
1
1. onCommand : replaced boolean return with false for sh/okx/rankup/commands/RankupCommand::onCommand → NO_COVERAGE |
return true; |
| 30 | } | |
| 31 | ||
| 32 | // check if player | |
| 33 |
1
1. onCommand : negated conditional → NO_COVERAGE |
if (!(sender instanceof Player)) { |
| 34 |
1
1. onCommand : replaced boolean return with true for sh/okx/rankup/commands/RankupCommand::onCommand → NO_COVERAGE |
return false; |
| 35 | } | |
| 36 | Player player = (Player) sender; | |
| 37 | ||
| 38 | Rankups rankups = plugin.getRankups(); | |
| 39 |
1
1. onCommand : negated conditional → NO_COVERAGE |
if (!plugin.getHelper().checkRankup(player)) { |
| 40 |
1
1. onCommand : replaced boolean return with false for sh/okx/rankup/commands/RankupCommand::onCommand → NO_COVERAGE |
return true; |
| 41 | } | |
| 42 | RankElement<Rank> rankElement = rankups.getByPlayer(player); | |
| 43 | ||
| 44 | FileConfiguration config = plugin.getConfig(); | |
| 45 | String confirmationType = config.getString("confirmation-type").toLowerCase(); | |
| 46 | ||
| 47 | // if they are on text confirming, rank them up | |
| 48 | // clicking on the gui cannot confirm a rankup | |
| 49 |
5
1. onCommand : changed conditional boundary → NO_COVERAGE 2. onCommand : negated conditional → NO_COVERAGE 3. onCommand : negated conditional → NO_COVERAGE 4. onCommand : negated conditional → NO_COVERAGE 5. onCommand : negated conditional → NO_COVERAGE |
if (confirmationType.equals("text") && confirming.containsKey(player) && !(args.length > 0 && args[0].equalsIgnoreCase("gui"))) { |
| 50 |
1
1. onCommand : Replaced long subtraction with addition → NO_COVERAGE |
long time = System.currentTimeMillis() - confirming.remove(player); |
| 51 |
3
1. onCommand : changed conditional boundary → NO_COVERAGE 2. onCommand : Replaced long multiplication with division → NO_COVERAGE 3. onCommand : negated conditional → NO_COVERAGE |
if (time < config.getInt("text.timeout") * 1000L) { |
| 52 |
1
1. onCommand : removed call to sh/okx/rankup/RankupHelper::rankup → NO_COVERAGE |
plugin.getHelper().rankup(player); |
| 53 |
1
1. onCommand : replaced boolean return with false for sh/okx/rankup/commands/RankupCommand::onCommand → NO_COVERAGE |
return true; |
| 54 | } | |
| 55 | } | |
| 56 | ||
| 57 | switch (confirmationType) { | |
| 58 | case "text": | |
| 59 | confirming.put(player, System.currentTimeMillis()); | |
| 60 | plugin.getMessage(rankElement.getRank(), Message.CONFIRMATION) | |
| 61 | .replacePlayer(player) | |
| 62 | .replaceOldRank(rankElement.getRank()) | |
| 63 | .replaceRank(rankElement.getNext().getRank()) | |
| 64 |
1
1. onCommand : removed call to sh/okx/rankup/messages/MessageBuilder::send → NO_COVERAGE |
.send(player); |
| 65 | break; | |
| 66 | case "gui": | |
| 67 |
3
1. onCommand : changed conditional boundary → NO_COVERAGE 2. onCommand : negated conditional → NO_COVERAGE 3. onCommand : negated conditional → NO_COVERAGE |
Gui gui = Gui.of(player, rankElement.getRank(), rankElement.getNext().getRank(), plugin, args.length > 0 && args[0].equalsIgnoreCase("gui")); |
| 68 |
1
1. onCommand : negated conditional → NO_COVERAGE |
if (gui == null) { |
| 69 |
1
1. onCommand : removed call to org/bukkit/entity/Player::sendMessage → NO_COVERAGE |
player.sendMessage(ChatColor.RED + "GUI is not available. Check console for more information."); |
| 70 |
1
1. onCommand : replaced boolean return with false for sh/okx/rankup/commands/RankupCommand::onCommand → NO_COVERAGE |
return true; |
| 71 | } | |
| 72 |
1
1. onCommand : removed call to sh/okx/rankup/gui/Gui::open → NO_COVERAGE |
gui.open(player); |
| 73 | break; | |
| 74 | case "none": | |
| 75 |
1
1. onCommand : removed call to sh/okx/rankup/RankupHelper::rankup → NO_COVERAGE |
plugin.getHelper().rankup(player); |
| 76 | break; | |
| 77 | default: | |
| 78 | throw new IllegalArgumentException("Invalid confirmation type " + confirmationType); | |
| 79 | } | |
| 80 |
1
1. onCommand : replaced boolean return with false for sh/okx/rankup/commands/RankupCommand::onCommand → NO_COVERAGE |
return true; |
| 81 | } | |
| 82 | } | |
Mutations | ||
| 28 |
1.1 |
|
| 29 |
1.1 |
|
| 33 |
1.1 |
|
| 34 |
1.1 |
|
| 39 |
1.1 |
|
| 40 |
1.1 |
|
| 49 |
1.1 2.2 3.3 4.4 5.5 |
|
| 50 |
1.1 |
|
| 51 |
1.1 2.2 3.3 |
|
| 52 |
1.1 |
|
| 53 |
1.1 |
|
| 64 |
1.1 |
|
| 67 |
1.1 2.2 3.3 |
|
| 68 |
1.1 |
|
| 69 |
1.1 |
|
| 70 |
1.1 |
|
| 72 |
1.1 |
|
| 75 |
1.1 |
|
| 80 |
1.1 |