Skip to content

Commit 029ea55

Browse files
tastybentoclaude
andcommitted
Modernise AcidEffect: putIfAbsent and Math.clamp (S3824, S6885)
Replace containsKey+put with putIfAbsent for the wet-players guard. Replace Math.max(0,Math.min(100,...)) with Math.clamp in both damage percent calculations (rain and acid). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d5ad06e commit 029ea55

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

src/main/java/world/bentobox/acidisland/listeners/AcidEffect.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ private void handleRainExposure(Player player) {
134134
}
135135
if (isSafeFromRain(player)) {
136136
wetPlayers.remove(player);
137-
} else if (!wetPlayers.containsKey(player)) {
138-
wetPlayers.put(player, System.currentTimeMillis() + addon.getSettings().getAcidDamageDelay() * 1000);
137+
} else if (wetPlayers.putIfAbsent(player, System.currentTimeMillis() + addon.getSettings().getAcidDamageDelay() * 1000L) == null) {
139138
new BukkitRunnable() {
140139
@Override
141140
public void run() {
@@ -175,8 +174,7 @@ protected boolean checkForRain(Player player) {
175174

176175
User user = User.getInstance(player);
177176
// Get the percentage reduction and ensure the value is between 0 and 100
178-
double percent = (100
179-
- Math.max(0, Math.min(100, user.getPermissionValue("acidisland.protection.rain", 0)))) / 100D;
177+
double percent = (100 - Math.clamp(user.getPermissionValue("acidisland.protection.rain", 0), 0, 100)) / 100D;
180178

181179
double totalDamage = Math.max(0, addon.getSettings().getAcidRainDamage() - protection) * percent;
182180

@@ -210,8 +208,7 @@ protected boolean continuouslyHurtPlayer(Player player) {
210208

211209
User user = User.getInstance(player);
212210
// Get the percentage reduction and ensure the value is between 0 and 100
213-
double percent = (100
214-
- Math.max(0, Math.min(100, user.getPermissionValue("acidisland.protection.acid", 0)))) / 100D;
211+
double percent = (100 - Math.clamp(user.getPermissionValue("acidisland.protection.acid", 0), 0, 100)) / 100D;
215212

216213
double totalDamage = Math.max(0, addon.getSettings().getAcidDamage() - protection) * percent;
217214

0 commit comments

Comments
 (0)