mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-16 20:32:29 +01:00
Merge pull request #2498 from BentoBoxWorld/2497_Blueprint_and_mobs
2497 blueprint and mobs
This commit is contained in:
commit
a716feb9a6
@ -13,7 +13,11 @@ public class ProfessionTypeAdapter extends TypeAdapter<Profession> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(JsonWriter out, Profession profession) throws IOException {
|
public void write(JsonWriter out, Profession profession) throws IOException {
|
||||||
|
if (profession != null) {
|
||||||
out.value(profession.name());
|
out.value(profession.name());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
out.nullValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -13,6 +13,10 @@ public class VillagerTypeAdapter extends TypeAdapter<Villager.Type> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(JsonWriter out, Villager.Type type) throws IOException {
|
public void write(JsonWriter out, Villager.Type type) throws IOException {
|
||||||
|
if (type == null) {
|
||||||
|
out.nullValue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
out.value(type.name());
|
out.value(type.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,10 +253,32 @@ public class Players implements DataObject, MetaDataAble {
|
|||||||
public Optional<Map<String, MetaDataValue>> getMetaData() {
|
public Optional<Map<String, MetaDataValue>> getMetaData() {
|
||||||
if (metaData == null) {
|
if (metaData == null) {
|
||||||
metaData = new HashMap<>();
|
metaData = new HashMap<>();
|
||||||
|
} else if (isImmutable(metaData)) {
|
||||||
|
metaData = new HashMap<>(metaData); // Convert immutable map to mutable
|
||||||
}
|
}
|
||||||
return Optional.of(metaData);
|
return Optional.of(metaData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isImmutable(Map<String, MetaDataValue> map) {
|
||||||
|
try {
|
||||||
|
String testKey = "testKey";
|
||||||
|
MetaDataValue testValue = new MetaDataValue("test");
|
||||||
|
|
||||||
|
// If the map already contains keys, use one of them
|
||||||
|
if (!map.isEmpty()) {
|
||||||
|
String existingKey = map.keySet().iterator().next();
|
||||||
|
map.put(existingKey, map.get(existingKey)); // Attempt to replace value
|
||||||
|
} else {
|
||||||
|
// Use a unique key-value pair
|
||||||
|
map.put(testKey, testValue);
|
||||||
|
map.remove(testKey);
|
||||||
|
}
|
||||||
|
return false; // No exception means the map is mutable
|
||||||
|
} catch (UnsupportedOperationException e) {
|
||||||
|
return true; // Exception means the map is immutable
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param metaData the metaData to set
|
* @param metaData the metaData to set
|
||||||
* @since 1.15.4
|
* @since 1.15.4
|
||||||
@ -264,6 +286,9 @@ public class Players implements DataObject, MetaDataAble {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setMetaData(Map<String, MetaDataValue> metaData) {
|
public void setMetaData(Map<String, MetaDataValue> metaData) {
|
||||||
|
if (isImmutable(metaData)) {
|
||||||
|
throw new IllegalArgumentException("Provided map is immutable and cannot be set.");
|
||||||
|
}
|
||||||
this.metaData = metaData;
|
this.metaData = metaData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user