use of com.denizenscript.denizen.utilities.blocks.FullBlockData in project Denizen-For-Bukkit by DenizenScript.
the class CopyBlockCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
LocationTag copy_location = scriptEntry.getObjectTag("location");
LocationTag destination = scriptEntry.getObjectTag("destination");
ElementTag remove_original = scriptEntry.getElement("remove");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), copy_location, destination, remove_original);
}
List<Location> locations = new ArrayList<>();
if (copy_location != null) {
locations.add(copy_location);
}
for (Location loc : locations) {
Block source = loc.getBlock();
BlockState sourceState = source.getState();
Block update = destination.getBlock();
FullBlockData block = new FullBlockData(source);
block.set(update, false);
BlockState updateState = update.getState();
// of InventoryHolder
if (sourceState instanceof InventoryHolder) {
((InventoryHolder) updateState).getInventory().setContents(((InventoryHolder) sourceState).getInventory().getContents());
} else if (sourceState instanceof Sign) {
int n = 0;
for (String line : ((Sign) sourceState).getLines()) {
AdvancedTextImpl.instance.setSignLine(((Sign) updateState), n++, line);
}
} else if (sourceState instanceof Skull) {
((Skull) updateState).setSkullType(((Skull) sourceState).getSkullType());
((Skull) updateState).setOwner(((Skull) sourceState).getOwner());
((Skull) updateState).setRotation(((Skull) sourceState).getRotation());
} else if (sourceState instanceof Jukebox) {
((Jukebox) updateState).setPlaying(((Jukebox) sourceState).getPlaying());
} else if (sourceState instanceof Banner) {
((Banner) updateState).setBaseColor(((Banner) sourceState).getBaseColor());
((Banner) updateState).setPatterns(((Banner) sourceState).getPatterns());
} else if (sourceState instanceof CommandBlock) {
((CommandBlock) updateState).setName(((CommandBlock) sourceState).getName());
((CommandBlock) updateState).setCommand(((CommandBlock) sourceState).getCommand());
} else if (sourceState instanceof CreatureSpawner) {
((CreatureSpawner) updateState).setSpawnedType(((CreatureSpawner) sourceState).getSpawnedType());
((CreatureSpawner) updateState).setDelay(((CreatureSpawner) sourceState).getDelay());
}
updateState.update();
if (remove_original.asBoolean()) {
loc.getBlock().setType(Material.AIR);
}
}
}
Aggregations