Convert MusicInstrument

This commit is contained in:
DerFrZocker 2023-05-31 13:29:30 +02:00
parent bba2eb5fbc
commit 00d778c791
No known key found for this signature in database
GPG key ID: 713F71FFFE1DDF91
2 changed files with 27 additions and 35 deletions

View file

@ -1,66 +1,52 @@
package org.bukkit; package org.bukkit;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public final class MusicInstrument implements Keyed { public abstract class MusicInstrument implements Keyed {
public static final MusicInstrument PONDER_GOAT_HORN = getInstrument("ponder_goat_horn");
private static final Map<NamespacedKey, MusicInstrument> INSTRUMENTS = new HashMap<>(); public static final MusicInstrument SING_GOAT_HORN = getInstrument("sing_goat_horn");
// public static final MusicInstrument SEEK_GOAT_HORN = getInstrument("seek_goat_horn");
public static final MusicInstrument PONDER = getInstrument("ponder_goat_horn"); public static final MusicInstrument FEEL_GOAT_HORN = getInstrument("feel_goat_horn");
public static final MusicInstrument SING = getInstrument("sing_goat_horn"); public static final MusicInstrument ADMIRE_GOAT_HORN = getInstrument("admire_goat_horn");
public static final MusicInstrument SEEK = getInstrument("seek_goat_horn"); public static final MusicInstrument CALL_GOAT_HORN = getInstrument("call_goat_horn");
public static final MusicInstrument FEEL = getInstrument("feel_goat_horn"); public static final MusicInstrument YEARN_GOAT_HORN = getInstrument("yearn_goat_horn");
public static final MusicInstrument ADMIRE = getInstrument("admire_goat_horn"); public static final MusicInstrument DREAM_GOAT_HORN = getInstrument("dream_goat_horn");
public static final MusicInstrument CALL = getInstrument("call_goat_horn");
public static final MusicInstrument YEARN = getInstrument("yearn_goat_horn");
public static final MusicInstrument DREAM = getInstrument("dream_goat_horn");
//
private final NamespacedKey key;
private MusicInstrument(NamespacedKey key) {
this.key = key;
INSTRUMENTS.put(key, this);
}
@NotNull
@Override
public NamespacedKey getKey() {
return key;
}
/** /**
* Returns a {@link MusicInstrument} by a {@link NamespacedKey}. * Returns a {@link MusicInstrument} by a {@link NamespacedKey}.
* *
* @param namespacedKey the key * @param namespacedKey the key
* @return the event or null * @return the event or null
* @deprecated Use {@link Registry#get(NamespacedKey)} instead.
*/ */
@Nullable @Nullable
@Deprecated
public static MusicInstrument getByKey(@NotNull NamespacedKey namespacedKey) { public static MusicInstrument getByKey(@NotNull NamespacedKey namespacedKey) {
Preconditions.checkArgument(namespacedKey != null, "NamespacedKey cannot be null"); return Registry.INSTRUMENT.get(namespacedKey);
return INSTRUMENTS.get(namespacedKey);
} }
/** /**
* Returns all known MusicInstruments. * Returns all known MusicInstruments.
* *
* @return the memoryKeys * @return the memoryKeys
* @deprecated use {@link Registry#iterator()}.
*/ */
@NotNull @NotNull
@Deprecated
public static Collection<MusicInstrument> values() { public static Collection<MusicInstrument> values() {
return Collections.unmodifiableCollection(INSTRUMENTS.values()); return Collections.unmodifiableCollection(Lists.newArrayList(Registry.INSTRUMENT));
} }
@NotNull
private static MusicInstrument getInstrument(@NotNull String name) { private static MusicInstrument getInstrument(@NotNull String name) {
Preconditions.checkArgument(name != null, "Instrument name cannot be null"); NamespacedKey namespacedKey = NamespacedKey.minecraft(name);
MusicInstrument instrument = Registry.INSTRUMENT.get(namespacedKey);
return new MusicInstrument(NamespacedKey.minecraft(name)); Preconditions.checkNotNull(instrument, "No MusicInstrument found for %s. This is a bug.", namespacedKey);
return instrument;
} }
} }

View file

@ -127,6 +127,12 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
* @see EntityType * @see EntityType
*/ */
Registry<EntityType> ENTITY_TYPE = Objects.requireNonNull(Bukkit.getRegistry(EntityType.class), "No registry present for EntityType. This is a bug."); Registry<EntityType> ENTITY_TYPE = Objects.requireNonNull(Bukkit.getRegistry(EntityType.class), "No registry present for EntityType. This is a bug.");
/**
* Server instruments.
*
* @see MusicInstrument
*/
Registry<MusicInstrument> INSTRUMENT = Objects.requireNonNull(Bukkit.getRegistry(MusicInstrument.class), "No registry present for MusicInstrument. This is a bug.");
/** /**
* Server item types. * Server item types.
* *