From b29342ec619a64461b8d0f31087cde116342479e Mon Sep 17 00:00:00 2001 From: Gabriel Harris-Rouquette Date: Wed, 16 Mar 2016 17:07:56 -0700 Subject: [PATCH] Add failsafe for CatalogTypes that are DataSerializables. Signed-off-by: Gabriel Harris-Rouquette --- .../org/spongepowered/api/data/MemoryDataView.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/spongepowered/api/data/MemoryDataView.java b/src/main/java/org/spongepowered/api/data/MemoryDataView.java index 083e8c5a1ec..c11c585401f 100644 --- a/src/main/java/org/spongepowered/api/data/MemoryDataView.java +++ b/src/main/java/org/spongepowered/api/data/MemoryDataView.java @@ -239,13 +239,13 @@ public DataView set(DataQuery path, Object value) { if (value instanceof DataView) { checkArgument(value != this, "Cannot set a DataView to itself."); copyDataView(path, (DataView) value); - } else if (value instanceof CatalogType) { - return set(path, ((CatalogType) value).getId()); - } else if (value instanceof DataSerializable) { + }else if (value instanceof DataSerializable) { DataContainer valueContainer = ((DataSerializable) value).toContainer(); checkArgument(!(valueContainer).equals(this), "Cannot insert self-referencing DataSerializable"); copyDataView(path, valueContainer); - } else { + } else if (value instanceof CatalogType) { + return set(path, ((CatalogType) value).getId()); + } else { List parts = path.getParts(); if (parts.size() > 1) { String subKey = parts.get(0); @@ -791,7 +791,10 @@ public Optional getSerializable(DataQuery path, checkNotNull(clazz, "clazz"); DataManager manager = Sponge.getDataManager(); if (clazz.isAssignableFrom(CatalogType.class)) { - return (Optional) getCatalogType(path, ((Class) clazz)); + final Optional catalog = (Optional) getCatalogType(path, ((Class) clazz)); + if (catalog.isPresent()) { + return catalog; + } } Optional optional = getUnsafeView(path);