Skip to content

Commit 1544ca8

Browse files
committed
small improvements
1 parent 10abcd4 commit 1544ca8

File tree

9 files changed

+21
-21
lines changed

9 files changed

+21
-21
lines changed

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
@@ -174,7 +174,7 @@ public interface CustomStatistic extends Keyed, Translatable {
174174
* @return the statistic for the custom stat.
175175
*/
176176
default Statistic<CustomStatistic> stat() {
177-
return StatisticType.CUSTOM.of(this);
177+
return StatisticType.CUSTOM.forValue(this);
178178
}
179179

180180
private static CustomStatistic get(@KeyPattern.Value final String key) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import org.jetbrains.annotations.ApiStatus;
55

66
/**
7-
* Represents an individual statistic. Obtained via {@link StatisticType#of(Object)}.
7+
* 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
*
1010
* @param <S> stat value type.
@@ -13,11 +13,11 @@
1313
public interface Statistic<S> extends Criteria {
1414

1515
/**
16-
* Gets the statistic.
16+
* Gets the owner of the statistic.
1717
*
18-
* @return the stat
18+
* @return the stat owner
1919
*/
20-
S value();
20+
S owner();
2121

2222
/**
2323
* Gets the stat type.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private static <S> StatisticType<S> get(@KeyPattern.Value final String key) {
4747
* @return the statistic for that thing
4848
* @throws IllegalArgumentException if the thing is not valid for this {@link StatisticType}
4949
*/
50-
Statistic<S> of(S value);
50+
Statistic<S> forValue(S value);
5151

5252
/**
5353
* Gets the registry key associated with this stat type.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public enum Type {
196196
@ApiStatus.Internal
197197
public static Statistic toLegacy(final io.papermc.paper.statistic.Statistic<?> stat) {
198198
Key key = stat.type().key();
199-
if (stat.type() == StatisticType.CUSTOM && stat.value() instanceof final CustomStatistic customStatistic) {
199+
if (stat.type() == StatisticType.CUSTOM && stat.owner() instanceof final CustomStatistic customStatistic) {
200200
key = customStatistic.getKey();
201201
}
202202
return Objects.requireNonNull(Registry.STATISTIC.get(key), "Couldn't convert " + stat + " to a legacy stat");
@@ -212,13 +212,13 @@ public io.papermc.paper.statistic.Statistic<?> toModern(@Nullable EntityType ent
212212
Preconditions.checkArgument(this.type != Type.BLOCK || material != null && material.isBlock(), "Must provide a valid block material");
213213
Preconditions.checkArgument(this.type != Type.ITEM || material != null && material.isItem(), "Must provide a valid item material");
214214
if (this.type == Type.UNTYPED) {
215-
return StatisticType.CUSTOM.of(Objects.requireNonNull(Registry.CUSTOM_STAT.get(this.key), "Couldn't convert " + this + " to a modern stat"));
215+
return StatisticType.CUSTOM.forValue(Objects.requireNonNull(Registry.CUSTOM_STAT.get(this.key), "Couldn't convert " + this + " to a modern stat"));
216216
} else {
217217
StatisticType<?> statType = Objects.requireNonNull(Registry.STAT_TYPE.get(this.key), "Couldn't convert " + this + " to a modern stat");
218218
return switch (this.type) {
219-
case Type.BLOCK -> ((StatisticType<BlockType>) statType).of(Objects.requireNonNull(material.asBlockType()));
220-
case Type.ITEM -> ((StatisticType<ItemType>) statType).of(Objects.requireNonNull(material.asItemType()));
221-
case Type.ENTITY -> ((StatisticType<EntityType>) statType).of(Objects.requireNonNull(entityType));
219+
case Type.BLOCK -> ((StatisticType<BlockType>) statType).forValue(Objects.requireNonNull(material.asBlockType()));
220+
case Type.ITEM -> ((StatisticType<ItemType>) statType).forValue(Objects.requireNonNull(material.asItemType()));
221+
case Type.ENTITY -> ((StatisticType<EntityType>) statType).forValue(Objects.requireNonNull(entityType));
222222
default -> throw new IllegalStateException("Unexpected value: " + this.type);
223223
};
224224
}

paper-api/src/main/java/org/bukkit/event/player/PlayerStatisticIncrementEvent.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ public PlayerStatisticIncrementEvent(final Player player, final Statistic<?> sta
3737
this.statistic = statistic;
3838
this.initialValue = initialValue;
3939
this.newValue = newValue;
40-
this.entityType = statistic.value() instanceof final EntityType et ? et : null;
41-
if (statistic.value() instanceof final ItemType it) {
40+
this.entityType = statistic.owner() instanceof final EntityType et ? et : null;
41+
if (statistic.owner() instanceof final ItemType it) {
4242
this.material = it.asMaterial();
43-
} else if (statistic.value() instanceof final BlockType bt) {
43+
} else if (statistic.owner() instanceof final BlockType bt) {
4444
this.material = bt.asMaterial();
4545
} else {
4646
this.material = null;

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
@@ -4,7 +4,7 @@
44
import org.bukkit.craftbukkit.scoreboard.CraftScoreboardTranslations;
55
import org.bukkit.scoreboard.RenderType;
66

7-
public record PaperStatistic<S, M>(Stat<M> handle, S value, M nmsValue, StatisticType<S> type) implements Statistic<S> {
7+
public record PaperStatistic<S, M>(Stat<M> handle, S owner, M nmsValue, StatisticType<S> type) implements Statistic<S> {
88

99
@Override
1010
public String getName() {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,20 @@ public static <M> StatisticType<?> create(final Holder<StatType<?>> holder) {
6060
}
6161
}
6262

63-
public static StatisticType<?> minecraftToBukkit(final StatType<?> minecraft) {
63+
public static <A, M> StatisticType<A> minecraftToBukkit(final StatType<M> minecraft) {
6464
return CraftRegistry.minecraftToBukkit(minecraft, Registries.STAT_TYPE);
6565
}
6666

67-
public static StatType<?> bukkitToMinecraft(final StatisticType<?> bukkit) {
67+
public static <A, M> StatType<M> bukkitToMinecraft(final StatisticType<A> bukkit) {
6868
return CraftRegistry.bukkitToMinecraft(bukkit);
6969
}
7070

7171
public Statistic<S> convertStat(final Stat<? extends M> nmsStat) {
72-
return this.of(this.minecraftToBukkit.apply(nmsStat.getValue(), this.getHandle().getRegistry().key()));
72+
return this.forValue(this.minecraftToBukkit.apply(nmsStat.getValue(), this.getHandle().getRegistry().key()));
7373
}
7474

7575
@Override
76-
public Statistic<S> of(final S value) {
76+
public Statistic<S> forValue(final S value) {
7777
if (!this.typeCheck.test(value)) {
7878
throw new IllegalArgumentException(value + " is not valid for stat type " + this.getKey());
7979
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public static <B extends Keyed, M> M bukkitToMinecraft(B bukkit) {
105105
return ((Handleable<M>) bukkit).getHandle();
106106
}
107107

108-
public static <B extends Keyed, M> Holder<M> bukkitToMinecraftHolder(B bukkit, ResourceKey<net.minecraft.core.Registry<M>> registryKey) {
108+
public static <B extends Keyed, M> Holder<M> bukkitToMinecraftHolder(B bukkit, ResourceKey<? extends net.minecraft.core.Registry<M>> registryKey) {
109109
Preconditions.checkArgument(bukkit != null);
110110
// Paper start - support direct Holder
111111
if (bukkit instanceof io.papermc.paper.util.Holderable<?>) {

paper-server/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,7 @@ public static PlayerShearEntityEvent handlePlayerShearEntityEvent(net.minecraft.
15741574
public static Cancellable handleStatisticsIncrease(final net.minecraft.world.entity.player.Player entityHuman, final Stat<?> statistic, final int current, final int newValue) {
15751575
final Player player = ((ServerPlayer) entityHuman).getBukkitEntity();
15761576
final Statistic<?> stat = PaperStatistics.getPaperStatistic(statistic);
1577-
if (stat.value() instanceof final CustomStatistic customStatistic && PaperStatistics.IGNORED_STATS_FOR_EVENT.contains(customStatistic.key())) {
1577+
if (stat.owner() instanceof final CustomStatistic customStatistic && PaperStatistics.IGNORED_STATS_FOR_EVENT.contains(customStatistic.key())) {
15781578
// Do not process event for these - too spammy
15791579
return null;
15801580
}

0 commit comments

Comments
 (0)