Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

37 changes: 21 additions & 16 deletions paper-api/src/main/java/co/aikar/timings/TimingHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,17 @@
package co.aikar.timings;

import co.aikar.timings.TimingHistory.RegionData.RegionId;
import co.aikar.util.LoadingMap;
import co.aikar.util.MRUMapCache;
import com.google.common.base.Function;
import com.google.common.collect.Sets;
import java.lang.management.ManagementFactory;
import java.util.Collection;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Material;
Expand All @@ -34,21 +43,17 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import co.aikar.util.LoadingMap;
import co.aikar.util.MRUMapCache;

import java.lang.management.ManagementFactory;
import java.util.Collection;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static co.aikar.timings.TimingsManager.FULL_SERVER_TICK;
import static co.aikar.timings.TimingsManager.MINUTE_REPORTS;
import static co.aikar.util.JSONUtil.*;
import static co.aikar.util.JSONUtil.JSONPair;
import static co.aikar.util.JSONUtil.createObject;
import static co.aikar.util.JSONUtil.pair;
import static co.aikar.util.JSONUtil.toArray;
import static co.aikar.util.JSONUtil.toArrayMapper;
import static co.aikar.util.JSONUtil.toObjectMapper;

/**
* @hidden
Expand Down Expand Up @@ -143,13 +148,13 @@ public Object apply(RegionData input) {
input.regionId.x,
input.regionId.z,
toObjectMapper(input.entityCounts.entrySet(),
new Function<Map.Entry<EntityType, Counter>, JSONPair>() {
new Function<Map.Entry<EntityType<?>, Counter>, JSONPair>() {
@NotNull
@Override
public JSONPair apply(Map.Entry<EntityType, Counter> entry) {
public JSONPair apply(Map.Entry<EntityType<?>, Counter> entry) {
entityTypeSet.add(entry.getKey());
return pair(
String.valueOf(entry.getKey().ordinal()),
entry.getKey().key().asString(), // todo check format
entry.getValue().count()
);
}
Expand Down Expand Up @@ -207,12 +212,12 @@ public int hashCode() {
}

@SuppressWarnings("unchecked")
final Map<EntityType, Counter> entityCounts = MRUMapCache.of(LoadingMap.of(
new EnumMap<EntityType, Counter>(EntityType.class), k -> new Counter()
final Map<EntityType<?>, Counter> entityCounts = MRUMapCache.of(LoadingMap.of(
new HashMap<>(), k -> new Counter()
));
@SuppressWarnings("unchecked")
final Map<Material, Counter> tileEntityCounts = MRUMapCache.of(LoadingMap.of(
new EnumMap<Material, Counter>(Material.class), k -> new Counter()
new EnumMap<>(Material.class), k -> new Counter()
));

static class RegionId {
Expand Down
10 changes: 10 additions & 0 deletions paper-api/src/main/java/io/papermc/paper/InternalAPIBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.bukkit.block.Biome;
import org.bukkit.damage.DamageEffect;
import org.bukkit.damage.DamageSource;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Pose;
import org.jetbrains.annotations.ApiStatus;
Expand Down Expand Up @@ -61,6 +62,15 @@ class Holder {
@ApiStatus.ScheduledForRemoval(inVersion = "1.22")
Biome constructLegacyCustomBiome();

/**
* Constructs the legacy unknown entity type instance for the entity type enum.
*
* @return the created entity type.
*/
@Deprecated(forRemoval = true, since = "1.21.11")
@ApiStatus.ScheduledForRemoval(inVersion = "1.22")
EntityType<?> constructLegacyUnknownEntityType();

/**
* Creates a new combat entry.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static Equippable.Builder equippable(final EquipmentSlot slot) {
* @return the set of allowed entities
*/
@Contract(pure = true)
@Nullable RegistryKeySet<EntityType> allowedEntities();
@Nullable RegistryKeySet<EntityType<?>> allowedEntities();

/**
* Checks if the item is dispensable.
Expand Down Expand Up @@ -161,7 +161,7 @@ interface Builder extends DataComponentBuilder<Equippable> {
* @return the builder for chaining
*/
@Contract(value = "_ -> this", mutates = "this")
Builder allowedEntities(@Nullable RegistryKeySet<EntityType> allowedEntities);
Builder allowedEntities(@Nullable RegistryKeySet<EntityType<?>> allowedEntities);

/**
* Sets whether the item is dispensable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ public sealed interface RegistryKey<T> extends Keyed permits RegistryKeyImpl {
* @see io.papermc.paper.registry.keys.GameRuleKeys
*/
RegistryKey<GameRule<?>> GAME_RULE = create("game_rule");
/**
* Built-in registry for entity types.
* @see io.papermc.paper.registry.keys.EntityTypeKeys
*/
RegistryKey<EntityType<?>> ENTITY_TYPE = create("entity_type");

/* ********************** *
* Data-driven Registries *
Expand Down Expand Up @@ -236,7 +241,6 @@ public sealed interface RegistryKey<T> extends Keyed permits RegistryKeyImpl {
/* ******************* *
* API-only Registries *
* ******************* */
RegistryKey<EntityType> ENTITY_TYPE = create("entity_type");
RegistryKey<Particle> PARTICLE_TYPE = create("particle_type");
RegistryKey<PotionType> POTION = create("potion");
RegistryKey<MemoryKey<?>> MEMORY_MODULE_TYPE = create("memory_module_type");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public BaseTag(@NotNull Class<T> clazz, @NotNull NamespacedKey key, @NotNull Pre
add(filter);
}

public BaseTag(@NotNull Class<T> clazz, @NotNull NamespacedKey key, @NotNull T...values) {
public BaseTag(@NotNull Class<T> clazz, @NotNull NamespacedKey key, @NotNull T... values) {
this(clazz, key, Lists.newArrayList(values));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package io.papermc.paper.tag;

import java.util.Collection;
import java.util.Locale;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.entity.EntityType;
import org.jetbrains.annotations.NotNull;

Expand All @@ -30,12 +31,12 @@ public EntitySetTag(@NotNull NamespacedKey key, @NotNull Collection<EntityType>
@NotNull
@Override
protected Set<EntityType> getAllPossibleValues() {
return Stream.of(EntityType.values()).collect(Collectors.toSet());
return Registry.ENTITY_TYPE.stream().collect(Collectors.toSet());
}

@NotNull
@Override
protected String getName(@NotNull EntityType value) {
return value.name();
return value.key().value().toUpperCase(Locale.ROOT); // should be close enough
}
}
Loading
Loading