Skip to content

Commit

Permalink
Fixed backwards-compatibility with Key#of(<string>) method (#1849)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Aug 26, 2023
1 parent ec7f59a commit 3c4f5a8
Showing 1 changed file with 13 additions and 0 deletions.
Expand Up @@ -6,6 +6,8 @@
import com.bgsoftware.superiorskyblock.api.key.KeyMap;
import com.bgsoftware.superiorskyblock.api.key.KeySet;
import com.bgsoftware.superiorskyblock.core.Manager;
import com.bgsoftware.superiorskyblock.core.key.types.EntityTypeKey;
import com.bgsoftware.superiorskyblock.core.key.types.MaterialKey;
import com.google.common.base.Preconditions;
import org.bukkit.Material;
import org.bukkit.block.Block;
Expand Down Expand Up @@ -99,6 +101,17 @@ public Key getSpawnerKey(String entityTypeName) {
@Override
public Key getKey(String key) {
Preconditions.checkNotNull(key, "key parameter cannot be null.");
// Due to backwards compatibility, we want to try and check if this is either a MaterialKey or EntityTypeKey.
Key materialKey = Key.ofMaterialAndData(key);
if (materialKey instanceof MaterialKey)
return materialKey;

Key entityTypeKey = Key.ofEntityType(key);
if (entityTypeKey instanceof EntityTypeKey)
return entityTypeKey;

// This key does not fit MaterialKey nor EntityTypeKey, therefore we'll create a CustomKey.

String[] keySections = key.split(":");
return ((BaseKey<? extends Key>) Keys.of(keySections[0], keySections.length >= 2 ? keySections[1] : null)).markAPIKey();
}
Expand Down

0 comments on commit 3c4f5a8

Please sign in to comment.