Skip to content

Commit

Permalink
RegistryClassInfo - some suggestions from pickle
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaneBeee committed May 15, 2024
1 parent 2d9f264 commit b2317c9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.CachedServerIcon;
import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.Nullable;

import ch.njol.skript.Skript;
import ch.njol.skript.SkriptConfig;
Expand Down Expand Up @@ -106,6 +105,7 @@
import ch.njol.util.StringUtils;
import ch.njol.yggdrasil.Fields;
import io.papermc.paper.world.MoonPhase;
import org.jetbrains.annotations.Nullable;

/**
* @author Peter Güttinger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,16 @@
import ch.njol.skript.lang.ParseContext;
import org.bukkit.Keyed;
import org.bukkit.Registry;
import org.eclipse.jdt.annotation.Nullable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* This class can be used for an easier writing of ClassInfos that are registries,
* it registers a language node with usage, a serializer, default expression and a parser.
* Making it easier to register registry ClassInfos.
*
* @param <R> The Registry class.
*/
public class RegistryClassInfo<R extends Keyed> extends ClassInfo<R> {

public RegistryClassInfo(Class<R> registryClass, Registry<R> registry, String codeName, String languageNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@

import java.io.StreamCorruptedException;

/**
* Serializer for {@link RegistryClassInfo}
*
* @param <R> Registry class
*/
public class RegistrySerializer<R extends Keyed> extends Serializer<R> {

private final Registry<R> registry;
Expand Down Expand Up @@ -73,6 +78,7 @@ protected boolean canBeInstantiated() {

@Override
public void deserialize(R o, Fields f) {
throw new UnsupportedOperationException();
}

}
13 changes: 9 additions & 4 deletions src/main/java/ch/njol/skript/classes/registry/RegistryUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@
import org.bukkit.Keyed;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.eclipse.jdt.annotation.Nullable;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

/**
* Utility class for {@link Registry}
*
* @param <R> Registry class
*/
public class RegistryUtils<R extends Keyed> {

private final Registry<R> registry;
Expand All @@ -47,7 +52,7 @@ public RegistryUtils(Registry<R> registry, String languageNode) {
Language.addListener(this::refresh);
}

void refresh() {
private void refresh() {
names.clear();
parseMap.clear();
for (R registryObject : registry) {
Expand All @@ -61,14 +66,14 @@ void refresh() {
parseMap.put(namespacedKey.toString(), registryObject);

// If the object is a vanilla Minecraft object, we'll add the key with spaces as a pattern
if (namespace.equalsIgnoreCase("minecraft")) {
if (namespace.equalsIgnoreCase(NamespacedKey.MINECRAFT)) {
parseMap.put(keyWithSpaces, registryObject);
}

String[] options = Language.getList(languageKey);
// Missing/Custom registry objects
if (options.length == 1 && options[0].equals(languageKey.toLowerCase(Locale.ENGLISH))) {
if (namespace.equalsIgnoreCase("minecraft")) {
if (namespace.equalsIgnoreCase(NamespacedKey.MINECRAFT)) {
// If the object is a vanilla Minecraft object, we'll use the key with spaces as a name
names.put(registryObject, keyWithSpaces);
} else {
Expand Down

0 comments on commit b2317c9

Please sign in to comment.