Skip to content

Commit 7b5aaf7

Browse files
committed
tweaks
1 parent b9342e1 commit 7b5aaf7

File tree

13 files changed

+71
-79
lines changed

13 files changed

+71
-79
lines changed

paper-api/src/main/java/io/papermc/paper/registry/RegistryKey.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ public sealed interface RegistryKey<T> extends Keyed permits RegistryKeyImpl {
145145
*/
146146
RegistryKey<StatisticType<?>> STAT_TYPE = create("stat_type");
147147

148-
149-
150148
/* ********************** *
151149
* Data-driven Registries *
152150
* ********************** */

paper-api/src/main/java/io/papermc/paper/statistic/CustomStatistic.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public interface CustomStatistic extends Keyed, Translatable {
1515
/**
1616
* Gets the statistic with the given custom stat.
1717
*
18-
* @return the statistic for the custom stat.
18+
* @return the statistic for the custom stat
1919
*/
2020
default Statistic<CustomStatistic> stat() {
2121
return StatisticTypes.CUSTOM.forValue(this);

paper-api/src/main/java/io/papermc/paper/statistic/CustomStatistics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public final class CustomStatistics {
165165
public static final CustomStatistic WALK_UNDER_WATER_ONE_CM = get("walk_under_water_one_cm");
166166
// End generate - CustomStatistics
167167

168-
private static CustomStatistic get(@KeyPattern.Value final String key) {
168+
private static CustomStatistic get(final @KeyPattern.Value String key) {
169169
return Registry.CUSTOM_STAT.getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key));
170170
}
171171

paper-api/src/main/java/io/papermc/paper/statistic/Statistic.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Represents an individual statistic. Obtained via {@link StatisticType#forValue(Object)}.
88
* Can be used as a criteria for {@link org.bukkit.scoreboard.Scoreboard#registerNewObjective(String, Criteria, net.kyori.adventure.text.Component)}
99
*
10-
* @param <S> stat value type.
10+
* @param <S> stat value type
1111
*/
1212
@ApiStatus.NonExtendable
1313
public interface Statistic<S> extends Criteria {

paper-api/src/main/java/io/papermc/paper/statistic/StatisticType.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
@ApiStatus.NonExtendable
1515
public interface StatisticType<S> extends Keyed, Translatable {
1616

17-
1817
/**
1918
* Creates or gets the statistic from this type for the specified value.
2019
*

paper-api/src/main/java/io/papermc/paper/statistic/StatisticTypes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public final class StatisticTypes {
3333
// End generate - StatisticTypes
3434

3535
@SuppressWarnings("unchecked")
36-
private static <S> StatisticType<S> get(@KeyPattern.Value final String key) {
36+
private static <S> StatisticType<S> get(final @KeyPattern.Value String key) {
3737
return (StatisticType<S>) Registry.STAT_TYPE.getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key));
3838
}
3939

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import org.bukkit.entity.Player;
1414
import org.bukkit.permissions.ServerOperator;
1515
import org.bukkit.profile.PlayerProfile;
16+
import org.checkerframework.checker.index.qual.NonNegative;
17+
import org.checkerframework.checker.index.qual.Positive;
1618
import org.jspecify.annotations.NonNull;
1719
import org.jspecify.annotations.NullMarked;
1820
import org.jspecify.annotations.Nullable;
@@ -315,19 +317,19 @@ default void incrementStatistic(final io.papermc.paper.statistic.Statistic<?> st
315317
*
316318
* @param statistic the stat to decrement
317319
* @param amount the value to decrement by
318-
* @throws IllegalArgumentException if amount is negative
320+
* @throws IllegalArgumentException if amount is negative or 0
319321
* @throws IllegalArgumentException if the stat would have a negative value after decrementing it
320322
*/
321-
void decrementStatistic(final io.papermc.paper.statistic.Statistic<?> statistic, final int amount);
323+
void decrementStatistic(io.papermc.paper.statistic.Statistic<?> statistic, @Positive int amount);
322324

323325
/**
324326
* Increments the given stat for this player.
325327
*
326328
* @param statistic the stat to increment
327329
* @param amount the amount to increment by
328-
* @throws IllegalArgumentException if amount is negative
330+
* @throws IllegalArgumentException if amount is negative or 0
329331
*/
330-
void incrementStatistic(io.papermc.paper.statistic.Statistic<?> statistic, int amount);
332+
void incrementStatistic(io.papermc.paper.statistic.Statistic<?> statistic, @Positive int amount);
331333

332334
/**
333335
* Sets the given stat for this player.
@@ -336,7 +338,7 @@ default void incrementStatistic(final io.papermc.paper.statistic.Statistic<?> st
336338
* @param newAmount the value to set the stat to
337339
* @throws IllegalArgumentException if the amount is negative
338340
*/
339-
void setStatistic(io.papermc.paper.statistic.Statistic<?> statistic, int newAmount);
341+
void setStatistic(io.papermc.paper.statistic.Statistic<?> statistic, @NonNegative int newAmount);
340342

341343
/**
342344
* Gets the given stat for this player.
@@ -394,8 +396,7 @@ default void incrementStatistic(final io.papermc.paper.statistic.Statistic<?> st
394396
*/
395397
@Deprecated(since = "1.21.11")
396398
default void incrementStatistic(Statistic statistic) throws IllegalArgumentException {
397-
Preconditions.checkArgument(statistic != null, "Statistic cannot be null");
398-
this.incrementStatistic(statistic.toModern(null, null));
399+
this.incrementStatistic(statistic, 1);
399400
}
400401

401402
/**
@@ -413,8 +414,7 @@ default void incrementStatistic(Statistic statistic) throws IllegalArgumentExcep
413414
*/
414415
@Deprecated(since = "1.21.11")
415416
default void decrementStatistic(Statistic statistic) throws IllegalArgumentException {
416-
Preconditions.checkArgument(statistic != null, "Statistic cannot be null");
417-
this.decrementStatistic(statistic.toModern(null, null));
417+
this.decrementStatistic(statistic, 1);
418418
}
419419

420420
/**

paper-server/patches/sources/net/minecraft/stats/StatsCounter.java.patch

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
--- a/net/minecraft/stats/StatsCounter.java
22
+++ b/net/minecraft/stats/StatsCounter.java
3-
@@ -14,6 +_,12 @@
3+
@@ -14,6 +_,11 @@
44

55
public void increment(Player player, Stat<?> stat, int amount) {
66
int i = (int)Math.min((long)this.getValue(stat) + amount, 2147483647L);
77
+ // CraftBukkit start - fire Statistic events
8-
+ org.bukkit.event.Cancellable cancellable = org.bukkit.craftbukkit.event.CraftEventFactory.handleStatisticsIncrease(player, stat, this.getValue(stat), i);
9-
+ if (cancellable != null && cancellable.isCancelled()) {
8+
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callStatisticIncreaseEvent(player, stat, this.getValue(stat), i)) {
109
+ return;
1110
+ }
1211
+ // CraftBukkit end

paper-server/src/main/java/io/papermc/paper/statistic/PaperStatistic.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public record PaperStatistic<S, M>(Stat<M> handle, S owner, M nmsValue, Statisti
88

99
@Override
1010
public String getName() {
11-
return Stat.buildName(this.handle.getType(),this.nmsValue);
11+
return Stat.buildName(this.handle.getType(), this.nmsValue);
1212
}
1313

1414
@Override

paper-server/src/main/java/io/papermc/paper/statistic/PaperStatisticType.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
import org.bukkit.craftbukkit.CraftRegistry;
2323
import org.bukkit.craftbukkit.entity.CraftEntityType;
2424
import org.bukkit.entity.EntityType;
25-
import org.jspecify.annotations.NonNull;
2625

27-
public class PaperStatisticType<S extends @NonNull Keyed, M> extends HolderableBase<StatType<M>> implements StatisticType<S> {
26+
public class PaperStatisticType<S extends Keyed, M> extends HolderableBase<StatType<M>> implements StatisticType<S> {
2827

2928
private final Supplier<RegistryKey<S>> registryKey;
3029
private final Map<S, Statistic<S>> statCacheMap;
@@ -46,25 +45,25 @@ private PaperStatisticType(final Holder<StatType<M>> holder, final Predicate<S>
4645
}
4746

4847
@SuppressWarnings("unchecked")
49-
public static <M> StatisticType<?> create(final Holder<StatType<?>> holder) {
50-
// don't call .value() here, its unbound
48+
public static <M> StatisticType<?> create(final Holder<?> holder) {
49+
// don't call .value() here, it's unbound
5150
if (holder.is(Identifier.withDefaultNamespace("killed")) || holder.is(Identifier.withDefaultNamespace("killed_by"))) {
5251
return new PaperStatisticType<>(
53-
(Holder<StatType<net.minecraft.world.entity.EntityType<?>>>) (Holder<?>) holder,
52+
(Holder<StatType<net.minecraft.world.entity.EntityType<?>>>) holder,
5453
t -> t != EntityType.UNKNOWN,
5554
CraftEntityType::bukkitToMinecraft,
5655
(entityType, ignored) -> CraftEntityType.minecraftToBukkit(entityType)
5756
);
5857
} else {
59-
return new PaperStatisticType<>((Holder<StatType<M>>) (Holder<?>) holder);
58+
return new PaperStatisticType<>((Holder<StatType<M>>) holder);
6059
}
6160
}
6261

63-
public static <A, M> StatisticType<A> minecraftToBukkit(final StatType<M> minecraft) {
62+
public static <S extends Keyed, M> PaperStatisticType<S, M> minecraftToBukkit(final StatType<M> minecraft) {
6463
return CraftRegistry.minecraftToBukkit(minecraft, Registries.STAT_TYPE);
6564
}
6665

67-
public static <A, M> StatType<M> bukkitToMinecraft(final StatisticType<A> bukkit) {
66+
public static <S, M> StatType<M> bukkitToMinecraft(final StatisticType<S> bukkit) {
6867
return CraftRegistry.bukkitToMinecraft(bukkit);
6968
}
7069

@@ -79,9 +78,9 @@ public Statistic<S> forValue(final S value) {
7978
}
8079
return this.statCacheMap.computeIfAbsent(
8180
value, newValue -> {
82-
final M nmsValue = this.bukkitToMinecraft.apply(value);
81+
final M nmsValue = this.bukkitToMinecraft.apply(newValue);
8382
final Stat<M> nmsStat = this.getHandle().get(nmsValue);
84-
return new PaperStatistic<>(nmsStat, value, nmsValue, this);
83+
return new PaperStatistic<>(nmsStat, newValue, nmsValue, this);
8584
}
8685
);
8786
}
@@ -93,7 +92,7 @@ public RegistryKey<S> registryKey() {
9392

9493
@Override
9594
public String translationKey() {
96-
Preconditions.checkArgument(this != StatisticTypes.CUSTOM, this.key() + " does not have a translation key, see CustomStatistic#translationKey()");
95+
Preconditions.checkArgument(this != StatisticTypes.CUSTOM, this.getKey() + " does not have a translation key, see CustomStatistic#translationKey()");
9796
return "stat_type." + this.getKey().toString().replace(':', '.');
9897
}
9998
}

0 commit comments

Comments
 (0)