Adds protection when pasting against unsupported blocks.

Will fix signs and wall signs from 1.13 to 1.14.
This commit is contained in:
tastybento 2019-05-15 14:18:51 -07:00
parent 700043fe40
commit 3cb9a0e4df

View File

@ -1,5 +1,11 @@
package world.bentobox.bentobox.blueprints; package world.bentobox.bentobox.blueprints;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
@ -9,6 +15,7 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.block.CreatureSpawner; import org.bukkit.block.CreatureSpawner;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.AbstractHorse; import org.bukkit.entity.AbstractHorse;
import org.bukkit.entity.Ageable; import org.bukkit.entity.Ageable;
import org.bukkit.entity.ChestedHorse; import org.bukkit.entity.ChestedHorse;
@ -22,6 +29,9 @@ import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import com.google.common.collect.ImmutableMap;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
@ -31,12 +41,6 @@ import world.bentobox.bentobox.blueprints.dataobjects.BlueprintEntity;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
/** /**
* This class pastes the clipboard it is given * This class pastes the clipboard it is given
* @author tastybento * @author tastybento
@ -52,6 +56,8 @@ public class BlueprintPaster {
CANCEL CANCEL
} }
private Map<String, String> BLOCK_CONVERSION = ImmutableMap.of("sign", "oak_sign", "wall_sign", "oak_wall_sign");
private BentoBox plugin; private BentoBox plugin;
// The minimum block position (x,y,z) // The minimum block position (x,y,z)
private Location pos1; private Location pos1;
@ -173,8 +179,25 @@ public class BlueprintPaster {
Location pasteTo = location.clone().add(entry.getKey()); Location pasteTo = location.clone().add(entry.getKey());
BlueprintBlock bpBlock = entry.getValue(); BlueprintBlock bpBlock = entry.getValue();
Block block = pasteTo.getBlock(); Block block = pasteTo.getBlock();
// Set the block data // Set the block data - default is AIR
block.setBlockData(Bukkit.createBlockData(bpBlock.getBlockData())); BlockData bd = Bukkit.createBlockData(Material.AIR);
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;
}
}
}
block.setBlockData(bd);
setBlockState(island, block, bpBlock); setBlockState(island, block, bpBlock);
// pos1 and pos2 update // pos1 and pos2 update
updatePos(world, entry.getKey()); updatePos(world, entry.getKey());