Finish moving over to Holderable (#12646)

This commit is contained in:
Jake Potrebic
2025-06-10 16:29:10 -07:00
committed by GitHub
parent 519e4224b1
commit ba7fb23ddd
17 changed files with 171 additions and 723 deletions

View File

@@ -1,12 +1,12 @@
package org.bukkit.craftbukkit;
import io.papermc.paper.util.Holderable;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import org.bukkit.GameEvent;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.util.Handleable;
import org.jetbrains.annotations.NotNull;
public class CraftGameEvent extends GameEvent implements Handleable<net.minecraft.world.level.gameevent.GameEvent> {
public class CraftGameEvent extends GameEvent implements Holderable<net.minecraft.world.level.gameevent.GameEvent> {
public static GameEvent minecraftToBukkit(net.minecraft.world.level.gameevent.GameEvent minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.GAME_EVENT);
@@ -16,57 +16,44 @@ public class CraftGameEvent extends GameEvent implements Handleable<net.minecraf
return CraftRegistry.bukkitToMinecraft(bukkit);
}
private final NamespacedKey key;
private final net.minecraft.resources.ResourceKey<net.minecraft.world.level.gameevent.GameEvent> handleKey; // Paper
private final net.minecraft.world.level.gameevent.GameEvent handle;
private final Holder<net.minecraft.world.level.gameevent.GameEvent> holder;
public CraftGameEvent(NamespacedKey key, net.minecraft.world.level.gameevent.GameEvent handle) {
this.key = key;
this.handleKey = net.minecraft.resources.ResourceKey.create(net.minecraft.core.registries.Registries.GAME_EVENT, org.bukkit.craftbukkit.util.CraftNamespacedKey.toMinecraft(key)); // Paper
this.handle = handle;
public CraftGameEvent(final Holder<net.minecraft.world.level.gameevent.GameEvent> holder) {
this.holder = holder;
}
@Override
public net.minecraft.world.level.gameevent.GameEvent getHandle() {
return this.handle;
public Holder<net.minecraft.world.level.gameevent.GameEvent> getHolder() {
return this.holder;
}
@Override
public int getRange() {
return this.handle.notificationRadius();
return this.getHandle().notificationRadius();
}
@Override
public int getVibrationLevel() {
return net.minecraft.world.level.gameevent.vibrations.VibrationSystem.getGameEventFrequency(this.handleKey);
return net.minecraft.world.level.gameevent.vibrations.VibrationSystem.getGameEventFrequency(this.getHolder().unwrapKey().orElseThrow());
}
@NotNull
@Override
public NamespacedKey getKey() {
return this.key;
return Holderable.super.getKey();
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof CraftGameEvent)) {
return false;
}
return this.getKey().equals(((GameEvent) other).getKey());
return Holderable.super.implEquals(other);
}
@Override
public int hashCode() {
return this.getKey().hashCode();
return Holderable.super.implHashCode();
}
@Override
public String toString() {
return "CraftGameEvent{key=" + this.key + "}";
return Holderable.super.implToString();
}
}

View File

@@ -1,22 +1,19 @@
package org.bukkit.craftbukkit;
import com.google.common.base.Preconditions;
import io.papermc.paper.registry.HolderableBase;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.contents.TranslatableContents;
import org.bukkit.JukeboxSong;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.util.Handleable;
import org.jetbrains.annotations.NotNull;
public class CraftJukeboxSong implements JukeboxSong, Handleable<net.minecraft.world.item.JukeboxSong> {
public class CraftJukeboxSong extends HolderableBase<net.minecraft.world.item.JukeboxSong> implements JukeboxSong {
public static JukeboxSong minecraftToBukkit(net.minecraft.world.item.JukeboxSong minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.JUKEBOX_SONG);
}
public static JukeboxSong minecraftHolderToBukkit(Holder<net.minecraft.world.item.JukeboxSong> minecraft) {
return CraftJukeboxSong.minecraftToBukkit(minecraft.value());
return CraftRegistry.minecraftHolderToBukkit(minecraft, Registries.JUKEBOX_SONG);
}
public static net.minecraft.world.item.JukeboxSong bukkitToMinecraft(JukeboxSong bukkit) {
@@ -24,41 +21,16 @@ public class CraftJukeboxSong implements JukeboxSong, Handleable<net.minecraft.w
}
public static Holder<net.minecraft.world.item.JukeboxSong> bukkitToMinecraftHolder(JukeboxSong bukkit) {
Preconditions.checkArgument(bukkit != null);
net.minecraft.core.Registry<net.minecraft.world.item.JukeboxSong> registry = CraftRegistry.getMinecraftRegistry(Registries.JUKEBOX_SONG);
if (registry.wrapAsHolder(CraftJukeboxSong.bukkitToMinecraft(bukkit)) instanceof Holder.Reference<net.minecraft.world.item.JukeboxSong> holder) {
return holder;
}
throw new IllegalArgumentException("No Reference holder found for " + bukkit
+ ", this can happen if a plugin creates its own trim pattern without properly registering it.");
return CraftRegistry.bukkitToMinecraftHolder(bukkit, Registries.JUKEBOX_SONG);
}
private final NamespacedKey key;
private final net.minecraft.world.item.JukeboxSong handle;
public CraftJukeboxSong(NamespacedKey key, net.minecraft.world.item.JukeboxSong handle) {
this.key = key;
this.handle = handle;
public CraftJukeboxSong(final Holder<net.minecraft.world.item.JukeboxSong> holder) {
super(holder);
}
@Override
public net.minecraft.world.item.JukeboxSong getHandle() {
return this.handle;
}
@Override
@NotNull
public NamespacedKey getKey() {
return this.key;
}
@NotNull
@Override
public String getTranslationKey() {
if (!(this.handle.description().getContents() instanceof TranslatableContents)) throw new UnsupportedOperationException("Description isn't translatable!"); // Paper
return ((TranslatableContents) this.handle.description().getContents()).getKey();
if (!(this.getHandle().description().getContents() instanceof TranslatableContents)) throw new UnsupportedOperationException("Description isn't translatable!"); // Paper
return ((TranslatableContents) this.getHandle().description().getContents()).getKey();
}
}

View File

@@ -2,6 +2,7 @@ package org.bukkit.craftbukkit.attribute;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import org.bukkit.NamespacedKey;
import org.jetbrains.annotations.NotNull;
@@ -54,11 +55,7 @@ final class AttributeMappings {
public static @NotNull NamespacedKey uuidToKey(final UUID uuid) {
final NamespacedKey key = ATTRIBUTE_MODIFIER_IDS.get(uuid);
if (key != null) {
return key;
} else {
return NamespacedKey.minecraft(uuid.toString());
}
return Objects.requireNonNullElseGet(key, () -> NamespacedKey.minecraft(uuid.toString()));
}
private static void add(final long msb, final long lsb, final String id) {

View File

@@ -2,6 +2,7 @@ package org.bukkit.craftbukkit.attribute;
import com.google.common.base.Preconditions;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.util.OldEnumHolderable;
import java.util.Locale;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
@@ -10,10 +11,8 @@ import org.bukkit.attribute.Attribute;
import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.legacy.FieldRename;
import org.bukkit.craftbukkit.util.ApiVersion;
import org.bukkit.craftbukkit.util.Handleable;
import org.jetbrains.annotations.NotNull;
public class CraftAttribute implements Attribute, Handleable<net.minecraft.world.entity.ai.attributes.Attribute> {
public class CraftAttribute extends OldEnumHolderable<Attribute, net.minecraft.world.entity.ai.attributes.Attribute> implements Attribute {
private static int count = 0;
@@ -22,7 +21,7 @@ public class CraftAttribute implements Attribute, Handleable<net.minecraft.world
}
public static Attribute minecraftHolderToBukkit(Holder<net.minecraft.world.entity.ai.attributes.Attribute> minecraft) {
return CraftAttribute.minecraftToBukkit(minecraft.value());
return CraftRegistry.minecraftHolderToBukkit(minecraft, Registries.ATTRIBUTE);
}
public static Attribute stringToBukkit(String string) {
@@ -44,16 +43,7 @@ public class CraftAttribute implements Attribute, Handleable<net.minecraft.world
}
public static Holder<net.minecraft.world.entity.ai.attributes.Attribute> bukkitToMinecraftHolder(Attribute bukkit) {
Preconditions.checkArgument(bukkit != null);
net.minecraft.core.Registry<net.minecraft.world.entity.ai.attributes.Attribute> registry = CraftRegistry.getMinecraftRegistry(Registries.ATTRIBUTE);
if (registry.wrapAsHolder(CraftAttribute.bukkitToMinecraft(bukkit)) instanceof Holder.Reference<net.minecraft.world.entity.ai.attributes.Attribute> holder) {
return holder;
}
throw new IllegalArgumentException("No Reference holder found for " + bukkit
+ ", this can happen if a plugin creates its own sound effect with out properly registering it.");
return CraftRegistry.bukkitToMinecraftHolder(bukkit, Registries.ATTRIBUTE);
}
public static String bukkitToString(Attribute bukkit) {
@@ -62,85 +52,17 @@ public class CraftAttribute implements Attribute, Handleable<net.minecraft.world
return bukkit.getKey().toString();
}
private final NamespacedKey key;
private final net.minecraft.world.entity.ai.attributes.Attribute attributeBase;
private final String name;
private final int ordinal;
public CraftAttribute(NamespacedKey key, net.minecraft.world.entity.ai.attributes.Attribute attributeBase) {
this.key = key;
this.attributeBase = attributeBase;
// For backwards compatibility, minecraft values will stile return the uppercase name without the namespace,
// in case plugins use for example the name as key in a config file to receive attribute specific values.
// Custom attributes will return the key with namespace. For a plugin this should look than like a new attribute
// (which can always be added in new minecraft versions and the plugin should therefore handle it accordingly).
if (NamespacedKey.MINECRAFT.equals(key.getNamespace())) {
this.name = key.getKey().toUpperCase(Locale.ROOT);
} else {
this.name = key.toString();
}
this.ordinal = CraftAttribute.count++;
public CraftAttribute(final Holder<net.minecraft.world.entity.ai.attributes.Attribute> holder) {
super(holder, count++);
}
@Override
public net.minecraft.world.entity.ai.attributes.Attribute getHandle() {
return this.attributeBase;
}
@NotNull
@Override
public NamespacedKey getKey() {
return this.key;
}
@NotNull
@Override
public String getTranslationKey() {
return this.attributeBase.getDescriptionId();
return this.getHandle().getDescriptionId();
}
@Override
public @NotNull String translationKey() {
return this.attributeBase.getDescriptionId();
}
@Override
public int compareTo(@NotNull Attribute attribute) {
return this.ordinal - attribute.ordinal();
}
@NotNull
@Override
public String name() {
return this.name;
}
@Override
public int ordinal() {
return this.ordinal;
}
@Override
public String toString() {
// For backwards compatibility
return this.name();
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof CraftAttribute otherAttribute)) {
return false;
}
return this.getKey().equals(otherAttribute.getKey());
}
@Override
public int hashCode() {
return this.getKey().hashCode();
public String translationKey() {
return this.getHandle().getDescriptionId();
}
}

View File

@@ -1,15 +1,13 @@
package org.bukkit.craftbukkit.entity;
import com.google.common.base.Preconditions;
import java.util.Locale;
import io.papermc.paper.util.OldEnumHolderable;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.entity.animal.CatVariant;
import org.bukkit.DyeColor;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.util.Handleable;
import org.bukkit.entity.Cat;
public class CraftCat extends CraftTameableAnimal implements Cat {
@@ -45,7 +43,7 @@ public class CraftCat extends CraftTameableAnimal implements Cat {
this.getHandle().setCollarColor(net.minecraft.world.item.DyeColor.byId(color.getWoolData()));
}
public static class CraftType implements Type, Handleable<CatVariant> {
public static class CraftType extends OldEnumHolderable<Type, CatVariant> implements Type {
private static int count = 0;
public static Type minecraftToBukkit(CatVariant minecraft) {
@@ -53,7 +51,7 @@ public class CraftCat extends CraftTameableAnimal implements Cat {
}
public static Type minecraftHolderToBukkit(Holder<CatVariant> minecraft) {
return CraftType.minecraftToBukkit(minecraft.value());
return CraftRegistry.minecraftHolderToBukkit(minecraft, Registries.CAT_VARIANT);
}
public static CatVariant bukkitToMinecraft(Type bukkit) {
@@ -64,73 +62,8 @@ public class CraftCat extends CraftTameableAnimal implements Cat {
return CraftRegistry.bukkitToMinecraftHolder(bukkit, Registries.CAT_VARIANT);
}
private final NamespacedKey key;
private final CatVariant catVariant;
private final String name;
private final int ordinal;
public CraftType(NamespacedKey key, CatVariant catVariant) {
this.key = key;
this.catVariant = catVariant;
// For backwards compatibility, minecraft values will still return the uppercase name without the namespace,
// in case plugins use for example the name as key in a config file to receive type specific values.
// Custom types will return the key with namespace. For a plugin this should look than like a new type
// (which can always be added in new minecraft versions and the plugin should therefore handle it accordingly).
if (NamespacedKey.MINECRAFT.equals(key.getNamespace())) {
this.name = key.getKey().toUpperCase(Locale.ROOT);
} else {
this.name = key.toString();
}
this.ordinal = CraftType.count++;
}
@Override
public CatVariant getHandle() {
return this.catVariant;
}
@Override
public NamespacedKey getKey() {
return this.key;
}
@Override
public int compareTo(Type variant) {
return this.ordinal - variant.ordinal();
}
@Override
public String name() {
return this.name;
}
@Override
public int ordinal() {
return this.ordinal;
}
@Override
public String toString() {
// For backwards compatibility
return this.name();
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof CraftType)) {
return false;
}
return this.getKey().equals(((CraftType) other).getKey());
}
@Override
public int hashCode() {
return this.getKey().hashCode();
public CraftType(final Holder<CatVariant> holder) {
super(holder, count++);
}
}

View File

@@ -1,15 +1,13 @@
package org.bukkit.craftbukkit.entity;
import com.google.common.base.Preconditions;
import java.util.Locale;
import io.papermc.paper.util.OldEnumHolderable;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.entity.animal.frog.Frog;
import net.minecraft.world.entity.animal.frog.FrogVariant;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.util.Handleable;
import org.bukkit.entity.Entity;
public class CraftFrog extends CraftAnimals implements org.bukkit.entity.Frog {
@@ -49,7 +47,7 @@ public class CraftFrog extends CraftAnimals implements org.bukkit.entity.Frog {
this.getHandle().setVariant(CraftVariant.bukkitToMinecraftHolder(variant));
}
public static class CraftVariant implements Variant, Handleable<FrogVariant> {
public static class CraftVariant extends OldEnumHolderable<Variant, FrogVariant> implements Variant {
private static int count = 0;
public static Variant minecraftToBukkit(FrogVariant minecraft) {
@@ -57,7 +55,7 @@ public class CraftFrog extends CraftAnimals implements org.bukkit.entity.Frog {
}
public static Variant minecraftHolderToBukkit(Holder<FrogVariant> minecraft) {
return CraftVariant.minecraftToBukkit(minecraft.value());
return CraftRegistry.minecraftHolderToBukkit(minecraft, Registries.FROG_VARIANT);
}
public static FrogVariant bukkitToMinecraft(Variant bukkit) {
@@ -67,74 +65,8 @@ public class CraftFrog extends CraftAnimals implements org.bukkit.entity.Frog {
public static Holder<FrogVariant> bukkitToMinecraftHolder(Variant bukkit) {
return CraftRegistry.bukkitToMinecraftHolder(bukkit, Registries.FROG_VARIANT);
}
private final NamespacedKey key;
private final FrogVariant frogVariant;
private final String name;
private final int ordinal;
public CraftVariant(NamespacedKey key, FrogVariant frogVariant) {
this.key = key;
this.frogVariant = frogVariant;
// For backwards compatibility, minecraft values will still return the uppercase name without the namespace,
// in case plugins use for example the name as key in a config file to receive variant specific values.
// Custom variants will return the key with namespace. For a plugin this should look than like a new variant
// (which can always be added in new minecraft versions and the plugin should therefore handle it accordingly).
if (NamespacedKey.MINECRAFT.equals(key.getNamespace())) {
this.name = key.getKey().toUpperCase(Locale.ROOT);
} else {
this.name = key.toString();
}
this.ordinal = CraftVariant.count++;
}
@Override
public FrogVariant getHandle() {
return this.frogVariant;
}
@Override
public NamespacedKey getKey() {
return this.key;
}
@Override
public int compareTo(Variant variant) {
return this.ordinal - variant.ordinal();
}
@Override
public String name() {
return this.name;
}
@Override
public int ordinal() {
return this.ordinal;
}
@Override
public String toString() {
// For backwards compatibility
return this.name();
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof CraftVariant)) {
return false;
}
return this.getKey().equals(((Variant) other).getKey());
}
@Override
public int hashCode() {
return this.getKey().hashCode();
public CraftVariant(final Holder<FrogVariant> holder) {
super(holder, count++);
}
}
}

View File

@@ -2,7 +2,7 @@ package org.bukkit.craftbukkit.entity;
import com.destroystokyo.paper.entity.villager.Reputation;
import com.google.common.base.Preconditions;
import java.util.Locale;
import io.papermc.paper.util.OldEnumHolderable;
import java.util.Map;
import java.util.UUID;
import net.minecraft.core.BlockPos;
@@ -14,11 +14,9 @@ import net.minecraft.world.entity.npc.VillagerType;
import net.minecraft.world.level.block.BedBlock;
import net.minecraft.world.level.block.state.BlockState;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.util.CraftLocation;
import org.bukkit.craftbukkit.util.Handleable;
import org.bukkit.entity.Villager;
import org.bukkit.entity.ZombieVillager;
import org.bukkit.event.entity.CreatureSpawnEvent;
@@ -164,7 +162,7 @@ public class CraftVillager extends CraftAbstractVillager implements Villager {
return (entityzombievillager != null) ? (ZombieVillager) entityzombievillager.getBukkitEntity() : null;
}
public static class CraftType implements Type, Handleable<VillagerType> {
public static class CraftType extends OldEnumHolderable<Type, VillagerType> implements Type {
private static int count = 0;
public static Type minecraftToBukkit(VillagerType minecraft) {
@@ -172,7 +170,7 @@ public class CraftVillager extends CraftAbstractVillager implements Villager {
}
public static Type minecraftHolderToBukkit(Holder<VillagerType> minecraft) {
return CraftType.minecraftToBukkit(minecraft.value());
return CraftRegistry.minecraftHolderToBukkit(minecraft, Registries.VILLAGER_TYPE);
}
public static VillagerType bukkitToMinecraft(Type bukkit) {
@@ -183,77 +181,12 @@ public class CraftVillager extends CraftAbstractVillager implements Villager {
return CraftRegistry.bukkitToMinecraftHolder(bukkit, Registries.VILLAGER_TYPE);
}
private final NamespacedKey key;
private final VillagerType villagerType;
private final String name;
private final int ordinal;
public CraftType(NamespacedKey key, VillagerType villagerType) {
this.key = key;
this.villagerType = villagerType;
// For backwards compatibility, minecraft values will still return the uppercase name without the namespace,
// in case plugins use for example the name as key in a config file to receive type specific values.
// Custom types will return the key with namespace. For a plugin this should look than like a new type
// (which can always be added in new minecraft versions and the plugin should therefore handle it accordingly).
if (NamespacedKey.MINECRAFT.equals(key.getNamespace())) {
this.name = key.getKey().toUpperCase(Locale.ROOT);
} else {
this.name = key.toString();
}
this.ordinal = CraftType.count++;
}
@Override
public VillagerType getHandle() {
return this.villagerType;
}
@Override
public NamespacedKey getKey() {
return this.key;
}
@Override
public int compareTo(Type type) {
return this.ordinal - type.ordinal();
}
@Override
public String name() {
return this.name;
}
@Override
public int ordinal() {
return this.ordinal;
}
@Override
public String toString() {
// For backwards compatibility
return this.name();
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof CraftType)) {
return false;
}
return this.getKey().equals(((Type) other).getKey());
}
@Override
public int hashCode() {
return this.getKey().hashCode();
public CraftType(final Holder<VillagerType> holder){
super(holder, count++);
}
}
public static class CraftProfession implements Profession, Handleable<VillagerProfession> {
public static class CraftProfession extends OldEnumHolderable<Profession, VillagerProfession> implements Profession {
private static int count = 0;
public static Profession minecraftHolderToBukkit(Holder<VillagerProfession> minecraft) {
@@ -272,73 +205,8 @@ public class CraftVillager extends CraftAbstractVillager implements Villager {
return CraftRegistry.bukkitToMinecraft(bukkit);
}
private final NamespacedKey key;
private final VillagerProfession villagerProfession;
private final String name;
private final int ordinal;
public CraftProfession(NamespacedKey key, VillagerProfession villagerProfession) {
this.key = key;
this.villagerProfession = villagerProfession;
// For backwards compatibility, minecraft values will still return the uppercase name without the namespace,
// in case plugins use for example the name as key in a config file to receive profession specific values.
// Custom professions will return the key with namespace. For a plugin this should look than like a new profession
// (which can always be added in new minecraft versions and the plugin should therefore handle it accordingly).
if (NamespacedKey.MINECRAFT.equals(key.getNamespace())) {
this.name = key.getKey().toUpperCase(Locale.ROOT);
} else {
this.name = key.toString();
}
this.ordinal = CraftProfession.count++;
}
@Override
public VillagerProfession getHandle() {
return this.villagerProfession;
}
@Override
public NamespacedKey getKey() {
return this.key;
}
@Override
public int compareTo(Profession profession) {
return this.ordinal - profession.ordinal();
}
@Override
public String name() {
return this.name;
}
@Override
public int ordinal() {
return this.ordinal;
}
@Override
public String toString() {
// For backwards compatibility
return this.name();
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof CraftProfession)) {
return false;
}
return this.getKey().equals(((Profession) other).getKey());
}
@Override
public int hashCode() {
return this.getKey().hashCode();
public CraftProfession(final Holder<VillagerProfession> holder) {
super(holder, count++);
}
}

View File

@@ -1,15 +1,14 @@
package org.bukkit.craftbukkit.entity;
import com.google.common.base.Preconditions;
import io.papermc.paper.registry.HolderableBase;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.entity.animal.wolf.WolfSoundVariant;
import net.minecraft.world.entity.animal.wolf.WolfVariant;
import org.bukkit.DyeColor;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.util.Handleable;
import org.bukkit.entity.Wolf;
public class CraftWolf extends CraftTameableAnimal implements Wolf {
@@ -91,14 +90,14 @@ public class CraftWolf extends CraftTameableAnimal implements Wolf {
this.getHandle().setSoundVariant(CraftSoundVariant.bukkitToMinecraftHolder(soundVariant));
}
public static class CraftVariant implements Variant, Handleable<WolfVariant> {
public static class CraftVariant extends HolderableBase<WolfVariant> implements Variant {
public static Variant minecraftToBukkit(WolfVariant minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.WOLF_VARIANT);
}
public static Variant minecraftHolderToBukkit(Holder<WolfVariant> minecraft) {
return CraftVariant.minecraftToBukkit(minecraft.value());
return CraftRegistry.minecraftHolderToBukkit(minecraft, Registries.WOLF_VARIANT);
}
public static WolfVariant bukkitToMinecraft(Variant bukkit) {
@@ -106,68 +105,22 @@ public class CraftWolf extends CraftTameableAnimal implements Wolf {
}
public static Holder<WolfVariant> bukkitToMinecraftHolder(Variant bukkit) {
Preconditions.checkArgument(bukkit != null);
net.minecraft.core.Registry<WolfVariant> registry = CraftRegistry.getMinecraftRegistry(Registries.WOLF_VARIANT);
if (registry.wrapAsHolder(CraftVariant.bukkitToMinecraft(bukkit)) instanceof Holder.Reference<WolfVariant> holder) {
return holder;
}
throw new IllegalArgumentException("No Reference holder found for " + bukkit
+ ", this can happen if a plugin creates its own wolf variant with out properly registering it.");
return CraftRegistry.bukkitToMinecraftHolder(bukkit, Registries.WOLF_VARIANT);
}
private final NamespacedKey key;
private final WolfVariant variant;
public CraftVariant(NamespacedKey key, WolfVariant variant) {
this.key = key;
this.variant = variant;
}
@Override
public WolfVariant getHandle() {
return this.variant;
}
@Override
public NamespacedKey getKey() {
return this.key;
}
@Override
public String toString() {
return this.key.toString();
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof CraftVariant otherVariant)) {
return false;
}
return this.getKey().equals(otherVariant.getKey());
}
@Override
public int hashCode() {
return this.getKey().hashCode();
public CraftVariant(final Holder<WolfVariant> holder) {
super(holder);
}
}
public static class CraftSoundVariant implements SoundVariant, Handleable<WolfSoundVariant> {
public static class CraftSoundVariant extends HolderableBase<WolfSoundVariant> implements SoundVariant {
public static SoundVariant minecraftToBukkit(WolfSoundVariant minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.WOLF_SOUND_VARIANT);
}
public static SoundVariant minecraftHolderToBukkit(Holder<WolfSoundVariant> minecraft) {
return CraftSoundVariant.minecraftToBukkit(minecraft.value());
return CraftRegistry.minecraftHolderToBukkit(minecraft, Registries.WOLF_SOUND_VARIANT);
}
public static WolfSoundVariant bukkitToMinecraft(SoundVariant bukkit) {
@@ -175,57 +128,11 @@ public class CraftWolf extends CraftTameableAnimal implements Wolf {
}
public static Holder<WolfSoundVariant> bukkitToMinecraftHolder(SoundVariant bukkit) {
Preconditions.checkArgument(bukkit != null);
net.minecraft.core.Registry<WolfSoundVariant> registry = CraftRegistry.getMinecraftRegistry(Registries.WOLF_SOUND_VARIANT);
if (registry.wrapAsHolder(CraftSoundVariant.bukkitToMinecraft(bukkit)) instanceof Holder.Reference<WolfSoundVariant> holder) {
return holder;
}
throw new IllegalArgumentException("No Reference holder found for " + bukkit
+ ", this can happen if a plugin creates its own wolf sound variant with out properly registering it.");
return CraftRegistry.bukkitToMinecraftHolder(bukkit, Registries.WOLF_SOUND_VARIANT);
}
private final NamespacedKey key;
private final WolfSoundVariant soundVariant;
public CraftSoundVariant(NamespacedKey key, WolfSoundVariant soundVariant) {
this.key = key;
this.soundVariant = soundVariant;
}
@Override
public WolfSoundVariant getHandle() {
return this.soundVariant;
}
@Override
public NamespacedKey getKey() {
return this.key;
}
@Override
public String toString() {
return this.key.toString();
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof CraftSoundVariant otherVariant)) {
return false;
}
return this.getKey().equals(otherVariant.getKey());
}
@Override
public int hashCode() {
return this.getKey().hashCode();
public CraftSoundVariant(final Holder<WolfSoundVariant> holder) {
super(holder);
}
}
}

View File

@@ -1,15 +1,14 @@
package org.bukkit.craftbukkit.generator.structure;
import com.google.common.base.Suppliers;
import java.util.function.Supplier;
import io.papermc.paper.util.Holderable;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.util.Handleable;
import org.bukkit.generator.structure.Structure;
import org.bukkit.generator.structure.StructureType;
public class CraftStructure extends Structure implements Handleable<net.minecraft.world.level.levelgen.structure.Structure> {
public class CraftStructure extends Structure implements Holderable<net.minecraft.world.level.levelgen.structure.Structure> {
public static Structure minecraftToBukkit(net.minecraft.world.level.levelgen.structure.Structure minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.STRUCTURE);
@@ -19,28 +18,39 @@ public class CraftStructure extends Structure implements Handleable<net.minecraf
return CraftRegistry.bukkitToMinecraft(bukkit);
}
private final NamespacedKey key;
private final net.minecraft.world.level.levelgen.structure.Structure structure;
private final Supplier<StructureType> structureType;
private final Holder<net.minecraft.world.level.levelgen.structure.Structure> holder;
public CraftStructure(NamespacedKey key, net.minecraft.world.level.levelgen.structure.Structure structure) {
this.key = key;
this.structure = structure;
this.structureType = Suppliers.memoize(() -> CraftStructureType.minecraftToBukkit(structure.type()));
public CraftStructure(Holder<net.minecraft.world.level.levelgen.structure.Structure> holder) {
this.holder = holder;
}
@Override
public net.minecraft.world.level.levelgen.structure.Structure getHandle() {
return this.structure;
public Holder<net.minecraft.world.level.levelgen.structure.Structure> getHolder() {
return this.holder;
}
@Override
public StructureType getStructureType() {
return this.structureType.get();
return CraftStructureType.minecraftToBukkit(this.getHandle().type());
}
@Override
public NamespacedKey getKey() {
return this.key;
return Holderable.super.getKey();
}
@Override
public int hashCode() {
return Holderable.super.implHashCode();
}
@Override
public boolean equals(final Object obj) {
return Holderable.super.implEquals(obj);
}
@Override
public String toString() {
return Holderable.super.implToString();
}
}

View File

@@ -1,12 +1,13 @@
package org.bukkit.craftbukkit.generator.structure;
import io.papermc.paper.util.Holderable;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.util.Handleable;
import org.bukkit.generator.structure.StructureType;
public class CraftStructureType extends StructureType implements Handleable<net.minecraft.world.level.levelgen.structure.StructureType<?>> {
public class CraftStructureType extends StructureType implements Holderable<net.minecraft.world.level.levelgen.structure.StructureType<?>> {
public static StructureType minecraftToBukkit(net.minecraft.world.level.levelgen.structure.StructureType<?> minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.STRUCTURE_TYPE);
@@ -16,21 +17,34 @@ public class CraftStructureType extends StructureType implements Handleable<net.
return CraftRegistry.bukkitToMinecraft(bukkit);
}
private final NamespacedKey key;
private final net.minecraft.world.level.levelgen.structure.StructureType<?> structureType;
private final Holder<net.minecraft.world.level.levelgen.structure.StructureType<?>> holder;
public CraftStructureType(NamespacedKey key, net.minecraft.world.level.levelgen.structure.StructureType<?> structureType) {
this.key = key;
this.structureType = structureType;
public CraftStructureType(final Holder<net.minecraft.world.level.levelgen.structure.StructureType<?>> holder) {
this.holder = holder;
}
@Override
public net.minecraft.world.level.levelgen.structure.StructureType<?> getHandle() {
return this.structureType;
public Holder<net.minecraft.world.level.levelgen.structure.StructureType<?>> getHolder() {
return this.holder;
}
@Override
public NamespacedKey getKey() {
return this.key;
return Holderable.super.getKey();
}
@Override
public int hashCode() {
return Holderable.super.implHashCode();
}
@Override
public boolean equals(final Object obj) {
return Holderable.super.implEquals(obj);
}
@Override
public String toString() {
return Holderable.super.implToString();
}
}

View File

@@ -577,7 +577,7 @@ public final class CraftItemStack extends ItemStack {
}
private <A, V> void setDataInternal(final io.papermc.paper.datacomponent.PaperDataComponentType<A, V> type, final A value) {
this.handle.set(type.getHandle(), type.getAdapter().toVanilla(value));
this.handle.set(type.getHandle(), type.getAdapter().toVanilla(value, type.getHolder()));
}
@Override

View File

@@ -1,17 +1,15 @@
package org.bukkit.craftbukkit.map;
import java.util.Locale;
import io.papermc.paper.util.OldEnumHolderable;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.level.saveddata.maps.MapDecorationType;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.util.Handleable;
import org.bukkit.map.MapCursor;
public final class CraftMapCursor {
public static final class CraftType implements MapCursor.Type, Handleable<MapDecorationType> {
public static final class CraftType extends OldEnumHolderable<MapCursor.Type, MapDecorationType> implements MapCursor.Type {
private static int count = 0;
@@ -20,7 +18,7 @@ public final class CraftMapCursor {
}
public static MapCursor.Type minecraftHolderToBukkit(Holder<MapDecorationType> minecraft) {
return CraftType.minecraftToBukkit(minecraft.value());
return CraftRegistry.minecraftHolderToBukkit(minecraft, Registries.MAP_DECORATION_TYPE);
}
public static MapDecorationType bukkitToMinecraft(MapCursor.Type bukkit) {
@@ -31,73 +29,8 @@ public final class CraftMapCursor {
return CraftRegistry.bukkitToMinecraftHolder(bukkit, Registries.MAP_DECORATION_TYPE);
}
private final NamespacedKey key;
private final MapDecorationType mapDecorationType;
private final String name;
private final int ordinal;
public CraftType(NamespacedKey key, MapDecorationType mapDecorationType) {
this.key = key;
this.mapDecorationType = mapDecorationType;
// For backwards compatibility, minecraft values will still return the uppercase name without the namespace,
// in case plugins use for example the name as key in a config file to receive type specific values.
// Custom types will return the key with namespace. For a plugin this should look than like a new type
// (which can always be added in new minecraft versions and the plugin should therefore handle it accordingly).
if (NamespacedKey.MINECRAFT.equals(key.getNamespace())) {
this.name = key.getKey().toUpperCase(Locale.ROOT);
} else {
this.name = key.toString();
}
this.ordinal = CraftType.count++;
}
@Override
public MapDecorationType getHandle() {
return this.mapDecorationType;
}
@Override
public NamespacedKey getKey() {
return this.key;
}
@Override
public int compareTo(MapCursor.Type type) {
return this.ordinal - type.ordinal();
}
@Override
public String name() {
return this.name;
}
@Override
public int ordinal() {
return this.ordinal;
}
@Override
public String toString() {
// For backwards compatibility
return this.name();
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof CraftType)) {
return false;
}
return this.getKey().equals(((MapCursor.Type) other).getKey());
}
@Override
public int hashCode() {
return this.getKey().hashCode();
public CraftType(final Holder<MapDecorationType> holder) {
super(holder, count++);
}
@Override