Disable version field in editor. Softer class name rules. Minor field naming.

This commit is contained in:
Olof Larsson 2017-03-24 15:52:37 +01:00
parent c7db1cf90d
commit 930e81c37e
2 changed files with 8 additions and 8 deletions

View File

@ -12,6 +12,7 @@ import com.massivecraft.massivecore.command.type.Type;
import com.massivecraft.massivecore.command.type.TypeWrapper;
import com.massivecraft.massivecore.mson.Mson;
import com.massivecraft.massivecore.particleeffect.ReflectionUtils;
import com.massivecraft.massivecore.store.migration.VersionMigrationUtil;
import com.massivecraft.massivecore.util.ReflectionUtil;
import com.massivecraft.massivecore.util.Txt;
import org.bukkit.ChatColor;
@ -230,6 +231,9 @@ public class PropertyReflection<O, V> extends Property<O, V>
int modifiers = field.getModifiers();
if (Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers) || Modifier.isFinal(modifiers)) ret = false;
// Fill > Version
if (field.getName().equals(VersionMigrationUtil.VERSION_FIELD_NAME)) ret = false;
// Fill > Annotation
ret = getAnnotationValue(field, EditorEditable.class, ret);

View File

@ -91,13 +91,9 @@ public class VersionMigratorRoot implements VersionMigrator, Active
public int getVersion()
{
String name = this.getClass().getSimpleName();
if (!name.startsWith("V")) throw new UnsupportedOperationException(String.format("Name of %s doesn't start with \"V\".", name));
if (!Character.isDigit(name.charAt(1))) throw new IllegalStateException(String.format("Second character of %s isn't a digit", name));
Matcher matcher = Txt.PATTERN_NUMBER.matcher(name);
if (!matcher.find()) throw new UnsupportedOperationException(String.format("%s doesn't have a version number.", name));
String number = matcher.group();
return Integer.parseInt(number);
}
@ -110,12 +106,12 @@ public class VersionMigratorRoot implements VersionMigrator, Active
{
if (entity == null) throw new NullPointerException("entity");
// Get entity version and the expected entity version ...
int entityVersion = VersionMigrationUtil.getVersion(entity);
int expectedEntityVersion = this.getVersion() - 1;
// Get current and expected entity version ...
int entityVersionCurrent = VersionMigrationUtil.getVersion(entity);
int entityVersionExpected = this.getVersion() - 1;
// ... make sure they match ...
if (entityVersion != expectedEntityVersion) throw new IllegalArgumentException(String.format("Entiy version: %d Expected: %d", entityVersion, expectedEntityVersion));
if (entityVersionCurrent != entityVersionExpected) throw new IllegalArgumentException(String.format("Entiy version: %d Expected: %d", entityVersionCurrent, entityVersionExpected));
// ... do the migration.
this.migrateInner(entity);