9
0
mirror of https://github.com/WiIIiam278/HuskSync.git synced 2025-12-30 12:19:20 +00:00

refactor: Use mappings class for PDC tag type handling

This commit is contained in:
William
2023-02-12 19:14:46 +00:00
parent 3425c97245
commit 1d7f6a8d8b
6 changed files with 90 additions and 125 deletions

View File

@@ -34,9 +34,9 @@ public class PersistentDataContainerData {
return Optional.empty();
}
public Optional<BukkitPersistentDataTagType> getTagType(@NotNull final String tagType) {
public Optional<PersistentDataTagType> getTagType(@NotNull final String tagType) {
if (persistentDataMap.containsKey(tagType)) {
return BukkitPersistentDataTagType.getDataType(persistentDataMap.get(tagType).type);
return PersistentDataTagType.getDataType(persistentDataMap.get(tagType).type);
}
return Optional.empty();
}

View File

@@ -19,16 +19,17 @@ public class PersistentDataTag<T> {
*/
public T value;
public PersistentDataTag(@NotNull BukkitPersistentDataTagType type, @NotNull T value) {
public PersistentDataTag(@NotNull PersistentDataTagType type, @NotNull T value) {
this.type = type.name();
this.value = value;
}
@SuppressWarnings("unused")
private PersistentDataTag() {
}
public Optional<BukkitPersistentDataTagType> getType() {
return BukkitPersistentDataTagType.getDataType(type);
public Optional<PersistentDataTagType> getType() {
return PersistentDataTagType.getDataType(type);
}
}

View File

@@ -7,7 +7,7 @@ import java.util.Optional;
/**
* Represents the type of a {@link PersistentDataTag}
*/
public enum BukkitPersistentDataTagType {
public enum PersistentDataTagType {
BYTE,
SHORT,
@@ -23,8 +23,8 @@ public enum BukkitPersistentDataTagType {
TAG_CONTAINER;
public static Optional<BukkitPersistentDataTagType> getDataType(@NotNull String typeName) {
for (BukkitPersistentDataTagType type : values()) {
public static Optional<PersistentDataTagType> getDataType(@NotNull String typeName) {
for (PersistentDataTagType type : values()) {
if (type.name().equalsIgnoreCase(typeName)) {
return Optional.of(type);
}