Switch Impl types to Holderable
This commit is contained in:
@@ -10,14 +10,14 @@ import org.bukkit.Registry;
|
||||
import org.bukkit.craftbukkit.util.Handleable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CraftMusicInstrument extends MusicInstrument implements Handleable<Instrument> {
|
||||
public class CraftMusicInstrument extends MusicInstrument implements io.papermc.paper.util.Holderable<Instrument> {
|
||||
|
||||
public static MusicInstrument minecraftToBukkit(Instrument minecraft) {
|
||||
return CraftRegistry.minecraftToBukkit(minecraft, Registries.INSTRUMENT, Registry.INSTRUMENT);
|
||||
}
|
||||
|
||||
public static MusicInstrument minecraftHolderToBukkit(Holder<Instrument> minecraft) {
|
||||
return CraftMusicInstrument.minecraftToBukkit(minecraft.value());
|
||||
return CraftRegistry.minecraftHolderToBukkit(minecraft, Registry.INSTRUMENT); // Paper - switch to Holder
|
||||
}
|
||||
|
||||
public static Instrument bukkitToMinecraft(MusicInstrument bukkit) {
|
||||
@@ -25,41 +25,51 @@ public class CraftMusicInstrument extends MusicInstrument implements Handleable<
|
||||
}
|
||||
|
||||
public static Holder<Instrument> bukkitToMinecraftHolder(MusicInstrument bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
net.minecraft.core.Registry<Instrument> registry = CraftRegistry.getMinecraftRegistry(Registries.INSTRUMENT);
|
||||
|
||||
if (registry.wrapAsHolder(CraftMusicInstrument.bukkitToMinecraft(bukkit)) instanceof Holder.Reference<Instrument> holder) {
|
||||
return holder;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("No Reference holder found for " + bukkit
|
||||
+ ", this can happen if a plugin creates its own instrument without properly registering it.");
|
||||
return CraftRegistry.bukkitToMinecraftHolder(bukkit, Registries.INSTRUMENT); // Paper - switch to Holder
|
||||
}
|
||||
|
||||
public static String bukkitToString(MusicInstrument bukkit) {
|
||||
public static Object bukkitToString(MusicInstrument bukkit) { // Paper - switch to Holder
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
return bukkit.getKey().toString();
|
||||
return ((CraftMusicInstrument) bukkit).toBukkitSerializationObject(Instrument.CODEC); // Paper - switch to Holder
|
||||
}
|
||||
|
||||
public static MusicInstrument stringToBukkit(String string) {
|
||||
public static MusicInstrument stringToBukkit(Object string) { // Paper - switch to Holder
|
||||
Preconditions.checkArgument(string != null);
|
||||
|
||||
return Registry.INSTRUMENT.get(NamespacedKey.fromString(string));
|
||||
return io.papermc.paper.util.Holderable.fromBukkitSerializationObject(string, Instrument.CODEC, Registry.INSTRUMENT); // Paper - switch to Holder
|
||||
}
|
||||
|
||||
private final NamespacedKey key;
|
||||
private final Instrument handle;
|
||||
|
||||
public CraftMusicInstrument(NamespacedKey key, Instrument handle) {
|
||||
this.key = key;
|
||||
this.handle = handle;
|
||||
// Paper start - switch to Holder
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
return this.implEquals(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instrument getHandle() {
|
||||
return this.handle;
|
||||
public int hashCode() {
|
||||
return this.implHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.implToString();
|
||||
}
|
||||
|
||||
private final Holder<Instrument> holder;
|
||||
public CraftMusicInstrument(Holder<Instrument> holder) {
|
||||
this.holder = holder;
|
||||
this.key = holder.unwrapKey().map(io.papermc.paper.util.MCUtil::fromResourceKey).orElse(null);
|
||||
this.handle = holder.value();
|
||||
// Paper end - switch to Holder
|
||||
}
|
||||
|
||||
@Override
|
||||
public Holder<Instrument> getHolder() { // Paper - switch to Holder
|
||||
return this.holder; // Paper - switch to Holder
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -79,26 +89,5 @@ public class CraftMusicInstrument extends MusicInstrument implements Handleable<
|
||||
}
|
||||
// Paper end - add translationKey methods
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(other instanceof CraftMusicInstrument)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.getKey().equals(((MusicInstrument) other).getKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.getKey().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CraftMusicInstrument{key=" + this.key + "}";
|
||||
}
|
||||
// Paper - switch to Holder
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user