Skip to content

Commit 425853e

Browse files
committed
add back positive checks
1 parent 463b4a6 commit 425853e

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

paper-api/src/main/java/org/bukkit/OfflinePlayer.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,17 +313,17 @@ default void incrementStatistic(final io.papermc.paper.statistic.Statistic<?> st
313313
*
314314
* @param statistic the stat to decrement
315315
* @param amount the value to decrement by
316+
* @throws IllegalArgumentException if amount is negative
316317
* @throws IllegalArgumentException if the stat would have a negative value after decrementing it
317318
*/
318-
default void decrementStatistic(final io.papermc.paper.statistic.Statistic<?> statistic, final int amount) {
319-
this.incrementStatistic(statistic, -amount);
320-
}
319+
void decrementStatistic(final io.papermc.paper.statistic.Statistic<?> statistic, final int amount);
321320

322321
/**
323322
* Increments the given stat for this player.
324323
*
325324
* @param statistic the stat to increment
326325
* @param amount the amount to increment by
326+
* @throws IllegalArgumentException if amount is negative
327327
*/
328328
void incrementStatistic(io.papermc.paper.statistic.Statistic<?> statistic, int amount);
329329

@@ -377,6 +377,7 @@ default void decrementStatistic(final io.papermc.paper.statistic.Statistic<?> st
377377
*/
378378
@Nullable Location getRespawnLocation(boolean loadLocationAndValidate);
379379

380+
//<editor-fold desc="deprecated statistic methods" defaultstate="collapsed">
380381
/**
381382
* Increments the given statistic for this player.
382383
* <p>
@@ -422,6 +423,7 @@ default void decrementStatistic(Statistic statistic) throws IllegalArgumentExcep
422423
* @throws IllegalArgumentException if statistic is null
423424
* @throws IllegalArgumentException if the statistic requires an
424425
* additional parameter
426+
* @throws IllegalArgumentException if amount isn't positive
425427
* @deprecated use {@link #incrementStatistic(io.papermc.paper.statistic.Statistic, int)}
426428
*/
427429
@Deprecated(since = "1.21.6")
@@ -438,6 +440,7 @@ default void incrementStatistic(Statistic statistic, int amount) throws IllegalA
438440
* @throws IllegalArgumentException if statistic is null
439441
* @throws IllegalArgumentException if the statistic requires an
440442
* additional parameter
443+
* @throws IllegalArgumentException if amount isn't positive
441444
* @throws IllegalArgumentException if the statistic would have a negative value after decrementing it
442445
* @deprecated use {@link #decrementStatistic(io.papermc.paper.statistic.Statistic, int)}
443446
*/
@@ -550,6 +553,7 @@ default int getStatistic(Statistic statistic, Material material) throws IllegalA
550553
* @param amount Amount to increment this statistic by
551554
* @throws IllegalArgumentException if statistic is null
552555
* @throws IllegalArgumentException if material is null
556+
* @throws IllegalArgumentException if amount isn't positive
553557
* @throws IllegalArgumentException if the given parameter is not valid
554558
* for the statistic
555559
* @deprecated use {@link #incrementStatistic(io.papermc.paper.statistic.Statistic, int)}
@@ -569,6 +573,7 @@ default void incrementStatistic(Statistic statistic, Material material, int amou
569573
* @param amount Amount to decrement this statistic by
570574
* @throws IllegalArgumentException if statistic is null
571575
* @throws IllegalArgumentException if material is null
576+
* @throws IllegalArgumentException if amount isn't positive
572577
* @throws IllegalArgumentException if the given parameter is not valid
573578
* for the statistic
574579
* @throws IllegalArgumentException if the statistic would have a negative value after decrementing it
@@ -671,6 +676,7 @@ default int getStatistic(Statistic statistic, EntityType entityType) throws Ille
671676
* @param amount Amount to increment this statistic by
672677
* @throws IllegalArgumentException if statistic is null
673678
* @throws IllegalArgumentException if entityType is null
679+
* @throws IllegalArgumentException if amount isn't positive
674680
* @throws IllegalArgumentException if the given parameter is not valid
675681
* for the statistic
676682
* @deprecated use {@link #incrementStatistic(io.papermc.paper.statistic.Statistic, int)}
@@ -690,6 +696,7 @@ default void incrementStatistic(Statistic statistic, EntityType entityType, int
690696
* @param amount Amount to decrement this statistic by
691697
* @throws IllegalArgumentException if statistic is null
692698
* @throws IllegalArgumentException if entityType is null
699+
* @throws IllegalArgumentException if amount isn't positive
693700
* @throws IllegalArgumentException if the given parameter is not valid
694701
* for the statistic
695702
* @throws IllegalArgumentException if the statistic would have a negative value after decrementing it
@@ -721,6 +728,7 @@ default void setStatistic(Statistic statistic, EntityType entityType, int newVal
721728
Preconditions.checkArgument(entityType != null, "EntityType cannot be null");
722729
this.setStatistic(statistic.toModern(entityType, null), newValue);
723730
}
731+
//</editor-fold>
724732

725733
/**
726734
* Gets the player's last death location.

paper-api/src/main/java/org/bukkit/Statistic.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public enum Type {
192192
ENTITY;
193193
}
194194

195-
@Deprecated(forRemoval = true)
195+
@Deprecated
196196
@ApiStatus.Internal
197197
public static Statistic toLegacy(final io.papermc.paper.statistic.Statistic<?> stat) {
198198
Key key = stat.type().key();
@@ -203,7 +203,7 @@ public static Statistic toLegacy(final io.papermc.paper.statistic.Statistic<?> s
203203
}
204204

205205
@SuppressWarnings("unchecked")
206-
@Deprecated(forRemoval = true)
206+
@Deprecated
207207
@ApiStatus.Internal
208208
public io.papermc.paper.statistic.Statistic<?> toModern(@Nullable EntityType entityType, @Nullable Material material) {
209209
Preconditions.checkArgument(entityType == null || material == null, "No stat has an entity type and material value at the same time");

paper-server/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.bukkit.craftbukkit;
22

3+
import com.google.common.base.Preconditions;
34
import com.mojang.authlib.GameProfile;
45
import io.papermc.paper.statistic.PaperStatistics;
56
import io.papermc.paper.statistic.Statistic;
@@ -383,8 +384,21 @@ private ServerStatsCounter getStatisticManager() {
383384
return this.server.getHandle().getPlayerStats(this.getUniqueId(), this.getName());
384385
}
385386

387+
@Override
388+
public void decrementStatistic(final Statistic<?> statistic, final int amount) {
389+
Preconditions.checkArgument(amount > 0, "Amount must be greater than 0");
390+
if (this.isOnline()) {
391+
this.getPlayer().decrementStatistic(statistic, amount);
392+
} else {
393+
final ServerStatsCounter manager = this.getStatisticManager();
394+
PaperStatistics.changeStatistic(manager, statistic, -amount, null);
395+
manager.save();
396+
}
397+
}
398+
386399
@Override
387400
public void incrementStatistic(final Statistic<?> statistic, final int amount) {
401+
Preconditions.checkArgument(amount > 0, "Amount must be greater than 0");
388402
if (this.isOnline()) {
389403
this.getPlayer().incrementStatistic(statistic, amount);
390404
} else {

paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,8 +1636,15 @@ public Set<NamespacedKey> getDiscoveredRecipes() {
16361636
return bukkitRecipeKeys.build();
16371637
}
16381638

1639+
@Override
1640+
public void decrementStatistic(final Statistic<?> statistic, final int amount) {
1641+
Preconditions.checkArgument(amount > 0, "Amount must be greater than 0");
1642+
PaperStatistics.changeStatistic(this.getHandle().getStats(), statistic, -amount, this.getHandle());
1643+
}
1644+
16391645
@Override
16401646
public void incrementStatistic(final Statistic<?> statistic, final int amount) {
1647+
Preconditions.checkArgument(amount > 0, "Amount must be greater than 0");
16411648
PaperStatistics.changeStatistic(this.getHandle().getStats(), statistic, amount, this.getHandle());
16421649
}
16431650

0 commit comments

Comments
 (0)