1 | package sh.okx.rankup; | |
2 | ||
3 | import java.util.HashMap; | |
4 | import java.util.Map; | |
5 | import java.util.Objects; | |
6 | import org.bukkit.Bukkit; | |
7 | import org.bukkit.configuration.ConfigurationSection; | |
8 | import org.bukkit.entity.Player; | |
9 | import sh.okx.rankup.events.PlayerPrestigeEvent; | |
10 | import sh.okx.rankup.events.PlayerRankupEvent; | |
11 | import sh.okx.rankup.hook.GroupProvider; | |
12 | import sh.okx.rankup.messages.Message; | |
13 | import sh.okx.rankup.prestige.Prestige; | |
14 | import sh.okx.rankup.prestige.Prestiges; | |
15 | import sh.okx.rankup.ranks.Rank; | |
16 | import sh.okx.rankup.ranks.RankElement; | |
17 | import sh.okx.rankup.ranks.Rankups; | |
18 | ||
19 | /** | |
20 | * Actually performs the ranking up and prestiging for the plugin and also manages the cooldowns | |
21 | * between ranking up. | |
22 | */ | |
23 | public class RankupHelper { | |
24 | ||
25 | private final RankupPlugin plugin; | |
26 | private final ConfigurationSection config; | |
27 | private final GroupProvider permissions; | |
28 | /** | |
29 | * Players who cannot rankup/prestige for a certain amount of time. | |
30 | */ | |
31 | private final Map<Player, Long> cooldowns = new HashMap<>(); | |
32 | ||
33 | public RankupHelper(RankupPlugin plugin) { | |
34 | this.plugin = plugin; | |
35 | this.config = plugin.getConfig(); | |
36 | this.permissions = plugin.getPermissions(); | |
37 | } | |
38 | ||
39 | public void doRankup(Player player, RankElement<Rank> rank) { | |
40 |
1
1. doRankup : negated conditional → SURVIVED |
if (rank.getRank() != null) { |
41 |
1
1. doRankup : removed call to sh/okx/rankup/hook/GroupProvider::removeGroup → SURVIVED |
permissions.removeGroup(player.getUniqueId(), rank.getRank().getRank()); |
42 | } | |
43 |
1
1. doRankup : removed call to sh/okx/rankup/hook/GroupProvider::addGroup → KILLED |
permissions.addGroup(player.getUniqueId(), rank.getNext().getRank().getRank()); |
44 | ||
45 |
1
1. doRankup : removed call to sh/okx/rankup/ranks/Rank::runCommands → SURVIVED |
rank.getRank().runCommands(player, rank.getNext().getRank()); |
46 | ||
47 |
1
1. doRankup : removed call to org/bukkit/plugin/PluginManager::callEvent → SURVIVED |
Bukkit.getPluginManager().callEvent(new PlayerRankupEvent(plugin, player, rank)); |
48 | } | |
49 | ||
50 | public void sendRankupMessages(Player player, RankElement<Rank> rank) { | |
51 | plugin.getMessage(rank.getRank(), Message.SUCCESS_PUBLIC) | |
52 | .failIfEmpty() | |
53 | .replacePlayer(player) | |
54 | .replaceOldRank(rank.getRank()) | |
55 | .replaceRank(rank.getNext().getRank()) | |
56 |
1
1. sendRankupMessages : removed call to sh/okx/rankup/messages/MessageBuilder::broadcast → KILLED |
.broadcast(); |
57 | plugin.getMessage(rank.getRank(), Message.SUCCESS_PRIVATE) | |
58 | .failIfEmpty() | |
59 | .replacePlayer(player) | |
60 | .replaceOldRank(rank.getRank()) | |
61 | .replaceRank(rank.getNext().getRank()) | |
62 |
1
1. sendRankupMessages : removed call to sh/okx/rankup/messages/MessageBuilder::send → KILLED |
.send(player); |
63 | } | |
64 | ||
65 | public void doPrestige(Player player, RankElement<Prestige> prestige) { | |
66 | Prestige rank = prestige.getRank(); | |
67 | ||
68 |
1
1. doPrestige : removed call to sh/okx/rankup/hook/GroupProvider::removeGroup → NO_COVERAGE |
permissions.removeGroup(player.getUniqueId(), rank.getFrom()); |
69 |
1
1. doPrestige : removed call to sh/okx/rankup/hook/GroupProvider::addGroup → NO_COVERAGE |
permissions.addGroup(player.getUniqueId(), rank.getTo()); |
70 | ||
71 |
1
1. doPrestige : negated conditional → NO_COVERAGE |
if (rank.getRank() != null) { |
72 |
1
1. doPrestige : removed call to sh/okx/rankup/hook/GroupProvider::removeGroup → NO_COVERAGE |
permissions.removeGroup(player.getUniqueId(), rank.getRank()); |
73 | } | |
74 |
1
1. doPrestige : removed call to sh/okx/rankup/hook/GroupProvider::addGroup → NO_COVERAGE |
permissions.addGroup(player.getUniqueId(), prestige.getNext().getRank().getRank()); |
75 | ||
76 |
1
1. doPrestige : removed call to sh/okx/rankup/prestige/Prestige::runCommands → NO_COVERAGE |
rank.runCommands(player, prestige.getNext().getRank()); |
77 | ||
78 |
1
1. doPrestige : removed call to org/bukkit/plugin/PluginManager::callEvent → NO_COVERAGE |
Bukkit.getPluginManager().callEvent(new PlayerPrestigeEvent(plugin, player, prestige)); |
79 | } | |
80 | ||
81 | public void sendPrestigeMessages(Player player, RankElement<Prestige> prestige) { | |
82 | Objects.requireNonNull(prestige); | |
83 | Objects.requireNonNull(prestige.getNext()); | |
84 | ||
85 | plugin.getMessage(prestige.getRank(), Message.PRESTIGE_SUCCESS_PUBLIC) | |
86 | .failIfEmpty() | |
87 | .replacePlayer(player) | |
88 | .replaceOldRank(prestige.getRank()) | |
89 | .replaceRank(prestige.getNext().getRank()) | |
90 |
1
1. sendPrestigeMessages : removed call to sh/okx/rankup/messages/MessageBuilder::broadcast → NO_COVERAGE |
.broadcast(); |
91 | plugin.getMessage(prestige.getRank(), Message.PRESTIGE_SUCCESS_PRIVATE) | |
92 | .failIfEmpty() | |
93 | .replacePlayer(player) | |
94 | .replaceOldRank(prestige.getRank()) | |
95 | .replaceRank(prestige.getNext().getRank()) | |
96 |
1
1. sendPrestigeMessages : removed call to sh/okx/rankup/messages/MessageBuilder::send → NO_COVERAGE |
.send(player); |
97 | } | |
98 | ||
99 | private boolean checkCooldown(Player player, Rank rank) { | |
100 |
1
1. checkCooldown : negated conditional → KILLED |
if (cooldowns.containsKey(player)) { |
101 |
1
1. checkCooldown : Replaced long subtraction with addition → NO_COVERAGE |
long time = System.currentTimeMillis() - cooldowns.get(player); |
102 | // if time passed is less than the cooldown | |
103 | long cooldownSeconds = config.getInt("cooldown"); | |
104 |
2
1. checkCooldown : Replaced long multiplication with division → NO_COVERAGE 2. checkCooldown : Replaced long subtraction with addition → NO_COVERAGE |
long timeLeft = (cooldownSeconds * 1000) - time; |
105 |
2
1. checkCooldown : changed conditional boundary → NO_COVERAGE 2. checkCooldown : negated conditional → NO_COVERAGE |
if (timeLeft > 0) { |
106 |
1
1. checkCooldown : Replaced float division with multiplication → NO_COVERAGE |
long secondsLeft = (long) Math.ceil(timeLeft / 1000f); |
107 | plugin | |
108 |
2
1. checkCooldown : changed conditional boundary → NO_COVERAGE 2. checkCooldown : negated conditional → NO_COVERAGE |
.getMessage(rank, secondsLeft > 1 ? Message.COOLDOWN_PLURAL : Message.COOLDOWN_SINGULAR) |
109 | .failIfEmpty() | |
110 | .replacePlayer(player) | |
111 | .replaceRank(rank) | |
112 | .replaceSeconds(cooldownSeconds, secondsLeft) | |
113 |
1
1. checkCooldown : removed call to sh/okx/rankup/messages/MessageBuilder::send → NO_COVERAGE |
.send(player); |
114 |
1
1. checkCooldown : replaced boolean return with false for sh/okx/rankup/RankupHelper::checkCooldown → NO_COVERAGE |
return true; |
115 | } | |
116 | // cooldown has expired so remove it | |
117 | cooldowns.remove(player); | |
118 | } | |
119 |
1
1. checkCooldown : replaced boolean return with true for sh/okx/rankup/RankupHelper::checkCooldown → KILLED |
return false; |
120 | } | |
121 | ||
122 | private void applyCooldown(Player player) { | |
123 |
2
1. applyCooldown : changed conditional boundary → SURVIVED 2. applyCooldown : negated conditional → SURVIVED |
if (config.getInt("cooldown") > 0) { |
124 | cooldowns.put(player, System.currentTimeMillis()); | |
125 | } | |
126 | } | |
127 | ||
128 | public void rankup(Player player) { | |
129 |
1
1. rankup : negated conditional → KILLED |
if (!checkRankup(player)) { |
130 | return; | |
131 | } | |
132 | ||
133 | RankElement<Rank> rankElement = plugin.getRankups().getByPlayer(player); | |
134 | Rank rank = rankElement.getRank(); | |
135 |
1
1. rankup : removed call to sh/okx/rankup/ranks/Rank::applyRequirements → KILLED |
rank.applyRequirements(player); |
136 |
1
1. rankup : removed call to sh/okx/rankup/RankupHelper::applyCooldown → SURVIVED |
applyCooldown(player); |
137 | ||
138 |
1
1. rankup : removed call to sh/okx/rankup/RankupHelper::doRankup → KILLED |
doRankup(player, rankElement); |
139 |
1
1. rankup : removed call to sh/okx/rankup/RankupHelper::sendRankupMessages → KILLED |
sendRankupMessages(player, rankElement); |
140 | } | |
141 | ||
142 | public boolean checkRankup(Player player) { | |
143 |
2
1. checkRankup : replaced boolean return with false for sh/okx/rankup/RankupHelper::checkRankup → KILLED 2. checkRankup : replaced boolean return with true for sh/okx/rankup/RankupHelper::checkRankup → KILLED |
return checkRankup(player, true); |
144 | } | |
145 | ||
146 | /** | |
147 | * Checks if a player can rankup, and if they can't, sends the player a message and returns false | |
148 | * | |
149 | * @param player the player to check if they can rankup | |
150 | * @return true if the player can rankup, false otherwise | |
151 | */ | |
152 | public boolean checkRankup(Player player, boolean message) { | |
153 | Rankups rankups = plugin.getRankups(); | |
154 | RankElement<Rank> rankElement = rankups.getByPlayer(player); | |
155 |
1
1. checkRankup : negated conditional → KILLED |
if (rankElement == null) { // check if in ladder |
156 |
1
1. checkRankup : negated conditional → KILLED |
plugin.getMessage(Message.NOT_IN_LADDER) |
157 | .failIf(!message) | |
158 | .replacePlayer(player) | |
159 |
1
1. checkRankup : removed call to sh/okx/rankup/messages/MessageBuilder::send → KILLED |
.send(player); |
160 |
1
1. checkRankup : replaced boolean return with true for sh/okx/rankup/RankupHelper::checkRankup → KILLED |
return false; |
161 | } | |
162 | Rank rank = rankElement.getRank(); | |
163 |
1
1. checkRankup : negated conditional → KILLED |
if (!rankElement.hasNext()) { |
164 | Prestiges prestiges = plugin.getPrestiges(); | |
165 | Message pMessage = Message.NO_RANKUP; | |
166 |
1
1. checkRankup : negated conditional → KILLED |
if (prestiges != null) { |
167 | RankElement<Prestige> byPlayer = prestiges.getByPlayer(player); | |
168 |
2
1. checkRankup : negated conditional → NO_COVERAGE 2. checkRankup : negated conditional → KILLED |
if (byPlayer != null && byPlayer.hasNext()) { |
169 | pMessage = Message.MUST_PRESTIGE; | |
170 | } | |
171 | } | |
172 |
1
1. checkRankup : negated conditional → KILLED |
plugin.getMessage(pMessage) |
173 | .failIf(!message) | |
174 | .replacePlayer(player) | |
175 | .replaceRank(rankups.getTree().last().getRank()) | |
176 |
1
1. checkRankup : removed call to sh/okx/rankup/messages/MessageBuilder::send → KILLED |
.send(player); |
177 |
1
1. checkRankup : replaced boolean return with true for sh/okx/rankup/RankupHelper::checkRankup → KILLED |
return false; |
178 |
1
1. checkRankup : negated conditional → KILLED |
} else if (!rank.hasRequirements(player)) { // check if they can afford it |
179 |
1
1. checkRankup : negated conditional → KILLED |
if (message) { |
180 | plugin.getMessage(rank, Message.REQUIREMENTS_NOT_MET) | |
181 | .replacePlayer(player) | |
182 | .replaceOldRank(rank) | |
183 | .replaceRank(rankElement.getNext().getRank()) | |
184 |
1
1. checkRankup : removed call to sh/okx/rankup/messages/MessageBuilder::send → KILLED |
.send(player); |
185 | } | |
186 |
1
1. checkRankup : replaced boolean return with true for sh/okx/rankup/RankupHelper::checkRankup → KILLED |
return false; |
187 |
2
1. checkRankup : negated conditional → SURVIVED 2. checkRankup : negated conditional → KILLED |
} else if (message && checkCooldown(player, rank)) { |
188 |
1
1. checkRankup : replaced boolean return with true for sh/okx/rankup/RankupHelper::checkRankup → NO_COVERAGE |
return false; |
189 | } | |
190 | ||
191 |
1
1. checkRankup : replaced boolean return with false for sh/okx/rankup/RankupHelper::checkRankup → KILLED |
return true; |
192 | } | |
193 | ||
194 | public void prestige(Player player) { | |
195 |
1
1. prestige : negated conditional → NO_COVERAGE |
if (!checkPrestige(player)) { |
196 | return; | |
197 | } | |
198 | ||
199 | RankElement<Prestige> rankElement = plugin.getPrestiges().getByPlayer(player); | |
200 | Prestige prestige = rankElement.getRank(); | |
201 |
1
1. prestige : removed call to sh/okx/rankup/prestige/Prestige::applyRequirements → NO_COVERAGE |
prestige.applyRequirements(player); |
202 | ||
203 |
1
1. prestige : removed call to sh/okx/rankup/RankupHelper::applyCooldown → NO_COVERAGE |
applyCooldown(player); |
204 |
1
1. prestige : removed call to sh/okx/rankup/RankupHelper::doPrestige → NO_COVERAGE |
doPrestige(player, rankElement); |
205 |
1
1. prestige : removed call to sh/okx/rankup/RankupHelper::sendPrestigeMessages → NO_COVERAGE |
sendPrestigeMessages(player, rankElement); |
206 | } | |
207 | ||
208 | public boolean checkPrestige(Player player) { | |
209 |
2
1. checkPrestige : replaced boolean return with false for sh/okx/rankup/RankupHelper::checkPrestige → NO_COVERAGE 2. checkPrestige : replaced boolean return with true for sh/okx/rankup/RankupHelper::checkPrestige → NO_COVERAGE |
return checkPrestige(player, true); |
210 | } | |
211 | ||
212 | public boolean checkPrestige(Player player, boolean message) { | |
213 | Prestiges prestiges = plugin.getPrestiges(); | |
214 | RankElement<Prestige> prestigeElement = prestiges.getByPlayer(player); | |
215 |
1
1. checkPrestige : negated conditional → NO_COVERAGE |
if (prestigeElement == null |
216 |
1
1. checkPrestige : negated conditional → NO_COVERAGE |
|| !prestigeElement.getRank().isEligible(player)) { // check if in ladder |
217 |
1
1. checkPrestige : negated conditional → NO_COVERAGE |
plugin.getMessage(Message.NOT_HIGH_ENOUGH) |
218 | .failIf(!message) | |
219 | .replacePlayer(player) | |
220 |
1
1. checkPrestige : removed call to sh/okx/rankup/messages/MessageBuilder::send → NO_COVERAGE |
.send(player); |
221 |
1
1. checkPrestige : replaced boolean return with true for sh/okx/rankup/RankupHelper::checkPrestige → NO_COVERAGE |
return false; |
222 |
1
1. checkPrestige : negated conditional → NO_COVERAGE |
} else if (!prestigeElement.hasNext()) { // check if they are at the highest rank |
223 |
1
1. checkPrestige : negated conditional → NO_COVERAGE |
plugin.getMessage(prestigeElement.getRank(), Message.PRESTIGE_NO_PRESTIGE) |
224 | .failIf(!message) | |
225 | .replacePlayer(player) | |
226 | .replaceRank(prestigeElement.getRank()) | |
227 |
1
1. checkPrestige : removed call to sh/okx/rankup/messages/MessageBuilder::send → NO_COVERAGE |
.send(player); |
228 |
1
1. checkPrestige : replaced boolean return with true for sh/okx/rankup/RankupHelper::checkPrestige → NO_COVERAGE |
return false; |
229 |
1
1. checkPrestige : negated conditional → NO_COVERAGE |
} else if (!prestigeElement.getRank().hasRequirements(player)) { // check if they can afford it |
230 |
1
1. checkPrestige : negated conditional → NO_COVERAGE |
plugin.getMessage(prestigeElement.getRank(), Message.PRESTIGE_REQUIREMENTS_NOT_MET) |
231 | .failIf(!message) | |
232 | .replacePlayer(player) | |
233 | .replaceOldRank(prestigeElement.getRank()) | |
234 | .replaceRank(prestigeElement.getNext().getRank()) | |
235 |
1
1. checkPrestige : removed call to sh/okx/rankup/messages/MessageBuilder::send → NO_COVERAGE |
.send(player); |
236 |
1
1. checkPrestige : replaced boolean return with true for sh/okx/rankup/RankupHelper::checkPrestige → NO_COVERAGE |
return false; |
237 |
1
1. checkPrestige : negated conditional → NO_COVERAGE |
} else if (checkCooldown(player, prestigeElement.getRank())) { |
238 |
1
1. checkPrestige : replaced boolean return with true for sh/okx/rankup/RankupHelper::checkPrestige → NO_COVERAGE |
return false; |
239 | } | |
240 | ||
241 |
1
1. checkPrestige : replaced boolean return with false for sh/okx/rankup/RankupHelper::checkPrestige → NO_COVERAGE |
return true; |
242 | } | |
243 | } | |
Mutations | ||
40 |
1.1 |
|
41 |
1.1 |
|
43 |
1.1 |
|
45 |
1.1 |
|
47 |
1.1 |
|
56 |
1.1 |
|
62 |
1.1 |
|
68 |
1.1 |
|
69 |
1.1 |
|
71 |
1.1 |
|
72 |
1.1 |
|
74 |
1.1 |
|
76 |
1.1 |
|
78 |
1.1 |
|
90 |
1.1 |
|
96 |
1.1 |
|
100 |
1.1 |
|
101 |
1.1 |
|
104 |
1.1 2.2 |
|
105 |
1.1 2.2 |
|
106 |
1.1 |
|
108 |
1.1 2.2 |
|
113 |
1.1 |
|
114 |
1.1 |
|
119 |
1.1 |
|
123 |
1.1 2.2 |
|
129 |
1.1 |
|
135 |
1.1 |
|
136 |
1.1 |
|
138 |
1.1 |
|
139 |
1.1 |
|
143 |
1.1 2.2 |
|
155 |
1.1 |
|
156 |
1.1 |
|
159 |
1.1 |
|
160 |
1.1 |
|
163 |
1.1 |
|
166 |
1.1 |
|
168 |
1.1 2.2 |
|
172 |
1.1 |
|
176 |
1.1 |
|
177 |
1.1 |
|
178 |
1.1 |
|
179 |
1.1 |
|
184 |
1.1 |
|
186 |
1.1 |
|
187 |
1.1 2.2 |
|
188 |
1.1 |
|
191 |
1.1 |
|
195 |
1.1 |
|
201 |
1.1 |
|
203 |
1.1 |
|
204 |
1.1 |
|
205 |
1.1 |
|
209 |
1.1 2.2 |
|
215 |
1.1 |
|
216 |
1.1 |
|
217 |
1.1 |
|
220 |
1.1 |
|
221 |
1.1 |
|
222 |
1.1 |
|
223 |
1.1 |
|
227 |
1.1 |
|
228 |
1.1 |
|
229 |
1.1 |
|
230 |
1.1 |
|
235 |
1.1 |
|
236 |
1.1 |
|
237 |
1.1 |
|
238 |
1.1 |
|
241 |
1.1 |