Revert "Added LONG_STRING column type"

This reverts commit 83958c719c.
This commit is contained in:
Auxilor
2022-05-25 19:20:47 +01:00
parent 83958c719c
commit de9b961d83
6 changed files with 3 additions and 59 deletions

View File

@@ -6,7 +6,6 @@ import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
/**
* All storable data key types.
@@ -20,14 +19,9 @@ public final class PersistentDataKeyType<T> {
private static final List<PersistentDataKeyType<?>> VALUES = new ArrayList<>();
/**
* String (Under 512 characters).
* String.
*/
public static final PersistentDataKeyType<String> STRING = new PersistentDataKeyType<>(String.class, "STRING", it -> it.length() < 512);
/**
* Long String.
*/
public static final PersistentDataKeyType<String> LONG_STRING = new PersistentDataKeyType<>(String.class, "LONG_STRING");
public static final PersistentDataKeyType<String> STRING = new PersistentDataKeyType<>(String.class, "STRING");
/**
* Boolean.
@@ -54,11 +48,6 @@ public final class PersistentDataKeyType<T> {
*/
private final String name;
/**
* The data validator.
*/
private final Predicate<T> validator;
/**
* Get the class of the type.
*
@@ -85,34 +74,10 @@ public final class PersistentDataKeyType<T> {
*/
private PersistentDataKeyType(@NotNull final Class<T> typeClass,
@NotNull final String name) {
this(typeClass, name, it -> true);
}
/**
* Create new PersistentDataKeyType.
*
* @param typeClass The type class.
* @param name The name.
* @param validator The validator.
*/
private PersistentDataKeyType(@NotNull final Class<T> typeClass,
@NotNull final String name,
@NotNull final Predicate<T> validator) {
VALUES.add(this);
this.typeClass = typeClass;
this.name = name;
this.validator = validator;
}
/**
* Test if the value is valid for this column.
*
* @param value The value.
* @return If valid.
*/
public boolean isValid(@NotNull final T value) {
return validator.test(value);
}
@Override

View File

@@ -24,7 +24,7 @@ class EcoKeyRegistry : KeyRegistry {
return registry.values.toMutableSet()
}
private fun <T> validateKey(key: PersistentDataKey<T>) where T : Any {
private fun <T> validateKey(key: PersistentDataKey<T>) {
when (key.type) {
PersistentDataKeyType.INT -> if (key.defaultValue !is Int) {
throw IllegalArgumentException("Invalid Data Type! Should be Int")
@@ -38,17 +38,9 @@ class EcoKeyRegistry : KeyRegistry {
PersistentDataKeyType.STRING -> if (key.defaultValue !is String) {
throw IllegalArgumentException("Invalid Data Type! Should be String")
}
PersistentDataKeyType.LONG_STRING -> if (key.defaultValue !is String) {
throw IllegalArgumentException("Invalid Data Type! Should be String")
}
else -> throw NullPointerException("Null value found!")
}
if (!key.type.isValid(key.defaultValue as T)) {
throw IllegalArgumentException("Invalid default value! Does not match test.")
}
}
override fun markKeyAs(key: PersistentDataKey<*>, category: KeyRegistry.KeyCategory) {

View File

@@ -14,10 +14,6 @@ abstract class EcoProfile(
private val handler: DataHandler
) : Profile {
override fun <T : Any> write(key: PersistentDataKey<T>, value: T) {
if (!key.type.isValid(value)) {
throw IllegalArgumentException("Invalid value provided for type ${key.type.name()}")
}
this.data[key] = value
val changedKeys = CHANGE_MAP[uuid] ?: mutableSetOf()

View File

@@ -21,11 +21,6 @@ object KeyHelpers {
type as PersistentDataKeyType<String>,
if (split.size >= 3) split.toList().subList(2, split.size).joinToString("") else ""
)
PersistentDataKeyType.LONG_STRING -> PersistentDataKey(
key,
type as PersistentDataKeyType<String>,
if (split.size >= 3) split.toList().subList(2, split.size).joinToString("") else ""
)
PersistentDataKeyType.INT -> PersistentDataKey(
key,
type as PersistentDataKeyType<Int>,

View File

@@ -23,7 +23,6 @@ import org.jetbrains.exposed.sql.DoubleColumnType
import org.jetbrains.exposed.sql.IntegerColumnType
import org.jetbrains.exposed.sql.ResultRow
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.TextColumnType
import org.jetbrains.exposed.sql.VarCharColumnType
import org.jetbrains.exposed.sql.exposedLogger
import org.jetbrains.exposed.sql.insert
@@ -290,8 +289,6 @@ private class ImplementedMySQLHandler(
.default(key.defaultValue as Boolean)
PersistentDataKeyType.STRING -> registerColumn<String>(key.key.toString(), VarCharColumnType(512))
.default(key.defaultValue as String)
PersistentDataKeyType.LONG_STRING -> registerColumn<String>(key.key.toString(), TextColumnType())
.default(key.defaultValue as String)
else -> throw NullPointerException("Null value found!")
}

View File

@@ -43,7 +43,6 @@ class YamlDataHandler(
PersistentDataKeyType.INT -> dataYml.getIntOrNull("player.$uuid.${key.key}")
PersistentDataKeyType.DOUBLE -> dataYml.getDoubleOrNull("player.$uuid.${key.key}")
PersistentDataKeyType.STRING -> dataYml.getStringOrNull("player.$uuid.${key.key}")
PersistentDataKeyType.LONG_STRING -> dataYml.getStringOrNull("player.$uuid.${key.key}")
PersistentDataKeyType.BOOLEAN -> dataYml.getBoolOrNull("player.$uuid.${key.key}")
else -> null
} as? T?