Skip to content

Commit f365e9b

Browse files
Machine-MakerLulu13022002
authored andcommitted
small improvements
1 parent effdb8a commit f365e9b

File tree

8 files changed

+20
-20
lines changed

8 files changed

+20
-20
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
@@ -194,7 +194,7 @@ public enum Type {
194194
@ApiStatus.Internal
195195
public static Statistic toLegacy(final io.papermc.paper.statistic.Statistic<?> stat) {
196196
Key key = stat.type().key();
197-
if (stat.type() == StatisticType.CUSTOM && stat.value() instanceof final CustomStatistic customStatistic) {
197+
if (stat.type() == StatisticType.CUSTOM && stat.owner() instanceof final CustomStatistic customStatistic) {
198198
key = customStatistic.getKey();
199199
}
200200
return Objects.requireNonNull(Registry.STATISTIC.get(key), "Couldn't convert " + stat + " to a legacy stat");
@@ -210,13 +210,13 @@ public io.papermc.paper.statistic.Statistic<?> toModern(@Nullable EntityType ent
210210
Preconditions.checkArgument(this.type != Type.BLOCK || material != null && material.isBlock(), "Must provide a valid block material");
211211
Preconditions.checkArgument(this.type != Type.ITEM || material != null && material.isItem(), "Must provide a valid item material");
212212
if (this.type == Type.UNTYPED) {
213-
return StatisticType.CUSTOM.of(Objects.requireNonNull(Registry.CUSTOM_STAT.get(this.key), "Couldn't convert " + this + " to a modern stat"));
213+
return StatisticType.CUSTOM.forValue(Objects.requireNonNull(Registry.CUSTOM_STAT.get(this.key), "Couldn't convert " + this + " to a modern stat"));
214214
} else {
215215
StatisticType<?> statType = Objects.requireNonNull(Registry.STAT_TYPE.get(this.key), "Couldn't convert " + this + " to a modern stat");
216216
return switch (this.type) {
217-
case Type.BLOCK -> ((StatisticType<BlockType>) statType).of(Objects.requireNonNull(material.asBlockType()));
218-
case Type.ITEM -> ((StatisticType<ItemType>) statType).of(Objects.requireNonNull(material.asItemType()));
219-
case Type.ENTITY -> ((StatisticType<EntityType>) statType).of(Objects.requireNonNull(entityType));
217+
case Type.BLOCK -> ((StatisticType<BlockType>) statType).forValue(Objects.requireNonNull(material.asBlockType()));
218+
case Type.ITEM -> ((StatisticType<ItemType>) statType).forValue(Objects.requireNonNull(material.asItemType()));
219+
case Type.ENTITY -> ((StatisticType<EntityType>) statType).forValue(Objects.requireNonNull(entityType));
220220
default -> throw new IllegalStateException("Unexpected value: " + this.type);
221221
};
222222
}

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/event/CraftEventFactory.java

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

0 commit comments

Comments
 (0)