mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-22 07:11:56 +01:00
Improved the on-the-fly Blueprint conversion
https://github.com/BentoBoxWorld/BentoBox/issues/802 It now avoids sending warnings if the conversion could be achieved seamlessly.
This commit is contained in:
parent
1fd880a529
commit
18f37c4efa
@ -183,22 +183,11 @@ public class BlueprintPaster {
|
||||
BlueprintBlock bpBlock = entry.getValue();
|
||||
Block block = pasteTo.getBlock();
|
||||
// Set the block data - default is AIR
|
||||
BlockData bd = Bukkit.createBlockData(Material.AIR);
|
||||
BlockData bd;
|
||||
try {
|
||||
bd = Bukkit.createBlockData(bpBlock.getBlockData());
|
||||
} catch (Exception e) {
|
||||
// This may happen if the block type is no longer supported by the server
|
||||
plugin.logWarning("Blueprint references materials not supported on this server version.");
|
||||
plugin.logWarning("Load blueprint manually, check and save to fix for this server version.");
|
||||
plugin.logWarning("World: " + world.getName() + " Failed block data: " + bpBlock.getBlockData());
|
||||
// Try to fix
|
||||
for (Entry<String, String> en : BLOCK_CONVERSION.entrySet()) {
|
||||
if (bpBlock.getBlockData().startsWith(MINECRAFT + en.getKey())) {
|
||||
bd = Bukkit.createBlockData(
|
||||
bpBlock.getBlockData().replace(MINECRAFT + en.getKey(), MINECRAFT + en.getValue()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
bd = convertBlockData(world, bpBlock);
|
||||
}
|
||||
block.setBlockData(bd, false);
|
||||
setBlockState(island, block, bpBlock);
|
||||
@ -206,6 +195,29 @@ public class BlueprintPaster {
|
||||
updatePos(world, entry.getKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to convert the BlockData to a newer version, and logs a warning if it fails to do so.
|
||||
* @return the converted BlockData or a default AIR BlockData.
|
||||
* @since 1.6.0
|
||||
*/
|
||||
private BlockData convertBlockData(World world, BlueprintBlock block) {
|
||||
BlockData blockData = Bukkit.createBlockData(Material.AIR);
|
||||
try {
|
||||
for (Entry<String, String> en : BLOCK_CONVERSION.entrySet()) {
|
||||
if (block.getBlockData().startsWith(MINECRAFT + en.getKey())) {
|
||||
blockData = Bukkit.createBlockData(block.getBlockData().replace(MINECRAFT + en.getKey(), MINECRAFT + en.getValue()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
// This may happen if the block type is no longer supported by the server
|
||||
plugin.logWarning("Blueprint references materials not supported on this server version.");
|
||||
plugin.logWarning("Load blueprint manually, check and save to fix for this server version.");
|
||||
plugin.logWarning("World: " + world.getName() + "; Failed block data: " + block.getBlockData());
|
||||
}
|
||||
return blockData;
|
||||
}
|
||||
|
||||
private void pasteEntity(World world, Location location, Entry<Vector, List<BlueprintEntity>> entry) {
|
||||
int x = location.getBlockX() + entry.getKey().getBlockX();
|
||||
int y = location.getBlockY() + entry.getKey().getBlockY();
|
||||
|
Loading…
Reference in New Issue
Block a user