mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-23 15:51:39 +01:00
Fixes conversion of legacy schem entities.
This commit is contained in:
parent
6b6a757727
commit
b2a6396cf8
@ -117,7 +117,11 @@ public class Blueprint {
|
||||
* @param entities the entities to set
|
||||
*/
|
||||
public void setEntities(Map<Vector, List<BlueprintEntity>> entities) {
|
||||
this.entities = entities;
|
||||
if (this.entities == null) {
|
||||
this.entities = entities;
|
||||
} else {
|
||||
this.entities.putAll(entities);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return the blocks
|
||||
|
@ -252,7 +252,7 @@ public class BlueprintPaster {
|
||||
* @param list - list of entities to paste
|
||||
*/
|
||||
private void setEntity(Location location, List<BlueprintEntity> list) {
|
||||
list.forEach(k -> {
|
||||
list.stream().filter(k -> k.getType() != null).forEach(k -> {
|
||||
// Center, and just a bit high
|
||||
Location center = location.add(new Vector(0.5, 0.5, 0.5));
|
||||
LivingEntity e = (LivingEntity)location.getWorld().spawnEntity(center, k.getType());
|
||||
|
@ -188,7 +188,7 @@ public class Players implements DataObject {
|
||||
*/
|
||||
public void setHomeLocation(Location location, int number) {
|
||||
// Remove any home locations in the same world with the same number
|
||||
homeLocations.entrySet().removeIf(e -> Util.sameWorld(location.getWorld(), e.getKey().getWorld()) && e.getValue().equals(number));
|
||||
homeLocations.entrySet().removeIf(e -> e.getKey() == null || (Util.sameWorld(location.getWorld(), e.getKey().getWorld()) && e.getValue().equals(number)));
|
||||
homeLocations.put(location, number);
|
||||
}
|
||||
|
||||
@ -205,7 +205,7 @@ public class Players implements DataObject {
|
||||
* @param world - world
|
||||
*/
|
||||
public void clearHomeLocations(World world) {
|
||||
homeLocations.keySet().removeIf(l -> Util.sameWorld(l.getWorld(), world));
|
||||
homeLocations.keySet().removeIf(l -> l == null || Util.sameWorld(l.getWorld(), world));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,6 +54,19 @@ public class Converter {
|
||||
.map(this::convertBlock)
|
||||
// Collect into a map
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
|
||||
// Legacy entities
|
||||
Map<Vector, List<BlueprintEntity>> le = bc.getConfigurationSection(BLOCKS_YAML_PREFIX).getKeys(false).stream()
|
||||
// make configuration section from key
|
||||
.map(k -> bc.getConfigurationSection(BLOCKS_YAML_PREFIX + k))
|
||||
// Check the config section contains block data key "entities"
|
||||
.filter(cs -> cs.contains("entity"))
|
||||
// Convert it
|
||||
.map(this::convertLegacyEntity)
|
||||
// Collect into a map
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
if (le != null) {
|
||||
bp.setEntities(le);
|
||||
}
|
||||
}
|
||||
// Attached blocks
|
||||
if (bc.isConfigurationSection(ATTACHED_YAML_PREFIX)) {
|
||||
@ -80,6 +93,20 @@ public class Converter {
|
||||
|
||||
}
|
||||
|
||||
private Entry<Vector, List<BlueprintEntity>> convertLegacyEntity(ConfigurationSection config) {
|
||||
ConfigurationSection en = config.getConfigurationSection("entity");
|
||||
// Vector
|
||||
Vector vector = getVector(config.getName());
|
||||
// Create a list of entities at this position
|
||||
List<BlueprintEntity> list = en.getKeys(false).stream()
|
||||
.map(en::getConfigurationSection)
|
||||
.map(this::createEntity)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
return new AbstractMap.SimpleEntry<>(vector, list);
|
||||
|
||||
}
|
||||
|
||||
private Entry<Vector, BlueprintBlock> convertBlock(ConfigurationSection config) {
|
||||
String blockData = config.getString("bd");
|
||||
// Make block
|
||||
@ -108,8 +135,10 @@ public class Converter {
|
||||
spawner.setSpawnRange(config.getInt("spawnRange", 4));
|
||||
block.setCreatureSpawner(spawner);
|
||||
}
|
||||
|
||||
// Vector
|
||||
Vector vector = getVector(config.getName());
|
||||
|
||||
// Return entry
|
||||
return new AbstractMap.SimpleEntry<>(vector, block);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user